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

[email protected] 26 Jul 2005 17:43:12 -0000
Newsgroups perl.php.sandwich.dev
Message-ID <[email protected]>
Author: gschlossnagle
Date: Tue Jul 26 10:43:11 2005
New Revision: 1417

Modified:
   PHP-Sandwich/trunk/PHP.xs
   PHP-Sandwich/trunk/phpinterp.c
   PHP-Sandwich/trunk/t/19.t
Log:
implement set_output_handler()

fix unitialized warnings


Modified: PHP-Sandwich/trunk/PHP.xs
==============================================================================
--- PHP-Sandwich/trunk/PHP.xs	(original)
+++ PHP-Sandwich/trunk/PHP.xs	Tue Jul 26 10:43:11 2005
@@ -572,6 +572,20 @@ SV *SAND_call(interp, method_name, ...)
   OUTPUT:
     RETVAL
 
+SV *SAND_set_output_handler(interp, sv)
+  PHP_Interpreter interp;
+  SV *sv;
+  CODE:
+    {
+      if(interp->output_handler) {
+        RETVAL = interp->output_handler;
+      }
+      SvREFCNT_inc(sv);
+      interp->output_handler = sv;
+    }
+  OUTPUT:
+    RETVAL
+
 void SAND_DESTROY(interp)
   PHP_Interpreter interp;
   CODE:
@@ -600,7 +614,7 @@ void SAND_clear_output(interp)
     {
       SV* oh = interp->output_handler;
       if(SvROK(oh) && SvPOK(SvRV(oh))) {
-        sv_setpvn_mg(SvRV(oh), NULL, 0);
+        sv_setpvn_mg(SvRV(oh), "", 0);
       }
     }
   

Modified: PHP-Sandwich/trunk/phpinterp.c
==============================================================================
--- PHP-Sandwich/trunk/phpinterp.c	(original)
+++ PHP-Sandwich/trunk/phpinterp.c	Tue Jul 26 10:43:11 2005
@@ -22,7 +22,7 @@ static int sandwich_sapi_ub_write(const 
   // FIXME - call out to Perl's selected fh
   SV *oh;
   sandwich_per_interp *interp = SG(server_context);
-  if(!interp || !interp->output_handler) {
+  if(!interp || !interp->output_handler || interp->output_handler == &PL_sv_undef) {
     fwrite(str, 1, str_length, stdout);
     return str_length;
   }
@@ -40,7 +40,11 @@ static int sandwich_sapi_ub_write(const 
     FREETMPS;
     LEAVE;
   } else {
-    sv_catpvn_mg(SvROK(oh)?SvRV(oh):oh, str, str_length);
+    if(SvROK(oh) && SvTYPE(SvRV(oh)) == SVt_NULL) {
+      sv_setpvn_mg(SvRV(oh), str, str_length);
+    } else {
+      sv_catpvn_mg(SvROK(oh)?SvRV(oh):oh, str, str_length);
+    }
   }
   return str_length;
 }
@@ -218,7 +222,6 @@ int my_eval_string(char *str, zval *retv
     EG(return_value_ptr_ptr) = &local_retval_ptr;
     EG(active_op_array) = new_op_array;
     EG(no_extensions)=1;
-
     zend_execute(new_op_array TSRMLS_CC);
 
     if (local_retval_ptr) {

Modified: PHP-Sandwich/trunk/t/19.t
==============================================================================
--- PHP-Sandwich/trunk/t/19.t	(original)
+++ PHP-Sandwich/trunk/t/19.t	Tue Jul 26 10:43:11 2005
@@ -19,9 +19,8 @@ $p->eval(q/print $BRIC['special'];/);
 is $output, 'datadata', 'check output buffering accumulation (scalar pass by ref)';
 is $p->get_output, 'datadata', 'check output buffer accessor';
 $p->clear_output;
-is $output, undef, 'check output buffering was cleared (scalar pass by ref)';
-my $arg = q/print $BRIC['special'];/;
-$p->eval($arg);
+is $output, '', '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'];/);
@@ -30,22 +29,13 @@ $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)';
+is $output, '', '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)';
-
-
+ok $p->set_output_handler(\&pr), "change output handler";
 
 my $output2;
 sub pr { $output2 .= $_[0]; }
-ok $p = PHP::Interpreter->new(
-  {
-    'BRIC' => 
-      {'special' => 'data',},
-    'OUTPUT' => \&pr
-  }),
-  "Create new PHP interpreter";
-
 $p->eval(q/print $BRIC['special'];/);
 is $output2, 'data', 'check output buffering (callback)';