Ignore:
Timestamp:
Oct 3, 2001, 9:22:00 PM (24 years ago)
Author:
sandervl
Message:

wine update

File:
1 edited

Legend:

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

    r6711 r6944  
    88 */
    99
    10 #ifdef __WIN32OS2__
    11 #define HAVE_FLOAT_H
    12 #define WINE_LARGE_INTEGER
    13 #include "oleaut32.h"
    14 #endif
    1510#include <stdio.h>
    1611#include <string.h>
     
    2419DEFAULT_DEBUG_CHANNEL(ole);
    2520
     21#define SYSDUPSTRING(str) SysAllocStringLen((str), SysStringLen(str))
     22
    2623/* Localy used methods */
    2724static INT 
     
    5956{
    6057  /* 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     */
     58VARTYPE_NOT_SUPPORTED,  /* VT_EMPTY    [V]   [P]    nothing                     */
     59VARTYPE_NOT_SUPPORTED,  /* VT_NULL     [V]   [P]    SQL style Nul       */
     602,                      /* VT_I2       [V][T][P][S] 2 byte signed int */
     614,                      /* VT_I4       [V][T][P][S] 4 byte signed int */
     624,                      /* VT_R4       [V][T][P][S] 4 byte real */
     638,                      /* VT_R8       [V][T][P][S] 8 byte real */
    67648,                      /* 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 *     */
     658,                      /* VT_DATE     [V][T][P][S] date */
     66sizeof(BSTR),           /* VT_BSTR     [V][T][P][S] OLE Automation string*/
     67sizeof(LPDISPATCH),     /* VT_DISPATCH [V][T][P][S] IDispatch * */
    71684,                      /* 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     */
     694,                      /* VT_BOOL     [V][T][P][S] True=-1, False=0*/
     70sizeof(VARIANT),        /* VT_VARIANT  [V][T][P][S] VARIANT *   */
     71sizeof(LPUNKNOWN),      /* VT_UNKNOWN  [V][T]   [S] IUnknown * */
     72sizeof(DECIMAL),        /* VT_DECIMAL  [V][T]   [S] 16 byte fixed point */
    7673VARTYPE_NOT_SUPPORTED,                         /* no VARTYPE here..... */
    7774VARTYPE_NOT_SUPPORTED,  /* VT_I1          [T]       signed char */
    78 1,                          /* VT_UI1      [V][T][P][S] unsigned char                   */
     751,                      /* VT_UI1      [V][T][P][S] unsigned char                       */
    7976VARTYPE_NOT_SUPPORTED,  /* VT_UI2         [T][P]    unsigned short      */
    8077VARTYPE_NOT_SUPPORTED,  /* VT_UI4         [T][P]    unsigned short      */
     
    109106
    110107/*************************************************************************
    111  *              SafeArrayAllocDescriptor
     108 *              SafeArrayAllocDescriptor (OLEAUT32.36)
    112109 * Allocate the appropriate amount of memory for the SafeArray descriptor
    113110 */
     
    134131
    135132/*************************************************************************
    136  *              SafeArrayAllocData
     133 *              SafeArrayAllocData (OLEAUT32.37)
    137134 * Allocate the appropriate amount of data for the SafeArray data
    138135 */
     
    141138{
    142139  ULONG  ulWholeArraySize;   /* to store the size of the whole thing */
    143 
    144   dprintf(("SafeArrayAllocData %x", psa));
    145140
    146141  if(! validArg(psa))
     
    161156
    162157/*************************************************************************
    163  *              SafeArrayCreate
     158 *              SafeArrayCreate (OLEAUT32.15)
    164159 * Create a SafeArray object by encapsulating AllocDescriptor and AllocData
    165160 */
     
    172167  HRESULT   hRes;
    173168  USHORT    cDim;
    174 
    175   dprintf(("SafeArrayCreate %x %d %x", vt, cDims, rgsabound));
    176169
    177170  /* Validate supported VARTYPE */
     
    208201
    209202/*************************************************************************
    210  *              SafeArrayDestroyDescriptor
     203 *              SafeArrayDestroyDescriptor (OLEAUT32.38)
    211204 * Frees the memory associated with the descriptor.
    212205 */
     
    214207  SAFEARRAY *psa)
    215208{
    216   dprintf(("SafeArrayDestroyDescriptor %x", psa));
    217 
    218209  /* Check for lockness before to free... */
    219210  if(psa->cLocks > 0)
     
    229220
    230221/*************************************************************************
    231  *              SafeArrayLock
     222 *              SafeArrayLock (OLEAUT32.21)
    232223 * Increment the lock counter
    233224 *
     
    239230  SAFEARRAY *psa)
    240231{
    241   dprintf(("SafeArrayLock %x", psa));
    242 
    243232  if(! validArg(psa))     
    244233    return E_INVALIDARG;
     
    250239
    251240/*************************************************************************
    252  *              SafeArrayUnlock
     241 *              SafeArrayUnlock (OLEAUT32.22)
    253242 * Decrement the lock counter
    254243 */
     
    256245  SAFEARRAY *psa)
    257246{
    258   dprintf(("SafeArrayUnlock %x", psa));
    259 
    260247  if(! validArg(psa))
    261248    return E_INVALIDARG;
     
    269256
    270257/*************************************************************************
    271  *              SafeArrayPutElement
     258 *              SafeArrayPutElement (OLEAUT32.26)
    272259 * Set the data at the given coordinate
    273260 */
     
    280267                                         the desired one... */
    281268  PVOID elementStorageAddress = NULL; /* Adress to store the data */
    282   BSTR  pbstrReAllocStr     = NULL; /* BSTR reallocated */
    283 
    284   dprintf(("SafeArrayPutElement %x %x %x", psa, rgIndices, pv));
    285269
    286270  /* Validate the index given */
     
    300284    if(isPointer(psa->fFeatures)) { /* increment ref count for this pointer */
    301285
    302       *((VOID**)elementStorageAddress) = *(VOID**)pv;
     286      *((PVOID*)elementStorageAddress) = *(PVOID*)pv;
    303287      IUnknown_AddRef( *(IUnknown**)pv);
    304288
     
    306290
    307291      if(psa->fFeatures == FADF_BSTR) { /* Create a new object */
    308 
    309         if((pbstrReAllocStr = SysAllocString( (OLECHAR*)pv )) == NULL) {
     292        BSTR pbstrReAllocStr = NULL;
     293        if(pv &&
     294           ((pbstrReAllocStr = SYSDUPSTRING( (OLECHAR*)pv )) == NULL)) {
    310295          SafeArrayUnlock(psa); 
    311296          return E_OUTOFMEMORY;
    312297        } else
    313298          *((BSTR*)elementStorageAddress) = pbstrReAllocStr;
    314 
    315       } else /* dupplicate the memory */
     299      }
     300      else if(psa->fFeatures == FADF_VARIANT) {
     301        HRESULT hr = VariantCopy(elementStorageAddress, pv);
     302        if (FAILED(hr)) {
     303          SafeArrayUnlock(psa);
     304          return hr;
     305        }
     306      }
     307      else /* duplicate the memory */
    316308        memcpy(elementStorageAddress, pv, SafeArrayGetElemsize(psa) );
    317309    }
     
    328320
    329321/*************************************************************************
    330  *              SafeArrayGetElement
     322 *              SafeArrayGetElement (OLEAUT32.25)
    331323 * Return the data element corresponding the the given coordinate
    332324 */
     
    339331                                         the desired one... */
    340332  PVOID elementStorageAddress = NULL; /* Adress to store the data */
    341   BSTR  pbstrReturnedStr    = NULL; /* BSTR reallocated */
    342 
    343   dprintf(("SafeArrayGetElement %x %x %x", psa, rgIndices, pv));
    344333
    345334  if(! validArg(psa))
     
    358347 
    359348    if( psa->fFeatures == FADF_BSTR) {           /* reallocate the obj */
    360       if( (pbstrReturnedStr =
    361           SysAllocString( *(OLECHAR**)elementStorageAddress )) == NULL) {
     349      BSTR pbstrStoredStr = *(OLECHAR**)elementStorageAddress;
     350      BSTR pbstrReturnedStr = NULL;
     351      if( pbstrStoredStr &&
     352          ((pbstrReturnedStr = SYSDUPSTRING( pbstrStoredStr )) == NULL) ) {
    362353        SafeArrayUnlock(psa);
    363354        return E_OUTOFMEMORY;
    364355      } else
    365356        *((BSTR*)pv) = pbstrReturnedStr;
    366        
    367     } else if( isPointer(psa->fFeatures) )       /* simply copy the pointer */
    368        pv = *((PVOID*)elementStorageAddress);
     357    }
     358    else if( psa->fFeatures == FADF_VARIANT) {
     359      HRESULT hr = VariantCopy(pv, elementStorageAddress);
     360      if (FAILED(hr)) {
     361        SafeArrayUnlock(psa);
     362        return hr;
     363      }
     364    }
     365    else if( isPointer(psa->fFeatures) )         /* simply copy the pointer */
     366      *(PVOID*)pv = *((PVOID*)elementStorageAddress);
    369367    else                                         /* copy the bytes */
    370       memcpy(pv, elementStorageAddress, SafeArrayGetElemsize(psa) );
     368      memcpy(pv, elementStorageAddress, psa->cbElements );
    371369
    372370  } else {
     
    379377
    380378/*************************************************************************
    381  *              SafeArrayGetUBound
     379 *              SafeArrayGetUBound (OLEAUT32.19)
    382380 * return the UP bound for a given array dimension
    383381 */
     
    387385  LONG      *plUbound)
    388386{
    389 
    390   dprintf(("SafeArrayGetUBound %x %x %x", psa, nDim, plUbound));
    391 
    392387  if(! validArg(psa))   
    393388    return E_INVALIDARG;
     
    396391    return DISP_E_BADINDEX;
    397392
     393  if(0 == nDim)
     394    return DISP_E_BADINDEX;
     395
    398396  *plUbound = psa->rgsabound[nDim-1].lLbound +
    399397              psa->rgsabound[nDim-1].cElements - 1;
     
    403401
    404402/*************************************************************************
    405  *              SafeArrayGetLBound
     403 *              SafeArrayGetLBound (OLEAUT32.20)
    406404 * Return the LO bound for a given array dimension
    407405 */
     
    417415    return DISP_E_BADINDEX;
    418416
     417  if(0 == nDim)
     418    return DISP_E_BADINDEX;
     419 
    419420  *plLbound = psa->rgsabound[nDim-1].lLbound;
    420421  return S_OK;
     
    422423
    423424/*************************************************************************
    424  *              SafeArrayGetDim
     425 *              SafeArrayGetDim (OLEAUT32.17)
    425426 * returns the number of dimension in the array
    426427 */
     
    439440
    440441/*************************************************************************
    441  *              SafeArrayGetElemsize
     442 *              SafeArrayGetElemsize (OLEAUT32.18)
    442443 * Return the size of the element in the array
    443444 */
     
    456457
    457458/*************************************************************************
    458  *              SafeArrayAccessData
     459 *              SafeArrayAccessData (OLEAUT32.23)
    459460 * increment the access count and return the data
    460461 */
     
    484485
    485486/*************************************************************************
    486  *              SafeArrayUnaccessData
     487 *              SafeArrayUnaccessData (OLEAUT32.24)
    487488 * Decrement the access count
    488489 */
     
    497498
    498499/************************************************************************
    499  *              SafeArrayPtrOfIndex
     500 *              SafeArrayPtrOfIndex (OLEAUT32.148)
    500501 * Return a pointer to the element at rgIndices
    501502 */
     
    523524
    524525/************************************************************************
    525  *              SafeArrayDestroyData
     526 *              SafeArrayDestroyData (OLEAUT32.39)
    526527 * Frees the memory data bloc
    527528 */
     
    532533  ULONG    ulWholeArraySize; /* count spot in array  */
    533534  ULONG    ulDataIter;       /* to iterate the data space */
    534   IUnknown *punk;
    535   BSTR   bstr;
    536535
    537536  if(! validArg(psa))
     
    544543
    545544  if(isPointer(psa->fFeatures)) {           /* release the pointers */
     545    IUnknown *punk;
    546546
    547547    for(ulDataIter=0; ulDataIter < ulWholeArraySize; ulDataIter++) {
     
    552552    }
    553553
    554   } else if(psa->fFeatures & FADF_BSTR) {  /* deallocate the obj */
     554  }
     555  else if(psa->fFeatures & FADF_BSTR) {  /* deallocate the obj */
     556    BSTR bstr;
    555557
    556558    for(ulDataIter=0; ulDataIter < ulWholeArraySize; ulDataIter++) {
     
    559561      if( bstr != NULL)
    560562        SysFreeString( bstr );
     563    }
     564  }
     565  else if(psa->fFeatures & FADF_VARIANT) {  /* deallocate the obj */
     566
     567    for(ulDataIter=0; ulDataIter < ulWholeArraySize; ulDataIter++) {
     568      VariantClear((VARIANT*)((char *) psa->pvData+(ulDataIter*(psa->cbElements))));
    561569    }
    562570  }
     
    578586
    579587/************************************************************************
    580  *              SafeArrayCopyData
     588 *              SafeArrayCopyData (OLEAUT32.412)
    581589 * Copy the psaSource's data block into psaTarget if dimension and size
    582590 * permits it.
     
    616624    }
    617625
    618   } else if( (*psaTarget)->fFeatures & FADF_BSTR) {  /* the target contain BSTR
     626  }
     627  else if( (*psaTarget)->fFeatures & FADF_BSTR) {    /* the target contain BSTR
    619628                                                        that must be freed */
    620629    for(lDelta=0;lDelta < ulWholeArraySize; lDelta++) {
     
    626635    }
    627636  }
     637  else if( (*psaTarget)->fFeatures & FADF_VARIANT) {
     638
     639    for(lDelta=0;lDelta < ulWholeArraySize; lDelta++) {
     640      VariantClear((VARIANT*)((char *) (*psaTarget)->pvData + (lDelta * (*psaTarget)->cbElements)));
     641    }
     642  }
    628643
    629644  return duplicateData(psaSource, psaTarget);
     
    631646
    632647/************************************************************************
    633  *              SafeArrayDestroy
     648 *              SafeArrayDestroy (OLEAUT32.16)
    634649 * Deallocates all memory reserved for the SafeArray
    635650 */
     
    653668
    654669/************************************************************************
    655  *              SafeArrayCopy
     670 *              SafeArrayCopy (OLEAUT32.27)
    656671 * Make a dupplicate of a SafeArray
    657672 */
     
    706721
    707722/************************************************************************
    708  *              SafeArrayCreateVector
     723 *              SafeArrayCreateVector (OLEAUT32.411)
    709724 * Creates a one dimension safearray where the data is next to the
    710725 * SAFEARRAY structure.
     
    743758
    744759/************************************************************************
    745  *              SafeArrayRedim
     760 *              SafeArrayRedim (OLEAUT32.40)
    746761 * Changes the caracteristics of the last dimension of the SafeArray
    747762 */
     
    808823  /* Check whether the size of the chunk makes sense... That's the only thing
    809824     I can think of now... */
     825
    810826  psaSize = HeapSize(GetProcessHeap(), 0, psa);
    811827  if (psaSize == -1)
     
    838854  if(lDelta < 0) {                    /* array needs to be shorthen  */
    839855    if( isPointer(psa->fFeatures))    /* ptr that need to be released */
    840             for(;lDelta < 0; lDelta++) {
     856      for(;lDelta < 0; lDelta++) {
    841857              punk = *(IUnknown**)
    842858          ((char *) psa->pvData+((ulWholeArraySize+lDelta)*psa->cbElements));
     
    847863
    848864    else if(psa->fFeatures & FADF_BSTR)  /* BSTR that need to be freed */
    849             for(;lDelta < 0; lDelta++) {
     865      for(;lDelta < 0; lDelta++) {
    850866        bstr = *(BSTR*)
    851867          ((char *) psa->pvData+((ulWholeArraySize+lDelta)*psa->cbElements));
     
    853869        if( bstr != NULL )
    854870          SysFreeString( bstr );
     871      }
     872    else if(psa->fFeatures & FADF_VARIANT)
     873      for(;lDelta < 0; lDelta++) {
     874        VariantClear((VARIANT*)((char *) psa->pvData+((ulWholeArraySize+lDelta)*psa->cbElements)));
    855875      }
    856876  }
     
    894914{
    895915  switch(vt) {
     916    case VT_BSTR:      return FADF_BSTR;
    896917    case VT_UNKNOWN:   return FADF_UNKNOWN;
    897918    case VT_DISPATCH:  return FADF_DISPATCH;
    898     case VT_BSTR:      return FADF_BSTR;
     919    case VT_VARIANT:   return FADF_VARIANT;
    899920  }
    900921  return 0;
     
    973994
    974995  for(; iter<psa->cDims; iter++) {
    975     if((hRes = SafeArrayGetLBound(psa, iter, &lLBound)) != S_OK)
     996    if((hRes = SafeArrayGetLBound(psa, (iter+1), &lLBound)) != S_OK)
    976997      return FALSE;
    977     if((hRes = SafeArrayGetUBound(psa, iter, &lUBound)) != S_OK)
     998    if((hRes = SafeArrayGetUBound(psa, (iter+1), &lUBound)) != S_OK)
    978999      return FALSE;
    9791000 
     
    10141035  ULONG    ulWholeArraySize; /* size of the thing */
    10151036  LONG     lDelta;
    1016   IUnknown *punk;
    1017   BSTR   pbstrReAllocStr = NULL; /* BSTR reallocated */
    10181037
    10191038  ulWholeArraySize = getArraySize(psa); /* Number of item in SA */
     
    10231042  if( isPointer(psa->fFeatures) ) {  /* If datatype is object increment
    10241043                                        object's reference count */
     1044    IUnknown *punk;
    10251045
    10261046    for(lDelta=0; lDelta < ulWholeArraySize; lDelta++) {
     
    10351055      ulWholeArraySize*psa->cbElements);
    10361056
    1037   } else if( psa->fFeatures & FADF_BSTR ) { /* if datatype is BSTR allocate
    1038                                                the BSTR in the new array */
     1057  }
     1058  else if( psa->fFeatures & FADF_BSTR ) { /* if datatype is BSTR allocate
     1059                                             the BSTR in the new array */
     1060    BSTR   pbstrReAllocStr = NULL;
    10391061
    10401062    for(lDelta=0; lDelta < ulWholeArraySize; lDelta++) {
    1041       if(( pbstrReAllocStr = SysAllocString(
     1063      if(( pbstrReAllocStr = SYSDUPSTRING(
    10421064            *(BSTR*)((char *) psa->pvData+(lDelta * psa->cbElements)))) == NULL) {
    10431065
     
    10501072    }
    10511073
    1052   } else { /* Simply copy the source array data into target array */
     1074  }
     1075  else if( psa->fFeatures & FADF_VARIANT ) {
     1076
     1077    for(lDelta=0; lDelta < ulWholeArraySize; lDelta++) {
     1078      VariantCopy((VARIANT*)((char *) (*ppsaOut)->pvData+(lDelta * psa->cbElements)),
     1079                  (VARIANT*)((char *) psa->pvData+(lDelta * psa->cbElements)));
     1080    }
     1081
     1082  }
     1083  else { /* Simply copy the source array data into target array */
    10531084
    10541085    memcpy((*ppsaOut)->pvData, psa->pvData,
     
    10631094
    10641095/************************************************************************
    1065  *              SafeArrayGetVarType
     1096 *              SafeArrayGetVarType (OLEAUT32.77)
    10661097 * Returns the VARTYPE stored in the given safearray
    10671098 */
     
    10781109  {
    10791110    /* VT tag @ negative offset 4 in the array descriptor */
    1080     FIXME("Returning VT_BSTR instead of VT_...");
     1111    FIXME("Returning VT_BSTR instead of VT_...\n");
    10811112    vt = VT_BSTR;
    10821113  }
     
    10851116    vt = VT_RECORD;
    10861117  }
     1118  else if (psa->fFeatures & FADF_BSTR)
     1119  {
     1120    vt = VT_BSTR;
     1121  }
     1122  else if (psa->fFeatures & FADF_UNKNOWN)
     1123  {
     1124    vt = VT_UNKNOWN;
     1125  }
    10871126  else if (psa->fFeatures & FADF_DISPATCH)
    10881127  {
    10891128    vt = VT_DISPATCH;
    10901129  }
    1091   else if (psa->fFeatures & FADF_UNKNOWN)
     1130  else if (psa->fFeatures & FADF_VARIANT)
    10921131  {
    1093     vt = VT_UNKNOWN;
     1132    vt = VT_VARIANT;
    10941133  }
    10951134
     
    10991138    hr = S_OK;
    11001139  }
    1101  
    1102   TRACE("HRESULT = %08lx", hr);
     1140
     1141  TRACE("HRESULT = %08lx\n", hr);
    11031142  return hr;
    11041143}
Note: See TracChangeset for help on using the changeset viewer.