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.
oldstable
Francois Gouget 2001-08-21 17:03:10 +00:00 committed by Alexandre Julliard
parent 05b6618ff3
commit 9947b68c3e
5 changed files with 332 additions and 322 deletions

View File

@ -1117,8 +1117,8 @@ static HRESULT WINAPI OLEPictureImpl_Invoke(
FIXME("(dispid: %ld):Stub\n",dispIdMember); FIXME("(dispid: %ld):Stub\n",dispIdMember);
VariantInit(pVarResult); VariantInit(pVarResult);
pVarResult->vt = VT_BOOL; V_VT(pVarResult) = VT_BOOL;
pVarResult->u.boolVal = FALSE; V_UNION(pVarResult,boolVal) = FALSE;
return S_OK; return S_OK;
} }

View File

@ -760,8 +760,8 @@ static void dump_Variant(VARIANT * pvar)
break; break;
} }
if (pvar->vt & VT_BYREF) if (V_VT(pvar) & VT_BYREF)
return dump_Variant(pvar->u.pvarVal); return dump_Variant(V_UNION(pvar,pvarVal));
} }
static void dump_DispParms(DISPPARAMS * pdp) static void dump_DispParms(DISPPARAMS * pdp)
@ -947,14 +947,14 @@ static void TLB_ReadValue( VARIANT * pVar, int offset, TLBContext *pcx )
TRACE_(typelib)("\n"); TRACE_(typelib)("\n");
if(offset <0) { /* data is packed in here */ 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; V_UNION(pVar, iVal) = offset & 0xffff;
return; return;
} }
TLB_Read(&(pVar->vt), sizeof(VARTYPE), pcx, TLB_Read(&(V_VT(pVar)), sizeof(VARTYPE), pcx,
pcx->pTblDir->pCustData.offset + offset ); pcx->pTblDir->pCustData.offset + offset );
TRACE_(typelib)("Vartype = %x\n", pVar->vt); TRACE_(typelib)("Vartype = %x\n", V_VT(pVar));
switch(pVar->vt){ switch (V_VT(pVar)){
case VT_EMPTY: /* FIXME: is this right? */ case VT_EMPTY: /* FIXME: is this right? */
case VT_NULL: /* FIXME: is this right? */ case VT_NULL: /* FIXME: is this right? */
case VT_I2 : /* this should not happen */ case VT_I2 : /* this should not happen */
@ -1017,7 +1017,7 @@ static void TLB_ReadValue( VARIANT * pVar, int offset, TLBContext *pcx )
default: default:
size=0; size=0;
FIXME("VARTYPE %d is not supported, setting pointer to NULL\n", FIXME("VARTYPE %d is not supported, setting pointer to NULL\n",
pVar->vt); V_VT(pVar));
} }
if(size>0) /* (big|small) endian correct? */ if(size>0) /* (big|small) endian correct? */
@ -1203,8 +1203,7 @@ TLB_DoFuncs(TLBContext* pcx,
paraminfo.DataType, paraminfo.DataType,
&(*pptfd)->funcdesc.lprgelemdescParam[j].tdesc) ; &(*pptfd)->funcdesc.lprgelemdescParam[j].tdesc) ;
V_UNION(& ((*pptfd)->funcdesc.lprgelemdescParam[j]), (*pptfd)->funcdesc.lprgelemdescParam[j].u.paramdesc.wParamFlags = paraminfo.Flags;
paramdesc.wParamFlags) = paraminfo.Flags;
(*pptfd)->pParamDesc[j].Name = (void *) paraminfo.oName; (*pptfd)->pParamDesc[j].Name = (void *) paraminfo.oName;
@ -1298,21 +1297,18 @@ TLB_DoFuncs(TLBContext* pcx,
/* default value */ /* default value */
if ( (PARAMFLAG_FHASDEFAULT & if ( (PARAMFLAG_FHASDEFAULT &
V_UNION(&((*pptfd)->funcdesc.lprgelemdescParam[j]), (*pptfd)->funcdesc.lprgelemdescParam[j].u.paramdesc.wParamFlags) &&
paramdesc.wParamFlags)) &&
((pFuncRec->FKCCIC) & 0x1000) ) ((pFuncRec->FKCCIC) & 0x1000) )
{ {
INT* pInt = (INT *)((char *)pFuncRec + INT* pInt = (INT *)((char *)pFuncRec +
reclength - reclength -
(pFuncRec->nrargs * 4 + 1) * sizeof(INT) ); (pFuncRec->nrargs * 4 + 1) * sizeof(INT) );
PARAMDESC* pParamDesc = &V_UNION( PARAMDESC* pParamDesc = & (*pptfd)->funcdesc.lprgelemdescParam[j].u.paramdesc;
& ((*pptfd)->funcdesc.lprgelemdescParam[j]),
paramdesc);
pParamDesc->pparamdescex = TLB_Alloc(sizeof(PARAMDESCEX)); pParamDesc->pparamdescex = TLB_Alloc(sizeof(PARAMDESCEX));
pParamDesc->pparamdescex->cBytes = sizeof(PARAMDESCEX); pParamDesc->pparamdescex->cBytes = sizeof(PARAMDESCEX);
TLB_ReadValue(&(pParamDesc->pparamdescex->varDefaultValue), TLB_ReadValue(&(pParamDesc->pparamdescex->varDefaultValue),
pInt[j], pcx); pInt[j], pcx);
} }
@ -1325,11 +1321,11 @@ TLB_DoFuncs(TLBContext* pcx,
} }
} }
} }
/* scode is not used: archaic win16 stuff FIXME: right? */ /* scode is not used: archaic win16 stuff FIXME: right? */
(*pptfd)->funcdesc.cScodes = 0 ; (*pptfd)->funcdesc.cScodes = 0 ;
(*pptfd)->funcdesc.lprgscode = NULL ; (*pptfd)->funcdesc.lprgscode = NULL ;
pptfd = & ((*pptfd)->next); pptfd = & ((*pptfd)->next);
recoffset += reclength; recoffset += reclength;
} }
@ -1376,11 +1372,11 @@ static void TLB_DoVars(TLBContext *pcx, int cFuncs, int cVars,
&(*pptvd)->vardesc.elemdescVar.tdesc) ; &(*pptvd)->vardesc.elemdescVar.tdesc) ;
/* (*pptvd)->vardesc.lpstrSchema; is reserved (SDK) fixme?? */ /* (*pptvd)->vardesc.lpstrSchema; is reserved (SDK) fixme?? */
if(pVarRec->VarKind == VAR_CONST ){ if(pVarRec->VarKind == VAR_CONST ){
V_UNION(&((*pptvd)->vardesc),lpvarValue)=TLB_Alloc(sizeof(VARIANT)); (*pptvd)->vardesc.u.lpvarValue=TLB_Alloc(sizeof(VARIANT));
TLB_ReadValue(V_UNION(&((*pptvd)->vardesc),lpvarValue), TLB_ReadValue((*pptvd)->vardesc.u.lpvarValue,
pVarRec->OffsValue, pcx); pVarRec->OffsValue, pcx);
}else } else
V_UNION(&((*pptvd)->vardesc),oInst)=pVarRec->OffsValue; (*pptvd)->vardesc.u.oInst=pVarRec->OffsValue;
pptvd=&((*pptvd)->next); pptvd=&((*pptvd)->next);
recoffset += reclength; recoffset += reclength;
} }
@ -1805,18 +1801,18 @@ static ITypeLib2* ITypeLib2_Constructor(LPVOID pLib, DWORD dwTLBLength)
{ {
/* FIXME: check safearray */ /* FIXME: check safearray */
if(td[3] < 0) if(td[3] < 0)
V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lptdesc)= & stndTypeDesc[td[2]]; pTypeLibImpl->pTypeDesc[i].u.lptdesc= & stndTypeDesc[td[2]];
else 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) else if(td[0] == VT_CARRAY)
{ {
/* array descr table here */ /* 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) 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); 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(pTypeLibImpl->pTypeDesc[i].vt != VT_CARRAY) continue;
if(tlbSegDir.pArrayDescriptions.offset>0) if(tlbSegDir.pArrayDescriptions.offset>0)
{ {
TLB_Read(td, sizeof(td), &cx, tlbSegDir.pArrayDescriptions.offset + (int) V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lpadesc)); TLB_Read(td, sizeof(td), &cx, tlbSegDir.pArrayDescriptions.offset + (int) pTypeLibImpl->pTypeDesc[i].u.lpadesc);
V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lpadesc) = TLB_Alloc(sizeof(ARRAYDESC)+sizeof(SAFEARRAYBOUND)*(td[3]-1)); pTypeLibImpl->pTypeDesc[i].u.lpadesc = TLB_Alloc(sizeof(ARRAYDESC)+sizeof(SAFEARRAYBOUND)*(td[3]-1));
if(td[1]<0) 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 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++) 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); 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); sizeof(INT), &cx, DO_NOT_SEEK);
} }
} }
else else
{ {
V_UNION(&(pTypeLibImpl->pTypeDesc[i]),lpadesc) = NULL; pTypeLibImpl->pTypeDesc[i].u.lpadesc = NULL;
ERR("didn't find array description data\n"); 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++) { for (i=0;i<pFDesc->funcdesc.cParams;i++) {
if (i<pDispParams->cArgs) { if (i<pDispParams->cArgs) {
TRACE("set %d to disparg type %d vs %d\n",i, 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 pFDesc->funcdesc.lprgelemdescParam[i].tdesc.vt
); );
args[i+1] = pDispParams->rgvarg[i].u.lVal; args[i+1] = V_UNION(pDispParams->rgvarg+i,lVal);
} else { } else {
TYPEDESC *tdesc = &(pFDesc->funcdesc.lprgelemdescParam[i].tdesc); TYPEDESC *tdesc = &(pFDesc->funcdesc.lprgelemdescParam[i].tdesc);
TRACE("set %d to pointer for get (type is %d)\n",i,tdesc->vt); TRACE("set %d to pointer for get (type is %d)\n",i,tdesc->vt);
@ -2978,11 +2974,11 @@ static HRESULT WINAPI ITypeInfo_fnInvoke(
continue; continue;
VariantInit(&pVarResult[i]); VariantInit(&pVarResult[i]);
pVarResult[i].u.intVal = args2[i]; V_UNION(pVarResult+i,intVal) = args2[i];
if (tdesc->vt == VT_PTR) if (tdesc->vt == VT_PTR)
tdesc = tdesc->u.lptdesc; tdesc = tdesc->u.lptdesc;
pVarResult[i].vt = tdesc->vt; V_VT(pVarResult+i) = tdesc->vt;
/* HACK: VB5 likes this. /* HACK: VB5 likes this.
* I do not know why. There is 1 example in MSDN which uses * I do not know why. There is 1 example in MSDN which uses
@ -2990,9 +2986,9 @@ static HRESULT WINAPI ITypeInfo_fnInvoke(
* IDispatch*.). * IDispatch*.).
*/ */
if ((tdesc->vt == VT_PTR) && (dwFlags & DISPATCH_METHOD)) 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", 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)
); );
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -111,11 +111,11 @@ SafeArrayRedim(struct tagSAFEARRAY *psa, struct tagSAFEARRAYBOUND *psaboundNew);
/* These are macros that help accessing the VARIANT date type. /* These are macros that help accessing the VARIANT date type.
*/ */
#ifdef __cplusplus #if (__STDC__ && !defined(_FORCENAMELESSUNION)) || defined(NONAMELESSUNION)
#define V_UNION(A, B) ((A)->B) #define V_UNION(A, B) ((A)->n1.n2.n3.B)
#define V_VT(A) ((A)->vt) #define V_VT(A) ((A)->n1.n2.vt)
#else #else
#define V_UNION(A, B) ((A)->u.B) #define V_UNION(A, B) ((A)->B)
#define V_VT(A) ((A)->vt) #define V_VT(A) ((A)->vt)
#endif /* cplusplus */ #endif /* cplusplus */

View File

@ -114,67 +114,81 @@ typedef CY CURRENCY;
* * E_OUTOFMEMORY : Memory could not be allocated for the conversion. * * E_OUTOFMEMORY : Memory could not be allocated for the conversion.
* DISP_E_ARRAYISLOCKED : The variant contains an array that is locked. * 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 VARIANT, *LPVARIANT;
typedef struct tagVARIANT VARIANTARG, *LPVARIANTARG; typedef struct tagVARIANT VARIANTARG, *LPVARIANTARG;
struct tagVARIANT { struct tagVARIANT
VARTYPE vt; {
WORD wReserved1; union
WORD wReserved2; {
WORD wReserved3; struct __tagVARIANT
union /* DUMMYUNIONNAME */ {
{ VARTYPE vt;
/* By value. */ WORD wReserved1;
CHAR cVal; WORD wReserved2;
USHORT uiVal; WORD wReserved3;
ULONG ulVal; union /* DUMMYUNIONNAME */
INT intVal; {
UINT uintVal; /* B y value. */
BYTE bVal; CHAR cVal;
short iVal; USHORT uiVal;
long lVal; ULONG ulVal;
float fltVal; INT intVal;
double dblVal; UINT uintVal;
VARIANT_BOOL boolVal; BYTE bVal;
SCODE scode; short iVal;
DATE date; long lVal;
BSTR bstrVal; float fltVal;
CY cyVal; double dblVal;
/* FIXME: This is not supposed to be at this level VARIANT_BOOL boolVal;
* See bug #181 in bugzilla SCODE scode;
* DECIMAL decVal; DATE date;
*/ BSTR bstrVal;
IUnknown* punkVal; CY cyVal;
IDispatch* pdispVal; IUnknown* punkVal;
SAFEARRAY* parray; IDispatch* pdispVal;
SAFEARRAY* parray;
/* By reference */ /* By reference */
CHAR* pcVal; CHAR* pcVal;
USHORT* puiVal; USHORT* puiVal;
ULONG* pulVal; ULONG* pulVal;
INT* pintVal; INT* pintVal;
UINT* puintVal; UINT* puintVal;
BYTE* pbVal; BYTE* pbVal;
short* piVal; short* piVal;
long* plVal; long* plVal;
float* pfltVal; float* pfltVal;
double* pdblVal; double* pdblVal;
VARIANT_BOOL* pboolVal; VARIANT_BOOL* pboolVal;
SCODE* pscode; SCODE* pscode;
DATE* pdate; DATE* pdate;
BSTR* pbstrVal; BSTR* pbstrVal;
VARIANT* pvarVal; VARIANT* pvarVal;
PVOID byref; PVOID byref;
CY* pcyVal; CY* pcyVal;
DECIMAL* pdecVal; DECIMAL* pdecVal;
IUnknown** ppunkVal; IUnknown** ppunkVal;
IDispatch** ppdispVal; IDispatch** ppdispVal;
SAFEARRAY** pparray; SAFEARRAY** pparray;
} DUMMYUNIONNAME; } __VARIANT_NAME_3;
} __VARIANT_NAME_2;
DECIMAL decVal;
} __VARIANT_NAME_1;
}; };
typedef LONG DISPID; typedef LONG DISPID;
typedef DWORD HREFTYPE; typedef DWORD HREFTYPE;
typedef DISPID MEMBERID; typedef DISPID MEMBERID;