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

[email protected] 15 Apr 2005 22:11:54 -0000
Newsgroups perl.php.sandwich.dev
Message-ID <[email protected]>
Author: gschlossnagle
Date: Fri Apr 15 15:11:53 2005
New Revision: 1002

Modified:
   PHP-Sandwich/trunk/PHP.xs
   PHP-Sandwich/trunk/phpinterp.c
   PHP-Sandwich/trunk/phpinterp.h
Log:
return nicer from include/eval


Modified: PHP-Sandwich/trunk/PHP.xs
==============================================================================
--- PHP-Sandwich/trunk/PHP.xs	(original)
+++ PHP-Sandwich/trunk/PHP.xs	Fri Apr 15 15:11:53 2005
@@ -145,7 +145,7 @@
                 /* something bad has happened here */ 
               }
               else {
-                hv_store((HV *) retval, sk, skl, newSVzval(*entry), 0);
+                hv_store((HV *) retval, sk, skl - 1, newSVzval(*entry), 0);
               }
               break;
             case HASH_KEY_IS_LONG:
@@ -214,21 +214,36 @@
   OUTPUT:
     RETVAL
 
-void SAND_eval(interp, code)
+SV *SAND_eval(interp, code)
   PHP_Interpreter interp;
   char *code;
   CODE:
     {
-      sandwich_eval(interp, code);
+      if(sandwich_eval(interp, code) == 0) {
+        RETVAL = &PL_sv_yes;
+      } else {
+        croak("PHP Error in eval(\"%s\")", code);
+        RETVAL = &PL_sv_no;
+      }
     }
+  OUTPUT:
+    RETVAL
 
-void SAND_include(interp, file)
+SV *SAND_include(interp, file)
   PHP_Interpreter interp;
   char *file;
   CODE:
     {
-      sandwich_include(interp, file);
+      if(sandwich_include(interp, file) == 0) {
+        RETVAL = newSVsv(ST(0));
+      }
+      else {
+        croak("Error including %s\n", file);
+        RETVAL = &PL_sv_no;
+      }
     }
+  OUTPUT:
+    RETVAL
 
 SV *SAND_call(interp, method_name, ...)
   PHP_Interpreter interp;

Modified: PHP-Sandwich/trunk/phpinterp.c
==============================================================================
--- PHP-Sandwich/trunk/phpinterp.c	(original)
+++ PHP-Sandwich/trunk/phpinterp.c	Fri Apr 15 15:11:53 2005
@@ -37,7 +37,7 @@
 static void sandwich_sapi_log_message(char *message)
 {
   // allow this to be overridden nicely?
-  Perl_croak("%s\n", message);
+  croak("%s\n", message);
 }
 
 
@@ -139,36 +139,40 @@
   {
     TSRMLS_FETCH();
     php_request_shutdown(NULL);
+    tsrm_set_interpreter_context(NULL);
     tsrm_free_interpreter_context(interp->ctx);
+    interp->ctx = NULL;
     free(interp);
   }
   tsrm_set_interpreter_context(old_ctx);
 }
 
-void sandwich_eval(sandwich_per_interp *interp, char *code)
+int sandwich_eval(sandwich_per_interp *interp, char *code)
 {
+  int rv = 0;
   void *old_ctx = NULL;
   old_ctx = tsrm_set_interpreter_context(interp->ctx);
   {
     TSRMLS_FETCH();
     zend_try {
       if (FAILURE == zend_eval_string_ex(code, NULL, "PHP::eval", 1 TSRMLS_CC)) {
-        Perl_croak("Failed to eval your PHP code\n");
+        rv = -1;
         goto cleanup;
       }
     } zend_catch {
-      Perl_croak("Failed to eval your PHP code\n");
+      rv = -1;
       goto cleanup;
     } zend_end_try() {
     }
   }
 cleanup:
   tsrm_set_interpreter_context(old_ctx);
-  return;
+  return rv;
 }
 
-void sandwich_include(sandwich_per_interp *interp, char *file)
+int sandwich_include(sandwich_per_interp *interp, char *file)
 {
+  int rv = 0;
   void *old_ctx = NULL;
   old_ctx = tsrm_set_interpreter_context(interp->ctx);
   {
@@ -181,17 +185,16 @@
         file_handle.filename = SG(request_info).path_translated;
         file_handle.opened_path = NULL;
         file_handle.free_filename = 0;
-fprintf(stderr, "executing %s\n", file_handle.filename);
         php_execute_script(&file_handle TSRMLS_CC);
     } zend_catch {
-      Perl_croak("Failed to eval your PHP code\n");
+      rv = -1;
       goto cleanup;
     } zend_end_try() {
     }
   }
 cleanup:
   tsrm_set_interpreter_context(old_ctx);
-  return;
+  return rv;
 }
 
 zval *sandwich_call_function(sandwich_per_interp *interp, zval *method, zval **params, zend_uint param_count)

Modified: PHP-Sandwich/trunk/phpinterp.h
==============================================================================
--- PHP-Sandwich/trunk/phpinterp.h	(original)
+++ PHP-Sandwich/trunk/phpinterp.h	Fri Apr 15 15:11:53 2005
@@ -22,8 +22,8 @@
 
 void sandwhich_per_interp_shutdown(sandwich_per_interp *interp);
 
-void sandwich_eval(sandwich_per_interp *interp, char *code);
-void sandwich_include(sandwich_per_interp *interp, char *file);
+int sandwich_eval(sandwich_per_interp *interp, char *code);
+int sandwich_include(sandwich_per_interp *interp, char *file);
 
 /* 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);