cvs: pecl /perl README php_perl.c /perl/tests perl002.phpt perl007.phpt perl019.phpt perl020.phpt perl070.phpt

From: Date: Thu, 11 Mar 2004 08:12:01 +0000
Subject: cvs: pecl /perl README php_perl.c /perl/tests perl002.phpt perl007.phpt perl019.phpt perl020.phpt perl070.phpt
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-1055@lists.php.net to get a copy of this message
dmitry Thu Mar 11 03:12:01 2004 EDT Added files: /pecl/perl/tests perl070.phpt Modified files: /pecl/perl README php_perl.c /pecl/perl/tests perl002.phpt perl007.phpt perl019.phpt perl020.phpt Log: Using PHP exceptions to report Perl errors. http://cvs.php.net/diff.php/pecl/perl/README?r1=1.3&r2=1.4&ty=u Index: pecl/perl/README diff -u pecl/perl/README:1.3 pecl/perl/README:1.4 --- pecl/perl/README:1.3 Wed Mar 10 05:08:29 2004 +++ pecl/perl/README Thu Mar 11 03:12:00 2004 @@ -37,7 +37,7 @@ Perl->eval($perl_code) ---------------------- Evaluates Perl code and returns result. If Perl code is invalid it will - produce PHP error. + throw PHP exception. Exampes: $perl = new Perl(); @@ -59,7 +59,7 @@ Perl->require($perl_file_name) ------------------------------ Loads and executes Perl file. It doesn't return any value. If required Perl - file doesn't exist or invalid it will produce PHP error. + file doesn't exist or invalid it will throw PHP exception. Examples: $perl = new Perl(); http://cvs.php.net/diff.php/pecl/perl/php_perl.c?r1=1.4&r2=1.5&ty=u Index: pecl/perl/php_perl.c diff -u pecl/perl/php_perl.c:1.4 pecl/perl/php_perl.c:1.5 --- pecl/perl/php_perl.c:1.4 Wed Mar 10 05:08:29 2004 +++ pecl/perl/php_perl.c Thu Mar 11 03:12:00 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Dmitry Stogov <dmitry@zend.com> | +----------------------------------------------------------------------+ - $Id: php_perl.c,v 1.4 2004/03/10 10:08:29 dmitry Exp $ + $Id: php_perl.c,v 1.5 2004/03/11 08:12:00 dmitry Exp $ */ #ifdef COMPILE_DL_PERL @@ -48,6 +48,7 @@ #include "php.h" #include "php_ini.h" #include "zend_objects_API.h" +#include "zend_exceptions.h" #include "ext/standard/info.h" #include "SAPI.h" #include "php_perl.h" @@ -108,6 +109,7 @@ static zend_class_entry* perl_class_entry; +static zend_class_entry* perl_exception_class_entry; /* PHP <-> Perl data conversion routines */ static SV* php_perl_zval_to_sv_noref(PerlInterpreter* my_perl, zval* zv, HashTable* var_hash TSRMLS_DC); @@ -1163,14 +1165,18 @@ constructor, constructor_len, argc-2, argv+2 TSRMLS_CC); + if (argc > 2) { + efree(argv); + } + if(SvTRUE(ERRSV)) { STRLEN na; - zend_error(E_ERROR, "[perl] constructor error: %s", SvPV(ERRSV, na)); + zval_ptr_dtor(&object); + zend_throw_exception_ex(perl_exception_class_entry, 0 TSRMLS_CC, + "[perl] constructor error: %s", SvPV(ERRSV, na)); + return; } - if (argc > 2) { - efree(argv); - } php_perl_remember_object(obj->sv, object->value.obj.handle TSRMLS_CC); } zval_ptr_dtor(&object); @@ -1226,16 +1232,18 @@ return_value_used?return_value:NULL TSRMLS_CC); } - if(SvTRUE(ERRSV)) { - STRLEN na; - zend_error(E_ERROR, "[perl] call error: %s", SvPV(ERRSV, na)); - } - zval_ptr_dtor(&object); if (argc > 0) { efree(argv); } + if(SvTRUE(ERRSV)) { + STRLEN na; + zend_throw_exception_ex(perl_exception_class_entry, 0 TSRMLS_CC, + "[perl] call error: %s", SvPV(ERRSV, na)); + return FAILURE; + } + return SUCCESS; } @@ -1560,6 +1568,9 @@ perl_class_entry = zend_register_internal_class(&perl_ce TSRMLS_CC); perl_class_entry->get_iterator = php_perl_get_iterator; + INIT_CLASS_ENTRY(perl_ce, "PerlException", NULL); + perl_exception_class_entry = zend_register_internal_class_ex(&perl_ce, zend_exception_get_default(), NULL TSRMLS_CC); + return SUCCESS; } @@ -1576,8 +1587,12 @@ PHP_MINFO_FUNCTION(perl) { + PerlInterpreter* my_perl = php_perl_init(TSRMLS_C); + php_info_print_table_start(); - php_info_print_table_row(2, "perl support", "enabled"); + php_info_print_table_header(2, "Perl support", "enabled"); + php_info_print_table_row(2, "Revision", "$Revision: 1.5 $"); + php_info_print_table_row(2, "Perl version", Perl_form(aTHX_ "%vd",PL_patchlevel)); php_info_print_table_end(); } @@ -1597,7 +1612,9 @@ require_pv(perl_filename); if(SvTRUE(ERRSV)) { STRLEN na; - zend_error(E_ERROR, "[perl] require error: %s", SvPV(ERRSV, na)); + + zend_throw_exception_ex(perl_exception_class_entry, 0 TSRMLS_CC, + "[perl] require error: %s", SvPV(ERRSV, na)); } } } @@ -1660,7 +1677,8 @@ if (SvTRUE(ERRSV)) { STRLEN na; - zend_error(E_ERROR, "[perl] eval error: %s", SvPV(ERRSV, na)); + zend_throw_exception_ex(perl_exception_class_entry, 0 TSRMLS_CC, + "[perl] eval error: %s", SvPV(ERRSV, na)); } } } http://cvs.php.net/diff.php/pecl/perl/tests/perl002.phpt?r1=1.2&r2=1.3&ty=u Index: pecl/perl/tests/perl002.phpt diff -u pecl/perl/tests/perl002.phpt:1.2 pecl/perl/tests/perl002.phpt:1.3 --- pecl/perl/tests/perl002.phpt:1.2 Wed Mar 10 05:08:29 2004 +++ pecl/perl/tests/perl002.phpt Thu Mar 11 03:12:01 2004 @@ -10,5 +10,8 @@ echo "ok\n"; ?> --EXPECTF-- -Fatal error: [perl] require error: Can't locate %sperl002.pl in @INC (@INC contains: %s) at (eval %d) line %d. - in %s on line %d \ No newline at end of file +Fatal error: Uncaught exception 'PerlException' with message '[perl] require error: Can't locate %sperl002.pl in @INC (@INC contains: %s) at (eval %d) line %d. +' in %sperl002.php:%d +Stack trace: +#0 {main} + thrown in %sperl002.php on line %d http://cvs.php.net/diff.php/pecl/perl/tests/perl007.phpt?r1=1.2&r2=1.3&ty=u Index: pecl/perl/tests/perl007.phpt diff -u pecl/perl/tests/perl007.phpt:1.2 pecl/perl/tests/perl007.phpt:1.3 --- pecl/perl/tests/perl007.phpt:1.2 Wed Mar 10 05:08:29 2004 +++ pecl/perl/tests/perl007.phpt Thu Mar 11 03:12:01 2004 @@ -9,5 +9,8 @@ echo "ok\n"; ?> --EXPECTF-- -Fatal error: [perl] eval error: syntax error at (eval %d) line %d, at EOF - in %s on line %d \ No newline at end of file +Fatal error: Uncaught exception 'PerlException' with message '[perl] eval error: syntax error at (eval %d) line %d, at EOF +' in %sperl007.php:%d +Stack trace: +#0 {main} + thrown in %sperl007.php on line %d http://cvs.php.net/diff.php/pecl/perl/tests/perl019.phpt?r1=1.2&r2=1.3&ty=u Index: pecl/perl/tests/perl019.phpt diff -u pecl/perl/tests/perl019.phpt:1.2 pecl/perl/tests/perl019.phpt:1.3 --- pecl/perl/tests/perl019.phpt:1.2 Wed Mar 10 05:08:30 2004 +++ pecl/perl/tests/perl019.phpt Thu Mar 11 03:12:01 2004 @@ -16,5 +16,8 @@ echo "ok\n"; ?> --EXPECTF-- -Fatal error: [perl] call error: (in cleanup) Bye bye! at (eval %d) line %d. - in %s on line %d +Fatal error: Uncaught exception 'PerlException' with message '[perl] call error: (in cleanup) Bye bye! at (eval %d) line %d. +' in %sperl019.php:%d +Stack trace: +#0 {main} + thrown in %sperl019.php on line %d http://cvs.php.net/diff.php/pecl/perl/tests/perl020.phpt?r1=1.2&r2=1.3&ty=u Index: pecl/perl/tests/perl020.phpt diff -u pecl/perl/tests/perl020.phpt:1.2 pecl/perl/tests/perl020.phpt:1.3 --- pecl/perl/tests/perl020.phpt:1.2 Wed Mar 10 05:08:30 2004 +++ pecl/perl/tests/perl020.phpt Thu Mar 11 03:12:01 2004 @@ -12,5 +12,8 @@ echo "ok\n"; ?> --EXPECTF-- -Fatal error: [perl] eval error: (in cleanup) Bye bye! at (eval %d) line %d. - in %s on line %d +Fatal error: Uncaught exception 'PerlException' with message '[perl] eval error: (in cleanup) Bye bye! at (eval %d) line %d. +' in %sperl020.php:%d +Stack trace: +#0 {main} + thrown in %sperl020.php on line %d http://cvs.php.net/co.php/pecl/perl/tests/perl070.phpt?r=1.1&p=1 Index: pecl/perl/tests/perl070.phpt +++ pecl/perl/tests/perl070.phpt --TEST-- Test 70: Catching Perl errors --SKIPIF-- <?php require_once('skipif.inc'); ?> --FILE-- <?php $perl = new Perl(); try { var_dump($perl->eval('$a = $s{$d}.')); echo "ok\n"; } catch (PerlException $exception) { echo "Perl error: " . $exception->getMessage() . "\n"; } ?> --EXPECTF-- Perl error: [perl] eval error: syntax error at (eval %d) line %d, at EOF

« previous php.pecl.cvs (#1055) next »