[svn:PHP-Sandwich] rev 984 - PHP-Sandwich/trunk

[email protected] 14 Apr 2005 18:39:55 -0000
Newsgroups perl.php.sandwich.dev
Message-ID <[email protected]>
Author: gschlossnagle
Date: Thu Apr 14 11:39:54 2005
New Revision: 984

Modified:
   PHP-Sandwich/trunk/PHP.xs
Log:
add ability to pass AVs and HVs into perl functions (by ref of course)
see t/3.pl, t/4.pl and t/5.pl for examples.

Note that even those these are passed by ref, they aren't currently 
modifiable.  PHP is a bit different that Perl.  In general we should
allow arrays/hashes passed into functions to be 'really' passed by 
ref if the PHP function callee is set to accept those values by reference.

That ability is not implemented at all.




Modified: PHP-Sandwich/trunk/PHP.xs
==============================================================================
--- PHP-Sandwich/trunk/PHP.xs	(original)
+++ PHP-Sandwich/trunk/PHP.xs	Thu Apr 14 11:39:54 2005
@@ -28,6 +28,9 @@
 {
   zval *retval;
   MAKE_STD_ZVAL(retval);
+  while(SvROK(sv)) {
+    sv = SvRV(sv);
+  }
   switch(SvTYPE(sv)) {
     case SVt_IV:   /* int */
       ZVAL_LONG(retval, SvIV(sv));
@@ -44,10 +47,34 @@
       }
       break;
     case SVt_RV:    /* reference */
+      /* should never happen, we fully dereferenced before */
       break;
     case SVt_PVAV: /* indexed array */
+      {
+        int i = 0;
+        SV **element;
+        I32 cnt = av_len((AV *)sv) + 1;
+        array_init(retval);
+        for(i = 0; i < cnt; i++) {
+          element = av_fetch((AV *)sv, i, 0);
+          if(element) {
+            add_index_zval(retval, i, SvZval(*element));
+          }
+        }
+      }
       break;
     case SVt_PVHV: /* assoc. array */
+      {
+        int i = 0;
+        SV *element;
+        char *key;
+        I32 key_len;
+        array_init(retval);
+        hv_iterinit((HV *)sv);
+        while((element = hv_iternextsv((HV *)sv, &key, &key_len)) != NULL) {
+          add_assoc_zval_ex(retval, key, key_len + 1, SvZval(element));
+        }
+      }
       break;
     case SVt_PVCV: /* code */
       break;
@@ -214,6 +241,9 @@
       } else {
         SV * c1 = sv_newmortal();
         switch(retval->type) {
+          case IS_NULL:
+            RETVAL = &PL_sv_undef;
+            break;
           case IS_LONG:
           case IS_BOOL:
           case IS_DOUBLE:
@@ -223,9 +253,10 @@
             sv_magic(RETVAL, c1, PERL_MAGIC_tiedscalar, NULL, 0);
             break;
           default:
+            fprintf(stderr, "unsupported return type in PHP_Interpreter_call\n");
+            RETVAL = &PL_sv_undef;
             break;
         }
-        fprintf(stderr, "worked!\n");
       }
       zval_dtor(&method);
     }
@@ -259,8 +290,9 @@
   SV *new;
   CODE:
     {
+      zval *newz = SvZval(new);
     fprintf(stderr, "PHP::Var::Scalar::STORE\n");
-      assign_to_zval(zptr, new);
+      ZVAL_ZVAL(zptr, newz, 1, 1);
     }
 
 void PHP_V_S_DESTROY(zptr)