cvs: pecl /classkit classkit.c

From: Date: Tue, 24 Aug 2004 00:30:29 +0000
Subject: cvs: pecl /classkit classkit.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-1719@lists.php.net to get a copy of this message
pollita Mon Aug 23 20:30:29 2004 EDT Modified files: /pecl/classkit classkit.c Log: More inheritence fixes... http://cvs.php.net/diff.php/pecl/classkit/classkit.c?r1=1.4&r2=1.5&ty=u Index: pecl/classkit/classkit.c diff -u pecl/classkit/classkit.c:1.4 pecl/classkit/classkit.c:1.5 --- pecl/classkit/classkit.c:1.4 Mon Aug 23 16:41:51 2004 +++ pecl/classkit/classkit.c Mon Aug 23 20:30:27 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: classkit.c,v 1.4 2004/08/23 20:41:51 pollita Exp $ */ +/* $Id: classkit.c,v 1.5 2004/08/24 00:30:27 pollita Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -84,7 +84,7 @@ ptr = EG(current_execute_data); while (ptr) { - if (ptr->op_array == op_array) { + if (ptr->op_array->opcodes == op_array->opcodes) { return FAILURE; } ptr = ptr->prev_execute_data; @@ -193,6 +193,49 @@ _zend_hash_add_or_update((ht), (arKey), (nKeyLength), (pData), (pDataSize), (pDest), (flag) ZEND_FILE_LINE_CC) #endif +/* {{{ php_classkit_clean_children + Scan the class_table for children of the class just updated */ +static int php_classkit_clean_children(zend_class_entry **ze, int num_args, va_list args, zend_hash_key *hash_key) +{ + zend_class_entry *ancestor_class = va_arg(args, zend_class_entry*); + zend_class_entry *parent_class = va_arg(args, zend_class_entry*); + zend_class_entry *ce; + char *fname = va_arg(args, char*); + int fname_len = va_arg(args, int); + zend_function *cfe = NULL; + TSRMLS_FETCH(); + +#ifdef ZEND_ENGINE_2 + ce = *ze; +#else + ce = (zend_class_entry *)ze; +#endif + + if (ce->parent != parent_class) { + /* Not a child, ignore */ + return ZEND_HASH_APPLY_KEEP; + } + + if (zend_hash_find(&ce->function_table, fname, fname_len + 1, (void**)&cfe) == SUCCESS && + cfe->common.scope != ancestor_class) { + /* This method was defined below our current level, leave it be */ + return ZEND_HASH_APPLY_KEEP; + } + + if (!cfe) { + /* Odd.... nothing to destroy.... */ + return ZEND_HASH_APPLY_KEEP; + } + + zend_hash_del(&ce->function_table, fname, fname_len + 1); + + /* Process children of this child */ + zend_hash_apply_with_arguments(EG(class_table), php_classkit_clean_children, 4, ancestor_class, ce, fname, fname_len); + + return ZEND_HASH_APPLY_KEEP; +} +/* }}} */ + /* {{{ php_classkit_update_children Scan the class_table for children of the class just updated */ static int php_classkit_update_children(zend_class_entry **ze, int num_args, va_list args, zend_hash_key *hash_key) @@ -400,6 +443,8 @@ RETURN_FALSE; } + zend_hash_apply_with_arguments(EG(class_table), php_classkit_clean_children, 4, fe->common.scope, ce, methodname, methodname_len); + if (zend_hash_del(&ce->function_table, methodname, methodname_len + 1) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error dereferencing old method"); RETURN_FALSE; @@ -442,6 +487,13 @@ RETURN_FALSE; } + if (ce != fe->common.scope) { + /* Inherited method: There's no such thing as op_array_ctor and I'm not fond of implementing it */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Method can only be renamed in its originating class(class %s). Patches welcomed.", + fe->common.scope->name ? fe->common.scope->name : "Unknown"); + RETURN_FALSE; + } + if (php_classkit_check_call_stack(&fe->op_array TSRMLS_CC) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot rename a method while it is active"); RETURN_FALSE; @@ -454,17 +506,20 @@ tmp = *fe; - /* Fool the op_array into not destructing */ - fe->type = ZEND_INTERNAL_FUNCTION; - if (zend_hash_del(&ce->function_table, methodname, methodname_len + 1) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error dereferencing old method"); - RETURN_FALSE; - } - efree(tmp.common.function_name); tmp.common.function_name = estrndup(newname, newname_len); + function_add_ref(&tmp); if (zend_hash_add(&ce->function_table, newname, newname_len + 1, &tmp, sizeof(zend_function), NULL) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error adding new method name"); + RETURN_FALSE; + } + + zend_hash_apply_with_arguments(EG(class_table), php_classkit_update_children, 5, fe->common.scope, ce, &tmp, newname, newname_len); + zend_hash_apply_with_arguments(EG(class_table), php_classkit_clean_children, 4, fe->common.scope, ce, methodname, methodname_len); + + /* Fool the op_array into not destructing */ + if (zend_hash_del(&ce->function_table, methodname, methodname_len + 1) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error dereferencing old method"); RETURN_FALSE; }

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