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

Use native functions #836

Merged
merged 18 commits into from Jul 12, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rebase
  • Loading branch information
sjinks committed Jul 12, 2013
commit e7bfe24285d7df573acf030d997333c197a93fd5
237 changes: 223 additions & 14 deletions build/32bits/phalcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,7 @@ static void PHALCON_FASTCALL phalcon_copy_ctor(zval *destiny, zval *origin);
/** Use these functions to call functions in the PHP userland using an arbitrary zval as callable */
#define PHALCON_CALL_USER_FUNC(return_value, handler) if(phalcon_call_user_func(return_value, handler TSRMLS_CC)==FAILURE) return;
#define PHALCON_CALL_USER_FUNC_ARRAY(return_value, handler, params) if(phalcon_call_user_func_array(return_value, handler, params TSRMLS_CC)==FAILURE) return;
#define PHALCON_CALL_USER_FUNC_ARRAY_NOEX(return_value, handler, params) if(phalcon_call_user_func_array_noex(return_value, handler, params TSRMLS_CC)==FAILURE) return;

/** Call single functions */
static int phalcon_call_func_ex(zval *return_value, const char *func_name, int func_length, int noreturn TSRMLS_DC);
Expand Down Expand Up @@ -1508,6 +1509,7 @@ static int phalcon_call_static_zval_str_func_one_param(zval *return_value, zval
/** Fast call_user_func_array/call_user_func */
static int phalcon_call_user_func(zval *return_value, zval *handler TSRMLS_DC);
static int phalcon_call_user_func_array(zval *return_value, zval *handler, zval *params TSRMLS_DC);
static int phalcon_call_user_func_array_noex(zval *return_value, zval *handler, zval *params TSRMLS_DC);

/** Check constructors */
static int phalcon_has_constructor(const zval *object TSRMLS_DC);
Expand Down Expand Up @@ -3856,6 +3858,61 @@ static int phalcon_call_user_func_array(zval *return_value, zval *handler, zval
return status;
}

static int phalcon_call_user_func_array_noex(zval *return_value, zval *handler, zval *params TSRMLS_DC){

zval *retval_ptr = NULL;
zend_fcall_info fci;
zend_fcall_info_cache fci_cache;
char *is_callable_error = NULL;
int status = FAILURE;

if (Z_TYPE_P(params) != IS_ARRAY) {
ZVAL_NULL(return_value);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments supplied for phalcon_call_user_func_array_noex()");
phalcon_memory_restore_stack(TSRMLS_C);
return FAILURE;
}

if (zend_fcall_info_init(handler, 0, &fci, &fci_cache, NULL, &is_callable_error TSRMLS_CC) == SUCCESS) {
if (is_callable_error) {
zend_error(E_STRICT, "%s", is_callable_error);
efree(is_callable_error);
}
status = SUCCESS;
} else {
if (is_callable_error) {
zend_error(E_WARNING, "%s", is_callable_error);
efree(is_callable_error);
} else {
status = SUCCESS;
}
}

if (status == SUCCESS) {

zend_fcall_info_args(&fci, params TSRMLS_CC);
fci.retval_ptr_ptr = &retval_ptr;

if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && fci.retval_ptr_ptr && *fci.retval_ptr_ptr) {
COPY_PZVAL_TO_ZVAL(*return_value, *fci.retval_ptr_ptr);
}

if (fci.params) {
efree(fci.params);
}
}

if (EG(exception)) {
status = SUCCESS;
}

if (status == FAILURE) {
phalcon_memory_restore_stack(TSRMLS_C);
}

return status;
}

static int phalcon_call_user_func(zval *return_value, zval *handler TSRMLS_DC){

zval *retval_ptr = NULL;
Expand Down Expand Up @@ -34214,11 +34271,11 @@ static PHP_METHOD(Phalcon_Dispatcher, dispatch){
zval *dependency_injector, *exception_code = NULL;
zval *exception_message = NULL, *events_manager;
zval *event_name = NULL, *status = NULL, *value = NULL, *handler = NULL, *number_dispatches;
zval *handler_suffix, *action_suffix, *_finished = NULL;
zval *handler_suffix, *action_suffix, *finished = NULL;
zval *namespace_name = NULL, *handler_name = NULL, *action_name = NULL;
zval *finished = NULL, *camelized_class = NULL, *handler_class = NULL;
zval *has_service = NULL, *was_fresh = NULL, *action_method = NULL;
zval *params = NULL, *call_object = NULL;
zval *camelized_class = NULL, *handler_class = NULL, *has_service = NULL;
zval *was_fresh = NULL, *action_method = NULL, *params = NULL, *call_object = NULL;
zval *exception = NULL;

PHALCON_MM_GROW();

Expand Down Expand Up @@ -34260,14 +34317,14 @@ static PHP_METHOD(Phalcon_Dispatcher, dispatch){

PHALCON_OBS_VAR(action_suffix);
phalcon_read_property_this_quick(&action_suffix, this_ptr, SL("_actionSuffix"), 879621975UL, PH_NOISY_CC);

phalcon_update_property_bool(this_ptr, SL("_finished"), 0 TSRMLS_CC);

while (1) {

PHALCON_OBS_NVAR(_finished);
phalcon_read_property_this_quick(&_finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC);
if (!zend_is_true(_finished)) {
} else {
PHALCON_OBS_NVAR(finished);
phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC);
if (zend_is_true(finished)) {
break;
}

Expand Down Expand Up @@ -34516,10 +34573,40 @@ static PHP_METHOD(Phalcon_Dispatcher, dispatch){
phalcon_array_append(&call_object, handler, PH_SEPARATE);
phalcon_array_append(&call_object, action_method, PH_SEPARATE);

PHALCON_INIT_NVAR(value);
PHALCON_CALL_USER_FUNC_ARRAY(value, call_object, params);
if (Z_TYPE_P(events_manager) == IS_OBJECT) {

PHALCON_INIT_NVAR(value);
PHALCON_CALL_USER_FUNC_ARRAY_NOEX(value, call_object, params);

if (EG(exception)) {

PHALCON_CPY_WRT(exception, EG(exception));

zend_clear_exception(TSRMLS_C);

PHALCON_INIT_NVAR(status);
phalcon_call_method_p1_key(status, this_ptr, "_handleexception", exception, 2165668191UL);
if (PHALCON_IS_FALSE(status)) {

PHALCON_OBS_NVAR(finished);
phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC);
if (PHALCON_IS_FALSE(finished)) {
continue;
}
} else {
phalcon_throw_exception(exception TSRMLS_CC);
return;
}
} else {
phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), value, 4143876906UL TSRMLS_CC);
}
} else {
PHALCON_INIT_NVAR(value);
PHALCON_CALL_USER_FUNC_ARRAY(value, call_object, params);

phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), value, 4143876906UL TSRMLS_CC);
}

phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), value, 4143876906UL TSRMLS_CC);
phalcon_update_property_this_quick(this_ptr, SL("_lastHandler"), handler, 1315517974UL TSRMLS_CC);

if (Z_TYPE_P(events_manager) == IS_OBJECT) {
Expand Down Expand Up @@ -34629,6 +34716,55 @@ static PHP_METHOD(Phalcon_Dispatcher, wasForwarded){
RETURN_MEMBER_QUICK(this_ptr, "_forwarded", 1865074274UL);
}

static PHP_METHOD(Phalcon_Dispatcher, getHandlerClass){

zval *handler_suffix, *namespace_name = NULL, *handler_name = NULL;
zval *camelized_class = NULL, *handler_class = NULL;

PHALCON_MM_GROW();

PHALCON_OBS_VAR(handler_suffix);
phalcon_read_property_this_quick(&handler_suffix, this_ptr, SL("_handlerSuffix"), 1659190583UL, PH_NOISY_CC);

PHALCON_OBS_VAR(namespace_name);
phalcon_read_property_this_quick(&namespace_name, this_ptr, SL("_namespaceName"), 816833906UL, PH_NOISY_CC);
if (!zend_is_true(namespace_name)) {
PHALCON_OBS_NVAR(namespace_name);
phalcon_read_property_this_quick(&namespace_name, this_ptr, SL("_defaultNamespace"), 761145590UL, PH_NOISY_CC);
phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC);
}

PHALCON_OBS_VAR(handler_name);
phalcon_read_property_this_quick(&handler_name, this_ptr, SL("_handlerName"), 2743819555UL, PH_NOISY_CC);
if (!zend_is_true(handler_name)) {
PHALCON_OBS_NVAR(handler_name);
phalcon_read_property_this_quick(&handler_name, this_ptr, SL("_defaultHandler"), 2940762855UL, PH_NOISY_CC);
phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), handler_name, 2743819555UL TSRMLS_CC);
}

if (!phalcon_memnstr_str(handler_name, SL("\\"))) {
PHALCON_INIT_VAR(camelized_class);
phalcon_camelize(camelized_class, handler_name);
} else {
PHALCON_CPY_WRT(camelized_class, handler_name);
}

if (zend_is_true(namespace_name)) {
if (phalcon_end_with_str(namespace_name, SL("\\"))) {
PHALCON_INIT_VAR(handler_class);
PHALCON_CONCAT_VVV(handler_class, namespace_name, camelized_class, handler_suffix);
} else {
PHALCON_INIT_NVAR(handler_class);
PHALCON_CONCAT_VSVV(handler_class, namespace_name, "\\", camelized_class, handler_suffix);
}
} else {
PHALCON_INIT_NVAR(handler_class);
PHALCON_CONCAT_VV(handler_class, camelized_class, handler_suffix);
}

RETURN_CTOR(handler_class);
}




Expand Down Expand Up @@ -65759,6 +65895,41 @@ static PHP_METHOD(Phalcon_Mvc_Dispatcher, _throwDispatchException){
return;
}

static PHP_METHOD(Phalcon_Mvc_Dispatcher, _handleException){

zval *exception, *events_manager, *event_name;
zval *status;

PHALCON_MM_GROW();

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

PHALCON_OBS_VAR(events_manager);
phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC);
if (Z_TYPE_P(events_manager) == IS_OBJECT) {

PHALCON_INIT_VAR(event_name);
ZVAL_STRING(event_name, "dispatch:beforeException", 1);

PHALCON_INIT_VAR(status);
phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, exception, 259017035UL);
if (PHALCON_IS_FALSE(status)) {
RETURN_MM_FALSE;
}
}

PHALCON_MM_RESTORE();
}

static PHP_METHOD(Phalcon_Mvc_Dispatcher, getControllerClass){


PHALCON_MM_GROW();

phalcon_call_method_key(return_value, this_ptr, "gethandlername", 1725429572UL);
RETURN_MM();
}

static PHP_METHOD(Phalcon_Mvc_Dispatcher, getLastController){


Expand Down Expand Up @@ -89694,9 +89865,10 @@ static PHP_METHOD(Phalcon_Escaper, escapeUrl){

zval *url;

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

phalcon_raw_url_encode(return_value, url);
return;
}


Expand Down Expand Up @@ -90030,6 +90202,41 @@ static PHP_METHOD(Phalcon_CLI_Dispatcher, _throwDispatchException){
return;
}

static PHP_METHOD(Phalcon_CLI_Dispatcher, _handleException){

zval *exception, *events_manager, *event_name;
zval *status;

PHALCON_MM_GROW();

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

PHALCON_OBS_VAR(events_manager);
phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC);
if (Z_TYPE_P(events_manager) == IS_OBJECT) {

PHALCON_INIT_VAR(event_name);
ZVAL_STRING(event_name, "dispatch:beforeException", 1);

PHALCON_INIT_VAR(status);
phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, exception, 259017035UL);
if (PHALCON_IS_FALSE(status)) {
RETURN_MM_FALSE;
}
}

PHALCON_MM_RESTORE();
}

static PHP_METHOD(Phalcon_CLI_Dispatcher, getTaskClass){


PHALCON_MM_GROW();

phalcon_call_method_key(return_value, this_ptr, "gethandlername", 1725429572UL);
RETURN_MM();
}

static PHP_METHOD(Phalcon_CLI_Dispatcher, getLastTask){


Expand Down Expand Up @@ -96534,18 +96741,20 @@ static PHP_METHOD(Phalcon_Text, camelize){

zval *str;

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

phalcon_camelize(return_value, str);
return;
}

static PHP_METHOD(Phalcon_Text, uncamelize){

zval *str;

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

phalcon_uncamelize(return_value, str);
return;
}

static PHP_METHOD(Phalcon_Text, increment){
Expand Down
10 changes: 10 additions & 0 deletions build/32bits/phalcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -4965,6 +4965,7 @@ static PHP_METHOD(Phalcon_Dispatcher, getReturnedValue);
static PHP_METHOD(Phalcon_Dispatcher, dispatch);
static PHP_METHOD(Phalcon_Dispatcher, forward);
static PHP_METHOD(Phalcon_Dispatcher, wasForwarded);
static PHP_METHOD(Phalcon_Dispatcher, getHandlerClass);

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_dispatcher_setdi, 0, 0, 1)
ZEND_ARG_INFO(0, dependencyInjector)
Expand Down Expand Up @@ -5048,6 +5049,7 @@ PHALCON_INIT_FUNCS(phalcon_dispatcher_method_entry){
PHP_ME(Phalcon_Dispatcher, dispatch, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, forward, arginfo_phalcon_dispatcher_forward, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, wasForwarded, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Dispatcher, getHandlerClass, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};

Expand Down Expand Up @@ -8816,6 +8818,8 @@ static PHP_METHOD(Phalcon_CLI_Dispatcher, setDefaultTask);
static PHP_METHOD(Phalcon_CLI_Dispatcher, setTaskName);
static PHP_METHOD(Phalcon_CLI_Dispatcher, getTaskName);
static PHP_METHOD(Phalcon_CLI_Dispatcher, _throwDispatchException);
static PHP_METHOD(Phalcon_CLI_Dispatcher, _handleException);
static PHP_METHOD(Phalcon_CLI_Dispatcher, getTaskClass);
static PHP_METHOD(Phalcon_CLI_Dispatcher, getLastTask);
static PHP_METHOD(Phalcon_CLI_Dispatcher, getActiveTask);

Expand All @@ -8837,6 +8841,8 @@ PHALCON_INIT_FUNCS(phalcon_cli_dispatcher_method_entry){
PHP_ME(Phalcon_CLI_Dispatcher, setTaskName, arginfo_phalcon_cli_dispatcher_settaskname, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_CLI_Dispatcher, getTaskName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_CLI_Dispatcher, _throwDispatchException, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_CLI_Dispatcher, _handleException, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_CLI_Dispatcher, getTaskClass, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_CLI_Dispatcher, getLastTask, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_CLI_Dispatcher, getActiveTask, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
Expand Down Expand Up @@ -12325,6 +12331,8 @@ static PHP_METHOD(Phalcon_Mvc_Dispatcher, setDefaultController);
static PHP_METHOD(Phalcon_Mvc_Dispatcher, setControllerName);
static PHP_METHOD(Phalcon_Mvc_Dispatcher, getControllerName);
static PHP_METHOD(Phalcon_Mvc_Dispatcher, _throwDispatchException);
static PHP_METHOD(Phalcon_Mvc_Dispatcher, _handleException);
static PHP_METHOD(Phalcon_Mvc_Dispatcher, getControllerClass);
static PHP_METHOD(Phalcon_Mvc_Dispatcher, getLastController);
static PHP_METHOD(Phalcon_Mvc_Dispatcher, getActiveController);

Expand All @@ -12346,6 +12354,8 @@ PHALCON_INIT_FUNCS(phalcon_mvc_dispatcher_method_entry){
PHP_ME(Phalcon_Mvc_Dispatcher, setControllerName, arginfo_phalcon_mvc_dispatcher_setcontrollername, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Dispatcher, getControllerName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Dispatcher, _throwDispatchException, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_Mvc_Dispatcher, _handleException, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_Mvc_Dispatcher, getControllerClass, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Dispatcher, getLastController, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Dispatcher, getActiveController, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
Expand Down
Loading