Skip to content

Commit 65fd18f

Browse files
committed
Merge branch 'PHP-5.6'
* PHP-5.6: Improved empty string handling. Now ZE uses an interned string instead of allocation new empty string each time. (Some extensions might need to be fixed using str_efree() instead of efree() to support interned strings). Conflicts: NEWS Zend/zend_extensions.h Zend/zend_modules.h
2 parents d6713f3 + 03a37de commit 65fd18f

10 files changed

+20
-8
lines changed

Diff for: Zend/zend.h

+4
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,11 @@ END_EXTERN_C()
680680
#define STR_FREE(ptr) if (ptr) { str_efree(ptr); }
681681
#define STR_FREE_REL(ptr) if (ptr) { str_efree_rel(ptr); }
682682

683+
#ifndef ZTS
684+
#define STR_EMPTY_ALLOC() CG(interned_empty_string)? CG(interned_empty_string) : estrndup("", sizeof("")-1)
685+
#else
683686
#define STR_EMPTY_ALLOC() estrndup("", sizeof("")-1)
687+
#endif
684688

685689
#define STR_REALLOC(ptr, size) \
686690
ptr = (char *) erealloc(ptr, size);

Diff for: Zend/zend_compile.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2461,14 +2461,14 @@ void zend_do_build_full_name(znode *result, znode *prefix, znode *name, int is_c
24612461

24622462
if (is_class_member) {
24632463
length = sizeof("::")-1 + Z_STRLEN(result->u.constant) + Z_STRLEN(name->u.constant);
2464-
Z_STRVAL(result->u.constant) = erealloc(Z_STRVAL(result->u.constant), length+1);
2464+
Z_STRVAL(result->u.constant) = str_erealloc(Z_STRVAL(result->u.constant), length+1);
24652465
memcpy(&Z_STRVAL(result->u.constant)[Z_STRLEN(result->u.constant)], "::", sizeof("::")-1);
24662466
memcpy(&Z_STRVAL(result->u.constant)[Z_STRLEN(result->u.constant) + sizeof("::")-1], Z_STRVAL(name->u.constant), Z_STRLEN(name->u.constant)+1);
24672467
str_efree(Z_STRVAL(name->u.constant));
24682468
Z_STRLEN(result->u.constant) = length;
24692469
} else {
24702470
length = sizeof("\\")-1 + Z_STRLEN(result->u.constant) + Z_STRLEN(name->u.constant);
2471-
Z_STRVAL(result->u.constant) = erealloc(Z_STRVAL(result->u.constant), length+1);
2471+
Z_STRVAL(result->u.constant) = str_erealloc(Z_STRVAL(result->u.constant), length+1);
24722472
memcpy(&Z_STRVAL(result->u.constant)[Z_STRLEN(result->u.constant)], "\\", sizeof("\\")-1);
24732473
memcpy(&Z_STRVAL(result->u.constant)[Z_STRLEN(result->u.constant) + sizeof("\\")-1], Z_STRVAL(name->u.constant), Z_STRLEN(name->u.constant)+1);
24742474
str_efree(Z_STRVAL(name->u.constant));

Diff for: Zend/zend_extensions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/* The first number is the engine version and the rest is the date.
2929
* This way engine 2/3 API no. is always greater than engine 1 API no..
3030
*/
31-
#define ZEND_EXTENSION_API_NO 220131218
31+
#define ZEND_EXTENSION_API_NO 220131227
3232

3333
typedef struct _zend_extension_version_info {
3434
int zend_extension_api_no;

Diff for: Zend/zend_globals.h

+3
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ struct _zend_compiler_globals {
146146
char *interned_strings_end;
147147
char *interned_strings_top;
148148
char *interned_strings_snapshot_top;
149+
#ifndef ZTS
150+
char *interned_empty_string;
151+
#endif
149152

150153
HashTable interned_strings;
151154

Diff for: Zend/zend_modules.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#define ZEND_MODULE_INFO_FUNC_ARGS zend_module_entry *zend_module TSRMLS_DC
3434
#define ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU zend_module TSRMLS_CC
3535

36-
#define ZEND_MODULE_API_NO 20131218
36+
#define ZEND_MODULE_API_NO 20131227
3737
#ifdef ZTS
3838
#define USING_ZTS 1
3939
#else

Diff for: Zend/zend_string.c

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ void zend_interned_strings_init(TSRMLS_D)
6161
mprotect(CG(interned_strings_start), CG(interned_strings_end) - CG(interned_strings_start), PROT_READ);
6262
#endif
6363

64+
/* interned empty string */
65+
CG(interned_empty_string) = zend_new_interned_string_int("", sizeof(""), 0 TSRMLS_CC);
6466
#endif
6567

6668
zend_new_interned_string = zend_new_interned_string_int;

Diff for: ext/opcache/ZendAccelerator.c

+3
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ static void accel_use_shm_interned_strings(TSRMLS_D)
387387
{
388388
Bucket *p, *q;
389389

390+
/* empty string */
391+
CG(interned_empty_string) = accel_new_interned_string("", sizeof(""), 0 TSRMLS_CC);
392+
390393
/* function table hash keys */
391394
p = CG(function_table)->pListHead;
392395
while (p) {

Diff for: ext/session/mod_user_class.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ PHP_METHOD(SessionHandler, read)
8686
}
8787

8888
RETVAL_STRINGL(val, val_len, 1);
89-
efree(val);
89+
str_efree(val);
9090
return;
9191
}
9292
/* }}} */

Diff for: ext/session/session.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,9 @@ static void php_session_initialize(TSRMLS_D) /* {{{ */
513513
PHP_MD5Final(PS(session_data_hash), &context);
514514

515515
php_session_decode(val, vallen TSRMLS_CC);
516-
efree(val);
516+
str_efree(val);
517517
} else {
518-
memset(PS(session_data_hash),'\0', 16);
518+
memset(PS(session_data_hash),'\0', 16);
519519
}
520520

521521
if (!PS(use_cookies) && PS(send_cookie)) {

Diff for: ext/spl/spl_iterators.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,7 @@ SPL_METHOD(RegexIterator, accept)
20592059
}
20602060

20612061
if (use_copy) {
2062-
efree(subject);
2062+
str_efree(subject);
20632063
}
20642064
} /* }}} */
20652065

0 commit comments

Comments
 (0)