Skip to content

Commit

Permalink
use c native char *
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Mar 4, 2021
1 parent b2aa878 commit f74ae92
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
12 changes: 4 additions & 8 deletions yaf_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ static ZEND_HOT int yaf_dispatcher_handle(yaf_dispatcher_object *dispatcher) /*
/* }}} */

static ZEND_COLD zend_never_inline void yaf_dispatcher_exception_handler(yaf_dispatcher_object *dispatcher) /* {{{ */ {
zend_string *exception_str, *controller, *action;
zend_string *controller, *action;
zval exception;
const zend_op *opline;
yaf_request_object *request = Z_YAFREQUESTOBJ(dispatcher->request);
Expand Down Expand Up @@ -724,21 +724,18 @@ static ZEND_COLD zend_never_inline void yaf_dispatcher_exception_handler(yaf_dis
zend_string_release(action);

/** use $request->getException() instand of */
exception_str = zend_string_init(ZEND_STRL("exception"), 0);
if (yaf_request_set_params_single(request, exception_str, &exception)) {
if (yaf_request_set_str_params_single(request, "exception", sizeof("exception") - 1, &exception)) {
zval_ptr_dtor(&exception);
} else {
/* failover to uncaught exception */
zend_string_release(exception_str);
EG(exception) = Z_OBJ(exception);
YAF_DISPATCHER_FLAGS(dispatcher) = ~YAF_DISPATCHER_IN_EXCEPTION;
return;
}
yaf_request_set_dispatched(request, 0);

if (UNEXPECTED(!yaf_dispatcher_init_view(dispatcher, NULL, NULL))) {
yaf_request_del_param(request, exception_str);
zend_string_release(exception_str);
yaf_request_del_str_param(request, "exception", sizeof("exception") - 1);
YAF_DISPATCHER_FLAGS(dispatcher) = ~YAF_DISPATCHER_IN_EXCEPTION;
return;
}
Expand All @@ -755,8 +752,7 @@ static ZEND_COLD zend_never_inline void yaf_dispatcher_exception_handler(yaf_dis
}
}

yaf_request_del_param(request, exception_str);
zend_string_release(exception_str);
yaf_request_del_str_param(request, "exception", sizeof("exception") - 1);

if (!(YAF_DISPATCHER_FLAGS(dispatcher) & YAF_DISPATCHER_RETURN_RESPONSE)) {
yaf_response_response(Z_YAFRESPONSEOBJ(dispatcher->response));
Expand Down
22 changes: 22 additions & 0 deletions yaf_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,14 @@ ZEND_HOT zval *yaf_request_query(unsigned type, zend_string *name) /* {{{ */ {
}
/* }}} */

int yaf_request_del_str_param(yaf_request_object *request, const char *key, size_t len) /* {{{ */ {
if (request->params) {
return zend_hash_str_del(request->params, key, len);
}
return 0;
}
/* }}} */

int yaf_request_del_param(yaf_request_object *request, zend_string *key) /* {{{ */ {
if (request->params) {
return zend_hash_del(request->params, key);
Expand All @@ -745,6 +753,20 @@ int yaf_request_del_param(yaf_request_object *request, zend_string *key) /* {{{
}
/* }}} */

int yaf_request_set_str_params_single(yaf_request_object *request, const char *key, size_t len, zval *value) /* {{{ */ {
if (!request->params) {
ALLOC_HASHTABLE(request->params);
zend_hash_init(request->params, 8, NULL, ZVAL_PTR_DTOR, 0);
YAF_ALLOW_VIOLATION(request->params);
}
if ((zend_hash_str_update(request->params, key, len, value)) != NULL) {
Z_TRY_ADDREF_P(value);
return 1;
}
return 0;
}
/* }}} */

int yaf_request_set_params_single(yaf_request_object *request, zend_string *key, zval *value) /* {{{ */ {
if (!request->params) {
ALLOC_HASHTABLE(request->params);
Expand Down
2 changes: 2 additions & 0 deletions yaf_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ zend_string *yaf_request_get_language(yaf_request_object *request);

void yaf_request_set_mvc(yaf_request_object *request, zend_string *module, zend_string *controller, zend_string *action, zend_array *params);
int yaf_request_set_params_single(yaf_request_object *instance, zend_string *key, zval *value);
int yaf_request_set_str_params_single(yaf_request_object *instance, const char *key, size_t len, zval *value);
int yaf_request_set_params_multi(yaf_request_object *instance, zval *values);
int yaf_request_del_str_param(yaf_request_object *request, const char *key, size_t len);
int yaf_request_del_param(yaf_request_object *request, zend_string *key);
const char *yaf_request_strip_base_uri(zend_string *uri, zend_string *base_uri, size_t *len);
const char *yaf_request_get_request_method(void);
Expand Down

0 comments on commit f74ae92

Please sign in to comment.