diff --git a/php_yaf.h b/php_yaf.h index 1f521de1..8a47cd9c 100644 --- a/php_yaf.h +++ b/php_yaf.h @@ -46,23 +46,23 @@ extern zend_module_entry yaf_module_entry; #define PHP_YAF_VERSION "3.1.4-dev" -#ifndef GC_ADDREF -#define GC_ADDREF(gc) (++GC_REFCOUNT(gc)) -#define GC_DELREF(gc) (--GC_REFCOUNT(gc)) -#endif - #define YAF_STARTUP_FUNCTION(module) ZEND_MINIT_FUNCTION(yaf_##module) #define YAF_RINIT_FUNCTION(module) ZEND_RINIT_FUNCTION(yaf_##module) #define YAF_STARTUP(module) ZEND_MODULE_STARTUP_N(yaf_##module)(INIT_FUNC_ARGS_PASSTHRU) #define YAF_SHUTDOWN_FUNCTION(module) ZEND_MSHUTDOWN_FUNCTION(yaf_##module) #define YAF_SHUTDOWN(module) ZEND_MODULE_SHUTDOWN_N(yaf_##module)(INIT_FUNC_ARGS_PASSTHRU) #define YAF_ME(c, m, a, f) {m, PHP_MN(c), a, (unsigned)(sizeof(a)/sizeof(struct _zend_arg_info)-1), f}, +#define YAF_VAR_FLAGS(v) ((v).u2.next) #if PHP_VERSION_ID < 70400 #define YAF_WRITE_HANDLER void #define YAF_WHANDLER_RET(zv) return #ifndef HT_ALLOW_COW_VIOLATION #define HT_ALLOW_COW_VIOLATION +#if PHP_VERSION_ID < 70300 +#define GC_ADDREF(gc) (++GC_REFCOUNT(gc)) +#define GC_DELREF(gc) (--GC_REFCOUNT(gc)) +#endif #endif #else #define YAF_WRITE_HANDLER zval * @@ -102,7 +102,6 @@ ZEND_BEGIN_MODULE_GLOBALS(yaf) zend_bool lowcase_path; zend_bool use_spl_autoload; zend_bool use_namespace; - zend_bool in_exception; zend_bool throw_exception; zend_bool catch_exception; unsigned int forward_limit; diff --git a/yaf.c b/yaf.c index c5b7ddd2..852b7722 100644 --- a/yaf.c +++ b/yaf.c @@ -341,7 +341,6 @@ PHP_MSHUTDOWN_FUNCTION(yaf) */ PHP_RINIT_FUNCTION(yaf) { - YAF_G(in_exception) = 0; YAF_G(throw_exception) = 1; YAF_G(catch_exception) = 0; diff --git a/yaf_application.c b/yaf_application.c index 5f3fae63..0bfb380d 100644 --- a/yaf_application.c +++ b/yaf_application.c @@ -198,7 +198,7 @@ static HashTable *yaf_application_get_properties(zval *object) /* {{{ */ { ZVAL_STR_COPY(&rv, app->env); zend_hash_str_update(ht, "environ:protected", sizeof("environ:protected") - 1, &rv); - ZVAL_BOOL(&rv, app->flags & YAF_APP_RUNNING); + ZVAL_BOOL(&rv, YAF_APP_FLAGS(app) & YAF_APP_RUNNING); zend_hash_str_update(ht, "running:protected", sizeof("running:protected") - 1, &rv); if (app->err_msg) { @@ -741,18 +741,18 @@ PHP_METHOD(yaf_application, run) { yaf_application_object *app = Z_YAFAPPOBJ_P(getThis()); yaf_response_t *response; - if (UNEXPECTED(app->flags & YAF_APP_RUNNING)) { + if (UNEXPECTED(YAF_APP_FLAGS(app) & YAF_APP_RUNNING)) { yaf_trigger_error(YAF_ERR_STARTUP_FAILED, "Application is already started"); RETURN_FALSE; } - app->flags |= YAF_APP_RUNNING; + YAF_APP_FLAGS(app) |= YAF_APP_RUNNING; if ((response = yaf_dispatcher_dispatch(Z_YAFDISPATCHEROBJ(app->dispatcher))) == NULL) { - app->flags &= ~YAF_APP_RUNNING; + YAF_APP_FLAGS(app) &= ~YAF_APP_RUNNING; RETURN_FALSE; } - app->flags &= ~YAF_APP_RUNNING; + YAF_APP_FLAGS(app) &= ~YAF_APP_RUNNING; RETURN_ZVAL(response, 1, 0); } /* }}} */ diff --git a/yaf_application.h b/yaf_application.h index 357c460a..a3233fe8 100644 --- a/yaf_application.h +++ b/yaf_application.h @@ -17,22 +17,24 @@ #ifndef PHP_YAF_APPLICATION_H #define PHP_YAF_APPLICATION_H +#define YAF_APP_RUNNING (1<<0) +#define YAF_APP_FLAGS(a) YAF_VAR_FLAGS(a->dispatcher) + typedef struct { - zend_uchar flags; - zend_string *default_module; - zend_string *default_controller; - zend_string *default_action; zend_string *library; zend_string *directory; - zend_string *ext; zend_string *bootstrap; - zend_string *view_ext; zend_string *base_uri; zend_array *default_route; - zend_array *modules; + zend_string *default_module; + zend_string *default_controller; + zend_string *default_action; yaf_dispatcher_t dispatcher; yaf_config_t config; + zend_string *ext; + zend_string *view_ext; zend_string *env; + zend_array *modules; unsigned int err_no; zend_string *err_msg; zend_array *properties; @@ -46,8 +48,6 @@ static zend_always_inline yaf_application_object *php_yaf_application_fetch_obje return (yaf_application_object *)((char*)(obj) - XtOffsetOf(yaf_application_object, std)); } -#define YAF_APP_RUNNING (1<<0) - extern zend_class_entry *yaf_application_ce; int yaf_application_is_module_name(zend_string *name); diff --git a/yaf_dispatcher.c b/yaf_dispatcher.c index 86c712b9..f52b041f 100644 --- a/yaf_dispatcher.c +++ b/yaf_dispatcher.c @@ -119,7 +119,7 @@ void yaf_dispatcher_instance(yaf_dispatcher_t *this_ptr) /* {{{ */ { ZVAL_NULL(&dispatcher->request); ZVAL_NULL(&dispatcher->response); ZVAL_NULL(&dispatcher->view); - dispatcher->flags = YAF_DISPATCHER_AUTO_RENDER; + YAF_DISPATCHER_FLAGS(dispatcher) = YAF_DISPATCHER_AUTO_RENDER; dispatcher->plugins = NULL; dispatcher->properties = NULL; @@ -170,11 +170,11 @@ static HashTable *yaf_dispatcher_get_properties(zval *object) /* {{{ */ { ht = dispatcher->properties; - ZVAL_BOOL(&rv, dispatcher->flags & YAF_DISPATCHER_AUTO_RENDER); + ZVAL_BOOL(&rv, YAF_DISPATCHER_FLAGS(dispatcher) & YAF_DISPATCHER_AUTO_RENDER); zend_hash_str_update(ht, "auto_render:protected", sizeof("auto_render:protected") - 1, &rv); - ZVAL_BOOL(&rv, dispatcher->flags & YAF_DISPATCHER_INSTANT_FLUSH); + ZVAL_BOOL(&rv, YAF_DISPATCHER_FLAGS(dispatcher) & YAF_DISPATCHER_INSTANT_FLUSH); zend_hash_str_update(ht, "instant_flush:protected", sizeof("instant_flush:protected") - 1, &rv); - ZVAL_BOOL(&rv, dispatcher->flags & YAF_DISPATCHER_RETURN_RESPONSE); + ZVAL_BOOL(&rv, YAF_DISPATCHER_FLAGS(dispatcher) & YAF_DISPATCHER_RETURN_RESPONSE); zend_hash_str_update(ht, "return_response:protected", sizeof("return_response:protected") - 1, &rv); ZVAL_COPY(&rv, &dispatcher->request); @@ -626,9 +626,9 @@ int yaf_dispatcher_handle(yaf_dispatcher_object *dispatcher) /* {{{ */ { return 0; } - if (yaf_controller_auto_render(ctl, dispatcher->flags & YAF_DISPATCHER_AUTO_RENDER)) { + if (yaf_controller_auto_render(ctl, YAF_DISPATCHER_FLAGS(dispatcher) & YAF_DISPATCHER_AUTO_RENDER)) { zval res; - zend_bool flush_instantly = dispatcher->flags & YAF_DISPATCHER_INSTANT_FLUSH; + zend_bool flush_instantly = YAF_DISPATCHER_FLAGS(dispatcher) & YAF_DISPATCHER_INSTANT_FLUSH; if ((yaf_controller_render(&controller, origin_action, NULL, flush_instantly? NULL : &res))) { if (!flush_instantly) { ZEND_ASSERT(Z_TYPE(res) == IS_STRING); @@ -659,11 +659,11 @@ void yaf_dispatcher_exception_handler(yaf_dispatcher_object *dispatcher) /* {{{ yaf_request_object *request = Z_YAFREQUESTOBJ(dispatcher->request); yaf_response_object *response = Z_YAFRESPONSEOBJ(dispatcher->response); - if (YAF_G(in_exception) || !EG(exception)) { + if ((YAF_DISPATCHER_FLAGS(dispatcher) & YAF_DISPATCHER_IN_EXCEPTION)|| !EG(exception)) { return; } - YAF_G(in_exception) = 1; + YAF_DISPATCHER_FLAGS(dispatcher) |= YAF_DISPATCHER_IN_EXCEPTION; ZVAL_OBJ(&exception, EG(exception)); EG(exception) = NULL; @@ -692,16 +692,15 @@ void yaf_dispatcher_exception_handler(yaf_dispatcher_object *dispatcher) /* {{{ /* failover to uncaught exception */ zend_string_release(exception_str); EG(exception) = Z_OBJ(exception); - YAF_G(in_exception) = 0; + YAF_DISPATCHER_FLAGS(dispatcher) = ~YAF_DISPATCHER_IN_EXCEPTION; return; } yaf_request_set_dispatched(request, 0); if (UNEXPECTED(!yaf_dispatcher_init_view(dispatcher, NULL, NULL))) { - /* ZEND VM report memleak if we don't remove this */ yaf_request_del_param(request, exception_str); zend_string_release(exception_str); - YAF_G(in_exception) = 0; + YAF_DISPATCHER_FLAGS(dispatcher) = ~YAF_DISPATCHER_IN_EXCEPTION; return; } @@ -722,7 +721,7 @@ void yaf_dispatcher_exception_handler(yaf_dispatcher_object *dispatcher) /* {{{ yaf_response_response(&dispatcher->response); EG(opline_before_exception) = opline; - YAF_G(in_exception) = 0; + YAF_DISPATCHER_FLAGS(dispatcher) = ~YAF_DISPATCHER_IN_EXCEPTION; YAF_EXCEPTION_ERASE_EXCEPTION(); } /* }}} */ @@ -796,7 +795,7 @@ yaf_response_t *yaf_dispatcher_dispatch(yaf_dispatcher_object *dispatcher) /* {{ return NULL; } - if (!(dispatcher->flags & YAF_DISPATCHER_RETURN_RESPONSE)) { + if (!(YAF_DISPATCHER_FLAGS(dispatcher) & YAF_DISPATCHER_RETURN_RESPONSE)) { yaf_response_response(&dispatcher->response); yaf_response_clear_body(Z_YAFRESPONSEOBJ(dispatcher->response), NULL); @@ -860,7 +859,7 @@ PHP_METHOD(yaf_dispatcher, disableView) { return; } - dispatcher->flags &= ~YAF_DISPATCHER_AUTO_RENDER; + YAF_DISPATCHER_FLAGS(dispatcher) &= ~YAF_DISPATCHER_AUTO_RENDER; RETURN_ZVAL(getThis(), 1, 0); } @@ -875,7 +874,7 @@ PHP_METHOD(yaf_dispatcher, enableView) { return; } - dispatcher->flags |= YAF_DISPATCHER_AUTO_RENDER; + YAF_DISPATCHER_FLAGS(dispatcher) |= YAF_DISPATCHER_AUTO_RENDER; RETURN_ZVAL(getThis(), 1, 0); } @@ -893,13 +892,13 @@ PHP_METHOD(yaf_dispatcher, returnResponse) { if (ZEND_NUM_ARGS()) { if (return_response) { - dispatcher->flags |= YAF_DISPATCHER_RETURN_RESPONSE; + YAF_DISPATCHER_FLAGS(dispatcher) |= YAF_DISPATCHER_RETURN_RESPONSE; } else { - dispatcher->flags &= ~YAF_DISPATCHER_RETURN_RESPONSE; + YAF_DISPATCHER_FLAGS(dispatcher) &= ~YAF_DISPATCHER_RETURN_RESPONSE; } RETURN_ZVAL(getThis(), 1, 0); } else { - RETURN_BOOL(dispatcher->flags & YAF_DISPATCHER_RETURN_RESPONSE); + RETURN_BOOL(YAF_DISPATCHER_FLAGS(dispatcher) & YAF_DISPATCHER_RETURN_RESPONSE); } } /* }}} */ @@ -916,14 +915,14 @@ PHP_METHOD(yaf_dispatcher, flushInstantly) { if (ZEND_NUM_ARGS()) { if (instantly_flush) { - dispatcher->flags |= YAF_DISPATCHER_INSTANT_FLUSH; + YAF_DISPATCHER_FLAGS(dispatcher) |= YAF_DISPATCHER_INSTANT_FLUSH; } else { - dispatcher->flags &= ~YAF_DISPATCHER_INSTANT_FLUSH; + YAF_DISPATCHER_FLAGS(dispatcher) &= ~YAF_DISPATCHER_INSTANT_FLUSH; } RETURN_ZVAL(getThis(), 1, 0); } else { - RETURN_BOOL(dispatcher->flags & YAF_DISPATCHER_INSTANT_FLUSH); + RETURN_BOOL(YAF_DISPATCHER_FLAGS(dispatcher) & YAF_DISPATCHER_INSTANT_FLUSH); } } /* }}} */ @@ -1085,14 +1084,14 @@ PHP_METHOD(yaf_dispatcher, autoRender) { if (ZEND_NUM_ARGS()) { if (flag) { - dispatcher->flags |= YAF_DISPATCHER_AUTO_RENDER; + YAF_DISPATCHER_FLAGS(dispatcher) |= YAF_DISPATCHER_AUTO_RENDER; } else { - dispatcher->flags &= ~YAF_DISPATCHER_AUTO_RENDER; + YAF_DISPATCHER_FLAGS(dispatcher) &= ~YAF_DISPATCHER_AUTO_RENDER; } RETURN_ZVAL(getThis(), 1, 0); } else { - RETURN_BOOL(dispatcher->flags & YAF_DISPATCHER_AUTO_RENDER); + RETURN_BOOL(YAF_DISPATCHER_FLAGS(dispatcher) & YAF_DISPATCHER_AUTO_RENDER); } } /* }}} */ diff --git a/yaf_dispatcher.h b/yaf_dispatcher.h index 82135073..1a4643e1 100644 --- a/yaf_dispatcher.h +++ b/yaf_dispatcher.h @@ -33,9 +33,11 @@ extern zend_class_entry *yaf_dispatcher_ce; #define YAF_DISPATCHER_AUTO_RENDER (1<<0) #define YAF_DISPATCHER_INSTANT_FLUSH (1<<1) #define YAF_DISPATCHER_RETURN_RESPONSE (1<<2) +#define YAF_DISPATCHER_IN_EXCEPTION (1<<7) + +#define YAF_DISPATCHER_FLAGS(d) YAF_VAR_FLAGS((d)->request) typedef struct { - zend_uchar flags; yaf_request_t request; yaf_response_t response; yaf_router_t router;