phanto          Wed Oct 16 19:56:33 2002 EDT

  Modified files:              
    /php4/ext/com       conversion.c conversion.h VARIANT.c 
  Log:
  @ changed the VARIANT class to be able to create arrays of all types
  @ and not only VT_VARIANT
  
  
Index: php4/ext/com/conversion.c
diff -u php4/ext/com/conversion.c:1.49 php4/ext/com/conversion.c:1.50
--- php4/ext/com/conversion.c:1.49      Thu May 30 19:07:21 2002
+++ php4/ext/com/conversion.c   Wed Oct 16 19:56:33 2002
@@ -42,7 +42,7 @@
 /* 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_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 @@
                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 @@
                        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: php4/ext/com/conversion.h
diff -u php4/ext/com/conversion.h:1.8 php4/ext/com/conversion.h:1.9
--- php4/ext/com/conversion.h:1.8       Thu Oct  4 14:24:43 2001
+++ php4/ext/com/conversion.h   Wed Oct 16 19:56:33 2002
@@ -13,7 +13,7 @@
 
 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);
Index: php4/ext/com/VARIANT.c
diff -u php4/ext/com/VARIANT.c:1.33 php4/ext/com/VARIANT.c:1.34
--- php4/ext/com/VARIANT.c:1.33 Mon Aug  5 19:38:35 2002
+++ php4/ext/com/VARIANT.c      Wed Oct 16 19:56:33 2002
@@ -230,7 +230,7 @@
 
 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);



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to