Optimize zend_string_realloc() add more specialized versions zend_string_extend() and zend_string_truncate()

This commit is contained in:
Dmitry Stogov 2015-03-20 02:02:42 +03:00
parent 184793b5c1
commit d146d15003
28 changed files with 114 additions and 74 deletions

View File

@ -1500,7 +1500,7 @@ zend_ast *zend_ast_append_str(zend_ast *left_ast, zend_ast *right_ast) /* {{{ */
size_t left_len = left->len;
size_t len = left_len + right->len + 1; /* left\right */
result = zend_string_realloc(left, len, 0);
result = zend_string_extend(left, len, 0);
result->val[left_len] = '\\';
memcpy(&result->val[left_len + 1], right->val, right->len);
result->val[len] = '\0';
@ -5225,7 +5225,7 @@ static zend_bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast) /* {{{ */
zend_dirname(dirname->val, dirname->len);
if (strcmp(dirname->val, ".") == 0) {
dirname = zend_string_realloc(dirname, MAXPATHLEN, 0);
dirname = zend_string_extend(dirname, MAXPATHLEN, 0);
#if HAVE_GETCWD
VCWD_GETCWD(dirname->val, MAXPATHLEN);
#elif HAVE_GETWD

View File

@ -1136,7 +1136,7 @@ static void zend_assign_to_string_offset(zval *str, zend_long offset, zval *valu
old_str = Z_STR_P(str);
if ((size_t)offset >= Z_STRLEN_P(str)) {
zend_long old_len = Z_STRLEN_P(str);
Z_STR_P(str) = zend_string_realloc(Z_STR_P(str), offset + 1, 0);
Z_STR_P(str) = zend_string_extend(Z_STR_P(str), offset + 1, 0);
Z_TYPE_INFO_P(str) = IS_STRING_EX;
memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
Z_STRVAL_P(str)[offset+1] = 0;

View File

@ -105,7 +105,7 @@ static void zend_ini_add_string(zval *result, zval *op1, zval *op2)
int op1_len = (int)Z_STRLEN_P(op1);
int length = op1_len + (int)Z_STRLEN_P(op2);
ZVAL_NEW_STR(result, zend_string_realloc(Z_STR_P(op1), length, 1));
ZVAL_NEW_STR(result, zend_string_extend(Z_STR_P(op1), length, 1));
memcpy(Z_STRVAL_P(result)+op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
Z_STRVAL_P(result)[length] = 0;
}

View File

@ -657,7 +657,7 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename)
/* enforce ZEND_MMAP_AHEAD trailing NULLs for flex... */
old_len = Z_STRLEN_P(str);
Z_STR_P(str) = zend_string_realloc(Z_STR_P(str), old_len + ZEND_MMAP_AHEAD, 0);
Z_STR_P(str) = zend_string_extend(Z_STR_P(str), old_len + ZEND_MMAP_AHEAD, 0);
Z_TYPE_INFO_P(str) = IS_STRING_EX;
memset(Z_STRVAL_P(str) + old_len, 0, ZEND_MMAP_AHEAD + 1);

View File

@ -655,7 +655,7 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename)
/* enforce ZEND_MMAP_AHEAD trailing NULLs for flex... */
old_len = Z_STRLEN_P(str);
Z_STR_P(str) = zend_string_realloc(Z_STR_P(str), old_len + ZEND_MMAP_AHEAD, 0);
Z_STR_P(str) = zend_string_extend(Z_STR_P(str), old_len + ZEND_MMAP_AHEAD, 0);
Z_TYPE_INFO_P(str) = IS_STRING_EX;
memset(Z_STRVAL_P(str) + old_len, 0, ZEND_MMAP_AHEAD + 1);

View File

@ -1501,7 +1501,7 @@ ZEND_API int ZEND_FASTCALL shift_right_function(zval *result, zval *op1, zval *o
ZEND_API int ZEND_FASTCALL add_char_to_string(zval *result, const zval *op1, const zval *op2) /* {{{ */
{
size_t length = Z_STRLEN_P(op1) + 1;
zend_string *buf = zend_string_realloc(Z_STR_P(op1), length, 0);
zend_string *buf = zend_string_extend(Z_STR_P(op1), length, 0);
buf->val[length - 1] = (char) Z_LVAL_P(op2);
buf->val[length] = 0;
@ -1515,7 +1515,7 @@ ZEND_API int ZEND_FASTCALL add_string_to_string(zval *result, const zval *op1, c
{
size_t op1_len = Z_STRLEN_P(op1);
size_t length = op1_len + Z_STRLEN_P(op2);
zend_string *buf = zend_string_realloc(Z_STR_P(op1), length, 0);
zend_string *buf = zend_string_extend(Z_STR_P(op1), length, 0);
memcpy(buf->val + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
buf->val[length] = 0;
@ -1577,7 +1577,7 @@ ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) /
if (result == op1 && Z_REFCOUNTED_P(result)) {
/* special case, perform operations on result */
result_str = zend_string_realloc(Z_STR_P(result), result_len, 0);
result_str = zend_string_extend(Z_STR_P(result), result_len, 0);
} else {
result_str = zend_string_alloc(result_len, 0);
memcpy(result_str->val, Z_STRVAL_P(op1), op1_len);

View File

@ -158,18 +158,58 @@ static zend_always_inline zend_string *zend_string_realloc(zend_string *s, size_
{
zend_string *ret;
if (IS_INTERNED(s)) {
ret = zend_string_alloc(len, persistent);
memcpy(ret->val, s->val, (len > s->len ? s->len : len) + 1);
} else if (EXPECTED(GC_REFCOUNT(s) == 1)) {
if (!IS_INTERNED(s)) {
if (EXPECTED(GC_REFCOUNT(s) == 1)) {
ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + len + 1), persistent);
ret->len = len;
zend_string_forget_hash_val(ret);
return ret;
} else {
ret = zend_string_alloc(len, persistent);
memcpy(ret->val, s->val, (len > s->len ? s->len : len) + 1);
GC_REFCOUNT(s)--;
}
}
ret = zend_string_alloc(len, persistent);
memcpy(ret->val, s->val, (len > s->len ? s->len : len) + 1);
return ret;
}
static zend_always_inline zend_string *zend_string_extend(zend_string *s, size_t len, int persistent)
{
zend_string *ret;
ZEND_ASSERT(len >= s->len);
if (!IS_INTERNED(s)) {
if (EXPECTED(GC_REFCOUNT(s) == 1)) {
ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + len + 1), persistent);
ret->len = len;
zend_string_forget_hash_val(ret);
return ret;
} else {
GC_REFCOUNT(s)--;
}
}
ret = zend_string_alloc(len, persistent);
memcpy(ret->val, s->val, s->len + 1);
return ret;
}
static zend_always_inline zend_string *zend_string_truncate(zend_string *s, size_t len, int persistent)
{
zend_string *ret;
ZEND_ASSERT(len <= s->len);
if (!IS_INTERNED(s)) {
if (EXPECTED(GC_REFCOUNT(s) == 1)) {
ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + len + 1), persistent);
ret->len = len;
zend_string_forget_hash_val(ret);
return ret;
} else {
GC_REFCOUNT(s)--;
}
}
ret = zend_string_alloc(len, persistent);
memcpy(ret->val, s->val, len + 1);
return ret;
}
@ -177,18 +217,18 @@ static zend_always_inline zend_string *zend_string_safe_realloc(zend_string *s,
{
zend_string *ret;
if (IS_INTERNED(s)) {
ret = zend_string_safe_alloc(n, m, l, persistent);
memcpy(ret->val, s->val, ((n * m) + l > (size_t)s->len ? (size_t)s->len : ((n * m) + l)) + 1);
} else if (GC_REFCOUNT(s) == 1) {
if (!IS_INTERNED(s)) {
if (GC_REFCOUNT(s) == 1) {
ret = (zend_string *)safe_perealloc(s, n, m, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + l + 1), persistent);
ret->len = (n * m) + l;
zend_string_forget_hash_val(ret);
return ret;
} else {
ret = zend_string_safe_alloc(n, m, l, persistent);
memcpy(ret->val, s->val, ((n * m) + l > (size_t)s->len ? (size_t)s->len : ((n * m) + l)) + 1);
GC_REFCOUNT(s)--;
}
}
ret = zend_string_safe_alloc(n, m, l, persistent);
memcpy(ret->val, s->val, ((n * m) + l > s->len ? s->len : ((n * m) + l)) + 1);
return ret;
}

View File

@ -1661,7 +1661,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
buf = zend_string_alloc(buf_len, 0);
while ((real_len = strftime(buf->val, buf_len, format, &ta)) == buf_len || real_len == 0) {
buf_len *= 2;
buf = zend_string_realloc(buf, buf_len, 0);
buf = zend_string_extend(buf, buf_len, 0);
if (!--max_reallocs) {
break;
}
@ -1680,7 +1680,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
}
if (real_len && real_len != buf_len) {
buf = zend_string_realloc(buf, real_len, 0);
buf = zend_string_truncate(buf, real_len, 0);
RETURN_NEW_STR(buf);
}
zend_string_free(buf);

View File

@ -581,7 +581,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
if (out_left < 8) {
size_t pos = out_p - out_buffer->val;
out_buffer = zend_string_realloc(out_buffer, out_size + 8, 0);
out_buffer = zend_string_extend(out_buffer, out_size + 8, 0);
out_p = out_buffer->val + pos;
out_size += 7;
out_left += 7;
@ -640,7 +640,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
/* converted string is longer than out buffer */
bsz += in_len;
out_buf = zend_string_realloc(out_buf, bsz, 0);
out_buf = zend_string_extend(out_buf, bsz, 0);
out_p = out_buf->val;
out_p += out_size;
out_left = bsz - out_size;
@ -662,7 +662,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
if (errno == E2BIG) {
bsz += 16;
out_buf = zend_string_realloc(out_buf, bsz, 0);
out_buf = zend_string_extend(out_buf, bsz, 0);
out_p = out_buf->val;
out_p += out_size;
out_left = bsz - out_size;

View File

@ -1988,7 +1988,7 @@ PHP_FUNCTION(mysqli_real_escape_string) {
newstr = zend_string_alloc(2 * escapestr_len, 0);
newstr->len = mysql_real_escape_string(mysql->mysql, newstr->val, escapestr, escapestr_len);
newstr = zend_string_realloc(newstr, newstr->len, 0);
newstr = zend_string_truncate(newstr, newstr->len, 0);
RETURN_NEW_STR(newstr);
}

View File

@ -983,7 +983,7 @@ int php_oci_bind_post_exec(void *data)
* binds, php_oci_bind_out_callback() should have allocated a
* new string that we can modify here.
*/
Z_STR(bind->zval) = zend_string_realloc(Z_STR(bind->zval), Z_STRLEN(bind->zval)+1, 0);
Z_STR(bind->zval) = zend_string_extend(Z_STR(bind->zval), Z_STRLEN(bind->zval)+1, 0);
Z_STRVAL(bind->zval)[ Z_STRLEN(bind->zval) ] = '\0';
} else if (Z_TYPE(bind->zval) == IS_ARRAY) {
int i;

View File

@ -899,7 +899,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
memcpy(tmp->val, Z_STRVAL(ZEND_OP1_LITERAL(last_op)), old_len);
Z_STR(ZEND_OP1_LITERAL(last_op)) = tmp;
} else {
Z_STR(ZEND_OP1_LITERAL(last_op)) = zend_string_realloc(Z_STR(ZEND_OP1_LITERAL(last_op)), l, 0);
Z_STR(ZEND_OP1_LITERAL(last_op)) = zend_string_extend(Z_STR(ZEND_OP1_LITERAL(last_op)), l, 0);
}
Z_TYPE_INFO(ZEND_OP1_LITERAL(last_op)) = IS_STRING_EX;
memcpy(Z_STRVAL(ZEND_OP1_LITERAL(last_op)) + old_len, Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)));
@ -954,7 +954,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
memcpy(tmp->val, Z_STRVAL(ZEND_OP2_LITERAL(src)), old_len);
Z_STR(ZEND_OP2_LITERAL(last_op)) = tmp;
} else {
Z_STR(ZEND_OP2_LITERAL(src)) = zend_string_realloc(Z_STR(ZEND_OP2_LITERAL(src)), l, 0);
Z_STR(ZEND_OP2_LITERAL(src)) = zend_string_extend(Z_STR(ZEND_OP2_LITERAL(src)), l, 0);
}
Z_TYPE_INFO(ZEND_OP2_LITERAL(last_op)) = IS_STRING_EX;
memcpy(Z_STRVAL(ZEND_OP2_LITERAL(src)) + old_len, Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)));

View File

@ -1158,7 +1158,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
result = zend_string_alloc(alloc_len, 0);
} else {
alloc_len = alloc_len + 2 * new_len;
result = zend_string_realloc(result, alloc_len, 0);
result = zend_string_extend(result, alloc_len, 0);
}
}
/* copy the part of the string before the match */
@ -1779,7 +1779,7 @@ static PHP_FUNCTION(preg_quote)
*q = '\0';
/* Reallocate string and return it */
out_str = zend_string_realloc(out_str, q - out_str->val, 0);
out_str = zend_string_truncate(out_str, q - out_str->val, 0);
RETURN_NEW_STR(out_str);
}
/* }}} */

View File

@ -4362,7 +4362,7 @@ PHP_FUNCTION(pg_escape_string)
to->len = PQescapeString(to->val, from->val, from->len);
}
to = zend_string_realloc(to, to->len, 0);
to = zend_string_truncate(to, to->len, 0);
RETURN_NEW_STR(to);
}
/* }}} */
@ -6048,7 +6048,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
str = zend_string_alloc(Z_STRLEN_P(val) * 2, 0);
/* better to use PGSQLescapeLiteral since PGescapeStringConn does not handle special \ */
str->len = PQescapeStringConn(pg_link, str->val, Z_STRVAL_P(val), Z_STRLEN_P(val), NULL);
str = zend_string_realloc(str, str->len, 0);
str = zend_string_truncate(str, str->len, 0);
ZVAL_NEW_STR(&new_val, str);
php_pgsql_add_quotes(&new_val, 1);
}

View File

@ -140,7 +140,7 @@ static string *string_printf(string *str, const char *format, ...)
if (str->alloced < nlen) {
size_t old_len = str->buf->len;
str->alloced = nlen;
str->buf = zend_string_realloc(str->buf, str->alloced, 0);
str->buf = zend_string_extend(str->buf, str->alloced, 0);
str->buf->len = old_len;
}
memcpy(str->buf->val + str->buf->len, s_tmp, len + 1);
@ -157,7 +157,7 @@ static string *string_write(string *str, char *buf, size_t len)
if (str->alloced < nlen) {
size_t old_len = str->buf->len;
str->alloced = nlen;
str->buf = zend_string_realloc(str->buf, str->alloced, 0);
str->buf = zend_string_extend(str->buf, str->alloced, 0);
str->buf->len = old_len;
}
memcpy(str->buf->val + str->buf->len, buf, len);

View File

@ -1177,7 +1177,7 @@ PHP_FUNCTION(socket_read)
RETURN_EMPTY_STRING();
}
tmpbuf = zend_string_realloc(tmpbuf, retval, 0);
tmpbuf = zend_string_truncate(tmpbuf, retval, 0);
tmpbuf->len = retval;
tmpbuf->val[tmpbuf->len] = '\0' ;

View File

@ -552,7 +552,7 @@ PHP_FUNCTION(spl_autoload_register)
if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
/* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */
lc_name = zend_string_realloc(lc_name, lc_name->len + sizeof(uint32_t), 0);
lc_name = zend_string_extend(lc_name, lc_name->len + sizeof(uint32_t), 0);
memcpy(lc_name->val + lc_name->len - sizeof(uint32_t), &obj_ptr->handle, sizeof(uint32_t));
lc_name->val[lc_name->len] = '\0';
ZVAL_OBJ(&alfi.obj, obj_ptr);
@ -663,7 +663,7 @@ PHP_FUNCTION(spl_autoload_unregister)
/* remove specific */
success = zend_hash_del(SPL_G(autoload_functions), lc_name);
if (success != SUCCESS && obj_ptr) {
lc_name = zend_string_realloc(lc_name, lc_name->len + sizeof(uint32_t), 0);
lc_name = zend_string_extend(lc_name, lc_name->len + sizeof(uint32_t), 0);
memcpy(lc_name->val + lc_name->len - sizeof(uint32_t), &obj_ptr->handle, sizeof(uint32_t));
lc_name->val[lc_name->len] = '\0';
success = zend_hash_del(SPL_G(autoload_functions), lc_name);

View File

@ -326,7 +326,7 @@ PHPAPI zend_string *php_escape_shell_cmd(char *str)
if ((estimate - y) > 4096) {
/* realloc if the estimate was way overill
* Arbitrary cutoff point of 4096 */
cmd = zend_string_realloc(cmd, y, 0);
cmd = zend_string_truncate(cmd, y, 0);
}
cmd->len = y;
@ -392,7 +392,7 @@ PHPAPI zend_string *php_escape_shell_arg(char *str)
if ((estimate - y) > 4096) {
/* realloc if the estimate was way overill
* Arbitrary cutoff point of 4096 */
cmd = zend_string_realloc(cmd, y, 0);
cmd = zend_string_truncate(cmd, y, 0);
}
cmd->len = y;
return cmd;

View File

@ -61,7 +61,7 @@ php_sprintf_appendchar(zend_string **buffer, size_t *pos, char add)
{
if (!*buffer || (*pos + 1) >= (*buffer)->len) {
PRINTF_DEBUG(("%s(): ereallocing buffer to %d bytes\n", get_active_function_name(), (*buffer)->len));
*buffer = zend_string_realloc(*buffer, (*buffer)->len << 1, 0);
*buffer = zend_string_extend(*buffer, (*buffer)->len << 1, 0);
}
PRINTF_DEBUG(("sprintf: appending '%c', pos=\n", add, *pos));
(*buffer)->val[(*pos)++] = add;
@ -101,7 +101,7 @@ php_sprintf_appendstring(zend_string **buffer, size_t *pos, char *add,
size <<= 1;
}
PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", size));
*buffer = zend_string_realloc(*buffer, size, 0);
*buffer = zend_string_extend(*buffer, size, 0);
}
if (alignment == ALIGN_RIGHT) {
if ((neg || always_sign) && padding=='0') {

View File

@ -142,7 +142,7 @@ static char Lookahead(char *word, int how_far)
* could be one though; or more too). */
#define Phonize(c) { \
if (p_idx >= max_buffer_len) { \
*phoned_word = zend_string_realloc(*phoned_word, 2 * sizeof(char) + max_buffer_len, 0); \
*phoned_word = zend_string_extend(*phoned_word, 2 * sizeof(char) + max_buffer_len, 0); \
max_buffer_len += 2; \
} \
(*phoned_word)->val[p_idx++] = c; \
@ -151,7 +151,7 @@ static char Lookahead(char *word, int how_far)
/* Slap a null character on the end of the phoned word */
#define End_Phoned_Word { \
if (p_idx == max_buffer_len) { \
*phoned_word = zend_string_realloc(*phoned_word, 1 * sizeof(char) + max_buffer_len, 0); \
*phoned_word = zend_string_extend(*phoned_word, 1 * sizeof(char) + max_buffer_len, 0); \
max_buffer_len += 1; \
} \
(*phoned_word)->val[p_idx] = '\0'; \

View File

@ -187,7 +187,7 @@ PHPAPI zend_string *php_quot_print_encode(const unsigned char *str, size_t lengt
}
}
*d = '\0';
ret = zend_string_realloc(ret, d - (unsigned char*)ret->val, 0);
ret = zend_string_truncate(ret, d - (unsigned char*)ret->val, 0);
return ret;
}
/* }}} */

View File

@ -1004,7 +1004,7 @@ PHP_FUNCTION(wordwrap)
for (current = 0; current < text->len; current++) {
if (chk <= 0) {
alloced += (size_t) (((text->len - current + 1)/linelength + 1) * breakchar_len) + 1;
newtext = zend_string_realloc(newtext, alloced, 0);
newtext = zend_string_extend(newtext, alloced, 0);
chk = (size_t) ((text->len - current)/linelength) + 1;
}
/* when we hit an existing break, copy to new buffer, and
@ -1065,7 +1065,7 @@ PHP_FUNCTION(wordwrap)
newtext->val[newtextlen] = '\0';
/* free unused memory */
newtext = zend_string_realloc(newtext, newtextlen, 0);
newtext = zend_string_truncate(newtext, newtextlen, 0);
RETURN_NEW_STR(newtext);
}
@ -2738,7 +2738,7 @@ PHP_FUNCTION(quotemeta)
*q = '\0';
RETURN_NEW_STR(zend_string_realloc(str, q - str->val, 0));
RETURN_NEW_STR(zend_string_truncate(str, q - str->val, 0));
}
/* }}} */
@ -3441,7 +3441,7 @@ PHPAPI zend_string *php_str_to_str(char *haystack, size_t length, char *needle,
}
*e = '\0';
new_str = zend_string_realloc(new_str, e - s, 0);
new_str = zend_string_truncate(new_str, e - s, 0);
return new_str;
}
} else if (needle_len > length || memcmp(haystack, needle, length)) {
@ -3878,7 +3878,7 @@ PHPAPI zend_string *php_addcslashes(zend_string *str, int should_free, char *wha
*target = 0;
newlen = target - new_str->val;
if (newlen < str->len * 4) {
new_str = zend_string_realloc(new_str, newlen, 0);
new_str = zend_string_truncate(new_str, newlen, 0);
}
if (should_free) {
zend_string_release(str);
@ -3954,7 +3954,7 @@ do_escape:
}
if (new_str->len - (target - new_str->val) > 16) {
new_str = zend_string_realloc(new_str, target - new_str->val, 0);
new_str = zend_string_truncate(new_str, target - new_str->val, 0);
} else {
new_str->len = target - new_str->val;
}
@ -5648,7 +5648,7 @@ PHP_FUNCTION(money_format)
str->len = (size_t)res_len;
str->val[str->len] = '\0';
RETURN_NEW_STR(zend_string_realloc(str, str->len, 0));
RETURN_NEW_STR(zend_string_truncate(str, str->len, 0));
}
/* }}} */
#endif

View File

@ -524,7 +524,7 @@ PHPAPI zend_string *php_url_encode(char const *s, size_t len)
}
*to = '\0';
start = zend_string_realloc(start, to - (unsigned char*)start->val, 0);
start = zend_string_truncate(start, to - (unsigned char*)start->val, 0);
return start;
}
@ -631,7 +631,7 @@ PHPAPI zend_string *php_raw_url_encode(char const *s, size_t len)
}
}
str->val[y] = '\0';
str = zend_string_realloc(str, y, 0);
str = zend_string_truncate(str, y, 0);
return str;
}

View File

@ -122,7 +122,7 @@ PHPAPI zend_string *php_uuencode(char *src, size_t src_len) /* {{{ */
*p++ = '\n';
*p = '\0';
dest = zend_string_realloc(dest, p - dest->val, 0);
dest = zend_string_truncate(dest, p - dest->val, 0);
return dest;
}
/* }}} */

View File

@ -991,7 +991,7 @@ static void php_wddx_process_data(void *user_data, const XML_Char *s, int len)
zval_ptr_dtor(&ent->data);
ZVAL_STRINGL(&ent->data, (char *)s, len);
} else {
Z_STR(ent->data) = zend_string_realloc(Z_STR(ent->data), Z_STRLEN(ent->data) + len, 0);
Z_STR(ent->data) = zend_string_extend(Z_STR(ent->data), Z_STRLEN(ent->data) + len, 0);
memcpy(Z_STRVAL(ent->data) + Z_STRLEN(ent->data) - len, (char *)s, len);
Z_STRVAL(ent->data)[Z_STRLEN(ent->data)] = '\0';
}

View File

@ -604,7 +604,7 @@ PHPAPI zend_string *xml_utf8_encode(const char *s, size_t len, const XML_Char *e
s++;
}
str->val[str->len] = '\0';
str = zend_string_realloc(str, str->len, 0);
str = zend_string_truncate(str, str->len, 0);
return str;
}
/* }}} */
@ -644,7 +644,7 @@ PHPAPI zend_string *xml_utf8_decode(const XML_Char *s, size_t len, const XML_Cha
}
str->val[str->len] = '\0';
if (str->len < len) {
str = zend_string_realloc(str, str->len, 0);
str = zend_string_truncate(str, str->len, 0);
}
return str;
@ -892,7 +892,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
/* check if the current tag already has a value - if yes append to that! */
if ((myval = zend_hash_str_find(Z_ARRVAL_P(parser->ctag), "value", sizeof("value") - 1))) {
int newlen = Z_STRLEN_P(myval) + decoded_value->len;
Z_STR_P(myval) = zend_string_realloc(Z_STR_P(myval), newlen, 0);
Z_STR_P(myval) = zend_string_extend(Z_STR_P(myval), newlen, 0);
strncpy(Z_STRVAL_P(myval) + Z_STRLEN_P(myval) - decoded_value->len,
decoded_value->val, decoded_value->len + 1);
zend_string_release(decoded_value);
@ -909,7 +909,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
if (!strcmp(Z_STRVAL_P(mytype), "cdata")) {
if ((myval = zend_hash_str_find(Z_ARRVAL_P(curtag), "value", sizeof("value") - 1))) {
int newlen = Z_STRLEN_P(myval) + decoded_value->len;
Z_STR_P(myval) = zend_string_realloc(Z_STR_P(myval), newlen, 0);
Z_STR_P(myval) = zend_string_extend(Z_STR_P(myval), newlen, 0);
strncpy(Z_STRVAL_P(myval) + Z_STRLEN_P(myval) - decoded_value->len,
decoded_value->val, decoded_value->len + 1);
zend_string_release(decoded_value);

View File

@ -336,7 +336,7 @@ static zend_string *php_zlib_encode(const char *in_buf, size_t in_len, int encod
if (Z_STREAM_END == status) {
/* size buffer down to actual length */
out = zend_string_realloc(out, Z.total_out, 0);
out = zend_string_truncate(out, Z.total_out, 0);
out->val[out->len] = '\0';
return out;
} else {

View File

@ -1477,7 +1477,7 @@ PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int
while ((ret = php_stream_read(src, ptr, max_len - len))) {
len += ret;
if (len + min_room >= max_len) {
result = zend_string_realloc(result, max_len + step, persistent);
result = zend_string_extend(result, max_len + step, persistent);
max_len += step;
ptr = result->val + len;
} else {
@ -1485,7 +1485,7 @@ PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int
}
}
if (len) {
result = zend_string_realloc(result, len, persistent);
result = zend_string_truncate(result, len, persistent);
result->val[len] = '\0';
} else {
zend_string_free(result);