Permalink
Browse files

split files

  • Loading branch information...
1 parent 91604ce commit 492cf12cae14c1c380c3e8d919bd54f8290ae25e @Juliens Juliens committed Dec 11, 2012
Showing with 298 additions and 247 deletions.
  1. +5 −228 aop.c
  2. +3 −18 aop.h
  3. +252 −0 aop_joinpoint.c
  4. +37 −0 aop_joinpoint.h
  5. +1 −1 config.m4
View
233 aop.c
@@ -23,6 +23,7 @@
#include "ext/standard/php_string.h"
#include "ext/pcre/php_pcre.h"
#include "Lexer.h"
+#include "aop_joinpoint.h"
#include "aop.h"
#include "Zend/zend_operators.h"
@@ -265,7 +266,7 @@ ZEND_DLEXPORT zval * zend_std_read_property_overload(zval *object, zval *member,
}
-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) {
+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;
TSRMLS_FETCH();
AopJoinpoint_object *obj;
@@ -347,7 +348,7 @@ static void _test_func_pointcut_and_execute(HashPosition pos, HashTable *ht, zen
return;
}
-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 *_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;
@@ -406,7 +407,7 @@ static zval *_test_read_pointcut_and_execute(HashPosition pos, HashTable *ht, zv
return to_return;
}
-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) {
+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;
@@ -589,230 +590,6 @@ PHP_MINIT_FUNCTION(aop)
return SUCCESS;
}
-PHP_METHOD(AopJoinpoint, getPropertyName){
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!(obj->current_pointcut->kind_of_advice & AOP_KIND_PROPERTY)) {
- zend_error(E_ERROR, "getPropertyName is only available when the JoinPoint is a property operation (read or write)");
- }
- if (obj->member != NULL) {
- RETURN_ZVAL(obj->member, 1, 0);
- return;
- }
- RETURN_NULL();
-}
-PHP_METHOD(AopJoinpoint, getArguments){
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- if (obj->current_pointcut->kind_of_advice & AOP_KIND_PROPERTY) {
- zend_error(E_ERROR, "getArguments is only available when the JoinPoint is a function or method call");
- }
- if (obj->args == NULL) {
- obj->args = get_current_args(obj->ex TSRMLS_CC);
- }
- if (obj->args != NULL) {
- RETURN_ZVAL(obj->args, 1, 0);
- }
- RETURN_NULL();
-}
-
-PHP_METHOD(AopJoinpoint, setArguments){
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *params;
- if (obj->current_pointcut->kind_of_advice & AOP_KIND_PROPERTY) {
- zend_error(E_ERROR, "setArguments is only available when the JoinPoint is a function or ia method call");
- }
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &params) == FAILURE) {
- zend_error(E_ERROR, "setArguments expects an array as its first argument");
- return;
- }
- obj->args = params;
- obj->args_overloaded = 1;
- Z_ADDREF_P(params);
- RETURN_NULL();
-}
-
-PHP_METHOD(AopJoinpoint, getKindOfAdvice){
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- RETURN_LONG(obj->kind_of_advice);
-}
-
-PHP_METHOD(AopJoinpoint, getPointcut){
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- RETURN_STRING(obj->current_pointcut->selector, 1);
-
-}
-
-PHP_METHOD(AopJoinpoint, getReturnedValue){
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- if (obj->current_pointcut->kind_of_advice & AOP_KIND_PROPERTY) {
- zend_error(E_ERROR, "getReturnedValue is not available when the JoinPoint is a property operation (read or write)");
- }
- if (obj->current_pointcut->kind_of_advice & AOP_KIND_BEFORE) {
- zend_error(E_ERROR, "getReturnedValue is not available when the advice was added with aop_add_before");
- }
- if ((*obj->to_return_ptr_ptr) != NULL) {
- zval_ptr_dtor (return_value_ptr);
- (*return_value_ptr) = (*obj->to_return_ptr_ptr);
- Z_ADDREF_P(*obj->to_return_ptr_ptr);
- }
- // RETURN_NULL();
-}
-
-PHP_METHOD(AopJoinpoint, getAssignedValue){
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!(obj->kind_of_advice & AOP_KIND_WRITE)) {
- zend_error(E_ERROR, "getAssignedValue is only available when the JoinPoint is a property write operation");
- }
- if (obj->value != NULL) {
- zval_ptr_dtor (return_value_ptr);
- *return_value_ptr = obj->value;
- Z_ADDREF_P(obj->value);
- } else {
- RETURN_NULL();
- }
-}
-
-PHP_METHOD(AopJoinpoint, setAssignedValue){
- zval *ret;
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- if (obj->kind_of_advice & AOP_KIND_READ) {
- zend_error(E_ERROR, "setAssignedValue is not available when the JoinPoint is a property read operation");
- }
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &ret) == FAILURE) {
- zend_error(E_ERROR, "Error");
- return;
- }
- obj->value = ret;
- Z_ADDREF_P(ret);
- RETURN_NULL();
-}
-
-PHP_METHOD(AopJoinpoint, setReturnedValue){
- zval *ret;
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- if (obj->kind_of_advice & AOP_KIND_WRITE) {
- zend_error(E_ERROR, "setReturnedValue is not available when the JoinPoint is a property write operation");
- }
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &ret) == FAILURE) {
- zend_error(E_ERROR, "Error");
- return;
- }
-
- obj->value = ret;
- Z_ADDREF_P(ret);
- RETURN_NULL();
-}
-
-PHP_METHOD(AopJoinpoint, getObject) {
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- if (obj->object != NULL) {
- RETURN_ZVAL(obj->object, 1, 0);
- }
- RETURN_NULL();
-
-}
-
-PHP_METHOD(AopJoinpoint, getClassName){
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- if (obj->current_pointcut->kind_of_advice & AOP_KIND_PROPERTY) {
- if (obj->object != NULL) {
- zend_class_entry *ce = Z_OBJCE_P(obj->object);
- RETURN_STRING(ce->name, 1);
- }
- } else {
- zend_class_entry *ce;
- zend_execute_data *data = obj->ex;
- zend_function *curr_func;
- if (data == NULL) {
- RETURN_NULL();
- }
- curr_func = data->function_state.function;
- ce = curr_func->common.scope;
- if (ce != NULL) {
- RETURN_STRING(ce->name, 1);
- }
- }
- RETURN_NULL();
-}
-
-PHP_METHOD(AopJoinpoint, getFunctionName){
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- zend_execute_data *data = obj->ex;
- zend_function *curr_func;
- if (obj->current_pointcut->kind_of_advice & AOP_KIND_PROPERTY || obj->current_pointcut->kind_of_advice & AOP_KIND_METHOD) {
- zend_error(E_ERROR, "getMethodName is only available when the JoinPoint is a function call");
- }
- if (data == NULL) {
- RETURN_NULL();
- }
- curr_func = data->function_state.function;
- RETURN_STRING(curr_func->common.function_name, 1);
-}
-
-PHP_METHOD(AopJoinpoint, getException){
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!(obj->current_pointcut->kind_of_advice & AOP_KIND_CATCH)){
- zend_error(E_ERROR, "getException is only available when the advice was added with aop_add_after or aop_add_after_throwing");
- }
- if (obj->exception != NULL) {
- RETURN_ZVAL(obj->exception, 1, 0);
- }
- RETURN_NULL();
-}
-
-
-
-PHP_METHOD(AopJoinpoint, getMethodName){
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- zend_execute_data *data = obj->ex;
- zend_function *curr_func;
- if (obj->current_pointcut->kind_of_advice & AOP_KIND_PROPERTY || obj->current_pointcut->kind_of_advice & AOP_KIND_FUNCTION) {
- zend_error(E_ERROR, "getMethodName is only available when the JoinPoint is a method call");
- }
- if (data == NULL) {
- RETURN_NULL();
- }
- curr_func = data->function_state.function;
- RETURN_STRING(curr_func->common.function_name, 1);
-}
-
-PHP_METHOD(AopJoinpoint, process){
- AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj || !obj->current_pointcut || !obj->current_pointcut->kind_of_advice) {
- zend_error(E_ERROR, "Error");
- }
- if (!(obj->current_pointcut->kind_of_advice & AOP_KIND_AROUND)) {
- zend_error(E_ERROR, "process is only available when the advice was added with aop_add_around");
- }
- if (obj->current_pointcut->kind_of_advice & AOP_KIND_PROPERTY) {
- if (obj->kind_of_advice & AOP_KIND_WRITE) {
-#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
- _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->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);
- obj->value = (*obj->to_return_ptr_ptr);
- if (!EG(exception)) {
- if ((*obj->to_return_ptr_ptr) != NULL) {
- RETURN_ZVAL((*obj->to_return_ptr_ptr), 1, 0);
- } else {
- RETURN_NULL();
- }
- } else {
- RETURN_NULL();
- }
- }
-}
@@ -1514,7 +1291,7 @@ void aop_execute_internal (zend_execute_data *current_execute_data, int return_v
return 1;
}
- static zval *get_current_args (zend_execute_data *ex TSRMLS_DC) {
+ zval *get_current_args (zend_execute_data *ex TSRMLS_DC) {
void **p;
int arg_count;
int i;
View
21 aop.h
@@ -188,21 +188,6 @@ PHP_FUNCTION(aop_add_after);
PHP_FUNCTION(aop_add_after_returning);
PHP_FUNCTION(aop_add_after_throwing);
-PHP_METHOD(AopJoinpoint, getArguments);
-PHP_METHOD(AopJoinpoint, getPropertyName);
-PHP_METHOD(AopJoinpoint, setArguments);
-PHP_METHOD(AopJoinpoint, getKindOfAdvice);
-PHP_METHOD(AopJoinpoint, getReturnedValue);
-PHP_METHOD(AopJoinpoint, getAssignedValue);
-PHP_METHOD(AopJoinpoint, setReturnedValue);
-PHP_METHOD(AopJoinpoint, setAssignedValue);
-PHP_METHOD(AopJoinpoint, getPointcut);
-PHP_METHOD(AopJoinpoint, getObject);
-PHP_METHOD(AopJoinpoint, getClassName);
-PHP_METHOD(AopJoinpoint, getMethodName);
-PHP_METHOD(AopJoinpoint, getFunctionName);
-PHP_METHOD(AopJoinpoint, getException);
-PHP_METHOD(AopJoinpoint, process);
extern zend_module_entry aop_module_entry;
#define phpext_aop_ptr &aop_module_entry
@@ -222,7 +207,7 @@ ZEND_DLEXPORT void aop_execute_internal (zend_execute_data *current_execute_data
#else
ZEND_DLEXPORT void aop_execute_internal (zend_execute_data *current_execute_data, struct _zend_fcall_info *fci, int return_value_used TSRMLS_DC);
#endif
-static zval *get_current_args (zend_execute_data *ex TSRMLS_DC);
+zval *get_current_args (zend_execute_data *ex TSRMLS_DC);
static int strcmp_with_joker (char *str_with_jok, char *str);
static int strcmp_with_joker_case (char *str_with_jok, char *str, int case_sensitive);
@@ -233,15 +218,15 @@ 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 void _test_write_pointcut_and_execute(HashPosition pos, HashTable *ht, zval *object, zval *member, zval *value, zend_class_entry *current_scope AOP_KEY_D);
+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 void execute_pointcut (pointcut *pointcut_to_execute, zval *arg);
static int test_property_scope (pointcut *current_pc, zend_class_entry *ce, zval *member AOP_KEY_D);
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);
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);
+zval *_test_read_pointcut_and_execute(HashPosition pos, HashTable *ht, zval *object, zval *member, int type, zend_class_entry *current_scope AOP_KEY_D);
void make_regexp_on_pointcut (pointcut **pc);
ZEND_DECLARE_MODULE_GLOBALS(aop)
Oops, something went wrong.

0 comments on commit 492cf12

Please sign in to comment.