Skip to content

Commit

Permalink
Fixed issue laruence#163 (forward from init controller)
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Nov 24, 2015
1 parent b867200 commit 18125c0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
<file name="bug62702.phpt" role="test" />
<file name="bug70913.phpt" role="test" />
<file name="issue134.phpt" role="test" />
<file name="issue163.phpt" role="test" />
<file name="simple.ini" role="test" />
<file name="system.ini" role="test" />
<file name="multi-section.ini" role="test" />
Expand Down
57 changes: 57 additions & 0 deletions tests/issue163.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--TEST--
Bug #70913 (Segfault while new Yaf_Controller)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=1
yaf.lowcase_path=0
yaf.throw_exception=0
yaf.catch_exception=1
yaf.use_namespace=0
--FILE--
<?php
require "build.inc";
startup();

$config = array(
"application" => array(
"directory" => APPLICATION_PATH,
),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
class IndexController extends Yaf_Controller_Abstract {
public function init() {
\$this->forward("index", "Second", "okey");
}
public function indexAction() {
echo "bad";
}
}
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Second.php", <<<PHP
<?php
class SecondController extends Yaf_Controller_Abstract {
public function okeyAction() {
echo "Okey";
return FALSE;
}
}
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "Okey");

$app = new Yaf_Application($config);
$response = $app->run();
?>
--CLEAN--
<?php
require "build.inc";
shutdown();
?>
--EXPECT--
Okey
30 changes: 18 additions & 12 deletions yaf_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,6 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request,

module = zend_read_property(request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_MODULE), 1 TSRMLS_CC);
controller = zend_read_property(request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_CONTROLLER), 1 TSRMLS_CC);

dmodule = zend_read_property(yaf_dispatcher_ce, dispatcher, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_MODULE), 1 TSRMLS_CC);
/*
dcontroller = zend_read_property(yaf_dispatcher_ce, dispatcher, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_CONTROLLER), 1 TSRMLS_CC);
Expand Down Expand Up @@ -585,22 +584,29 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request,

/* cause controller's constructor is a final method, so it must be a internal function
do {
zend_function *constructor = NULL;
constructor = Z_OBJ_HT_P(exec_ctr)->get_constructor(exec_ctr TSRMLS_CC);
if (constructor != NULL) {
if (zend_call_method_with_2_params(&exec_ctr, *ce
, &constructor, NULL, &ret, request, response) == NULL) {
yaf_trigger_error(YAF_ERR_CALL_FAILED, "function call for %s::__construct failed", (*ce)->name);
return 0;
}
}
zend_function *constructor = NULL;
constructor = Z_OBJ_HT_P(exec_ctr)->get_constructor(exec_ctr TSRMLS_CC);
if (constructor != NULL) {
if (zend_call_method_with_2_params(&exec_ctr, *ce
, &constructor, NULL, &ret, request, response) == NULL) {
yaf_trigger_error(YAF_ERR_CALL_FAILED, "function call for %s::__construct failed", (*ce)->name);
return 0;
}
}
} while(0);
*/
*/
yaf_controller_construct(ce, icontroller, request, response, view, NULL TSRMLS_CC);

if (EG(exception)) {
zval_ptr_dtor(&icontroller);
return 0;
}

if (!yaf_request_is_dispatched(request TSRMLS_CC)) {
/* forward is called in init method */
zval_ptr_dtor(&icontroller);
return yaf_dispatcher_handle(dispatcher, request, response, view TSRMLS_CC);
}

/* view template directory for application, please notice that view engine's directory has high priority */
if (is_def_module) {
Expand All @@ -616,7 +622,7 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request,

zend_update_property(ce, icontroller, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_NAME), controller TSRMLS_CC);

action = zend_read_property(request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_ACTION), 1 TSRMLS_CC);
action = zend_read_property(request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_ACTION), 1 TSRMLS_CC);
action_lower = zend_str_tolower_dup(Z_STRVAL_P(action), Z_STRLEN_P(action));

/* because the action might call the forward to override the old action */
Expand Down

0 comments on commit 18125c0

Please sign in to comment.