static unsigned long wire_extra_user_size(unsigned long *pFlags, unsigned long Start, VARIANT *pvar) { if (V_ISARRAY(pvar)) { if (V_ISBYREF(pvar)) return LPSAFEARRAY_UserSize(pFlags, Start, V_ARRAYREF(pvar)); else return LPSAFEARRAY_UserSize(pFlags, Start, &V_ARRAY(pvar)); } switch (V_VT(pvar)) { case VT_BSTR: return BSTR_UserSize(pFlags, Start, &V_BSTR(pvar)); case VT_BSTR | VT_BYREF: return BSTR_UserSize(pFlags, Start, V_BSTRREF(pvar)); case VT_VARIANT | VT_BYREF: return VARIANT_UserSize(pFlags, Start, V_VARIANTREF(pvar)); case VT_UNKNOWN: return Start + interface_variant_size(pFlags, &IID_IUnknown, pvar); case VT_DISPATCH: return Start + interface_variant_size(pFlags, &IID_IDispatch, pvar); case VT_RECORD: FIXME("wire-size record\n"); return Start; case VT_SAFEARRAY: case VT_SAFEARRAY | VT_BYREF: FIXME("wire-size safearray: shouldn't be marshaling this\n"); return Start; default: return Start; } }
const char *debugstr_variant(const VARIANT *v) { if(!v) return "(null)"; if(V_ISBYREF(v)) return wine_dbg_sprintf("{V_BYREF -> %s}", debugstr_variant(V_BYREF(v))); switch(V_VT(v)) { case VT_EMPTY: return "{VT_EMPTY}"; case VT_NULL: return "{VT_NULL}"; case VT_I2: return wine_dbg_sprintf("{VT_I2: %d}", V_I2(v)); case VT_I4: return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v)); case VT_UI4: return wine_dbg_sprintf("{VT_UI4: %u}", V_UI4(v)); case VT_R8: return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v)); case VT_BSTR: return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v))); case VT_DISPATCH: return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v)); case VT_BOOL: return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v)); default: return wine_dbg_sprintf("{vt %d}", V_VT(v)); } }
//+--------------------------------------------------------------------------- // // Function: CVarToVARIANTARG // // Synopsis: Converts a C-language variable to a VARIANT. // // Arguments: [pv] -- Pointer to C-language variable. // [vt] -- Type of C-language variable. // [pvarg] -- Resulting VARIANT. Must be initialized by caller. // Any contents will be freed. // // Modifies: [pvarg] // // History: 2-23-94 adams Created // // Notes: Supports all variant pointer types, VT_UI2, VT_I2, VT_UI4, // VT_I4, VT_R4, VT_R8, VT_ERROR. // //---------------------------------------------------------------------------- void CVarToVARIANTARG(void* pv, VARTYPE vt, VARIANTARG* pvarg) { Assert(pv); Assert(pvarg); VariantClear(pvarg); V_VT(pvarg) = vt; if(V_ISBYREF(pvarg)) { // Use a supported pointer type for derefencing. vt = VT_UNKNOWN; } switch(vt) { case VT_BOOL: // convert TRUE to VT_TRUE Assert(*(BOOL*)pv==1 || *(BOOL*)pv==0); V_BOOL(pvarg) = VARIANT_BOOL(-*(BOOL*)pv); break; case VT_I2: V_I2(pvarg) = *(short*)pv; break; case VT_ERROR: case VT_I4: V_I4(pvarg) = *(long*)pv; break; case VT_R4: V_R4(pvarg) = *(float*)pv; break; case VT_R8: V_R8(pvarg) = *(double*)pv; break; case VT_CY: V_CY(pvarg) = *(CY*)pv; break; // All Pointer types. case VT_PTR: case VT_BSTR: case VT_LPSTR: case VT_LPWSTR: case VT_DISPATCH: case VT_UNKNOWN: V_BYREF(pvarg) = *(void**)pv; break; default: Assert(FALSE && "Unknown type."); break; } }
// oleauto.h:#define V_VT(X) ((X)->vt) // oleauto.h:#define V_ISBYREF(X) (V_VT(X)&VT_BYREF) IDispatch *Variant2Dispatch(VARIANT *pVariant){ IDispatch *pDispatch; if (V_ISBYREF(pVariant)) pDispatch = *V_DISPATCHREF(pVariant); else pDispatch = V_DISPATCH(pVariant); return pDispatch; }
/* Get the number of dimensions. For each of these dimensions, get the lower and upper bound and iterate over the elements. */ static SEXP convertArrayToR(const VARIANT *var) { SAFEARRAY *arr; SEXP ans; UINT dim; if(V_ISBYREF(var)) arr = *V_ARRAYREF(var); else arr = V_ARRAY(var); dim = SafeArrayGetDim(arr); long *indices = (long*) S_alloc(dim, sizeof(long)); // new long[dim]; ans = getArray(arr, dim, dim, indices); return(ans); }
static SAFEARRAY * get_locked_safe_array(VALUE val) { struct olevariantdata *pvar; SAFEARRAY *psa = NULL; HRESULT hr; TypedData_Get_Struct(val, struct olevariantdata, &olevariant_datatype, pvar); if (!(V_VT(&(pvar->var)) & VT_ARRAY)) { rb_raise(rb_eTypeError, "variant type is not VT_ARRAY."); } psa = V_ISBYREF(&(pvar->var)) ? *V_ARRAYREF(&(pvar->var)) : V_ARRAY(&(pvar->var)); if (psa == NULL) { return psa; } hr = SafeArrayLock(psa); if (FAILED(hr)) { ole_raise(hr, rb_eRuntimeError, "failed to SafeArrayLock"); } return psa; }
HRESULT CALLBACK IDispatch_Invoke_Proxy( IDispatch* This, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) { HRESULT hr; VARIANT VarResult; UINT* rgVarRefIdx = NULL; VARIANTARG* rgVarRef = NULL; UINT u, cVarRef; UINT uArgErr; EXCEPINFO ExcepInfo; TRACE("(%p)->(%ld,%s,%lx,%x,%p,%p,%p,%p)\n", This, dispIdMember, debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); /* [out] args can't be null, use dummy vars if needed */ if (!pVarResult) pVarResult = &VarResult; if (!puArgErr) puArgErr = &uArgErr; if (!pExcepInfo) pExcepInfo = &ExcepInfo; /* count by-ref args */ for (cVarRef=0,u=0; u<pDispParams->cArgs; u++) { VARIANTARG* arg = &pDispParams->rgvarg[u]; if (V_ISBYREF(arg)) { cVarRef++; } } if (cVarRef) { rgVarRefIdx = CoTaskMemAlloc(sizeof(UINT)*cVarRef); rgVarRef = CoTaskMemAlloc(sizeof(VARIANTARG)*cVarRef); /* make list of by-ref args */ for (cVarRef=0,u=0; u<pDispParams->cArgs; u++) { VARIANTARG* arg = &pDispParams->rgvarg[u]; if (V_ISBYREF(arg)) { rgVarRefIdx[cVarRef] = u; VariantInit(&rgVarRef[cVarRef]); cVarRef++; } } } else { /* [out] args still can't be null, * but we can point these anywhere in this case, * since they won't be written to when cVarRef is 0 */ rgVarRefIdx = puArgErr; rgVarRef = pVarResult; } TRACE("passed by ref: %d args\n", cVarRef); hr = IDispatch_RemoteInvoke_Proxy(This, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr, cVarRef, rgVarRefIdx, rgVarRef); if (cVarRef) { for (u=0; u<cVarRef; u++) { unsigned i = rgVarRefIdx[u]; VariantCopy(&pDispParams->rgvarg[i], &rgVarRef[u]); VariantClear(&rgVarRef[u]); } CoTaskMemFree(rgVarRef); CoTaskMemFree(rgVarRefIdx); } if(pExcepInfo == &ExcepInfo) { SysFreeString(pExcepInfo->bstrSource); SysFreeString(pExcepInfo->bstrDescription); SysFreeString(pExcepInfo->bstrHelpFile); } return hr; }
HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags, const VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers) { SAFEARRAY *post_array = NULL; PBYTE post_data = NULL; ULONG post_data_len = 0; LPWSTR headers = NULL; HRESULT hres = S_OK; TRACE("navigating to %s\n", debugstr_w(url)); if((Flags && V_VT(Flags) != VT_EMPTY && V_VT(Flags) != VT_ERROR) || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY && V_VT(TargetFrameName) != VT_ERROR)) FIXME("Unsupported args (Flags %s; TargetFrameName %s)\n", debugstr_variant(Flags), debugstr_variant(TargetFrameName)); if(PostData) { if(V_VT(PostData) & VT_ARRAY) post_array = V_ISBYREF(PostData) ? *V_ARRAYREF(PostData) : V_ARRAY(PostData); else WARN("Invalid post data %s\n", debugstr_variant(PostData)); } if(post_array) { LONG elem_max; SafeArrayAccessData(post_array, (void**)&post_data); SafeArrayGetUBound(post_array, 1, &elem_max); post_data_len = (elem_max+1) * SafeArrayGetElemsize(post_array); } if(Headers && V_VT(Headers) == VT_BSTR) { headers = V_BSTR(Headers); TRACE("Headers: %s\n", debugstr_w(headers)); } set_doc_state(This, READYSTATE_LOADING); This->ready_state = READYSTATE_LOADING; if(This->doc_navigate) { WCHAR new_url[INTERNET_MAX_URL_LENGTH]; if(PathIsURLW(url)) { new_url[0] = 0; }else { DWORD size; size = sizeof(new_url)/sizeof(WCHAR); hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME | URL_APPLY_GUESSFILE | URL_APPLY_DEFAULT); if(FAILED(hres)) { WARN("UrlApplyScheme failed: %08x\n", hres); new_url[0] = 0; } } hres = async_doc_navigate(This, *new_url ? new_url : url, headers, post_data, post_data_len, TRUE); }else { task_navigate_bsc_t *task; task = heap_alloc(sizeof(*task)); task->bsc = create_callback(This, url, post_data, post_data_len, headers); push_dochost_task(This, &task->header, navigate_bsc_proc, navigate_bsc_task_destr, This->url == NULL); } if(post_data) SafeArrayUnaccessData(post_array); return hres; }
SEXP R_convertDCOMObjectToR(VARIANT *var) { SEXP ans = R_NilValue; VARTYPE type = V_VT(var); #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("Converting VARIANT to R %d\n", V_VT(var)); #endif if(V_ISARRAY(var)) { #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("Finishing convertDCOMObjectToR - convert array\n"); #endif return(convertArrayToR(var)); } else if(V_VT(var) == VT_DISPATCH || (V_ISBYREF(var) && ((V_VT(var) & (~ VT_BYREF)) == VT_DISPATCH)) ) { IDispatch *ptr; if(V_ISBYREF(var)) { #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("BYREF and DISPATCH in convertDCOMObjectToR\n"); #endif IDispatch **tmp = V_DISPATCHREF(var); if(!tmp) return(ans); ptr = *tmp; } else ptr = V_DISPATCH(var); //xxx if(ptr) ptr->AddRef(); ans = R_createRCOMUnknownObject((void*) ptr, "COMIDispatch"); #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("Finished convertDCOMObjectToR COMIDispatch\n"); #endif return(ans); } if(V_ISBYREF(var)) { VARTYPE rtype = type & (~ VT_BYREF); #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("ISBYREF() in convertDCOMObjectToR: ref type %d\n", rtype); #endif if(rtype == VT_BSTR) { BSTR *tmp; const char *ptr = ""; #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("BYREF and BSTR convertDCOMObjectToR (scalar string)\n"); #endif tmp = V_BSTRREF(var); if(tmp) ptr = FromBstr(*tmp); ans = R_scalarString(ptr); return(ans); } else if(rtype == VT_BOOL || rtype == VT_I4 || rtype == VT_R8){ return(createVariantRef(var, rtype)); } else { fprintf(stderr, "Unhandled by-reference conversion type %d\n", V_VT(var));fflush(stderr); return(R_NilValue); } } switch(type) { case VT_BOOL: ans = R_scalarLogical( (Rboolean) (V_BOOL(var) ? TRUE : FALSE)); break; case VT_UI1: case VT_UI2: case VT_UI4: case VT_UINT: VariantChangeType(var, var, 0, VT_I4); ans = R_scalarReal((double) V_I4(var)); break; case VT_I1: case VT_I2: case VT_I4: case VT_INT: VariantChangeType(var, var, 0, VT_I4); ans = R_scalarInteger(V_I4(var)); break; case VT_R4: case VT_R8: case VT_I8: VariantChangeType(var, var, 0, VT_R8); ans = R_scalarReal(V_R8(var)); break; case VT_CY: case VT_DATE: case VT_HRESULT: case VT_DECIMAL: VariantChangeType(var, var, 0, VT_R8); ans = numberFromVariant(var, type); break; case VT_BSTR: { char *ptr = FromBstr(V_BSTR(var)); ans = R_scalarString(ptr); } break; case VT_UNKNOWN: { IUnknown *ptr = V_UNKNOWN(var); //xxx if(ptr) ptr->AddRef(); ans = R_createRCOMUnknownObject((void**) ptr, "COMUnknown"); } break; case VT_EMPTY: case VT_NULL: case VT_VOID: return(R_NilValue); break; /*XXX Need to fill these in */ case VT_RECORD: case VT_FILETIME: case VT_BLOB: case VT_STREAM: case VT_STORAGE: case VT_STREAMED_OBJECT: /* case LPSTR: */ case VT_LPWSTR: case VT_PTR: case VT_ERROR: case VT_VARIANT: case VT_CARRAY: case VT_USERDEFINED: default: fprintf(stderr, "Unhandled conversion type %d\n", V_VT(var));fflush(stderr); //XXX this consumes the variant. So the variant clearance in Invoke() does it again! ans = createRVariantObject(var, V_VT(var)); } #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("Finished convertDCOMObjectToR\n"); #endif return(ans); }
//+--------------------------------------------------------------------------- // // Function: VARIANTARGToCVar // // Synopsis: Converts a VARIANT to a C-language variable. // // Arguments: [pvarg] -- Variant to convert. // [pfAlloc] -- BSTR allocated during conversion caller is // now owner of this BSTR or IUnknown or IDispatch // object allocated needs to be released. // [vt] -- Type to convert to. // [pv] -- Location to place C-language variable. // // Modifies: [pv]. // // Returns: HRESULT. // // History: 2-23-94 adams Created // // Notes: Supports all variant pointer types, VT_I2, VT_I4, VT_R4, // VT_R8, VT_ERROR. //---------------------------------------------------------------------------- HRESULT VARIANTARGToCVar(VARIANT* pvarg, BOOL* pfAlloc, VARTYPE vt, void* pv, IServiceProvider* pSrvProvider, WORD wMaxstrlen) { HRESULT hr = S_OK; VARIANTARG* pVArgCopy = pvarg; VARIANTARG vargNew; // variant of new type BOOL fAlloc; Assert(pvarg); Assert(pv); if(!pfAlloc) { pfAlloc = &fAlloc; } Assert((vt&~VT_TYPEMASK) == 0 || (vt&~VT_TYPEMASK)==VT_BYREF); // Assume no allocations yet. *pfAlloc = FALSE; if(vt & VT_BYREF) { // If the parameter is a variant pointer then everything is acceptable. if((vt&VT_TYPEMASK) == VT_VARIANT) { switch(V_VT(pvarg)) { case VT_VARIANT|VT_BYREF: hr = ClipVarString(pvarg->pvarVal, *(VARIANT**)pv, pfAlloc, wMaxstrlen); break; default: hr = ClipVarString(pvarg, *(VARIANT**)pv, pfAlloc, wMaxstrlen); break; } if(hr == S_FALSE) { hr = S_OK; *(PVOID*)pv = (PVOID)pvarg; } goto Cleanup; } if((V_VT(pvarg)&VT_TYPEMASK) != (vt&VT_TYPEMASK)) { hr = DISP_E_TYPEMISMATCH; goto Cleanup; } // Type of both original and destination or same type (however, original // may not be a byref only the original. if(V_ISBYREF(pvarg)) { // Destination and original are byref and same type just copy pointer. *(PVOID*)pv = V_BYREF(pvarg); } else { // Convert original to byref. switch(vt & VT_TYPEMASK) { case VT_BOOL: *(PVOID*)pv = (PVOID)&V_BOOL(pvarg); break; case VT_I2: *(PVOID*)pv = (PVOID)&V_I2(pvarg); break; case VT_ERROR: case VT_I4: *(PVOID*)pv = (PVOID)&V_I4(pvarg); break; case VT_R4: *(PVOID*)pv = (PVOID)&V_R4(pvarg); break; case VT_R8: *(PVOID*)pv = (PVOID)&V_R8(pvarg); break; case VT_CY: *(PVOID*)pv = (PVOID)&V_CY(pvarg); break; // All pointer types. case VT_PTR: case VT_BSTR: case VT_LPSTR: case VT_LPWSTR: case VT_DISPATCH: case VT_UNKNOWN: *(PVOID*)pv = (PVOID)&V_UNKNOWN(pvarg); break; case VT_VARIANT: Assert("Dead code: shudn't have gotten here!"); *(PVOID*)pv = (PVOID)pvarg; break; default: Assert(!"Unknown type in BYREF VARIANTARGToCVar().\n"); hr = DISP_E_TYPEMISMATCH; goto Cleanup; } } goto Cleanup; } // If the c style parameter is the same type as the VARIANT then we'll just // move the data. Also if the c style type is a VARIANT then there's // nothing to convert just copy the variant to the C parameter. else if((V_VT(pvarg)&(VT_TYPEMASK|VT_BYREF))!=vt && (vt!=VT_VARIANT)) { // If the request type isn't the same as the variant passed in then we // need to convert. VariantInit(&vargNew); pVArgCopy = &vargNew; hr = VariantChangeTypeSpecial(pVArgCopy, pvarg, vt,pSrvProvider); if(hr) { goto Cleanup; } *pfAlloc = (vt==VT_BSTR) || (vt==VT_UNKNOWN) || (vt==VT_DISPATCH); } // Move the variant data to C style data. switch(vt) { case VT_BOOL: // convert VT_TRUE and any other non-zero values to TRUE *(VARIANT_BOOL*)pv = V_BOOL(pVArgCopy); break; case VT_I2: *(short*)pv = V_I2(pVArgCopy); break; case VT_ERROR: case VT_I4: *(long*)pv = V_I4(pVArgCopy); break; case VT_R4: *(float*)pv = V_R4(pVArgCopy); break; case VT_R8: *(double*)pv = V_R8(pVArgCopy); break; case VT_CY: *(CY*)pv = V_CY(pVArgCopy); break; // All Pointer types. case VT_BSTR: if(wMaxstrlen && FormsStringLen(V_BSTR(pVArgCopy))>wMaxstrlen) { hr = FormsAllocStringLen(V_BSTR(pVArgCopy), wMaxstrlen, (BSTR*)pv); if(hr) { goto Cleanup; } if(*pfAlloc) { VariantClear(&vargNew); } else { *pfAlloc = TRUE; } goto Cleanup; } case VT_PTR: case VT_LPSTR: case VT_LPWSTR: case VT_DISPATCH: case VT_UNKNOWN: *(void**)pv = V_BYREF(pVArgCopy); break; case VT_VARIANT: hr = ClipVarString(pVArgCopy, (VARIANT*)pv, pfAlloc, wMaxstrlen); if(hr == S_FALSE) { hr = S_OK; // Copy entire variant to output parameter. *(VARIANT*)pv = *pVArgCopy; } break; default: Assert(FALSE && "Unknown type in VARIANTARGToCVar().\n"); hr = DISP_E_TYPEMISMATCH; break; } Cleanup: RRETURN(hr); }
PyObject *PyRecord::getattro(PyObject *self, PyObject *obname) { PyObject *res; PyRecord *pyrec = (PyRecord *)self; char *name=PYWIN_ATTR_CONVERT(obname); if (name==NULL) return NULL; if (strcmp(name, "__members__")==0) { ULONG cnames = 0; HRESULT hr = pyrec->pri->GetFieldNames(&cnames, NULL); if (FAILED(hr)) return PyCom_BuildPyException(hr, pyrec->pri, IID_IRecordInfo); BSTR *strs = (BSTR *)malloc(sizeof(BSTR) * cnames); if (strs==NULL) return PyErr_NoMemory(); hr = pyrec->pri->GetFieldNames(&cnames, strs); if (FAILED(hr)) { free(strs); return PyCom_BuildPyException(hr, pyrec->pri, IID_IRecordInfo); } res = PyList_New(cnames); for (ULONG i=0;i<cnames && res != NULL;i++) { PyObject *item = PyWinCoreString_FromString(strs[i]); SysFreeString(strs[i]); if (item==NULL) { Py_DECREF(res); res = NULL; } else PyList_SET_ITEM(res, i, item); // ref count swallowed. } free(strs); return res; } res = PyObject_GenericGetAttr(self, obname); if (res != NULL) return res; PyErr_Clear(); WCHAR *wname; if (!PyWinObject_AsWCHAR(obname, &wname)) return NULL; VARIANT vret; VariantInit(&vret); void *sub_data = NULL; PY_INTERFACE_PRECALL; HRESULT hr = pyrec->pri->GetFieldNoCopy(pyrec->pdata, wname, &vret, &sub_data); PyWinObject_FreeWCHAR(wname); PY_INTERFACE_POSTCALL; if (FAILED(hr)) { if (hr == TYPE_E_FIELDNOTFOUND){ // This is slightly suspect - throwing a unicode // object for an AttributeError in py2k - but this // is the value we asked COM for, so it makes sense... // (and PyErr_Format doesn't handle unicode in py2x) PyErr_SetObject(PyExc_AttributeError, obname); return NULL; } return PyCom_BuildPyException(hr, pyrec->pri, IID_IRecordInfo); } // Short-circuit sub-structs and arrays here, so we dont allocate a new chunk // of memory and copy it - we need sub-structs to persist. if (V_VT(&vret)==(VT_BYREF | VT_RECORD)) return new PyRecord(V_RECORDINFO(&vret), V_RECORD(&vret), pyrec->owner); else if (V_VT(&vret)==(VT_BYREF | VT_ARRAY | VT_RECORD)) { SAFEARRAY *psa = *V_ARRAYREF(&vret); int d = SafeArrayGetDim(psa); if (sub_data==NULL) return PyErr_Format(PyExc_RuntimeError, "Did not get a buffer for the array!"); if (SafeArrayGetDim(psa) != 1) return PyErr_Format(PyExc_TypeError, "Only support single dimensional arrays of records"); IRecordInfo *sub = NULL; long ubound, lbound, nelems; int i; BYTE *this_data; PyObject *ret_tuple = NULL; ULONG element_size = 0; hr = SafeArrayGetUBound(psa, 1, &ubound); if (FAILED(hr)) goto array_end; hr = SafeArrayGetLBound(psa, 1, &lbound); if (FAILED(hr)) goto array_end; hr = SafeArrayGetRecordInfo(psa, &sub); if (FAILED(hr)) goto array_end; hr = sub->GetSize(&element_size); if (FAILED(hr)) goto array_end; nelems = ubound-lbound; ret_tuple = PyTuple_New(nelems); if (ret_tuple==NULL) goto array_end; this_data = (BYTE *)sub_data; for (i=0;i<nelems;i++) { PyTuple_SET_ITEM(ret_tuple, i, new PyRecord(sub, this_data, pyrec->owner)); this_data += element_size; } array_end: if (sub) sub->Release(); if (FAILED(hr)) return PyCom_BuildPyException(hr, pyrec->pri, IID_IRecordInfo); return ret_tuple; } // This default conversion we use is a little slow (but it will do!) // For arrays, the pparray->pvData member is *not* set, since the actual data // pointer from the record is returned in sub_data, so set it here. if (V_ISARRAY(&vret) && V_ISBYREF(&vret)) (*V_ARRAYREF(&vret))->pvData = sub_data; PyObject *ret = PyCom_PyObjectFromVariant(&vret); // VariantClear(&vret); return ret; }
TclObject::TclObject (VARIANT *pSrc, const Type &type, Tcl_Interp *interp, int bytes) { if (V_ISARRAY(pSrc)) { SAFEARRAY *psa = V_ISBYREF(pSrc) ? *V_ARRAYREF(pSrc) : V_ARRAY(pSrc); VARTYPE elementType = V_VT(pSrc) & VT_TYPEMASK; unsigned numDimensions = SafeArrayGetDim(psa); std::vector<long> indices(numDimensions); m_pObj = convertFromSafeArray( psa, elementType, 1, &indices[0], type, interp, bytes); } else if (vtMissing == pSrc) { m_pObj = Extension::newNaObj(); } else { switch (V_VT(pSrc)) { case VT_BOOL: m_pObj = Tcl_NewBooleanObj(V_BOOL(pSrc)); break; case VT_ERROR: m_pObj = Tcl_NewLongObj(V_ERROR(pSrc)); break; case VT_I1: case VT_UI1: m_pObj = Tcl_NewLongObj(V_I1(pSrc)); break; case VT_I2: case VT_UI2: m_pObj = Tcl_NewLongObj(V_I2(pSrc)); break; case VT_I4: case VT_UI4: case VT_INT: case VT_UINT: m_pObj = Tcl_NewLongObj(V_I4(pSrc)); break; #ifdef V_I8 case VT_I8: case VT_UI8: m_pObj = Tcl_NewWideIntObj(V_I8(pSrc)); break; #endif case VT_R4: m_pObj = Tcl_NewDoubleObj(V_R4(pSrc)); break; case VT_DATE: case VT_R8: m_pObj = Tcl_NewDoubleObj(V_R8(pSrc)); break; case VT_DISPATCH: m_pObj = convertFromUnknown(V_DISPATCH(pSrc), type.iid(), interp); break; case VT_DISPATCH | VT_BYREF: m_pObj = convertFromUnknown( (V_DISPATCHREF(pSrc) != 0) ? *V_DISPATCHREF(pSrc) : 0, type.iid(), interp); break; case VT_UNKNOWN: m_pObj = convertFromUnknown(V_UNKNOWN(pSrc), type.iid(), interp); break; case VT_UNKNOWN | VT_BYREF: m_pObj = convertFromUnknown( (V_UNKNOWNREF(pSrc) != 0) ? *V_UNKNOWNREF(pSrc) : 0, type.iid(), interp); break; case VT_NULL: m_pObj = Extension::newNullObj(); break; case VT_LPSTR: m_pObj = Tcl_NewStringObj(V_I1REF(pSrc), -1); break; case VT_LPWSTR: { #if TCL_MINOR_VERSION >= 2 // Uses Unicode function introduced in Tcl 8.2. m_pObj = newUnicodeObj(V_UI2REF(pSrc), -1); #else const wchar_t *pWide = V_UI2REF(pSrc); _bstr_t str(pWide); m_pObj = Tcl_NewStringObj(str, -1); #endif } break; default: if (V_VT(pSrc) == VT_USERDEFINED && type.name() == "GUID") { Uuid uuid(*static_cast<UUID *>(V_BYREF(pSrc))); m_pObj = Tcl_NewStringObj( const_cast<char *>(uuid.toString().c_str()), -1); } else { if (V_VT(pSrc) == (VT_VARIANT | VT_BYREF)) { pSrc = V_VARIANTREF(pSrc); } _bstr_t str(pSrc); #if TCL_MINOR_VERSION >= 2 // Uses Unicode function introduced in Tcl 8.2. wchar_t *pWide = str; m_pObj = newUnicodeObj( reinterpret_cast<Tcl_UniChar *>(pWide), str.length()); #else m_pObj = Tcl_NewStringObj(str, -1); #endif } } } Tcl_IncrRefCount(m_pObj); }