Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashes with multimodule applications #1982

Merged
merged 4 commits into from Feb 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions ext/cli/router.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ PHALCON_INIT_CLASS(Phalcon_CLI_Router){
*/
PHP_METHOD(Phalcon_CLI_Router, __construct){


phalcon_update_property_empty_array(phalcon_cli_router_ce, this_ptr, SL("_params") TSRMLS_CC);

phalcon_update_property_empty_array(phalcon_cli_router_ce, this_ptr, SL("_defaultParams") TSRMLS_CC);

phalcon_update_property_empty_array(this_ptr, SL("_params") TSRMLS_CC);
phalcon_update_property_empty_array(this_ptr, SL("_defaultParams") TSRMLS_CC);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions ext/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ PHALCON_INIT_CLASS(Phalcon_Dispatcher){
*/
PHP_METHOD(Phalcon_Dispatcher, __construct){


phalcon_update_property_empty_array(phalcon_dispatcher_ce, this_ptr, SL("_params") TSRMLS_CC);

phalcon_update_property_empty_array(this_ptr, SL("_params") TSRMLS_CC);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ext/kernel/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ int phalcon_update_property_array_append(zval *object, char *property, unsigned
/**
* Intializes an object property with an empty array
*/
int phalcon_update_property_empty_array(zend_class_entry *ce, zval *object, char *property_name, unsigned int property_length TSRMLS_DC) {
int phalcon_update_property_empty_array(zval *object, char *property_name, unsigned int property_length TSRMLS_DC) {

zval *empty_array;
int res;
Expand Down
2 changes: 1 addition & 1 deletion ext/kernel/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int phalcon_update_property_bool(zval *obj, char *property_name, unsigned int pr
int phalcon_update_property_null(zval *obj, char *property_name, unsigned int property_length TSRMLS_DC);
int phalcon_update_property_zval(zval *obj, char *property_name, unsigned int property_length, zval *value TSRMLS_DC);
int phalcon_update_property_zval_zval(zval *obj, zval *property, zval *value TSRMLS_DC);
int phalcon_update_property_empty_array(zend_class_entry *ce, zval *object, char *property, unsigned int property_length TSRMLS_DC);
int phalcon_update_property_empty_array(zval *object, char *property, unsigned int property_length TSRMLS_DC);

/** Updating array properties */
int phalcon_update_property_array(zval *object, char *property, unsigned int property_length, zval *index, zval *value TSRMLS_DC);
Expand Down
4 changes: 3 additions & 1 deletion ext/kernel/require.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ int phalcon_require_ret(zval **return_value_ptr, const char *require_path TSRMLS
return ret;
}
}
else {
zend_destroy_file_handle(&file_handle TSRMLS_CC);
}

zend_destroy_file_handle(&file_handle TSRMLS_CC);
return FAILURE;
}
134 changes: 61 additions & 73 deletions ext/mvc/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "mvc/viewinterface.h"
#include "di/injectable.h"
#include "diinterface.h"
#include "events/managerinterface.h"
#include "http/responseinterface.h"

#include <Zend/zend_closures.h>
Expand Down Expand Up @@ -269,6 +270,26 @@ PHP_METHOD(Phalcon_Mvc_Application, getDefaultModule){
RETURN_MEMBER(this_ptr, "_defaultModule");
}

static int phalcon_mvc_application_fire_event(zval *mgr, const char *event, zval *this_ptr, zval *params TSRMLS_DC)
{
if (mgr) {
zval *event_name;
zval *status = NULL;
uint params_cnt = 2 + (params != NULL ? 1 : 0);

PHALCON_ALLOC_GHOST_ZVAL(event_name);
ZVAL_STRING(event_name, event, 1);

if (FAILURE == phalcon_call_method_params(status, &status, mgr, SL("fire"), zend_inline_hash_func(SS("fire")) TSRMLS_CC, params_cnt, event_name, this_ptr, params)) {
return FAILURE;
}

return (Z_TYPE_P(status) == IS_BOOL && !Z_BVAL_P(status)) ? FAILURE : SUCCESS;
}

return SUCCESS;
}

/**
* Handles a MVC request
*
Expand All @@ -278,14 +299,14 @@ PHP_METHOD(Phalcon_Mvc_Application, getDefaultModule){
PHP_METHOD(Phalcon_Mvc_Application, handle){

zval *uri = NULL, *dependency_injector, *events_manager;
zval *event_name = NULL, *status = NULL, *service = NULL, *router, *module_name = NULL;
zval *status = NULL, *service = NULL, *router, *module_name = NULL;
zval *module_object = NULL, *modules;
zval *module, *class_name = NULL, *module_params;
zval *implicit_view, *view, *namespace_name;
zval *controller_name = NULL, *action_name = NULL, *params = NULL;
zval *dispatcher, *controller, *returned_response = NULL;
zval *possible_response, *render_status = NULL, *response = NULL;
zval *content;
zval *content, *path;
int f_implicit_view;

PHALCON_MM_GROW();
Expand All @@ -303,20 +324,16 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
}

events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC);

/**
* Call boot event, this allow the developer to perform initialization actions
*/
if (Z_TYPE_P(events_manager) == IS_OBJECT) {

PHALCON_INIT_VAR(event_name);
ZVAL_STRING(event_name, "application:boot", 1);

PHALCON_INIT_VAR(status);
phalcon_call_method_p2(status, events_manager, "fire", event_name, this_ptr);
if (PHALCON_IS_FALSE(status)) {
RETURN_MM_FALSE;
}
if (Z_TYPE_P(events_manager) != IS_OBJECT) {
events_manager = NULL;
}
else {
PHALCON_VERIFY_INTERFACE_EX(events_manager, phalcon_events_managerinterface_ce, phalcon_mvc_application_exception_ce, 1);
}

/* Call boot event, this allows the developer to perform initialization actions */
if (FAILURE == phalcon_mvc_application_fire_event(events_manager, "application:boot", getThis(), NULL TSRMLS_CC)) {
RETURN_MM_FALSE;
}

PHALCON_INIT_VAR(service);
Expand Down Expand Up @@ -349,18 +366,10 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
* Process the module definition
*/
if (zend_is_true(module_name)) {
if (Z_TYPE_P(events_manager) == IS_OBJECT) {

PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "application:beforeStartModule", 1);

PHALCON_INIT_NVAR(status);
phalcon_call_method_p3(status, events_manager, "fire", event_name, this_ptr, module_name);
if (PHALCON_IS_FALSE(status)) {
RETURN_MM_FALSE;
}
if (FAILURE == phalcon_mvc_application_fire_event(events_manager, "application:beforeStartModule", getThis(), module_name TSRMLS_CC)) {
RETURN_MM_FALSE;
}

/**
* Check if the module passed by the router is registered in the modules container
*/
Expand All @@ -373,7 +382,7 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
}

/**
* A module definition must ne an array or an object
* A module definition must be an array or an object
*/
if (Z_TYPE_P(module) != IS_ARRAY && Z_TYPE_P(module) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "Invalid module definition");
Expand All @@ -386,8 +395,6 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
* An array module definition contains a path to a module definition class
*/
if (Z_TYPE_P(module) == IS_ARRAY) {
zval *path;

/**
* Class name used to load the module definition
*/
Expand Down Expand Up @@ -437,18 +444,10 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
return;
}

/**
* Calling afterStartModule event
*/
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
/* Calling afterStartModule event */
if (events_manager) {
phalcon_update_property_this(this_ptr, SL("_moduleObject"), module_object TSRMLS_CC);

PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "application:afterStartModule", 1);

PHALCON_INIT_NVAR(status);
phalcon_call_method_p3(status, events_manager, "fire", event_name, this_ptr, module_name);
if (PHALCON_IS_FALSE(status)) {
if (FAILURE == phalcon_mvc_application_fire_event(events_manager, "application:afterStartModule", getThis(), module_name TSRMLS_CC)) {
RETURN_MM_FALSE;
}
}
Expand Down Expand Up @@ -516,19 +515,9 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
phalcon_call_method_noret(view, "start");
}

/**
* Calling beforeHandleRequest
*/
if (Z_TYPE_P(events_manager) == IS_OBJECT) {

PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "application:beforeHandleRequest", 1);

PHALCON_INIT_NVAR(status);
phalcon_call_method_p3(status, events_manager, "fire", event_name, this_ptr, dispatcher);
if (PHALCON_IS_FALSE(status)) {
RETURN_MM_FALSE;
}
/* Calling beforeHandleRequest */
if (FAILURE == phalcon_mvc_application_fire_event(events_manager, "application:beforeHandleRequest", getThis(), dispatcher TSRMLS_CC)) {
RETURN_MM_FALSE;
}

/**
Expand All @@ -554,13 +543,9 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
ZVAL_FALSE(returned_response);
}

/**
* Calling afterHandleRequest
*/
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "application:afterHandleRequest", 1);
phalcon_call_method_p3_noret(events_manager, "fire", event_name, this_ptr, controller);
/* Calling afterHandleRequest */
if (FAILURE == phalcon_mvc_application_fire_event(events_manager, "application:afterHandleRequest", getThis(), controller TSRMLS_CC) && EG(exception)) {
RETURN_MM();
}

/**
Expand All @@ -577,11 +562,17 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
/**
* This allows to make a custom view render
*/
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "application:viewRender", 1);

phalcon_call_method_p3(render_status, events_manager, "fire", event_name, this_ptr, view);
if (events_manager) {
if (FAILURE == phalcon_mvc_application_fire_event(events_manager, "application:viewRender", getThis(), view TSRMLS_CC)) {
if (EG(exception)) {
RETURN_MM();
}

ZVAL_FALSE(render_status);
}
else {
ZVAL_TRUE(render_status);
}
}
else {
ZVAL_TRUE(render_status);
Expand Down Expand Up @@ -639,13 +630,10 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
PHALCON_CPY_WRT(response, possible_response);
}

/**
* Calling beforeSendResponse
*/
if (Z_TYPE_P(events_manager) == IS_OBJECT) {
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "application:beforeSendResponse", 1);
phalcon_call_method_p3_noret(events_manager, "fire", event_name, this_ptr, response);

/* Calling beforeSendResponse */
if (FAILURE == phalcon_mvc_application_fire_event(events_manager, "application:beforeSendResponse", getThis(), response TSRMLS_CC) && EG(exception)) {
RETURN_MM();
}

/**
Expand Down
26 changes: 12 additions & 14 deletions ext/mvc/router.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Router){
*/
PHP_METHOD(Phalcon_Mvc_Router, __construct){

zval *default_routes = NULL, *routes, *routes_name_lookup, *paths = NULL, *action_pattern;
zval *route = NULL, *params_pattern, *params;
zval *default_routes = NULL, *routes, *paths = NULL, *action_pattern;
zval *route = NULL, *params_pattern;

PHALCON_MM_GROW();

phalcon_update_property_empty_array(phalcon_mvc_router_ce, this_ptr, SL("_defaultParams") TSRMLS_CC);
phalcon_update_property_empty_array(this_ptr, SL("_defaultParams") TSRMLS_CC);

phalcon_fetch_params(1, 0, 1, &default_routes);

Expand Down Expand Up @@ -267,13 +267,9 @@ PHP_METHOD(Phalcon_Mvc_Router, __construct){
phalcon_array_append(&routes, route, 0);
}

PHALCON_INIT_VAR(params);
array_init(params);
PHALCON_INIT_VAR(routes_name_lookup);
array_init(routes_name_lookup);
phalcon_update_property_this(this_ptr, SL("_params"), params TSRMLS_CC);
phalcon_update_property_empty_array(this_ptr, SL("_params") TSRMLS_CC);
phalcon_update_property_this(this_ptr, SL("_routes"), routes TSRMLS_CC);
phalcon_update_property_this(this_ptr, SL("_routesNameLookup"), routes_name_lookup TSRMLS_CC);
phalcon_update_property_empty_array(this_ptr, SL("_routesNameLookup") TSRMLS_CC);

PHALCON_MM_RESTORE();
}
Expand Down Expand Up @@ -321,7 +317,7 @@ PHP_METHOD(Phalcon_Mvc_Router, getRewriteUri){
/**
* By default we use $_GET['url'] to obtain the rewrite information
*/
if (!zend_is_true(uri_source)) {
if (!zend_is_true(uri_source)) { /* FIXME: Compare with URI_SOURCE_SERVER_REQUEST_URI */
_GET = phalcon_get_global(SS("_GET") TSRMLS_CC);
if (phalcon_array_isset_string_fetch(&url, _GET, SS("_url"))) {
if (PHALCON_IS_NOT_EMPTY(url)) {
Expand Down Expand Up @@ -357,7 +353,7 @@ PHP_METHOD(Phalcon_Mvc_Router, getRewriteUri){
* $router->setUriSource(Router::URI_SOURCE_SERVER_REQUEST_URI);
*</code>
*
* @param string $uriSource
* @param int $uriSource
* @return Phalcon\Mvc\Router
*/
PHP_METHOD(Phalcon_Mvc_Router, setUriSource){
Expand Down Expand Up @@ -545,7 +541,7 @@ PHP_METHOD(Phalcon_Mvc_Router, setDefaults){
}

/**
* Returns an array of default paths
* Returns an array of default parameters
*
* @return array
*/
Expand Down Expand Up @@ -727,13 +723,15 @@ PHP_METHOD(Phalcon_Mvc_Router, handle){
if (phalcon_memnstr_str(hostname, SL("("))) {
if (!phalcon_memnstr_str(hostname, SL("#"))) {
PHALCON_INIT_NVAR(regex_host_name);
/* FIXME: handle mixed case */
PHALCON_CONCAT_SVS(regex_host_name, "#^", hostname, "$#");
} else {
PHALCON_CPY_WRT(regex_host_name, hostname);
}

RETURN_MM_ON_FAILURE(phalcon_preg_match(matched, regex_host_name, current_host_name, NULL TSRMLS_CC));
} else {
/* FIXME: handle mixed case */
is_equal_function(matched, current_host_name, hostname TSRMLS_CC);
}

Expand Down Expand Up @@ -1221,7 +1219,7 @@ PHP_METHOD(Phalcon_Mvc_Router, mount){
/**
* Set a group of paths to be returned when none of the defined routes are matched
*
* @param array $paths
* @param array|string $paths
* @return Phalcon\Mvc\Router
*/
PHP_METHOD(Phalcon_Mvc_Router, notFound){
Expand Down Expand Up @@ -1361,7 +1359,7 @@ PHP_METHOD(Phalcon_Mvc_Router, getRoutes){
* Returns a route object by its id
*
* @param string $id
* @return Phalcon\Mvc\Router\Route
* @return Phalcon\Mvc\Router\Route | false
*/
PHP_METHOD(Phalcon_Mvc_Router, getRouteById){

Expand Down
2 changes: 1 addition & 1 deletion ext/mvc/router/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Router_Route){
zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_beforeMatch"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_group"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_uniqueId"), ZEND_ACC_STATIC|ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_long(phalcon_mvc_router_route_ce, SL("_uniqueId"), 0, ZEND_ACC_STATIC|ZEND_ACC_PROTECTED TSRMLS_CC);

zend_class_implements(phalcon_mvc_router_route_ce TSRMLS_CC, 1, phalcon_mvc_router_routeinterface_ce);

Expand Down
Loading