ReactOS  0.4.14-dev-98-gb0d4763
safearray.c File Reference
#include "config.h"
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winerror.h"
#include "winbase.h"
#include "variant.h"
#include "wine/debug.h"
Include dependency graph for safearray.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 
#define SAFEARRAY_HIDDEN_SIZE   sizeof(GUID)
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (variant)
 
static voidSAFEARRAY_Malloc (ULONG size)
 
static void SAFEARRAY_Free (void *ptr)
 
static DWORD SAFEARRAY_GetVTSize (VARTYPE vt)
 
static void SAFEARRAY_SetHiddenDWORD (SAFEARRAY *psa, DWORD dw)
 
static DWORD SAFEARRAY_GetHiddenDWORD (SAFEARRAY *psa)
 
static ULONG SAFEARRAY_GetCellCount (const SAFEARRAY *psa)
 
static HRESULT SAFEARRAY_AllocDescriptor (ULONG ulSize, SAFEARRAY **ppsaOut)
 
static void SAFEARRAY_SetFeatures (VARTYPE vt, SAFEARRAY *psa)
 
static SAFEARRAYSAFEARRAY_Create (VARTYPE vt, UINT cDims, const SAFEARRAYBOUND *rgsabound, ULONG ulSize)
 
static SAFEARRAYSAFEARRAY_CreateVector (VARTYPE vt, LONG lLbound, ULONG cElements, ULONG ulSize)
 
static HRESULT SAFEARRAY_DestroyData (SAFEARRAY *psa, ULONG ulStartCell)
 
static HRESULT SAFEARRAY_CopyData (SAFEARRAY *psa, SAFEARRAY *dest)
 
HRESULT WINAPI SafeArrayAllocDescriptor (UINT cDims, SAFEARRAY **ppsaOut)
 
HRESULT WINAPI SafeArrayAllocDescriptorEx (VARTYPE vt, UINT cDims, SAFEARRAY **ppsaOut)
 
HRESULT WINAPI SafeArrayAllocData (SAFEARRAY *psa)
 
SAFEARRAY *WINAPI SafeArrayCreate (VARTYPE vt, UINT cDims, SAFEARRAYBOUND *rgsabound)
 
SAFEARRAY *WINAPI SafeArrayCreateEx (VARTYPE vt, UINT cDims, SAFEARRAYBOUND *rgsabound, LPVOID pvExtra)
 
SAFEARRAY *WINAPI SafeArrayCreateVector (VARTYPE vt, LONG lLbound, ULONG cElements)
 
SAFEARRAY *WINAPI SafeArrayCreateVectorEx (VARTYPE vt, LONG lLbound, ULONG cElements, LPVOID pvExtra)
 
HRESULT WINAPI SafeArrayDestroyDescriptor (SAFEARRAY *psa)
 
HRESULT WINAPI SafeArrayLock (SAFEARRAY *psa)
 
HRESULT WINAPI SafeArrayUnlock (SAFEARRAY *psa)
 
HRESULT WINAPI SafeArrayPutElement (SAFEARRAY *psa, LONG *rgIndices, void *pvData)
 
HRESULT WINAPI SafeArrayGetElement (SAFEARRAY *psa, LONG *rgIndices, void *pvData)
 
HRESULT WINAPI SafeArrayGetUBound (SAFEARRAY *psa, UINT nDim, LONG *plUbound)
 
HRESULT WINAPI SafeArrayGetLBound (SAFEARRAY *psa, UINT nDim, LONG *plLbound)
 
UINT WINAPI SafeArrayGetDim (SAFEARRAY *psa)
 
UINT WINAPI SafeArrayGetElemsize (SAFEARRAY *psa)
 
HRESULT WINAPI SafeArrayAccessData (SAFEARRAY *psa, void **ppvData)
 
HRESULT WINAPI SafeArrayUnaccessData (SAFEARRAY *psa)
 
HRESULT WINAPI SafeArrayPtrOfIndex (SAFEARRAY *psa, LONG *rgIndices, void **ppvData)
 
HRESULT WINAPI SafeArrayDestroyData (SAFEARRAY *psa)
 
HRESULT WINAPI SafeArrayCopyData (SAFEARRAY *psaSource, SAFEARRAY *psaTarget)
 
HRESULT WINAPI SafeArrayDestroy (SAFEARRAY *psa)
 
HRESULT WINAPI SafeArrayCopy (SAFEARRAY *psa, SAFEARRAY **ppsaOut)
 
HRESULT WINAPI SafeArrayRedim (SAFEARRAY *psa, SAFEARRAYBOUND *psabound)
 
HRESULT WINAPI SafeArrayGetVartype (SAFEARRAY *psa, VARTYPE *pvt)
 
HRESULT WINAPI SafeArraySetRecordInfo (SAFEARRAY *psa, IRecordInfo *pRinfo)
 
HRESULT WINAPI SafeArrayGetRecordInfo (SAFEARRAY *psa, IRecordInfo **pRinfo)
 
HRESULT WINAPI SafeArraySetIID (SAFEARRAY *psa, REFGUID guid)
 
HRESULT WINAPI SafeArrayGetIID (SAFEARRAY *psa, GUID *pGuid)
 
HRESULT WINAPI VectorFromBstr (BSTR bstr, SAFEARRAY **ppsa)
 
HRESULT WINAPI BstrFromVector (SAFEARRAY *psa, BSTR *pbstr)
 

Variables

static const USHORT ignored_copy_features
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 40 of file safearray.c.

◆ SAFEARRAY_HIDDEN_SIZE

#define SAFEARRAY_HIDDEN_SIZE   sizeof(GUID)

Definition at line 86 of file safearray.c.

Function Documentation

◆ BstrFromVector()

HRESULT WINAPI BstrFromVector ( SAFEARRAY psa,
BSTR pbstr 
)

Definition at line 1742 of file safearray.c.

1743 {
1744  TRACE("(%p,%p)\n", psa, pbstr);
1745 
1746  if (!pbstr)
1747  return E_INVALIDARG;
1748 
1749  *pbstr = NULL;
1750 
1751  if (!psa || psa->cbElements != 1 || psa->cDims != 1)
1752  return E_INVALIDARG;
1753 
1754  *pbstr = SysAllocStringByteLen(psa->pvData, psa->rgsabound[0].cElements);
1755  if (!*pbstr)
1756  return E_OUTOFMEMORY;
1757  return S_OK;
1758 }
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
BSTR WINAPI DECLSPEC_HOTPATCH SysAllocStringByteLen(LPCSTR str, UINT len)
Definition: oleaut.c:431
#define TRACE(s)
Definition: solgame.cpp:4
#define S_OK
Definition: intsafe.h:59
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64

Referenced by VARIANT_CoerceArray().

◆ SAFEARRAY_AllocDescriptor()

static HRESULT SAFEARRAY_AllocDescriptor ( ULONG  ulSize,
SAFEARRAY **  ppsaOut 
)
static

Definition at line 182 of file safearray.c.

183 {
184  char *ptr = SAFEARRAY_Malloc(ulSize + SAFEARRAY_HIDDEN_SIZE);
185 
186  if (!ptr)
187  {
188  *ppsaOut = NULL;
189  return E_OUTOFMEMORY;
190  }
191 
192  *ppsaOut = (SAFEARRAY*)(ptr + SAFEARRAY_HIDDEN_SIZE);
193  return S_OK;
194 }
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
#define SAFEARRAY_HIDDEN_SIZE
Definition: safearray.c:86
#define S_OK
Definition: intsafe.h:59
static void * SAFEARRAY_Malloc(ULONG size)
Definition: safearray.c:98

Referenced by SAFEARRAY_CreateVector(), and SafeArrayAllocDescriptor().

◆ SAFEARRAY_CopyData()

static HRESULT SAFEARRAY_CopyData ( SAFEARRAY psa,
SAFEARRAY dest 
)
static

Definition at line 351 of file safearray.c.

352 {
353  HRESULT hr = S_OK;
354 
355  if (!psa->pvData)
356  return S_OK;
357 
358  if (!dest->pvData || psa->fFeatures & FADF_DATADELETED)
359  return E_INVALIDARG;
360  else
361  {
362  ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
363 
364  dest->fFeatures = (dest->fFeatures & FADF_CREATEVECTOR) | (psa->fFeatures & ~ignored_copy_features);
365 
366  if (psa->fFeatures & FADF_VARIANT)
367  {
368  VARIANT *src_var = psa->pvData;
369  VARIANT *dest_var = dest->pvData;
370 
371  while(ulCellCount--)
372  {
373  HRESULT hRet;
374 
375  /* destination is cleared automatically */
376  hRet = VariantCopy(dest_var, src_var);
377  if (FAILED(hRet)) FIXME("VariantCopy failed with 0x%08x, element %u\n", hRet, ulCellCount);
378  src_var++;
379  dest_var++;
380  }
381  }
382  else if (psa->fFeatures & FADF_BSTR)
383  {
384  BSTR *src_bstr = psa->pvData;
385  BSTR *dest_bstr = dest->pvData;
386 
387  while(ulCellCount--)
388  {
389  SysFreeString(*dest_bstr);
390  if (*src_bstr)
391  {
392  *dest_bstr = SysAllocStringByteLen((char*)*src_bstr, SysStringByteLen(*src_bstr));
393  if (!*dest_bstr)
394  return E_OUTOFMEMORY;
395  }
396  else
397  *dest_bstr = NULL;
398  src_bstr++;
399  dest_bstr++;
400  }
401  }
402  else if (psa->fFeatures & FADF_RECORD)
403  {
404  BYTE *dest_data = dest->pvData;
405  BYTE *src_data = psa->pvData;
407 
409  while (ulCellCount--)
410  {
411  /* RecordCopy() clears destination record */
412  hr = IRecordInfo_RecordCopy(record, src_data, dest_data);
413  if (FAILED(hr)) break;
414  src_data += psa->cbElements;
415  dest_data += psa->cbElements;
416  }
417 
419  /* This value is set to 32 bytes by default on descriptor creation,
420  update with actual structure size. */
421  dest->cbElements = psa->cbElements;
422  IRecordInfo_Release(record);
423  }
424  else if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
425  {
426  IUnknown **dest_unk = dest->pvData;
427  IUnknown **src_unk = psa->pvData;
428 
429  /* release old iface, addref new one */
430  while (ulCellCount--)
431  {
432  if (*dest_unk)
433  IUnknown_Release(*dest_unk);
434  *dest_unk = *src_unk;
435  if (*dest_unk)
436  IUnknown_AddRef(*dest_unk);
437  src_unk++;
438  dest_unk++;
439  }
440  }
441  else
442  {
443  /* Copy the data over */
444  memcpy(dest->pvData, psa->pvData, ulCellCount * psa->cbElements);
445  }
446 
447  if (psa->fFeatures & FADF_HAVEIID)
448  {
449  GUID guid;
452  }
453  else if (psa->fFeatures & FADF_HAVEVARTYPE)
454  {
456  }
457  }
458 
459  return hr;
460 }
static void SAFEARRAY_SetHiddenDWORD(SAFEARRAY *psa, DWORD dw)
Definition: safearray.c:149
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
Definition: safearray.c:164
static const USHORT ignored_copy_features
Definition: safearray.c:90
HRESULT WINAPI SafeArrayGetRecordInfo(SAFEARRAY *psa, IRecordInfo **pRinfo)
Definition: safearray.c:1611
HRESULT hr
Definition: shlfolder.c:183
UINT WINAPI SysStringByteLen(BSTR str)
Definition: oleaut.c:218
OLECHAR * BSTR
Definition: compat.h:1934
const USHORT FADF_CREATEVECTOR
Definition: safearray.c:43
const GUID * guid
HRESULT WINAPI SafeArraySetIID(SAFEARRAY *psa, REFGUID guid)
Definition: safearray.c:1643
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static DWORD SAFEARRAY_GetHiddenDWORD(SAFEARRAY *psa)
Definition: safearray.c:157
#define FIXME(fmt,...)
Definition: debug.h:110
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI SafeArraySetRecordInfo(SAFEARRAY *psa, IRecordInfo *pRinfo)
Definition: safearray.c:1576
BSTR WINAPI DECLSPEC_HOTPATCH SysAllocStringByteLen(LPCSTR str, UINT len)
Definition: oleaut.c:431
LONG HRESULT
Definition: typedefs.h:77
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
HRESULT WINAPI SafeArrayGetIID(SAFEARRAY *psa, GUID *pGuid)
Definition: safearray.c:1672
#define S_OK
Definition: intsafe.h:59
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
unsigned int ULONG
Definition: retypes.h:1
static char * dest
Definition: rtl.c:135
HRESULT WINAPI VariantCopy(VARIANTARG *pvargDest, VARIANTARG *pvargSrc)
Definition: variant.c:751

Referenced by SafeArrayCopy(), and SafeArrayCopyData().

◆ SAFEARRAY_Create()

static SAFEARRAY* SAFEARRAY_Create ( VARTYPE  vt,
UINT  cDims,
const SAFEARRAYBOUND rgsabound,
ULONG  ulSize 
)
static

Definition at line 220 of file safearray.c.

221 {
222  SAFEARRAY *psa = NULL;
223  unsigned int i;
224 
225  if (!rgsabound)
226  return NULL;
227 
229  {
230  switch (vt)
231  {
232  case VT_BSTR: psa->fFeatures |= FADF_BSTR; break;
233  case VT_UNKNOWN: psa->fFeatures |= FADF_UNKNOWN; break;
234  case VT_DISPATCH: psa->fFeatures |= FADF_DISPATCH; break;
235  case VT_VARIANT: psa->fFeatures |= FADF_VARIANT; break;
236  }
237 
238  for (i = 0; i < cDims; i++)
239  memcpy(psa->rgsabound + i, rgsabound + cDims - 1 - i, sizeof(SAFEARRAYBOUND));
240 
241  if (ulSize)
242  psa->cbElements = ulSize;
243 
244  if (!psa->cbElements || FAILED(SafeArrayAllocData(psa)))
245  {
247  psa = NULL;
248  }
249  }
250  return psa;
251 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI SafeArrayAllocData(SAFEARRAY *psa)
Definition: safearray.c:559
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
HRESULT WINAPI SafeArrayDestroyDescriptor(SAFEARRAY *psa)
Definition: safearray.c:757
HRESULT WINAPI SafeArrayAllocDescriptorEx(VARTYPE vt, UINT cDims, SAFEARRAY **ppsaOut)
Definition: safearray.c:523
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
VARTYPE vt
Definition: safearray.c:331
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by SafeArrayCreate(), SafeArrayCreateEx(), and VectorFromBstr().

◆ SAFEARRAY_CreateVector()

static SAFEARRAY* SAFEARRAY_CreateVector ( VARTYPE  vt,
LONG  lLbound,
ULONG  cElements,
ULONG  ulSize 
)
static

Definition at line 254 of file safearray.c.

255 {
256  SAFEARRAY *psa = NULL;
257 
258  if (ulSize || (vt == VT_RECORD))
259  {
260  /* Allocate the header and data together */
261  if (SUCCEEDED(SAFEARRAY_AllocDescriptor(sizeof(SAFEARRAY) + ulSize * cElements, &psa)))
262  {
264 
265  psa->cDims = 1;
266  psa->fFeatures |= FADF_CREATEVECTOR;
267  psa->pvData = &psa[1]; /* Data follows the header */
268  psa->cbElements = ulSize;
269  psa->rgsabound[0].cElements = cElements;
270  psa->rgsabound[0].lLbound = lLbound;
271 
272  switch (vt)
273  {
274  case VT_BSTR: psa->fFeatures |= FADF_BSTR; break;
275  case VT_UNKNOWN: psa->fFeatures |= FADF_UNKNOWN; break;
276  case VT_DISPATCH: psa->fFeatures |= FADF_DISPATCH; break;
277  case VT_VARIANT: psa->fFeatures |= FADF_VARIANT; break;
278  }
279  }
280  }
281  return psa;
282 }
static void SAFEARRAY_SetFeatures(VARTYPE vt, SAFEARRAY *psa)
Definition: safearray.c:197
const USHORT FADF_CREATEVECTOR
Definition: safearray.c:43
smooth NULL
Definition: ftsmooth.c:416
static HRESULT SAFEARRAY_AllocDescriptor(ULONG ulSize, SAFEARRAY **ppsaOut)
Definition: safearray.c:182
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
VARTYPE vt
Definition: safearray.c:331
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by SafeArrayCreateVector(), and SafeArrayCreateVectorEx().

◆ SAFEARRAY_DestroyData()

static HRESULT SAFEARRAY_DestroyData ( SAFEARRAY psa,
ULONG  ulStartCell 
)
static

Definition at line 285 of file safearray.c.

286 {
287  if (psa->pvData && !(psa->fFeatures & FADF_DATADELETED))
288  {
289  ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
290 
291  if (ulStartCell > ulCellCount) {
292  FIXME("unexpected ulCellCount %d, start %d\n",ulCellCount,ulStartCell);
293  return E_UNEXPECTED;
294  }
295 
296  ulCellCount -= ulStartCell;
297 
298  if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
299  {
300  LPUNKNOWN *lpUnknown = (LPUNKNOWN *)psa->pvData + ulStartCell;
301 
302  while(ulCellCount--)
303  {
304  if (*lpUnknown)
305  IUnknown_Release(*lpUnknown);
306  lpUnknown++;
307  }
308  }
309  else if (psa->fFeatures & FADF_RECORD)
310  {
311  IRecordInfo *lpRecInfo;
312 
313  if (SUCCEEDED(SafeArrayGetRecordInfo(psa, &lpRecInfo)))
314  {
315  PBYTE pRecordData = psa->pvData;
316  while(ulCellCount--)
317  {
318  IRecordInfo_RecordClear(lpRecInfo, pRecordData);
319  pRecordData += psa->cbElements;
320  }
321  IRecordInfo_Release(lpRecInfo);
322  }
323  }
324  else if (psa->fFeatures & FADF_BSTR)
325  {
326  BSTR* lpBstr = (BSTR*)psa->pvData + ulStartCell;
327 
328  while(ulCellCount--)
329  {
330  SysFreeString(*lpBstr);
331  lpBstr++;
332  }
333  }
334  else if (psa->fFeatures & FADF_VARIANT)
335  {
336  VARIANT* lpVariant = (VARIANT*)psa->pvData + ulStartCell;
337 
338  while(ulCellCount--)
339  {
340  HRESULT hRet = VariantClear(lpVariant);
341 
342  if (FAILED(hRet)) FIXME("VariantClear of element failed!\n");
343  lpVariant++;
344  }
345  }
346  }
347  return S_OK;
348 }
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
Definition: safearray.c:164
HRESULT WINAPI SafeArrayGetRecordInfo(SAFEARRAY *psa, IRecordInfo **pRinfo)
Definition: safearray.c:1611
OLECHAR * BSTR
Definition: compat.h:1934
static LPUNKNOWN
Definition: ndr_ole.c:49
#define FIXME(fmt,...)
Definition: debug.h:110
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:651
#define S_OK
Definition: intsafe.h:59
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
#define E_UNEXPECTED
Definition: winerror.h:2456
unsigned int ULONG
Definition: retypes.h:1
BYTE * PBYTE
Definition: pedump.c:66
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by SafeArrayDestroyData(), SafeArrayDestroyDescriptor(), and SafeArrayRedim().

◆ SAFEARRAY_Free()

static void SAFEARRAY_Free ( void ptr)
inlinestatic

Definition at line 107 of file safearray.c.

108 {
110 }
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:422
static PVOID ptr
Definition: dispmode.c:27

Referenced by SafeArrayCopy(), SafeArrayDestroyData(), SafeArrayDestroyDescriptor(), and SafeArrayRedim().

◆ SAFEARRAY_GetCellCount()

static ULONG SAFEARRAY_GetCellCount ( const SAFEARRAY psa)
static

Definition at line 164 of file safearray.c.

165 {
166  const SAFEARRAYBOUND* psab = psa->rgsabound;
167  USHORT cCount = psa->cDims;
168  ULONG ulNumCells = 1;
169 
170  while (cCount--)
171  {
172  /* This is a valid bordercase. See testcases. -Marcus */
173  if (!psab->cElements)
174  return 0;
175  ulNumCells *= psab->cElements;
176  psab++;
177  }
178  return ulNumCells;
179 }
unsigned short USHORT
Definition: pedump.c:61
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
unsigned int ULONG
Definition: retypes.h:1

Referenced by SAFEARRAY_CopyData(), SAFEARRAY_DestroyData(), SafeArrayAllocData(), SafeArrayCopy(), SafeArrayDestroyData(), and SafeArrayRedim().

◆ SAFEARRAY_GetHiddenDWORD()

static DWORD SAFEARRAY_GetHiddenDWORD ( SAFEARRAY psa)
inlinestatic

Definition at line 157 of file safearray.c.

158 {
159  LPDWORD lpDw = (LPDWORD)psa;
160  return lpDw[-1];
161 }
#define LPDWORD
Definition: nt_native.h:46
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
uint32_t * LPDWORD
Definition: typedefs.h:57

Referenced by SAFEARRAY_CopyData(), and SafeArrayGetVartype().

◆ SAFEARRAY_GetVTSize()

static DWORD SAFEARRAY_GetVTSize ( VARTYPE  vt)
static

Definition at line 113 of file safearray.c.

114 {
115  switch (vt)
116  {
117  case VT_I1:
118  case VT_UI1: return sizeof(BYTE);
119  case VT_BOOL:
120  case VT_I2:
121  case VT_UI2: return sizeof(SHORT);
122  case VT_I4:
123  case VT_UI4:
124  case VT_R4:
125  case VT_ERROR: return sizeof(LONG);
126  case VT_R8:
127  case VT_I8:
128  case VT_UI8: return sizeof(LONG64);
129  case VT_INT:
130  case VT_UINT: return sizeof(INT);
131  case VT_INT_PTR:
132  case VT_UINT_PTR: return sizeof(UINT_PTR);
133  case VT_CY: return sizeof(CY);
134  case VT_DATE: return sizeof(DATE);
135  case VT_BSTR: return sizeof(BSTR);
136  case VT_DISPATCH: return sizeof(LPDISPATCH);
137  case VT_VARIANT: return sizeof(VARIANT);
138  case VT_UNKNOWN: return sizeof(LPUNKNOWN);
139  case VT_DECIMAL: return sizeof(DECIMAL);
140  /* Note: Return a non-zero size to indicate vt is valid. The actual size
141  * of a UDT is taken from the result of IRecordInfo_GetSize().
142  */
143  case VT_RECORD: return 32;
144  }
145  return 0;
146 }
unsigned __int3264 UINT_PTR
Definition: activex.cpp:275
struct tagVARIANT VARIANT
Definition: compat.h:2018
Definition: compat.h:1939
Definition: compat.h:1955
Definition: compat.h:1951
#define INT
Definition: polytest.cpp:20
double DATE
Definition: compat.h:1894
OLECHAR * BSTR
Definition: compat.h:1934
long LONG
Definition: pedump.c:60
short SHORT
Definition: pedump.c:59
static LPUNKNOWN
Definition: ndr_ole.c:49
union tagCY CY
int64_t LONG64
Definition: typedefs.h:66
Definition: compat.h:1940
unsigned char BYTE
Definition: mem.h:68
Definition: compat.h:1942
struct tagDEC DECIMAL
VARTYPE vt
Definition: safearray.c:331
Definition: compat.h:1941
Definition: compat.h:1938

Referenced by SafeArrayAllocDescriptorEx(), SafeArrayCreateVector(), and SafeArrayCreateVectorEx().

◆ SAFEARRAY_Malloc()

static void* SAFEARRAY_Malloc ( ULONG  size)
inlinestatic

Definition at line 98 of file safearray.c.

99 {
100  void *ret = CoTaskMemAlloc(size);
101  if (ret)
102  memset(ret, 0, size);
103  return ret;
104 }
GLsizeiptr size
Definition: glext.h:5919
int ret
#define memset(x, y, z)
Definition: compat.h:39
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:406

Referenced by SAFEARRAY_AllocDescriptor(), SafeArrayAllocData(), SafeArrayCopy(), and SafeArrayRedim().

◆ SAFEARRAY_SetFeatures()

static void SAFEARRAY_SetFeatures ( VARTYPE  vt,
SAFEARRAY psa 
)
static

Definition at line 197 of file safearray.c.

198 {
199  /* Set the IID if we have one, otherwise set the type */
200  if (vt == VT_DISPATCH)
201  {
202  psa->fFeatures = FADF_HAVEIID;
204  }
205  else if (vt == VT_UNKNOWN)
206  {
207  psa->fFeatures = FADF_HAVEIID;
209  }
210  else if (vt == VT_RECORD)
211  psa->fFeatures = FADF_RECORD;
212  else
213  {
214  psa->fFeatures = FADF_HAVEVARTYPE;
216  }
217 }
static void SAFEARRAY_SetHiddenDWORD(SAFEARRAY *psa, DWORD dw)
Definition: safearray.c:149
HRESULT WINAPI SafeArraySetIID(SAFEARRAY *psa, REFGUID guid)
Definition: safearray.c:1643
const GUID IID_IUnknown
const GUID IID_IDispatch
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
VARTYPE vt
Definition: safearray.c:331

Referenced by SAFEARRAY_CreateVector(), and SafeArrayAllocDescriptorEx().

◆ SAFEARRAY_SetHiddenDWORD()

static void SAFEARRAY_SetHiddenDWORD ( SAFEARRAY psa,
DWORD  dw 
)
inlinestatic

Definition at line 149 of file safearray.c.

150 {
151  /* Implementation data is stored in the 4 bytes before the header */
152  LPDWORD lpDw = (LPDWORD)psa;
153  lpDw[-1] = dw;
154 }
REFIID LPVOID DWORD dw
Definition: atlbase.h:40
#define LPDWORD
Definition: nt_native.h:46
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
uint32_t * LPDWORD
Definition: typedefs.h:57

Referenced by SAFEARRAY_CopyData(), and SAFEARRAY_SetFeatures().

◆ SafeArrayAccessData()

HRESULT WINAPI SafeArrayAccessData ( SAFEARRAY psa,
void **  ppvData 
)

Definition at line 1139 of file safearray.c.

1140 {
1141  HRESULT hr;
1142 
1143  TRACE("(%p,%p)\n", psa, ppvData);
1144 
1145  if(!psa || !ppvData)
1146  return E_INVALIDARG;
1147 
1148  hr = SafeArrayLock(psa);
1149  *ppvData = SUCCEEDED(hr) ? psa->pvData : NULL;
1150 
1151  return hr;
1152 }
HRESULT hr
Definition: shlfolder.c:183
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI SafeArrayLock(SAFEARRAY *psa)
Definition: safearray.c:797
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by check_safearray(), DEVENUM_IPropertyBag_Read(), DEVENUM_IPropertyBag_Write(), dictionary_Items(), dictionary_Keys(), doc_complex_write(), doc_write(), document_write(), exec_print(), fill_filter_container(), FilterMapper3_EnumMatchingFilters(), FilterMapper3_RegisterFilter(), Global_Array(), Global_InvokeEx(), Host_Echo(), HTMLPrivateWindow_SuperNavigate(), InitVariantFromBuffer(), InvokeObjectPickerDialog(), ITypeInfo_fnInvoke(), make_safearray(), navigate_url(), request_send(), test_InitPropVariantFromBuffer(), test_load(), test_parse_filter_data(), test_put_nodeTypedValue(), test_safearray(), test_saxreader(), test_SystemSecurity(), test_Win32_SystemEnclosure(), test_XMLHTTP(), to_byte_array(), VBArray_toArray(), Widget_VarArg(), Widget_VarArg_Ref_Run(), Widget_VarArg_Run(), winhttp_request_get_ResponseBody(), write_filter_data(), WshShell3_RegRead(), and xslprocessor_transform().

◆ SafeArrayAllocData()

HRESULT WINAPI SafeArrayAllocData ( SAFEARRAY psa)

Definition at line 559 of file safearray.c.

560 {
561  HRESULT hRet = E_INVALIDARG;
562 
563  TRACE("(%p)\n", psa);
564 
565  if (psa)
566  {
567  ULONG ulSize = SAFEARRAY_GetCellCount(psa);
568 
569  psa->pvData = SAFEARRAY_Malloc(ulSize * psa->cbElements);
570 
571  if (psa->pvData)
572  {
573  hRet = S_OK;
574  TRACE("%u bytes allocated for data at %p (%u objects).\n",
575  ulSize * psa->cbElements, psa->pvData, ulSize);
576  }
577  else
578  hRet = E_OUTOFMEMORY;
579  }
580  return hRet;
581 }
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
Definition: safearray.c:164
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
#define S_OK
Definition: intsafe.h:59
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
static void * SAFEARRAY_Malloc(ULONG size)
Definition: safearray.c:98
unsigned int ULONG
Definition: retypes.h:1

Referenced by LPSAFEARRAY_UserUnmarshal(), SAFEARRAY_Create(), test_marshal_LPSAFEARRAY(), test_safearray(), and test_SafeArrayAllocDestroyDescriptor().

◆ SafeArrayAllocDescriptor()

HRESULT WINAPI SafeArrayAllocDescriptor ( UINT  cDims,
SAFEARRAY **  ppsaOut 
)

Definition at line 478 of file safearray.c.

479 {
480  LONG allocSize;
481  HRESULT hr;
482 
483  TRACE("(%d,%p)\n", cDims, ppsaOut);
484 
485  if (!cDims || cDims >= 0x10000) /* Maximum 65535 dimensions */
486  return E_INVALIDARG;
487 
488  if (!ppsaOut)
489  return E_POINTER;
490 
491  /* We need enough space for the header and its bounds */
492  allocSize = sizeof(SAFEARRAY) + sizeof(SAFEARRAYBOUND) * (cDims - 1);
493 
494  hr = SAFEARRAY_AllocDescriptor(allocSize, ppsaOut);
495  if (FAILED(hr))
496  return hr;
497 
498  (*ppsaOut)->cDims = cDims;
499 
500  TRACE("(%d): %u bytes allocated for descriptor.\n", cDims, allocSize);
501  return S_OK;
502 }
HRESULT hr
Definition: shlfolder.c:183
struct tagSAFEARRAY SAFEARRAY
long LONG
Definition: pedump.c:60
#define E_INVALIDARG
Definition: ddrawi.h:101
static HRESULT SAFEARRAY_AllocDescriptor(ULONG ulSize, SAFEARRAY **ppsaOut)
Definition: safearray.c:182
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
#define S_OK
Definition: intsafe.h:59
#define E_POINTER
Definition: winerror.h:2365

Referenced by LPSAFEARRAY_UserUnmarshal(), SafeArrayAllocDescriptorEx(), SafeArrayCopy(), test_marshal_LPSAFEARRAY(), test_safearray(), test_SafeArrayAllocDestroyDescriptor(), test_SafeArrayCopy(), and test_SafeArrayDestroyData().

◆ SafeArrayAllocDescriptorEx()

HRESULT WINAPI SafeArrayAllocDescriptorEx ( VARTYPE  vt,
UINT  cDims,
SAFEARRAY **  ppsaOut 
)

Definition at line 523 of file safearray.c.

524 {
525  ULONG cbElements;
526  HRESULT hRet;
527 
528  TRACE("(%d->%s,%d,%p)\n", vt, debugstr_vt(vt), cDims, ppsaOut);
529 
530  cbElements = SAFEARRAY_GetVTSize(vt);
531  if (!cbElements)
532  WARN("Creating a descriptor with an invalid VARTYPE!\n");
533 
534  hRet = SafeArrayAllocDescriptor(cDims, ppsaOut);
535 
536  if (SUCCEEDED(hRet))
537  {
538  SAFEARRAY_SetFeatures(vt, *ppsaOut);
539  (*ppsaOut)->cbElements = cbElements;
540  }
541  return hRet;
542 }
#define WARN(fmt,...)
Definition: debug.h:111
static void SAFEARRAY_SetFeatures(VARTYPE vt, SAFEARRAY *psa)
Definition: safearray.c:197
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
static DWORD SAFEARRAY_GetVTSize(VARTYPE vt)
Definition: safearray.c:113
unsigned int ULONG
Definition: retypes.h:1
VARTYPE vt
Definition: safearray.c:331
HRESULT WINAPI SafeArrayAllocDescriptor(UINT cDims, SAFEARRAY **ppsaOut)
Definition: safearray.c:478
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by SAFEARRAY_Create(), SafeArrayCopy(), and START_TEST().

◆ SafeArrayCopy()

HRESULT WINAPI SafeArrayCopy ( SAFEARRAY psa,
SAFEARRAY **  ppsaOut 
)

Definition at line 1381 of file safearray.c.

1382 {
1383  HRESULT hRet;
1384 
1385  TRACE("(%p,%p)\n", psa, ppsaOut);
1386 
1387  if (!ppsaOut)
1388  return E_INVALIDARG;
1389 
1390  *ppsaOut = NULL;
1391 
1392  if (!psa)
1393  return S_OK; /* Handles copying of NULL arrays */
1394 
1395  if (!psa->cbElements)
1396  return E_INVALIDARG;
1397 
1398  if (psa->fFeatures & (FADF_RECORD|FADF_HAVEIID|FADF_HAVEVARTYPE))
1399  {
1400  VARTYPE vt;
1401 
1402  hRet = SafeArrayGetVartype(psa, &vt);
1403  if (SUCCEEDED(hRet))
1404  hRet = SafeArrayAllocDescriptorEx(vt, psa->cDims, ppsaOut);
1405  }
1406  else
1407  {
1408  hRet = SafeArrayAllocDescriptor(psa->cDims, ppsaOut);
1409  if (SUCCEEDED(hRet))
1410  {
1411  (*ppsaOut)->fFeatures = psa->fFeatures & ~ignored_copy_features;
1412  (*ppsaOut)->cbElements = psa->cbElements;
1413  }
1414  }
1415 
1416  if (SUCCEEDED(hRet))
1417  {
1418  /* Copy dimension bounds */
1419  memcpy((*ppsaOut)->rgsabound, psa->rgsabound, psa->cDims * sizeof(SAFEARRAYBOUND));
1420 
1421  (*ppsaOut)->pvData = SAFEARRAY_Malloc(SAFEARRAY_GetCellCount(psa) * psa->cbElements);
1422  if (!(*ppsaOut)->pvData)
1423  {
1424  SafeArrayDestroyDescriptor(*ppsaOut);
1425  *ppsaOut = NULL;
1426  return E_OUTOFMEMORY;
1427  }
1428 
1429  hRet = SAFEARRAY_CopyData(psa, *ppsaOut);
1430  if (FAILED(hRet))
1431  {
1432  SAFEARRAY_Free((*ppsaOut)->pvData);
1433  SafeArrayDestroyDescriptor(*ppsaOut);
1434  *ppsaOut = NULL;
1435  return hRet;
1436  }
1437  }
1438 
1439  return hRet;
1440 }
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
Definition: safearray.c:164
static const USHORT ignored_copy_features
Definition: safearray.c:90
static void SAFEARRAY_Free(void *ptr)
Definition: safearray.c:107
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
static HRESULT SAFEARRAY_CopyData(SAFEARRAY *psa, SAFEARRAY *dest)
Definition: safearray.c:351
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
HRESULT WINAPI SafeArrayDestroyDescriptor(SAFEARRAY *psa)
Definition: safearray.c:757
#define S_OK
Definition: intsafe.h:59
unsigned short VARTYPE
Definition: compat.h:1895
HRESULT WINAPI SafeArrayAllocDescriptorEx(VARTYPE vt, UINT cDims, SAFEARRAY **ppsaOut)
Definition: safearray.c:523
HRESULT WINAPI SafeArrayGetVartype(SAFEARRAY *psa, VARTYPE *pvt)
Definition: safearray.c:1536
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
static void * SAFEARRAY_Malloc(ULONG size)
Definition: safearray.c:98
VARTYPE vt
Definition: safearray.c:331
HRESULT WINAPI SafeArrayAllocDescriptor(UINT cDims, SAFEARRAY **ppsaOut)
Definition: safearray.c:478
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by create_vbarray(), IRecordInfoImpl_RecordCopy(), test_safearray(), test_SafeArrayCopy(), test_SafeArrayCopyData(), VARIANT_CoerceArray(), VariantCopy(), VariantCopyInd(), and VBArrayConstr_value().

◆ SafeArrayCopyData()

HRESULT WINAPI SafeArrayCopyData ( SAFEARRAY psaSource,
SAFEARRAY psaTarget 
)

Definition at line 1314 of file safearray.c.

1315 {
1316  int dim;
1317 
1318  TRACE("(%p,%p)\n", psaSource, psaTarget);
1319 
1320  if (!psaSource || !psaTarget ||
1321  psaSource->cDims != psaTarget->cDims ||
1322  psaSource->cbElements != psaTarget->cbElements)
1323  return E_INVALIDARG;
1324 
1325  /* Each dimension must be the same size */
1326  for (dim = psaSource->cDims - 1; dim >= 0 ; dim--)
1327  if (psaSource->rgsabound[dim].cElements !=
1328  psaTarget->rgsabound[dim].cElements)
1329  return E_INVALIDARG;
1330 
1331  return SAFEARRAY_CopyData(psaSource, psaTarget);
1332 }
ULONG cbElements
Definition: compat.h:1998
SAFEARRAYBOUND rgsabound[1]
Definition: compat.h:2001
#define E_INVALIDARG
Definition: ddrawi.h:101
USHORT cDims
Definition: compat.h:1996
static HRESULT SAFEARRAY_CopyData(SAFEARRAY *psa, SAFEARRAY *dest)
Definition: safearray.c:351
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by START_TEST(), test_SafeArrayCopyData(), and test_SafeArrayCreateEx().

◆ SafeArrayCreate()

SAFEARRAY* WINAPI SafeArrayCreate ( VARTYPE  vt,
UINT  cDims,
SAFEARRAYBOUND rgsabound 
)

◆ SafeArrayCreateEx()

SAFEARRAY* WINAPI SafeArrayCreateEx ( VARTYPE  vt,
UINT  cDims,
SAFEARRAYBOUND rgsabound,
LPVOID  pvExtra 
)

Definition at line 630 of file safearray.c.

631 {
632  ULONG ulSize = 0;
633  IRecordInfo* iRecInfo = pvExtra;
634  SAFEARRAY* psa;
635 
636  TRACE("(%d->%s,%d,%p,%p)\n", vt, debugstr_vt(vt), cDims, rgsabound, pvExtra);
637 
638  if (vt == VT_RECORD)
639  {
640  if (!iRecInfo)
641  return NULL;
642  IRecordInfo_GetSize(iRecInfo, &ulSize);
643  }
644  psa = SAFEARRAY_Create(vt, cDims, rgsabound, ulSize);
645 
646  if (pvExtra)
647  {
648  switch(vt)
649  {
650  case VT_RECORD:
651  SafeArraySetRecordInfo(psa, pvExtra);
652  break;
653  case VT_UNKNOWN:
654  case VT_DISPATCH:
655  SafeArraySetIID(psa, pvExtra);
656  break;
657  }
658  }
659  return psa;
660 }
static SAFEARRAY * SAFEARRAY_Create(VARTYPE vt, UINT cDims, const SAFEARRAYBOUND *rgsabound, ULONG ulSize)
Definition: safearray.c:220
HRESULT WINAPI SafeArraySetIID(SAFEARRAY *psa, REFGUID guid)
Definition: safearray.c:1643
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI SafeArraySetRecordInfo(SAFEARRAY *psa, IRecordInfo *pRinfo)
Definition: safearray.c:1576
#define TRACE(s)
Definition: solgame.cpp:4
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
unsigned int ULONG
Definition: retypes.h:1
VARTYPE vt
Definition: safearray.c:331

Referenced by LPSAFEARRAY_UserUnmarshal(), and START_TEST().

◆ SafeArrayCreateVector()

SAFEARRAY* WINAPI SafeArrayCreateVector ( VARTYPE  vt,
LONG  lLbound,
ULONG  cElements 
)

Definition at line 679 of file safearray.c.

680 {
681  TRACE("(%d->%s,%d,%d\n", vt, debugstr_vt(vt), lLbound, cElements);
682 
683  if (vt == VT_RECORD)
684  return NULL;
685 
686  return SAFEARRAY_CreateVector(vt, lLbound, cElements, SAFEARRAY_GetVTSize(vt));
687 }
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
static DWORD SAFEARRAY_GetVTSize(VARTYPE vt)
Definition: safearray.c:113
VARTYPE vt
Definition: safearray.c:331
static SAFEARRAY * SAFEARRAY_CreateVector(VARTYPE vt, LONG lLbound, ULONG cElements, ULONG ulSize)
Definition: safearray.c:254

Referenced by async_doc_navigate(), DocObjectService_FireBeforeNavigate2(), get_properties(), InitVariantFromBuffer(), make_safearray(), navigate_bsc(), CBandProxy::NavigateToPIDL(), START_TEST(), test_load(), test_put_nodeTypedValue(), test_SafeArrayCopy(), test_SafeArrayCopyData(), test_SafeArrayDestroyData(), to_bstr_array(), to_byte_array(), to_i4_array(), to_safearray(), and winhttp_request_get_ResponseBody().

◆ SafeArrayCreateVectorEx()

SAFEARRAY* WINAPI SafeArrayCreateVectorEx ( VARTYPE  vt,
LONG  lLbound,
ULONG  cElements,
LPVOID  pvExtra 
)

Definition at line 707 of file safearray.c.

708 {
709  ULONG ulSize;
710  IRecordInfo* iRecInfo = pvExtra;
711  SAFEARRAY* psa;
712 
713  TRACE("(%d->%s,%d,%d,%p\n", vt, debugstr_vt(vt), lLbound, cElements, pvExtra);
714 
715  if (vt == VT_RECORD)
716  {
717  if (!iRecInfo)
718  return NULL;
719  IRecordInfo_GetSize(iRecInfo, &ulSize);
720  }
721  else
722  ulSize = SAFEARRAY_GetVTSize(vt);
723 
724  psa = SAFEARRAY_CreateVector(vt, lLbound, cElements, ulSize);
725 
726  if (pvExtra)
727  {
728  switch(vt)
729  {
730  case VT_RECORD:
731  SafeArraySetRecordInfo(psa, iRecInfo);
732  break;
733  case VT_UNKNOWN:
734  case VT_DISPATCH:
735  SafeArraySetIID(psa, pvExtra);
736  break;
737  }
738  }
739  return psa;
740 }
HRESULT WINAPI SafeArraySetIID(SAFEARRAY *psa, REFGUID guid)
Definition: safearray.c:1643
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI SafeArraySetRecordInfo(SAFEARRAY *psa, IRecordInfo *pRinfo)
Definition: safearray.c:1576
#define TRACE(s)
Definition: solgame.cpp:4
static DWORD SAFEARRAY_GetVTSize(VARTYPE vt)
Definition: safearray.c:113
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
unsigned int ULONG
Definition: retypes.h:1
VARTYPE vt
Definition: safearray.c:331
static SAFEARRAY * SAFEARRAY_CreateVector(VARTYPE vt, LONG lLbound, ULONG cElements, ULONG ulSize)
Definition: safearray.c:254

◆ SafeArrayDestroy()

HRESULT WINAPI SafeArrayDestroy ( SAFEARRAY psa)

Definition at line 1349 of file safearray.c.

1350 {
1351  TRACE("(%p)\n", psa);
1352 
1353  if(!psa)
1354  return S_OK;
1355 
1356  if(psa->cLocks > 0)
1357  return DISP_E_ARRAYISLOCKED;
1358 
1359  /* Native doesn't check to see if the free succeeds */
1362  return S_OK;
1363 }
#define DISP_E_ARRAYISLOCKED
Definition: winerror.h:2522
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT WINAPI SafeArrayDestroyData(SAFEARRAY *psa)
Definition: safearray.c:1258
HRESULT WINAPI SafeArrayDestroyDescriptor(SAFEARRAY *psa)
Definition: safearray.c:757
#define S_OK
Definition: intsafe.h:59
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64

Referenced by check_for_VT_INT_PTR(), clean_props(), dictionary_Items(), dictionary_Keys(), doc_complex_write(), doc_navigate_task_destr(), doc_write(), DocObjectService_FireBeforeNavigate2(), FilterMapper3_RegisterFilter(), find_prop(), get_properties(), Global_Array(), handle_navigation_error(), InitVariantFromBuffer(), IRecordInfoImpl_RecordClear(), ITypeInfo_fnInvoke(), LPSAFEARRAY_UserFree(), LPSAFEARRAY_UserUnmarshal(), navigate_bsc(), release_exec(), test_GetNames(), test_GetProp(), test_LockUnlock(), test_marshal_LPSAFEARRAY(), test_marshal_safearray(), test_marshal_VARIANT(), test_parse_filter_data(), test_safearray(), test_safearray_layout(), test_SafeArrayAllocDestroyDescriptor(), test_SafeArrayChangeTypeEx(), test_SafeArrayClear(), test_SafeArrayCopy(), test_SafeArrayCopyData(), test_SafeArrayCreateEx(), test_SafeArrayCreateLockDestroy(), test_SafeArrayDestroyData(), test_SafeArrayGetPutElement(), test_SafeArrayGetPutElement_BSTR(), test_SafeArrayGetPutElement_IUnknown(), test_SafeArrayGetPutElement_VARIANT(), test_SafeArrayRedim_IUnknown(), test_saxreader(), test_VectorCreateLockDestroy(), to_bstr_array(), to_byte_array(), to_i4_array(), to_safearray(), VARIANT_ClearInd(), VariantClear(), VBArray_destructor(), Widget_safearray(), winhttp_request_get_ResponseBody(), and WshShell3_RegRead().

◆ SafeArrayDestroyData()

HRESULT WINAPI SafeArrayDestroyData ( SAFEARRAY psa)

Definition at line 1258 of file safearray.c.

1259 {
1260  HRESULT hr;
1261 
1262  TRACE("(%p)\n", psa);
1263 
1264  if (!psa)
1265  return E_INVALIDARG;
1266 
1267  if (psa->cLocks)
1268  return DISP_E_ARRAYISLOCKED; /* Can't delete a locked array */
1269 
1270  /* Delete the actual item data */
1272  if (FAILED(hr))
1273  return hr;
1274 
1275  if (psa->pvData)
1276  {
1277  if (psa->fFeatures & FADF_STATIC)
1278  {
1279  ZeroMemory(psa->pvData, SAFEARRAY_GetCellCount(psa) * psa->cbElements);
1280  return S_OK;
1281  }
1282  /* If this is not a vector, free the data memory block */
1283  if (!(psa->fFeatures & FADF_CREATEVECTOR))
1284  {
1285  SAFEARRAY_Free(psa->pvData);
1286  psa->pvData = NULL;
1287  }
1288  else
1289  psa->fFeatures |= FADF_DATADELETED; /* Mark the data deleted */
1290 
1291  }
1292  return S_OK;
1293 }
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
Definition: safearray.c:164
HRESULT hr
Definition: shlfolder.c:183
#define ZeroMemory
Definition: winbase.h:1642
static void SAFEARRAY_Free(void *ptr)
Definition: safearray.c:107
#define DISP_E_ARRAYISLOCKED
Definition: winerror.h:2522
const USHORT FADF_CREATEVECTOR
Definition: safearray.c:43
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
static HRESULT SAFEARRAY_DestroyData(SAFEARRAY *psa, ULONG ulStartCell)
Definition: safearray.c:285
#define S_OK
Definition: intsafe.h:59
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64

Referenced by LPSAFEARRAY_UserUnmarshal(), SafeArrayDestroy(), test_marshal_LPSAFEARRAY(), test_put_nodeTypedValue(), test_safearray(), test_SafeArrayCreateLockDestroy(), and test_SafeArrayDestroyData().

◆ SafeArrayDestroyDescriptor()

HRESULT WINAPI SafeArrayDestroyDescriptor ( SAFEARRAY psa)

Definition at line 757 of file safearray.c.

758 {
759  TRACE("(%p)\n", psa);
760 
761  if (psa)
762  {
763  LPVOID lpv = (char*)psa - SAFEARRAY_HIDDEN_SIZE;
764 
765  if (psa->cLocks)
766  return DISP_E_ARRAYISLOCKED; /* Can't destroy a locked array */
767 
768  if (psa->fFeatures & FADF_RECORD)
770 
771  if (psa->fFeatures & FADF_CREATEVECTOR &&
772  !(psa->fFeatures & FADF_DATADELETED))
773  SAFEARRAY_DestroyData(psa, 0); /* Data not previously deleted */
774 
775  SAFEARRAY_Free(lpv);
776  }
777  return S_OK;
778 }
static void SAFEARRAY_Free(void *ptr)
Definition: safearray.c:107
#define DISP_E_ARRAYISLOCKED
Definition: winerror.h:2522
const USHORT FADF_CREATEVECTOR
Definition: safearray.c:43
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI SafeArraySetRecordInfo(SAFEARRAY *psa, IRecordInfo *pRinfo)
Definition: safearray.c:1576
#define TRACE(s)
Definition: solgame.cpp:4
#define SAFEARRAY_HIDDEN_SIZE
Definition: safearray.c:86
static HRESULT SAFEARRAY_DestroyData(SAFEARRAY *psa, ULONG ulStartCell)
Definition: safearray.c:285
#define S_OK
Definition: intsafe.h:59
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64

Referenced by SAFEARRAY_Create(), SafeArrayCopy(), SafeArrayDestroy(), test_marshal_LPSAFEARRAY(), test_safearray(), test_SafeArrayAllocDestroyDescriptor(), test_SafeArrayCreateLockDestroy(), and test_SafeArrayDestroyData().

◆ SafeArrayGetDim()

UINT WINAPI SafeArrayGetDim ( SAFEARRAY psa)

Definition at line 1096 of file safearray.c.

1097 {
1098  TRACE("(%p) returning %d\n", psa, psa ? psa->cDims : 0u);
1099  return psa ? psa->cDims : 0;
1100 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define TRACE(s)
Definition: solgame.cpp:4
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64

Referenced by ClOleCommandTarget_Exec(), Host_Echo(), OleCommandTarget_Exec(), response_BinaryWrite(), test_InitPropVariantFromBuffer(), test_Keys(), test_marshal_VARIANT(), test_put_nodeTypedValue(), test_registry(), test_safearray(), test_SafeArrayAllocDestroyDescriptor(), test_SafeArrayCopyData(), test_SafeArrayCreateLockDestroy(), test_VectorCreateLockDestroy(), test_XMLHTTP(), VBArray_dimensions(), VBArray_getItem(), and VBArray_toArray().

◆ SafeArrayGetElement()

HRESULT WINAPI SafeArrayGetElement ( SAFEARRAY psa,
LONG rgIndices,
void pvData 
)

Definition at line 949 of file safearray.c.

950 {
951  HRESULT hRet;
952 
953  TRACE("(%p,%p,%p)\n", psa, rgIndices, pvData);
954 
955  if (!psa || !rgIndices || !pvData)
956  return E_INVALIDARG;
957 
958  hRet = SafeArrayLock(psa);
959 
960  if (SUCCEEDED(hRet))
961  {
962  PVOID lpvSrc;
963 
964  hRet = SafeArrayPtrOfIndex(psa, rgIndices, &lpvSrc);
965 
966  if (SUCCEEDED(hRet))
967  {
968  if (psa->fFeatures & FADF_VARIANT)
969  {
970  VARIANT* lpVariant = lpvSrc;
971  VARIANT* lpDest = pvData;
972 
973  /* The original content of pvData is ignored. */
974  V_VT(lpDest) = VT_EMPTY;
975  hRet = VariantCopy(lpDest, lpVariant);
976  if (FAILED(hRet)) FIXME("VariantCopy failed with 0x%x\n", hRet);
977  }
978  else if (psa->fFeatures & FADF_BSTR)
979  {
980  BSTR* lpBstr = lpvSrc;
981  BSTR* lpDest = pvData;
982 
983  if (*lpBstr)
984  {
985  *lpDest = SysAllocStringByteLen((char*)*lpBstr, SysStringByteLen(*lpBstr));
986  if (!*lpBstr)
987  hRet = E_OUTOFMEMORY;
988  }
989  else
990  *lpDest = NULL;
991  }
992  else if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
993  {
994  IUnknown **src_unk = lpvSrc;
995  IUnknown **dest_unk = pvData;
996 
997  if (*src_unk)
998  IUnknown_AddRef(*src_unk);
999  *dest_unk = *src_unk;
1000  }
1001  else if (psa->fFeatures & FADF_RECORD)
1002  {
1004 
1006  hRet = IRecordInfo_RecordCopy(record, lpvSrc, pvData);
1007  IRecordInfo_Release(record);
1008  }
1009  else
1010  /* Copy the data over */
1011  memcpy(pvData, lpvSrc, psa->cbElements);
1012  }
1014  }
1015  return hRet;
1016 }
HRESULT WINAPI SafeArrayGetRecordInfo(SAFEARRAY *psa, IRecordInfo **pRinfo)
Definition: safearray.c:1611
UINT WINAPI SysStringByteLen(BSTR str)
Definition: oleaut.c:218
OLECHAR * BSTR
Definition: compat.h:1934
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define FIXME(fmt,...)
Definition: debug.h:110
#define E_INVALIDARG
Definition: ddrawi.h:101
HRESULT WINAPI SafeArrayPtrOfIndex(SAFEARRAY *psa, LONG *rgIndices, void **ppvData)
Definition: safearray.c:1196
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3748
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI SafeArrayLock(SAFEARRAY *psa)
Definition: safearray.c:797
BSTR WINAPI DECLSPEC_HOTPATCH SysAllocStringByteLen(LPCSTR str, UINT len)
Definition: oleaut.c:431
HRESULT WINAPI SafeArrayUnlock(SAFEARRAY *psa)
Definition: safearray.c:833
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
#define V_VT(A)
Definition: oleauto.h:211
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
HRESULT WINAPI VariantCopy(VARIANTARG *pvargDest, VARIANTARG *pvargSrc)
Definition: variant.c:751
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by ClOleCommandTarget_Exec(), find_prop(), OleCommandTarget_Exec(), test_Keys(), test_marshal_LPSAFEARRAY(), test_registry(), test_safearray(), test_SafeArrayDestroyData(), test_SafeArrayGetPutElement(), test_SafeArrayGetPutElement_BSTR(), test_SafeArrayGetPutElement_IUnknown(), test_SafeArrayGetPutElement_VARIANT(), to_array(), and VBArray_getItem().

◆ SafeArrayGetElemsize()

UINT WINAPI SafeArrayGetElemsize ( SAFEARRAY psa)

Definition at line 1116 of file safearray.c.

1117 {
1118  TRACE("(%p) returning %d\n", psa, psa ? psa->cbElements : 0u);
1119  return psa ? psa->cbElements : 0;
1120 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define TRACE(s)
Definition: solgame.cpp:4
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64

Referenced by navigate_url(), test_safearray(), test_SafeArrayCopyData(), test_SafeArrayCreateLockDestroy(), and test_VectorCreateLockDestroy().

◆ SafeArrayGetIID()

HRESULT WINAPI SafeArrayGetIID ( SAFEARRAY psa,
GUID pGuid 
)

Definition at line 1672 of file safearray.c.

1673 {
1674  GUID* src = (GUID*)psa;
1675 
1676  TRACE("(%p,%p)\n", psa, pGuid);
1677 
1678  if (!psa || !pGuid || !(psa->fFeatures & FADF_HAVEIID))
1679  return E_INVALIDARG;
1680 
1681  *pGuid = src[-1];
1682  return S_OK;
1683 }
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRACE(s)
Definition: solgame.cpp:4
GLenum src
Definition: glext.h:6340
#define S_OK
Definition: intsafe.h:59
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64

Referenced by LPSAFEARRAY_UserMarshal(), SAFEARRAY_CopyData(), START_TEST(), test_safearray(), test_safearray_layout(), and test_SafeArrayCreateEx().

◆ SafeArrayGetLBound()

HRESULT WINAPI SafeArrayGetLBound ( SAFEARRAY psa,
UINT  nDim,
LONG plLbound 
)

Definition at line 1068 of file safearray.c.

1069 {
1070  TRACE("(%p,%d,%p)\n", psa, nDim, plLbound);
1071 
1072  if (!psa || !plLbound)
1073  return E_INVALIDARG;
1074 
1075  if(!nDim || nDim > psa->cDims)
1076  return DISP_E_BADINDEX;
1077 
1078  *plLbound = psa->rgsabound[psa->cDims - nDim].lLbound;
1079  return S_OK;
1080 }
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRACE(s)
Definition: solgame.cpp:4
#define S_OK
Definition: intsafe.h:59
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
#define DISP_E_BADINDEX
Definition: winerror.h:2520

Referenced by DEVENUM_IPropertyBag_Write(), Host_Echo(), OleCommandTarget_Exec(), response_BinaryWrite(), test_InitPropVariantFromBuffer(), test_marshal_VARIANT(), test_put_nodeTypedValue(), test_registry(), test_safearray(), test_Win32_SystemEnclosure(), test_XMLHTTP(), VBArray_lbound(), VBArray_toArray(), Widget_VarArg(), Widget_VarArg_Ref_Run(), and Widget_VarArg_Run().

◆ SafeArrayGetRecordInfo()

HRESULT WINAPI SafeArrayGetRecordInfo ( SAFEARRAY psa,
IRecordInfo **  pRinfo 
)

Definition at line 1611 of file safearray.c.

1612 {
1613  IRecordInfo** src = (IRecordInfo**)psa;
1614 
1615  TRACE("(%p,%p)\n", psa, pRinfo);
1616 
1617  if (!psa || !pRinfo || !(psa->fFeatures & FADF_RECORD))
1618  return E_INVALIDARG;
1619 
1620  *pRinfo = src[-1];
1621 
1622  if (*pRinfo)
1623  IRecordInfo_AddRef(*pRinfo);
1624  return S_OK;
1625 }
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRACE(s)
Definition: solgame.cpp:4
GLenum src
Definition: glext.h:6340
#define S_OK
Definition: intsafe.h:59
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64

Referenced by LPSAFEARRAY_UserMarshal(), LPSAFEARRAY_UserSize(), SAFEARRAY_CopyData(), SAFEARRAY_DestroyData(), SafeArrayGetElement(), SafeArrayPutElement(), and START_TEST().

◆ SafeArrayGetUBound()

HRESULT WINAPI SafeArrayGetUBound ( SAFEARRAY psa,
UINT  nDim,
LONG plUbound 
)

Definition at line 1035 of file safearray.c.

1036 {
1037  TRACE("(%p,%d,%p)\n", psa, nDim, plUbound);
1038 
1039  if (!psa || !plUbound)
1040  return E_INVALIDARG;
1041 
1042  if(!nDim || nDim > psa->cDims)
1043  return DISP_E_BADINDEX;
1044 
1045  *plUbound = psa->rgsabound[psa->cDims - nDim].lLbound +
1046  psa->rgsabound[psa->cDims - nDim].cElements - 1;
1047 
1048  return S_OK;
1049 }
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRACE(s)
Definition: solgame.cpp:4
#define S_OK
Definition: intsafe.h:59
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
#define DISP_E_BADINDEX
Definition: winerror.h:2520

Referenced by check_safearray(), DEVENUM_IPropertyBag_Write(), find_prop(), Global_UBound(), Host_Echo(), ITypeInfo_fnInvoke(), navigate_url(), OleCommandTarget_Exec(), request_send(), response_BinaryWrite(), test_InitPropVariantFromBuffer(), test_Keys(), test_marshal_VARIANT(), test_put_nodeTypedValue(), test_registry(), test_safearray(), test_Win32_SystemEnclosure(), to_array(), VBArray_toArray(), VBArray_ubound(), Widget_VarArg(), Widget_VarArg_Ref_Run(), and Widget_VarArg_Run().

◆ SafeArrayGetVartype()

HRESULT WINAPI SafeArrayGetVartype ( SAFEARRAY psa,
VARTYPE pvt 
)

Definition at line 1536 of file safearray.c.

1537 {
1538  TRACE("(%p,%p)\n", psa, pvt);
1539 
1540  if (!psa || !pvt)
1541  return E_INVALIDARG;
1542 
1543  if (psa->fFeatures & FADF_RECORD)
1544  *pvt = VT_RECORD;
1545  else if ((psa->fFeatures & (FADF_HAVEIID|FADF_DISPATCH)) == (FADF_HAVEIID|FADF_DISPATCH))
1546  *pvt = VT_DISPATCH;
1547  else if (psa->fFeatures & FADF_HAVEIID)
1548  *pvt = VT_UNKNOWN;
1549  else if (psa->fFeatures & FADF_HAVEVARTYPE)
1550  {
1552  *pvt = vt;
1553  }
1554  else
1555  return E_INVALIDARG;
1556 
1557  return S_OK;
1558 }
static DWORD SAFEARRAY_GetHiddenDWORD(SAFEARRAY *psa)
Definition: safearray.c:157
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRACE(s)
Definition: solgame.cpp:4
#define S_OK
Definition: intsafe.h:59
unsigned short VARTYPE
Definition: compat.h:1895
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
VARTYPE vt
Definition: safearray.c:331

Referenced by LPSAFEARRAY_UserMarshal(), SAFEARRAY_GetUnionType(), SafeArrayCopy(), START_TEST(), test_registry(), and to_array().

◆ SafeArrayLock()

HRESULT WINAPI SafeArrayLock ( SAFEARRAY psa)

Definition at line 797 of file safearray.c.

798 {
799  ULONG ulLocks;
800 
801  TRACE("(%p)\n", psa);
802 
803  if (!psa)
804  return E_INVALIDARG;
805 
806  ulLocks = InterlockedIncrement( (LONG*) &psa->cLocks);
807 
808  if (ulLocks > 0xffff) /* Maximum of 16384 locks at a time */
809  {
810  WARN("Out of locks!\n");
811  InterlockedDecrement( (LONG*) &psa->cLocks);
812  return E_UNEXPECTED;
813  }
814  return S_OK;
815 }
#define WARN(fmt,...)
Definition: debug.h:111
long LONG
Definition: pedump.c:60
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRACE(s)
Definition: solgame.cpp:4
#define InterlockedDecrement
Definition: armddk.h:52
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
#define E_UNEXPECTED
Definition: winerror.h:2456
unsigned int ULONG
Definition: retypes.h:1

Referenced by array_access(), create_safearray_iter(), SafeArrayAccessData(), SafeArrayGetElement(), SafeArrayPutElement(), SafeArrayRedim(), test_GetProp(), test_LockUnlock(), test_SafeArrayCreateLockDestroy(), and test_VectorCreateLockDestroy().

◆ SafeArrayPtrOfIndex()

HRESULT WINAPI SafeArrayPtrOfIndex ( SAFEARRAY psa,
LONG rgIndices,
void **  ppvData 
)

Definition at line 1196 of file safearray.c.

1197 {
1198  USHORT dim;
1199  ULONG cell = 0, dimensionSize = 1;
1200  SAFEARRAYBOUND* psab;
1201  LONG c1;
1202 
1203  TRACE("(%p,%p,%p)\n", psa, rgIndices, ppvData);
1204 
1205  /* The general formula for locating the cell number of an entry in an n
1206  * dimensional array (where cn = coordinate in dimension dn) is:
1207  *
1208  * c1 + c2 * sizeof(d1) + c3 * sizeof(d2) ... + cn * sizeof(c(n-1))
1209  *
1210  * We calculate the size of the last dimension at each step through the
1211  * dimensions to avoid recursing to calculate the last dimensions size.
1212  */
1213  if (!psa || !rgIndices || !ppvData)
1214  return E_INVALIDARG;
1215 
1216  psab = psa->rgsabound + psa->cDims - 1;
1217  c1 = *rgIndices++;
1218 
1219  if (c1 < psab->lLbound || c1 >= psab->lLbound + (LONG)psab->cElements)
1220  return DISP_E_BADINDEX; /* Initial index out of bounds */
1221 
1222  for (dim = 1; dim < psa->cDims; dim++)
1223  {
1224  dimensionSize *= psab->cElements;
1225 
1226  psab--;
1227 
1228  if (!psab->cElements ||
1229  *rgIndices < psab->lLbound ||
1230  *rgIndices >= psab->lLbound + (LONG)psab->cElements)
1231  return DISP_E_BADINDEX; /* Index out of bounds */
1232 
1233  cell += (*rgIndices - psab->lLbound) * dimensionSize;
1234  rgIndices++;
1235  }
1236 
1237  cell += (c1 - psa->rgsabound[psa->cDims - 1].lLbound);
1238 
1239  *ppvData = (char*)psa->pvData + cell * psa->cbElements;
1240  return S_OK;
1241 }
long LONG
Definition: pedump.c:60
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRACE(s)
Definition: solgame.cpp:4
#define S_OK
Definition: intsafe.h:59
unsigned short USHORT
Definition: pedump.c:61
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
unsigned int ULONG
Definition: retypes.h:1
#define DISP_E_BADINDEX
Definition: winerror.h:2520

Referenced by array_access(), SafeArrayGetElement(), SafeArrayPutElement(), and test_safearray().

◆ SafeArrayPutElement()

HRESULT WINAPI SafeArrayPutElement ( SAFEARRAY psa,
LONG rgIndices,
void pvData 
)

Definition at line 866 of file safearray.c.

867 {
868  HRESULT hRet;
869 
870  TRACE("(%p,%p,%p)\n", psa, rgIndices, pvData);
871 
872  if (!psa || !rgIndices)
873  return E_INVALIDARG;
874 
875  hRet = SafeArrayLock(psa);
876 
877  if (SUCCEEDED(hRet))
878  {
879  PVOID lpvDest;
880 
881  hRet = SafeArrayPtrOfIndex(psa, rgIndices, &lpvDest);
882 
883  if (SUCCEEDED(hRet))
884  {
885  if (psa->fFeatures & FADF_VARIANT)
886  {
887  VARIANT* lpVariant = pvData;
888  VARIANT* lpDest = lpvDest;
889 
890  hRet = VariantCopy(lpDest, lpVariant);
891  if (FAILED(hRet)) FIXME("VariantCopy failed with 0x%x\n", hRet);
892  }
893  else if (psa->fFeatures & FADF_BSTR)
894  {
895  BSTR lpBstr = (BSTR)pvData;
896  BSTR* lpDest = lpvDest;
897 
898  SysFreeString(*lpDest);
899 
900  *lpDest = SysAllocStringByteLen((char*)lpBstr, SysStringByteLen(lpBstr));
901  if (!*lpDest)
902  hRet = E_OUTOFMEMORY;
903  }
904  else if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
905  {
906  IUnknown *lpUnknown = pvData;
907  IUnknown **lpDest = lpvDest;
908 
909  if (lpUnknown)
910  IUnknown_AddRef(lpUnknown);
911  if (*lpDest)
912  IUnknown_Release(*lpDest);
913  *lpDest = lpUnknown;
914  }
915  else if (psa->fFeatures & FADF_RECORD)
916  {
918 
920  hRet = IRecordInfo_RecordCopy(record, pvData, lpvDest);
921  IRecordInfo_Release(record);
922  } else
923  /* Copy the data over */
924  memcpy(lpvDest, pvData, psa->cbElements);
925  }
927  }
928  return hRet;
929 }
HRESULT WINAPI SafeArrayGetRecordInfo(SAFEARRAY *psa, IRecordInfo **pRinfo)
Definition: safearray.c:1611
UINT WINAPI SysStringByteLen(BSTR str)
Definition: oleaut.c:218
OLECHAR * BSTR
Definition: compat.h:1934
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define FIXME(fmt,...)
Definition: debug.h:110
#define E_INVALIDARG
Definition: ddrawi.h:101
HRESULT WINAPI SafeArrayPtrOfIndex(SAFEARRAY *psa, LONG *rgIndices, void **ppvData)
Definition: safearray.c:1196
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3748
HRESULT WINAPI SafeArrayLock(SAFEARRAY *psa)
Definition: safearray.c:797
BSTR WINAPI DECLSPEC_HOTPATCH SysAllocStringByteLen(LPCSTR str, UINT len)
Definition: oleaut.c:431
HRESULT WINAPI SafeArrayUnlock(SAFEARRAY *psa)
Definition: safearray.c:833
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
HRESULT WINAPI VariantCopy(VARIANTARG *pvargDest, VARIANTARG *pvargSrc)
Definition: variant.c:751
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by get_properties(), handle_navigation_error(), test_marshal_LPSAFEARRAY(), test_SafeArrayDestroyData(), test_SafeArrayGetPutElement(), test_SafeArrayGetPutElement_BSTR(), test_SafeArrayGetPutElement_IUnknown(), test_SafeArrayGetPutElement_VARIANT(), test_SafeArrayRedim_IUnknown(), to_bstr_array(), to_i4_array(), and to_safearray().

◆ SafeArrayRedim()

HRESULT WINAPI SafeArrayRedim ( SAFEARRAY psa,
SAFEARRAYBOUND psabound 
)

Definition at line 1458 of file safearray.c.

1459 {
1460  SAFEARRAYBOUND *oldBounds;
1461  HRESULT hr;
1462 
1463  TRACE("(%p,%p)\n", psa, psabound);
1464 
1465  if (!psa || psa->fFeatures & FADF_FIXEDSIZE || !psabound)
1466  return E_INVALIDARG;
1467 
1468  if (psa->cLocks > 0)
1469  return DISP_E_ARRAYISLOCKED;
1470 
1471  hr = SafeArrayLock(psa);
1472  if (FAILED(hr))
1473  return hr;
1474 
1475  oldBounds = psa->rgsabound;
1476  oldBounds->lLbound = psabound->lLbound;
1477 
1478  if (psabound->cElements != oldBounds->cElements)
1479  {
1480  if (psabound->cElements < oldBounds->cElements)
1481  {
1482  /* Shorten the final dimension. */
1483  ULONG ulStartCell = psabound->cElements *
1484  (SAFEARRAY_GetCellCount(psa) / oldBounds->cElements);
1485  SAFEARRAY_DestroyData(psa, ulStartCell);
1486  }
1487  else
1488  {
1489  /* Lengthen the final dimension */
1490  ULONG ulOldSize, ulNewSize;
1491  PVOID pvNewData;
1492 
1493  ulOldSize = SAFEARRAY_GetCellCount(psa) * psa->cbElements;
1494  if (ulOldSize)
1495  ulNewSize = (ulOldSize / oldBounds->cElements) * psabound->cElements;
1496  else {
1497  int oldelems = oldBounds->cElements;
1498  oldBounds->cElements = psabound->cElements;
1499  ulNewSize = SAFEARRAY_GetCellCount(psa) * psa->cbElements;
1500  oldBounds->cElements = oldelems;
1501  }
1502 
1503  if (!(pvNewData = SAFEARRAY_Malloc(ulNewSize)))
1504  {
1506  return E_OUTOFMEMORY;
1507  }
1508 
1509  memcpy(pvNewData, psa->pvData, ulOldSize);
1510  SAFEARRAY_Free(psa->pvData);
1511  psa->pvData = pvNewData;
1512  }
1513  oldBounds->cElements = psabound->cElements;
1514  }
1515 
1517  return S_OK;
1518 }
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
Definition: safearray.c:164
HRESULT hr
Definition: shlfolder.c:183
static void SAFEARRAY_Free(void *ptr)
Definition: safearray.c:107
#define DISP_E_ARRAYISLOCKED
Definition: winerror.h:2522
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
HRESULT WINAPI SafeArrayLock(SAFEARRAY *psa)
Definition: safearray.c:797
HRESULT WINAPI SafeArrayUnlock(SAFEARRAY *psa)
Definition: safearray.c:833
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
static HRESULT SAFEARRAY_DestroyData(SAFEARRAY *psa, ULONG ulStartCell)
Definition: safearray.c:285
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define S_OK
Definition: intsafe.h:59
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
static void * SAFEARRAY_Malloc(ULONG size)
Definition: safearray.c:98
unsigned int ULONG
Definition: retypes.h:1

Referenced by test_safearray(), and test_SafeArrayRedim_IUnknown().

◆ SafeArraySetIID()

HRESULT WINAPI SafeArraySetIID ( SAFEARRAY psa,
REFGUID  guid 
)

Definition at line 1643 of file safearray.c.

1644 {
1645  GUID* dest = (GUID*)psa;
1646 
1647  TRACE("(%p,%s)\n", psa, debugstr_guid(guid));
1648 
1649  if (!psa || !guid || !(psa->fFeatures & FADF_HAVEIID))
1650  return E_INVALIDARG;
1651 
1652  dest[-1] = *guid;
1653  return S_OK;
1654 }
const GUID * guid
#define E_INVALIDARG
Definition: ddrawi.h:101
#define debugstr_guid
Definition: kernel32.h:35
#define TRACE(s)
Definition: solgame.cpp:4
#define S_OK
Definition: intsafe.h:59
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
static char * dest
Definition: rtl.c:135

Referenced by SAFEARRAY_CopyData(), SAFEARRAY_SetFeatures(), SafeArrayCreateEx(), SafeArrayCreateVectorEx(), test_safearray(), test_safearray_layout(), test_SafeArrayCreateEx(), and test_SafeArrayCreateLockDestroy().

◆ SafeArraySetRecordInfo()

HRESULT WINAPI SafeArraySetRecordInfo ( SAFEARRAY psa,
IRecordInfo pRinfo 
)

Definition at line 1576 of file safearray.c.

1577 {
1579 
1580  TRACE("(%p,%p)\n", psa, pRinfo);
1581 
1582  if (!psa || !(psa->fFeatures & FADF_RECORD))
1583  return E_INVALIDARG;
1584 
1585  if (pRinfo)
1586  IRecordInfo_AddRef(pRinfo);
1587 
1588  if (dest[-1])
1589  IRecordInfo_Release(dest[-1]);
1590 
1591  dest[-1] = pRinfo;
1592  return S_OK;
1593 }
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRACE(s)
Definition: solgame.cpp:4
#define S_OK
Definition: intsafe.h:59
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
static char * dest
Definition: rtl.c:135

Referenced by SAFEARRAY_CopyData(), SafeArrayCreateEx(), SafeArrayCreateVectorEx(), and SafeArrayDestroyDescriptor().

◆ SafeArrayUnaccessData()

◆ SafeArrayUnlock()

HRESULT WINAPI SafeArrayUnlock ( SAFEARRAY psa)

Definition at line 833 of file safearray.c.

834 {
835  TRACE("(%p)\n", psa);
836 
837  if (!psa)
838  return E_INVALIDARG;
839 
840  if (InterlockedDecrement( (LONG*) &psa->cLocks) < 0)
841  {
842  WARN("Unlocked but no lock held!\n");
843  InterlockedIncrement( (LONG*) &psa->cLocks);
844  return E_UNEXPECTED;
845  }
846  return S_OK;
847 }
#define WARN(fmt,...)
Definition: debug.h:111
long LONG
Definition: pedump.c:60
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRACE(s)
Definition: solgame.cpp:4
#define InterlockedDecrement
Definition: armddk.h:52
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
#define E_UNEXPECTED
Definition: winerror.h:2456

Referenced by array_access(), safearray_iter_IEnumVARIANT_Release(), SafeArrayGetElement(), SafeArrayPutElement(), SafeArrayRedim(), SafeArrayUnaccessData(), test_GetProp(), test_load(), test_LockUnlock(), test_SafeArrayCreateLockDestroy(), and test_VectorCreateLockDestroy().

◆ VectorFromBstr()

HRESULT WINAPI VectorFromBstr ( BSTR  bstr,
SAFEARRAY **  ppsa 
)

Definition at line 1701 of file safearray.c.

1702 {
1703  SAFEARRAYBOUND sab;
1704 
1705  TRACE("(%p,%p)\n", bstr, ppsa);
1706 
1707  if (!ppsa)
1708  return E_INVALIDARG;
1709 
1710  sab.lLbound = 0;
1711  sab.cElements = SysStringByteLen(bstr);
1712 
1713  *ppsa = SAFEARRAY_Create(VT_UI1, 1, &sab, 0);
1714 
1715  if (*ppsa)
1716  {
1717  memcpy((*ppsa)->pvData, bstr, sab.cElements);
1718  return S_OK;
1719  }
1720  return E_OUTOFMEMORY;
1721 }
static SAFEARRAY * SAFEARRAY_Create(VARTYPE vt, UINT cDims, const SAFEARRAYBOUND *rgsabound, ULONG ulSize)
Definition: safearray.c:220
UINT WINAPI SysStringByteLen(BSTR str)
Definition: oleaut.c:218
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRACE(s)
Definition: solgame.cpp:4
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define S_OK
Definition: intsafe.h:59

Referenced by VARIANT_CoerceArray().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( variant  )

Variable Documentation

◆ ignored_copy_features

const USHORT ignored_copy_features
static
Initial value:
=
FADF_AUTO |
FADF_STATIC |
FADF_EMBEDDED |
FADF_FIXEDSIZE |
const USHORT FADF_CREATEVECTOR
Definition: safearray.c:43

Definition at line 90 of file safearray.c.

Referenced by SAFEARRAY_CopyData(), and SafeArrayCopy().