diff options
author | Dmitry Stogov <dmitry@zend.com> | 2014-02-13 17:54:23 +0400 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2014-02-13 17:54:23 +0400 |
commit | 40e053e7f333b5fc3f4c75c964600666810cc969 (patch) | |
tree | 3436d014c44e3eab00107e67b10229ec0262dbb6 /ext/standard/info.c | |
parent | 6306918ed2c9d87cf5fadc62d210a797a794926e (diff) | |
download | php-git-40e053e7f333b5fc3f4c75c964600666810cc969.tar.gz |
Use better data structures (incomplete)
Diffstat (limited to 'ext/standard/info.c')
-rw-r--r-- | ext/standard/info.c | 103 |
1 files changed, 51 insertions, 52 deletions
diff --git a/ext/standard/info.c b/ext/standard/info.c index 0acf4c75b8..682af53798 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -63,14 +63,13 @@ PHPAPI extern char *php_ini_scanned_files; static int php_info_print_html_esc(const char *str, int len) /* {{{ */ { - size_t new_len; int written; - char *new_str; + zend_string *new_str; TSRMLS_FETCH(); - new_str = php_escape_html_entities((unsigned char *) str, len, &new_len, 0, ENT_QUOTES, "utf-8" TSRMLS_CC); - written = php_output_write(new_str, new_len TSRMLS_CC); - str_efree(new_str); + new_str = php_escape_html_entities((unsigned char *) str, len, 0, ENT_QUOTES, "utf-8" TSRMLS_CC); + written = php_output_write(new_str->val, new_str->len TSRMLS_CC); + STR_FREE(new_str); return written; } /* }}} */ @@ -101,8 +100,7 @@ static int php_info_print(const char *str) /* {{{ */ static void php_info_print_stream_hash(const char *name, HashTable *ht TSRMLS_DC) /* {{{ */ { - char *key; - uint len; + zend_string *key; if (ht) { if (zend_hash_num_elements(ht)) { @@ -115,15 +113,15 @@ static void php_info_print_stream_hash(const char *name, HashTable *ht TSRMLS_DC } zend_hash_internal_pointer_reset_ex(ht, &pos); - while (zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, &pos) == HASH_KEY_IS_STRING) + while (zend_hash_get_current_key_ex(ht, &key, NULL, 0, &pos) == HASH_KEY_IS_STRING) { if (!sapi_module.phpinfo_as_text) { - php_info_print_html_esc(key, len-1); + php_info_print_html_esc(key->val, key->len); } else { - php_info_print(key); + php_info_print(key->val); } zend_hash_move_forward_ex(ht, &pos); - if (zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, &pos) == HASH_KEY_IS_STRING) { + if (zend_hash_get_current_key_ex(ht, &key, NULL, 0, &pos) == HASH_KEY_IS_STRING) { php_info_print(", "); } else { break; @@ -194,17 +192,18 @@ static int _display_module_info_def(zend_module_entry *module TSRMLS_DC) /* {{{ */ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) { - zval **data, **tmp, tmp2; - char *string_key; - uint string_len; + zval *data, *tmp, tmp2; + zend_string *string_key; ulong num_key; - - zend_is_auto_global(name, name_length TSRMLS_CC); - - if (zend_hash_find(&EG(symbol_table), name, name_length+1, (void **) &data)!=FAILURE - && (Z_TYPE_PP(data)==IS_ARRAY)) { - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data)); - while (zend_hash_get_current_data(Z_ARRVAL_PP(data), (void **) &tmp) == SUCCESS) { + zend_string *key; + + key = STR_INIT(name, name_length, 0); + zend_is_auto_global(key TSRMLS_CC); + + if ((data = zend_hash_find(&EG(symbol_table).ht, key)) != NULL + && (Z_TYPE_P(data)==IS_ARRAY)) { + zend_hash_internal_pointer_reset(Z_ARRVAL_P(data)); + while ((tmp = zend_hash_get_current_data(Z_ARRVAL_P(data))) != NULL) { if (!sapi_module.phpinfo_as_text) { php_info_print("<tr>"); php_info_print("<td class=\"e\">"); @@ -213,12 +212,12 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) php_info_print(name); php_info_print("[\""); - switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(data), &string_key, &string_len, &num_key, 0, NULL)) { + switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(data), &string_key, &num_key, 0, NULL)) { case HASH_KEY_IS_STRING: if (!sapi_module.phpinfo_as_text) { - php_info_print_html_esc(string_key, string_len-1); + php_info_print_html_esc(string_key->val, string_key->len); } else { - php_info_print(string_key); + php_info_print(string_key->val); } break; case HASH_KEY_IS_LONG: @@ -231,17 +230,17 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) } else { php_info_print(" => "); } - if (Z_TYPE_PP(tmp) == IS_ARRAY) { + if (Z_TYPE_P(tmp) == IS_ARRAY) { if (!sapi_module.phpinfo_as_text) { php_info_print("<pre>"); - zend_print_zval_r_ex((zend_write_func_t) php_info_print_html_esc, *tmp, 0 TSRMLS_CC); + zend_print_zval_r_ex((zend_write_func_t) php_info_print_html_esc, tmp, 0 TSRMLS_CC); php_info_print("</pre>"); } else { - zend_print_zval_r(*tmp, 0 TSRMLS_CC); + zend_print_zval_r(tmp, 0 TSRMLS_CC); } } else { - tmp2 = **tmp; - if (Z_TYPE_PP(tmp) != IS_STRING) { + ZVAL_COPY_VALUE(&tmp2, tmp); + if (Z_TYPE(tmp2) != IS_STRING) { tmp = NULL; zval_copy_ctor(&tmp2); convert_to_string(&tmp2); @@ -266,7 +265,7 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) } else { php_info_print("\n"); } - zend_hash_move_forward(Z_ARRVAL_PP(data)); + zend_hash_move_forward(Z_ARRVAL_P(data)); } } } @@ -284,10 +283,9 @@ void php_info_print_style(TSRMLS_D) /* {{{ php_info_html_esc */ -PHPAPI char *php_info_html_esc(char *string TSRMLS_DC) +PHPAPI zend_string *php_info_html_esc(char *string TSRMLS_DC) { - size_t new_len; - return php_escape_html_entities((unsigned char *) string, strlen(string), &new_len, 0, ENT_QUOTES, NULL TSRMLS_CC); + return php_escape_html_entities((unsigned char *) string, strlen(string), 0, ENT_QUOTES, NULL TSRMLS_CC); } /* }}} */ @@ -651,8 +649,8 @@ static int module_name_cmp(const void *a, const void *b TSRMLS_DC) Bucket *f = (Bucket *) a; Bucket *s = (Bucket *) b; - return strcasecmp(((zend_module_entry *)f->xData)->name, - ((zend_module_entry *)s->xData)->name); + return strcasecmp(((zend_module_entry *)Z_PTR(f->val))->name, + ((zend_module_entry *)Z_PTR(s->val))->name); } /* }}} */ @@ -824,10 +822,10 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) if (flag & PHP_INFO_MODULES) { HashTable sorted_registry; - zend_module_entry tmp; zend_hash_init(&sorted_registry, zend_hash_num_elements(&module_registry), NULL, NULL, 1); - zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry)); +//??? zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry)); + zend_hash_copy(&sorted_registry, &module_registry, NULL); zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC); zend_hash_apply(&sorted_registry, (apply_func_t) _display_module_info_func TSRMLS_CC); @@ -860,23 +858,23 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) } if (flag & PHP_INFO_VARIABLES) { - zval **data; + zval *data; SECTION("PHP Variables"); php_info_print_table_start(); php_info_print_table_header(2, "Variable", "Value"); - if (zend_hash_find(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void **) &data) != FAILURE) { - php_info_print_table_row(2, "PHP_SELF", Z_STRVAL_PP(data)); + if ((data = zend_hash_str_find(&EG(symbol_table).ht, "PHP_SELF", sizeof("PHP_SELF")-1)) != NULL) { + php_info_print_table_row(2, "PHP_SELF", Z_STRVAL_P(data)); } - if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE"), (void **) &data) != FAILURE) { - php_info_print_table_row(2, "PHP_AUTH_TYPE", Z_STRVAL_PP(data)); + if ((data = zend_hash_str_find(&EG(symbol_table).ht, "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE")-1)) != NULL) { + php_info_print_table_row(2, "PHP_AUTH_TYPE", Z_STRVAL_P(data)); } - if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &data) != FAILURE) { - php_info_print_table_row(2, "PHP_AUTH_USER", Z_STRVAL_PP(data)); + if ((data = zend_hash_str_find(&EG(symbol_table).ht, "PHP_AUTH_USER", sizeof("PHP_AUTH_USER")-1)) != NULL) { + php_info_print_table_row(2, "PHP_AUTH_USER", Z_STRVAL_P(data)); } - if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &data) != FAILURE) { - php_info_print_table_row(2, "PHP_AUTH_PW", Z_STRVAL_PP(data)); + if ((data = zend_hash_str_find(&EG(symbol_table).ht, "PHP_AUTH_PW", sizeof("PHP_AUTH_PW")-1)) != NULL) { + php_info_print_table_row(2, "PHP_AUTH_PW", Z_STRVAL_P(data)); } php_print_gpcse_array(ZEND_STRL("_REQUEST") TSRMLS_CC); php_print_gpcse_array(ZEND_STRL("_GET") TSRMLS_CC); @@ -1166,14 +1164,14 @@ PHP_FUNCTION(phpversion) } if (!ext_name) { - RETURN_STRING(PHP_VERSION, 1); + RETURN_STRING(PHP_VERSION); } else { const char *version; version = zend_get_module_version(ext_name); if (version == NULL) { RETURN_FALSE; } - RETURN_STRING(version, 1); + RETURN_STRING(version); } } /* }}} */ @@ -1202,7 +1200,7 @@ PHP_FUNCTION(php_sapi_name) } if (sapi_module.name) { - RETURN_STRING(sapi_module.name, 1); + RETURN_STRING(sapi_module.name); } else { RETURN_FALSE; } @@ -1220,7 +1218,8 @@ PHP_FUNCTION(php_uname) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &mode, &modelen) == FAILURE) { return; } - RETURN_STRING(php_get_uname(*mode), 0); +//??? RETURN_STRING(php_get_uname(*mode), 0); + RETURN_STRING(php_get_uname(*mode)); } /* }}} */ @@ -1234,7 +1233,7 @@ PHP_FUNCTION(php_ini_scanned_files) } if (strlen(PHP_CONFIG_FILE_SCAN_DIR) && php_ini_scanned_files) { - RETURN_STRING(php_ini_scanned_files, 1); + RETURN_STRING(php_ini_scanned_files); } else { RETURN_FALSE; } @@ -1250,7 +1249,7 @@ PHP_FUNCTION(php_ini_loaded_file) } if (php_ini_opened_path) { - RETURN_STRING(php_ini_opened_path, 1); + RETURN_STRING(php_ini_opened_path); } else { RETURN_FALSE; } |