Skip to content

Commit

Permalink
make code better
Browse files Browse the repository at this point in the history
  • Loading branch information
zxcvdavid committed Apr 11, 2013
1 parent 68f522c commit 909c517
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 249 deletions.
12 changes: 6 additions & 6 deletions configs/yaf_config_ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static void yaf_config_ini_parser_cb(zval *key, zval *value, zval *index, int ca
}

/* remove the tail space, thinking of 'foo : bar : test' */
section = seg + strlen(seg) - 1;
section = seg + strlen(seg) - 1;
while (*section == ' ' || *section == ':') {
*(section--) = '\0';
}
Expand All @@ -286,8 +286,8 @@ static void yaf_config_ini_parser_cb(zval *key, zval *value, zval *index, int ca
(copy_ctor_func_t)yaf_config_ini_zval_deep_copy, NULL, sizeof(zval *));
}
}
seg = skey + strlen(skey) - 1;
while (*seg == ' ' || *seg == ':') {
seg = skey + strlen(skey) - 1;
while (*seg == ' ' || *seg == ':') {
*(seg--) = '\0';
}
skey_len = strlen(skey);
Expand Down Expand Up @@ -476,7 +476,7 @@ static void yaf_config_ini_parser_cb(zval *key, zval *value, int callback_type,
}

/* remove the tail space, thinking of 'foo : bar : test' */
section = seg + strlen(seg) - 1;
section = seg + strlen(seg) - 1;
while (*section == ' ' || *section == ':') {
*(section--) = '\0';
}
Expand All @@ -486,8 +486,8 @@ static void yaf_config_ini_parser_cb(zval *key, zval *value, int callback_type,
(copy_ctor_func_t)yaf_config_ini_zval_deep_copy, NULL, sizeof(zval *));
}
}
seg = skey + strlen(skey) - 1;
while (*seg == ' ' || *seg == ':') {
seg = skey + strlen(skey) - 1;
while (*seg == ' ' || *seg == ':') {
*(seg--) = '\0';
}
skey_len = strlen(skey);
Expand Down
25 changes: 13 additions & 12 deletions requests/yaf_request_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ yaf_request_t * yaf_request_http_instance(yaf_request_t *this_ptr, char *request
object_init_ex(instance, yaf_request_http_ce);
}

MAKE_STD_ZVAL(method);
if (SG(request_info).request_method) {
ZVAL_STRING(method, (char *)SG(request_info).request_method, 1);
} else if (strncasecmp(sapi_module.name, "cli", 3)) {
ZVAL_STRING(method, "Unknow", 1);
} else {
ZVAL_STRING(method, "Cli", 1);
}
MAKE_STD_ZVAL(method);
if (SG(request_info).request_method) {
ZVAL_STRING(method, (char *)SG(request_info).request_method, 1);
} else if (strncasecmp(sapi_module.name, "cli", 3)) {
ZVAL_STRING(method, "Unknow", 1);
} else {
ZVAL_STRING(method, "Cli", 1);
}

zend_update_property(yaf_request_http_ce, instance, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_METHOD), method TSRMLS_CC);
zval_ptr_dtor(&method);

Expand Down Expand Up @@ -276,14 +277,14 @@ PHP_METHOD(yaf_request_http, __clone) {
*/
zend_function_entry yaf_request_http_methods[] = {
PHP_ME(yaf_request_http, getQuery, NULL, ZEND_ACC_PUBLIC)
PHP_ME(yaf_request_http, getRequest, NULL, ZEND_ACC_PUBLIC)
PHP_ME(yaf_request_http, getRequest, NULL, ZEND_ACC_PUBLIC)
PHP_ME(yaf_request_http, getPost, NULL, ZEND_ACC_PUBLIC)
PHP_ME(yaf_request_http, getCookie, NULL, ZEND_ACC_PUBLIC)
PHP_ME(yaf_request_http, getFiles, NULL, ZEND_ACC_PUBLIC)
PHP_ME(yaf_request_http, get, NULL, ZEND_ACC_PUBLIC)
PHP_ME(yaf_request_http, isXmlHttpRequest,NULL,ZEND_ACC_PUBLIC)
PHP_ME(yaf_request_http, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(yaf_request_http, __clone, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CLONE)
PHP_ME(yaf_request_http, isXmlHttpRequest, NULL, ZEND_ACC_PUBLIC)
PHP_ME(yaf_request_http, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(yaf_request_http, __clone, NULL, ZEND_ACC_PRIVATE | ZEND_ACC_CLONE)
{NULL, NULL, NULL}
};
/* }}} */
Expand Down
2 changes: 1 addition & 1 deletion requests/yaf_request_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ PHP_METHOD(yaf_request_simple, __construct) {
zval *action = NULL;
zval *params = NULL;
zval *method = NULL;
zval *self = getThis();
zval *self = getThis();

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zzzzz", &method, &module, &controller, &action, &params) == FAILURE) {
YAF_UNINITIALIZED_OBJECT(getThis());
Expand Down
2 changes: 1 addition & 1 deletion views/yaf_view_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ PHP_METHOD(yaf_view_simple, assign) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len, &value) == FAILURE) {
return;
}
RETURN_BOOL(yaf_view_simple_assign_single(getThis(), name, len, value TSRMLS_CC));
RETURN_BOOL(yaf_view_simple_assign_single(getThis(), name, len, value TSRMLS_CC));
} else {
WRONG_PARAM_COUNT;
}
Expand Down
208 changes: 104 additions & 104 deletions yaf_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ ZEND_END_ARG_INFO()
/** {{{ int yaf_application_is_module_name(char *name, int len TSRMLS_DC)
*/
int yaf_application_is_module_name(char *name, int len TSRMLS_DC) {
zval *modules, **ppzval;
HashTable *ht;
zval *modules, **ppzval;
HashTable *ht;
yaf_application_t *app;

app = zend_read_static_property(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_APP), 1 TSRMLS_CC);
Expand Down Expand Up @@ -172,7 +172,7 @@ static int yaf_application_parse_option(zval *options TSRMLS_DC) {
if (src[i] == ',') {
target[len++] = DEFAULT_DIR_SEPARATOR;
} else if (src[i] != ' ') {
target[len++] = src[i];
target[len++] = src[i];
}
}
target[len] = '\0';
Expand Down Expand Up @@ -318,8 +318,8 @@ PHP_METHOD(yaf_application, __construct) {
yaf_dispatcher_t *zdispatcher;
yaf_application_t *app, *self;
yaf_loader_t *loader;
zval *config;
zval *section = NULL;
zval *config;
zval *section = NULL;

app = zend_read_static_property(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_APP), 1 TSRMLS_CC);

Expand Down Expand Up @@ -478,78 +478,78 @@ PHP_METHOD(yaf_application, run) {
*/
PHP_METHOD(yaf_application, execute) {
#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION > 2)) || (PHP_MAJOR_VERSION > 5)
zval *retval_ptr;
zend_fcall_info fci;
zend_fcall_info_cache fci_cache;
zval *retval_ptr;
zend_fcall_info fci;
zend_fcall_info_cache fci_cache;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f*", &fci, &fci_cache, &fci.params, &fci.param_count) == FAILURE) {
return;
}
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f*", &fci, &fci_cache, &fci.params, &fci.param_count) == FAILURE) {
return;
}

fci.retval_ptr_ptr = &retval_ptr;
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 (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 (fci.params) {
efree(fci.params);
}
#else
zval ***params;
zval *retval_ptr;
char *name;
int argc = ZEND_NUM_ARGS();

if (argc < 1) {
return;
}

params = safe_emalloc(sizeof(zval **), argc, 0);
if (zend_get_parameters_array_ex(1, params) == FAILURE) {
efree(params);
RETURN_FALSE;
}

if (Z_TYPE_PP(params[0]) != IS_STRING && Z_TYPE_PP(params[0]) != IS_ARRAY) {
SEPARATE_ZVAL(params[0]);
convert_to_string_ex(params[0]);
}

if (!zend_is_callable(*params[0], 0, &name)) {
php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "First argument is expected to be a valid callback");
efree(name);
efree(params);
RETURN_NULL();
}

if (zend_get_parameters_array_ex(argc, params) == FAILURE) {
efree(params);
RETURN_FALSE;
}

if (call_user_function_ex(EG(function_table), NULL, *params[0], &retval_ptr, argc - 1, params + 1, 0, NULL TSRMLS_CC) == SUCCESS) {
if (retval_ptr) {
COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
}
} else {
if (argc > 1) {
SEPARATE_ZVAL(params[1]);
convert_to_string_ex(params[1]);
if (argc > 2) {
SEPARATE_ZVAL(params[2]);
convert_to_string_ex(params[2]);
php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s(%s,%s)", name, Z_STRVAL_PP(params[1]), Z_STRVAL_PP(params[2]));
} else {
php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s(%s)", name, Z_STRVAL_PP(params[1]));
}
} else {
php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s()", name);
}
}

efree(name);
efree(params);
zval ***params;
zval *retval_ptr;
char *name;
int argc = ZEND_NUM_ARGS();

if (argc < 1) {
return;
}

params = safe_emalloc(sizeof(zval **), argc, 0);
if (zend_get_parameters_array_ex(1, params) == FAILURE) {
efree(params);
RETURN_FALSE;
}

if (Z_TYPE_PP(params[0]) != IS_STRING && Z_TYPE_PP(params[0]) != IS_ARRAY) {
SEPARATE_ZVAL(params[0]);
convert_to_string_ex(params[0]);
}

if (!zend_is_callable(*params[0], 0, &name)) {
php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "First argument is expected to be a valid callback");
efree(name);
efree(params);
RETURN_NULL();
}

if (zend_get_parameters_array_ex(argc, params) == FAILURE) {
efree(params);
RETURN_FALSE;
}

if (call_user_function_ex(EG(function_table), NULL, *params[0], &retval_ptr, argc - 1, params + 1, 0, NULL TSRMLS_CC) == SUCCESS) {
if (retval_ptr) {
COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
}
} else {
if (argc > 1) {
SEPARATE_ZVAL(params[1]);
convert_to_string_ex(params[1]);
if (argc > 2) {
SEPARATE_ZVAL(params[2]);
convert_to_string_ex(params[2]);
php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s(%s,%s)", name, Z_STRVAL_PP(params[1]), Z_STRVAL_PP(params[2]));
} else {
php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s(%s)", name, Z_STRVAL_PP(params[1]));
}
} else {
php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s()", name);
}
}

efree(name);
efree(params);
#endif
}
/* }}} */
Expand Down Expand Up @@ -597,8 +597,8 @@ PHP_METHOD(yaf_application, environ) {
/** {{{ proto public Yaf_Application::bootstrap(void)
*/
PHP_METHOD(yaf_application, bootstrap) {
char *bootstrap_path;
uint len, retval = 1;
char *bootstrap_path;
uint len, retval = 1;
zend_class_entry **ce;
yaf_application_t *self = getThis();

Expand Down Expand Up @@ -629,13 +629,13 @@ PHP_METHOD(yaf_application, bootstrap) {
} else {
zval *bootstrap;
HashTable *methods;
yaf_dispatcher_t *dispatcher;
yaf_dispatcher_t *dispatcher;

MAKE_STD_ZVAL(bootstrap);
object_init_ex(bootstrap, *ce);
dispatcher = zend_read_property(yaf_application_ce, self, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_DISPATCHER), 1 TSRMLS_CC);
dispatcher = zend_read_property(yaf_application_ce, self, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_DISPATCHER), 1 TSRMLS_CC);

methods = &((*ce)->function_table);
methods = &((*ce)->function_table);
for(zend_hash_internal_pointer_reset(methods);
zend_hash_has_more_elements(methods) == SUCCESS;
zend_hash_move_forward(methods)) {
Expand Down Expand Up @@ -693,9 +693,9 @@ PHP_METHOD(yaf_application, clearLastError) {
/** {{{ proto public Yaf_Application::setAppDirectory(string $directory)
*/
PHP_METHOD(yaf_application, setAppDirectory) {
int len;
char *directory;
yaf_dispatcher_t *self = getThis();
int len;
char *directory;
yaf_dispatcher_t *self = getThis();

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &directory, &len) == FAILURE) {
return;
Expand Down Expand Up @@ -723,24 +723,24 @@ PHP_METHOD(yaf_application, getAppDirectory) {
/** {{{ yaf_application_methods
*/
zend_function_entry yaf_application_methods[] = {
PHP_ME(yaf_application, __construct, yaf_application_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(yaf_application, __construct, yaf_application_construct_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(yaf_application, run, yaf_application_run_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, execute, yaf_application_execute_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, app, yaf_application_app_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
YAF_ME(yaf_application_environ, "environ", yaf_application_environ_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, bootstrap, yaf_application_bootstrap_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getConfig, yaf_application_getconfig_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getModules, yaf_application_getmodule_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getDispatcher, yaf_application_getdispatch_arginfo,ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, setAppDirectory,yaf_application_setappdir_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getAppDirectory,yaf_application_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getLastErrorNo, yaf_application_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getLastErrorMsg,yaf_application_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, clearLastError, yaf_application_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
PHP_ME(yaf_application, __clone, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CLONE)
PHP_ME(yaf_application, __sleep, NULL, ZEND_ACC_PRIVATE)
PHP_ME(yaf_application, __wakeup, NULL, ZEND_ACC_PRIVATE)
PHP_ME(yaf_application, app, yaf_application_app_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
YAF_ME(yaf_application_environ, "environ", yaf_application_environ_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, bootstrap, yaf_application_bootstrap_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getConfig, yaf_application_getconfig_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getModules, yaf_application_getmodule_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getDispatcher, yaf_application_getdispatch_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, setAppDirectory, yaf_application_setappdir_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getAppDirectory, yaf_application_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getLastErrorNo, yaf_application_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getLastErrorMsg, yaf_application_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, clearLastError, yaf_application_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, __destruct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
PHP_ME(yaf_application, __clone, NULL, ZEND_ACC_PRIVATE | ZEND_ACC_CLONE)
PHP_ME(yaf_application, __sleep, NULL, ZEND_ACC_PRIVATE)
PHP_ME(yaf_application, __wakeup, NULL, ZEND_ACC_PRIVATE)
{NULL, NULL, NULL}
};
/* }}} */
Expand All @@ -751,19 +751,19 @@ YAF_STARTUP_FUNCTION(application) {
zend_class_entry ce;
YAF_INIT_CLASS_ENTRY(ce, "Yaf_Application", "Yaf\\Application", yaf_application_methods);

yaf_application_ce = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
yaf_application_ce = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
yaf_application_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;

zend_declare_property_null(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_CONFIG), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_DISPATCHER), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_APP), ZEND_ACC_STATIC|ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_CONFIG), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_DISPATCHER), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_APP), ZEND_ACC_STATIC | ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_MODULES), ZEND_ACC_PROTECTED TSRMLS_CC);

zend_declare_property_bool(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_RUN), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ENV), YAF_G(environ), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_RUN), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ENV), YAF_G(environ), ZEND_ACC_PROTECTED TSRMLS_CC);

zend_declare_property_long(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRNO), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRMSG), "", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_long(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRNO), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRMSG), "", ZEND_ACC_PROTECTED TSRMLS_CC);

return SUCCESS;
}
Expand Down
Loading

0 comments on commit 909c517

Please sign in to comment.