gron                                     Sun, 02 May 2010 16:32:25 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=298877

Log:
Refactored part of the Traits implementation.
# - renamed php_runkit_function_copy_ctor to _duplicate_function
#   REM: runkit does not compile with trunk at the moment, fixing it would 
introduce even more version #ifs, don't know what the best way is to fix it
# - extracted traits related stuff from destroy_zend_class into 
_destroy_zend_class_traits_info
#   - need to investigate implementation/handling of internal classes further 
before enabling internal traits

Changed paths:
    U   php/php-src/trunk/Zend/zend_compile.c
    U   php/php-src/trunk/Zend/zend_opcode.c

Modified: php/php-src/trunk/Zend/zend_compile.c
===================================================================
--- php/php-src/trunk/Zend/zend_compile.c       2010-05-02 15:38:31 UTC (rev 
298876)
+++ php/php-src/trunk/Zend/zend_compile.c       2010-05-02 16:32:25 UTC (rev 
298877)
@@ -3321,9 +3321,9 @@
        else if (IS_EQUAL(mname, mname_len, 
"unserialize_func"))(ce)->unserialize_func  = (fe); \
 }

-/* {{{ php_runkit_function_copy_ctor
+/* {{{ Originates from php_runkit_function_copy_ctor
        Duplicate structures in an op_array where necessary to make an outright 
duplicate */
-void php_runkit_function_copy_ctor(zend_function *fe, char *newname)
+void _duplicate_function(zend_function *fe, char *newname)
 {
        zend_literal *literals_copy;
        zend_compiled_variable *dupvars;
@@ -3497,7 +3497,7 @@
                                  fn->common.function_name, fnname_len) == 0)) {
                                if (aliases[i]->alias) {
                                        fn_copy = *fn;
-                                       php_runkit_function_copy_ctor(&fn_copy, 
estrndup(aliases[i]->alias, aliases[i]->alias_len));
+                                       _duplicate_function(&fn_copy, 
estrndup(aliases[i]->alias, aliases[i]->alias_len));

                                        if (aliases[i]->modifiers) { /* if it 
is 0, no modifieres has been changed */
                                                fn_copy.common.fn_flags = 
aliases[i]->modifiers;
@@ -3527,7 +3527,7 @@
        if (zend_hash_find(exclude_table, lcname, lcname_len, &dummy) == 
FAILURE) {
                /* is not in hashtable, thus, function is not to be excluded */
                fn_copy = *fn;
-               php_runkit_function_copy_ctor(&fn_copy, 
estrndup(fn->common.function_name, fnname_len));
+               _duplicate_function(&fn_copy, 
estrndup(fn->common.function_name, fnname_len));

                /* apply aliases which are not qualified by a class name, or 
which have not alias name, just setting visibility */
                /* TODO: i am still not sure, that there will be no 
ambigousities... */
@@ -3543,7 +3543,7 @@
                                                zend_uint lcname2_len;
                                                char* lcname2;
                                                zend_function fn_copy2 = *fn;
-                                               
php_runkit_function_copy_ctor(&fn_copy2, estrndup(aliases[i]->alias, 
aliases[i]->alias_len));
+                                               _duplicate_function(&fn_copy2, 
estrndup(aliases[i]->alias, aliases[i]->alias_len));

                                                if (aliases[i]->modifiers) { /* 
if it is 0, no modifieres has been changed */
                                                        
fn_copy2.common.fn_flags = aliases[i]->modifiers;

Modified: php/php-src/trunk/Zend/zend_opcode.c
===================================================================
--- php/php-src/trunk/Zend/zend_opcode.c        2010-05-02 15:38:31 UTC (rev 
298876)
+++ php/php-src/trunk/Zend/zend_opcode.c        2010-05-02 16:32:25 UTC (rev 
298877)
@@ -176,6 +176,55 @@
        return 0;
 }

+void _destroy_zend_class_traits_info(zend_class_entry *ce)
+{
+       if (ce->num_traits > 0 && ce->traits) {
+               efree(ce->traits);
+       }
+
+       if (ce->trait_aliases) {
+               size_t i = 0;
+               while (ce->trait_aliases[i]) {
+                       if (ce->trait_aliases[i]->trait_method) {
+                               if 
(ce->trait_aliases[i]->trait_method->method_name) {
+                                       
efree(ce->trait_aliases[i]->trait_method->method_name);
+                               }
+                               if 
(ce->trait_aliases[i]->trait_method->class_name) {
+                                       
efree(ce->trait_aliases[i]->trait_method->class_name);
+                               }
+                               efree(ce->trait_aliases[i]->trait_method);
+                       }
+
+                       if (ce->trait_aliases[i]->alias) {
+                               efree(ce->trait_aliases[i]->alias);
+                       }
+
+                       efree(ce->trait_aliases[i]);
+                       i++;
+               }
+
+               efree(ce->trait_aliases);
+       }
+
+       if (ce->trait_precedences) {
+               size_t i = 0;
+
+               while (ce->trait_precedences[i]) {
+                       
efree(ce->trait_precedences[i]->trait_method->method_name);
+                       
efree(ce->trait_precedences[i]->trait_method->class_name);
+                       efree(ce->trait_precedences[i]->trait_method);
+
+                       if (ce->trait_precedences[i]->exclude_from_classes) {
+                               
efree(ce->trait_precedences[i]->exclude_from_classes);
+                       }
+
+                       efree(ce->trait_precedences[i]);
+                       i++;
+               }
+               efree(ce->trait_precedences);
+       }
+}
+
 ZEND_API void destroy_zend_class(zend_class_entry **pce)
 {
        zend_class_entry *ce = *pce;
@@ -194,50 +243,12 @@
                        if (ce->num_interfaces > 0 && ce->interfaces) {
                                efree(ce->interfaces);
                        }
-            if (ce->num_traits > 0 && ce->traits) {
-               efree(ce->traits);
-            }
                        if (ce->doc_comment) {
                                efree(ce->doc_comment);
                        }
-                       if (ce->trait_aliases) {
-                               size_t i = 0;
-                               while (ce->trait_aliases[i]) {
-                                       if (ce->trait_aliases[i]->trait_method) 
{
-                                               if 
(ce->trait_aliases[i]->trait_method->method_name) {
-                                                       
efree(ce->trait_aliases[i]->trait_method->method_name);
-                                               }
-                                               if 
(ce->trait_aliases[i]->trait_method->class_name) {
-                                                       
efree(ce->trait_aliases[i]->trait_method->class_name);
-                                               }
-                                               
efree(ce->trait_aliases[i]->trait_method);
-                                       }
-                                       if (ce->trait_aliases[i]->alias) {
-                                               
efree(ce->trait_aliases[i]->alias);
-                                       }
-                                       efree(ce->trait_aliases[i]);
-                                       i++;
-                               }
-                               efree(ce->trait_aliases);
-                       }
-
-                       if (ce->trait_precedences) {
-                               size_t i = 0;
-                               while (ce->trait_precedences[i]) {
-                                       
efree(ce->trait_precedences[i]->trait_method->method_name);
-                                       
efree(ce->trait_precedences[i]->trait_method->class_name);
-                                       
efree(ce->trait_precedences[i]->trait_method);
-
-                                       if 
(ce->trait_precedences[i]->exclude_from_classes) {
-                                               
efree(ce->trait_precedences[i]->exclude_from_classes);
-                                       }
-
-                                       efree(ce->trait_precedences[i]);
-                                       i++;
-                               }
-                               efree(ce->trait_precedences);
-                       }

+                       _destroy_zend_class_traits_info(ce);
+
                        efree(ce);
                        break;
                case ZEND_INTERNAL_CLASS:

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to