]> granicus.if.org Git - php/commitdiff
- Nuke empty_string. It is a reminanent from the time where RETURN_FALSE()
authorAndi Gutmans <andi@php.net>
Mon, 19 Jul 2004 07:19:50 +0000 (07:19 +0000)
committerAndi Gutmans <andi@php.net>
Mon, 19 Jul 2004 07:19:50 +0000 (07:19 +0000)
  used to return "" and not bool(false). It's not worth keeping it because
  STR_FREE() and zval_dtor() always have to check for it and it slows down
  the general case. In addition, it seems that empty_string has been abused
  quite a lot, and was used not only for setting zval's but generally in
  PHP code instead of "", which wasn't the intention. Last but not least,
  nuking empty_string should improve stability as I doubt every place
  correctly checked if they are not mistakenly erealloc()'ing it or
  calling efree() on it.
  NOTE: Some code is probably broken. Each extension maintainer should
  check and see that my changes are OK. Also, I haven't had time to touch
  PECL yet. Will try and do it tomorrow.

38 files changed:
Zend/zend.c
Zend/zend.h
Zend/zend_API.h
Zend/zend_alloc.h
Zend/zend_execute.c
Zend/zend_object_handlers.c
Zend/zend_operators.c
Zend/zend_variables.c
ext/ereg/ereg.c
ext/gd/gd.c
ext/gd/gd_ctx.c
ext/mbstring/php_mbregex.c
ext/msql/php_msql.c
ext/mssql/php_mssql.c
ext/mysql/php_mysql.c
ext/mysqli/mysqli_api.c
ext/oci8/oci8.c
ext/odbc/php_odbc.c
ext/pcre/php_pcre.c
ext/pgsql/pgsql.c
ext/session/session.c
ext/standard/file.c
ext/standard/math.c
ext/standard/reg.c
ext/standard/string.c
ext/standard/var_unserializer.c
ext/standard/var_unserializer.re
ext/sybase/php_sybase_db.c
ext/sybase_ct/php_sybase_ct.c
ext/wddx/wddx.c
main/php_ini.c
main/safe_mode.c
sapi/apache/mod_php5.c
sapi/apache2filter/php_functions.c
sapi/apache2filter/sapi_apache2.c
sapi/apache2handler/php_functions.c
sapi/apache2handler/sapi_apache2.c
sapi/apache_hooks/mod_php5.c

index 22af4592ae85154c67f932f4d4b079537a9201fb..a5c0e3ed69b3d436d00f8f20cca1200112e833b5 100644 (file)
@@ -194,7 +194,7 @@ ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_cop
        switch (expr->type) {
                case IS_NULL:
                        expr_copy->value.str.len = 0;
-                       expr_copy->value.str.val = empty_string;
+                       expr_copy->value.str.val = STR_EMPTY_ALLOC();
                        break;
                case IS_BOOL:
                        if (expr->value.lval) {
@@ -202,7 +202,7 @@ ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_cop
                                expr_copy->value.str.val = estrndup("1", 1);
                        } else {
                                expr_copy->value.str.len = 0;
-                               expr_copy->value.str.val = empty_string;
+                               expr_copy->value.str.val = STR_EMPTY_ALLOC();
                        }
                        break;
                case IS_RESOURCE:
@@ -242,7 +242,7 @@ ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_cop
                                if (EG(exception)) {
                                        zval_dtor(expr_copy);
                                        expr_copy->value.str.len = 0;
-                                       expr_copy->value.str.val = empty_string;
+                                       expr_copy->value.str.val = STR_EMPTY_ALLOC();
                                        break;
                                }
                        }
index c9b58779b56e5ec4cfcf6657b47c871182c039e6..d3ad270795ce9d30d1c3086670f9a342ab5fbe4a 100644 (file)
@@ -460,22 +460,19 @@ void zend_post_deactivate_modules(TSRMLS_D);
 #define        Z_DBG(expr)
 #endif
 
-ZEND_API extern char *empty_string;
-
 BEGIN_EXTERN_C()
 ZEND_API void free_estring(char **str_p);
 END_EXTERN_C()
 
-#define STR_FREE(ptr) if (ptr && ptr!=empty_string) { efree(ptr); }
-#define STR_FREE_REL(ptr) if (ptr && ptr!=empty_string) { efree_rel(ptr); }
+/* FIXME: Check if we can save if (ptr) too */
 
-#define STR_REALLOC(ptr, size)                                                                         \
-       if (ptr!=empty_string) {                                                                                \
-               ptr = (char *) erealloc(ptr, size);                                                     \
-       } else {                                                                                                                \
-               ptr = (char *) emalloc(size);                                                           \
-               memset(ptr, 0, size);                                                                           \
-       }
+#define STR_FREE(ptr) if (ptr) { efree(ptr); }
+#define STR_FREE_REL(ptr) if (ptr) { efree_rel(ptr); }
+
+#define STR_EMPTY_ALLOC() estrndup("", sizeof("")-1)
+
+#define STR_REALLOC(ptr, size) \
+                       ptr = (char *) erealloc(ptr, size);
 
 /* output support */
 #define ZEND_WRITE(str, str_len)               zend_write((str), (str_len))
index 353b9385a48e949fe33735055d0266010690ddd9..313dd217ee3a105e3d5dbecc2538d77ac97faf7f 100644 (file)
@@ -385,7 +385,7 @@ END_EXTERN_C()
 
 #define ZVAL_EMPTY_STRING(z) {         \
                (z)->value.str.len = 0;             \
-               (z)->value.str.val = empty_string; \
+               (z)->value.str.val = STR_EMPTY_ALLOC(); \
                (z)->type = IS_STRING;              \
        }
 
index 6e93d6abed216802263e8a0ea0d1b5577a835cc4..7521787ab85efdd7e037e5223da0cd3b0aa661be 100644 (file)
@@ -119,8 +119,8 @@ ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZE
 #define perealloc_recoverable_rel(ptr, size, persistent) ((persistent)?realloc((ptr), (size)):erealloc_recoverable_rel((ptr), (size)))
 #define pestrdup_rel(s, persistent) ((persistent)?strdup(s):estrdup_rel(s))
 
-#define safe_estrdup(ptr)  ((ptr)?(estrdup(ptr)):(empty_string))
-#define safe_estrndup(ptr, len) ((ptr)?(estrndup((ptr), (len))):(empty_string))
+#define safe_estrdup(ptr)  ((ptr)?(estrdup(ptr)):STR_EMPTY_ALLOC())
+#define safe_estrndup(ptr, len) ((ptr)?(estrndup((ptr), (len))):STR_EMPTY_ALLOC())
 
 ZEND_API int zend_set_memory_limit(unsigned int memory_limit);
 
index a958a1be6014ca6cde7a5183adeef6e9d7f6df71..4acdcf2c9bab7463694a23b1eb36eeaa1878e165 100644 (file)
@@ -111,7 +111,7 @@ static inline zval *_get_zval_ptr(znode *node, temp_variable *Ts, zval **should_
                                        || ((int)T->str_offset.offset<0)
                                        || (T->str_offset.str->value.str.len <= T->str_offset.offset)) {
                                        zend_error(E_NOTICE, "Uninitialized string offset:  %d", T->str_offset.offset);
-                                       T->tmp_var.value.str.val = empty_string;
+                                       T->tmp_var.value.str.val = STR_EMPTY_ALLOC();
                                        T->tmp_var.value.str.len = 0;
                                } else {
                                        char c = str->value.str.val[T->str_offset.offset];
index 7965bb0eb3f0ce96e5b3dc19db57d96823a909fb..a1bfbe58f22f5cc304f888e94bfcc61da363af76 100644 (file)
@@ -939,7 +939,7 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty
                                        }
                                } else {
                                        MAKE_STD_ZVAL(retval);
-                                       ZVAL_STRINGL(retval, empty_string, 0, 0);
+                                       ZVAL_STRINGL(retval, "", 0, 1);
                                }
                                *writeobj = *retval;
                                zval_copy_ctor(writeobj);
index 96217df5b15df6cc68a9ec0fc158939e5b9c701b..8ef15ba102c2065b1273ed29d31bb717bd8abf9a 100644 (file)
@@ -510,7 +510,7 @@ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC)
 
        switch (op->type) {
                case IS_NULL:
-                       op->value.str.val = empty_string;
+                       op->value.str.val = STR_EMPTY_ALLOC();
                        op->value.str.len = 0;
                        break;
                case IS_STRING:
@@ -520,7 +520,7 @@ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC)
                                op->value.str.val = estrndup_rel("1", 1);
                                op->value.str.len = 1;
                        } else {
-                               op->value.str.val = empty_string;
+                               op->value.str.val = STR_EMPTY_ALLOC();
                                op->value.str.len = 0;
                        }
                        break;
@@ -1130,11 +1130,8 @@ ZEND_API int add_char_to_string(zval *result, zval *op1, zval *op2)
 ZEND_API int add_string_to_string(zval *result, zval *op1, zval *op2)
 {
        int length = op1->value.str.len + op2->value.str.len;
-       if (op1->value.str.val == empty_string) {
-               result->value.str.val = (char *) emalloc(length+1);
-       } else {
-               result->value.str.val = (char *) erealloc(op1->value.str.val, length+1);
-       }
+
+       result->value.str.val = (char *) erealloc(op1->value.str.val, length+1);
     memcpy(result->value.str.val+op1->value.str.len, op2->value.str.val, op2->value.str.len);
     result->value.str.val[length] = 0;
        result->value.str.len = length;
@@ -1167,12 +1164,8 @@ ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
        if (result==op1) {      /* special case, perform operations on result */
                uint res_len = op1->value.str.len + op2->value.str.len;
                
-               if (result->value.str.len == 0) { /* handle empty_string */
-                       STR_FREE(result->value.str.val);
-                       result->value.str.val = emalloc(res_len+1);
-               } else {
-                       result->value.str.val = erealloc(result->value.str.val, res_len+1);
-               }
+               result->value.str.val = erealloc(result->value.str.val, res_len+1);
+
                memcpy(result->value.str.val+result->value.str.len, op2->value.str.val, op2->value.str.len);
                result->value.str.val[res_len]=0;
                result->value.str.len = res_len;
index e6fbd5342c3813d35a24b56f9aefd647c6970d54..f147136a4d3dc28b8663c996f416384cc7b077eb 100644 (file)
 #include "zend_constants.h"
 #include "zend_list.h"
 
-ZEND_API char *empty_string = "";      /* in order to save emalloc() and efree() time for
-                                                                        * empty strings (usually used to denote empty
-                                                                        * return values in failed functions).
-                                                                        * The macro STR_FREE() will not efree() it.
-                                                                        */
-
 
 ZEND_API void _zval_dtor(zval *zvalue ZEND_FILE_LINE_DC)
 {
@@ -86,9 +80,7 @@ ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC)
                case IS_STRING:
                case IS_CONSTANT:
                        CHECK_ZVAL_STRING_REL(zvalue);
-                       if (zvalue->value.str.val != empty_string) {
-                               free(zvalue->value.str.val);
-                       }
+                       free(zvalue->value.str.val);
                        break;
                case IS_ARRAY:
                case IS_CONSTANT_ARRAY:
@@ -127,12 +119,6 @@ ZEND_API int _zval_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC)
                        break;
                case IS_CONSTANT:
                case IS_STRING:
-                       if (zvalue->value.str.val) {
-                               if (zvalue->value.str.len==0) {
-                                       zvalue->value.str.val = empty_string;
-                                       return SUCCESS;
-                               }
-                       }
                        CHECK_ZVAL_STRING_REL(zvalue);
                        zvalue->value.str.val = (char *) estrndup_rel(zvalue->value.str.val, zvalue->value.str.len);
                        break;
index cf8e15cd95b22cb5663b44d5ce88cf324ee8a97e..02d19035390eddeae305c0ae7734ebab98a7af65 100644 (file)
@@ -428,7 +428,7 @@ static void php_ereg_replace(INTERNAL_FUNCTION_PARAMETERS, int icase)
                if (Z_STRVAL_PP(arg_pattern) && Z_STRLEN_PP(arg_pattern))
                        pattern = estrndup(Z_STRVAL_PP(arg_pattern), Z_STRLEN_PP(arg_pattern));
                else
-                       pattern = empty_string;
+                       pattern = STR_EMPTY_ALLOC();
        } else {
                convert_to_long_ex(arg_pattern);
                pattern = emalloc(2);
@@ -440,7 +440,7 @@ static void php_ereg_replace(INTERNAL_FUNCTION_PARAMETERS, int icase)
                if (Z_STRVAL_PP(arg_replace) && Z_STRLEN_PP(arg_replace))
                        replace = estrndup(Z_STRVAL_PP(arg_replace), Z_STRLEN_PP(arg_replace));
                else
-                       replace = empty_string;
+                       replace = STR_EMPTY_ALLOC();
        } else {
                convert_to_long_ex(arg_replace);
                replace = emalloc(2);
@@ -452,7 +452,7 @@ static void php_ereg_replace(INTERNAL_FUNCTION_PARAMETERS, int icase)
        if (Z_STRVAL_PP(arg_string) && Z_STRLEN_PP(arg_string))
                string = estrndup(Z_STRVAL_PP(arg_string), Z_STRLEN_PP(arg_string));
        else
-               string = empty_string;
+               string = STR_EMPTY_ALLOC();
 
        /* do the actual work */
        ret = php_reg_replace(pattern, replace, string, icase, 1);
@@ -527,7 +527,7 @@ static void php_split(INTERNAL_FUNCTION_PARAMETERS, int icase)
        while ((count == -1 || count > 1) && !(err = regexec(&re, strp, 1, subs, 0))) {
                if (subs[0].rm_so == 0 && subs[0].rm_eo) {
                        /* match is at start of string, return empty string */
-                       add_next_index_stringl(return_value, empty_string, 0, 1);
+                       add_next_index_stringl(return_value, "", 0, 1);
                        /* skip ahead the length of the regex match */
                        strp += subs[0].rm_eo;
                } else if (subs[0].rm_so == 0 && subs[0].rm_eo == 0) {
index 9627d2cdf393c7508c66fa07acb5e789abe45865..1476e5ee3847394e24a2ca518cca6324c2158d31 100644 (file)
@@ -1709,7 +1709,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
        }
 
        if ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))) {
-               if (!fn || fn == empty_string || php_check_open_basedir(fn TSRMLS_CC)) {
+               if (!fn || php_check_open_basedir(fn TSRMLS_CC)) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid filename '%s'", fn);
                        RETURN_FALSE;
                }
@@ -3825,13 +3825,13 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
        }
 
        /* Check origin file */
-       if (!fn_org || fn_org == empty_string || php_check_open_basedir(fn_org TSRMLS_CC)) {
+       if (!fn_org || php_check_open_basedir(fn_org TSRMLS_CC)) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid origin filename '%s'", fn_org);
                RETURN_FALSE;
        }
 
        /* Check destination file */
-       if (!fn_dest || fn_dest == empty_string || php_check_open_basedir(fn_dest TSRMLS_CC)) {
+       if (!fn_dest || php_check_open_basedir(fn_dest TSRMLS_CC)) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid destination filename '%s'", fn_dest);
                RETURN_FALSE;
        }
index 6fb7b84ce4d7c1422cdb46b3022175e40596bc32..b27ee45856cc6652ae4c31eae7d745a0b542c177 100644 (file)
@@ -82,7 +82,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
        }
 
        if ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))) {
-               if (!fn || fn == empty_string || php_check_open_basedir(fn TSRMLS_CC)) {
+               if (!fn || php_check_open_basedir(fn TSRMLS_CC)) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid filename '%s'", fn);
                        RETURN_FALSE;
                }
index b1543f290928cde8121e6b9da6d1defb398c4229..fdf9195b5faadbdcf1bbccf5d0055edc472f1db0 100644 (file)
@@ -864,7 +864,7 @@ PHP_FUNCTION(mb_split)
        if (n > 0) {
                add_next_index_stringl(return_value, pos, n, 1);
        } else {
-               add_next_index_stringl(return_value, empty_string, 0, 1);
+               add_next_index_stringl(return_value, "", 0, 1);
        }
 }
 /* }}} */
index f9a9e19feb176b2b711538d6fa949d940319cb4a..93522865b27160ecb80ad2f7c0c9bc1dee268179 100644 (file)
@@ -959,7 +959,7 @@ static void php_msql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
                        }
                } else {
                        /*
-                       add_get_index_stringl(return_value, i, empty_string, 0, (void **) &pval_ptr, 1);
+                       add_get_index_stringl(return_value, i, "", 0, (void **) &pval_ptr, 1);
                        */
                }
        }
@@ -1097,8 +1097,8 @@ PHP_FUNCTION(msql_fetch_field)
        }
        object_init(return_value);
 
-       add_property_string(return_value, "name",(msql_field->name?msql_field->name:empty_string), 1);
-       add_property_string(return_value, "table",(msql_field->table?msql_field->table:empty_string), 1);
+       add_property_string(return_value, "name",(msql_field->name?msql_field->name:""), 1);
+       add_property_string(return_value, "table",(msql_field->table?msql_field->table:""), 1);
        add_property_long(return_value, "not_null",IS_NOT_NULL(msql_field->flags));
 #if MSQL1
        add_property_long(return_value, "primary_key",(msql_field->flags&PRI_KEY_FLAG?1:0));
index 9930d3d0e4ee8603c588862218b3262b6588b4d6..9f8dd183b34e3af622de54346cf3b28a53f5c704 100644 (file)
@@ -333,7 +333,7 @@ PHP_RINIT_FUNCTION(mssql)
        MS_SQL_G(default_link) = -1;
        MS_SQL_G(num_links) = MS_SQL_G(num_persistent);
        MS_SQL_G(appname) = estrndup("PHP 5", 5);
-       MS_SQL_G(server_message) = empty_string;
+       MS_SQL_G(server_message) = NULL;
        MS_SQL_G(min_error_severity) = MS_SQL_G(cfg_min_error_severity);
        MS_SQL_G(min_message_severity) = MS_SQL_G(cfg_min_message_severity);
        if (MS_SQL_G(connect_timeout) < 1) MS_SQL_G(connect_timeout) = 1;
@@ -1045,7 +1045,7 @@ static int _mssql_fetch_batch(mssql_link *mssql_ptr, mssql_result *result, int r
                        result->fields[i].column_source = estrdup(source);
                }
                else {
-                       result->fields[i].column_source = empty_string;
+                       result->fields[i].column_source = STR_EMPTY_ALLOC();
                }
 
                column_types[i] = coltype(i+1);
@@ -1267,7 +1267,7 @@ PHP_FUNCTION(mssql_get_last_message)
                RETURN_STRING(MS_SQL_G(server_message),1);
        }
        else {
-               RETURN_STRING(empty_string,1);
+               RETURN_STRING("",1);
        }
 }
 
index 11dae416329dfb862d19ab1ed2a2029781b97a50..f8da8c8ea53e8a9c0957c07fd4682a7944a22f5f 100644 (file)
@@ -2245,9 +2245,9 @@ PHP_FUNCTION(mysql_fetch_field)
        }
        object_init(return_value);
 
-       add_property_string(return_value, "name",(mysql_field->name?mysql_field->name:empty_string), 1);
-       add_property_string(return_value, "table",(mysql_field->table?mysql_field->table:empty_string), 1);
-       add_property_string(return_value, "def",(mysql_field->def?mysql_field->def:empty_string), 1);
+       add_property_string(return_value, "name",(mysql_field->name?mysql_field->name:""), 1);
+       add_property_string(return_value, "table",(mysql_field->table?mysql_field->table:""), 1);
+       add_property_string(return_value, "def",(mysql_field->def?mysql_field->def:""), 1);
        add_property_long(return_value, "max_length", mysql_field->max_length);
        add_property_long(return_value, "not_null", IS_NOT_NULL(mysql_field->flags)?1:0);
        add_property_long(return_value, "primary_key", IS_PRI_KEY(mysql_field->flags)?1:0);
index b6dbc0efc0f71bbf9635fb8403a45606055994e3..4f6a80ad0532120a4f4fcbb674d07f826a202263 100644 (file)
@@ -906,7 +906,7 @@ PHP_FUNCTION(mysqli_get_host_info)
        }
        MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link");
 
-       RETURN_STRING((mysql->mysql->host_info) ? mysql->mysql->host_info : empty_string, 1);
+       RETURN_STRING((mysql->mysql->host_info) ? mysql->mysql->host_info : "", 1);
 }
 /* }}} */
 
@@ -971,7 +971,7 @@ PHP_FUNCTION(mysqli_info)
        }
        MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link");
 
-       RETURN_STRING((mysql->mysql->info) ? mysql->mysql->info : empty_string, 1);
+       RETURN_STRING((mysql->mysql->info) ? mysql->mysql->info : "", 1);
 }
 /* }}} */
 
index 597b177a49b10c3c5e98993e18d6273edfef71c7..3f46fb4e33098be8091b1020253d9ef8d8684492 100644 (file)
@@ -880,12 +880,12 @@ static int _oci_bind_post_exec(void *data TSRMLS_DC)
 
        if (bind->indicator == -1) { /* NULL */
                zval *val = bind->zval;
-               if (Z_TYPE_P(val) == IS_STRING && (Z_STRVAL_P(val) != empty_string)) {
+               if (Z_TYPE_P(val) == IS_STRING)) {
                        *Z_STRVAL_P(val) = '\0'; /* XXX avoid warning in debug mode */
                }
                zval_dtor(val);
                ZVAL_NULL(val);
-       } else if (Z_TYPE_P(bind->zval) == IS_STRING && (Z_STRVAL_P(bind->zval) != empty_string)) {
+       } else if (Z_TYPE_P(bind->zval) == IS_STRING) {
                Z_STRVAL_P(bind->zval) = erealloc(Z_STRVAL_P(bind->zval), Z_STRLEN_P(bind->zval)+1);
                Z_STRVAL_P(bind->zval)[ Z_STRLEN_P(bind->zval) ] = '\0';
        }
index 0908ce6a5bdab4abc024f46e84eff186564f61c1..7e98b1cf05c5f470ef8223dc4d1b193fcda922b3 100644 (file)
@@ -1421,13 +1421,13 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
                        case SQL_VARBINARY:
                        case SQL_LONGVARBINARY:
                                if (result->binmode <= 0) {
-                                       Z_STRVAL_P(tmp) = empty_string;
+                                       Z_STRVAL_P(tmp) = STR_EMPTY_ALLOC();
                                        break;
                                }
                                if (result->binmode == 1) sql_c_type = SQL_C_BINARY;
                        case SQL_LONGVARCHAR:
                                if (IS_SQL_LONG(result->values[i].coltype) && result->longreadlen <= 0) {
-                                       Z_STRVAL_P(tmp) = empty_string;
+                                       Z_STRVAL_P(tmp) = STR_EMPTY_ALLOC();
                                        break;
                                }
                                if (buf == NULL) buf = emalloc(result->longreadlen + 1);
@@ -1580,13 +1580,13 @@ PHP_FUNCTION(odbc_fetch_into)
                        case SQL_VARBINARY:
                        case SQL_LONGVARBINARY:
                                if (result->binmode <= 0) {
-                                       Z_STRVAL_P(tmp) = empty_string;
+                                       Z_STRVAL_P(tmp) = STR_EMPTY_ALLOC();
                                        break;
                                }
                                if (result->binmode == 1) sql_c_type = SQL_C_BINARY; 
                        case SQL_LONGVARCHAR:
                                if (IS_SQL_LONG(result->values[i].coltype) && result->longreadlen <= 0) {
-                                       Z_STRVAL_P(tmp) = empty_string;
+                                       Z_STRVAL_P(tmp) = STR_EMPTY_ALLOC();
                                        break;
                                }
 
index f489291ccb7f5af1e0fc422a217e8f18df81f9d1..52ceb6f727cda114470afcaf22b1bb3642c87d2e 100644 (file)
@@ -511,7 +511,7 @@ static void php_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global)
                                                 */
                                                if (count < num_subpats) {
                                                        for (; i < num_subpats; i++) {
-                                                               add_next_index_string(match_sets[i], empty_string, 1);
+                                                               add_next_index_string(match_sets[i], "", 1);
                                                        }
                                                }
                                        } else {
@@ -734,7 +734,7 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject,
                                                esc_match_len = 0;
                                        }
                                } else {
-                                       esc_match = empty_string;
+                                       esc_match = "";
                                        esc_match_len = 0;
                                        match_len = 0;
                                }
@@ -1005,7 +1005,8 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject,
 
        /* Make sure we're dealing with strings. */     
        convert_to_string_ex(subject);
-       ZVAL_STRINGL(&empty_replace, empty_string, 0, 0);
+       /* FIXME: This might need to be changed to STR_EMPTY_ALLOC(). Check if this zval could be dtor()'ed somehow */
+       ZVAL_STRINGL(&empty_replace, "", 0, 0);
        
        /* If regex is an array */
        if (Z_TYPE_P(regex) == IS_ARRAY) {
@@ -1389,7 +1390,7 @@ PHP_FUNCTION(preg_quote)
 
        /* Nothing to do if we got an empty string */
        if (in_str == in_str_end) {
-               RETVAL_STRINGL(empty_string, 0, 0);
+               RETVAL_STRINGL("", 0, 1);
        }
 
        if (ZEND_NUM_ARGS() == 2) {
index 414e2050ecd9f35409ab6ca8bce94b0fee5093f1..786be839fc7b0af9b0a92bcaf1e2997d0eaa984c 100644 (file)
@@ -1214,7 +1214,7 @@ static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list TSRMLS_DC)
                                PQclear(result);
                        }
                        smart_str_free(&str);
-                       return empty_string;
+                       return STR_EMPTY_ALLOC();
                }
                num_rows = PQntuples(result);
                oid_offset = PQfnumber(result,"oid");
@@ -1786,7 +1786,7 @@ PHP_FUNCTION(pg_last_oid)
        if (Z_STRVAL_P(return_value)) {
                RETURN_STRING(Z_STRVAL_P(return_value), 1);
        }
-       RETURN_STRING(empty_string, 0);
+       RETURN_STRING("", 1);
 #endif
 }
 /* }}} */
index 135a732253ac6e72cfcc609c428c2f297ab526de..f5efc8ba9df9e686f3afa2b20221b1e0bf17573c 100644 (file)
@@ -1060,7 +1060,7 @@ static void php_session_reset_id(TSRMLS_D)
                smart_str_0(&var);
                REGISTER_STRINGL_CONSTANT("SID", var.c, var.len, 0);
        } else {
-               REGISTER_STRINGL_CONSTANT("SID", empty_string, 0, 0);
+               REGISTER_STRINGL_CONSTANT("SID", "", 0, 1);
        }
 
        if (PS(apply_trans_sid)) {
@@ -1370,13 +1370,16 @@ PHP_FUNCTION(session_id)
 {
        zval **p_name;
        int ac = ZEND_NUM_ARGS();
-       char *old = empty_string;
+       char *old;
 
        if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
                WRONG_PARAM_COUNT;
 
-       if (PS(id))
+       if (PS(id)) {
                old = estrdup(PS(id));
+       } else {
+               old = STR_EMPTY_ALLOC();
+       }
 
        if (ac == 1) {
                convert_to_string_ex(p_name);
index 6041fa4249fab984812011a61cd33a7e171c5979..b3af5a20c0ab9c856e6c06e7cff2471fe2fdd6d7 100644 (file)
@@ -416,7 +416,7 @@ PHP_FUNCTION(get_meta_tags)
                                if (have_content) {
                                        add_assoc_string(return_value, name, value, 0); 
                                } else {
-                                       add_assoc_string(return_value, name, empty_string, 0);
+                                       add_assoc_string(return_value, name, "", 0);
                                }
 
                                efree(name);
index 1ab898569b7caa76cb8d362fd009f07912bdb4c5..8a2b3ecec1e996cfd719b3b8d43bd53d71de6b49 100644 (file)
@@ -791,7 +791,7 @@ _php_math_longtobase(zval *arg, int base)
        unsigned long value;
 
        if (Z_TYPE_P(arg) != IS_LONG || base < 2 || base > 36) {
-               return empty_string;
+               return STR_EMPTY_ALLOC();
        }
 
        value = Z_LVAL_P(arg);
@@ -820,7 +820,7 @@ _php_math_zvaltobase(zval *arg, int base TSRMLS_DC)
        static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
 
        if ((Z_TYPE_P(arg) != IS_LONG && Z_TYPE_P(arg) != IS_DOUBLE) || base < 2 || base > 36) {
-               return empty_string;
+               return STR_EMPTY_ALLOC();
        }
 
        if (Z_TYPE_P(arg) == IS_DOUBLE) {
@@ -831,7 +831,7 @@ _php_math_zvaltobase(zval *arg, int base TSRMLS_DC)
                /* Don't try to convert +/- infinity */
                if (fvalue == HUGE_VAL || fvalue == -HUGE_VAL) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number too large");
-                       return empty_string;
+                       return STR_EMPTY_ALLOC();
                }
 
                end = ptr = buf + sizeof(buf) - 1;
index cf8e15cd95b22cb5663b44d5ce88cf324ee8a97e..02d19035390eddeae305c0ae7734ebab98a7af65 100644 (file)
@@ -428,7 +428,7 @@ static void php_ereg_replace(INTERNAL_FUNCTION_PARAMETERS, int icase)
                if (Z_STRVAL_PP(arg_pattern) && Z_STRLEN_PP(arg_pattern))
                        pattern = estrndup(Z_STRVAL_PP(arg_pattern), Z_STRLEN_PP(arg_pattern));
                else
-                       pattern = empty_string;
+                       pattern = STR_EMPTY_ALLOC();
        } else {
                convert_to_long_ex(arg_pattern);
                pattern = emalloc(2);
@@ -440,7 +440,7 @@ static void php_ereg_replace(INTERNAL_FUNCTION_PARAMETERS, int icase)
                if (Z_STRVAL_PP(arg_replace) && Z_STRLEN_PP(arg_replace))
                        replace = estrndup(Z_STRVAL_PP(arg_replace), Z_STRLEN_PP(arg_replace));
                else
-                       replace = empty_string;
+                       replace = STR_EMPTY_ALLOC();
        } else {
                convert_to_long_ex(arg_replace);
                replace = emalloc(2);
@@ -452,7 +452,7 @@ static void php_ereg_replace(INTERNAL_FUNCTION_PARAMETERS, int icase)
        if (Z_STRVAL_PP(arg_string) && Z_STRLEN_PP(arg_string))
                string = estrndup(Z_STRVAL_PP(arg_string), Z_STRLEN_PP(arg_string));
        else
-               string = empty_string;
+               string = STR_EMPTY_ALLOC();
 
        /* do the actual work */
        ret = php_reg_replace(pattern, replace, string, icase, 1);
@@ -527,7 +527,7 @@ static void php_split(INTERNAL_FUNCTION_PARAMETERS, int icase)
        while ((count == -1 || count > 1) && !(err = regexec(&re, strp, 1, subs, 0))) {
                if (subs[0].rm_so == 0 && subs[0].rm_eo) {
                        /* match is at start of string, return empty string */
-                       add_next_index_stringl(return_value, empty_string, 0, 1);
+                       add_next_index_stringl(return_value, "", 0, 1);
                        /* skip ahead the length of the regex match */
                        strp += subs[0].rm_eo;
                } else if (subs[0].rm_so == 0 && subs[0].rm_eo == 0) {
index 7a7020b852995580798ea23cff7134e928581d77..3eb4e8f707d145e12e3a898858a2eebfff097ecc 100644 (file)
@@ -3206,7 +3206,7 @@ static void php_str_replace_in_subject(zval *search, zval *replace, zval **subje
        convert_to_string_ex(subject);
        Z_TYPE_P(result) = IS_STRING;
        if (Z_STRLEN_PP(subject) == 0) {
-               ZVAL_STRINGL(result, empty_string, 0, 1);
+               ZVAL_STRINGL(result, "", 0, 1);
                return;
        }
        
@@ -3254,7 +3254,7 @@ static void php_str_replace_in_subject(zval *search, zval *replace, zval **subje
                                        zend_hash_move_forward(Z_ARRVAL_P(replace));
                                } else {
                                        /* We've run out of replacement strings, so use an empty one. */
-                                       replace_value = empty_string;
+                                       replace_value = "";
                                        replace_len = 0;
                                }
                        }
@@ -4186,11 +4186,11 @@ PHP_FUNCTION(str_repeat)
 
        /* Don't waste our time if it's empty */
        if (Z_STRLEN_PP(input_str) == 0)
-               RETURN_STRINGL(empty_string, 0, 1);
+               RETURN_STRINGL("", 0, 1);
        
        /* ... or if the multiplier is zero */
        if (Z_LVAL_PP(mult) == 0)
-               RETURN_STRINGL(empty_string, 0, 1);
+               RETURN_STRINGL("", 0, 1);
        
        /* Initialize the result string */      
        result_len = Z_STRLEN_PP(input_str) * Z_LVAL_PP(mult);
index 261c1fc79138a43a34cebff85c5732333498346b..649661bcaee196fc8676efef7cf45d90f1e60aad 100644 (file)
@@ -605,11 +605,7 @@ yy44:
 
        len = parse_iv(start + 2);
 
-       if (len == 0) {
-               str = empty_string;
-       } else {
-               str = estrndup(YYCURSOR, len);
-       }
+       str = estrndup(YYCURSOR, len);
 
        YYCURSOR += len + 2;
        *p = YYCURSOR;
index 6ae7424b7778b07aa4a3a8647a9bbe00fc35ce76..e42af889f856006fbf1a9eb6693ce1f1b5b29b8a 100644 (file)
@@ -350,11 +350,7 @@ PHPAPI int php_var_unserialize(UNSERIALIZE_PARAMETER)
 
        len = parse_iv(start + 2);
 
-       if (len == 0) {
-               str = empty_string;
-       } else {
-               str = estrndup(YYCURSOR, len);
-       }
+       str = estrndup(YYCURSOR, len);
 
        YYCURSOR += len + 2;
        *p = YYCURSOR;
index f2c98c76408e3f3cc4bb12e6d8d7c4b19caa000c..a6f0886f864b39d09651472fab807db10ea31e23 100644 (file)
@@ -282,7 +282,7 @@ PHP_RINIT_FUNCTION(sybase)
        php_sybase_module.default_link=-1;
        php_sybase_module.num_links = php_sybase_module.num_persistent;
        php_sybase_module.appname = estrndup("PHP " PHP_VERSION, sizeof("PHP " PHP_VERSION));
-       php_sybase_module.server_message = empty_string;
+       php_sybase_module.server_message = STR_EMPTY_ALLOC();
        php_sybase_module.min_error_severity = php_sybase_module.cfg_min_error_severity;
        php_sybase_module.min_message_severity = php_sybase_module.cfg_min_message_severity;
        return SUCCESS;
@@ -886,7 +886,7 @@ PHP_FUNCTION(sybase_query)
                result->fields[i].max_length = dbcollen(sybase_ptr->link,i+1);
                result->fields[i].column_source = estrdup(dbcolsource(sybase_ptr->link,i+1));
                if (!result->fields[i].column_source) {
-                       result->fields[i].column_source = empty_string;
+                       result->fields[i].column_source = STR_EMPTY_ALLOC();
                }
                Z_TYPE(result->fields[i]) = column_types[i];
                /* set numeric flag */
index 43dca5df2a5cf8b60c87ea54a7b38bf1a6794737..a7593685bee16fd14682d9d5a368079926aa43bf 100644 (file)
@@ -428,7 +428,7 @@ PHP_RINIT_FUNCTION(sybase)
        SybCtG(default_link)=-1;
        SybCtG(num_links) = SybCtG(num_persistent);
        SybCtG(appname) = estrndup("PHP " PHP_VERSION, sizeof("PHP " PHP_VERSION));
-       SybCtG(server_message) = empty_string;
+       SybCtG(server_message) = STR_EMPTY_ALLOC();
        return SUCCESS;
 }
 
@@ -1274,7 +1274,7 @@ static sybase_result * php_sybase_fetch_result_set (sybase_link *sybase_ptr, int
                        result->fields[i].name = estrdup(computed_buf);
                        j++;
                }
-               result->fields[i].column_source = empty_string;
+               result->fields[i].column_source = STR_EMPTY_ALLOC();
                result->fields[i].max_length = result->datafmt[i].maxlength-1;
                result->fields[i].numeric = result->numerics[i];
                Z_TYPE(result->fields[i]) = result->types[i];
index 33dbfbd9fd1e7566bde7330dae24e191ee5a7533..59c518850525579ba85c5be3f4a8e2277d0d10d6 100644 (file)
@@ -710,7 +710,7 @@ static void php_wddx_push_element(void *user_data, const XML_Char *name, const X
                ALLOC_ZVAL(ent.data);
                INIT_PZVAL(ent.data);
                Z_TYPE_P(ent.data) = IS_STRING;
-               Z_STRVAL_P(ent.data) = empty_string;
+               Z_STRVAL_P(ent.data) = STR_EMPTY_ALLOC();
                Z_STRLEN_P(ent.data) = 0;
                wddx_stack_push((wddx_stack *)stack, &ent, sizeof(st_entry));
        } else if (!strcmp(name, EL_BINARY)) {
@@ -720,7 +720,7 @@ static void php_wddx_push_element(void *user_data, const XML_Char *name, const X
                ALLOC_ZVAL(ent.data);
                INIT_PZVAL(ent.data);
                Z_TYPE_P(ent.data) = IS_STRING;
-               Z_STRVAL_P(ent.data) = empty_string;
+               Z_STRVAL_P(ent.data) = STR_EMPTY_ALLOC();
                Z_STRLEN_P(ent.data) = 0;
                wddx_stack_push((wddx_stack *)stack, &ent, sizeof(st_entry));
        } else if (!strcmp(name, EL_CHAR)) {
index 5fb95c71d82b493b5ccd52067518cf263e3285b2..35542ef63d7cf2559e99da6160a1a1e5de33e2dc 100644 (file)
@@ -170,7 +170,7 @@ PHPAPI void display_ini_entries(zend_module_entry *module)
  */
 static void pvalue_config_destructor(zval *pvalue)
 {   
-       if (Z_TYPE_P(pvalue) == IS_STRING && Z_STRVAL_P(pvalue) != empty_string) {
+       if (Z_TYPE_P(pvalue) == IS_STRING) {
                free(Z_STRVAL_P(pvalue));
        }
 }
index 9271610f9bdf223fa55c9a236300b2c490182572..0412433b22e9c3210d5364607877be134845b122 100644 (file)
@@ -207,11 +207,11 @@ PHPAPI char *php_get_current_user()
        pstat = sapi_get_stat(TSRMLS_C);
 
        if (!pstat) {
-               return empty_string;
+               return "";
        }
 
        if ((pwd=getpwuid(pstat->st_uid))==NULL) {
-               return empty_string;
+               return "";
        }
        SG(request_info).current_user_length = strlen(pwd->pw_name);
        SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
index 4aac2d2862447b61ebfd227e307934dcf913c7ca..083cc8be565bafa05edefa787a8203562ab36632 100644 (file)
@@ -235,7 +235,7 @@ static void sapi_apache_register_server_variables(zval *track_vars_array TSRMLS_
                if (elts[i].val) {
                        val = elts[i].val;
                } else {
-                       val = empty_string;
+                       val = "";
                }
                php_register_variable(elts[i].key, val, track_vars_array  TSRMLS_CC);
        }
index 5e160ce47aa445a2b8f7b2d649dedeadbfac3ab8..b3ac9c2c099569bc1e12a02a926fdc7304ba742c 100644 (file)
@@ -165,7 +165,7 @@ PHP_FUNCTION(apache_request_headers)
        arr = apr_table_elts(ctx->f->r->headers_in);
 
        APR_ARRAY_FOREACH_OPEN(arr, key, val)
-               if (!val) val = empty_string;
+               if (!val) val = "";
                add_assoc_string(return_value, key, val, 1);
        APR_ARRAY_FOREACH_CLOSE()
 }
@@ -185,7 +185,7 @@ PHP_FUNCTION(apache_response_headers)
        arr = apr_table_elts(ctx->f->r->headers_out);
 
        APR_ARRAY_FOREACH_OPEN(arr, key, val)
-               if (!val) val = empty_string;
+               if (!val) val = "";
                add_assoc_string(return_value, key, val, 1);
        APR_ARRAY_FOREACH_CLOSE()
 }
index d9eee97493c75917371dfb6ecf928f3c882a125a..cf6bec19339ebfe560e08f70bdde54f5e8fdbc78 100644 (file)
@@ -220,7 +220,7 @@ php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC)
        char *key, *val;
        
        APR_ARRAY_FOREACH_OPEN(arr, key, val)
-               if (!val) val = empty_string;
+               if (!val) val = "";
                php_register_variable(key, val, track_vars_array TSRMLS_CC);
        APR_ARRAY_FOREACH_CLOSE()
                
index eeba18a691994f4b0c0be91f19b4d0394e53c9e0..fca55d9c33020faafc20ccb4d8df550a61433ecd 100644 (file)
@@ -183,7 +183,7 @@ PHP_FUNCTION(apache_request_headers)
        arr = apr_table_elts(ctx->r->headers_in);
 
        APR_ARRAY_FOREACH_OPEN(arr, key, val)
-               if (!val) val = empty_string;
+               if (!val) val = "";
                add_assoc_string(return_value, key, val, 1);
        APR_ARRAY_FOREACH_CLOSE()
 }
@@ -203,7 +203,7 @@ PHP_FUNCTION(apache_response_headers)
        arr = apr_table_elts(ctx->r->headers_out);
 
        APR_ARRAY_FOREACH_OPEN(arr, key, val)
-               if (!val) val = empty_string;
+               if (!val) val = "";
                add_assoc_string(return_value, key, val, 1);
        APR_ARRAY_FOREACH_CLOSE()
 }
@@ -423,7 +423,7 @@ PHP_MINFO_FUNCTION(apache)
                php_info_print_table_header(2, "Variable", "Value");
                APR_ARRAY_FOREACH_OPEN(arr, key, val)
                        if (!val) {
-                               val = empty_string;
+                               val = "";
                        }
                        php_info_print_table_row(2, key, val);
                APR_ARRAY_FOREACH_CLOSE()
@@ -438,7 +438,7 @@ PHP_MINFO_FUNCTION(apache)
                arr = apr_table_elts(((php_struct *) SG(server_context))->r->headers_in);
                APR_ARRAY_FOREACH_OPEN(arr, key, val)
                        if (!val) {
-                               val = empty_string;
+                               val = "";
                        }
                        php_info_print_table_row(2, key, val);
                APR_ARRAY_FOREACH_CLOSE()
@@ -447,7 +447,7 @@ PHP_MINFO_FUNCTION(apache)
                arr = apr_table_elts(((php_struct *) SG(server_context))->r->headers_out);
                APR_ARRAY_FOREACH_OPEN(arr, key, val)
                        if (!val) {
-                               val = empty_string;
+                               val = "";
                        }
                        php_info_print_table_row(2, key, val);
                APR_ARRAY_FOREACH_CLOSE()
index f5b133bcc1bf475b603bb6f248762ea097a02c4d..e7e9571044cc169c8eaaabafcbcce412792a9d96 100644 (file)
@@ -215,7 +215,7 @@ php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC)
        char *key, *val;
        
        APR_ARRAY_FOREACH_OPEN(arr, key, val)
-               if (!val) val = empty_string;
+               if (!val) val = "";
                php_register_variable(key, val, track_vars_array TSRMLS_CC);
        APR_ARRAY_FOREACH_CLOSE()
                
index 516a465c2bb92369505aa7bf35b3171f8d14fd42..53beeb094358ae42da26af1b5652340c8b959458 100644 (file)
@@ -382,7 +382,7 @@ static void sapi_apache_register_server_variables(zval *track_vars_array TSRMLS_
                if (elts[i].val) {
                        val = elts[i].val;
                } else {
-                       val = empty_string;
+                       val = "";
                }
                php_register_variable(elts[i].key, val, track_vars_array  TSRMLS_CC);
        }