cvs: pecl /classkit classkit.c

From: Date: Mon, 23 Aug 2004 20:41:51 +0000
Subject: cvs: pecl /classkit classkit.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-1713@lists.php.net to get a copy of this message
pollita Mon Aug 23 16:41:51 2004 EDT Modified files: /pecl/classkit classkit.c Log: Override inhereted methods in descendants (but not overriden methods of course) http://cvs.php.net/diff.php/pecl/classkit/classkit.c?r1=1.3&r2=1.4&ty=u Index: pecl/classkit/classkit.c diff -u pecl/classkit/classkit.c:1.3 pecl/classkit/classkit.c:1.4 --- pecl/classkit/classkit.c:1.3 Sat Aug 21 13:19:24 2004 +++ pecl/classkit/classkit.c Mon Aug 23 16:41:51 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: classkit.c,v 1.3 2004/08/21 17:19:24 pollita Exp $ */ +/* $Id: classkit.c,v 1.4 2004/08/23 20:41:51 pollita Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -193,13 +193,56 @@ _zend_hash_add_or_update((ht), (arKey), (nKeyLength), (pData), (pDataSize), (pDest), (flag) ZEND_FILE_LINE_CC) #endif +/* {{{ 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) +{ + 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; + zend_function *fe = va_arg(args, zend_function*); + 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; + } + + function_add_ref(fe); + if (zend_hash_add_or_update(&ce->function_table, fname, fname_len + 1, fe, sizeof(zend_function), NULL, cfe ? HASH_UPDATE : HASH_ADD) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error updating child class"); + return ZEND_HASH_APPLY_KEEP; + } + + /* Process children of this child */ + zend_hash_apply_with_arguments(EG(class_table), php_classkit_update_children, 5, ancestor_class, ce, fe, fname, fname_len); + + return ZEND_HASH_APPLY_KEEP; +} +/* }}} */ + /* {{{ php_classkit_method_add_or_update */ static void php_classkit_method_add_or_update(INTERNAL_FUNCTION_PARAMETERS, int add_or_update) { char *classname, *methodname, *arguments, *phpcode; int classname_len, methodname_len, arguments_len, phpcode_len; - zend_class_entry *ce; + zend_class_entry *ce, *ancestor_class = NULL; zend_function func, *fe; #ifdef ZEND_ENGINE_2 long flags = ZEND_ACC_PUBLIC; @@ -230,6 +273,7 @@ if (php_classkit_fetch_class_method(classname, classname_len, methodname, methodname_len, &ce, &fe TSRMLS_CC) == FAILURE) { RETURN_FALSE; } + ancestor_class = fe->common.scope; if (php_classkit_check_call_stack(&fe->op_array TSRMLS_CC) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot redefine a method while that method is active."); RETURN_FALSE; @@ -238,6 +282,7 @@ if (php_classkit_fetch_class(classname, classname_len, &ce TSRMLS_CC) == FAILURE) { RETURN_FALSE; } + ancestor_class = ce; } if (php_classkit_generate_lambda_method(arguments, arguments_len, phpcode, phpcode_len, &fe TSRMLS_CC) == FAILURE) { @@ -266,6 +311,8 @@ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to add method to class"); RETURN_FALSE; } + + zend_hash_apply_with_arguments(EG(class_table), php_classkit_update_children, 5, ancestor_class, ce, &func, methodname, methodname_len); if (zend_hash_del(EG(function_table), CLASSKIT_TEMP_FUNCNAME, sizeof(CLASSKIT_TEMP_FUNCNAME)) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to remove temporary function entry");

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