Skip to content

Commit

Permalink
refactor class constants resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
zenovich committed Aug 22, 2015
1 parent 22628ac commit c70451f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 55 deletions.
4 changes: 2 additions & 2 deletions php_runkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ extern ZEND_DECLARE_MODULE_GLOBALS(runkit);
#endif

#if PHP_VERSION_ID < 50600
#define _CONSTANT_INDEX(a) (void*) a
#define PHP_RUNKIT_CONSTANT_INDEX(a) (void*) a
#else
#define _CONSTANT_INDEX(a) a
#define PHP_RUNKIT_CONSTANT_INDEX(a) a
#endif


Expand Down
21 changes: 21 additions & 0 deletions php_runkit_zval.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef PHP_RUNKIT_ZVAL_H
#define PHP_RUNKIT_ZVAL_H

/* {{{ php_runkit_zval_resolve_class_constant */
static void php_runkit_zval_resolve_class_constant(zval **pp, zend_class_entry *ce TSRMLS_DC) {
if (
Z_TYPE_PP(pp) == IS_CONSTANT_AST
#if RUNKIT_ABOVE53
|| (Z_TYPE_PP(pp) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT
#endif
) {
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2) || (PHP_MAJOR_VERSION > 5)
zval_update_constant_ex(pp, PHP_RUNKIT_CONSTANT_INDEX(1), ce TSRMLS_CC);
#else
zval_update_constant(pp, ce TSRMLS_CC);
#endif
}
}
/* }}} */

#endif
15 changes: 3 additions & 12 deletions runkit_classes.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/* $Id$ */

#include "php_runkit.h"
#include "php_runkit_zval.h"

#ifdef PHP_RUNKIT_MANIPULATION
/* {{{ php_runkit_remove_inherited_methods */
Expand Down Expand Up @@ -287,18 +288,8 @@ PHP_FUNCTION(runkit_class_adopt)
}
#endif // (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION > 5)
}
if (
Z_TYPE_PP(pp) == IS_CONSTANT_AST
#if RUNKIT_ABOVE53
|| (Z_TYPE_PP(pp) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT
#endif
) {
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2) || (PHP_MAJOR_VERSION > 5)
zval_update_constant_ex(pp, _CONSTANT_INDEX(1), parent TSRMLS_CC);
#else
zval_update_constant(pp, parent TSRMLS_CC);
#endif
}

php_runkit_zval_resolve_class_constant(pp, parent TSRMLS_CC);

last_null = php_runkit_memrchr(propname, 0, propname_len);
if (last_null) {
Expand Down
35 changes: 6 additions & 29 deletions runkit_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/* $Id$ */

#include "php_runkit.h"
#include "php_runkit_zval.h"

#ifdef PHP_RUNKIT_MANIPULATION
/* {{{ php_runkit_import_functions
Expand Down Expand Up @@ -216,19 +217,10 @@ static int php_runkit_import_class_consts(zend_class_entry *dce, zend_class_entr
goto import_const_skip;
}
}
if (
Z_TYPE_PP(c) == IS_CONSTANT_AST
#if RUNKIT_ABOVE53
|| (Z_TYPE_PP(c) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT
#endif
) {
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2 || PHP_MAJOR_VERSION > 5
zval_update_constant_ex(c, _CONSTANT_INDEX(1), dce TSRMLS_CC);
#else
zval_update_constant(c, dce TSRMLS_CC);
#endif
}

php_runkit_zval_resolve_class_constant(c, dce TSRMLS_CC);
Z_ADDREF_P(*c);

if (zend_hash_add_or_update(&dce->constants_table, key, key_len, (void*)c, sizeof(zval*), NULL, action) == FAILURE) {
zval_ptr_dtor(c);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to import %s::%s", dce->name, key);
Expand Down Expand Up @@ -286,11 +278,7 @@ static int php_runkit_import_class_static_props(zend_class_entry *dce, zend_clas
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to import %s::$%s (cannot remove old member)", dce->name, key);
goto import_st_prop_skip;
}
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2 || PHP_MAJOR_VERSION > 5
zval_update_constant_ex(pp, _CONSTANT_INDEX(1), dce TSRMLS_CC);
#else
zval_update_constant(pp, dce TSRMLS_CC);
#endif
php_runkit_zval_resolve_class_constant(pp, dce TSRMLS_CC);
if (php_runkit_def_prop_add_int(dce, key, key_len - 1, *pp, property_info_ptr->flags,
property_info_ptr->doc_comment,
property_info_ptr->doc_comment_len, dce,
Expand Down Expand Up @@ -357,19 +345,8 @@ static int php_runkit_import_class_props(zend_class_entry *dce, zend_class_entry
goto import_st54_prop_skip;
}
#endif // (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION > 5)
if (
Z_TYPE_PP(p) == IS_CONSTANT_AST
#if RUNKIT_ABOVE53
|| (Z_TYPE_PP(p) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT
#endif // RUNKIT_ABOVE53
) {
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2 || PHP_MAJOR_VERSION > 5
zval_update_constant_ex(p, _CONSTANT_INDEX(1), dce TSRMLS_CC);
#else
zval_update_constant(p, dce TSRMLS_CC);
#endif
}

php_runkit_zval_resolve_class_constant(p, dce TSRMLS_CC);
php_runkit_def_prop_add_int(dce, key, key_len - 1, *p,
property_info_ptr->flags, property_info_ptr->doc_comment,
property_info_ptr->doc_comment_len, dce, override, remove_from_objects TSRMLS_CC);
Expand Down
15 changes: 3 additions & 12 deletions runkit_props.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/* $Id$ */

#include "php_runkit.h"
#include "php_runkit_zval.h"

#ifdef PHP_RUNKIT_MANIPULATION

Expand Down Expand Up @@ -499,18 +500,8 @@ static int php_runkit_def_prop_add(char *classname, int classname_len, char *pro
(existing_prop->flags & ZEND_ACC_STATIC) ? "::$" : "->", propname);
return FAILURE;
}
if (
Z_TYPE_P(copyval) == IS_CONSTANT_AST
# if RUNKIT_ABOVE53
|| (Z_TYPE_P(copyval) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT
# endif
) {
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2) || (PHP_MAJOR_VERSION > 5)
zval_update_constant_ex(&copyval, _CONSTANT_INDEX(1), ce TSRMLS_CC);
#else
zval_update_constant(&copyval, ce TSRMLS_CC);
#endif
}

php_runkit_zval_resolve_class_constant(&copyval, ce TSRMLS_CC);

if (php_runkit_def_prop_add_int(ce, propname, propname_len, copyval, visibility, NULL, 0, ce, 0,
override_in_objects TSRMLS_CC) != SUCCESS) {
Expand Down

0 comments on commit c70451f

Please sign in to comment.