]> granicus.if.org Git - php/commitdiff
@ changed the VARIANT class to be able to create arrays of all types
authorHarald Radi <phanto@php.net>
Wed, 16 Oct 2002 23:56:33 +0000 (23:56 +0000)
committerHarald Radi <phanto@php.net>
Wed, 16 Oct 2002 23:56:33 +0000 (23:56 +0000)
@ and not only VT_VARIANT

ext/com/VARIANT.c
ext/com/conversion.c
ext/com/conversion.h

index 2dba0d92cd9942376f474796ba8af90a742862dd..d6e944f1835e4ab9501b2e330e0802913d688b1a 100644 (file)
@@ -230,7 +230,7 @@ static int php_VARIANT_set_property_handler(zend_property_reference *property_re
 
 static int do_VARIANT_propset(VARIANT *var_arg, pval *arg_property, pval *value TSRMLS_DC)
 {
-       int type;
+       VARTYPE type;
 
        if (!strcmp(Z_STRVAL_P(arg_property), "value")) {
                php_pval_to_variant(value, var_arg, codepage TSRMLS_CC);
index 189a578f5300d43093e1062e41115e0ba68a4841..b073f43af88cfc78f15d4c51c22a8acc36e27642 100644 (file)
@@ -42,7 +42,7 @@ static void comval_to_variant(pval *pval_arg, VARIANT *var_arg TSRMLS_DC);
 /* implementations */
 PHPAPI void php_pval_to_variant(pval *pval_arg, VARIANT *var_arg, int codepage TSRMLS_DC)
 {
-       int type = VT_EMPTY;    /* default variant type */
+       VARTYPE type = VT_EMPTY;        /* default variant type */
 
        switch (Z_TYPE_P(pval_arg)) {
                case IS_NULL:
@@ -90,11 +90,11 @@ PHPAPI void php_pval_to_variant(pval *pval_arg, VARIANT *var_arg, int codepage T
 
 PHPAPI void php_pval_to_variant_ex(pval *pval_arg, VARIANT *var_arg, pval *pval_type, int codepage TSRMLS_DC)
 {
-       php_pval_to_variant_ex2(pval_arg, var_arg, Z_LVAL_P(pval_type), codepage TSRMLS_CC);
+       php_pval_to_variant_ex2(pval_arg, var_arg, (unsigned short) Z_LVAL_P(pval_type), codepage TSRMLS_CC);
 }
 
 
-PHPAPI void php_pval_to_variant_ex2(pval *pval_arg, VARIANT *var_arg, int type, int codepage TSRMLS_DC)
+PHPAPI void php_pval_to_variant_ex2(pval *pval_arg, VARIANT *var_arg, VARTYPE type, int codepage TSRMLS_DC)
 {
        OLECHAR *unicode_str;
 
@@ -108,7 +108,7 @@ PHPAPI void php_pval_to_variant_ex2(pval *pval_arg, VARIANT *var_arg, int type,
                int numberOfElements = zend_hash_num_elements(ht);
                SAFEARRAY *safeArray;
                SAFEARRAYBOUND bounds[1];
-               VARIANT *v;
+               VARIANT *v, var;
                zval **entry;        /* An entry in the input array */
                
                type &= ~VT_ARRAY;
@@ -118,29 +118,35 @@ PHPAPI void php_pval_to_variant_ex2(pval *pval_arg, VARIANT *var_arg, int type,
                        ALLOC_VARIANT(V_VARIANTREF(var_arg));
                        var_arg = V_VARIANTREF(var_arg);                /* put the array in that VARIANT */
                }
+               if (!type) {
+                       // if no type is given we take the variant type
+                       type = VT_VARIANT;
+               }
 
                bounds[0].lLbound = 0;
                bounds[0].cElements = numberOfElements;
-               safeArray = SafeArrayCreate(VT_VARIANT, 1, bounds);
+               safeArray = SafeArrayCreate(type, 1, bounds);
                
                if (NULL == safeArray) {
                        php_error( E_WARNING,"Unable to convert php array to VARIANT array - %s", numberOfElements ? "" : "(Empty input array)");
                        ZVAL_FALSE(pval_arg);
                } else {
                        V_ARRAY(var_arg) = safeArray;
-                       V_VT(var_arg) = VT_ARRAY|VT_VARIANT;                /* Now have a valid safe array allocated */
+                       V_VT(var_arg) = VT_ARRAY|type;                /* Now have a valid safe array allocated */
                        if (SUCCEEDED(SafeArrayLock(safeArray))) {
                                ulong i;
+                               UINT size = SafeArrayGetElemsize(safeArray);
 
                                zend_hash_internal_pointer_reset(ht);
                                for (i = 0; i < (ulong)numberOfElements; ++i) {
                                        if ((zend_hash_get_current_data(ht, (void **)&entry) == SUCCESS) && (entry != NULL)) { /* Get a pointer to the php array element */
                                                /* Add another value to the safe array */
-                                               if (SUCCEEDED(SafeArrayPtrOfIndex( safeArray, &i, &v))) {               /* Pointer to output element entry retrieved successfully */
-                                                       if (type) {     /* explicit type */
-                                                          php_pval_to_variant_ex2(*entry, v, type, codepage TSRMLS_CC);                /* Do the required conversion */
+                                               if (SUCCEEDED(SafeArrayPtrOfIndex(safeArray, &i, &v))) {                        /* Pointer to output element entry retrieved successfully */
+                                                       if (type == VT_VARIANT) {
+                                                               php_pval_to_variant(*entry, v, codepage TSRMLS_CC);                             /* Do the required conversion */
                                                        } else {
-                                                               php_pval_to_variant(*entry, v, codepage TSRMLS_CC);                    /* Do the required conversion */
+                                                               php_pval_to_variant_ex2(*entry, &var, type, codepage TSRMLS_CC);        /* Do the required conversion */
+                                                               memcpy(v, &(var.byref), size);
                                                        }
                                                } else {
                                                        php_error( E_WARNING,"phpArrayToSafeArray() - Unable to retrieve pointer to output element number (%d)", i);
index b8c534fa221d45735bab1bdb81d4e5a8f7fa6e3b..7bd75f4882c6ad5886448cf166322b51c1359d84 100644 (file)
@@ -13,7 +13,7 @@ BEGIN_EXTERN_C()
 
 PHPAPI void php_pval_to_variant(pval *pval_arg, VARIANT *var_arg, int codepage TSRMLS_DC);
 PHPAPI void php_pval_to_variant_ex(pval *pval_arg, VARIANT *var_arg, pval *pval_type, int codepage TSRMLS_DC);
-PHPAPI void php_pval_to_variant_ex2(pval *pval_arg, VARIANT *var_arg, int type, int codepage TSRMLS_DC);
+PHPAPI void php_pval_to_variant_ex2(pval *pval_arg, VARIANT *var_arg, VARTYPE type, int codepage TSRMLS_DC);
 PHPAPI int php_variant_to_pval(VARIANT *var_arg, pval *pval_arg, int codepage TSRMLS_DC);
 PHPAPI OLECHAR *php_char_to_OLECHAR(char *C_str, uint strlen, int codepage TSRMLS_DC);
 PHPAPI char *php_OLECHAR_to_char(OLECHAR *unicode_str, uint *out_length, int codepage TSRMLS_DC);