Handle VT_ERROR->VT_I4/VT_R4 coercion.
VariantCopy does not need to check the return of VariantClear. VariantCopyInd now copies VT_UNKNOWN and VT_DISPATCH too. VarCmp handles VT_BOOL. VarFormat handles VT_BSTR. coerce_array fixed for VT_ARRAY|VT_UI1 -> VT_BSTR and VT_ARRAY|x -> VT_SAFEARRAY cases. VarCat tries to coerce types into VT_BSTR to do cat.
This commit is contained in:
parent
4beaa06e9d
commit
48e583db52
|
@ -1164,6 +1164,11 @@ static HRESULT Coerce( VARIANTARG* pd, LCID lcid, ULONG dwFlags, VARIANTARG* ps,
|
||||||
break;
|
break;
|
||||||
case( VT_I2 ):
|
case( VT_I2 ):
|
||||||
res = VarI4FromI2( V_UNION(ps,iVal), &V_UNION(pd,lVal) );
|
res = VarI4FromI2( V_UNION(ps,iVal), &V_UNION(pd,lVal) );
|
||||||
|
|
||||||
|
break;
|
||||||
|
case( VT_ERROR ):
|
||||||
|
V_UNION(pd,lVal) = V_UNION(pd,scode);
|
||||||
|
res = S_OK;
|
||||||
break;
|
break;
|
||||||
case( VT_INT ):
|
case( VT_INT ):
|
||||||
case( VT_I4 ):
|
case( VT_I4 ):
|
||||||
|
@ -1409,6 +1414,10 @@ static HRESULT Coerce( VARIANTARG* pd, LCID lcid, ULONG dwFlags, VARIANTARG* ps,
|
||||||
case( VT_CY ):
|
case( VT_CY ):
|
||||||
res = VarR4FromCy( V_UNION(ps,cyVal), &V_UNION(pd,fltVal) );
|
res = VarR4FromCy( V_UNION(ps,cyVal), &V_UNION(pd,fltVal) );
|
||||||
break;
|
break;
|
||||||
|
case( VT_ERROR ):
|
||||||
|
V_UNION(pd,fltVal) = V_UNION(ps,scode);
|
||||||
|
res = S_OK;
|
||||||
|
break;
|
||||||
case( VT_DISPATCH ):
|
case( VT_DISPATCH ):
|
||||||
/*res = VarR4FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,fltVal) );*/
|
/*res = VarR4FromDisp( V_UNION(ps,pdispVal), lcid, &V_UNION(pd,fltVal) );*/
|
||||||
case( VT_DECIMAL ):
|
case( VT_DECIMAL ):
|
||||||
|
@ -1919,10 +1928,8 @@ HRESULT WINAPI VariantCopy(VARIANTARG* pvargDest, VARIANTARG* pvargSrc)
|
||||||
*/
|
*/
|
||||||
if( pvargDest != pvargSrc && res == S_OK )
|
if( pvargDest != pvargSrc && res == S_OK )
|
||||||
{
|
{
|
||||||
res = VariantClear( pvargDest );
|
VariantClear( pvargDest ); /* result is not checked */
|
||||||
|
|
||||||
if( res == S_OK )
|
|
||||||
{
|
|
||||||
if( V_VT(pvargSrc) & VT_BYREF )
|
if( V_VT(pvargSrc) & VT_BYREF )
|
||||||
{
|
{
|
||||||
/* In the case of byreference we only need
|
/* In the case of byreference we only need
|
||||||
|
@ -1974,9 +1981,8 @@ HRESULT WINAPI VariantCopy(VARIANTARG* pvargDest, VARIANTARG* pvargSrc)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
V_VT(pvargDest) = V_VT(pvargSrc);
|
V_VT(pvargDest) = V_VT(pvargSrc);
|
||||||
}
|
dump_Variant(pvargDest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2043,6 +2049,9 @@ HRESULT WINAPI VariantCopyInd(VARIANT* pvargDest, VARIANTARG* pvargSrc)
|
||||||
V_UNION(pvargDest,bstrVal) = SYSDUPSTRING( *(V_UNION(pvargSrc,pbstrVal)) );
|
V_UNION(pvargDest,bstrVal) = SYSDUPSTRING( *(V_UNION(pvargSrc,pbstrVal)) );
|
||||||
break;
|
break;
|
||||||
case( VT_DISPATCH ):
|
case( VT_DISPATCH ):
|
||||||
|
V_UNION(pvargDest,pdispVal) = *V_UNION(pvargSrc,ppdispVal);
|
||||||
|
if (V_UNION(pvargDest,pdispVal)!=NULL)
|
||||||
|
ICOM_CALL(AddRef,V_UNION(pvargDest,pdispVal));
|
||||||
break;
|
break;
|
||||||
case( VT_VARIANT ):
|
case( VT_VARIANT ):
|
||||||
{
|
{
|
||||||
|
@ -2079,6 +2088,9 @@ HRESULT WINAPI VariantCopyInd(VARIANT* pvargDest, VARIANTARG* pvargSrc)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case( VT_UNKNOWN ):
|
case( VT_UNKNOWN ):
|
||||||
|
V_UNION(pvargDest,punkVal) = *V_UNION(pvargSrc,ppunkVal);
|
||||||
|
if (V_UNION(pvargDest,pdispVal)!=NULL)
|
||||||
|
ICOM_CALL(AddRef,V_UNION(pvargDest,punkVal));
|
||||||
break;
|
break;
|
||||||
case( VT_SAFEARRAY ):
|
case( VT_SAFEARRAY ):
|
||||||
SafeArrayCopy(*V_UNION(pvargSrc,pparray), &V_UNION(pvargDest,parray));
|
SafeArrayCopy(*V_UNION(pvargSrc,pparray), &V_UNION(pvargDest,parray));
|
||||||
|
@ -2118,53 +2130,42 @@ HRESULT WINAPI VariantCopyInd(VARIANT* pvargDest, VARIANTARG* pvargSrc)
|
||||||
*/
|
*/
|
||||||
static HRESULT
|
static HRESULT
|
||||||
coerce_array(
|
coerce_array(
|
||||||
VARIANTARG* src, SAFEARRAY **narr, LCID lcid, USHORT wFlags, VARTYPE vt
|
VARIANTARG* src, VARIANTARG *dst, LCID lcid, USHORT wFlags, VARTYPE vt
|
||||||
) {
|
) {
|
||||||
int elems,i,j;
|
SAFEARRAY *sarr = V_ARRAY(src);
|
||||||
SAFEARRAY *darr, *sarr = V_ARRAY(src);
|
|
||||||
long *addr;
|
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
LPVOID data;
|
||||||
|
VARTYPE vartype;
|
||||||
|
|
||||||
hres = SafeArrayAllocDescriptor( sarr->cDims, &darr);
|
SafeArrayGetVartype(sarr,&vartype);
|
||||||
|
switch (vt) {
|
||||||
|
case VT_BSTR:
|
||||||
|
if (sarr->cDims != 1) {
|
||||||
|
FIXME("Can not coerce array with dim %d into BSTR\n", sarr->cDims);
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
switch (V_VT(src) & VT_TYPEMASK) {
|
||||||
|
case VT_UI1:
|
||||||
|
hres = SafeArrayAccessData(sarr, &data);
|
||||||
if (FAILED(hres)) return hres;
|
if (FAILED(hres)) return hres;
|
||||||
memcpy(
|
|
||||||
darr->rgsabound,
|
/* Yes, just memcpied apparently. */
|
||||||
sarr->rgsabound,
|
V_BSTR(dst) = SysAllocStringByteLen(data, sarr->rgsabound[0].cElements);
|
||||||
sizeof(sarr->rgsabound[0])*sarr->cDims
|
hres = SafeArrayUnaccessData(sarr);
|
||||||
);
|
if (FAILED(hres)) return hres;
|
||||||
hres = SafeArrayAllocData(darr);
|
break;
|
||||||
if (FAILED(hres)) {
|
default:
|
||||||
SafeArrayDestroyDescriptor(darr);
|
FIXME("Cannot coerce array of %d into BSTR yet. Please report!\n", V_VT(src) & VT_TYPEMASK);
|
||||||
return hres;
|
|
||||||
}
|
|
||||||
elems = 1;
|
|
||||||
for (i=0;i<sarr->cDims;i++)
|
|
||||||
elems *= sarr->rgsabound[i].cElements;
|
|
||||||
addr = HeapAlloc(GetProcessHeap(),0,sizeof(long)*sarr->cDims);
|
|
||||||
for (i=0;i<elems;i++) {
|
|
||||||
VARIANT tmpvar,newvar;
|
|
||||||
int tmpi = i;
|
|
||||||
/* convert absolute value in array address */
|
|
||||||
for (j=0;j<sarr->cDims;j++) {
|
|
||||||
addr[j] = (tmpi % sarr->rgsabound[j].cElements) + sarr->rgsabound[j].lLbound;
|
|
||||||
tmpi /= sarr->rgsabound[j].cElements;
|
|
||||||
}
|
|
||||||
V_VT(&tmpvar) = V_VT(src) & VT_TYPEMASK;
|
|
||||||
hres = SafeArrayGetElement(sarr, addr, &V_UNION(&tmpvar,lVal));
|
|
||||||
if (FAILED(hres)) {
|
|
||||||
FIXME("Did not get element %d\n",i);
|
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
hres = Coerce( &newvar, lcid, wFlags, &tmpvar, vt );
|
break;
|
||||||
if (FAILED(hres)) return E_FAIL;
|
case VT_SAFEARRAY:
|
||||||
hres = SafeArrayPutElement( darr, addr, &V_UNION(&newvar,lVal));
|
V_VT(dst) = VT_SAFEARRAY;
|
||||||
if (FAILED(hres)) {
|
return SafeArrayCopy(sarr, &V_ARRAY(dst));
|
||||||
FIXME("SAPE failed for element %d, %lx\n",i,hres);
|
default:
|
||||||
|
FIXME("Cannot coerce array of vt 0x%x/0x%x into vt 0x%x yet. Please report/implement!\n", vartype, V_VT(src), vt);
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
HeapFree(GetProcessHeap(),0,addr);
|
|
||||||
*narr = darr;
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2239,7 +2240,6 @@ HRESULT WINAPI VariantChangeTypeEx(VARIANTARG* pvargDest, VARIANTARG* pvargSrc,
|
||||||
*/
|
*/
|
||||||
VariantClear( &Variant );
|
VariantClear( &Variant );
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (V_VT(pvargSrc) & VT_ARRAY) {
|
if (V_VT(pvargSrc) & VT_ARRAY) {
|
||||||
if ((V_VT(pvargSrc) & 0xf000) != VT_ARRAY) {
|
if ((V_VT(pvargSrc) & 0xf000) != VT_ARRAY) {
|
||||||
|
@ -2247,7 +2247,7 @@ HRESULT WINAPI VariantChangeTypeEx(VARIANTARG* pvargDest, VARIANTARG* pvargSrc,
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
V_VT(pvargDest) = VT_ARRAY | vt;
|
V_VT(pvargDest) = VT_ARRAY | vt;
|
||||||
res = coerce_array(pvargSrc, &V_ARRAY(pvargDest), lcid, wFlags, vt);
|
res = coerce_array(pvargSrc, pvargDest, lcid, wFlags, vt);
|
||||||
} else {
|
} else {
|
||||||
if ((V_VT(pvargSrc) & 0xf000)) {
|
if ((V_VT(pvargSrc) & 0xf000)) {
|
||||||
FIXME("VT_TYPEMASK %x is unhandled in normal case.\n",V_VT(pvargSrc) & VT_TYPEMASK);
|
FIXME("VT_TYPEMASK %x is unhandled in normal case.\n",V_VT(pvargSrc) & VT_TYPEMASK);
|
||||||
|
@ -5022,14 +5022,40 @@ HRESULT WINAPI VarCat(LPVARIANT left, LPVARIANT right, LPVARIANT out)
|
||||||
V_VT(out) = VT_NULL;
|
V_VT(out) = VT_NULL;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
else if (V_VT(left) == VT_BSTR && V_VT(right) == VT_BSTR)
|
|
||||||
|
if (V_VT(left) == VT_BSTR && V_VT(right) == VT_BSTR)
|
||||||
{
|
{
|
||||||
V_VT(out) = VT_BSTR;
|
V_VT(out) = VT_BSTR;
|
||||||
VarBstrCat (V_BSTR(left), V_BSTR(right), &V_BSTR(out));
|
VarBstrCat (V_BSTR(left), V_BSTR(right), &V_BSTR(out));
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
else
|
if (V_VT(left) == VT_BSTR) {
|
||||||
FIXME ("types not supported\n");
|
VARIANT bstrvar;
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
V_VT(out) = VT_BSTR;
|
||||||
|
hres = VariantChangeTypeEx(&bstrvar,right,0,0,VT_BSTR);
|
||||||
|
if (hres) {
|
||||||
|
FIXME("Failed to convert right side from vt %d to VT_BSTR?\n",V_VT(right));
|
||||||
|
return hres;
|
||||||
|
}
|
||||||
|
VarBstrCat (V_BSTR(left), V_BSTR(&bstrvar), &V_BSTR(out));
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
if (V_VT(right) == VT_BSTR) {
|
||||||
|
VARIANT bstrvar;
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
V_VT(out) = VT_BSTR;
|
||||||
|
hres = VariantChangeTypeEx(&bstrvar,left,0,0,VT_BSTR);
|
||||||
|
if (hres) {
|
||||||
|
FIXME("Failed to convert right side from vt %d to VT_BSTR?\n",V_VT(right));
|
||||||
|
return hres;
|
||||||
|
}
|
||||||
|
VarBstrCat (V_BSTR(&bstrvar), V_BSTR(right), &V_BSTR(out));
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
FIXME ("types %d / %d not supported\n",V_VT(left)&VT_TYPEMASK, V_VT(right)&VT_TYPEMASK);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5078,6 +5104,7 @@ HRESULT WINAPI VarCmp(LPVARIANT left, LPVARIANT right, LCID lcid, DWORD flags)
|
||||||
case VT_UI2 : lVal = V_UNION(left,uiVal); break;
|
case VT_UI2 : lVal = V_UNION(left,uiVal); break;
|
||||||
case VT_UI4 : lVal = V_UNION(left,ulVal); break;
|
case VT_UI4 : lVal = V_UNION(left,ulVal); break;
|
||||||
case VT_UINT : lVal = V_UNION(left,ulVal); break;
|
case VT_UINT : lVal = V_UNION(left,ulVal); break;
|
||||||
|
case VT_BOOL : lVal = V_UNION(left,boolVal); break;
|
||||||
default: lOk = FALSE;
|
default: lOk = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5091,6 +5118,7 @@ HRESULT WINAPI VarCmp(LPVARIANT left, LPVARIANT right, LCID lcid, DWORD flags)
|
||||||
case VT_UI2 : rVal = V_UNION(right,uiVal); break;
|
case VT_UI2 : rVal = V_UNION(right,uiVal); break;
|
||||||
case VT_UI4 : rVal = V_UNION(right,ulVal); break;
|
case VT_UI4 : rVal = V_UNION(right,ulVal); break;
|
||||||
case VT_UINT : rVal = V_UNION(right,ulVal); break;
|
case VT_UINT : rVal = V_UNION(right,ulVal); break;
|
||||||
|
case VT_BOOL : rVal = V_UNION(right,boolVal); break;
|
||||||
default: rOk = FALSE;
|
default: rOk = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5139,7 +5167,7 @@ HRESULT WINAPI VarCmp(LPVARIANT left, LPVARIANT right, LCID lcid, DWORD flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FIXME("VarCmp partial implementation, doesnt support these pair of variant types");
|
FIXME("VarCmp partial implementation, doesnt support vt 0x%x / 0x%x\n",V_VT(left), V_VT(right));
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5824,13 +5852,18 @@ HRESULT WINAPI VarFormat(LPVARIANT varIn, LPOLESTR format,
|
||||||
|
|
||||||
} else if ((V_VT(varIn)&VT_TYPEMASK) == VT_R8) {
|
} else if ((V_VT(varIn)&VT_TYPEMASK) == VT_R8) {
|
||||||
if (V_VT(varIn)&VT_BYREF) {
|
if (V_VT(varIn)&VT_BYREF) {
|
||||||
sprintf(pBuffer, "%f", *(double *)V_UNION(varIn,byref));
|
sprintf(pBuffer, "%f", *V_UNION(varIn,pdblVal));
|
||||||
} else {
|
} else {
|
||||||
sprintf(pBuffer, "%f", V_UNION(varIn,dblVal));
|
sprintf(pBuffer, "%f", V_UNION(varIn,dblVal));
|
||||||
}
|
}
|
||||||
|
|
||||||
*pbstrOut = StringDupAtoBstr( pBuffer );
|
*pbstrOut = StringDupAtoBstr( pBuffer );
|
||||||
|
|
||||||
|
} else if ((V_VT(varIn)&VT_TYPEMASK) == VT_BSTR) {
|
||||||
|
if (V_VT(varIn)&VT_BYREF)
|
||||||
|
*pbstrOut = SysAllocString( *V_UNION(varIn,pbstrVal) );
|
||||||
|
else
|
||||||
|
*pbstrOut = SysAllocString( V_UNION(varIn,bstrVal) );
|
||||||
} else {
|
} else {
|
||||||
FIXME("VarFormat: Unsupported format %d!\n", V_VT(varIn)&VT_TYPEMASK);
|
FIXME("VarFormat: Unsupported format %d!\n", V_VT(varIn)&VT_TYPEMASK);
|
||||||
*pbstrOut = StringDupAtoBstr( "??" );
|
*pbstrOut = StringDupAtoBstr( "??" );
|
||||||
|
|
Loading…
Reference in New Issue