cvs: ZendEngine2(PHP_5_3) / zend_API.c zend_closures.c zend_compile.c zend_vm_def.h zend_vm_execute.h /tests closure_016.phpt

From: Date: Mon, 14 Jul 2008 12:18:26 +0000
Subject: cvs: ZendEngine2(PHP_5_3) / zend_API.c zend_closures.c zend_compile.c zend_vm_def.h zend_vm_execute.h /tests closure_016.phpt
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-6890@lists.php.net to get a copy of this message
dmitry Mon Jul 14 12:18:26 2008 UTC Added files: (Branch: PHP_5_3) /ZendEngine2/tests closure_016.phpt Modified files: /ZendEngine2 zend_API.c zend_closures.c zend_compile.c zend_vm_def.h zend_vm_execute.h Log: Fixed is_callable() to support closures and return appropriate function name http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_API.c?r1=1.296.2.27.2.34.2.39&r2=1.296.2.27.2.34.2.40&diff_format=u Index: ZendEngine2/zend_API.c diff -u ZendEngine2/zend_API.c:1.296.2.27.2.34.2.39 ZendEngine2/zend_API.c:1.296.2.27.2.34.2.40 --- ZendEngine2/zend_API.c:1.296.2.27.2.34.2.39 Mon Jul 14 09:48:59 2008 +++ ZendEngine2/zend_API.c Mon Jul 14 12:18:20 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.c,v 1.296.2.27.2.34.2.39 2008/07/14 09:48:59 dmitry Exp $ */ +/* $Id: zend_API.c,v 1.296.2.27.2.34.2.40 2008/07/14 12:18:20 dmitry Exp $ */ #include "zend.h" #include "zend_execute.h" @@ -2619,8 +2619,12 @@ case IS_OBJECT: if (zend_get_closure(callable, ce_ptr, fptr_ptr, NULL, zobj_ptr_ptr TSRMLS_CC) == SUCCESS) { if (callable_name) { - *callable_name_len = strlen((*fptr_ptr)->common.function_name); - *callable_name = estrndup((*fptr_ptr)->common.function_name, *callable_name_len); + zend_class_entry *ce = Z_OBJCE_P(callable); /* TBFixed: what if it's overloaded? */ + + *callable_name_len = ce->name_length + sizeof("::__invoke") - 1; + *callable_name = emalloc(*callable_name_len + 1); + memcpy(*callable_name, ce->name, ce->name_length); + memcpy((*callable_name) + ce->name_length, "::__invoke", sizeof("::__invoke")); } return 1; } http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_closures.c?r1=1.3.2.2&r2=1.3.2.3&diff_format=u Index: ZendEngine2/zend_closures.c diff -u ZendEngine2/zend_closures.c:1.3.2.2 ZendEngine2/zend_closures.c:1.3.2.3 --- ZendEngine2/zend_closures.c:1.3.2.2 Mon Jul 14 09:48:59 2008 +++ ZendEngine2/zend_closures.c Mon Jul 14 12:18:20 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_closures.c,v 1.3.2.2 2008/07/14 09:48:59 dmitry Exp $ */ +/* $Id: zend_closures.c,v 1.3.2.3 2008/07/14 12:18:20 dmitry Exp $ */ #include "zend.h" #include "zend_API.h" @@ -70,6 +70,12 @@ } /* }}} */ +const static zend_function_entry closure_functions[] = { /* {{{ */ + ZEND_ME(Closure, __invoke, NULL, 0) + {NULL, NULL, NULL} +}; +/* }}} */ + static zend_function *zend_closure_get_constructor(zval *object TSRMLS_DC) /* {{{ */ { zend_error(E_ERROR, "Instantiation of 'Closure' is not allowed"); @@ -181,7 +187,7 @@ { zend_class_entry ce; - INIT_CLASS_ENTRY(ce, "Closure", NULL); + INIT_CLASS_ENTRY(ce, "Closure", closure_functions); zend_ce_closure = zend_register_internal_class(&ce TSRMLS_CC); zend_ce_closure->ce_flags |= ZEND_ACC_FINAL_CLASS; zend_ce_closure->create_object = zend_closure_new; http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.647.2.27.2.41.2.71&r2=1.647.2.27.2.41.2.72&diff_format=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.71 ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.72 --- ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.71 Mon Jul 14 09:48:59 2008 +++ ZendEngine2/zend_compile.c Mon Jul 14 12:18:20 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.647.2.27.2.41.2.71 2008/07/14 09:48:59 dmitry Exp $ */ +/* $Id: zend_compile.c,v 1.647.2.27.2.41.2.72 2008/07/14 12:18:20 dmitry Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -1409,7 +1409,7 @@ zend_op *current_op; function_name.op_type = IS_CONST; - ZVAL_STRINGL(&function_name.u.constant, "lambda", sizeof("lambda")-1, 1); + ZVAL_STRINGL(&function_name.u.constant, "", sizeof("")-1, 1); zend_do_begin_function_declaration(function_token, &function_name, 0, return_reference, NULL TSRMLS_CC); http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_def.h?r1=1.59.2.29.2.48.2.59&r2=1.59.2.29.2.48.2.60&diff_format=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.59.2.29.2.48.2.59 ZendEngine2/zend_vm_def.h:1.59.2.29.2.48.2.60 --- ZendEngine2/zend_vm_def.h:1.59.2.29.2.48.2.59 Mon Jul 14 09:49:00 2008 +++ ZendEngine2/zend_vm_def.h Mon Jul 14 12:18:20 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.59.2.29.2.48.2.59 2008/07/14 09:49:00 dmitry Exp $ */ +/* $Id: zend_vm_def.h,v 1.59.2.29.2.48.2.60 2008/07/14 12:18:20 dmitry Exp $ */ /* If you change this file, please regenerate the zend_vm_execute.h and * zend_vm_opcodes.h files by running: @@ -4339,7 +4339,7 @@ ZEND_VM_HANDLER(153, ZEND_DECLARE_LAMBDA_FUNCTION, CONST, CONST) { zend_op *opline = EX(opline); - zend_op_array *op_array; + zend_function *op_array; if (zend_hash_quick_find(EG(function_table), Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), Z_LVAL(opline->op2.u.constant), (void *) &op_array) == FAILURE || op_array->type != ZEND_USER_FUNCTION) { http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_execute.h?r1=1.62.2.30.2.49.2.59&r2=1.62.2.30.2.49.2.60&diff_format=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.62.2.30.2.49.2.59 ZendEngine2/zend_vm_execute.h:1.62.2.30.2.49.2.60 --- ZendEngine2/zend_vm_execute.h:1.62.2.30.2.49.2.59 Mon Jul 14 09:49:00 2008 +++ ZendEngine2/zend_vm_execute.h Mon Jul 14 12:18:20 2008 @@ -2914,7 +2914,7 @@ static int ZEND_FASTCALL ZEND_DECLARE_LAMBDA_FUNCTION_SPEC_CONST_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { zend_op *opline = EX(opline); - zend_op_array *op_array; + zend_function *op_array; if (zend_hash_quick_find(EG(function_table), Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), Z_LVAL(opline->op2.u.constant), (void *) &op_array) == FAILURE || op_array->type != ZEND_USER_FUNCTION) { http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/closure_016.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/closure_016.phpt +++ ZendEngine2/tests/closure_016.phpt --TEST-- Closure 016: closures and is_callable() --FILE-- <?php class Foo { function __invoke() { echo "Hello World!\n"; } } function foo() { return function() { echo "Hello World!\n"; }; } $test = new Foo; var_dump(is_callable($test, true, $name)); echo $name."\n"; var_dump(is_callable($test, false, $name)); echo $name."\n"; var_dump(is_callable(array($test,"__invoke"), true, $name)); echo $name."\n"; var_dump(is_callable(array($test,"__invoke"), false, $name)); echo $name."\n"; $test = foo(); var_dump(is_callable($test, true, $name)); echo $name."\n"; var_dump(is_callable($test, false, $name)); echo $name."\n"; var_dump(is_callable(array($test,"__invoke"), true, $name)); echo $name."\n"; var_dump(is_callable(array($test,"__invoke"), false, $name)); echo $name."\n"; ?> --EXPECT-- bool(true) Foo::__invoke bool(true) Foo::__invoke bool(true) Foo::__invoke bool(true) Foo::__invoke bool(true) Closure::__invoke bool(true) Closure::__invoke bool(true) Closure::__invoke bool(true) Closure::__invoke

« previous php.zend-engine.cvs (#6890) next »