Commit 9947b68c authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

Add the decVal field to VARIANT.

Fix the VARIANT C layout, i.e. the union/struct names/nesting. Encapsulate all accesses to VARIANT types with the V_VT and V_UNION macros.
parent 05b6618f
......@@ -1117,8 +1117,8 @@ static HRESULT WINAPI OLEPictureImpl_Invoke(
FIXME("(dispid: %ld):Stub\n",dispIdMember);
VariantInit(pVarResult);
pVarResult->vt = VT_BOOL;
pVarResult->u.boolVal = FALSE;
V_VT(pVarResult) = VT_BOOL;
V_UNION(pVarResult,boolVal) = FALSE;
return S_OK;
}
......
......@@ -760,8 +760,8 @@ static void dump_Variant(VARIANT * pvar)
break;
}
if (pvar->vt & VT_BYREF)
return dump_Variant(pvar->u.pvarVal);
if (V_VT(pvar) & VT_BYREF)
return dump_Variant(V_UNION(pvar,pvarVal));
}
static void dump_DispParms(DISPPARAMS * pdp)
......@@ -947,14 +947,14 @@ static void TLB_ReadValue( VARIANT * pVar, int offset, TLBContext *pcx )
TRACE_(typelib)("\n");
if(offset <0) { /* data is packed in here */
pVar->vt = (offset & 0x7c000000 )>> 26;
V_VT(pVar) = (offset & 0x7c000000 )>> 26;
V_UNION(pVar, iVal) = offset & 0xffff;
return;
}
TLB_Read(&(pVar->vt), sizeof(VARTYPE), pcx,
TLB_Read(&(V_VT(pVar)), sizeof(VARTYPE), pcx,
pcx->pTblDir->pCustData.offset + offset );
TRACE_(typelib)("Vartype = %x\n", pVar->vt);
switch(pVar->vt){
TRACE_(typelib)("Vartype = %x\n", V_VT(pVar));
switch (V_VT(pVar)){
case VT_EMPTY: /* FIXME: is this right? */
case VT_NULL: /* FIXME: is this right? */
case VT_I2 : /* this should not happen */
......@@ -1017,7 +1017,7 @@ static void TLB_ReadValue( VARIANT * pVar, int offset, TLBContext *pcx )
default:
size=0;
FIXME("VARTYPE %d is not supported, setting pointer to NULL\n",
pVar->vt);
V_VT(pVar));
}
if(size>0) /* (big|small) endian correct? */
......@@ -1203,8 +1203,7 @@ TLB_DoFuncs(TLBContext* pcx,
paraminfo.DataType,
&(*pptfd)->funcdesc.lprgelemdescParam[j].tdesc) ;
V_UNION(& ((*pptfd)->funcdesc.lprgelemdescParam[j]),
paramdesc.wParamFlags) = paraminfo.Flags;
(*pptfd)->funcdesc.lprgelemdescParam[j].u.paramdesc.wParamFlags = paraminfo.Flags;
(*pptfd)->pParamDesc[j].Name = (void *) paraminfo.oName;
......@@ -1298,21 +1297,18 @@ TLB_DoFuncs(TLBContext* pcx,
/* default value */
if ( (PARAMFLAG_FHASDEFAULT &
V_UNION(&((*pptfd)->funcdesc.lprgelemdescParam[j]),
paramdesc.wParamFlags)) &&
(*pptfd)->funcdesc.lprgelemdescParam[j].u.paramdesc.wParamFlags) &&
((pFuncRec->FKCCIC) & 0x1000) )
{
INT* pInt = (INT *)((char *)pFuncRec +
reclength -
(pFuncRec->nrargs * 4 + 1) * sizeof(INT) );
PARAMDESC* pParamDesc = &V_UNION(
& ((*pptfd)->funcdesc.lprgelemdescParam[j]),
paramdesc);
PARAMDESC* pParamDesc = & (*pptfd)->funcdesc.lprgelemdescParam[j].u.paramdesc;
pParamDesc->pparamdescex = TLB_Alloc(sizeof(PARAMDESCEX));
pParamDesc->pparamdescex->cBytes = sizeof(PARAMDESCEX);
TLB_ReadValue(&(pParamDesc->pparamdescex->varDefaultValue),
pInt[j], pcx);
}
......@@ -1325,11 +1321,11 @@ TLB_DoFuncs(TLBContext* pcx,
}
}
}
/* scode is not used: archaic win16 stuff FIXME: right? */
(*pptfd)->funcdesc.cScodes = 0 ;
(*pptfd)->funcdesc.lprgscode = NULL ;
pptfd = & ((*pptfd)->next);
recoffset += reclength;
}
......@@ -1376,11 +1372,11 @@ static void TLB_DoVars(TLBContext *pcx, int cFuncs, int cVars,
&(*pptvd)->vardesc.elemdescVar.tdesc) ;
/* (*pptvd)->vardesc.lpstrSchema; is reserved (SDK) fixme?? */
if(pVarRec->VarKind == VAR_CONST ){
V_UNION(&((*pptvd)->vardesc),lpvarValue)=TLB_Alloc(sizeof(VARIANT));
TLB_ReadValue(V_UNION(&((*pptvd)->vardesc),lpvarValue),
(*pptvd)->vardesc.u.lpvarValue=TLB_Alloc(sizeof(VARIANT));
TLB_ReadValue((*pptvd)->vardesc.u.lpvarValue,
pVarRec->OffsValue, pcx);
}else
V_UNION(&((*pptvd)->vardesc),oInst)=pVarRec->OffsValue;
} else
(*pptvd)->vardesc.u.oInst=pVarRec->OffsValue;
pptvd=&((*pptvd)->next);
recoffset += reclength;
}
......@@ -1805,18 +1801,18 @@ static ITypeLib2* ITypeLib2_Constructor(LPVOID pLib, DWORD dwTLBLength)
{
/* FIXME: check safearray */
if(td[3] < 0)
V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lptdesc)= & stndTypeDesc[td[2]];
pTypeLibImpl->pTypeDesc[i].u.lptdesc= & stndTypeDesc[td[2]];
else
V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lptdesc)= & pTypeLibImpl->pTypeDesc[td[2]/8];
pTypeLibImpl->pTypeDesc[i].u.lptdesc= & pTypeLibImpl->pTypeDesc[td[2]/8];
}
else if(td[0] == VT_CARRAY)
{
/* array descr table here */
V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lpadesc) = (void *)((int) td[2]); /* temp store offset in*/
}
pTypeLibImpl->pTypeDesc[i].u.lpadesc = (void *)((int) td[2]); /* temp store offset in*/
}
else if(td[0] == VT_USERDEFINED)
{
V_UNION(&(pTypeLibImpl->pTypeDesc[i]),hreftype) = MAKELONG(td[2],td[3]);
pTypeLibImpl->pTypeDesc[i].u.hreftype = MAKELONG(td[2],td[3]);
}
if(++i<cTD) TLB_Read(td, sizeof(td), &cx, DO_NOT_SEEK);
}
......@@ -1827,27 +1823,27 @@ static ITypeLib2* ITypeLib2_Constructor(LPVOID pLib, DWORD dwTLBLength)
if(pTypeLibImpl->pTypeDesc[i].vt != VT_CARRAY) continue;
if(tlbSegDir.pArrayDescriptions.offset>0)
{
TLB_Read(td, sizeof(td), &cx, tlbSegDir.pArrayDescriptions.offset + (int) V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lpadesc));
V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lpadesc) = TLB_Alloc(sizeof(ARRAYDESC)+sizeof(SAFEARRAYBOUND)*(td[3]-1));
TLB_Read(td, sizeof(td), &cx, tlbSegDir.pArrayDescriptions.offset + (int) pTypeLibImpl->pTypeDesc[i].u.lpadesc);
pTypeLibImpl->pTypeDesc[i].u.lpadesc = TLB_Alloc(sizeof(ARRAYDESC)+sizeof(SAFEARRAYBOUND)*(td[3]-1));
if(td[1]<0)
V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lpadesc)->tdescElem.vt = td[0] & VT_TYPEMASK;
pTypeLibImpl->pTypeDesc[i].u.lpadesc->tdescElem.vt = td[0] & VT_TYPEMASK;
else
V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lpadesc)->tdescElem = stndTypeDesc[td[0]/8];
pTypeLibImpl->pTypeDesc[i].u.lpadesc->tdescElem = stndTypeDesc[td[0]/8];
V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lpadesc)->cDims = td[2];
pTypeLibImpl->pTypeDesc[i].u.lpadesc->cDims = td[2];
for(j = 0; j<td[2]; j++)
{
TLB_Read(& V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lpadesc)->rgbounds[j].cElements,
TLB_Read(& pTypeLibImpl->pTypeDesc[i].u.lpadesc->rgbounds[j].cElements,
sizeof(INT), &cx, DO_NOT_SEEK);
TLB_Read(& V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lpadesc)->rgbounds[j].lLbound,
TLB_Read(& pTypeLibImpl->pTypeDesc[i].u.lpadesc->rgbounds[j].lLbound,
sizeof(INT), &cx, DO_NOT_SEEK);
}
}
else
{
V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lpadesc) = NULL;
pTypeLibImpl->pTypeDesc[i].u.lpadesc = NULL;
ERR("didn't find array description data\n");
}
}
......@@ -2940,10 +2936,10 @@ static HRESULT WINAPI ITypeInfo_fnInvoke(
for (i=0;i<pFDesc->funcdesc.cParams;i++) {
if (i<pDispParams->cArgs) {
TRACE("set %d to disparg type %d vs %d\n",i,
pDispParams->rgvarg[i].vt,
V_VT(pDispParams->rgvarg+i),
pFDesc->funcdesc.lprgelemdescParam[i].tdesc.vt
);
args[i+1] = pDispParams->rgvarg[i].u.lVal;
args[i+1] = V_UNION(pDispParams->rgvarg+i,lVal);
} else {
TYPEDESC *tdesc = &(pFDesc->funcdesc.lprgelemdescParam[i].tdesc);
TRACE("set %d to pointer for get (type is %d)\n",i,tdesc->vt);
......@@ -2978,11 +2974,11 @@ static HRESULT WINAPI ITypeInfo_fnInvoke(
continue;
VariantInit(&pVarResult[i]);
pVarResult[i].u.intVal = args2[i];
V_UNION(pVarResult+i,intVal) = args2[i];
if (tdesc->vt == VT_PTR)
tdesc = tdesc->u.lptdesc;
pVarResult[i].vt = tdesc->vt;
V_VT(pVarResult+i) = tdesc->vt;
/* HACK: VB5 likes this.
* I do not know why. There is 1 example in MSDN which uses
......@@ -2990,9 +2986,9 @@ static HRESULT WINAPI ITypeInfo_fnInvoke(
* IDispatch*.).
*/
if ((tdesc->vt == VT_PTR) && (dwFlags & DISPATCH_METHOD))
pVarResult[i].vt = VT_DISPATCH;
V_VT(pVarResult+i) = VT_DISPATCH;
TRACE("storing into variant: [%d] type %d, val %08x\n",
i,pVarResult[i].vt,pVarResult[i].u.intVal
i,V_VT(pVarResult+i),V_UNION(pVarResult+i,intVal)
);
}
}
......
......@@ -111,11 +111,11 @@ SafeArrayRedim(struct tagSAFEARRAY *psa, struct tagSAFEARRAYBOUND *psaboundNew);
/* These are macros that help accessing the VARIANT date type.
*/
#ifdef __cplusplus
#define V_UNION(A, B) ((A)->B)
#define V_VT(A) ((A)->vt)
#if (__STDC__ && !defined(_FORCENAMELESSUNION)) || defined(NONAMELESSUNION)
#define V_UNION(A, B) ((A)->n1.n2.n3.B)
#define V_VT(A) ((A)->n1.n2.vt)
#else
#define V_UNION(A, B) ((A)->u.B)
#define V_UNION(A, B) ((A)->B)
#define V_VT(A) ((A)->vt)
#endif /* cplusplus */
......
......@@ -114,67 +114,81 @@ typedef CY CURRENCY;
* * E_OUTOFMEMORY : Memory could not be allocated for the conversion.
* DISP_E_ARRAYISLOCKED : The variant contains an array that is locked.
*/
#if (__STDC__ && !defined(_FORCENAMELESSUNION)) || defined(NONAMELESSUNION)
#define __VARIANT_NAME_1 n1
#define __VARIANT_NAME_2 n2
#define __VARIANT_NAME_3 n3
#else
#define __tagVARIANT
#define __VARIANT_NAME_1
#define __VARIANT_NAME_2
#define __VARIANT_NAME_3
#endif
typedef struct tagVARIANT VARIANT, *LPVARIANT;
typedef struct tagVARIANT VARIANTARG, *LPVARIANTARG;
struct tagVARIANT {
VARTYPE vt;
WORD wReserved1;
WORD wReserved2;
WORD wReserved3;
union /* DUMMYUNIONNAME */
{
/* By value. */
CHAR cVal;
USHORT uiVal;
ULONG ulVal;
INT intVal;
UINT uintVal;
BYTE bVal;
short iVal;
long lVal;
float fltVal;
double dblVal;
VARIANT_BOOL boolVal;
SCODE scode;
DATE date;
BSTR bstrVal;
CY cyVal;
/* FIXME: This is not supposed to be at this level
* See bug #181 in bugzilla
* DECIMAL decVal;
*/
IUnknown* punkVal;
IDispatch* pdispVal;
SAFEARRAY* parray;
/* By reference */
CHAR* pcVal;
USHORT* puiVal;
ULONG* pulVal;
INT* pintVal;
UINT* puintVal;
BYTE* pbVal;
short* piVal;
long* plVal;
float* pfltVal;
double* pdblVal;
VARIANT_BOOL* pboolVal;
SCODE* pscode;
DATE* pdate;
BSTR* pbstrVal;
VARIANT* pvarVal;
PVOID byref;
CY* pcyVal;
DECIMAL* pdecVal;
IUnknown** ppunkVal;
IDispatch** ppdispVal;
SAFEARRAY** pparray;
} DUMMYUNIONNAME;
struct tagVARIANT
{
union
{
struct __tagVARIANT
{
VARTYPE vt;
WORD wReserved1;
WORD wReserved2;
WORD wReserved3;
union /* DUMMYUNIONNAME */
{
/* B y value. */
CHAR cVal;
USHORT uiVal;
ULONG ulVal;
INT intVal;
UINT uintVal;
BYTE bVal;
short iVal;
long lVal;
float fltVal;
double dblVal;
VARIANT_BOOL boolVal;
SCODE scode;
DATE date;
BSTR bstrVal;
CY cyVal;
IUnknown* punkVal;
IDispatch* pdispVal;
SAFEARRAY* parray;
/* By reference */
CHAR* pcVal;
USHORT* puiVal;
ULONG* pulVal;
INT* pintVal;
UINT* puintVal;
BYTE* pbVal;
short* piVal;
long* plVal;
float* pfltVal;
double* pdblVal;
VARIANT_BOOL* pboolVal;
SCODE* pscode;
DATE* pdate;
BSTR* pbstrVal;
VARIANT* pvarVal;
PVOID byref;
CY* pcyVal;
DECIMAL* pdecVal;
IUnknown** ppunkVal;
IDispatch** ppdispVal;
SAFEARRAY** pparray;
} __VARIANT_NAME_3;
} __VARIANT_NAME_2;
DECIMAL decVal;
} __VARIANT_NAME_1;
};
typedef LONG DISPID;
typedef DWORD HREFTYPE;
typedef DISPID MEMBERID;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment