[svn:PHP-Sandwich] rev 1382 - in PHP-Sandwich/trunk: . t

[email protected] 5 Jul 2005 18:06:12 -0000
Newsgroups perl.php.sandwich.dev
Message-ID <[email protected]>
Author: gschlossnagle
Date: Tue Jul  5 11:06:12 2005
New Revision: 1382

Modified:
   PHP-Sandwich/trunk/PHP.xs
   PHP-Sandwich/trunk/phpfuncs.c
   PHP-Sandwich/trunk/phpinterp.h
   PHP-Sandwich/trunk/t/19.t
   PHP-Sandwich/trunk/t/8.t
Log:
humongo trash debuggin commit, will clear out later

Modified: PHP-Sandwich/trunk/PHP.xs
==============================================================================
--- PHP-Sandwich/trunk/PHP.xs	(original)
+++ PHP-Sandwich/trunk/PHP.xs	Tue Jul  5 11:06:12 2005
@@ -154,7 +154,7 @@ zval *SvZval(SV *sv TSRMLS_DC)
         }
       } else {
         fprintf(stderr, "[%s:%d] can I be here?\n", __FILE__, __LINE__);
-        // do something else
+        plsv_wrap_sv(retval, orig_sv TSRMLS_CC);
       }
       break;
     case SVt_PVLV: 
@@ -456,6 +456,13 @@ SV* SAND_new(classname, ...)
           else if(!strcmp(trackvars_key, "FILES")) {
             track_vars_array = PG(http_globals)[TRACK_VARS_FILES];
           }
+          /*
+          else if(!strcmp(trackvars_key, "BRIC")) {
+            zval *bric = SvZval(trackvars TSRMLS_CC);
+            zend_register_auto_global("BRIC", sizeof("BRIC")-1, NULL TSRMLS_CC);
+            zend_hash_update(&EG(symbol_table), "BRIC", sizeof("BRIC"), &bric, sizeof(zval *), NULL);
+          }
+          */
           else if(!strcmp(trackvars_key, "OUTPUT")) {
             sandwich_per_interp *interp = (sandwich_per_interp *)SG(server_context);
             if(interp) {
@@ -488,6 +495,7 @@ SV* SAND_new(classname, ...)
       }
       RETVAL = newSV(0);
       sv_setref_pv(RETVAL, classname, (void *)interp);
+      SvREFCNT_inc(RETVAL);
     }
   OUTPUT:
     RETVAL
@@ -507,6 +515,8 @@ SV *SAND_include(interp, file)
   char *file;
   CODE:
     {
+      sv_dump(SvRV(ST(0)));
+      fprintf(stderr, "calling include(%s)\n", file);
       if(sandwich_include(interp, file) == 0) {
         RETVAL = newSVsv(ST(0));
       }
@@ -530,7 +540,6 @@ SV *SAND_call(method_name, interp, ...)
       zval *retval;
       void *old_ctx;
       char *croakstr = NULL;
-
       old_ctx = tsrm_set_interpreter_context(interp->ctx);
       {
         TSRMLS_FETCH();
@@ -544,17 +553,15 @@ SV *SAND_call(method_name, interp, ...)
           param_count = items - 2;
         }
         retval = sandwich_call_function(interp, &method, params, param_count);
+        zval_dtor(&method);
         if(retval == NULL) {
-          croakstr = "A PHP error occured";
-          goto cleanup;
+          tsrm_set_interpreter_context(old_ctx);
+          croak("A PHP error occured\n");
         } else {
           RETVAL = newSVzval(retval, interp);
         }
-  cleanup:
-        zval_dtor(&method);
       }
       tsrm_set_interpreter_context(old_ctx);
-      if(croakstr) croak(croakstr);
     }
   OUTPUT:
     RETVAL
@@ -563,6 +570,8 @@ void SAND_DESTROY(interp)
   PHP_Interpreter interp;
   CODE:
     {
+      sv_dump(ST(0));
+      sv_dump(SvRV(ST(0)));
       sandwich_interp_dec_ref(interp);
     }
 
@@ -574,6 +583,9 @@ SV* SAND_get_output(interp)
       if(SvROK(oh) && SvPOK(SvRV(oh))) {
         RETVAL = newSVsv(SvRV(oh));
       }
+      else {
+        RETVAL = newSVpv("wtf?", 0);
+      }
     }
   OUTPUT:
     RETVAL

Modified: PHP-Sandwich/trunk/phpfuncs.c
==============================================================================
--- PHP-Sandwich/trunk/phpfuncs.c	(original)
+++ PHP-Sandwich/trunk/phpfuncs.c	Tue Jul  5 11:06:12 2005
@@ -581,19 +581,52 @@ int sv_get_class_name(zval *obj, char **
     *class_name_len = strlen("PerlSV") + 1;
     *class_name = estrndup("PerlSV", *class_name_len);
   } else {
+    pTHX;
     struct plsv *pl;
     char *tmp;
     pl = (struct plsv *) zend_object_store_get_object(obj TSRMLS_CC);
-    tmp = HvNAME((SvSTASH(SvRV(pl->sv))));
-    if(!tmp) return FAILURE;
-    *class_name_len = strlen(tmp) + sizeof("PerlSV::") - 1;
-    *class_name = emalloc(*class_name_len);
-    strncpy(*class_name, "PerlSV::", sizeof("PerlSV::"));
-    strcat(*class_name, tmp);
-    return SUCCESS;
+#ifdef USE_ITHREADS
+    aTHX = pl->perl;
+#endif
+    if(!sv_isobject(pl->sv)) {
+      *class_name_len = strlen("PerlSV") + 1;
+      *class_name = estrndup("PerlSV", *class_name_len);
+    } else {
+      tmp = HvNAME((SvSTASH(SvRV(pl->sv))));
+      if(!tmp) return FAILURE;
+      *class_name_len = strlen(tmp) + sizeof("PerlSV::") - 1;
+      *class_name = emalloc(*class_name_len);
+      strncpy(*class_name, "PerlSV::", sizeof("PerlSV::"));
+      strcat(*class_name, tmp);
+    }
   }
+  return SUCCESS;
+}
+
+static void stderr_dump(char *in, int inlen) {
+  fwrite(in, inlen, 1, stderr);
 }
 
+PHP_METHOD(perlsv, __tostring)
+{
+  struct plsv *pl;
+  char         *string;
+  STRLEN       stringlen;
+  pTHX;
+  
+  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
+    return;
+  }
+  pl = (struct plsv *) zend_object_store_get_object(getThis() TSRMLS_CC);
+#ifdef USE_ITHREADS
+  aTHX = pl->perl;
+#endif
+  fprintf(stderr, "looking at plsv: %p\n", pl->sv);
+  string = SvPV(pl->sv, stringlen);
+  fprintf(stderr, "string: %s\n", string);
+  RETURN_STRINGL(string, stringlen, 1);
+}  
+
 struct plsv_iterator {
   zend_object_iterator iter;
   SV *sv;
@@ -742,6 +775,7 @@ static function_entry plobj_functions[] 
 };
 
 static function_entry plsv_functions[] = {
+  PHP_ME(perlsv, __tostring, NULL, ZEND_ACC_PUBLIC)
   {NULL, NULL, NULL}
 };
 
@@ -891,6 +925,7 @@ plsv_create_object(zend_class_entry *ce 
 
 void plsv_wrap_sv(zval *retval, SV *sv TSRMLS_DC)
 {
+  dTHX;
   struct plsv *pl;
 
   object_init_ex(retval, plsv_ce);
@@ -900,6 +935,7 @@ void plsv_wrap_sv(zval *retval, SV *sv T
   pl = (struct plsv *) zend_object_store_get_object(retval TSRMLS_CC);
   SvREFCNT_inc(sv);
   pl->sv = sv;
+  fprintf(stderr, "stashing %p\n", sv);
 }
  
 

Modified: PHP-Sandwich/trunk/phpinterp.h
==============================================================================
--- PHP-Sandwich/trunk/phpinterp.h	(original)
+++ PHP-Sandwich/trunk/phpinterp.h	Tue Jul  5 11:06:12 2005
@@ -36,8 +36,8 @@ int sandwich_include(sandwich_per_interp
 /* NOTE: caller must tsrm_set_interpreter_context and reset the old one */
 zval *sandwich_call_function(sandwich_per_interp *interp, zval *method, zval **params, zend_uint param_count);
 
-#define sandwich_interp_inc_ref(interp)  interp->ref++
-#define sandwich_interp_dec_ref(interp)  if(--interp->ref == 0) sandwich_per_interp_shutdown(interp)
+#define sandwich_interp_inc_ref(interp)  fprintf(stderr, "inc [%s:%d] refcnt = %d\n", __FILE__, __LINE__, interp->ref+1); interp->ref++
+#define sandwich_interp_dec_ref(interp)  fprintf(stderr, "dec [%s:%d] refcnt = %d\n", __FILE__, __LINE__, interp->ref-1);if(--interp->ref == 0) sandwich_per_interp_shutdown(interp)
 
 zval *SvZval(SV *sv TSRMLS_DC);
 SV *newSVzval(zval *param, sandwich_per_interp *interp);

Modified: PHP-Sandwich/trunk/t/19.t
==============================================================================
--- PHP-Sandwich/trunk/t/19.t	(original)
+++ PHP-Sandwich/trunk/t/19.t	Tue Jul  5 11:06:12 2005
@@ -9,6 +9,7 @@ BEGIN {
 }
 
 my $output;
+my $data;
 ok my $p = PHP::Interpreter->new(
   {
     'BRIC' => 
@@ -25,7 +26,16 @@ $p->clear_output;
 is $output, undef, 'check output buffering was cleared (scalar pass by ref)';
 $p->eval(q/print $BRIC['special'];/);
 is $output, 'data', 'check output buffering, post-clearing (scalar pass by ref)';
-
+$p->clear_output;
+$p->eval(q/print $BRIC['special'];/);
+is $output, 'data', 'check output buffering (scalar pass by ref 2)';
+$p->eval(q/print $BRIC['special'];/);
+is $output, 'datadata', 'check output buffering accumulation (scalar pass by ref 2)';
+is $p->get_output, 'datadata', 'check output buffer accessor 2';
+$p->clear_output;
+is $output, undef, 'check output buffering was cleared (scalar pass by ref 2)';
+$p->eval(q/print $BRIC['special'];/);
+is $output, 'data', 'check output buffering, post-clearing (scalar pass by ref 2)';
 
 
 

Modified: PHP-Sandwich/trunk/t/8.t
==============================================================================
--- PHP-Sandwich/trunk/t/8.t	(original)
+++ PHP-Sandwich/trunk/t/8.t	Tue Jul  5 11:06:12 2005
@@ -20,7 +20,6 @@ function foo() { return $foo = new Foo()
 
 /);
 my $arg = $p->foo();
-
 is ref($arg), "PHP::Class::Foo", "class membership correct";
 is $arg->{a}, 123, "attribute access";
 $arg->{a} = 456;