ReactOS  0.4.14-dev-583-g2a1ba2c
safearray.c File Reference
#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 38 of file safearray.c.

◆ SAFEARRAY_HIDDEN_SIZE

#define SAFEARRAY_HIDDEN_SIZE   sizeof(GUID)

Definition at line 84 of file safearray.c.

Function Documentation

◆ BstrFromVector()

HRESULT WINAPI BstrFromVector ( SAFEARRAY psa,
BSTR pbstr 
)

Definition at line 1740 of file safearray.c.

1741 {
1742  TRACE("(%p,%p)\n", psa, pbstr);
1743 
1744  if (!pbstr)
1745  return E_INVALIDARG;
1746 
1747  *pbstr = NULL;
1748 
1749  if (!psa || psa->cbElements != 1 || psa->cDims != 1)
1750  return E_INVALIDARG;
1751 
1752  *pbstr = SysAllocStringByteLen(psa->pvData, psa->rgsabound[0].cElements);
1753  if (!*pbstr)
1754  return E_OUTOFMEMORY;
1755  return S_OK;
1756 }
#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:428
#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 180 of file safearray.c.

181 {
182  char *ptr = SAFEARRAY_Malloc(ulSize + SAFEARRAY_HIDDEN_SIZE);
183 
184  if (!ptr)
185  {
186  *ppsaOut = NULL;
187  return E_OUTOFMEMORY;
188  }
189 
190  *ppsaOut = (SAFEARRAY*)(ptr + SAFEARRAY_HIDDEN_SIZE);
191  return S_OK;
192 }
#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:84
#define S_OK
Definition: intsafe.h:59
static void * SAFEARRAY_Malloc(ULONG size)
Definition: safearray.c:96

Referenced by SAFEARRAY_CreateVector(), and SafeArrayAllocDescriptor().

◆ SAFEARRAY_CopyData()

static HRESULT SAFEARRAY_CopyData ( SAFEARRAY psa,
SAFEARRAY dest 
)
static

Definition at line 349 of file safearray.c.

350 {
351  HRESULT hr = S_OK;
352 
353  if (!psa->pvData)
354  return S_OK;
355 
356  if (!dest->pvData || psa->fFeatures & FADF_DATADELETED)
357  return E_INVALIDARG;
358  else
359  {
360  ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
361 
362  dest->fFeatures = (dest->fFeatures & FADF_CREATEVECTOR) | (psa->fFeatures & ~ignored_copy_features);
363 
364  if (psa->fFeatures & FADF_VARIANT)
365  {
366  VARIANT *src_var = psa->pvData;
367  VARIANT *dest_var = dest->pvData;
368 
369  while(ulCellCount--)
370  {
371  HRESULT hRet;
372 
373  /* destination is cleared automatically */
374  hRet = VariantCopy(dest_var, src_var);
375  if (FAILED(hRet)) FIXME("VariantCopy failed with 0x%08x, element %u\n", hRet, ulCellCount);
376  src_var++;
377  dest_var++;
378  }
379  }
380  else if (psa->fFeatures & FADF_BSTR)
381  {
382  BSTR *src_bstr = psa->pvData;
383  BSTR *dest_bstr = dest->pvData;
384 
385  while(ulCellCount--)
386  {
387  SysFreeString(*dest_bstr);
388  if (*src_bstr)
389  {
390  *dest_bstr = SysAllocStringByteLen((char*)*src_bstr, SysStringByteLen(*src_bstr));
391  if (!*dest_bstr)
392  return E_OUTOFMEMORY;
393  }
394  else
395  *dest_bstr = NULL;
396  src_bstr++;
397  dest_bstr++;
398  }
399  }
400  else if (psa->fFeatures & FADF_RECORD)
401  {
402  BYTE *dest_data = dest->pvData;
403  BYTE *src_data = psa->pvData;
405 
407  while (ulCellCount--)
408  {
409  /* RecordCopy() clears destination record */
410  hr = IRecordInfo_RecordCopy(record, src_data, dest_data);
411  if (FAILED(hr)) break;
412  src_data += psa->cbElements;
413  dest_data += psa->cbElements;
414  }
415 
417  /* This value is set to 32 bytes by default on descriptor creation,
418  update with actual structure size. */
419  dest->cbElements = psa->cbElements;
420  IRecordInfo_Release(record);
421  }
422  else if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
423  {
424  IUnknown **dest_unk = dest->pvData;
425  IUnknown **src_unk = psa->pvData;
426 
427  /* release old iface, addref new one */
428  while (ulCellCount--)
429  {
430  if (*dest_unk)
431  IUnknown_Release(*dest_unk);
432  *dest_unk = *src_unk;
433  if (*dest_unk)
434  IUnknown_AddRef(*dest_unk);
435  src_unk++;
436  dest_unk++;
437  }
438  }
439  else
440  {
441  /* Copy the data over */
442  memcpy(dest->pvData, psa->pvData, ulCellCount * psa->cbElements);
443  }
444 
445  if (psa->fFeatures & FADF_HAVEIID)
446  {
447  GUID guid;
450  }
451  else if (psa->fFeatures & FADF_HAVEVARTYPE)
452  {
454  }
455  }
456 
457  return hr;
458 }
static void SAFEARRAY_SetHiddenDWORD(SAFEARRAY *psa, DWORD dw)
Definition: safearray.c:147
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
Definition: safearray.c:162
static const USHORT ignored_copy_features
Definition: safearray.c:88
HRESULT WINAPI SafeArrayGetRecordInfo(SAFEARRAY *psa, IRecordInfo **pRinfo)
Definition: safearray.c:1609
HRESULT hr
Definition: shlfolder.c:183
UINT WINAPI SysStringByteLen(BSTR str)
Definition: oleaut.c:215
OLECHAR * BSTR
Definition: compat.h:1942
const USHORT FADF_CREATEVECTOR
Definition: safearray.c:43
const GUID * guid
HRESULT WINAPI SafeArraySetIID(SAFEARRAY *psa, REFGUID guid)
Definition: safearray.c:1641
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static DWORD SAFEARRAY_GetHiddenDWORD(SAFEARRAY *psa)
Definition: safearray.c:155
#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:1574
BSTR WINAPI DECLSPEC_HOTPATCH SysAllocStringByteLen(LPCSTR str, UINT len)
Definition: oleaut.c:428
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:1670
#define S_OK
Definition: intsafe.h:59
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
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:748

Referenced by SafeArrayCopy(), and SafeArrayCopyData().

◆ SAFEARRAY_Create()

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

Definition at line 218 of file safearray.c.

219 {
220  SAFEARRAY *psa = NULL;
221  unsigned int i;
222 
223  if (!rgsabound)
224  return NULL;
225 
227  {
228  switch (vt)
229  {
230  case VT_BSTR: psa->fFeatures |= FADF_BSTR; break;
231  case VT_UNKNOWN: psa->fFeatures |= FADF_UNKNOWN; break;
232  case VT_DISPATCH: psa->fFeatures |= FADF_DISPATCH; break;
233  case VT_VARIANT: psa->fFeatures |= FADF_VARIANT; break;
234  }
235 
236  for (i = 0; i < cDims; i++)
237  memcpy(psa->rgsabound + i, rgsabound + cDims - 1 - i, sizeof(SAFEARRAYBOUND));
238 
239  if (ulSize)
240  psa->cbElements = ulSize;
241 
242  if (!psa->cbElements || FAILED(SafeArrayAllocData(psa)))
243  {
245  psa = NULL;
246  }
247  }
248  return psa;
249 }
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:557
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
HRESULT WINAPI SafeArrayDestroyDescriptor(SAFEARRAY *psa)
Definition: safearray.c:755
HRESULT WINAPI SafeArrayAllocDescriptorEx(VARTYPE vt, UINT cDims, SAFEARRAY **ppsaOut)
Definition: safearray.c:521
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 252 of file safearray.c.

253 {
254  SAFEARRAY *psa = NULL;
255 
256  if (ulSize || (vt == VT_RECORD))
257  {
258  /* Allocate the header and data together */
259  if (SUCCEEDED(SAFEARRAY_AllocDescriptor(sizeof(SAFEARRAY) + ulSize * cElements, &psa)))
260  {
262 
263  psa->cDims = 1;
264  psa->fFeatures |= FADF_CREATEVECTOR;
265  psa->pvData = &psa[1]; /* Data follows the header */
266  psa->cbElements = ulSize;
267  psa->rgsabound[0].cElements = cElements;
268  psa->rgsabound[0].lLbound = lLbound;
269 
270  switch (vt)
271  {
272  case VT_BSTR: psa->fFeatures |= FADF_BSTR; break;
273  case VT_UNKNOWN: psa->fFeatures |= FADF_UNKNOWN; break;
274  case VT_DISPATCH: psa->fFeatures |= FADF_DISPATCH; break;
275  case VT_VARIANT: psa->fFeatures |= FADF_VARIANT; break;
276  }
277  }
278  }
279  return psa;
280 }
static void SAFEARRAY_SetFeatures(VARTYPE vt, SAFEARRAY *psa)
Definition: safearray.c:195
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:180
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 283 of file safearray.c.

284 {
285  if (psa->pvData && !(psa->fFeatures & FADF_DATADELETED))
286  {
287  ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
288 
289  if (ulStartCell > ulCellCount) {
290  FIXME("unexpected ulCellCount %d, start %d\n",ulCellCount,ulStartCell);
291  return E_UNEXPECTED;
292  }
293 
294  ulCellCount -= ulStartCell;
295 
296  if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
297  {
298  LPUNKNOWN *lpUnknown = (LPUNKNOWN *)psa->pvData + ulStartCell;
299 
300  while(ulCellCount--)
301  {
302  if (*lpUnknown)
303  IUnknown_Release(*lpUnknown);
304  lpUnknown++;
305  }
306  }
307  else if (psa->fFeatures & FADF_RECORD)
308  {
309  IRecordInfo *lpRecInfo;
310 
311  if (SUCCEEDED(SafeArrayGetRecordInfo(psa, &lpRecInfo)))
312  {
313  PBYTE pRecordData = psa->pvData;
314  while(ulCellCount--)
315  {
316  IRecordInfo_RecordClear(lpRecInfo, pRecordData);
317  pRecordData += psa->cbElements;
318  }
319  IRecordInfo_Release(lpRecInfo);
320  }
321  }
322  else if (psa->fFeatures & FADF_BSTR)
323  {
324  BSTR* lpBstr = (BSTR*)psa->pvData + ulStartCell;
325 
326  while(ulCellCount--)
327  {
328  SysFreeString(*lpBstr);
329  lpBstr++;
330  }
331  }
332  else if (psa->fFeatures & FADF_VARIANT)
333  {
334  VARIANT* lpVariant = (VARIANT*)psa->pvData + ulStartCell;
335 
336  while(ulCellCount--)
337  {
338  HRESULT hRet = VariantClear(lpVariant);
339 
340  if (FAILED(hRet)) FIXME("VariantClear of element failed!\n");
341  lpVariant++;
342  }
343  }
344  }
345  return S_OK;
346 }
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
Definition: safearray.c:162
HRESULT WINAPI SafeArrayGetRecordInfo(SAFEARRAY *psa, IRecordInfo **pRinfo)
Definition: safearray.c:1609
OLECHAR * BSTR
Definition: compat.h:1942
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:648
#define S_OK
Definition: intsafe.h:59
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
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 105 of file safearray.c.

106 {
108 }
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:420
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 162 of file safearray.c.

163 {
164  const SAFEARRAYBOUND* psab = psa->rgsabound;
165  USHORT cCount = psa->cDims;
166  ULONG ulNumCells = 1;
167 
168  while (cCount--)
169  {
170  /* This is a valid bordercase. See testcases. -Marcus */
171  if (!psab->cElements)
172  return 0;
173  ulNumCells *= psab->cElements;
174  psab++;
175  }
176  return ulNumCells;
177 }
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 155 of file safearray.c.

156 {
157  LPDWORD lpDw = (LPDWORD)psa;
158  return lpDw[-1];
159 }
#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 111 of file safearray.c.

112 {
113  switch (vt)
114  {
115  case VT_I1:
116  case VT_UI1: return sizeof(BYTE);
117  case VT_BOOL:
118  case VT_I2:
119  case VT_UI2: return sizeof(SHORT);
120  case VT_I4:
121  case VT_UI4:
122  case VT_R4:
123  case VT_ERROR: return sizeof(LONG);
124  case VT_R8:
125  case VT_I8:
126  case VT_UI8: return sizeof(LONG64);
127  case VT_INT:
128  case VT_UINT: return sizeof(INT);
129  case VT_INT_PTR:
130  case VT_UINT_PTR: return sizeof(UINT_PTR);
131  case VT_CY: return sizeof(CY);
132  case VT_DATE: return sizeof(DATE);
133  case VT_BSTR: return sizeof(BSTR);
134  case VT_DISPATCH: return sizeof(LPDISPATCH);
135  case VT_VARIANT: return sizeof(VARIANT);
136  case VT_UNKNOWN: return sizeof(LPUNKNOWN);
137  case VT_DECIMAL: return sizeof(DECIMAL);
138  /* Note: Return a non-zero size to indicate vt is valid. The actual size
139  * of a UDT is taken from the result of IRecordInfo_GetSize().
140  */
141  case VT_RECORD: return 32;
142  }
143  return 0;
144 }
unsigned __int3264 UINT_PTR
Definition: activex.cpp:275
struct tagVARIANT VARIANT
Definition: compat.h:2026
Definition: compat.h:1947
Definition: compat.h:1963
Definition: compat.h:1959
#define INT
Definition: polytest.cpp:20
double DATE
Definition: compat.h:1902
OLECHAR * BSTR
Definition: compat.h:1942
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:1948
unsigned char BYTE
Definition: mem.h:68
Definition: compat.h:1950
struct tagDEC DECIMAL
VARTYPE vt
Definition: safearray.c:331
Definition: compat.h:1949
Definition: compat.h:1946

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

◆ SAFEARRAY_Malloc()

static void* SAFEARRAY_Malloc ( ULONG  size)
inlinestatic

Definition at line 96 of file safearray.c.

97 {
98  void *ret = CoTaskMemAlloc(size);
99  if (ret)
100  memset(ret, 0, size);
101  return ret;
102 }
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:404

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

◆ SAFEARRAY_SetFeatures()

static void SAFEARRAY_SetFeatures ( VARTYPE  vt,
SAFEARRAY psa 
)
static

Definition at line 195 of file safearray.c.

196 {
197  /* Set the IID if we have one, otherwise set the type */
198  if (vt == VT_DISPATCH)
199  {
200  psa->fFeatures = FADF_HAVEIID;
202  }
203  else if (vt == VT_UNKNOWN)
204  {
205  psa->fFeatures = FADF_HAVEIID;
207  }
208  else if (vt == VT_RECORD)
209  psa->fFeatures = FADF_RECORD;
210  else
211  {
212  psa->fFeatures = FADF_HAVEVARTYPE;
214  }
215 }
static void SAFEARRAY_SetHiddenDWORD(SAFEARRAY *psa, DWORD dw)
Definition: safearray.c:147
HRESULT WINAPI SafeArraySetIID(SAFEARRAY *psa, REFGUID guid)
Definition: safearray.c:1641
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 147 of file safearray.c.

148 {
149  /* Implementation data is stored in the 4 bytes before the header */
150  LPDWORD lpDw = (LPDWORD)psa;
151  lpDw[-1] = dw;
152 }
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 1137 of file safearray.c.

1138 {
1139  HRESULT hr;
1140 
1141  TRACE("(%p,%p)\n", psa, ppvData);
1142 
1143  if(!psa || !ppvData)
1144  return E_INVALIDARG;
1145 
1146  hr = SafeArrayLock(psa);
1147  *ppvData = SUCCEEDED(hr) ? psa->pvData : NULL;
1148 
1149  return hr;
1150 }
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:795
#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_PropVariantToBuffer(), 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 557 of file safearray.c.

558 {
559  HRESULT hRet = E_INVALIDARG;
560 
561  TRACE("(%p)\n", psa);
562 
563  if (psa)
564  {
565  ULONG ulSize = SAFEARRAY_GetCellCount(psa);
566 
567  psa->pvData = SAFEARRAY_Malloc(ulSize * psa->cbElements);
568 
569  if (psa->pvData)
570  {
571  hRet = S_OK;
572  TRACE("%u bytes allocated for data at %p (%u objects).\n",
573  ulSize * psa->cbElements, psa->pvData, ulSize);
574  }
575  else
576  hRet = E_OUTOFMEMORY;
577  }
578  return hRet;
579 }
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
Definition: safearray.c:162
#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:96
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 476 of file safearray.c.

477 {
478  LONG allocSize;
479  HRESULT hr;
480 
481  TRACE("(%d,%p)\n", cDims, ppsaOut);
482 
483  if (!cDims || cDims >= 0x10000) /* Maximum 65535 dimensions */
484  return E_INVALIDARG;
485 
486  if (!ppsaOut)
487  return E_POINTER;
488 
489  /* We need enough space for the header and its bounds */
490  allocSize = sizeof(SAFEARRAY) + sizeof(SAFEARRAYBOUND) * (cDims - 1);
491 
492  hr = SAFEARRAY_AllocDescriptor(allocSize, ppsaOut);
493  if (FAILED(hr))
494  return hr;
495 
496  (*ppsaOut)->cDims = cDims;
497 
498  TRACE("(%d): %u bytes allocated for descriptor.\n", cDims, allocSize);
499  return S_OK;
500 }
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:180
#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 521 of file safearray.c.

522 {
523  ULONG cbElements;
524  HRESULT hRet;
525 
526  TRACE("(%s,%u,%p)\n", debugstr_vt(vt), cDims, ppsaOut);
527 
528  cbElements = SAFEARRAY_GetVTSize(vt);
529  if (!cbElements)
530  WARN("Creating a descriptor with an invalid VARTYPE!\n");
531 
532  hRet = SafeArrayAllocDescriptor(cDims, ppsaOut);
533 
534  if (SUCCEEDED(hRet))
535  {
536  SAFEARRAY_SetFeatures(vt, *ppsaOut);
537  (*ppsaOut)->cbElements = cbElements;
538  }
539  return hRet;
540 }
#define WARN(fmt,...)
Definition: debug.h:111
static void SAFEARRAY_SetFeatures(VARTYPE vt, SAFEARRAY *psa)
Definition: safearray.c:195
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
static DWORD SAFEARRAY_GetVTSize(VARTYPE vt)
Definition: safearray.c:111
unsigned int ULONG
Definition: retypes.h:1
VARTYPE vt
Definition: safearray.c:331
HRESULT WINAPI SafeArrayAllocDescriptor(UINT cDims, SAFEARRAY **ppsaOut)
Definition: safearray.c:476
#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 1379 of file safearray.c.

1380 {
1381  HRESULT hRet;
1382 
1383  TRACE("(%p,%p)\n", psa, ppsaOut);
1384 
1385  if (!ppsaOut)
1386  return E_INVALIDARG;
1387 
1388  *ppsaOut = NULL;
1389 
1390  if (!psa)
1391  return S_OK; /* Handles copying of NULL arrays */
1392 
1393  if (!psa->cbElements)
1394  return E_INVALIDARG;
1395 
1396  if (psa->fFeatures & (FADF_RECORD|FADF_HAVEIID|FADF_HAVEVARTYPE))
1397  {
1398  VARTYPE vt;
1399 
1400  hRet = SafeArrayGetVartype(psa, &vt);
1401  if (SUCCEEDED(hRet))
1402  hRet = SafeArrayAllocDescriptorEx(vt, psa->cDims, ppsaOut);
1403  }
1404  else
1405  {
1406  hRet = SafeArrayAllocDescriptor(psa->cDims, ppsaOut);
1407  if (SUCCEEDED(hRet))
1408  {
1409  (*ppsaOut)->fFeatures = psa->fFeatures & ~ignored_copy_features;
1410  (*ppsaOut)->cbElements = psa->cbElements;
1411  }
1412  }
1413 
1414  if (SUCCEEDED(hRet))
1415  {
1416  /* Copy dimension bounds */
1417  memcpy((*ppsaOut)->rgsabound, psa->rgsabound, psa->cDims * sizeof(SAFEARRAYBOUND));
1418 
1419  (*ppsaOut)->pvData = SAFEARRAY_Malloc(SAFEARRAY_GetCellCount(psa) * psa->cbElements);
1420  if (!(*ppsaOut)->pvData)
1421  {
1422  SafeArrayDestroyDescriptor(*ppsaOut);
1423  *ppsaOut = NULL;
1424  return E_OUTOFMEMORY;
1425  }
1426 
1427  hRet = SAFEARRAY_CopyData(psa, *ppsaOut);
1428  if (FAILED(hRet))
1429  {
1430  SAFEARRAY_Free((*ppsaOut)->pvData);
1431  SafeArrayDestroyDescriptor(*ppsaOut);
1432  *ppsaOut = NULL;
1433  return hRet;
1434  }
1435  }
1436 
1437  return hRet;
1438 }
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
Definition: safearray.c:162
static const USHORT ignored_copy_features
Definition: safearray.c:88
static void SAFEARRAY_Free(void *ptr)
Definition: safearray.c:105
#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:349
#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:755
#define S_OK
Definition: intsafe.h:59
unsigned short VARTYPE
Definition: compat.h:1903
HRESULT WINAPI SafeArrayAllocDescriptorEx(VARTYPE vt, UINT cDims, SAFEARRAY **ppsaOut)
Definition: safearray.c:521
HRESULT WINAPI SafeArrayGetVartype(SAFEARRAY *psa, VARTYPE *pvt)
Definition: safearray.c:1534
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
static void * SAFEARRAY_Malloc(ULONG size)
Definition: safearray.c:96
VARTYPE vt
Definition: safearray.c:331
HRESULT WINAPI SafeArrayAllocDescriptor(UINT cDims, SAFEARRAY **ppsaOut)
Definition: safearray.c:476
#define SUCCEEDED(hr)
Definition: intsafe.h:57

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

◆ SafeArrayCopyData()

HRESULT WINAPI SafeArrayCopyData ( SAFEARRAY psaSource,
SAFEARRAY psaTarget 
)

Definition at line 1312 of file safearray.c.

1313 {
1314  int dim;
1315 
1316  TRACE("(%p,%p)\n", psaSource, psaTarget);
1317 
1318  if (!psaSource || !psaTarget ||
1319  psaSource->cDims != psaTarget->cDims ||
1320  psaSource->cbElements != psaTarget->cbElements)
1321  return E_INVALIDARG;
1322 
1323  /* Each dimension must be the same size */
1324  for (dim = psaSource->cDims - 1; dim >= 0 ; dim--)
1325  if (psaSource->rgsabound[dim].cElements !=
1326  psaTarget->rgsabound[dim].cElements)
1327  return E_INVALIDARG;
1328 
1329  return SAFEARRAY_CopyData(psaSource, psaTarget);
1330 }
ULONG cbElements
Definition: compat.h:2006
SAFEARRAYBOUND rgsabound[1]
Definition: compat.h:2009
#define E_INVALIDARG
Definition: ddrawi.h:101
USHORT cDims
Definition: compat.h:2004
static HRESULT SAFEARRAY_CopyData(SAFEARRAY *psa, SAFEARRAY *dest)
Definition: safearray.c:349
#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 628 of file safearray.c.

629 {
630  ULONG ulSize = 0;
631  IRecordInfo* iRecInfo = pvExtra;
632  SAFEARRAY* psa;
633 
634  TRACE("(%s,%u,%p,%p)\n", debugstr_vt(vt), cDims, rgsabound, pvExtra);
635 
636  if (vt == VT_RECORD)
637  {
638  if (!iRecInfo)
639  return NULL;
640  IRecordInfo_GetSize(iRecInfo, &ulSize);
641  }
642  psa = SAFEARRAY_Create(vt, cDims, rgsabound, ulSize);
643 
644  if (pvExtra)
645  {
646  switch(vt)
647  {
648  case VT_RECORD:
649  SafeArraySetRecordInfo(psa, pvExtra);
650  break;
651  case VT_UNKNOWN:
652  case VT_DISPATCH:
653  SafeArraySetIID(psa, pvExtra);
654  break;
655  }
656  }
657  return psa;
658 }
static SAFEARRAY * SAFEARRAY_Create(VARTYPE vt, UINT cDims, const SAFEARRAYBOUND *rgsabound, ULONG ulSize)
Definition: safearray.c:218
HRESULT WINAPI SafeArraySetIID(SAFEARRAY *psa, REFGUID guid)
Definition: safearray.c:1641
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI SafeArraySetRecordInfo(SAFEARRAY *psa, IRecordInfo *pRinfo)
Definition: safearray.c:1574
#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 677 of file safearray.c.

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

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 705 of file safearray.c.

706 {
707  ULONG ulSize;
708  IRecordInfo* iRecInfo = pvExtra;
709  SAFEARRAY* psa;
710 
711  TRACE("(%s,%d,%u,%p)\n", debugstr_vt(vt), lLbound, cElements, pvExtra);
712 
713  if (vt == VT_RECORD)
714  {
715  if (!iRecInfo)
716  return NULL;
717  IRecordInfo_GetSize(iRecInfo, &ulSize);
718  }
719  else
720  ulSize = SAFEARRAY_GetVTSize(vt);
721 
722  psa = SAFEARRAY_CreateVector(vt, lLbound, cElements, ulSize);
723 
724  if (pvExtra)
725  {
726  switch(vt)
727  {
728  case VT_RECORD:
729  SafeArraySetRecordInfo(psa, iRecInfo);
730  break;
731  case VT_UNKNOWN:
732  case VT_DISPATCH:
733  SafeArraySetIID(psa, pvExtra);
734  break;
735  }
736  }
737  return psa;
738 }
HRESULT WINAPI SafeArraySetIID(SAFEARRAY *psa, REFGUID guid)
Definition: safearray.c:1641
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI SafeArraySetRecordInfo(SAFEARRAY *psa, IRecordInfo *pRinfo)
Definition: safearray.c:1574
#define TRACE(s)
Definition: solgame.cpp:4
static DWORD SAFEARRAY_GetVTSize(VARTYPE vt)
Definition: safearray.c:111
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:252

◆ SafeArrayDestroy()

HRESULT WINAPI SafeArrayDestroy ( SAFEARRAY psa)

Definition at line 1347 of file safearray.c.

1348 {
1349  TRACE("(%p)\n", psa);
1350 
1351  if(!psa)
1352  return S_OK;
1353 
1354  if(psa->cLocks > 0)
1355  return DISP_E_ARRAYISLOCKED;
1356 
1357  /* Native doesn't check to see if the free succeeds */
1360  return S_OK;
1361 }
#define DISP_E_ARRAYISLOCKED
Definition: winerror.h:2522
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT WINAPI SafeArrayDestroyData(SAFEARRAY *psa)
Definition: safearray.c:1256
HRESULT WINAPI SafeArrayDestroyDescriptor(SAFEARRAY *psa)
Definition: safearray.c:755
#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(), exec_query(), FilterMapper3_RegisterFilter(), find_prop(), get_properties(), Global_Array(), handle_navigation_error(), InitVariantFromBuffer(), IRecordInfoImpl_RecordClear(), ITypeInfo_fnInvoke(), LPSAFEARRAY_UserFree(), LPSAFEARRAY_UserUnmarshal(), navigate_bsc(), PropVariantClear(), 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 1256 of file safearray.c.

1257 {
1258  HRESULT hr;
1259 
1260  TRACE("(%p)\n", psa);
1261 
1262  if (!psa)
1263  return E_INVALIDARG;
1264 
1265  if (psa->cLocks)
1266  return DISP_E_ARRAYISLOCKED; /* Can't delete a locked array */
1267 
1268  /* Delete the actual item data */
1270  if (FAILED(hr))
1271  return hr;
1272 
1273  if (psa->pvData)
1274  {
1275  if (psa->fFeatures & FADF_STATIC)
1276  {
1277  ZeroMemory(psa->pvData, SAFEARRAY_GetCellCount(psa) * psa->cbElements);
1278  return S_OK;
1279  }
1280  /* If this is not a vector, free the data memory block */
1281  if (!(psa->fFeatures & FADF_CREATEVECTOR))
1282  {
1283  SAFEARRAY_Free(psa->pvData);
1284  psa->pvData = NULL;
1285  }
1286  else
1287  psa->fFeatures |= FADF_DATADELETED; /* Mark the data deleted */
1288 
1289  }
1290  return S_OK;
1291 }
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
Definition: safearray.c:162
HRESULT hr
Definition: shlfolder.c:183
#define ZeroMemory
Definition: winbase.h:1642
static void SAFEARRAY_Free(void *ptr)
Definition: safearray.c:105
#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:283
#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 755 of file safearray.c.

756 {
757  TRACE("(%p)\n", psa);
758 
759  if (psa)
760  {
761  LPVOID lpv = (char*)psa - SAFEARRAY_HIDDEN_SIZE;
762 
763  if (psa->cLocks)
764  return DISP_E_ARRAYISLOCKED; /* Can't destroy a locked array */
765 
766  if (psa->fFeatures & FADF_RECORD)
768 
769  if (psa->fFeatures & FADF_CREATEVECTOR &&
770  !(psa->fFeatures & FADF_DATADELETED))
771  SAFEARRAY_DestroyData(psa, 0); /* Data not previously deleted */
772 
773  SAFEARRAY_Free(lpv);
774  }
775  return S_OK;
776 }
static void SAFEARRAY_Free(void *ptr)
Definition: safearray.c:105
#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:1574
#define TRACE(s)
Definition: solgame.cpp:4
#define SAFEARRAY_HIDDEN_SIZE
Definition: safearray.c:84
static HRESULT SAFEARRAY_DestroyData(SAFEARRAY *psa, ULONG ulStartCell)
Definition: safearray.c:283
#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 1094 of file safearray.c.

1095 {
1096  TRACE("(%p) returning %d\n", psa, psa ? psa->cDims : 0u);
1097  return psa ? psa->cDims : 0;
1098 }
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 947 of file safearray.c.

948 {
949  HRESULT hRet;
950 
951  TRACE("(%p,%p,%p)\n", psa, rgIndices, pvData);
952 
953  if (!psa || !rgIndices || !pvData)
954  return E_INVALIDARG;
955 
956  hRet = SafeArrayLock(psa);
957 
958  if (SUCCEEDED(hRet))
959  {
960  PVOID lpvSrc;
961 
962  hRet = SafeArrayPtrOfIndex(psa, rgIndices, &lpvSrc);
963 
964  if (SUCCEEDED(hRet))
965  {
966  if (psa->fFeatures & FADF_VARIANT)
967  {
968  VARIANT* lpVariant = lpvSrc;
969  VARIANT* lpDest = pvData;
970 
971  /* The original content of pvData is ignored. */
972  V_VT(lpDest) = VT_EMPTY;
973  hRet = VariantCopy(lpDest, lpVariant);
974  if (FAILED(hRet)) FIXME("VariantCopy failed with 0x%x\n", hRet);
975  }
976  else if (psa->fFeatures & FADF_BSTR)
977  {
978  BSTR* lpBstr = lpvSrc;
979  BSTR* lpDest = pvData;
980 
981  if (*lpBstr)
982  {
983  *lpDest = SysAllocStringByteLen((char*)*lpBstr, SysStringByteLen(*lpBstr));
984  if (!*lpBstr)
985  hRet = E_OUTOFMEMORY;
986  }
987  else
988  *lpDest = NULL;
989  }
990  else if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
991  {
992  IUnknown **src_unk = lpvSrc;
993  IUnknown **dest_unk = pvData;
994 
995  if (*src_unk)
996  IUnknown_AddRef(*src_unk);
997  *dest_unk = *src_unk;
998  }
999  else if (psa->fFeatures & FADF_RECORD)
1000  {
1002 
1004  hRet = IRecordInfo_RecordCopy(record, lpvSrc, pvData);
1005  IRecordInfo_Release(record);
1006  }
1007  else
1008  /* Copy the data over */
1009  memcpy(pvData, lpvSrc, psa->cbElements);
1010  }
1012  }
1013  return hRet;
1014 }
HRESULT WINAPI SafeArrayGetRecordInfo(SAFEARRAY *psa, IRecordInfo **pRinfo)
Definition: safearray.c:1609
UINT WINAPI SysStringByteLen(BSTR str)
Definition: oleaut.c:215
OLECHAR * BSTR
Definition: compat.h:1942
#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:1194
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3748
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI SafeArrayLock(SAFEARRAY *psa)
Definition: safearray.c:795
BSTR WINAPI DECLSPEC_HOTPATCH SysAllocStringByteLen(LPCSTR str, UINT len)
Definition: oleaut.c:428
HRESULT WINAPI SafeArrayUnlock(SAFEARRAY *psa)
Definition: safearray.c:831
#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:748
#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 1114 of file safearray.c.

1115 {
1116  TRACE("(%p) returning %d\n", psa, psa ? psa->cbElements : 0u);
1117  return psa ? psa->cbElements : 0;
1118 }
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 1670 of file safearray.c.

1671 {
1672  GUID* src = (GUID*)psa;
1673 
1674  TRACE("(%p,%p)\n", psa, pGuid);
1675 
1676  if (!psa || !pGuid || !(psa->fFeatures & FADF_HAVEIID))
1677  return E_INVALIDARG;
1678 
1679  *pGuid = src[-1];
1680  return S_OK;
1681 }
#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 1066 of file safearray.c.

1067 {
1068  TRACE("(%p,%d,%p)\n", psa, nDim, plLbound);
1069 
1070  if (!psa || !plLbound)
1071  return E_INVALIDARG;
1072 
1073  if(!nDim || nDim > psa->cDims)
1074  return DISP_E_BADINDEX;
1075 
1076  *plLbound = psa->rgsabound[psa->cDims - nDim].lLbound;
1077  return S_OK;
1078 }
#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 1609 of file safearray.c.

1610 {
1611  IRecordInfo** src = (IRecordInfo**)psa;
1612 
1613  TRACE("(%p,%p)\n", psa, pRinfo);
1614 
1615  if (!psa || !pRinfo || !(psa->fFeatures & FADF_RECORD))
1616  return E_INVALIDARG;
1617 
1618  *pRinfo = src[-1];
1619 
1620  if (*pRinfo)
1621  IRecordInfo_AddRef(*pRinfo);
1622  return S_OK;
1623 }
#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 1033 of file safearray.c.

1034 {
1035  TRACE("(%p,%d,%p)\n", psa, nDim, plUbound);
1036 
1037  if (!psa || !plUbound)
1038  return E_INVALIDARG;
1039 
1040  if(!nDim || nDim > psa->cDims)
1041  return DISP_E_BADINDEX;
1042 
1043  *plUbound = psa->rgsabound[psa->cDims - nDim].lLbound +
1044  psa->rgsabound[psa->cDims - nDim].cElements - 1;
1045 
1046  return S_OK;
1047 }
#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 1534 of file safearray.c.

1535 {
1536  TRACE("(%p,%p)\n", psa, pvt);
1537 
1538  if (!psa || !pvt)
1539  return E_INVALIDARG;
1540 
1541  if (psa->fFeatures & FADF_RECORD)
1542  *pvt = VT_RECORD;
1543  else if ((psa->fFeatures & (FADF_HAVEIID|FADF_DISPATCH)) == (FADF_HAVEIID|FADF_DISPATCH))
1544  *pvt = VT_DISPATCH;
1545  else if (psa->fFeatures & FADF_HAVEIID)
1546  *pvt = VT_UNKNOWN;
1547  else if (psa->fFeatures & FADF_HAVEVARTYPE)
1548  {
1550  *pvt = vt;
1551  }
1552  else
1553  return E_INVALIDARG;
1554 
1555  return S_OK;
1556 }
static DWORD SAFEARRAY_GetHiddenDWORD(SAFEARRAY *psa)
Definition: safearray.c:155
#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:1903
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 795 of file safearray.c.

796 {
797  ULONG ulLocks;
798 
799  TRACE("(%p)\n", psa);
800 
801  if (!psa)
802  return E_INVALIDARG;
803 
804  ulLocks = InterlockedIncrement( (LONG*) &psa->cLocks);
805 
806  if (ulLocks > 0xffff) /* Maximum of 16384 locks at a time */
807  {
808  WARN("Out of locks!\n");
809  InterlockedDecrement( (LONG*) &psa->cLocks);
810  return E_UNEXPECTED;
811  }
812  return S_OK;
813 }
#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 1194 of file safearray.c.

1195 {
1196  USHORT dim;
1197  ULONG cell = 0, dimensionSize = 1;
1198  SAFEARRAYBOUND* psab;
1199  LONG c1;
1200 
1201  TRACE("(%p,%p,%p)\n", psa, rgIndices, ppvData);
1202 
1203  /* The general formula for locating the cell number of an entry in an n
1204  * dimensional array (where cn = coordinate in dimension dn) is:
1205  *
1206  * c1 + c2 * sizeof(d1) + c3 * sizeof(d2) ... + cn * sizeof(c(n-1))
1207  *
1208  * We calculate the size of the last dimension at each step through the
1209  * dimensions to avoid recursing to calculate the last dimensions size.
1210  */
1211  if (!psa || !rgIndices || !ppvData)
1212  return E_INVALIDARG;
1213 
1214  psab = psa->rgsabound + psa->cDims - 1;
1215  c1 = *rgIndices++;
1216 
1217  if (c1 < psab->lLbound || c1 >= psab->lLbound + (LONG)psab->cElements)
1218  return DISP_E_BADINDEX; /* Initial index out of bounds */
1219 
1220  for (dim = 1; dim < psa->cDims; dim++)
1221  {
1222  dimensionSize *= psab->cElements;
1223 
1224  psab--;
1225 
1226  if (!psab->cElements ||
1227  *rgIndices < psab->lLbound ||
1228  *rgIndices >= psab->lLbound + (LONG)psab->cElements)
1229  return DISP_E_BADINDEX; /* Index out of bounds */
1230 
1231  cell += (*rgIndices - psab->lLbound) * dimensionSize;
1232  rgIndices++;
1233  }
1234 
1235  cell += (c1 - psa->rgsabound[psa->cDims - 1].lLbound);
1236 
1237  *ppvData = (char*)psa->pvData + cell * psa->cbElements;
1238  return S_OK;
1239 }
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 864 of file safearray.c.

865 {
866  HRESULT hRet;
867 
868  TRACE("(%p,%p,%p)\n", psa, rgIndices, pvData);
869 
870  if (!psa || !rgIndices)
871  return E_INVALIDARG;
872 
873  hRet = SafeArrayLock(psa);
874 
875  if (SUCCEEDED(hRet))
876  {
877  PVOID lpvDest;
878 
879  hRet = SafeArrayPtrOfIndex(psa, rgIndices, &lpvDest);
880 
881  if (SUCCEEDED(hRet))
882  {
883  if (psa->fFeatures & FADF_VARIANT)
884  {
885  VARIANT* lpVariant = pvData;
886  VARIANT* lpDest = lpvDest;
887 
888  hRet = VariantCopy(lpDest, lpVariant);
889  if (FAILED(hRet)) FIXME("VariantCopy failed with 0x%x\n", hRet);
890  }
891  else if (psa->fFeatures & FADF_BSTR)
892  {
893  BSTR lpBstr = (BSTR)pvData;
894  BSTR* lpDest = lpvDest;
895 
896  SysFreeString(*lpDest);
897 
898  *lpDest = SysAllocStringByteLen((char*)lpBstr, SysStringByteLen(lpBstr));
899  if (!*lpDest)
900  hRet = E_OUTOFMEMORY;
901  }
902  else if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
903  {
904  IUnknown *lpUnknown = pvData;
905  IUnknown **lpDest = lpvDest;
906 
907  if (lpUnknown)
908  IUnknown_AddRef(lpUnknown);
909  if (*lpDest)
910  IUnknown_Release(*lpDest);
911  *lpDest = lpUnknown;
912  }
913  else if (psa->fFeatures & FADF_RECORD)
914  {
916 
918  hRet = IRecordInfo_RecordCopy(record, pvData, lpvDest);
919  IRecordInfo_Release(record);
920  } else
921  /* Copy the data over */
922  memcpy(lpvDest, pvData, psa->cbElements);
923  }
925  }
926  return hRet;
927 }
HRESULT WINAPI SafeArrayGetRecordInfo(SAFEARRAY *psa, IRecordInfo **pRinfo)
Definition: safearray.c:1609
UINT WINAPI SysStringByteLen(BSTR str)
Definition: oleaut.c:215
OLECHAR * BSTR
Definition: compat.h:1942
#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:1194
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3748
HRESULT WINAPI SafeArrayLock(SAFEARRAY *psa)
Definition: safearray.c:795
BSTR WINAPI DECLSPEC_HOTPATCH SysAllocStringByteLen(LPCSTR str, UINT len)
Definition: oleaut.c:428
HRESULT WINAPI SafeArrayUnlock(SAFEARRAY *psa)
Definition: safearray.c:831
#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:271
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
HRESULT WINAPI VariantCopy(VARIANTARG *pvargDest, VARIANTARG *pvargSrc)
Definition: variant.c:748
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by get_properties(), handle_navigation_error(), test_copy(), 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 1456 of file safearray.c.

1457 {
1458  SAFEARRAYBOUND *oldBounds;
1459  HRESULT hr;
1460 
1461  TRACE("(%p,%p)\n", psa, psabound);
1462 
1463  if (!psa || psa->fFeatures & FADF_FIXEDSIZE || !psabound)
1464  return E_INVALIDARG;
1465 
1466  if (psa->cLocks > 0)
1467  return DISP_E_ARRAYISLOCKED;
1468 
1469  hr = SafeArrayLock(psa);
1470  if (FAILED(hr))
1471  return hr;
1472 
1473  oldBounds = psa->rgsabound;
1474  oldBounds->lLbound = psabound->lLbound;
1475 
1476  if (psabound->cElements != oldBounds->cElements)
1477  {
1478  if (psabound->cElements < oldBounds->cElements)
1479  {
1480  /* Shorten the final dimension. */
1481  ULONG ulStartCell = psabound->cElements *
1482  (SAFEARRAY_GetCellCount(psa) / oldBounds->cElements);
1483  SAFEARRAY_DestroyData(psa, ulStartCell);
1484  }
1485  else
1486  {
1487  /* Lengthen the final dimension */
1488  ULONG ulOldSize, ulNewSize;
1489  PVOID pvNewData;
1490 
1491  ulOldSize = SAFEARRAY_GetCellCount(psa) * psa->cbElements;
1492  if (ulOldSize)
1493  ulNewSize = (ulOldSize / oldBounds->cElements) * psabound->cElements;
1494  else {
1495  int oldelems = oldBounds->cElements;
1496  oldBounds->cElements = psabound->cElements;
1497  ulNewSize = SAFEARRAY_GetCellCount(psa) * psa->cbElements;
1498  oldBounds->cElements = oldelems;
1499  }
1500 
1501  if (!(pvNewData = SAFEARRAY_Malloc(ulNewSize)))
1502  {
1504  return E_OUTOFMEMORY;
1505  }
1506 
1507  memcpy(pvNewData, psa->pvData, ulOldSize);
1508  SAFEARRAY_Free(psa->pvData);
1509  psa->pvData = pvNewData;
1510  }
1511  oldBounds->cElements = psabound->cElements;
1512  }
1513 
1515  return S_OK;
1516 }
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
Definition: safearray.c:162
HRESULT hr
Definition: shlfolder.c:183
static void SAFEARRAY_Free(void *ptr)
Definition: safearray.c:105
#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:795
HRESULT WINAPI SafeArrayUnlock(SAFEARRAY *psa)
Definition: safearray.c:831
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
static HRESULT SAFEARRAY_DestroyData(SAFEARRAY *psa, ULONG ulStartCell)
Definition: safearray.c:283
#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:96
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 1641 of file safearray.c.

1642 {
1643  GUID* dest = (GUID*)psa;
1644 
1645  TRACE("(%p,%s)\n", psa, debugstr_guid(guid));
1646 
1647  if (!psa || !guid || !(psa->fFeatures & FADF_HAVEIID))
1648  return E_INVALIDARG;
1649 
1650  dest[-1] = *guid;
1651  return S_OK;
1652 }
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 1574 of file safearray.c.

1575 {
1577 
1578  TRACE("(%p,%p)\n", psa, pRinfo);
1579 
1580  if (!psa || !(psa->fFeatures & FADF_RECORD))
1581  return E_INVALIDARG;
1582 
1583  if (pRinfo)
1584  IRecordInfo_AddRef(pRinfo);
1585 
1586  if (dest[-1])
1587  IRecordInfo_Release(dest[-1]);
1588 
1589  dest[-1] = pRinfo;
1590  return S_OK;
1591 }
#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 831 of file safearray.c.

832 {
833  TRACE("(%p)\n", psa);
834 
835  if (!psa)
836  return E_INVALIDARG;
837 
838  if (InterlockedDecrement( (LONG*) &psa->cLocks) < 0)
839  {
840  WARN("Unlocked but no lock held!\n");
841  InterlockedIncrement( (LONG*) &psa->cLocks);
842  return E_UNEXPECTED;
843  }
844  return S_OK;
845 }
#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 1699 of file safearray.c.

1700 {
1701  SAFEARRAYBOUND sab;
1702 
1703  TRACE("(%p,%p)\n", bstr, ppsa);
1704 
1705  if (!ppsa)
1706  return E_INVALIDARG;
1707 
1708  sab.lLbound = 0;
1709  sab.cElements = SysStringByteLen(bstr);
1710 
1711  *ppsa = SAFEARRAY_Create(VT_UI1, 1, &sab, 0);
1712 
1713  if (*ppsa)
1714  {
1715  memcpy((*ppsa)->pvData, bstr, sab.cElements);
1716  return S_OK;
1717  }
1718  return E_OUTOFMEMORY;
1719 }
static SAFEARRAY * SAFEARRAY_Create(VARTYPE vt, UINT cDims, const SAFEARRAYBOUND *rgsabound, ULONG ulSize)
Definition: safearray.c:218
UINT WINAPI SysStringByteLen(BSTR str)
Definition: oleaut.c:215
#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 88 of file safearray.c.

Referenced by SAFEARRAY_CopyData(), and SafeArrayCopy().