diff options
author | Harald Radi <phanto@php.net> | 2001-06-05 16:24:53 +0000 |
---|---|---|
committer | Harald Radi <phanto@php.net> | 2001-06-05 16:24:53 +0000 |
commit | f6dc573f32b767747a09c1a2a5aa59b1be5f5e41 (patch) | |
tree | 089fb95ae6975b4bb85e53dac73953e643aaf84d | |
parent | 14afcf724d96039e8ff59400dab20822e15e4521 (diff) | |
download | php-git-f6dc573f32b767747a09c1a2a5aa59b1be5f5e41.tar.gz |
put VT_ARRAY outside of the switch
-rw-r--r-- | ext/com/conversion.c | 162 | ||||
-rw-r--r-- | ext/rpc/com/conversion.c | 162 |
2 files changed, 160 insertions, 164 deletions
diff --git a/ext/com/conversion.c b/ext/com/conversion.c index 9af7032e24..a352f0185d 100644 --- a/ext/com/conversion.c +++ b/ext/com/conversion.c @@ -404,93 +404,91 @@ PHPAPI int php_variant_to_pval(VARIANT *var_arg, pval *pval_arg, int persistent, int ret = SUCCESS; /* Add SafeArray support */ - switch(var_arg->vt & ~VT_BYREF) - { - case VT_ARRAY: - { - SAFEARRAY *array = V_ARRAY(var_arg); - LONG indices[1]; - LONG lbound=0, ubound; - VARTYPE vartype; - register int ii; - UINT Dims; - VARIANT vv; - pval *element; - - /* TODO: Add support for multi-dimensional SafeArrays */ - /* For now just validate that the SafeArray has one dimension */ - if (1 != (Dims = SafeArrayGetDim(array))) - { - php_error(E_WARNING,"Unsupported: multi-dimensional (%d) SafeArrays", Dims); - var_reset(pval_arg); - return FAILURE; - } + if (var_arg->vt & VT_ARRAY) + { + SAFEARRAY *array = V_ARRAY(var_arg); + LONG indices[1]; + LONG lbound=0, ubound; + VARTYPE vartype; + register int ii; + UINT Dims; + VARIANT vv; + pval *element; + + /* TODO: Add support for multi-dimensional SafeArrays */ + /* For now just validate that the SafeArray has one dimension */ + if (1 != (Dims = SafeArrayGetDim(array))) + { + php_error(E_WARNING,"Unsupported: multi-dimensional (%d) SafeArrays", Dims); + var_reset(pval_arg); + return FAILURE; + } - /* This call has failed for everything I have tried */ - /* But best leave it to be on the safe side */ - if (S_OK != SafeArrayGetVartype(array, &vartype)) - { - /* Fall back to what we do know */ - /* Mask off the array bit and assume */ - /* what is left is the type of the array */ - /* elements */ - vartype = var_arg->vt & ~VT_ARRAY; - } - SafeArrayGetUBound(array, 1, &ubound); - SafeArrayGetLBound(array, 1, &lbound); + /* This call has failed for everything I have tried */ + /* But best leave it to be on the safe side */ + if (S_OK != SafeArrayGetVartype(array, &vartype)) + { + /* Fall back to what we do know */ + /* Mask off the array bit and assume */ + /* what is left is the type of the array */ + /* elements */ + vartype = var_arg->vt & ~VT_ARRAY; + } + SafeArrayGetUBound(array, 1, &ubound); + SafeArrayGetLBound(array, 1, &lbound); - /* Since COM returned an array we set up the php */ - /* return value to be an array */ - array_init(pval_arg); + /* Since COM returned an array we set up the php */ + /* return value to be an array */ + array_init(pval_arg); - /* Walk the safe array */ - for (ii=lbound;ii<=ubound;ii++) - { - indices[0] = ii; - VariantInit(&vv); /* Docs say this just set the vt field, but you never know */ - /* Set up a variant to pass to a recursive call */ - /* So that we do not need to have two copies */ - /* of the code */ - vv.vt = vartype; - if (S_OK != SafeArrayGetElement(array, indices, (VOID *) &(vv.lVal))) - { - /* Failure to retieve an element probably means the array is sparse */ - /* So leave the php array sparse too */ - continue; - } - /* Create an element to be added to the array */ - ALLOC_ZVAL(element); - /* Call ourself again to handle the base type conversion */ - /* If SafeArrayGetElement proclaims to allocate */ - /* memory for a BSTR, so the recursive call frees */ - /* the string correctly */ - if (FAILURE == php_variant_to_pval(&vv, element, persistent, codepage)) - { - /* Error occurred setting up array element */ - /* Error was displayed by the recursive call */ - FREE_ZVAL(element); - /* TODO: Do we stop here, or go on and */ - /* try to make sense of the rest of the array */ - /* Going on leads to multiple errors displayed */ - /* for the same conversion. For large arrays that */ - /* could be very annoying */ - /* And if we don't go on - what to do about */ - /* the parts of the array that are OK? */ - /* break; */ - } - else - { - /* Just insert the element into our return array */ - add_index_zval(pval_arg, ii, element); - } - } - - /* Clean up the SafeArray since that is our responsibility */ - SafeArrayDestroyData(array); - SafeArrayDestroyDescriptor(array); + /* Walk the safe array */ + for (ii=lbound;ii<=ubound;ii++) + { + indices[0] = ii; + VariantInit(&vv); /* Docs say this just set the vt field, but you never know */ + /* Set up a variant to pass to a recursive call */ + /* So that we do not need to have two copies */ + /* of the code */ + vv.vt = vartype; + if (S_OK != SafeArrayGetElement(array, indices, (VOID *) &(vv.lVal))) + { + /* Failure to retieve an element probably means the array is sparse */ + /* So leave the php array sparse too */ + continue; + } + /* Create an element to be added to the array */ + ALLOC_ZVAL(element); + /* Call ourself again to handle the base type conversion */ + /* If SafeArrayGetElement proclaims to allocate */ + /* memory for a BSTR, so the recursive call frees */ + /* the string correctly */ + if (FAILURE == php_variant_to_pval(&vv, element, persistent, codepage)) + { + /* Error occurred setting up array element */ + /* Error was displayed by the recursive call */ + FREE_ZVAL(element); + /* TODO: Do we stop here, or go on and */ + /* try to make sense of the rest of the array */ + /* Going on leads to multiple errors displayed */ + /* for the same conversion. For large arrays that */ + /* could be very annoying */ + /* And if we don't go on - what to do about */ + /* the parts of the array that are OK? */ + /* break; */ } - break; + else + { + /* Just insert the element into our return array */ + add_index_zval(pval_arg, ii, element); + } + } + /* Clean up the SafeArray since that is our responsibility */ + SafeArrayDestroyData(array); + SafeArrayDestroyDescriptor(array); + } + else switch(var_arg->vt & ~VT_BYREF) + { case VT_EMPTY: var_uninit(pval_arg); break; diff --git a/ext/rpc/com/conversion.c b/ext/rpc/com/conversion.c index 9af7032e24..a352f0185d 100644 --- a/ext/rpc/com/conversion.c +++ b/ext/rpc/com/conversion.c @@ -404,93 +404,91 @@ PHPAPI int php_variant_to_pval(VARIANT *var_arg, pval *pval_arg, int persistent, int ret = SUCCESS; /* Add SafeArray support */ - switch(var_arg->vt & ~VT_BYREF) - { - case VT_ARRAY: - { - SAFEARRAY *array = V_ARRAY(var_arg); - LONG indices[1]; - LONG lbound=0, ubound; - VARTYPE vartype; - register int ii; - UINT Dims; - VARIANT vv; - pval *element; - - /* TODO: Add support for multi-dimensional SafeArrays */ - /* For now just validate that the SafeArray has one dimension */ - if (1 != (Dims = SafeArrayGetDim(array))) - { - php_error(E_WARNING,"Unsupported: multi-dimensional (%d) SafeArrays", Dims); - var_reset(pval_arg); - return FAILURE; - } + if (var_arg->vt & VT_ARRAY) + { + SAFEARRAY *array = V_ARRAY(var_arg); + LONG indices[1]; + LONG lbound=0, ubound; + VARTYPE vartype; + register int ii; + UINT Dims; + VARIANT vv; + pval *element; + + /* TODO: Add support for multi-dimensional SafeArrays */ + /* For now just validate that the SafeArray has one dimension */ + if (1 != (Dims = SafeArrayGetDim(array))) + { + php_error(E_WARNING,"Unsupported: multi-dimensional (%d) SafeArrays", Dims); + var_reset(pval_arg); + return FAILURE; + } - /* This call has failed for everything I have tried */ - /* But best leave it to be on the safe side */ - if (S_OK != SafeArrayGetVartype(array, &vartype)) - { - /* Fall back to what we do know */ - /* Mask off the array bit and assume */ - /* what is left is the type of the array */ - /* elements */ - vartype = var_arg->vt & ~VT_ARRAY; - } - SafeArrayGetUBound(array, 1, &ubound); - SafeArrayGetLBound(array, 1, &lbound); + /* This call has failed for everything I have tried */ + /* But best leave it to be on the safe side */ + if (S_OK != SafeArrayGetVartype(array, &vartype)) + { + /* Fall back to what we do know */ + /* Mask off the array bit and assume */ + /* what is left is the type of the array */ + /* elements */ + vartype = var_arg->vt & ~VT_ARRAY; + } + SafeArrayGetUBound(array, 1, &ubound); + SafeArrayGetLBound(array, 1, &lbound); - /* Since COM returned an array we set up the php */ - /* return value to be an array */ - array_init(pval_arg); + /* Since COM returned an array we set up the php */ + /* return value to be an array */ + array_init(pval_arg); - /* Walk the safe array */ - for (ii=lbound;ii<=ubound;ii++) - { - indices[0] = ii; - VariantInit(&vv); /* Docs say this just set the vt field, but you never know */ - /* Set up a variant to pass to a recursive call */ - /* So that we do not need to have two copies */ - /* of the code */ - vv.vt = vartype; - if (S_OK != SafeArrayGetElement(array, indices, (VOID *) &(vv.lVal))) - { - /* Failure to retieve an element probably means the array is sparse */ - /* So leave the php array sparse too */ - continue; - } - /* Create an element to be added to the array */ - ALLOC_ZVAL(element); - /* Call ourself again to handle the base type conversion */ - /* If SafeArrayGetElement proclaims to allocate */ - /* memory for a BSTR, so the recursive call frees */ - /* the string correctly */ - if (FAILURE == php_variant_to_pval(&vv, element, persistent, codepage)) - { - /* Error occurred setting up array element */ - /* Error was displayed by the recursive call */ - FREE_ZVAL(element); - /* TODO: Do we stop here, or go on and */ - /* try to make sense of the rest of the array */ - /* Going on leads to multiple errors displayed */ - /* for the same conversion. For large arrays that */ - /* could be very annoying */ - /* And if we don't go on - what to do about */ - /* the parts of the array that are OK? */ - /* break; */ - } - else - { - /* Just insert the element into our return array */ - add_index_zval(pval_arg, ii, element); - } - } - - /* Clean up the SafeArray since that is our responsibility */ - SafeArrayDestroyData(array); - SafeArrayDestroyDescriptor(array); + /* Walk the safe array */ + for (ii=lbound;ii<=ubound;ii++) + { + indices[0] = ii; + VariantInit(&vv); /* Docs say this just set the vt field, but you never know */ + /* Set up a variant to pass to a recursive call */ + /* So that we do not need to have two copies */ + /* of the code */ + vv.vt = vartype; + if (S_OK != SafeArrayGetElement(array, indices, (VOID *) &(vv.lVal))) + { + /* Failure to retieve an element probably means the array is sparse */ + /* So leave the php array sparse too */ + continue; + } + /* Create an element to be added to the array */ + ALLOC_ZVAL(element); + /* Call ourself again to handle the base type conversion */ + /* If SafeArrayGetElement proclaims to allocate */ + /* memory for a BSTR, so the recursive call frees */ + /* the string correctly */ + if (FAILURE == php_variant_to_pval(&vv, element, persistent, codepage)) + { + /* Error occurred setting up array element */ + /* Error was displayed by the recursive call */ + FREE_ZVAL(element); + /* TODO: Do we stop here, or go on and */ + /* try to make sense of the rest of the array */ + /* Going on leads to multiple errors displayed */ + /* for the same conversion. For large arrays that */ + /* could be very annoying */ + /* And if we don't go on - what to do about */ + /* the parts of the array that are OK? */ + /* break; */ } - break; + else + { + /* Just insert the element into our return array */ + add_index_zval(pval_arg, ii, element); + } + } + /* Clean up the SafeArray since that is our responsibility */ + SafeArrayDestroyData(array); + SafeArrayDestroyDescriptor(array); + } + else switch(var_arg->vt & ~VT_BYREF) + { case VT_EMPTY: var_uninit(pval_arg); break; |