summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2014-04-24 10:18:39 +0800
committerXinchen Hui <laruence@gmail.com>2014-04-24 10:18:39 +0800
commit9824418c61974e4d8bef372da91e64deadbfdd9b (patch)
tree0785d4611634759ce6ff53287f52f9df8dbe51c3
parenta30442c1c8cbd718ffb83911fac87ed099b25508 (diff)
parentd2e45b05c7734181ece641d8cb20f165c3122ddc (diff)
downloadphp-git-9824418c61974e4d8bef372da91e64deadbfdd9b.tar.gz
Merge branch 'refactoring2' of github.com:zendtech/php into refactoring2
-rw-r--r--Zend/zend.h30
-rw-r--r--Zend/zend_hash.c2
-rw-r--r--Zend/zend_ini.h30
-rw-r--r--Zend/zend_string.h10
-rw-r--r--ext/hash/hash.c181
-rw-r--r--ext/opcache/ZendAccelerator.c4
-rw-r--r--ext/opcache/zend_accelerator_util_funcs.c6
-rw-r--r--ext/opcache/zend_persist.c4
-rw-r--r--ext/opcache/zend_persist_calc.c2
-rw-r--r--ext/pdo/pdo_dbh.c2
-rw-r--r--ext/sqlite3/sqlite3.c4
-rw-r--r--ext/standard/php_smart_str.h4
-rw-r--r--ext/standard/tests/strings/str_pad_variation5.phpt2
13 files changed, 135 insertions, 146 deletions
diff --git a/Zend/zend.h b/Zend/zend.h
index 3aae759dde..799eb25cfe 100644
--- a/Zend/zend.h
+++ b/Zend/zend.h
@@ -347,6 +347,36 @@ void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((nore
# define UNEXPECTED(condition) (condition)
#endif
+#ifndef XtOffsetOf
+# if defined(CRAY) || (defined(__ARMCC_VERSION) && !defined(LINUX))
+# ifdef __STDC__
+# define XtOffset(p_type, field) _Offsetof(p_type, field)
+# else
+# ifdef CRAY2
+# define XtOffset(p_type, field) \
+ (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
+
+# else /* !CRAY2 */
+
+# define XtOffset(p_type, field) ((unsigned int)&(((p_type)NULL)->field))
+
+# endif /* !CRAY2 */
+# endif /* __STDC__ */
+# else /* ! (CRAY || __arm) */
+
+# define XtOffset(p_type, field) \
+ ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
+
+# endif /* !CRAY */
+
+# ifdef offsetof
+# define XtOffsetOf(s_type, field) offsetof(s_type, field)
+# else
+# define XtOffsetOf(s_type, field) XtOffset(s_type*, field)
+# endif
+
+#endif
+
#include "zend_string.h"
static zend_always_inline zend_uint zval_refcount_p(zval* pz) {
diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c
index 38e027d608..ffe71a6791 100644
--- a/Zend/zend_hash.c
+++ b/Zend/zend_hash.c
@@ -1655,7 +1655,7 @@ ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t co
HASH_UNPROTECT_RECURSION(ht2);
return 1; /* That's not supposed to happen */
}
- if (p2) break;
+ if (Z_TYPE(p2->val) != IS_UNDEF) break;
idx2++;
}
if (p1->key == NULL && p2->key == NULL) { /* numeric indices */
diff --git a/Zend/zend_ini.h b/Zend/zend_ini.h
index 8782ec6f20..0a0c1137e1 100644
--- a/Zend/zend_ini.h
+++ b/Zend/zend_ini.h
@@ -27,36 +27,6 @@
#define ZEND_INI_ALL (ZEND_INI_USER|ZEND_INI_PERDIR|ZEND_INI_SYSTEM)
-#ifndef XtOffsetOf
-# if defined(CRAY) || (defined(__ARMCC_VERSION) && !defined(LINUX))
-# ifdef __STDC__
-# define XtOffset(p_type, field) _Offsetof(p_type, field)
-# else
-# ifdef CRAY2
-# define XtOffset(p_type, field) \
- (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
-
-# else /* !CRAY2 */
-
-# define XtOffset(p_type, field) ((unsigned int)&(((p_type)NULL)->field))
-
-# endif /* !CRAY2 */
-# endif /* __STDC__ */
-# else /* ! (CRAY || __arm) */
-
-# define XtOffset(p_type, field) \
- ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
-
-# endif /* !CRAY */
-
-# ifdef offsetof
-# define XtOffsetOf(s_type, field) offsetof(s_type, field)
-# else
-# define XtOffsetOf(s_type, field) XtOffset(s_type*, field)
-# endif
-
-#endif
-
#define ZEND_INI_MH(name) int name(zend_ini_entry *entry, char *new_value, uint new_value_length, void *mh_arg1, void *mh_arg2, void *mh_arg3, int stage TSRMLS_DC)
#define ZEND_INI_DISP(name) void name(zend_ini_entry *ini_entry, int type)
diff --git a/Zend/zend_string.h b/Zend/zend_string.h
index 5226c06e79..af83d4d3b5 100644
--- a/Zend/zend_string.h
+++ b/Zend/zend_string.h
@@ -54,6 +54,8 @@ END_EXTERN_C()
#define STR_RELEASE(s) zend_str_release(s)
#define STR_EMPTY_ALLOC() CG(empty_string)
+#define _STR_HEADER_SIZE XtOffsetOf(zend_string, val)
+
static zend_always_inline zend_ulong zend_str_hash_val(zend_string *s)
{
if (!s->h) {
@@ -93,7 +95,7 @@ static zend_always_inline zend_uint zend_str_delref(zend_string *s)
static zend_always_inline zend_string *zend_str_alloc(int len, int persistent)
{
- zend_string *ret = pemalloc(sizeof(zend_string) + len, persistent);
+ zend_string *ret = pemalloc(_STR_HEADER_SIZE + len + 1, persistent);
GC_REFCOUNT(ret) = 1;
#if 1
@@ -111,7 +113,7 @@ static zend_always_inline zend_string *zend_str_alloc(int len, int persistent)
static zend_always_inline zend_string *zend_str_safe_alloc(size_t n, size_t m, size_t l, int persistent)
{
- zend_string *ret = safe_pemalloc(n, m, sizeof(zend_string) + l - 1, persistent);
+ zend_string *ret = safe_pemalloc(n, m, _STR_HEADER_SIZE + l + 1, persistent);
GC_REFCOUNT(ret) = 1;
#if 1
@@ -161,7 +163,7 @@ static zend_always_inline zend_string *zend_str_realloc(zend_string *s, int len,
ret = STR_ALLOC(len, persistent);
memcpy(ret->val, s->val, (len > s->len ? s->len : len) + 1);
} else if (STR_REFCOUNT(s) == 1) {
- ret = perealloc(s, sizeof(zend_string) + len, persistent);
+ ret = perealloc(s, _STR_HEADER_SIZE + len + 1, persistent);
ret->len = len;
STR_FORGET_HASH_VAL(ret);
} else {
@@ -180,7 +182,7 @@ static zend_always_inline zend_string *zend_str_safe_realloc(zend_string *s, siz
ret = STR_SAFE_ALLOC(n, m, l, persistent);
memcpy(ret->val, s->val, ((n * m) + l > s->len ? s->len : ((n * m) + l)) + 1);
} else if (STR_REFCOUNT(s) == 1) {
- ret = safe_perealloc(s, n, m, sizeof(zend_string) + l - 1, persistent);
+ ret = safe_perealloc(s, n, m, _STR_HEADER_SIZE + l + 1, persistent);
ret->len = (n * m) + l;
STR_FORGET_HASH_VAL(ret);
} else {
diff --git a/ext/hash/hash.c b/ext/hash/hash.c
index 1e8d45eca5..15568b8d9f 100644
--- a/ext/hash/hash.c
+++ b/ext/hash/hash.c
@@ -88,13 +88,8 @@ static struct mhash_bc_entry mhash_to_hash[MHASH_NUM_ALGOS] = {
PHP_HASH_API const php_hash_ops *php_hash_fetch_ops(const char *algo, int algo_len) /* {{{ */
{
- php_hash_ops *ops;
- char *lower = estrndup(algo, algo_len);
-
- zend_str_tolower(lower, algo_len);
- if (SUCCESS != zend_hash_find(&php_hash_hashtable, lower, algo_len + 1, (void*)&ops)) {
- ops = NULL;
- }
+ char *lower = zend_str_tolower_dup(algo, algo_len);
+ php_hash_ops *ops = zend_hash_str_find_ptr(&php_hash_hashtable, lower, algo_len);
efree(lower);
return ops;
@@ -104,10 +99,8 @@ PHP_HASH_API const php_hash_ops *php_hash_fetch_ops(const char *algo, int algo_l
PHP_HASH_API void php_hash_register_algo(const char *algo, const php_hash_ops *ops) /* {{{ */
{
int algo_len = strlen(algo);
- char *lower = estrndup(algo, algo_len);
-
- zend_str_tolower(lower, algo_len);
- zend_hash_add(&php_hash_hashtable, lower, algo_len + 1, (void*)ops, sizeof(php_hash_ops), NULL);
+ char *lower = zend_str_tolower_dup(algo, algo_len);
+ zend_hash_str_add_ptr(&php_hash_hashtable, lower, algo_len, (void *) ops);
efree(lower);
}
/* }}} */
@@ -125,7 +118,8 @@ PHP_HASH_API int php_hash_copy(const void *ops, void *orig_context, void *dest_c
static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_bool raw_output_default) /* {{{ */
{
- char *algo, *data, *digest;
+ zend_string *digest;
+ char *algo, *data;
int algo_len, data_len;
zend_bool raw_output = raw_output_default;
const php_hash_ops *ops;
@@ -167,20 +161,20 @@ static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_
ops->hash_update(context, (unsigned char *) data, data_len);
}
- digest = emalloc(ops->digest_size + 1);
- ops->hash_final((unsigned char *) digest, context);
+ digest = STR_ALLOC(ops->digest_size, 0);
+ ops->hash_final((unsigned char *) digest->val, context);
efree(context);
if (raw_output) {
- digest[ops->digest_size] = 0;
- RETURN_STRINGL(digest, ops->digest_size, 0);
+ digest->val[ops->digest_size] = 0;
+ RETURN_STR(digest);
} else {
- char *hex_digest = safe_emalloc(ops->digest_size, 2, 1);
+ zend_string *hex_digest = STR_SAFE_ALLOC(ops->digest_size, 2, 0, 0);
- php_hash_bin2hex(hex_digest, (unsigned char *) digest, ops->digest_size);
- hex_digest[2 * ops->digest_size] = 0;
- efree(digest);
- RETURN_STRINGL(hex_digest, 2 * ops->digest_size, 0);
+ php_hash_bin2hex(hex_digest->val, (unsigned char *) digest->val, ops->digest_size);
+ hex_digest->val[2 * ops->digest_size] = 0;
+ STR_RELEASE(digest);
+ RETURN_STR(hex_digest);
}
}
/* }}} */
@@ -240,7 +234,9 @@ static inline void php_hash_hmac_round(unsigned char *final, const php_hash_ops
static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_bool raw_output_default) /* {{{ */
{
- char *algo, *data, *digest, *key, *K;
+ zend_string *digest;
+ char *algo, *data, *key;
+ unsigned char *K;
int algo_len, data_len, key_len;
zend_bool raw_output = raw_output_default;
const php_hash_ops *ops;
@@ -268,27 +264,27 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename,
context = emalloc(ops->context_size);
K = emalloc(ops->block_size);
- digest = emalloc(ops->digest_size + 1);
+ digest = STR_ALLOC(ops->digest_size, 0);
- php_hash_hmac_prep_key((unsigned char *) K, ops, context, (unsigned char *) key, key_len);
+ php_hash_hmac_prep_key(K, ops, context, (unsigned char *) key, key_len);
if (isfilename) {
char buf[1024];
int n;
ops->hash_init(context);
- ops->hash_update(context, (unsigned char *) K, ops->block_size);
+ ops->hash_update(context, K, ops->block_size);
while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
ops->hash_update(context, (unsigned char *) buf, n);
}
php_stream_close(stream);
- ops->hash_final((unsigned char *) digest, context);
+ ops->hash_final((unsigned char *) digest->val, context);
} else {
- php_hash_hmac_round((unsigned char *) digest, ops, context, (unsigned char *) K, (unsigned char *) data, data_len);
+ php_hash_hmac_round((unsigned char *) digest->val, ops, context, K, (unsigned char *) data, data_len);
}
- php_hash_string_xor_char((unsigned char *) K, (unsigned char *) K, 0x6A, ops->block_size);
+ php_hash_string_xor_char(K, K, 0x6A, ops->block_size);
- php_hash_hmac_round((unsigned char *) digest, ops, context, (unsigned char *) K, (unsigned char *) digest, ops->digest_size);
+ php_hash_hmac_round((unsigned char *) digest->val, ops, context, K, (unsigned char *) digest->val, ops->digest_size);
/* Zero the key */
memset(K, 0, ops->block_size);
@@ -296,15 +292,15 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename,
efree(context);
if (raw_output) {
- digest[ops->digest_size] = 0;
- RETURN_STRINGL(digest, ops->digest_size, 0);
+ digest->val[ops->digest_size] = 0;
+ RETURN_STR(digest);
} else {
- char *hex_digest = safe_emalloc(ops->digest_size, 2, 1);
+ zend_string *hex_digest = STR_SAFE_ALLOC(ops->digest_size, 2, 0, 0);
- php_hash_bin2hex(hex_digest, (unsigned char *) digest, ops->digest_size);
- hex_digest[2 * ops->digest_size] = 0;
- efree(digest);
- RETURN_STRINGL(hex_digest, 2 * ops->digest_size, 0);
+ php_hash_bin2hex(hex_digest->val, (unsigned char *) digest->val, ops->digest_size);
+ hex_digest->val[2 * ops->digest_size] = 0;
+ STR_RELEASE(digest);
+ RETURN_STR(hex_digest);
}
}
/* }}} */
@@ -406,7 +402,7 @@ PHP_FUNCTION(hash_update)
return;
}
- ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
+ ZEND_FETCH_RESOURCE(hash, php_hash_data*, zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
hash->ops->hash_update(hash->context, (unsigned char *) data, data_len);
@@ -427,8 +423,8 @@ PHP_FUNCTION(hash_update_stream)
return;
}
- ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
- php_stream_from_zval(stream, &zstream);
+ ZEND_FETCH_RESOURCE(hash, php_hash_data*, zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
+ php_stream_from_zval(stream, zstream);
while (length) {
char buf[1024];
@@ -466,7 +462,7 @@ PHP_FUNCTION(hash_update_file)
return;
}
- ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
+ ZEND_FETCH_RESOURCE(hash, php_hash_data*, zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
context = php_stream_context_from_zval(zcontext, 0);
stream = php_stream_open_wrapper_ex(filename, "rb", REPORT_ERRORS, NULL, context);
@@ -491,19 +487,18 @@ PHP_FUNCTION(hash_final)
zval *zhash;
php_hash_data *hash;
zend_bool raw_output = 0;
- zend_rsrc_list_entry *le;
- char *digest;
+ zend_string *digest;
int digest_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|b", &zhash, &raw_output) == FAILURE) {
return;
}
- ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
+ ZEND_FETCH_RESOURCE(hash, php_hash_data*, zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
digest_len = hash->ops->digest_size;
- digest = emalloc(digest_len + 1);
- hash->ops->hash_final((unsigned char *) digest, hash->context);
+ digest = STR_ALLOC(digest_len, 0);
+ hash->ops->hash_final((unsigned char *) digest->val, hash->context);
if (hash->options & PHP_HASH_HMAC) {
int i;
@@ -514,36 +509,37 @@ PHP_FUNCTION(hash_final)
/* Feed this result into the outter hash */
hash->ops->hash_init(hash->context);
- hash->ops->hash_update(hash->context, (unsigned char *) hash->key, hash->ops->block_size);
- hash->ops->hash_update(hash->context, (unsigned char *) digest, hash->ops->digest_size);
- hash->ops->hash_final((unsigned char *) digest, hash->context);
+ hash->ops->hash_update(hash->context, hash->key, hash->ops->block_size);
+ hash->ops->hash_update(hash->context, (unsigned char *) digest->val, hash->ops->digest_size);
+ hash->ops->hash_final((unsigned char *) digest->val, hash->context);
/* Zero the key */
memset(hash->key, 0, hash->ops->block_size);
efree(hash->key);
hash->key = NULL;
}
- digest[digest_len] = 0;
+ digest->val[digest_len] = 0;
efree(hash->context);
hash->context = NULL;
- /* zend_list_REAL_delete() */
- if (zend_hash_index_find(&EG(regular_list), Z_RESVAL_P(zhash), (void *) &le)==SUCCESS) {
- /* This is a hack to avoid letting the resource hide elsewhere (like in separated vars)
- FETCH_RESOURCE is intelligent enough to handle dealing with any issues this causes */
- le->refcount = 1;
- } /* FAILURE is not an option */
- zend_list_delete(Z_RESVAL_P(zhash));
+ //???
+ //??? /* zend_list_REAL_delete() */
+ //??? if (zend_hash_index_find(&EG(regular_list), Z_RESVAL_P(zhash), (void *) &le)==SUCCESS) {
+ //??? /* This is a hack to avoid letting the resource hide elsewhere (like in separated vars)
+ //??? FETCH_RESOURCE is intelligent enough to handle dealing with any issues this causes */
+ //??? le->refcount = 1;
+ //??? } /* FAILURE is not an option */
+ zend_list_close(Z_RES_P(zhash));
if (raw_output) {
- RETURN_STRINGL(digest, digest_len, 0);
+ RETURN_STR(digest);
} else {
- char *hex_digest = safe_emalloc(digest_len,2,1);
+ zend_string *hex_digest = STR_SAFE_ALLOC(digest_len, 2, 0, 0);
- php_hash_bin2hex(hex_digest, (unsigned char *) digest, digest_len);
- hex_digest[2 * digest_len] = 0;
- efree(digest);
- RETURN_STRINGL(hex_digest, 2 * digest_len, 0);
+ php_hash_bin2hex(hex_digest->val, (unsigned char *) digest->val, digest_len);
+ hex_digest->val[2 * digest_len] = 0;
+ STR_RELEASE(digest);
+ RETURN_STR(hex_digest);
}
}
/* }}} */
@@ -561,7 +557,7 @@ PHP_FUNCTION(hash_copy)
return;
}
- ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
+ ZEND_FETCH_RESOURCE(hash, php_hash_data*, zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
context = emalloc(hash->ops->context_size);
@@ -589,18 +585,12 @@ PHP_FUNCTION(hash_copy)
Return a list of registered hashing algorithms */
PHP_FUNCTION(hash_algos)
{
- HashPosition pos;
- char *str;
- uint str_len;
- long type;
- ulong idx;
+ zend_string *str;
array_init(return_value);
- for(zend_hash_internal_pointer_reset_ex(&php_hash_hashtable, &pos);
- (type = zend_hash_get_current_key_ex(&php_hash_hashtable, &str, &str_len, &idx, 0, &pos)) != HASH_KEY_NON_EXISTENT;
- zend_hash_move_forward_ex(&php_hash_hashtable, &pos)) {
- add_next_index_stringl(return_value, str, str_len-1);
- }
+ ZEND_HASH_FOREACH_STR_KEY(&php_hash_hashtable, str) {
+ add_next_index_str(return_value, STR_COPY(str));
+ } ZEND_HASH_FOREACH_END();
}
/* }}} */
@@ -609,7 +599,8 @@ Generate a PBKDF2 hash of the given password and salt
Returns lowercase hexits by default */
PHP_FUNCTION(hash_pbkdf2)
{
- char *returnval, *algo, *salt, *pass = NULL;
+ zend_string *returnval;
+ char *algo, *salt, *pass = NULL;
unsigned char *computed_salt, *digest, *temp, *result, *K1, *K2 = NULL;
long loops, i, j, algo_len, pass_len, iterations, length, digest_length = 0;
int argc, salt_len = 0;
@@ -717,21 +708,21 @@ PHP_FUNCTION(hash_pbkdf2)
efree(digest);
efree(temp);
- returnval = safe_emalloc(length, 1, 1);
+ returnval = STR_ALLOC(length, 0);
if (raw_output) {
- memcpy(returnval, result, length);
+ memcpy(returnval->val, result, length);
} else {
- php_hash_bin2hex(returnval, result, digest_length);
+ php_hash_bin2hex(returnval->val, result, digest_length);
}
- returnval[length] = 0;
+ returnval->val[length] = 0;
efree(result);
- RETURN_STRINGL(returnval, length, 0);
+ RETURN_STR(returnval);
}
/* }}} */
/* Module Housekeeping */
-static void php_hash_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
+static void php_hash_dtor(zend_resource *rsrc TSRMLS_DC) /* {{{ */
{
php_hash_data *hash = (php_hash_data*)rsrc->ptr;
@@ -789,7 +780,7 @@ static void mhash_init(INIT_FUNC_ARGS)
}
len = slprintf(buf, 127, "MHASH_%s", algorithm.mhash_name, strlen(algorithm.mhash_name));
- zend_register_long_constant(buf, len + 1, algorithm.value, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
+ zend_register_long_constant(buf, len, algorithm.value, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
}
zend_register_internal_module(&mhash_module_entry TSRMLS_CC);
}
@@ -798,22 +789,22 @@ static void mhash_init(INIT_FUNC_ARGS)
Hash data with hash */
PHP_FUNCTION(mhash)
{
- zval **z_algorithm;
+ zval *z_algorithm;
long algorithm;
- if (zend_parse_parameters(1 TSRMLS_CC, "Z", &z_algorithm) == FAILURE) {
+ if (zend_parse_parameters(1 TSRMLS_CC, "z", &z_algorithm) == FAILURE) {
return;
}
SEPARATE_ZVAL(z_algorithm);
convert_to_long_ex(z_algorithm);
- algorithm = Z_LVAL_PP(z_algorithm);
+ algorithm = Z_LVAL_P(z_algorithm);
/* need to convert the first parameter from int constant to string algorithm name */
if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) {
struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm];
if (algorithm_lookup.hash_name) {
- ZVAL_STRING(*z_algorithm, algorithm_lookup.hash_name, 1);
+ ZVAL_STRING(z_algorithm, algorithm_lookup.hash_name);
}
}
@@ -840,7 +831,7 @@ PHP_FUNCTION(mhash_get_hash_name)
if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) {
struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm];
if (algorithm_lookup.mhash_name) {
- RETURN_STRING(algorithm_lookup.mhash_name, 1);
+ RETURN_STRING(algorithm_lookup.mhash_name);
}
}
RETURN_FALSE;
@@ -943,7 +934,7 @@ PHP_FUNCTION(mhash_keygen_s2k)
memcpy( &key[i*block_size], digest, block_size);
}
- RETVAL_STRINGL(key, bytes, 1);
+ RETVAL_STRINGL(key, bytes);
memset(key, 0, bytes);
efree(digest);
efree(context);
@@ -1036,17 +1027,13 @@ PHP_MSHUTDOWN_FUNCTION(hash)
*/
PHP_MINFO_FUNCTION(hash)
{
- HashPosition pos;
char buffer[2048];
- char *s = buffer, *e = s + sizeof(buffer), *str;
- ulong idx;
- long type;
-
- for(zend_hash_internal_pointer_reset_ex(&php_hash_hashtable, &pos);
- (type = zend_hash_get_current_key_ex(&php_hash_hashtable, &str, NULL, &idx, 0, &pos)) != HASH_KEY_NON_EXISTENT;
- zend_hash_move_forward_ex(&php_hash_hashtable, &pos)) {
- s += slprintf(s, e - s, "%s ", str);
- }
+ zend_string *str;
+ char *s = buffer, *e = s + sizeof(buffer);
+
+ ZEND_HASH_FOREACH_STR_KEY(&php_hash_hashtable, str) {
+ s += slprintf(s, e - s, "%s ", str->val);
+ } ZEND_HASH_FOREACH_END();
*s = 0;
php_info_print_table_start();
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index 84c397d7ab..11ca76e2f3 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -336,7 +336,7 @@ zend_string *accel_new_interned_string(zend_string *str TSRMLS_DC)
idx = Z_NEXT(p->val);
}
- if (ZCSG(interned_strings_top) + ZEND_MM_ALIGNED_SIZE(sizeof(zend_string) + str->len) >=
+ if (ZCSG(interned_strings_top) + ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + str->len + 1) >=
ZCSG(interned_strings_end)) {
/* no memory, return the same non-interned string */
return str;
@@ -348,7 +348,7 @@ zend_string *accel_new_interned_string(zend_string *str TSRMLS_DC)
ZCSG(interned_strings).nNumOfElements++;
p = ZCSG(interned_strings).arData + idx;
p->key = (zend_string*) ZCSG(interned_strings_top);
- ZCSG(interned_strings_top) += ZEND_MM_ALIGNED_SIZE(sizeof(zend_string) + str->len);
+ ZCSG(interned_strings_top) += ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + str->len + 1);
p->h = h;
GC_REFCOUNT(p->key) = 1;
#if 1
diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c
index c93bec7994..2ac26897b4 100644
--- a/ext/opcache/zend_accelerator_util_funcs.c
+++ b/ext/opcache/zend_accelerator_util_funcs.c
@@ -299,7 +299,7 @@ static inline void zend_clone_zval(zval *src, int bind TSRMLS_DC)
if (bind && Z_REFCOUNT_P(src) > 1) {
accel_xlat_set(old, Z_REF_P(src));
}
- zend_clone_zval(Z_REFVAL_P(src), bind TSRMLS_C);
+ zend_clone_zval(Z_REFVAL_P(src), bind TSRMLS_CC);
}
break;
case IS_CONSTANT_AST:
@@ -330,7 +330,7 @@ static zend_ast *zend_ast_clone(zend_ast *ast TSRMLS_DC)
node->kind = ZEND_CONST;
node->children = 0;
ZVAL_COPY_VALUE(&node->u.val, &ast->u.val);
- zend_clone_zval(&node->u.val, 0);
+ zend_clone_zval(&node->u.val, 0 TSRMLS_CC);
} else {
node = emalloc(sizeof(zend_ast) + sizeof(zend_ast*) * (ast->children - 1));
node->kind = ast->kind;
@@ -412,7 +412,7 @@ static void zend_hash_clone_zval(HashTable *ht, HashTable *source, int bind)
/* Copy data */
ZVAL_COPY_VALUE(&q->val, &p->val);
- zend_clone_zval(&q->val, bind TSRMLS_C);
+ zend_clone_zval(&q->val, bind TSRMLS_CC);
}
}
diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c
index ca2ad5150c..39a2aa4a7c 100644
--- a/ext/opcache/zend_persist.c
+++ b/ext/opcache/zend_persist.c
@@ -40,13 +40,13 @@
STR_RELEASE(str); \
str = new_str; \
} else { \
- new_str = _zend_shared_memdup((void*)str, sizeof(zend_string) + (str)->len, 0 TSRMLS_CC); \
+ new_str = _zend_shared_memdup((void*)str, _STR_HEADER_SIZE + (str)->len + 1, 0 TSRMLS_CC); \
STR_RELEASE(str); \
str = new_str; \
} \
} while (0)
# define zend_accel_memdup_string(str) \
- zend_accel_memdup(str, sizeof(zend_string) + (str)->len)
+ zend_accel_memdup(str, _STR_HEADER_SIZE + (str)->len + 1)
# define zend_accel_store_interned_string(str) do { \
if (!IS_ACCEL_INTERNED(str)) { \
zend_accel_store_string(str); \
diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c
index 6298fb1aa2..a347a34cf3 100644
--- a/ext/opcache/zend_persist_calc.c
+++ b/ext/opcache/zend_persist_calc.c
@@ -33,7 +33,7 @@
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
# define ADD_STRING(str) \
- ADD_DUP_SIZE((str), sizeof(zend_string) + (str)->len)
+ ADD_DUP_SIZE((str), _STR_HEADER_SIZE + (str)->len + 1)
# define ADD_INTERNED_STRING(str, do_free) do { \
if (!IS_ACCEL_INTERNED(str)) { \
zend_string *tmp = accel_new_interned_string(str TSRMLS_CC); \
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index 651015106d..3e0c7e67e2 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -575,7 +575,7 @@ static PHP_METHOD(PDO, prepare)
stmt->default_fetch_type = dbh->default_fetch_type;
stmt->dbh = dbh;
/* give it a reference to me */
- Z_ADDREF_P(getThis() TSRMLS_CC);
+ Z_ADDREF_P(getThis());
php_pdo_dbh_addref(dbh TSRMLS_CC);
ZVAL_COPY_VALUE(&stmt->database_object_handle, getThis());
/* we haven't created a lazy object yet */
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index 9888b26281..f5449ca943 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -535,7 +535,7 @@ PHP_METHOD(sqlite3, query)
stmt_obj->initialised = 1;
object_init_ex(return_value, php_sqlite3_result_entry);
- result = Z_SQLITE3_RESULT_P(return_value TSRMLS_CC);
+ result = Z_SQLITE3_RESULT_P(return_value);
result->db_obj = db_obj;
result->stmt_obj = stmt_obj;
ZVAL_COPY_VALUE(&result->stmt_obj_zval, &stmt);
@@ -1531,7 +1531,7 @@ PHP_METHOD(sqlite3stmt, execute)
{
sqlite3_reset(stmt_obj->stmt);
object_init_ex(return_value, php_sqlite3_result_entry);
- result = Z_SQLITE3_RESULT_P(return_value TSRMLS_CC);
+ result = Z_SQLITE3_RESULT_P(return_value);
result->is_prepared_statement = 1;
result->db_obj = stmt_obj->db_obj;
diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h
index a518fbfddf..5cc3a62137 100644
--- a/ext/standard/php_smart_str.h
+++ b/ext/standard/php_smart_str.h
@@ -45,11 +45,11 @@
#ifdef SMART_STR_USE_REALLOC
#define SMART_STR_DO_REALLOC(b, w) do { \
- (b)->s = erealloc((buf)->s, sizeof(zend_string) + (b)->a); \
+ (b)->s = erealloc((buf)->s, _STR_HEADER_SIZE + (b)->a + 1); \
} while (0)
#else
#define SMART_STR_DO_REALLOC(b, w) do { \
- (b)->s = perealloc((b)->s, sizeof(zend_string) + (b)->a, (w)); \
+ (b)->s = perealloc((b)->s, _STR_HEADER_SIZE + (b)->a + 1, (w)); \
} while (0)
#endif
diff --git a/ext/standard/tests/strings/str_pad_variation5.phpt b/ext/standard/tests/strings/str_pad_variation5.phpt
index 0dee148650..d050ae80e8 100644
--- a/ext/standard/tests/strings/str_pad_variation5.phpt
+++ b/ext/standard/tests/strings/str_pad_variation5.phpt
@@ -24,7 +24,7 @@ echo "*** Testing str_pad() function: with large value for for 'pad_length' argu
//defining '$input' argument
$input = "Test string";
-$pad_length = PHP_INT_MAX - 20 + 1; /* sizeof(zend_string) is 20, 1 character is included in zend_string structure itself */
+$pad_length = PHP_INT_MAX - 16; /* zend_string header is 16 bytes */
var_dump( str_pad($input, $pad_length) );
?>