- Nuke empty_string. It is a reminanent from the time where RETURN_FALSE()

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.
This commit is contained in:
Andi Gutmans 2004-07-19 07:19:50 +00:00
parent 599ae4b1b5
commit 56f8195fe5
38 changed files with 96 additions and 124 deletions

View 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;
}
}

View 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))

View 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; \
}

View 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);

View 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];

View 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);

View 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;

View File

@ -26,12 +26,6 @@
#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;

View 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) {

View 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;
}

View 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;
}

View 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);
}
}
/* }}} */

View 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));

View 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);
}
}

View 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);

View 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);
}
/* }}} */

View 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';
}

View 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;
}

View 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) {

View 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
}
/* }}} */

View 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);

View 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);

View 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;

View 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) {

View 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);

View 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;

View 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;

View 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 */

View 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];

View 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)) {

View 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));
}
}

View 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);

View 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);
}

View 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()
}

View 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()

View 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()

View 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()

View 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);
}