Ignore:
Timestamp:
Sep 15, 2001, 11:32:00 AM (24 years ago)
Author:
sandervl
Message:

restored old version + wine update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/oleaut32/safearray.c

    r6689 r6711  
    2525
    2626/* Localy used methods */
    27 static INT
     27static INT 
    2828endOfDim(LONG *coor, SAFEARRAYBOUND *mat, LONG dim, LONG realDim);
    2929
    30 static ULONG
     30static ULONG   
    3131calcDisplacement(LONG *coor, SAFEARRAYBOUND *mat, LONG dim);
    3232
    33 static BOOL
     33static BOOL 
    3434isPointer(USHORT feature);
    3535
    36 static INT
     36static INT   
    3737getFeatures(VARTYPE vt);
    3838
    39 static BOOL
     39static BOOL 
    4040validCoordinate(LONG *coor, SAFEARRAY *psa);
    4141
    42 static BOOL
     42static BOOL 
    4343resizeSafeArray(SAFEARRAY *psa, LONG lDelta);
    4444
    45 static BOOL
     45static BOOL 
    4646validArg(SAFEARRAY *psa);
    4747
    48 static ULONG
     48static ULONG   
    4949getArraySize(SAFEARRAY *psa);
    5050
    51 static HRESULT
     51static HRESULT 
    5252duplicateData(SAFEARRAY *psa, SAFEARRAY **ppsaOut);
    5353
     
    5959{
    6060  /* this is taken from wtypes.h.  Only [S]es are supported by the SafeArray */
    61 VARTYPE_NOT_SUPPORTED,  /* VT_EMPTY    [V]   [P]    nothing         */
    62 VARTYPE_NOT_SUPPORTED,  /* VT_NULL     [V]   [P]    SQL style Nul   */
    63 2,                      /* VT_I2       [V][T][P][S] 2 byte signed int */
    64 4,                      /* VT_I4       [V][T][P][S] 4 byte signed int */
    65 4,                      /* VT_R4       [V][T][P][S] 4 byte real */
    66 8,                      /* VT_R8       [V][T][P][S] 8 byte real */
     61VARTYPE_NOT_SUPPORTED,  /* VT_EMPTY    [V]   [P]    nothing                     */
     62VARTYPE_NOT_SUPPORTED,  /* VT_NULL     [V]   [P]    SQL style Nul       */
     632,                          /* VT_I2       [V][T][P][S] 2 byte signed int */
     644,                          /* VT_I4       [V][T][P][S] 4 byte signed int */
     654,                          /* VT_R4       [V][T][P][S] 4 byte real     */
     668,                          /* VT_R8       [V][T][P][S] 8 byte real     */
    67678,                      /* VT_CY       [V][T][P][S] currency */
    68 8,                      /* VT_DATE     [V][T][P][S] date */
    69 4,                      /* VT_BSTR     [V][T][P][S] OLE Automation string*/
    70 4,                      /* VT_DISPATCH [V][T][P][S] IDispatch * */
    71 4,                      /* VT_ERROR    [V][T]   [S] SCODE   */
    72 4,                      /* VT_BOOL     [V][T][P][S] True=-1, False=0*/
    73 24,                     /* VT_VARIANT  [V][T][P][S] VARIANT *   */
    74 4,                      /* VT_UNKNOWN  [V][T]   [S] IUnknown * */
    75 16,                     /* VT_DECIMAL  [V][T]   [S] 16 byte fixed point */
     688,                          /* VT_DATE     [V][T][P][S] date */
     694,                          /* VT_BSTR     [V][T][P][S] OLE Automation string*/
     704,                          /* VT_DISPATCH [V][T][P][S] IDispatch *     */
     714,                      /* VT_ERROR    [V][T]   [S] SCODE       */
     724,                          /* VT_BOOL     [V][T][P][S] True=-1, False=0*/
     7324,                     /* VT_VARIANT  [V][T][P][S] VARIANT *   */
     744,                          /* VT_UNKNOWN  [V][T]   [S] IUnknown * */
     7516,                         /* VT_DECIMAL  [V][T]   [S] 16 byte fixed point     */
    7676VARTYPE_NOT_SUPPORTED,                         /* no VARTYPE here..... */
    77 VARTYPE_NOT_SUPPORTED,  /* VT_I1          [T]       signed char */
    78 1,                      /* VT_UI1      [V][T][P][S] unsigned char           */
    79 VARTYPE_NOT_SUPPORTED,  /* VT_UI2         [T][P]    unsigned short  */
    80 VARTYPE_NOT_SUPPORTED,  /* VT_UI4         [T][P]    unsigned short  */
    81 VARTYPE_NOT_SUPPORTED,  /* VT_I8          [T][P]    signed 64-bit int           */
    82 VARTYPE_NOT_SUPPORTED,  /* VT_UI8         [T][P]    unsigned 64-bit int     */
    83 VARTYPE_NOT_SUPPORTED,  /* VT_INT         [T]       signed machine int      */
    84 VARTYPE_NOT_SUPPORTED,  /* VT_UINT        [T]       unsigned machine int    */
    85 VARTYPE_NOT_SUPPORTED,  /* VT_VOID        [T]       C style void            */
    86 VARTYPE_NOT_SUPPORTED,  /* VT_HRESULT     [T]       Standard return type    */
    87 VARTYPE_NOT_SUPPORTED,  /* VT_PTR         [T]       pointer type            */
    88 VARTYPE_NOT_SUPPORTED,  /* VT_SAFEARRAY   [T]       (use VT_ARRAY in VARIANT)*/
    89 VARTYPE_NOT_SUPPORTED,  /* VT_CARRAY      [T]       C style array           */
    90 VARTYPE_NOT_SUPPORTED,  /* VT_USERDEFINED [T]       user defined type           */
    91 VARTYPE_NOT_SUPPORTED,  /* VT_LPSTR       [T][P]    null terminated string  */
    92 VARTYPE_NOT_SUPPORTED,  /* VT_LPWSTR      [T][P]    wide null term string       */
    93 VARTYPE_NOT_SUPPORTED,  /* VT_FILETIME       [P]    FILETIME            */
    94 VARTYPE_NOT_SUPPORTED,  /* VT_BLOB           [P]    Length prefixed bytes */
    95 VARTYPE_NOT_SUPPORTED,  /* VT_STREAM         [P]    Name of stream follows      */
    96 VARTYPE_NOT_SUPPORTED,  /* VT_STORAGE        [P]    Name of storage follows */
    97 VARTYPE_NOT_SUPPORTED,  /* VT_STREAMED_OBJECT[P]    Stream contains an object*/
    98 VARTYPE_NOT_SUPPORTED,  /* VT_STORED_OBJECT  [P]    Storage contains object*/
    99 VARTYPE_NOT_SUPPORTED,  /* VT_BLOB_OBJECT    [P]    Blob contains an object*/
    100 VARTYPE_NOT_SUPPORTED,  /* VT_CF             [P]    Clipboard format            */
    101 VARTYPE_NOT_SUPPORTED,  /* VT_CLSID          [P]    A Class ID          */
    102 VARTYPE_NOT_SUPPORTED,  /* VT_VECTOR         [P]    simple counted array        */
    103 VARTYPE_NOT_SUPPORTED,  /* VT_ARRAY    [V]          SAFEARRAY*          */
    104 VARTYPE_NOT_SUPPORTED   /* VT_BYREF    [V]          void* for local use */
     77VARTYPE_NOT_SUPPORTED,  /* VT_I1          [T]       signed char */
     781,                          /* VT_UI1      [V][T][P][S] unsigned char                   */
     79VARTYPE_NOT_SUPPORTED,  /* VT_UI2         [T][P]    unsigned short      */
     80VARTYPE_NOT_SUPPORTED,  /* VT_UI4         [T][P]    unsigned short      */
     81VARTYPE_NOT_SUPPORTED,  /* VT_I8          [T][P]    signed 64-bit int                   */
     82VARTYPE_NOT_SUPPORTED,  /* VT_UI8         [T][P]    unsigned 64-bit int         */
     83VARTYPE_NOT_SUPPORTED,  /* VT_INT         [T]       signed machine int          */
     84VARTYPE_NOT_SUPPORTED,  /* VT_UINT        [T]       unsigned machine int        */
     85VARTYPE_NOT_SUPPORTED,  /* VT_VOID        [T]       C style void                        */
     86VARTYPE_NOT_SUPPORTED,  /* VT_HRESULT     [T]       Standard return type        */
     87VARTYPE_NOT_SUPPORTED,  /* VT_PTR         [T]       pointer type                        */
     88VARTYPE_NOT_SUPPORTED,  /* VT_SAFEARRAY   [T]       (use VT_ARRAY in VARIANT)*/
     89VARTYPE_NOT_SUPPORTED,  /* VT_CARRAY      [T]       C style array                       */
     90VARTYPE_NOT_SUPPORTED,  /* VT_USERDEFINED [T]       user defined type                   */
     91VARTYPE_NOT_SUPPORTED,  /* VT_LPSTR       [T][P]    null terminated string      */
     92VARTYPE_NOT_SUPPORTED,  /* VT_LPWSTR      [T][P]    wide null term string               */
     93VARTYPE_NOT_SUPPORTED,  /* VT_FILETIME       [P]    FILETIME                    */
     94VARTYPE_NOT_SUPPORTED,  /* VT_BLOB           [P]    Length prefixed bytes */
     95VARTYPE_NOT_SUPPORTED,  /* VT_STREAM         [P]    Name of stream follows              */
     96VARTYPE_NOT_SUPPORTED,  /* VT_STORAGE        [P]    Name of storage follows     */
     97VARTYPE_NOT_SUPPORTED,  /* VT_STREAMED_OBJECT[P]    Stream contains an object*/
     98VARTYPE_NOT_SUPPORTED,  /* VT_STORED_OBJECT  [P]    Storage contains object*/
     99VARTYPE_NOT_SUPPORTED,  /* VT_BLOB_OBJECT    [P]    Blob contains an object*/
     100VARTYPE_NOT_SUPPORTED,  /* VT_CF             [P]    Clipboard format                    */
     101VARTYPE_NOT_SUPPORTED,  /* VT_CLSID          [P]    A Class ID                  */
     102VARTYPE_NOT_SUPPORTED,  /* VT_VECTOR         [P]    simple counted array                */
     103VARTYPE_NOT_SUPPORTED,  /* VT_ARRAY    [V]          SAFEARRAY*                  */
     104VARTYPE_NOT_SUPPORTED   /* VT_BYREF    [V]          void* for local use */
    105105};
    106106
     
    109109
    110110/*************************************************************************
    111  *      SafeArrayAllocDescriptor
     111 *              SafeArrayAllocDescriptor
    112112 * Allocate the appropriate amount of memory for the SafeArray descriptor
    113113 */
    114 HRESULT WINAPI SafeArrayAllocDescriptor(
    115   UINT    cDims,
    116   SAFEARRAY **ppsaOut)
     114HRESULT WINAPI SafeArrayAllocDescriptor( 
     115  UINT    cDims, 
     116  SAFEARRAY **ppsaOut) 
    117117{
    118118  SAFEARRAYBOUND *sab;
     
    124124
    125125  /* Allocate memory for SAFEARRAY struc */
    126   if(( (*ppsaOut)=HeapAlloc(
     126  if(( (*ppsaOut)=HeapAlloc( 
    127127        GetProcessHeap(), HEAP_ZERO_MEMORY, allocSize)) == NULL){
    128128    return(E_UNEXPECTED);
     
    134134
    135135/*************************************************************************
    136  *      SafeArrayAllocData
     136 *              SafeArrayAllocData
    137137 * Allocate the appropriate amount of data for the SafeArray data
    138138 */
    139139HRESULT WINAPI SafeArrayAllocData(
    140   SAFEARRAY *psa)
     140  SAFEARRAY *psa) 
    141141{
    142142  ULONG  ulWholeArraySize;   /* to store the size of the whole thing */
     
    144144  dprintf(("SafeArrayAllocData %x", psa));
    145145
    146   if(! validArg(psa))
     146  if(! validArg(psa)) 
    147147    return E_INVALIDARG;
    148148
     
    150150
    151151  /* Allocate memory for the data itself */
    152   if((psa->pvData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
     152  if((psa->pvData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 
    153153        psa->cbElements*ulWholeArraySize)) == NULL)
    154154    return(E_UNEXPECTED);
    155155
    156   TRACE("SafeArray: %lu bytes allocated for data at %p (%lu objects).\n",
     156  TRACE("SafeArray: %lu bytes allocated for data at %p (%lu objects).\n", 
    157157    psa->cbElements*ulWholeArraySize, psa->pvData, ulWholeArraySize);
    158158
     
    161161
    162162/*************************************************************************
    163  *      SafeArrayCreate
    164  * Create a SafeArray object by encapsulating AllocDescriptor and AllocData
     163 *              SafeArrayCreate
     164 * Create a SafeArray object by encapsulating AllocDescriptor and AllocData 
    165165 */
    166166SAFEARRAY* WINAPI SafeArrayCreate(
    167   VARTYPE        vt,
    168   UINT         cDims,
     167  VARTYPE        vt, 
     168  UINT         cDims, 
    169169  SAFEARRAYBOUND *rgsabound)
    170170{
     
    184184    return NULL;
    185185
    186   /* setup data members... */
     186  /* setup data members... */ 
    187187  psa->cDims     = cDims;
    188188  psa->fFeatures = getFeatures(vt);
     
    197197  }
    198198
    199   /* allocate memory for the data... */
     199  /* allocate memory for the data... */ 
    200200  if( FAILED( hRes = SafeArrayAllocData(psa))) {
    201     SafeArrayDestroyDescriptor(psa);
     201    SafeArrayDestroyDescriptor(psa); 
    202202    ERR("() : Failed to allocate the Safe Array data\n");
    203203    return NULL;
    204204  }
    205205
    206   return(psa);
    207 }
    208 
    209 /*************************************************************************
    210  *      SafeArrayDestroyDescriptor
     206  return(psa); 
     207}
     208
     209/*************************************************************************
     210 *              SafeArrayDestroyDescriptor
    211211 * Frees the memory associated with the descriptor.
    212212 */
     
    217217
    218218  /* Check for lockness before to free... */
    219   if(psa->cLocks > 0)
     219  if(psa->cLocks > 0) 
    220220    return DISP_E_ARRAYISLOCKED;
    221221
    222222  /* The array is unlocked, then, deallocate memory */
    223   if(HeapFree( GetProcessHeap(), 0, psa) == FALSE)
     223  if(HeapFree( GetProcessHeap(), 0, psa) == FALSE) 
    224224    return E_UNEXPECTED;
    225 
     225 
    226226  return(S_OK);
    227227}
     
    229229
    230230/*************************************************************************
    231  *      SafeArrayLock
     231 *              SafeArrayLock
    232232 * Increment the lock counter
    233233 *
    234234 * Doc says (MSDN Library ) that psa->pvData should be made available (!= NULL)
    235  * only when psa->cLocks is > 0... I don't get it since pvData is allocated
    236  * before the array is locked, therefore
     235 * only when psa->cLocks is > 0... I don't get it since pvData is allocated 
     236 * before the array is locked, therefore 
    237237 */
    238238HRESULT WINAPI SafeArrayLock(
     
    241241  dprintf(("SafeArrayLock %x", psa));
    242242
    243   if(! validArg(psa))
     243  if(! validArg(psa))     
    244244    return E_INVALIDARG;
    245245
     
    250250
    251251/*************************************************************************
    252  *      SafeArrayUnlock
     252 *              SafeArrayUnlock
    253253 * Decrement the lock counter
    254254 */
     
    258258  dprintf(("SafeArrayUnlock %x", psa));
    259259
    260   if(! validArg(psa))
    261     return E_INVALIDARG;
    262 
    263   if (psa->cLocks > 0)
     260  if(! validArg(psa)) 
     261    return E_INVALIDARG;
     262
     263  if (psa->cLocks > 0) 
    264264    psa->cLocks--;
    265265
     
    269269
    270270/*************************************************************************
    271  *      SafeArrayPutElement
     271 *              SafeArrayPutElement
    272272 * Set the data at the given coordinate
    273273 */
    274274HRESULT WINAPI SafeArrayPutElement(
    275   SAFEARRAY *psa,
    276   LONG      *rgIndices,
     275  SAFEARRAY *psa, 
     276  LONG      *rgIndices, 
    277277  void      *pv)
    278278{
    279   ULONG stepCountInSAData     = 0;    /* Number of array item to skip to get to
     279  ULONG stepCountInSAData     = 0;    /* Number of array item to skip to get to 
    280280                                         the desired one... */
    281281  PVOID elementStorageAddress = NULL; /* Adress to store the data */
     
    285285
    286286  /* Validate the index given */
    287   if(! validCoordinate(rgIndices, psa))
     287  if(! validCoordinate(rgIndices, psa)) 
    288288    return DISP_E_BADINDEX;
    289289  if(! validArg(psa))
     
    294294    /* Figure out the number of items to skip */
    295295    stepCountInSAData = calcDisplacement(rgIndices, psa->rgsabound, psa->cDims);
    296 
     296 
    297297    /* Figure out the number of byte to skip ... */
    298298    elementStorageAddress = (char *) psa->pvData+(stepCountInSAData*psa->cbElements);
    299 
     299 
    300300    if(isPointer(psa->fFeatures)) { /* increment ref count for this pointer */
    301301
    302       *((VOID**)elementStorageAddress) = *(VOID**)pv;
     302      *((VOID**)elementStorageAddress) = *(VOID**)pv; 
    303303      IUnknown_AddRef( *(IUnknown**)pv);
    304304
    305     } else {
     305    } else { 
    306306
    307307      if(psa->fFeatures == FADF_BSTR) { /* Create a new object */
    308308
    309309        if((pbstrReAllocStr = SysAllocString( (OLECHAR*)pv )) == NULL) {
    310           SafeArrayUnlock(psa);
     310          SafeArrayUnlock(psa); 
    311311          return E_OUTOFMEMORY;
    312         } else
     312        } else 
    313313          *((BSTR*)elementStorageAddress) = pbstrReAllocStr;
    314314
     
    323323
    324324  TRACE("SafeArray: item put at adress %p.\n",elementStorageAddress);
    325   return SafeArrayUnlock(psa);
    326 }
    327 
    328 
    329 /*************************************************************************
    330  *      SafeArrayGetElement
     325  return SafeArrayUnlock(psa); 
     326}
     327
     328
     329/*************************************************************************
     330 *              SafeArrayGetElement
    331331 * Return the data element corresponding the the given coordinate
    332332 */
    333333HRESULT WINAPI SafeArrayGetElement(
    334   SAFEARRAY *psa,
    335   LONG      *rgIndices,
     334  SAFEARRAY *psa, 
     335  LONG      *rgIndices, 
    336336  void      *pv)
    337337{
    338   ULONG stepCountInSAData     = 0;    /* Number of array item to skip to get to
     338  ULONG stepCountInSAData     = 0;    /* Number of array item to skip to get to 
    339339                                         the desired one... */
    340340  PVOID elementStorageAddress = NULL; /* Adress to store the data */
     
    343343  dprintf(("SafeArrayGetElement %x %x %x", psa, rgIndices, pv));
    344344
    345   if(! validArg(psa))
    346     return E_INVALIDARG;
    347 
     345  if(! validArg(psa)) 
     346    return E_INVALIDARG;
     347 
    348348  if(! validCoordinate(rgIndices, psa)) /* Validate the index given */
    349349    return(DISP_E_BADINDEX);
     
    353353    /* Figure out the number of items to skip */
    354354    stepCountInSAData = calcDisplacement(rgIndices, psa->rgsabound, psa->cDims);
    355 
     355 
    356356    /* Figure out the number of byte to skip ... */
    357357    elementStorageAddress = (char *) psa->pvData+(stepCountInSAData*psa->cbElements);
    358 
     358 
    359359    if( psa->fFeatures == FADF_BSTR) {           /* reallocate the obj */
    360       if( (pbstrReturnedStr =
     360      if( (pbstrReturnedStr = 
    361361          SysAllocString( *(OLECHAR**)elementStorageAddress )) == NULL) {
    362362        SafeArrayUnlock(psa);
    363363        return E_OUTOFMEMORY;
    364       } else
    365         *((BSTR*)pv) = pbstrReturnedStr;
    366 
     364      } else 
     365        *((BSTR*)pv) = pbstrReturnedStr; 
     366       
    367367    } else if( isPointer(psa->fFeatures) )       /* simply copy the pointer */
    368        pv = *((PVOID*)elementStorageAddress);
     368       pv = *((PVOID*)elementStorageAddress); 
    369369    else                                         /* copy the bytes */
    370370      memcpy(pv, elementStorageAddress, SafeArrayGetElemsize(psa) );
     
    375375  }
    376376
    377   return( SafeArrayUnlock(psa) );
    378 }
    379 
    380 /*************************************************************************
    381  *      SafeArrayGetUBound
     377  return( SafeArrayUnlock(psa) ); 
     378}
     379
     380/*************************************************************************
     381 *              SafeArrayGetUBound
    382382 * return the UP bound for a given array dimension
    383383 */
    384384HRESULT WINAPI SafeArrayGetUBound(
    385   SAFEARRAY *psa,
     385  SAFEARRAY *psa, 
    386386  UINT    nDim,
    387387  LONG      *plUbound)
     
    390390  dprintf(("SafeArrayGetUBound %x %x %x", psa, nDim, plUbound));
    391391
    392   if(! validArg(psa))
    393     return E_INVALIDARG;
    394 
    395   if(nDim > psa->cDims)
     392  if(! validArg(psa))   
     393    return E_INVALIDARG;
     394
     395  if(nDim > psa->cDims) 
    396396    return DISP_E_BADINDEX;
    397397
    398   *plUbound = psa->rgsabound[nDim-1].lLbound +
     398  *plUbound = psa->rgsabound[nDim-1].lLbound + 
    399399              psa->rgsabound[nDim-1].cElements - 1;
    400400
     
    403403
    404404/*************************************************************************
    405  *      SafeArrayGetLBound
    406  * Return the LO bound for a given array dimension
     405 *              SafeArrayGetLBound
     406 * Return the LO bound for a given array dimension 
    407407 */
    408408HRESULT WINAPI SafeArrayGetLBound(
    409409  SAFEARRAY *psa,
    410   UINT    nDim,
     410  UINT    nDim, 
    411411  LONG      *plLbound)
    412412{
    413   if(! validArg(psa))
    414     return E_INVALIDARG;
    415 
    416   if(nDim > psa->cDims)
     413  if(! validArg(psa))   
     414    return E_INVALIDARG;
     415
     416  if(nDim > psa->cDims) 
    417417    return DISP_E_BADINDEX;
    418418
     
    422422
    423423/*************************************************************************
    424  *      SafeArrayGetDim
     424 *              SafeArrayGetDim
    425425 * returns the number of dimension in the array
    426426 */
    427427UINT WINAPI SafeArrayGetDim(
    428428  SAFEARRAY * psa)
    429 {
     429{ 
    430430  /*
    431431   * A quick test in Windows shows that the behavior here for an invalid
    432432   * pointer is to return 0.
    433433   */
    434   if(! validArg(psa))
     434  if(! validArg(psa)) 
    435435    return 0;
    436436
     
    439439
    440440/*************************************************************************
    441  *      SafeArrayGetElemsize
     441 *              SafeArrayGetElemsize
    442442 * Return the size of the element in the array
    443443 */
    444444UINT WINAPI SafeArrayGetElemsize(
    445445  SAFEARRAY * psa)
    446 {
     446{ 
    447447  /*
    448448   * A quick test in Windows shows that the behavior here for an invalid
    449449   * pointer is to return 0.
    450450   */
    451   if(! validArg(psa))
     451  if(! validArg(psa)) 
    452452    return 0;
    453453
     
    456456
    457457/*************************************************************************
    458  *      SafeArrayAccessData
    459  * increment the access count and return the data
     458 *              SafeArrayAccessData
     459 * increment the access count and return the data 
    460460 */
    461461HRESULT WINAPI SafeArrayAccessData(
    462   SAFEARRAY *psa,
     462  SAFEARRAY *psa, 
    463463  void      **ppvData)
    464 {
     464{ 
    465465  HRESULT hRes;
    466466
    467   if(! validArg(psa))
     467  if(! validArg(psa)) 
    468468    return E_INVALIDARG;
    469469
     
    471471
    472472  switch (hRes) {
    473     case S_OK:
     473    case S_OK: 
    474474      (*ppvData) = psa->pvData;
    475475      break;
     
    478478      return E_INVALIDARG;
    479479  }
    480 
     480 
    481481  return S_OK;
    482482}
     
    484484
    485485/*************************************************************************
    486  *      SafeArrayUnaccessData
     486 *              SafeArrayUnaccessData
    487487 * Decrement the access count
    488488 */
    489489HRESULT WINAPI SafeArrayUnaccessData(
    490490  SAFEARRAY * psa)
    491 {
    492   if(! validArg(psa))
     491{ 
     492  if(! validArg(psa)) 
    493493    return E_INVALIDARG;
    494494
     
    496496}
    497497
    498 /************************************************************************
    499  *      SafeArrayPtrOfIndex
     498/************************************************************************ 
     499 *              SafeArrayPtrOfIndex
    500500 * Return a pointer to the element at rgIndices
    501501 */
    502502HRESULT WINAPI SafeArrayPtrOfIndex(
    503   SAFEARRAY *psa,
    504   LONG      *rgIndices,
     503  SAFEARRAY *psa, 
     504  LONG      *rgIndices, 
    505505  void      **ppvData)
    506 {
    507   ULONG stepCountInSAData     = 0;    /* Number of array item to skip to get to
     506{ 
     507  ULONG stepCountInSAData     = 0;    /* Number of array item to skip to get to 
    508508                                         the desired one... */
    509509
    510   if(! validArg(psa))
    511     return E_INVALIDARG;
    512 
    513   if(! validCoordinate(rgIndices, psa))
     510  if(! validArg(psa))                   
     511    return E_INVALIDARG;
     512
     513  if(! validCoordinate(rgIndices, psa)) 
    514514    return DISP_E_BADINDEX;
    515515
    516516  /* Figure out the number of items to skip */
    517517  stepCountInSAData = calcDisplacement(rgIndices, psa->rgsabound, psa->cDims);
    518 
     518 
    519519  *ppvData = (char *) psa->pvData+(stepCountInSAData*psa->cbElements);
    520520
     
    522522}
    523523
    524 /************************************************************************
    525  *      SafeArrayDestroyData
     524/************************************************************************ 
     525 *              SafeArrayDestroyData
    526526 * Frees the memory data bloc
    527527 */
    528528HRESULT WINAPI SafeArrayDestroyData(
    529529  SAFEARRAY *psa)
    530 {
     530{ 
    531531  HRESULT  hRes;
    532532  ULONG    ulWholeArraySize; /* count spot in array  */
     
    535535  BSTR   bstr;
    536536
    537   if(! validArg(psa))
    538     return E_INVALIDARG;
    539 
    540   if(psa->cLocks > 0)
     537  if(! validArg(psa)) 
     538    return E_INVALIDARG;
     539
     540  if(psa->cLocks > 0) 
    541541    return DISP_E_ARRAYISLOCKED;
    542542
     
    546546
    547547    for(ulDataIter=0; ulDataIter < ulWholeArraySize; ulDataIter++) {
    548       punk = *(IUnknown**)((char *) psa->pvData+(ulDataIter*(psa->cbElements)));
    549 
    550       if( punk != NULL)
     548      punk = *(IUnknown**)((char *) psa->pvData+(ulDataIter*(psa->cbElements)));       
     549
     550      if( punk != NULL) 
    551551        IUnknown_Release(punk);
    552552    }
     
    557557      bstr = *(BSTR*)((char *) psa->pvData+(ulDataIter*(psa->cbElements)));
    558558
    559       if( bstr != NULL)
     559      if( bstr != NULL) 
    560560        SysFreeString( bstr );
    561561    }
    562562  }
    563 
    564   /* check if this array is a Vector, in which case do not free the data
     563     
     564  /* check if this array is a Vector, in which case do not free the data 
    565565     block since it has been allocated by AllocDescriptor and therefore
    566566     deserve to be freed by DestroyDescriptor */
     
    573573    psa->pvData = NULL;
    574574  }
    575 
     575 
    576576  return S_OK;
    577577}
    578578
    579 /************************************************************************
    580  *      SafeArrayCopyData
     579/************************************************************************ 
     580 *              SafeArrayCopyData
    581581 * Copy the psaSource's data block into psaTarget if dimension and size
    582582 * permits it.
     
    585585  SAFEARRAY *psaSource,
    586586  SAFEARRAY **psaTarget)
    587 {
     587{ 
    588588  USHORT   cDimCount;        /* looper */
    589589  LONG     lDelta;           /* looper */
    590   IUnknown *punk;
     590  IUnknown *punk;   
    591591  ULONG    ulWholeArraySize; /* Number of item in SA */
    592592  BSTR   bstr;
    593593
    594   if(! (validArg(psaSource) && validArg(*psaTarget)) )
     594  if(! (validArg(psaSource) && validArg(*psaTarget)) ) 
    595595    return E_INVALIDARG;
    596596
     
    598598    return E_INVALIDARG;
    599599
    600   ulWholeArraySize = getArraySize(psaSource);
     600  ulWholeArraySize = getArraySize(psaSource); 
    601601
    602602  /* The two arrays boundaries must be of same lenght */
    603603  for(cDimCount=0;cDimCount < psaSource->cDims; cDimCount++)
    604     if( psaSource->rgsabound[cDimCount].cElements !=
     604    if( psaSource->rgsabound[cDimCount].cElements != 
    605605      (*psaTarget)->rgsabound[cDimCount].cElements)
    606606      return E_INVALIDARG;
    607607
    608   if( isPointer((*psaTarget)->fFeatures) ) {         /* the target contains ptr
     608  if( isPointer((*psaTarget)->fFeatures) ) {         /* the target contains ptr 
    609609                                                        that must be released */
    610610    for(lDelta=0;lDelta < ulWholeArraySize; lDelta++) {
     
    612612        ((char *) (*psaTarget)->pvData + (lDelta * (*psaTarget)->cbElements));
    613613
    614       if( punk != NULL)
     614      if( punk != NULL) 
    615615        IUnknown_Release(punk);
    616616    }
    617617
    618618  } else if( (*psaTarget)->fFeatures & FADF_BSTR) {  /* the target contain BSTR
    619                                                         that must be freed */
     619                                                        that must be freed */ 
    620620    for(lDelta=0;lDelta < ulWholeArraySize; lDelta++) {
    621       bstr =
     621      bstr = 
    622622        *(BSTR*)((char *) (*psaTarget)->pvData + (lDelta * (*psaTarget)->cbElements));
    623623
    624       if( bstr != NULL)
     624      if( bstr != NULL) 
    625625        SysFreeString( bstr );
    626626    }
     
    630630}
    631631
    632 /************************************************************************
    633  *      SafeArrayDestroy
     632/************************************************************************ 
     633 *              SafeArrayDestroy
    634634 * Deallocates all memory reserved for the SafeArray
    635635 */
    636636HRESULT WINAPI SafeArrayDestroy(
    637637  SAFEARRAY * psa)
    638 {
     638{ 
    639639  HRESULT hRes;
    640640
    641   if(! validArg(psa))
    642     return E_INVALIDARG;
    643 
    644   if(psa->cLocks > 0)
     641  if(! validArg(psa)) 
     642    return E_INVALIDARG;
     643
     644  if(psa->cLocks > 0) 
    645645    return DISP_E_ARRAYISLOCKED;
    646646
     
    652652}
    653653
    654 /************************************************************************
    655  *      SafeArrayCopy
     654/************************************************************************ 
     655 *              SafeArrayCopy
    656656 * Make a dupplicate of a SafeArray
    657657 */
    658658HRESULT WINAPI SafeArrayCopy(
    659   SAFEARRAY *psa,
     659  SAFEARRAY *psa, 
    660660  SAFEARRAY **ppsaOut)
    661 {
     661{ 
    662662  HRESULT hRes;
    663663  DWORD   dAllocSize;
    664664  ULONG   ulWholeArraySize; /* size of the thing */
    665665
    666   if(! validArg(psa))
     666  if(! validArg(psa)) 
    667667    return E_INVALIDARG;
    668668
     
    670670
    671671    /* Duplicate the SAFEARRAY struc */
    672     memcpy(*ppsaOut, psa,
     672    memcpy(*ppsaOut, psa, 
    673673            sizeof(*psa)+(sizeof(*(psa->rgsabound))*(psa->cDims-1)));
    674674
     
    677677    /* make sure the new safe array doesn't have the FADF_CREATEVECTOR flag,
    678678       because the data has not been allocated with the descriptor. */
    679     (*ppsaOut)->fFeatures &= ~FADF_CREATEVECTOR;
    680 
    681     /* Get the allocated memory size for source and allocate it for target */
     679    (*ppsaOut)->fFeatures &= ~FADF_CREATEVECTOR; 
     680 
     681    /* Get the allocated memory size for source and allocate it for target */ 
    682682    ulWholeArraySize = getArraySize(psa); /* Number of item in SA */
    683683    dAllocSize = ulWholeArraySize*psa->cbElements;
    684684
    685     (*ppsaOut)->pvData =
     685    (*ppsaOut)->pvData = 
    686686      HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dAllocSize);
    687687    if( (*ppsaOut)->pvData != NULL) {   /* HeapAlloc succeed */
     
    693693        return hRes;
    694694      }
    695 
     695       
    696696    } else { /* failed to allocate or dupplicate... */
    697697      SafeArrayDestroyDescriptor(*ppsaOut);
     
    705705}
    706706
    707 /************************************************************************
    708  *      SafeArrayCreateVector
    709  * Creates a one dimension safearray where the data is next to the
     707/************************************************************************ 
     708 *              SafeArrayCreateVector
     709 * Creates a one dimension safearray where the data is next to the 
    710710 * SAFEARRAY structure.
    711711 */
    712712SAFEARRAY* WINAPI SafeArrayCreateVector(
    713   VARTYPE vt,
    714   LONG    lLbound,
    715   ULONG   cElements)
    716 {
     713  VARTYPE vt, 
     714  LONG    lLbound, 
     715  ULONG   cElements) 
     716{ 
    717717  SAFEARRAY *psa;
    718718
     
    723723
    724724  /* Allocate memory for the array descriptor and data contiguously  */
    725   if( FAILED( psa = HeapAlloc( GetProcessHeap(),
    726                       HEAP_ZERO_MEMORY,
     725  if( FAILED( psa = HeapAlloc( GetProcessHeap(), 
     726                      HEAP_ZERO_MEMORY, 
    727727                      (sizeof(*psa) + (VARTYPE_SIZE[vt] * cElements))))) {
    728728    return NULL;
    729729  }
    730 
    731   /* setup data members... */
     730                                                                               
     731  /* setup data members... */ 
    732732  psa->cDims      = 1; /* always and forever */
    733733  psa->fFeatures  = getFeatures(vt) | FADF_CREATEVECTOR;  /* undocumented flag used by Microsoft */
     
    739739  psa->rgsabound[0].lLbound   = lLbound;
    740740
    741   return(psa);
    742 }
    743 
    744 /************************************************************************
    745  *      SafeArrayRedim
     741  return(psa);                           
     742} 
     743
     744/************************************************************************ 
     745 *              SafeArrayRedim
    746746 * Changes the caracteristics of the last dimension of the SafeArray
    747747 */
    748748HRESULT WINAPI SafeArrayRedim(
    749   SAFEARRAY      *psa,
     749  SAFEARRAY      *psa, 
    750750  SAFEARRAYBOUND *psaboundNew)
    751 {
     751{ 
    752752  LONG   lDelta;  /* hold difference in size */
    753753  USHORT cDims=1; /* dims counter */
    754754
    755   if( !validArg(psa) )
    756     return E_INVALIDARG;
    757 
    758   if( psa->cLocks > 0 )
     755  if( !validArg(psa) )                   
     756    return E_INVALIDARG;
     757
     758  if( psa->cLocks > 0 )                   
    759759    return DISP_E_ARRAYISLOCKED;
    760760
    761   if( psa->fFeatures & FADF_FIXEDSIZE )
    762     return E_INVALIDARG;
    763 
    764   if( SafeArrayLock(psa)==E_UNEXPECTED )
     761  if( psa->fFeatures & FADF_FIXEDSIZE )   
     762    return E_INVALIDARG;
     763
     764  if( SafeArrayLock(psa)==E_UNEXPECTED ) 
    765765    return E_UNEXPECTED;/* UNDOC error condition */
    766766
     
    774774
    775775  } else /* need to enlarge (lDelta +) reduce (lDelta -) */
    776     if(! resizeSafeArray(psa, lDelta))
     776    if(! resizeSafeArray(psa, lDelta)) 
    777777      return E_UNEXPECTED; /* UNDOC error condition */
    778778
    779   /* the only modifyable dimension sits in [0] as the dimensions were reversed
     779  /* the only modifyable dimension sits in [0] as the dimensions were reversed 
    780780     at array creation time... */
    781781  psa->rgsabound[0].cElements = psaboundNew->cElements;
     
    789789 ************************************************************************/
    790790
    791 /************************************************************************
     791/************************************************************************ 
    792792 * Used to validate the SAFEARRAY type of arg
    793793 */
    794794static BOOL validArg(
    795   SAFEARRAY *psa)
     795  SAFEARRAY *psa) 
    796796{
    797797  SAFEARRAYBOUND *sab;
     
    822822}
    823823
    824 /************************************************************************
     824/************************************************************************ 
    825825 * Used to reallocate memory
    826826 */
    827827static BOOL resizeSafeArray(
    828   SAFEARRAY *psa,
     828  SAFEARRAY *psa, 
    829829  LONG lDelta)
    830830{
    831831  ULONG    ulWholeArraySize;  /* use as multiplicator */
    832   PVOID    pvNewBlock = NULL;
     832  PVOID    pvNewBlock = NULL; 
    833833  IUnknown *punk;
    834834  BSTR   bstr;
     
    838838  if(lDelta < 0) {                    /* array needs to be shorthen  */
    839839    if( isPointer(psa->fFeatures))    /* ptr that need to be released */
    840         for(;lDelta < 0; lDelta++) {
    841           punk = *(IUnknown**)
     840            for(;lDelta < 0; lDelta++) {
     841              punk = *(IUnknown**)
    842842          ((char *) psa->pvData+((ulWholeArraySize+lDelta)*psa->cbElements));
    843 
     843       
    844844        if( punk != NULL )
    845845          IUnknown_Release(punk);
    846         }
     846            }
    847847
    848848    else if(psa->fFeatures & FADF_BSTR)  /* BSTR that need to be freed */
    849         for(;lDelta < 0; lDelta++) {
     849            for(;lDelta < 0; lDelta++) {
    850850        bstr = *(BSTR*)
    851851          ((char *) psa->pvData+((ulWholeArraySize+lDelta)*psa->cbElements));
     
    858858  if (!(psa->fFeatures & FADF_CREATEVECTOR))
    859859  {
    860     /* Ok now, if we are enlarging the array, we *MUST* move the whole block
     860    /* Ok now, if we are enlarging the array, we *MUST* move the whole block 
    861861       pointed to by pvData.   If we are shorthening the array, this move is
    862        optional but we do it anyway becuase the benefit is that we are
     862       optional but we do it anyway becuase the benefit is that we are 
    863863       releasing to the system the unused memory */
    864864
    865     if((pvNewBlock = HeapReAlloc(GetProcessHeap(), 0, psa->pvData,
    866        (ulWholeArraySize + lDelta) * psa->cbElements)) == NULL)
     865    if((pvNewBlock = HeapReAlloc(GetProcessHeap(), 0, psa->pvData, 
     866       (ulWholeArraySize + lDelta) * psa->cbElements)) == NULL) 
    867867        return FALSE; /* TODO If we get here it means:
    868868                         SHRINK situation :  we've deleted the undesired
     
    873873  else
    874874  {
    875     /* Allocate a new block, because the previous data has been allocated with
     875    /* Allocate a new block, because the previous data has been allocated with 
    876876       the descriptor in SafeArrayCreateVector function. */
    877877
    878878    if((pvNewBlock = HeapAlloc(GetProcessHeap(), 0,
    879        ulWholeArraySize * psa->cbElements)) == NULL)
     879       ulWholeArraySize * psa->cbElements)) == NULL) 
    880880        return FALSE;
    881881
     
    887887}
    888888
    889 /************************************************************************
    890  * Used to set the fFeatures data member of the SAFEARRAY structure.
     889/************************************************************************ 
     890 * Used to set the fFeatures data member of the SAFEARRAY structure. 
    891891 */
    892892static INT getFeatures(
    893   VARTYPE vt)
     893  VARTYPE vt) 
    894894{
    895895  switch(vt) {
     
    901901}
    902902
    903 /************************************************************************
    904  * Used to figure out if the fFeatures data member of the SAFEARRAY
    905  * structure contain any information about the type of data stored...
     903/************************************************************************ 
     904 * Used to figure out if the fFeatures data member of the SAFEARRAY 
     905 * structure contain any information about the type of data stored... 
    906906 */
    907907static BOOL isPointer(
    908   USHORT feature)
     908  USHORT feature) 
    909909{
    910910  switch(feature) {
     
    915915}
    916916
    917 /************************************************************************
    918  * Used to calculate the displacement when accessing or modifying
     917/************************************************************************ 
     918 * Used to calculate the displacement when accessing or modifying 
    919919 * safearray data set.
    920920 *
     
    926926 */
    927927static ULONG calcDisplacement(
    928   LONG           *coor,
    929   SAFEARRAYBOUND *mat,
    930   LONG           dim)
     928  LONG           *coor, 
     929  SAFEARRAYBOUND *mat, 
     930  LONG           dim) 
    931931{
    932932  ULONG res = 0;
    933933  LONG  iterDim;
    934934
    935   for(iterDim=0; iterDim<dim; iterDim++)
     935  for(iterDim=0; iterDim<dim; iterDim++) 
    936936    /* the -mat[dim] bring coor[dim] relative to 0 for calculation */
    937     res += ((coor[iterDim]-mat[iterDim].lLbound) *
     937    res += ((coor[iterDim]-mat[iterDim].lLbound) * 
    938938            endOfDim(coor, mat, iterDim+1, dim));
    939939
     
    942942}
    943943
    944 /************************************************************************
    945  * Recursivity agent for calcDisplacement method.  Used within Put and
     944/************************************************************************ 
     945 * Recursivity agent for calcDisplacement method.  Used within Put and 
    946946 * Get methods.
    947947 */
    948948static INT endOfDim(
    949   LONG           *coor,
    950   SAFEARRAYBOUND *mat,
    951   LONG           dim,
    952   LONG           realDim)
    953 {
    954   if(dim==realDim)
     949  LONG           *coor, 
     950  SAFEARRAYBOUND *mat, 
     951  LONG           dim, 
     952  LONG           realDim) 
     953{
     954  if(dim==realDim) 
    955955    return 1;
    956   else
     956  else 
    957957    return (endOfDim(coor, mat, dim+1, realDim) * mat[dim].cElements);
    958958}
    959959
    960960
    961 /************************************************************************
    962  * Method used to validate the coordinate received in Put and Get
     961/************************************************************************ 
     962 * Method used to validate the coordinate received in Put and Get 
    963963 * methods.
    964964 */
    965965static BOOL validCoordinate(
    966   LONG      *coor,
    967   SAFEARRAY *psa)
     966  LONG      *coor, 
     967  SAFEARRAY *psa) 
    968968{
    969969  INT   iter=0;
     
    977977    if((hRes = SafeArrayGetUBound(psa, iter, &lUBound)) != S_OK)
    978978      return FALSE;
    979 
    980     if(lLBound == lUBound)
    981       return FALSE;
    982 
     979 
     980    if(lLBound == lUBound) 
     981      return FALSE; 
     982   
    983983    if((coor[iter] >= lLBound) && (coor[iter] <= lUBound))
    984984      return TRUE;
     
    987987  }
    988988  return FALSE;
    989 }
    990 
    991 /************************************************************************
     989} 
     990
     991/************************************************************************ 
    992992 * Method used to calculate the number of cells of the SA
    993993 */
    994994static ULONG getArraySize(
    995   SAFEARRAY *psa)
    996 {
    997   USHORT cCount;
     995  SAFEARRAY *psa) 
     996{
     997  USHORT cCount; 
    998998  ULONG  ulWholeArraySize = 1;
    999999
     
    10011001    ulWholeArraySize *= psa->rgsabound[cCount].cElements;
    10021002
    1003   return ulWholeArraySize;
    1004 }
    1005 
    1006 
    1007 /************************************************************************
     1003  return ulWholeArraySize; 
     1004}
     1005
     1006
     1007/************************************************************************ 
    10081008 * Method used to handle data space dupplication for Copy32 and CopyData32
    10091009 */
    10101010static HRESULT duplicateData(
    1011   SAFEARRAY *psa,
    1012   SAFEARRAY **ppsaOut)
     1011  SAFEARRAY *psa, 
     1012  SAFEARRAY **ppsaOut) 
    10131013{
    10141014  ULONG    ulWholeArraySize; /* size of the thing */
     
    10181018
    10191019  ulWholeArraySize = getArraySize(psa); /* Number of item in SA */
    1020 
     1020 
    10211021  SafeArrayLock(*ppsaOut);
    10221022
    1023   if( isPointer(psa->fFeatures) ) {  /* If datatype is object increment
     1023  if( isPointer(psa->fFeatures) ) {  /* If datatype is object increment 
    10241024                                        object's reference count */
    10251025
     
    10321032
    10331033    /* Copy the source array data into target array */
    1034     memcpy((*ppsaOut)->pvData, psa->pvData,
     1034    memcpy((*ppsaOut)->pvData, psa->pvData, 
    10351035      ulWholeArraySize*psa->cbElements);
    10361036
    1037   } else if( psa->fFeatures & FADF_BSTR ) { /* if datatype is BSTR allocate
     1037  } else if( psa->fFeatures & FADF_BSTR ) { /* if datatype is BSTR allocate 
    10381038                                               the BSTR in the new array */
    10391039
     
    10461046      }
    10471047
    1048       *((BSTR*)((char *) (*ppsaOut)->pvData+(lDelta * psa->cbElements))) =
     1048      *((BSTR*)((char *) (*ppsaOut)->pvData+(lDelta * psa->cbElements))) = 
    10491049        pbstrReAllocStr;
    10501050    }
     
    10521052  } else { /* Simply copy the source array data into target array */
    10531053
    1054     memcpy((*ppsaOut)->pvData, psa->pvData,
     1054    memcpy((*ppsaOut)->pvData, psa->pvData, 
    10551055      ulWholeArraySize*psa->cbElements);
    10561056  }
     
    10621062
    10631063
    1064 /************************************************************************
    1065  *      SafeArrayGetVarType
     1064/************************************************************************ 
     1065 *              SafeArrayGetVarType
    10661066 * Returns the VARTYPE stored in the given safearray
    10671067 */
     
    10991099    hr = S_OK;
    11001100  }
    1101 
     1101 
    11021102  TRACE("HRESULT = %08lx", hr);
    11031103  return hr;
Note: See TracChangeset for help on using the changeset viewer.