Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New Implementation (with less memoryleak but no cache) + eclipse proj…

…ect file in gitignore
  • Loading branch information...
commit ae0d4e0edbcd64a5c2da53fce7624bc60c0ec067 1 parent 60168f8
@Juliens Juliens authored
Showing with 668 additions and 934 deletions.
  1. +2 −0  .gitignore
  2. +655 −903 aop.c
  3. +11 −31 aop.h
View
2  .gitignore
@@ -41,3 +41,5 @@ Debug/
*.v11.suo
*.vcxproj
*.vcxproj.filters
+.cproject
+.project
View
1,558 aop.c
@@ -86,6 +86,7 @@ zend_object_value aop_create_handler(zend_class_entry *type TSRMLS_DC)
zend_object_value retval;
AopJoinpoint_object *obj = (AopJoinpoint_object *)emalloc(sizeof(AopJoinpoint_object));
+ obj->value = NULL;
memset(obj, 0, sizeof(AopJoinpoint_object));
obj->std.ce = type;
@@ -133,13 +134,14 @@ PHP_RSHUTDOWN_FUNCTION(aop)
}
}
*/
- zend_hash_destroy(aop_g(aop_functions));
- FREE_HASHTABLE(aop_g(aop_functions));
+ zend_hash_destroy(aop_g(pointcuts));
+ FREE_HASHTABLE(aop_g(pointcuts));
for (i = 0; i < aop_g(count_aopJoinpoint_cache); i++) {
zval *aop_object = aop_g(aopJoinpoint_cache)[i];
FREE_ZVAL(aop_object);
}
+ efree(aop_g(aopJoinpoint_cache));
return SUCCESS;
}
@@ -153,18 +155,17 @@ PHP_RINIT_FUNCTION(aop)
aop_g(lock_read_property) = 0;
aop_g(count_aopJoinpoint_cache) = 0;
- ALLOC_HASHTABLE(aop_g(aop_functions));
- zend_hash_init(aop_g(aop_functions), 16, NULL, free_pointcut,0);
-
-
+ ALLOC_HASHTABLE(aop_g(pointcuts));
+ zend_hash_init(aop_g(pointcuts), 16, NULL, free_pointcut,0);
+/*
aop_g(object_cache_write_size) = 1024;
aop_g(object_cache_write) = ecalloc(1024, sizeof(HashTable *));
aop_g(object_cache_read_size) = 1024;
aop_g(object_cache_read) = ecalloc(1024, sizeof(HashTable *));
aop_g(object_cache_func_size) = 1024;
aop_g(object_cache_func) = ecalloc(1024, sizeof(HashTable *));
-
+*/
return SUCCESS;
}
@@ -203,6 +204,7 @@ static void free_pointcut(void *pc)
pcre_free(_pc->re_class);
}
//*/
+ efree(_pc);
/* Need to free members */
}
@@ -214,6 +216,9 @@ static zval *get_aopJoinpoint () {
zval *aop_object = aop_g(aopJoinpoint_cache)[i];
if (Z_REFCOUNT_P(aop_object) == 1) {
AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(aop_object TSRMLS_CC);
+ if (obj->value) {
+ FREE_ZVAL(obj->value);
+ }
obj->value = NULL;
#if ZEND_MODULE_API_NO >= 20100525
obj->key = NULL;
@@ -253,120 +258,15 @@ ZEND_DLEXPORT zval **zend_std_get_property_ptr_ptr_overload(zval *object, zval *
ZEND_DLEXPORT zval * zend_std_read_property_overload(zval *object, zval *member, int type AOP_KEY_D TSRMLS_DC) {
zval *to_return;
- if (aop_g(count_read_property)>0) {
if (aop_g(lock_read_property)>25) {
zend_error(E_ERROR, "Too many level of nested advices. Are there any recursive call ?");
}
aop_g(lock_read_property)++;
- to_return = test_read_pointcut_and_execute(0, object, member, type, EG(scope) AOP_KEY_C);
+ to_return = _test_read_pointcut_and_execute(NULL, NULL, object, member, type, EG(scope) AOP_KEY_C);
aop_g(lock_read_property)--;
return to_return;
- } else {
- return zend_std_read_property(object,member, type AOP_KEY_C TSRMLS_CC);
- }
}
-static int get_pointcuts_read_properties(zval *object, zval *member, pointcut ***pointcuts AOP_KEY_D) {
- zval *tmp_member;
- int i, count = 0;
- pointcut *current_pc;
- zend_class_entry *ce;
- TSRMLS_FETCH();
-
- ce = Z_OBJCE_P(object);
- for (i = 0; i < aop_g(count_read_property); i++) {
- current_pc = aop_g(property_pointcuts_read)[i];
- if (current_pc->method[0] != '*') {
- if (!strcmp_with_joker_case(current_pc->method, Z_STRVAL_P(member), 1)) {
- continue;
- }
- }
- //Scope
- if (current_pc->static_state != 2 || current_pc->scope != 0) {
- if (!test_property_scope(current_pc, ce, member AOP_KEY_C)) {
- continue;
- }
- }
-
- if (pointcut_match_zend_class_entry(current_pc, ce)) {
- if (count==0) {
- (*pointcuts) = emalloc(sizeof(pointcut *));
- } else {
- (*pointcuts) = erealloc((*pointcuts), sizeof(pointcut *)*(count+1));
- }
- (*pointcuts)[count] = current_pc;
- count++;
- }
- }
- return count;
-
-}
-
-static HashTable *make_matching_ht (zend_execute_data *ex) {
- TSRMLS_FETCH();
- zend_function *curr_func;
- HashTable *ht = NULL;
- HashPosition pos;
- pointcut **temp;
- if (ex) {
- curr_func = ex->function_state.function;
- }
- zend_hash_internal_pointer_reset_ex(aop_g(aop_functions), &pos);
- while (zend_hash_get_current_data_ex(aop_g(aop_functions), (void **)&temp, &pos) == SUCCESS) {
- if (pointcut_match_zend_function(*temp, curr_func, ex)) {
- if (ht==NULL) {
- ALLOC_HASHTABLE(ht);
- zend_hash_init(ht, 16, NULL, free,0);
- }
- zend_hash_next_index_insert (ht, temp, sizeof(pointcut **), NULL);
- }
- zend_hash_move_forward_ex (aop_g(aop_functions), &pos);
- }
- return ht;
-
-}
-
-
-
-static HashTable *get_matching_ht (zval *object, zend_execute_data *ex) {
- TSRMLS_FETCH();
- zend_function *curr_func;
- char *func_name;
- pointcut_cache *cache = NULL;
- HashTable *object_cache;
- if (object==NULL) {
- return make_matching_ht(ex);
- }
- if (ex) {
- curr_func = ex->function_state.function;
- }
- func_name = estrdup(curr_func->common.function_name);
- object_cache = get_object_cache_func(object);
- if (object_cache == NULL) {
- ALLOC_HASHTABLE(object_cache);
- zend_hash_init(object_cache, 16, NULL, free_pointcut_cache ,0);
- store_object_cache_func(object, object_cache);
- } else {
- zend_hash_find(object_cache,func_name, strlen(func_name), (void **)&cache);
- }
- if (cache == NULL || cache->declare_count < aop_g(count_pcs) || cache->ce != Z_OBJCE_P(object)) {
- if (cache != NULL) {
- zend_hash_del(object_cache,func_name, strlen(func_name));
- }
- cache = emalloc (sizeof (pointcut_cache));
- cache->ht = (HashTable *)make_matching_ht (ex);
- if (cache->ht==NULL) {
- cache->count = 0;
- } else {
- cache->count = cache->ht->nApplyCount;
- }
- cache->declare_count = aop_g(count_pcs);
- cache->ce = Z_OBJCE_P(object);
- zend_hash_add(object_cache, func_name, strlen(func_name), cache, sizeof(pointcut_cache), NULL);
- }
- efree(func_name);
- return cache->ht;
-}
static void _test_func_pointcut_and_execute(HashPosition pos, HashTable *ht, zend_execute_data *ex, zval *object, zend_class_entry *scope, zend_class_entry *called_scope, int args_overloaded, zval *args, zval **to_return_ptr_ptr) {
zval *aop_object, *exception;
@@ -375,7 +275,7 @@ static void _test_func_pointcut_and_execute(HashPosition pos, HashTable *ht, zen
pointcut *current_pc;
pointcut **temp;
if (ht==NULL) {
- ht = get_matching_ht (object, ex);
+ ht = calculate_function_pointcuts (object, ex);
if (ht==NULL) {
aop_g(overloaded) = 0;
execute_context (ex, object, scope, called_scope,args_overloaded, args, to_return_ptr_ptr);
@@ -386,14 +286,15 @@ static void _test_func_pointcut_and_execute(HashPosition pos, HashTable *ht, zen
} else {
zend_hash_move_forward_ex (ht, &pos);
}
-
- if (zend_hash_get_current_data_ex(aop_g(aop_functions), (void **)&temp, &pos) != SUCCESS) {
+ if (zend_hash_get_current_data_ex(ht, (void **)&temp, &pos) != SUCCESS) {
+
+ zend_hash_destroy(ht);
+ FREE_HASHTABLE(ht);
aop_g(overloaded) = 0;
execute_context (ex, object, scope, called_scope,args_overloaded, args, to_return_ptr_ptr);
aop_g(overloaded) = 1;
return;
}
-
current_pc = *temp;
aop_object = get_aopJoinpoint();
@@ -449,155 +350,100 @@ static void _test_func_pointcut_and_execute(HashPosition pos, HashTable *ht, zen
return;
}
-
-static void test_func_pointcut_and_execute(int current_pointcut_index, zend_execute_data *ex, zval *object, zend_class_entry *scope, zend_class_entry *called_scope, int args_overloaded, zval *args, zval **to_return_ptr_ptr) {
-
- zend_function *curr_func = NULL;
- zval *aop_object, *exception;
- AopJoinpoint_object *obj;
- pointcut *current_pc;
+static zval *_test_read_pointcut_and_execute(HashPosition pos, HashTable *ht, zval *object, zval *member, int type, zend_class_entry *current_scope AOP_KEY_D) {
+ zval *temp_this, *to_return;
+ zend_class_entry *scope;
pointcut **temp;
- HashTable *test;
- TSRMLS_FETCH();
- if (current_pointcut_index == aop_g(count_pcs)) {
- aop_g(overloaded) = 0;
- execute_context (ex, object, scope, called_scope,args_overloaded, args, to_return_ptr_ptr);
- aop_g(overloaded) = 1;
- return;
- }
-
- if (zend_hash_index_find(aop_g(aop_functions), current_pointcut_index, (void **)&temp)!=SUCCESS) {
- php_printf("ERROR");
- }
- current_pc = *temp;
- //current_pc = aop_g(pcs)[current_pointcut_index];
-
+ pointcut *current_pc;
+ AopJoinpoint_object *obj;
+ zval *aop_object;
- if (ex) {
- curr_func = ex->function_state.function;
+ if (ht==NULL) {
+ ht = calculate_property_pointcuts (object, member, AOP_KIND_READ AOP_KEY_C);
+ zend_hash_internal_pointer_reset_ex(ht, &pos);
+ } else {
+ zend_hash_move_forward_ex (ht, &pos);
}
- if (!pointcut_match_zend_function(current_pc, curr_func, ex)) {
- test_func_pointcut_and_execute(current_pointcut_index+1, ex, object, scope, called_scope, args_overloaded, args, to_return_ptr_ptr);
- return;
+ if (zend_hash_get_current_data_ex(ht, (void **)&temp, &pos) != SUCCESS) {
+ scope = EG(scope);
+ temp_this = EG(This);
+ EG(scope) = current_scope;
+ EG(This) = object;
+ to_return = zend_std_read_property(object, member, type AOP_KEY_C TSRMLS_CC);
+ EG(This) = temp_this;
+ EG(scope) = scope;
+ return to_return;
}
+ current_pc = *temp;
aop_object = get_aopJoinpoint();
obj = (AopJoinpoint_object *) zend_object_store_get_object(aop_object TSRMLS_CC);
obj->current_pointcut = current_pc;
- obj->current_pointcut_index = current_pointcut_index;
- obj->kind_of_advice = current_pc->kind_of_advice;
- obj->object = object;
- obj->to_return_ptr_ptr = to_return_ptr_ptr;
- obj->value = (*to_return_ptr_ptr);
- obj->ex = ex;
+ obj->pos = pos;
+ obj->advice = ht;
+ obj->kind_of_advice = (current_pc->kind_of_advice&AOP_KIND_WRITE) ? (current_pc->kind_of_advice - AOP_KIND_WRITE) : current_pc->kind_of_advice;
obj->object = object;
- obj->scope = scope;
- obj->called_scope = called_scope;
- obj->args = args;
- obj->args_overloaded = args_overloaded;
- obj->exception = NULL;
+ obj->member = member;
+ obj->type = type;
+ obj->scope = current_scope;
+#if ZEND_MODULE_API_NO >= 20100525
+ obj->key = key;
+#endif
+
if (current_pc->kind_of_advice & AOP_KIND_BEFORE) {
- if (!EG(exception)) {
- execute_pointcut(current_pc, aop_object);
- }
+ execute_pointcut (current_pc, aop_object);
}
if (current_pc->kind_of_advice & AOP_KIND_AROUND) {
- if (!EG(exception)) {
- execute_pointcut(current_pc, aop_object);
- if (obj->value != NULL) {
- (*to_return_ptr_ptr) = obj->value;
- }
- }
+ execute_pointcut (current_pc, aop_object);
+ to_return = obj->value;
} else {
- test_func_pointcut_and_execute(current_pointcut_index+1, ex, object, scope, called_scope, obj->args_overloaded, obj->args, to_return_ptr_ptr);
+ to_return = _test_read_pointcut_and_execute(pos, ht, object, member, type, current_scope AOP_KEY_C);
}
if (current_pc->kind_of_advice & AOP_KIND_AFTER) {
- if (current_pc->kind_of_advice & AOP_KIND_CATCH && EG(exception)) {
- exception = EG(exception);
- obj->exception = exception;
- EG(exception)=NULL;
- execute_pointcut(current_pc, aop_object);
- EG(exception) = exception;
- if (obj->value != NULL) {
- (*to_return_ptr_ptr) = obj->value;
- }
- } else if (current_pc->kind_of_advice & AOP_KIND_RETURN && !EG(exception)) {
- execute_pointcut(current_pc, aop_object);
- if (obj->value != NULL) {
- (*to_return_ptr_ptr) = obj->value;
- }
+ execute_pointcut (current_pc, aop_object);
+ if (obj->value != NULL) {
+ to_return = obj->value;
}
}
Z_DELREF_P(aop_object);
- return;
+ return to_return;
}
-static zval *test_read_pointcut_and_execute(int current_pointcut_index, zval *object, zval *member, int type, zend_class_entry *current_scope AOP_KEY_D) {
- zval *temp, *to_return, *tmp_member;
- zend_class_entry *scope;
- zend_object_handle handle = Z_OBJ_HANDLE_P(object);
+static void _test_write_pointcut_and_execute(HashPosition pos, HashTable *ht, zval *object, zval *member, zval *value, zend_class_entry *current_scope AOP_KEY_D) {
+ zval *temp_this, *to_return;
+ zend_class_entry *scope;
+ pointcut **temp;
pointcut *current_pc;
- zend_class_entry *ce;
AopJoinpoint_object *obj;
zval *aop_object;
- int i;
- pointcut_cache *cache = NULL;
- HashTable *object_cache;
- TSRMLS_FETCH();
- if (Z_TYPE_P(member) != IS_STRING ) {
- ALLOC_ZVAL(tmp_member);
- *tmp_member = *member;
- INIT_PZVAL(tmp_member);
- zval_copy_ctor(tmp_member);
- convert_to_string(tmp_member);
- member = tmp_member;
-#if ZEND_MODULE_API_NO >= 20100525
- key = NULL;
-#endif
- }
-
- object_cache = get_object_cache_read(object);
- if (object_cache == NULL) {
- ALLOC_HASHTABLE(object_cache);
- zend_hash_init(object_cache, 16, NULL, free_pointcut_cache ,0);
- store_object_cache_read(object, object_cache);
- } else {
- zend_hash_find(object_cache, Z_STRVAL_P(member), Z_STRLEN_P(member), (void **)&cache);
- }
- if (cache == NULL || cache->declare_count < aop_g(count_read_property) || cache->ce != Z_OBJCE_P(object)) {
- if (cache != NULL) {
- zend_hash_del(object_cache, Z_STRVAL_P(member), Z_STRLEN_P(member));
- }
- cache = emalloc (sizeof (pointcut_cache));
- cache->count = get_pointcuts_read_properties(object, member, &cache->pointcuts_cache AOP_KEY_C);
- cache->declare_count = aop_g(count_read_property);
- cache->ce = Z_OBJCE_P(object);
- cache->ht = NULL;
- zend_hash_add(object_cache, Z_STRVAL_P(member), Z_STRLEN_P(member), cache, sizeof(pointcut_cache), NULL);
+ if (ht==NULL) {
+ ht = calculate_property_pointcuts (object, member, AOP_KIND_WRITE AOP_KEY_C);
+ zend_hash_internal_pointer_reset_ex(ht, &pos);
} else {
+ zend_hash_move_forward_ex (ht, &pos);
}
-
- if (current_pointcut_index == cache->count) {
+ if (zend_hash_get_current_data_ex(ht, (void **)&temp, &pos) != SUCCESS) {
scope = EG(scope);
- temp = EG(This);
+ temp_this = EG(This);
EG(scope) = current_scope;
EG(This) = object;
- to_return = zend_std_read_property(object, member, type AOP_KEY_C TSRMLS_CC);
- EG(This) = temp;
+ zend_std_write_property(object,member,value AOP_KEY_C TSRMLS_CC);
+ EG(This) = temp_this;
EG(scope) = scope;
- return to_return;
+ return;
}
- current_pc = cache->pointcuts_cache[current_pointcut_index];
+ current_pc = *temp;
aop_object = get_aopJoinpoint();
obj = (AopJoinpoint_object *) zend_object_store_get_object(aop_object TSRMLS_CC);
obj->current_pointcut = current_pc;
- obj->current_pointcut_index = current_pointcut_index;
- obj->kind_of_advice = (current_pc->kind_of_advice&AOP_KIND_WRITE) ? (current_pc->kind_of_advice - AOP_KIND_WRITE) : current_pc->kind_of_advice;
+ obj->pos = pos;
+ obj->advice = ht;
+ obj->kind_of_advice = (current_pc->kind_of_advice&AOP_KIND_READ) ? (current_pc->kind_of_advice - AOP_KIND_READ) : current_pc->kind_of_advice;
obj->object = object;
obj->member = member;
- obj->type = type;
+ obj->value = value;
obj->scope = current_scope;
#if ZEND_MODULE_API_NO >= 20100525
obj->key = key;
@@ -608,9 +454,9 @@ static zval *test_read_pointcut_and_execute(int current_pointcut_index, zval *ob
}
if (current_pc->kind_of_advice & AOP_KIND_AROUND) {
execute_pointcut (current_pc, aop_object);
- to_return = obj->value;
} else {
- to_return = test_read_pointcut_and_execute(current_pointcut_index+1, object, member, type, current_scope AOP_KEY_C);
+ value = obj->value;
+ _test_write_pointcut_and_execute(pos, ht, object, member, value, current_scope AOP_KEY_C);
}
if (current_pc->kind_of_advice & AOP_KIND_AFTER) {
execute_pointcut (current_pc, aop_object);
@@ -619,8 +465,9 @@ static zval *test_read_pointcut_and_execute(int current_pointcut_index, zval *ob
}
}
Z_DELREF_P(aop_object);
- return to_return;
}
+
+
static int test_property_scope (pointcut *current_pc, zend_class_entry *ce, zval *member AOP_KEY_D) {
zend_property_info *property_info = NULL;
ulong h;
@@ -659,127 +506,7 @@ static int test_property_scope (pointcut *current_pc, zend_class_entry *ce, zval
return 1;
}
-static int get_pointcuts_write_properties(zval *object, zval *member, pointcut ***pointcuts AOP_KEY_D) {
- int i, count = 0;
- pointcut *current_pc;
- zend_class_entry *ce;
- TSRMLS_FETCH();
-
- ce = Z_OBJCE_P(object);
-
- for (i = 0; i < aop_g(count_write_property); i++) {
- current_pc = aop_g(property_pointcuts_write)[i];
- if (current_pc->method[0] != '*') {
- if (!strcmp_with_joker_case(current_pc->method, Z_STRVAL_P(member), 1)) {
- continue;
- }
- }
- //Scope
- if (current_pc->static_state != 2 || current_pc->scope != 0) {
- if (!test_property_scope(current_pc, ce, member AOP_KEY_C)) {
- continue;
- }
- }
-
- if (pointcut_match_zend_class_entry(current_pc, ce)) {
- if (count == 0) {
- (*pointcuts) = emalloc(sizeof(pointcut *));
- } else {
- (*pointcuts) = erealloc((*pointcuts), sizeof(pointcut *)*(count+1));
- }
- (*pointcuts)[count] = current_pc;
- count++;
- }
- }
- return count;
-}
-
-static void test_write_pointcut_and_execute(int current_pointcut_index, zval *object, zval *member, zval *value, zend_class_entry *current_scope AOP_KEY_D) {
- zval *temp, *tmp_member;
- zend_class_entry *scope;
- zend_object_handle handle = Z_OBJ_HANDLE_P(object);
- pointcut *current_pc;
- zend_class_entry *ce;
- AopJoinpoint_object *obj;
- zval *aop_object;
- int i;
- pointcut_cache *cache = NULL;
- HashTable *object_cache;
- TSRMLS_FETCH();
-
- if (Z_TYPE_P(member) != IS_STRING ) {
- ALLOC_ZVAL(tmp_member);
- *tmp_member = *member;
- INIT_PZVAL(tmp_member);
- zval_copy_ctor(tmp_member);
- convert_to_string(tmp_member);
- member = tmp_member;
-#if ZEND_MODULE_API_NO >= 20100525
- key = NULL;
-#endif
- }
-
-
- object_cache = get_object_cache_write(object);
- if (object_cache == NULL) {
- ALLOC_HASHTABLE(object_cache);
- zend_hash_init(object_cache, 16, NULL, free_pointcut_cache ,0);
- store_object_cache_write(object, object_cache);
- } else {
- zend_hash_find(object_cache, Z_STRVAL_P(member), Z_STRLEN_P(member), (void **)&cache);
- }
-
- if (cache == NULL || cache->declare_count<aop_g(count_write_property) || cache->ce != Z_OBJCE_P(object)) {
- if (cache != NULL) {
- zend_hash_del(object_cache, Z_STRVAL_P(member), Z_STRLEN_P(member));
- }
- cache = emalloc (sizeof (pointcut_cache));
- cache->count = get_pointcuts_write_properties(object, member, &cache->pointcuts_cache AOP_KEY_C);
- cache->declare_count = aop_g(count_write_property);
- cache->ce = Z_OBJCE_P(object);
- cache->ht = NULL;
- zend_hash_add(object_cache, Z_STRVAL_P(member), Z_STRLEN_P(member), cache, sizeof(pointcut_cache), NULL);
- }
-
- if (current_pointcut_index == cache->count) {
- scope = EG(scope);
- temp = EG(This);
- EG(scope) = current_scope;
- EG(This) = object;
- zend_std_write_property(object,member,value AOP_KEY_C TSRMLS_CC);
- EG(This) = temp;
- EG(scope) = scope;
- return;
- }
-
- current_pc = cache->pointcuts_cache[current_pointcut_index];
- aop_object = get_aopJoinpoint();
- obj = (AopJoinpoint_object *)zend_object_store_get_object(aop_object TSRMLS_CC);
- obj->current_pointcut = current_pc;
- obj->current_pointcut_index = current_pointcut_index;
- obj->kind_of_advice = (current_pc->kind_of_advice&AOP_KIND_READ) ? (current_pc->kind_of_advice - AOP_KIND_READ) : current_pc->kind_of_advice;
- obj->object = object;
- obj->member = member;
- obj->value = value;
- obj->scope = current_scope;
-#if ZEND_MODULE_API_NO >= 20100525
- obj->key = key;
-#endif
- if (current_pc->kind_of_advice & AOP_KIND_BEFORE) {
- execute_pointcut (current_pc, aop_object);
- }
- if (current_pc->kind_of_advice & AOP_KIND_AROUND) {
- execute_pointcut (current_pc, aop_object);
- } else {
- value = obj->value;
- test_write_pointcut_and_execute(current_pointcut_index+1, object, member, value, current_scope AOP_KEY_C);
- }
- if (current_pc->kind_of_advice & AOP_KIND_AFTER) {
- execute_pointcut (current_pc, aop_object);
- }
- Z_DELREF_P(aop_object);
-}
static void execute_pointcut (pointcut *pointcut_to_execute, zval *arg) {
zval *args[1], *zret_ptr;
@@ -802,16 +529,12 @@ static void execute_pointcut (pointcut *pointcut_to_execute, zval *arg) {
}
ZEND_DLEXPORT void zend_std_write_property_overload(zval *object, zval *member, zval *value AOP_KEY_D TSRMLS_DC) {
- if (aop_g(count_write_property) > 0) {
if (aop_g(lock_write_property) > 25) {
zend_error(E_ERROR, "Too many level of nested advices. Are there any recursive call ?");
}
aop_g(lock_write_property)++;
- test_write_pointcut_and_execute(0, object, member, value, EG(scope) AOP_KEY_C);
+ _test_write_pointcut_and_execute(NULL, NULL, object, member, value, EG(scope) AOP_KEY_C);
aop_g(lock_write_property)--;
- } else {
- zend_std_write_property(object, member, value AOP_KEY_C TSRMLS_CC);
- }
}
static int resource_pointcut;
@@ -1075,14 +798,14 @@ PHP_METHOD(AopJoinpoint, process){
// NULL for no segfault (use by zend_get_property_info_quick)
zend_literal *key = NULL;
#endif
- test_write_pointcut_and_execute(obj->current_pointcut_index+1, obj->object, obj->member, obj->value, obj->scope AOP_KEY_C);
+ _test_write_pointcut_and_execute(obj->pos, obj->advice, obj->object, obj->member, obj->value, obj->scope AOP_KEY_C);
} else {
#if ZEND_MODULE_API_NO >= 20100525
// zend_literal *key = obj->key;
// NULL for no segfault (use by zend_get_property_info_quick)
zend_literal *key = NULL;
#endif
- obj->value = test_read_pointcut_and_execute(obj->current_pointcut_index+1, obj->object, obj->member, obj->type, obj->scope AOP_KEY_C);
+ obj->value = _test_read_pointcut_and_execute(obj->pos, obj->advice, obj->object, obj->member, obj->type, obj->scope AOP_KEY_C);
}
} else {
_test_func_pointcut_and_execute(obj->pos, obj->advice, obj->ex, obj->object, obj->scope, obj->called_scope, obj->args_overloaded, obj->args, obj->to_return_ptr_ptr);
@@ -1113,13 +836,7 @@ static pointcut *add_pointcut_property (zend_fcall_info fci, zend_fcall_info_cac
//And we had it on the write
pc->kind_of_advice |= AOP_KIND_WRITE;
- aop_g(count_write_property)++;
- if (aop_g(count_write_property) == 1) {
- aop_g(property_pointcuts_write) = emalloc(sizeof(pointcut *));
- } else {
- aop_g(property_pointcuts_write) = erealloc(aop_g(property_pointcuts_write), aop_g(count_write_property)*sizeof(pointcut *));
- }
- aop_g(property_pointcuts_write)[aop_g(count_write_property) - 1] = pc;
+ //zend_hash_next_index_insert(aop_g(pointcuts), &pc, sizeof(pointcut **),NULL);
return pc;
}
}
@@ -1130,19 +847,19 @@ static pointcut * alloc_pointcut () {
pointcut *pc = emalloc(sizeof(pointcut));
- pc->scope = 0;
- pc->static_state = 2;
- pc->method_jok = 0;
- pc->class_jok = 0;
- pc->class_name = NULL;
- pc->method = NULL;
- pc->selector = NULL;
- pc->kind_of_advice = 0;
- //pc->fci = NULL;
- //pc->fcic = NULL;
- pc->re_method = NULL;
- pc->re_class = NULL;
- return pc;
+ pc->scope = 0;
+ pc->static_state = 2;
+ pc->method_jok = 0;
+ pc->class_jok = 0;
+ pc->class_name = NULL;
+ pc->method = NULL;
+ pc->selector = NULL;
+ pc->kind_of_advice = 0;
+ //pc->fci = NULL;
+ //pc->fcic = NULL;
+ pc->re_method = NULL;
+ pc->re_class = NULL;
+ return pc;
}
static void add_pointcut (zend_fcall_info fci, zend_fcall_info_cache fcic, char *selector, int selector_len, int type , zval **return_value_ptr TSRMLS_DC) {
@@ -1163,7 +880,8 @@ static void add_pointcut (zend_fcall_info fci, zend_fcall_info_cache fcic, char
pc->kind_of_advice = type;
parse_pointcut(&pc);
- zend_hash_index_update(aop_g(aop_functions), count, &pc, sizeof(pointcut **),NULL);
+ zend_hash_next_index_insert(aop_g(pointcuts), &pc, sizeof(pointcut **),NULL);
+
@@ -1178,6 +896,7 @@ void make_regexp_on_pointcut (pointcut **pc) {
int preg_options = 0, i;
int *replace_count, *new_length;
char *regexp;
+ char *regexp_buffer;
char tempregexp[500];
TSRMLS_FETCH();
@@ -1185,32 +904,58 @@ void make_regexp_on_pointcut (pointcut **pc) {
replace_count = emalloc (sizeof(int));
new_length = emalloc (sizeof(int));
regexp = estrdup((*pc)->method);
- regexp = php_str_to_str_ex(regexp, strlen(regexp), "**\\", 3, "[.#}", 4, new_length, 0, replace_count);
- regexp = php_str_to_str_ex(regexp, strlen(regexp), "**", 2, "[.#]", 4, new_length, 0, replace_count);
- regexp = php_str_to_str_ex(regexp, strlen(regexp), "\\", 1, "\\\\", 2, new_length, 0, replace_count);
- regexp = php_str_to_str_ex(regexp, strlen(regexp), "*", 1, "[^\\\\]*", 6, new_length, 0, replace_count);
- regexp = php_str_to_str_ex(regexp, strlen(regexp), "[.#]", 4, ".*", 2, new_length, 0, replace_count);
- regexp = php_str_to_str_ex(regexp, strlen(regexp), "[.#}", 4, "(.*\\\\)?", 7, new_length, 0, replace_count);
+ regexp_buffer = php_str_to_str_ex(regexp, strlen(regexp), "**\\", 3, "[.#}", 4, new_length, 0, replace_count);
+ efree(regexp);
+ regexp = regexp_buffer;
+ regexp_buffer = php_str_to_str_ex(regexp, strlen(regexp), "**", 2, "[.#]", 4, new_length, 0, replace_count);
+ efree(regexp);
+ regexp = regexp_buffer;
+ regexp_buffer = php_str_to_str_ex(regexp, strlen(regexp), "\\", 1, "\\\\", 2, new_length, 0, replace_count);
+ efree(regexp);
+ regexp = regexp_buffer;
+ regexp_buffer = php_str_to_str_ex(regexp, strlen(regexp), "*", 1, "[^\\\\]*", 6, new_length, 0, replace_count);
+ efree(regexp);
+ regexp = regexp_buffer;
+ regexp_buffer = php_str_to_str_ex(regexp, strlen(regexp), "[.#]", 4, ".*", 2, new_length, 0, replace_count);
+ efree(regexp);
+ regexp = regexp_buffer;
+ regexp_buffer = php_str_to_str_ex(regexp, strlen(regexp), "[.#}", 4, "(.*\\\\)?", 7, new_length, 0, replace_count);
+ efree(regexp);
+ regexp = regexp_buffer;
sprintf((char *)tempregexp, "/^%s$/i", regexp);
- (*pc)->re_method = pcre_get_compiled_regex(estrdup(tempregexp), &pcre_extra, &preg_options TSRMLS_CC);
+ efree(regexp);
+ (*pc)->re_method = pcre_get_compiled_regex(tempregexp, &pcre_extra, &preg_options TSRMLS_CC);
+ //efree(tempregexp);
if (!(*pc)->re_method) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid expression");
}
if ((*pc)->class_name != NULL) {
regexp = estrdup((*pc)->class_name);
- regexp = php_str_to_str_ex(regexp, strlen(regexp), "**\\", 3, "[.#}", 4, new_length, 0, replace_count);
- regexp = php_str_to_str_ex(regexp, strlen(regexp), "**", 2, "[.#]", 4, new_length, 0, replace_count);
- regexp = php_str_to_str_ex(regexp, strlen(regexp), "\\", 1, "\\\\", 2, new_length, 0, replace_count);
- regexp = php_str_to_str_ex(regexp, strlen(regexp), "*", 1, "[^\\\\]*", 6, new_length, 0, replace_count);
- regexp = php_str_to_str_ex(regexp, strlen(regexp), "[.#]", 4, ".*", 2, new_length, 0, replace_count);
- regexp = php_str_to_str_ex(regexp, strlen(regexp), "[.#}", 4, "(.*\\\\)?", 7, new_length, 0, replace_count);
- sprintf(tempregexp, "/^%s$/i", estrdup(regexp));
- (*pc)->re_class = pcre_get_compiled_regex(estrdup(tempregexp), &pcre_extra, &preg_options TSRMLS_CC);
+ regexp_buffer = php_str_to_str_ex(regexp, strlen(regexp), "**\\", 3, "[.#}", 4, new_length, 0, replace_count);
+ efree(regexp);
+ regexp = regexp_buffer;
+ regexp_buffer = php_str_to_str_ex(regexp, strlen(regexp), "**", 2, "[.#]", 4, new_length, 0, replace_count);
+ efree(regexp);
+ regexp = regexp_buffer;
+ regexp_buffer = php_str_to_str_ex(regexp, strlen(regexp), "\\", 1, "\\\\", 2, new_length, 0, replace_count);
+ efree(regexp);
+ regexp = regexp_buffer;
+ regexp_buffer = php_str_to_str_ex(regexp, strlen(regexp), "*", 1, "[^\\\\]*", 6, new_length, 0, replace_count);
+ efree(regexp);
+ regexp = regexp_buffer;
+ regexp_buffer = php_str_to_str_ex(regexp, strlen(regexp), "[.#]", 4, ".*", 2, new_length, 0, replace_count);
+ efree(regexp);
+ regexp = regexp_buffer;
+ regexp_buffer = php_str_to_str_ex(regexp, strlen(regexp), "[.#}", 4, "(.*\\\\)?", 7, new_length, 0, replace_count);
+ efree(regexp);
+ regexp = regexp_buffer;
+ sprintf(tempregexp, "/^%s$/i", regexp);
+ efree(regexp);
+ (*pc)->re_class = pcre_get_compiled_regex(tempregexp, &pcre_extra, &preg_options TSRMLS_CC);
if (!(*pc)->re_class) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid expression");
}
}
- efree(regexp);
efree(replace_count);
efree(new_length);
}
@@ -1230,7 +975,7 @@ static void parse_pointcut (pointcut **pc) {
// Class and method separate by ::
temp = strstr(strval, "::");
if (temp == NULL) {
- // Class and method separate by ->
+ // Class and method separate by ->
temp = strstr(strval, "->");
}
// No class
@@ -1247,6 +992,7 @@ static void parse_pointcut (pointcut **pc) {
(*pc)->kind_of_advice = (*pc)->kind_of_advice|AOP_KIND_FUNCTION;
}
make_regexp_on_pointcut(pc);
+ efree(strval);
}
static pointcut *aop_add_read (char *selector, zend_fcall_info fci, zend_fcall_info_cache fcic, int type) {
@@ -1301,7 +1047,7 @@ static pointcut *aop_add_read (char *selector, zend_fcall_info fci, zend_fcall_i
pc->static_state = is_static(strval);
make_regexp_on_pointcut(&pc);
- aop_g(property_pointcuts_read)[count]=pc;
+ zend_hash_next_index_insert(aop_g(pointcuts), &pc, sizeof(pointcut **),NULL);
return pc;
}
@@ -1355,7 +1101,7 @@ static pointcut *aop_add_write (char *selector, zend_fcall_info fci, zend_fcall_
pc->scope = get_scope(strval);
pc->static_state = is_static(strval);
make_regexp_on_pointcut(&pc);
- aop_g(property_pointcuts_write)[count] = pc;
+ zend_hash_next_index_insert(aop_g(pointcuts), &pc, sizeof(pointcut **),NULL);
return pc;
}
@@ -1510,620 +1256,626 @@ ZEND_DLEXPORT void aop_execute (zend_op_array *ops TSRMLS_DC) {
#if ZEND_MODULE_API_NO < 20121113
void aop_execute_internal (zend_execute_data *current_execute_data, int return_value_used TSRMLS_DC) {
#else
-void aop_execute_internal (zend_execute_data *current_execute_data, struct _zend_fcall_info *fci, int return_value_used TSRMLS_DC) {
+ void aop_execute_internal (zend_execute_data *current_execute_data, struct _zend_fcall_info *fci, int return_value_used TSRMLS_DC) {
#endif
- zend_execute_data *data;
- zend_function *curr_func = NULL;
+ zend_execute_data *data;
+ zend_function *curr_func = NULL;
- zval ** to_return_ptr_ptr;
+ zval ** to_return_ptr_ptr;
- if (!aop_g(aop_enable)) {
- if (_zend_execute_internal) {
+ if (!aop_g(aop_enable)) {
+ if (_zend_execute_internal) {
#if ZEND_MODULE_API_NO < 20121113
- _zend_execute_internal(current_execute_data, return_value_used TSRMLS_CC);
+ _zend_execute_internal(current_execute_data, return_value_used TSRMLS_CC);
#else
- _zend_execute_internal(current_execute_data, fci, return_value_used TSRMLS_CC);
+ _zend_execute_internal(current_execute_data, fci, return_value_used TSRMLS_CC);
#endif
- } else {
+ } else {
#if ZEND_MODULE_API_NO < 20121113
- execute_internal(current_execute_data, return_value_used TSRMLS_CC);
+ execute_internal(current_execute_data, return_value_used TSRMLS_CC);
#else
- execute_internal(current_execute_data, fci, return_value_used TSRMLS_CC);
+ execute_internal(current_execute_data, fci, return_value_used TSRMLS_CC);
#endif
+ }
+ return;
}
- return;
- }
- data = EG(current_execute_data);
+ data = EG(current_execute_data);
- if (data) {
- curr_func = data->function_state.function;
- }
- if (curr_func == NULL || curr_func->common.function_name == NULL || aop_g(overloaded) || EG(exception)) {
- if (_zend_execute_internal) {
+ if (data) {
+ curr_func = data->function_state.function;
+ }
+ if (curr_func == NULL || curr_func->common.function_name == NULL || aop_g(overloaded) || EG(exception)) {
+ if (_zend_execute_internal) {
#if ZEND_MODULE_API_NO < 20121113
- _zend_execute_internal(current_execute_data, return_value_used TSRMLS_CC);
+ _zend_execute_internal(current_execute_data, return_value_used TSRMLS_CC);
#else
- _zend_execute_internal(current_execute_data, fci, return_value_used TSRMLS_CC);
+ _zend_execute_internal(current_execute_data, fci, return_value_used TSRMLS_CC);
#endif
- } else {
+ } else {
#if ZEND_MODULE_API_NO < 20121113
- execute_internal(current_execute_data, return_value_used TSRMLS_CC);
+ execute_internal(current_execute_data, return_value_used TSRMLS_CC);
#else
- execute_internal(current_execute_data, fci, return_value_used TSRMLS_CC);
+ execute_internal(current_execute_data, fci, return_value_used TSRMLS_CC);
#endif
- }
- return;
- }
+ }
+ return;
+ }
#if ZEND_MODULE_API_NO >= 20100525
- to_return_ptr_ptr = &(*(temp_variable *)((char *) current_execute_data->Ts + current_execute_data->opline->result.var)).var.ptr;
+ to_return_ptr_ptr = &(*(temp_variable *)((char *) current_execute_data->Ts + current_execute_data->opline->result.var)).var.ptr;
#else
- to_return_ptr_ptr = &(*(temp_variable *)((char *) current_execute_data->Ts + current_execute_data->opline->result.u.var)).var.ptr;
+ to_return_ptr_ptr = &(*(temp_variable *)((char *) current_execute_data->Ts + current_execute_data->opline->result.u.var)).var.ptr;
#endif
- aop_g(overloaded) = 1;
- _test_func_pointcut_and_execute(NULL,NULL, EG(current_execute_data), current_execute_data->object, EG(scope), EG(called_scope), 0, NULL, to_return_ptr_ptr);
- aop_g(overloaded) = 0;
- // SegFault
- /*
- if (!return_value_used && !(EG(opline_ptr) && ((zend_op *)EG(opline_ptr))->result_type & EXT_TYPE_UNUSED)) {
- zval_ptr_dtor(to_return_ptr_ptr);
- }
- //*/
-}
-
-static void execute_context (zend_execute_data *ex, zval *object, zend_class_entry *calling_scope, zend_class_entry *called_scope, int args_overloaded, zval *args, zval **to_return_ptr_ptr) {
- zval **return_value_ptr;
- zval ***params;
- zend_uint i;
- zval **original_return_value;
- HashTable *calling_symbol_table;
- zend_op_array *original_op_array;
- zend_op **original_opline_ptr;
- zend_class_entry *current_scope;
- zend_class_entry *current_called_scope;
- // zend_class_entry *calling_scope = NULL;
- zval *current_this;
- zend_execute_data *original_execute_data;
- zend_execute_data execute_data;
- zval *original_object;
- HashPosition pos;
- zval ** temp = NULL;
- int arg_count = 0;
- TSRMLS_FETCH();
+ aop_g(overloaded) = 1;
+ _test_func_pointcut_and_execute(NULL,NULL, EG(current_execute_data), current_execute_data->object, EG(scope), EG(called_scope), 0, NULL, to_return_ptr_ptr);
+ aop_g(overloaded) = 0;
+ // SegFault
+ /*
+ if (!return_value_used && !(EG(opline_ptr) && ((zend_op *)EG(opline_ptr))->result_type & EXT_TYPE_UNUSED)) {
+ zval_ptr_dtor(to_return_ptr_ptr);
+ }
+ //*/
+ }
+
+ static void execute_context (zend_execute_data *ex, zval *object, zend_class_entry *calling_scope, zend_class_entry *called_scope, int args_overloaded, zval *args, zval **to_return_ptr_ptr) {
+ zval **return_value_ptr;
+ zval ***params;
+ zend_uint i;
+ zval **original_return_value;
+ HashTable *calling_symbol_table;
+ zend_op_array *original_op_array;
+ zend_op **original_opline_ptr;
+ zend_class_entry *current_scope;
+ zend_class_entry *current_called_scope;
+ // zend_class_entry *calling_scope = NULL;
+ zval *current_this;
+ zend_execute_data *original_execute_data;
+ zend_execute_data execute_data;
+ zval *original_object;
+ HashPosition pos;
+ zval ** temp = NULL;
+ int arg_count = 0;
+ TSRMLS_FETCH();
+
+ if (!EG(active)) {
+ //TODO ERROR
+ return ;
+ }
- if (!EG(active)) {
- //TODO ERROR
- return ;
- }
-
- if (EG(exception)) {
- //TODO ERROR
- return ;
- }
- execute_data = *ex;
-
- //EX(function_state).function = fci_cache->function_handler;
- original_object = EX(object);
- EX(object) = object;
- if (object && Z_TYPE_P(object) == IS_OBJECT &&
- (!EG(objects_store).object_buckets || !EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(object)].valid)) {
- //TODO ERROR
- php_printf("ERRRORR");
- return ;
- }
- original_execute_data = EG(current_execute_data);
- EG(current_execute_data) = ex;
-
- if (args_overloaded) {
- if (args && Z_TYPE_P(args) == IS_ARRAY) {
- args_overloaded = 1;
- arg_count=0;
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(args), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(args), (void **)&temp, &pos) == SUCCESS) {
- arg_count++;
- if (arg_count == 1) {
- params = emalloc(sizeof(zval **));
- } else {
- params = erealloc(params, arg_count*sizeof(zval **));
+ if (EG(exception)) {
+ //TODO ERROR
+ return ;
+ }
+ execute_data = *ex;
+
+ //EX(function_state).function = fci_cache->function_handler;
+ original_object = EX(object);
+ EX(object) = object;
+ if (object && Z_TYPE_P(object) == IS_OBJECT &&
+ (!EG(objects_store).object_buckets || !EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(object)].valid)) {
+ //TODO ERROR
+ php_printf("ERRRORR");
+ return ;
+ }
+ original_execute_data = EG(current_execute_data);
+ EG(current_execute_data) = ex;
+
+ if (args_overloaded) {
+ if (args && Z_TYPE_P(args) == IS_ARRAY) {
+ args_overloaded = 1;
+ arg_count=0;
+ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(args), &pos);
+ while (zend_hash_get_current_data_ex(Z_ARRVAL_P(args), (void **)&temp, &pos) == SUCCESS) {
+ arg_count++;
+ if (arg_count == 1) {
+ params = emalloc(sizeof(zval **));
+ } else {
+ params = erealloc(params, arg_count*sizeof(zval **));
+ }
+ params[arg_count-1] = temp;
+ zend_hash_move_forward_ex(Z_ARRVAL_P(args), &pos);
}
- params[arg_count-1] = temp;
- zend_hash_move_forward_ex(Z_ARRVAL_P(args), &pos);
}
- }
- if (arg_count > 0) {
- //Copy from zend_call_function
- ZEND_VM_STACK_GROW_IF_NEEDED((int) arg_count + 1);
- for (i=0; i < arg_count; i++) {
- zval *param;
- if (ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
- if (!PZVAL_IS_REF(*params[i]) && Z_REFCOUNT_PP(params[i]) > 1) {
- zval *new_zval;
-
- if (!ARG_MAY_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
- if (i || UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == (EG(argument_stack)->top))) {
- zend_vm_stack_push_nocheck((void *) (zend_uintptr_t)i TSRMLS_CC);
- zend_vm_stack_clear_multiple(TSRMLS_C);
+ if (arg_count > 0) {
+ //Copy from zend_call_function
+ ZEND_VM_STACK_GROW_IF_NEEDED((int) arg_count + 1);
+ for (i=0; i < arg_count; i++) {
+ zval *param;
+ if (ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
+ if (!PZVAL_IS_REF(*params[i]) && Z_REFCOUNT_PP(params[i]) > 1) {
+ zval *new_zval;
+
+ if (!ARG_MAY_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
+ if (i || UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == (EG(argument_stack)->top))) {
+ zend_vm_stack_push_nocheck((void *) (zend_uintptr_t)i TSRMLS_CC);
+ zend_vm_stack_clear_multiple(TSRMLS_C);
+ }
+
+ zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
+ i+1,
+ EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
+ EX(function_state).function->common.scope ? "::" : "",
+ EX(function_state).function->common.function_name
+ );
+ return;
}
- zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
- i+1,
- EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
- EX(function_state).function->common.scope ? "::" : "",
- EX(function_state).function->common.function_name
- );
- return;
+ ALLOC_ZVAL(new_zval);
+ *new_zval = **params[i];
+ zval_copy_ctor(new_zval);
+ Z_SET_REFCOUNT_P(new_zval, 1);
+ Z_DELREF_PP(params[i]);
+ *params[i] = new_zval;
}
-
- ALLOC_ZVAL(new_zval);
- *new_zval = **params[i];
- zval_copy_ctor(new_zval);
- Z_SET_REFCOUNT_P(new_zval, 1);
- Z_DELREF_PP(params[i]);
- *params[i] = new_zval;
+ Z_ADDREF_PP(params[i]);
+ Z_SET_ISREF_PP(params[i]);
+ param = *params[i];
+ } else if (PZVAL_IS_REF(*params[i]) && (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) == 0 ) {
+ ALLOC_ZVAL(param);
+ *param = **(params[i]);
+ INIT_PZVAL(param);
+ zval_copy_ctor(param);
+ } else if (*params[i] != &EG(uninitialized_zval)) {
+ Z_ADDREF_PP(params[i]);
+ param = *params[i];
+ } else {
+ ALLOC_ZVAL(param);
+ *param = **(params[i]);
+ INIT_PZVAL(param);
}
- Z_ADDREF_PP(params[i]);
- Z_SET_ISREF_PP(params[i]);
- param = *params[i];
- } else if (PZVAL_IS_REF(*params[i]) && (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) == 0 ) {
- ALLOC_ZVAL(param);
- *param = **(params[i]);
- INIT_PZVAL(param);
- zval_copy_ctor(param);
- } else if (*params[i] != &EG(uninitialized_zval)) {
- Z_ADDREF_PP(params[i]);
- param = *params[i];
- } else {
- ALLOC_ZVAL(param);
- *param = **(params[i]);
- INIT_PZVAL(param);
+ zend_vm_stack_push_nocheck(param TSRMLS_CC);
}
- zend_vm_stack_push_nocheck(param TSRMLS_CC);
+ EG(current_execute_data)->function_state.arguments = zend_vm_stack_top(TSRMLS_C);
+ zend_vm_stack_push_nocheck((void*)(zend_uintptr_t)arg_count TSRMLS_CC);
}
- EG(current_execute_data)->function_state.arguments = zend_vm_stack_top(TSRMLS_C);
- zend_vm_stack_push_nocheck((void*)(zend_uintptr_t)arg_count TSRMLS_CC);
+ } else {
+ arg_count = (int)(zend_uintptr_t) *EX(function_state).arguments;
}
- } else {
- arg_count = (int)(zend_uintptr_t) *EX(function_state).arguments;
- }
-
- current_scope = EG(scope);
- EG(scope) = calling_scope;
- current_this = EG(This);
- current_called_scope = EG(called_scope);
- if (called_scope) {
- EG(called_scope) = called_scope;
- } else if (EX(function_state).function->type != ZEND_INTERNAL_FUNCTION) {
- EG(called_scope) = NULL;
- }
- if (object) {
- if ((EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)) {
- EG(This) = NULL;
- } else {
- EG(This) = object;
+ current_scope = EG(scope);
+ EG(scope) = calling_scope;
+ current_this = EG(This);
+ current_called_scope = EG(called_scope);
+ if (called_scope) {
+ EG(called_scope) = called_scope;
+ } else if (EX(function_state).function->type != ZEND_INTERNAL_FUNCTION) {
+ EG(called_scope) = NULL;
+ }
- if (!PZVAL_IS_REF(EG(This))) {
- Z_ADDREF_P(EG(This));
+ if (object) {
+ if ((EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)) {
+ EG(This) = NULL;
} else {
- zval *this_ptr;
- ALLOC_ZVAL(this_ptr);
- *this_ptr = *EG(This);
- INIT_PZVAL(this_ptr);
- zval_copy_ctor(this_ptr);
- EG(This) = this_ptr;
+ EG(This) = object;
+
+ if (!PZVAL_IS_REF(EG(This))) {
+ Z_ADDREF_P(EG(This));
+ } else {
+ zval *this_ptr;
+ ALLOC_ZVAL(this_ptr);
+ *this_ptr = *EG(This);
+ INIT_PZVAL(this_ptr);
+ zval_copy_ctor(this_ptr);
+ EG(This) = this_ptr;
+ }
}
+ } else {
+ EG(This) = NULL;
}
- } else {
- EG(This) = NULL;
- }
- // EX(prev_execute_data) = EG(current_execute_data);
- if (EX(function_state).function->type == ZEND_USER_FUNCTION) {
- calling_symbol_table = EG(active_symbol_table);
- EG(scope) = EX(function_state).function->common.scope;
+ // EX(prev_execute_data) = EG(current_execute_data);
+ if (EX(function_state).function->type == ZEND_USER_FUNCTION) {
+ calling_symbol_table = EG(active_symbol_table);
+ EG(scope) = EX(function_state).function->common.scope;
- original_return_value = EG(return_value_ptr_ptr);
- original_op_array = EG(active_op_array);
- EG(return_value_ptr_ptr) = to_return_ptr_ptr;
- EG(active_op_array) = (zend_op_array *) EX(function_state).function;
- original_opline_ptr = EG(opline_ptr);
- _zend_execute(EG(active_op_array) TSRMLS_CC);
+ original_return_value = EG(return_value_ptr_ptr);
+ original_op_array = EG(active_op_array);
+ EG(return_value_ptr_ptr) = to_return_ptr_ptr;
+ EG(active_op_array) = (zend_op_array *) EX(function_state).function;
+ original_opline_ptr = EG(opline_ptr);
+ _zend_execute(EG(active_op_array) TSRMLS_CC);
- if (EG(symtable_cache_ptr)>=EG(symtable_cache_limit)) {
- zend_hash_destroy(EG(active_symbol_table));
- FREE_HASHTABLE(EG(active_symbol_table));
- } else {
- /* clean before putting into the cache, since clean
- could call dtors, which could use cached hash */
- if (EG(active_symbol_table)) {
- zend_hash_clean(EG(active_symbol_table));
- *(++EG(symtable_cache_ptr)) = EG(active_symbol_table);
+ if (EG(symtable_cache_ptr)>=EG(symtable_cache_limit)) {
+ zend_hash_destroy(EG(active_symbol_table));
+ FREE_HASHTABLE(EG(active_symbol_table));
+ } else {
+ /* clean before putting into the cache, since clean
+ could call dtors, which could use cached hash */
+ if (EG(active_symbol_table)) {
+ zend_hash_clean(EG(active_symbol_table));
+ *(++EG(symtable_cache_ptr)) = EG(active_symbol_table);
+ }
+ }
+ EG(active_op_array) = original_op_array;
+ EG(return_value_ptr_ptr)=original_return_value;
+ EG(opline_ptr) = original_opline_ptr;
+ EG(active_symbol_table) = calling_symbol_table;
+ } else if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION) {
+ int call_via_handler = (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0;
+ if ((*to_return_ptr_ptr)==NULL) {
+ ALLOC_INIT_ZVAL(*to_return_ptr_ptr);
+ }
+ if (EX(function_state).function->common.scope) {
+ EG(scope) = EX(function_state).function->common.scope;
+ }
+ ((zend_internal_function *) EX(function_state).function)->handler(arg_count, *to_return_ptr_ptr, to_return_ptr_ptr, object, 1 TSRMLS_CC);
+ /* We shouldn't fix bad extensions here,
+ because it can break proper ones (Bug #34045)
+ if (!EX(function_state).function->common.return_reference)
+ {
+ INIT_PZVAL(*fci->retval_ptr_ptr);
+ }*/
+
+ } else { /* ZEND_OVERLOADED_FUNCTION */
+ if ((*to_return_ptr_ptr)==NULL) {
+ ALLOC_INIT_ZVAL(*to_return_ptr_ptr);
+ }
+ if (object) {
+ Z_OBJ_HT_P(object)->call_method(EX(function_state).function->common.function_name, arg_count, *to_return_ptr_ptr, to_return_ptr_ptr, object, 1 TSRMLS_CC);
+ } else {
+ zend_error(E_ERROR, "Cannot call overloaded function for non-object");
}
- }
- EG(active_op_array) = original_op_array;
- EG(return_value_ptr_ptr)=original_return_value;
- EG(opline_ptr) = original_opline_ptr;
- EG(active_symbol_table) = calling_symbol_table;
- } else if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION) {
- int call_via_handler = (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0;
- if ((*to_return_ptr_ptr)==NULL) {
- ALLOC_INIT_ZVAL(*to_return_ptr_ptr);
- }
- if (EX(function_state).function->common.scope) {
- EG(scope) = EX(function_state).function->common.scope;
- }
- ((zend_internal_function *) EX(function_state).function)->handler(arg_count, *to_return_ptr_ptr, to_return_ptr_ptr, object, 1 TSRMLS_CC);
- /* We shouldn't fix bad extensions here,
- because it can break proper ones (Bug #34045)
- if (!EX(function_state).function->common.return_reference)
- {
- INIT_PZVAL(*fci->retval_ptr_ptr);
- }*/
-
- } else { /* ZEND_OVERLOADED_FUNCTION */
- if ((*to_return_ptr_ptr)==NULL) {
- ALLOC_INIT_ZVAL(*to_return_ptr_ptr);
- }
- if (object) {
- Z_OBJ_HT_P(object)->call_method(EX(function_state).function->common.function_name, arg_count, *to_return_ptr_ptr, to_return_ptr_ptr, object, 1 TSRMLS_CC);
- } else {
- zend_error(E_ERROR, "Cannot call overloaded function for non-object");
- }
- if (EX(function_state).function->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
- efree((char*)EX(function_state).function->common.function_name);
- }
- efree(EX(function_state).function);
+ if (EX(function_state).function->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
+ efree((char*)EX(function_state).function->common.function_name);
+ }
+ efree(EX(function_state).function);
- }
+ }
- EG(current_execute_data) = original_execute_data;
- if (args_overloaded) {
- zend_vm_stack_clear_multiple(TSRMLS_C);
- }
+ EG(current_execute_data) = original_execute_data;
+ if (args_overloaded) {
+ zend_vm_stack_clear_multiple(TSRMLS_C);
+ }
- if (EG(This)) {
- zval_ptr_dtor(&EG(This));
+ if (EG(This)) {
+ zval_ptr_dtor(&EG(This));
+ }
+ EG(called_scope) = current_called_scope;
+ EG(scope) = current_scope;
+ EG(This) = current_this;
+ // EG(current_execute_data) = EX(prev_execute_data);
+ EX(object) = original_object;
}
- EG(called_scope) = current_called_scope;
- EG(scope) = current_scope;
- EG(This) = current_this;
- // EG(current_execute_data) = EX(prev_execute_data);
- EX(object) = original_object;
-}
-static int strcmp_with_joker_case(char *str_with_jok, char *str, int case_sensitive) {
- int joker = 0;
- if (str_with_jok[0] == '*') {
- if (str_with_jok[1] == '\0') {
- return 1;
+ static int strcmp_with_joker_case(char *str_with_jok, char *str, int case_sensitive) {
+ int joker = 0;
+ if (str_with_jok[0] == '*') {
+ if (str_with_jok[1] == '\0') {
+ return 1;
+ }
}
- }
- if (str_with_jok[0] == '*') {
- if (case_sensitive) {
- return !strcmp(str_with_jok+1, str+(strlen(str)-(strlen(str_with_jok)-1)));
- } else {
- return !strcasecmp(str_with_jok+1, str+(strlen(str)-(strlen(str_with_jok)-1)));
+ if (str_with_jok[0] == '*') {
+ if (case_sensitive) {
+ return !strcmp(str_with_jok+1, str+(strlen(str)-(strlen(str_with_jok)-1)));
+ } else {
+ return !strcasecmp(str_with_jok+1, str+(strlen(str)-(strlen(str_with_jok)-1)));
+ }
+ }
+ if (str_with_jok[strlen(str_with_jok)-1] == '*') {
+ if (case_sensitive) {
+ return !strncmp(str_with_jok, str, strlen(str_with_jok)-1);
+ } else {
+ return !strncasecmp(str_with_jok, str, strlen(str_with_jok)-1);
+ }
}
- }
- if (str_with_jok[strlen(str_with_jok)-1] == '*') {
if (case_sensitive) {
- return !strncmp(str_with_jok, str, strlen(str_with_jok)-1);
+ return !strcmp(str_with_jok, str);
} else {
- return !strncasecmp(str_with_jok, str, strlen(str_with_jok)-1);
+ return !strcasecmp(str_with_jok, str);
}
}
- if (case_sensitive) {
- return !strcmp(str_with_jok, str);
- } else {
- return !strcasecmp(str_with_jok, str);
- }
-}
-
-static int strcmp_with_joker(char *str_with_jok, char *str) {
- return strcmp_with_joker_case (str_with_jok, str, 0);
-}
-static int is_static (char *str) {
- int i = 0;
- int last = 0;
- char *space;
- char *p_space;
- char *temp;
- space = strchr(str, ' ');
- p_space = str;
- while (space != NULL) {
- if (!strncmp(p_space, "static", space-p_space)) {
- return 1;
- }
- if (!strncmp(p_space, "!static", space-p_space)) {
- return 0;
- }
- temp = space + 1;
- space = strchr(p_space, ' ');
- p_space = temp;
+ static int strcmp_with_joker(char *str_with_jok, char *str) {
+ return strcmp_with_joker_case (str_with_jok, str, 0);
}
- return 2;
-}
-static int explode_scope_by_pipe (char *partial) {
- int i = 0;
- int last = 0;
- int toReturn = 0;
- while (i< (int) strlen(partial)) {
- if (partial[i] == '|') {
- if (!strcmp(estrndup(partial+last, i-last), "public")) {
- toReturn = toReturn | ZEND_ACC_PUBLIC;
- }
- if (!strcmp(estrndup(partial+last, i-last), "private")) {
- toReturn = toReturn | ZEND_ACC_PRIVATE;
+ static int is_static (char *str) {
+ int i = 0;
+ int last = 0;
+ char *space;
+ char *p_space;
+ char *temp;
+ space = strchr(str, ' ');
+ p_space = str;
+ while (space != NULL) {
+ if (!strncmp(p_space, "static", space-p_space)) {
+ return 1;
}
- if (!strcmp(estrndup(partial+last, i-last), "protected")) {
- toReturn = toReturn | ZEND_ACC_PROTECTED;
- }
- if (!strcmp(estrndup(partial+last, i-last), "!public")) {
- toReturn = toReturn | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE;
- }
- if (!strcmp(estrndup(partial+last, i-last), "!private")) {
- toReturn = toReturn | ZEND_ACC_PROTECTED | ZEND_ACC_PUBLIC;
- }
- if (!strcmp(estrndup(partial+last, i-last), "!protected")) {
- toReturn = toReturn | ZEND_ACC_PUBLIC | ZEND_ACC_PRIVATE;
+ if (!strncmp(p_space, "!static", space-p_space)) {
+ return 0;
}
- last = i+1;
+ temp = space + 1;
+ space = strchr(p_space, ' ');
+ p_space = temp;
}
- i++;
- }
- if (!strcmp(estrdup(partial+last), "public")) {
- toReturn = toReturn | ZEND_ACC_PUBLIC;
- }
- if (!strcmp(estrdup(partial+last), "private")) {
- toReturn = toReturn | ZEND_ACC_PRIVATE;
- }
- if (!strcmp(estrdup(partial+last), "protected")) {
- toReturn = toReturn | ZEND_ACC_PROTECTED;
+ return 2;
}
- if (!strcmp(estrdup(partial+last), "!public")) {
- toReturn = toReturn | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE;
- }
- if (!strcmp(estrdup(partial+last), "!private")) {
- toReturn = toReturn | ZEND_ACC_PROTECTED | ZEND_ACC_PUBLIC;
- }
- if (!strcmp(estrdup(partial+last), "!protected")) {
- toReturn = toReturn | ZEND_ACC_PUBLIC | ZEND_ACC_PRIVATE;
- }
- return toReturn;
-}
-static int get_scope (char *str) {
- int i = 0;
- int toReturn = 0;
- char *partial = NULL;
- int last = 0;
- int temp_return;
- while (i < (int) strlen(str)) {
- if (str[i] == ' ') {
- partial = estrndup(str,i);
- temp_return = explode_scope_by_pipe(partial);
- if (temp_return != 0) {
- toReturn |= explode_scope_by_pipe(partial);
+ static int explode_scope_by_pipe (char *partial) {
+ int i = 0;
+ int last = 0;
+ int toReturn = 0;
+ while (i< (int) strlen(partial)) {
+ if (partial[i] == '|') {
+ if (!strcmp(estrndup(partial+last, i-last), "public")) {
+ toReturn = toReturn | ZEND_ACC_PUBLIC;
+ }
+ if (!strcmp(estrndup(partial+last, i-last), "private")) {
+ toReturn = toReturn | ZEND_ACC_PRIVATE;
+ }
+ if (!strcmp(estrndup(partial+last, i-last), "protected")) {
+ toReturn = toReturn | ZEND_ACC_PROTECTED;
+ }
+ if (!strcmp(estrndup(partial+last, i-last), "!public")) {
+ toReturn = toReturn | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE;
+ }
+ if (!strcmp(estrndup(partial+last, i-last), "!private")) {
+ toReturn = toReturn | ZEND_ACC_PROTECTED | ZEND_ACC_PUBLIC;
+ }
+ if (!strcmp(estrndup(partial+last, i-last), "!protected")) {
+ toReturn = toReturn | ZEND_ACC_PUBLIC | ZEND_ACC_PRIVATE;
+ }
+ last = i+1;
}
- last = i;
+ i++;
+ }
+ if (!strcmp(estrdup(partial+last), "public")) {
+ toReturn = toReturn | ZEND_ACC_PUBLIC;
+ }
+ if (!strcmp(estrdup(partial+last), "private")) {
+ toReturn = toReturn | ZEND_ACC_PRIVATE;
+ }
+ if (!strcmp(estrdup(partial+last), "protected")) {
+ toReturn = toReturn | ZEND_ACC_PROTECTED;
+ }
+ if (!strcmp(estrdup(partial+last), "!public")) {
+ toReturn = toReturn | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE;
+ }
+ if (!strcmp(estrdup(partial+last), "!private")) {
+ toReturn = toReturn | ZEND_ACC_PROTECTED | ZEND_ACC_PUBLIC;
}
- i++;
+ if (!strcmp(estrdup(partial+last), "!protected")) {
+ toReturn = toReturn | ZEND_ACC_PUBLIC | ZEND_ACC_PRIVATE;
+ }
+ return toReturn;
+ }
+
+ static int get_scope (char *str) {
+ int i = 0;
+ int toReturn = 0;
+ char *partial = NULL;
+ int last = 0;
+ int temp_return;
+ while (i < (int) strlen(str)) {
+ if (str[i] == ' ') {
+ partial = estrndup(str,i);
+ temp_return = explode_scope_by_pipe(partial);
+ if (temp_return != 0) {
+ toReturn |= explode_scope_by_pipe(partial);
+ }
+ last = i;
+ }
+ i++;
+ }
+ return toReturn;
}
- return toReturn;
-}
-static int pointcut_match_zend_class_entry (pointcut *pc, zend_class_entry *ce) {
- int i, matches;
+ static int pointcut_match_zend_class_entry (pointcut *pc, zend_class_entry *ce) {
+ int i, matches;
- matches = pcre_exec(pc->re_class, NULL, ce->name, strlen(ce->name), 0, 0, NULL, 0);
- if (matches >= 0) {
- return 1;
- }
- for (i = 0; i < (int) ce->num_interfaces; i++) {
- matches = pcre_exec(pc->re_class, NULL, ce->interfaces[i]->name, strlen(ce->interfaces[i]->name), 0, 0, NULL, 0);
+ matches = pcre_exec(pc->re_class, NULL, ce->name, strlen(ce->name), 0, 0, NULL, 0);
if (matches >= 0) {
return 1;
}
- }
+ for (i = 0; i < (int) ce->num_interfaces; i++) {
+ matches = pcre_exec(pc->re_class, NULL, ce->interfaces[i]->name, strlen(ce->interfaces[i]->name), 0, 0, NULL, 0);
+ if (matches >= 0) {
+ return 1;
+ }
+ }
#if ZEND_MODULE_API_NO >= 20100525
- for (i = 0; i < (int) ce->num_traits; i++) {
- matches = pcre_exec(pc->re_class, NULL, ce->traits[i]->name, strlen(ce->traits[i]->name), 0, 0, NULL, 0);
- if (matches>=0) {
- return 1;
+ for (i = 0; i < (int) ce->num_traits; i++) {
+ matches = pcre_exec(pc->re_class, NULL, ce->traits[i]->name, strlen(ce->traits[i]->name), 0, 0, NULL, 0);
+ if (matches>=0) {
+ return 1;
+ }
}
- }
#endif
- ce = ce->parent;
- while (ce != NULL) {
- matches = pcre_exec(pc->re_class, NULL, ce->name, strlen(ce->name), 0, 0, NULL, 0);
- if (matches >= 0) {
- return 1;
- }
ce = ce->parent;
+ while (ce != NULL) {
+ matches = pcre_exec(pc->re_class, NULL, ce->name, strlen(ce->name), 0, 0, NULL, 0);
+ if (matches >= 0) {
+ return 1;
+ }
+ ce = ce->parent;
+ }
+ return 0;
}
- return 0;
-}
-static int pointcut_match_zend_function (pointcut *pc, zend_function *curr_func, zend_execute_data *data) {
- zend_class_entry *ce = NULL;
- TSRMLS_FETCH();
+ static int pointcut_match_zend_function (pointcut *pc, zend_function *curr_func, zend_execute_data *data) {
+ zend_class_entry *ce = NULL;
+ TSRMLS_FETCH();
+
+ if (pc->static_state != 2) {
+ if (pc->static_state) {
+ if (!(curr_func->common.fn_flags & ZEND_ACC_STATIC)) {
+ return 0;
+ }
+ } else {
+ if ((curr_func->common.fn_flags & ZEND_ACC_STATIC)) {
+ return 0;
+ }
+ }
+ }
+ if (pc->scope != 0 && !(pc->scope & (curr_func->common.fn_flags & ZEND_ACC_PPP_MASK))) {
+ return 0;
+ }
+ if (pc->class_name == NULL && pc->method[0] == '*' && pc->method[1]=='\0') {
+ return 1;
+ }
+ if (pc->class_name == NULL && curr_func->common.scope != NULL) {
+ return 0;
+ }
+ if (pc->method_jok) {
+ int matches = pcre_exec(pc->re_method, NULL, curr_func->common.function_name, strlen(curr_func->common.function_name), 0, 0, NULL, 0);
- if (pc->static_state != 2) {
- if (pc->static_state) {
- if (!(curr_func->common.fn_flags & ZEND_ACC_STATIC)) {
+ if (matches < 0) {
return 0;
}
} else {
- if ((curr_func->common.fn_flags & ZEND_ACC_STATIC)) {
+ if (strcasecmp(pc->method, curr_func->common.function_name)) {
return 0;
}
}
- }
- if (pc->scope != 0 && !(pc->scope & (curr_func->common.fn_flags & ZEND_ACC_PPP_MASK))) {
- return 0;
- }
- if (pc->class_name == NULL && pc->method[0] == '*' && pc->method[1]=='\0') {
+ if (data != NULL) {
+ if (curr_func->common.fn_flags & ZEND_ACC_STATIC) {
+ ce = curr_func->common.scope;
+ } else if (data->object != NULL && Z_OBJCE(*data->object) != NULL) {
+ ce = Z_OBJCE(*data->object);
+ }
+ }
return 1;
}
- if (pc->class_name == NULL && curr_func->common.scope != NULL) {
- return 0;
- }
- if (pc->method_jok) {
- int matches = pcre_exec(pc->re_method, NULL, curr_func->common.function_name, strlen(curr_func->common.function_name), 0, 0, NULL, 0);
- if (matches < 0) {
- return 0;
- }
- } else {
- if (strcasecmp(pc->method, curr_func->common.function_name)) {
+ static zval *get_current_args (zend_execute_data *ex TSRMLS_DC) {
+ void **p;
+ int arg_count;
+ int i;
+ zval *return_value;
+ MAKE_STD_ZVAL(return_value);
+ array_init(return_value);
+ if (!ex || !ex->function_state.arguments) {
+ zend_error(E_WARNING, "Problem in AOP getArgs");
return 0;
}
- }
- if (data != NULL) {
- if (curr_func->common.fn_flags & ZEND_ACC_STATIC) {
- ce = curr_func->common.scope;
- } else if (data->object != NULL && Z_OBJCE(*data->object) != NULL) {
- ce = Z_OBJCE(*data->object);
- }
- }
- if (ce != NULL) {
- return pointcut_match_zend_class_entry(pc, ce);
- }
- if (pc->class_name == NULL) {
- return 1;
- }
- return 0;
-}
-static zval *get_current_args (zend_execute_data *ex TSRMLS_DC) {
- void **p;
- int arg_count;
- int i;
- zval *return_value;
- MAKE_STD_ZVAL(return_value);
- array_init(return_value);
- if (!ex || !ex->function_state.arguments) {
- zend_error(E_WARNING, "Problem in AOP getArgs");
- return 0;
- }
+ p = ex->function_state.arguments;
+ arg_count = (int)(zend_uintptr_t) *p;
- p = ex->function_state.arguments;
- arg_count = (int)(zend_uintptr_t) *p;
-
- for (i=0; i < arg_count; i++) {
- zval *element;
- element = *((zval **) (p-(arg_count-i)));
- zend_hash_next_index_insert(return_value->value.ht, &element, sizeof(zval *), NULL);
+ for (i=0; i < arg_count; i++) {
+ zval *element;
+ element = *((zval **) (p-(arg_count-i)));
+ zend_hash_next_index_insert(return_value->value.ht, &element, sizeof(zval *), NULL);
+ }
+ return return_value;
}
- return return_value;
-}
-
-PHP_MSHUTDOWN_FUNCTION(aop)
-{
- UNREGISTER_INI_ENTRIES();
- return SUCCESS;
-}
-
-//Cache on object (zval)
-//pointcut's HashTable
-HashTable *get_object_cache_write (zval *object) //aop_g(object_cache_write)
-{
- return get_object_cache(object, aop_g(object_cache_write), &aop_g(object_cache_write_size));
-}
-HashTable *get_object_cache_read (zval *object) //aop_g(object_cache_read)
-{
- return get_object_cache(object, aop_g(object_cache_read), &aop_g(object_cache_read_size));
-
-}
-HashTable *get_object_cache_func (zval *object)
-{
- return get_object_cache(object, aop_g(object_cache_func), &aop_g(object_cache_func_size));
-
-}
-HashTable *get_object_cache (zval *object, HashTable **ht, int *size)
-{
- int i;
- zend_object_handle handle;
- handle = Z_OBJ_HANDLE_P(object);
- if (handle>=(*size)) {
- ht = erealloc(ht, sizeof (HashTable *)*handle+1);
- for (i = (*size); i <= handle; i++) {
- ht[i] = NULL;
- }
- (*size) = handle+1;
+ PHP_MSHUTDOWN_FUNCTION(aop)
+ {
+ UNREGISTER_INI_ENTRIES();
+ return SUCCESS;
}
- return ht[handle];
-}
-void store_object_cache_write(zval *object, HashTable *cache_ht)
-{
- store_object_cache(object, cache_ht, aop_g(object_cache_write));
-}
-void store_object_cache_read(zval *object, HashTable *cache_ht)
-{
- store_object_cache(object, cache_ht, aop_g(object_cache_read));
-}
-void store_object_cache_func(zval *object, HashTable *cache_ht)
-{
- store_object_cache(object, cache_ht, aop_g(object_cache_func));
-}
-void store_object_cache(zval *object, HashTable *cache_ht, HashTable **ht)
-{
- zend_object_handle handle;
- handle = Z_OBJ_HANDLE_P(object);
- ht[handle] = cache_ht;
-}
+ HashTable *calculate_class_pointcuts (zend_class_entry *ce, int kind_of_advice) {
+ pointcut **pc;
+ HashPosition pos;
+ HashTable *ht;
+ ALLOC_HASHTABLE(ht);
+ //No free because pointcuts are free in the aop_g(pointcuts)
+ zend_hash_init(ht, 16, NULL, NULL ,0);
-// Cache on ZCE
-//pointcut's HashTable
-HashTable *get_zce_cache_write (zend_class_entry ce) //aop_g(zce_cache_write)
-{
+ zend_hash_internal_pointer_reset_ex(aop_g(pointcuts), &pos);
+ while (zend_hash_get_current_data_ex(aop_g(pointcuts), (void **)&pc, &pos) == SUCCESS) {
+ if (!((*pc)->kind_of_advice & kind_of_advice)) {
+ zend_hash_move_forward_ex (aop_g(pointcuts), &pos);
+ } else if (ce==NULL || pointcut_match_zend_class_entry (*pc, ce)) {
+ zend_hash_next_index_insert(ht, pc, sizeof(pointcut **), NULL);
+ zend_hash_move_forward_ex (aop_g(pointcuts), &pos);
+ } else {
+ zend_hash_move_forward_ex (aop_g(pointcuts), &pos);
+ }
+ }
+ return ht;
-}
-HashTable *get_zce_cache_read (zend_class_entry ce) //aop_g(zce_cache_read)
-{
+ }
-}
-HashTable *get_zce_cache_func (zend_class_entry ce) //aop_g(zce_cache_func)
-{
+ HashTable *calculate_function_pointcuts (zval *object, zend_execute_data *ex) {
+ TSRMLS_FETCH();
+ zend_function *curr_func;
+ HashTable *ht = NULL;
+ HashTable *class_pointcuts;
+ HashPosition pos;
+ pointcut **pc;
+ zend_class_entry *ce = NULL;
+ if (object != NULL) {
+ ce = Z_OBJCE_P(object);
+ }
+ if (ex) {
+ curr_func = ex->function_state.function;
+ }
+ ALLOC_HASHTABLE(ht);
+ //No free because pointcuts are free in the aop_g(pointcuts)
+ zend_hash_init(ht, 16, NULL, NULL ,0);
-}
-HashTable *get_zce_cache (zend_class_entry ce, HashTable *ht)
-{
+ class_pointcuts = calculate_class_pointcuts(ce, AOP_KIND_FUNCTION | AOP_KIND_METHOD);
-}
+ zend_hash_internal_pointer_reset_ex(class_pointcuts, &pos);
+ while (zend_hash_get_current_data_ex(class_pointcuts, (void **)&pc, &pos) == SUCCESS) {
+ if (pointcut_match_zend_function((*pc), curr_func, ex)) {
+ zend_hash_next_index_insert (ht, pc, sizeof(pointcut **), NULL);
+ }
+ zend_hash_move_forward_ex (class_pointcuts, &pos);
+ }
-void store_zce_cache_write(zend_class_entry ce, HashTable *cache_ht)
-{
+ zend_hash_destroy(class_pointcuts);
+ FREE_HASHTABLE(class_pointcuts);
-}
-void store_zce_cache_read(zend_class_entry ce, HashTable *cache_ht)
-{
+ return ht;
+ }
+ HashTable *calculate_property_pointcuts (zval *object, zval *member, int kind AOP_KEY_D) {
-}
-void store_zce_cache_func(zend_class_entry ce, HashTable *cache_ht)
-{
+ zval *tmp_member;
+ HashTable *class_pointcuts;
+ HashTable *ht;
+ HashPosition pos;
+ pointcut **pc;
+ TSRMLS_FETCH();
+ ALLOC_HASHTABLE(ht);
+ //No free because pointcuts are free in the aop_g(pointcuts)
+ zend_hash_init(ht, 16, NULL, NULL ,0);
-}
-void store_zce_cache(zend_class_entry ce, HashTable *cache_ht, HashTable *ht)
-{
+ class_pointcuts = calculate_class_pointcuts(Z_OBJCE_P(object), kind);
-}
+ if (Z_TYPE_P(member) != IS_STRING ) {
+ ALLOC_ZVAL(tmp_member);
+ *tmp_member = *member;
+ INIT_PZVAL(tmp_member);
+ zval_copy_ctor(tmp_member);
+ convert_to_string(tmp_member);
+ member = tmp_member;
+#if ZEND_MODULE_API_NO >= 20100525
+ key = NULL;
+#endif
+ }
-HashTable *make_zce_cache(zend_class_entry ce, HashTable *ht)
-{
+ zend_hash_internal_pointer_reset_ex(class_pointcuts, &pos);
+ while (zend_hash_get_current_data_ex(class_pointcuts, (void **)&pc, &pos) == SUCCESS) {
+ if ((*pc)->method[0] != '*') {
+ if (!strcmp_with_joker_case((*pc)->method, Z_STRVAL_P(member), 1)) {
+ zend_hash_move_forward_ex (class_pointcuts, &pos);
+ continue;
+ }
+ }
+ //Scope
+ if ((*pc)->static_state != 2 || (*pc)->scope != 0) {
+ if (!test_property_scope(*pc, Z_OBJCE_P(object), member AOP_KEY_C)) {
+ zend_hash_move_forward_ex (aop_g(pointcuts), &pos);
+ continue;
+ }
+ }
+ zend_hash_next_index_insert(ht, pc, sizeof(pointcut *), NULL);
+ zend_hash_move_forward_ex (aop_g(pointcuts), &pos);
+ }
+ return ht;
-}
+ }
View
42 aop.h
@@ -98,6 +98,11 @@ typedef struct {
pcre *re_class;
} pointcut;
+typedef struct {
+ HashTable *reads;
+ HashTable *writes;
+ HashTable *funcs;
+} object_cache;
typedef struct {
int count;
@@ -170,9 +175,10 @@ int object_cache_read_size;
HashTable **object_cache_func;
int object_cache_func_size;
-HashTable * aop_functions;
zend_bool aop_enable;
+HashTable * pointcuts;
+
ZEND_END_MODULE_GLOBALS(aop)
#ifdef ZTS
@@ -247,8 +253,7 @@ static void (*zend_std_write_property)(zval *object, zval *member, zval *value T
#endif
static zval * (*zend_std_read_property)(zval *object, zval *member, int type AOP_KEY_D TSRMLS_DC);
static zval ** (*zend_std_get_property_ptr_ptr)(zval *object, zval *member AOP_KEY_D TSRMLS_DC);
-static zval * test_read_pointcut_and_execute(int current_pointcut_index, zval *object, zval *member, int type, zend_class_entry *current_scope AOP_KEY_D);
-static void test_write_pointcut_and_execute(int current_pointcut_index, zval *object, zval *member, zval *value, zend_class_entry *current_scope AOP_KEY_D);
+static void _test_write_pointcut_and_execute(HashPosition pos, HashTable *ht, zval *object, zval *member, zval *value, zend_class_entry *current_scope AOP_KEY_D);
static pointcut *aop_add_read (char *selector, zend_fcall_info fci, zend_fcall_info_cache fcic, int type);
static pointcut *aop_add_write (char *selector, zend_fcall_info fci, zend_fcall_info_cache fcic, int type);
static void execute_pointcut (pointcut *pointcut_to_execute, zval *arg);
@@ -257,31 +262,6 @@ static void execute_context (zend_execute_data *ex, zval *object, zend_class_ent
ZEND_DECLARE_MODULE_GLOBALS(aop)
-//Cache on object (zval)
-//pointcut's HashTable
-HashTable *get_object_cache_write (zval *object); //aop_g(object_cache_write)
-HashTable *get_object_cache_read (zval *object); //aop_g(object_cache_read)
-HashTable* get_object_cache_func (zval *object); //aop_g(object_cache_func)
-HashTable *get_object_cache (zval *object, HashTable **ht, int *size);
-
-void store_object_cache_write(zval *object, HashTable *cache_ht);
-void store_object_cache_read(zval *object, HashTable *cache_ht);
-void store_object_cache_func(zval *object, HashTable *cache_ht);
-void store_object_cache(zval *object, HashTable *cache_ht, HashTable **ht);
-
-
-// Cache on ZCE
-//pointcut's HashTable
-HashTable *get_zce_cache_write (zend_class_entry ce); //aop_g(zce_cache_write);
-HashTable *get_zce_cache_read (zend_class_entry ce); //aop_g(zce_cache_read);
-HashTable *get_zce_cache_func (zend_class_entry ce); //aop_g(zce_cache_func);
-HashTable *get_zce_cache (zend_class_entry ce, HashTable *ht);
-
-void store_zce_cache_write(zend_class_entry ce, HashTable *cache_ht);
-void store_zce_cache_read(zend_class_entry ce, HashTable *cache_ht);
-void store_zce_cache_func(zend_class_entry ce, HashTable *cache_ht);
-void store_zce_cache(zend_class_entry ce, HashTable *cache_ht, HashTable *ht);
-
-
-HashTable *make_zce_cache(zend_class_entry ce, HashTable *ht);
-
+HashTable *calculate_function_pointcuts (zval *object, zend_execute_data *ex);
+HashTable *calculate_property_pointcuts (zval *object, zval *member, int kind AOP_KEY_D);
+static zval *_test_read_pointcut_and_execute(HashPosition pos, HashTable *ht, zval *object, zval *member, int type, zend_class_entry *current_scope AOP_KEY_D);
Please sign in to comment.
Something went wrong with that request. Please try again.