Skip to content

Instantly share code, notes, and snippets.

@krakjoe
Created December 15, 2015 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krakjoe/9976866c9cc8a27cde32 to your computer and use it in GitHub Desktop.
Save krakjoe/9976866c9cc8a27cde32 to your computer and use it in GitHub Desktop.
strings.patch
diff --git a/Zend/zend_string.h b/Zend/zend_string.h
index 9c022e8..38f1ffe 100644
--- a/Zend/zend_string.h
+++ b/Zend/zend_string.h
@@ -54,6 +54,7 @@ END_EXTERN_C()
/*---*/
#define ZSTR_IS_INTERNED(s) (GC_FLAGS(s) & IS_STR_INTERNED)
+#define ZSTR_IS_REFCOUNTED(s) (!(GC_FLAGS(s) & (IS_STR_INTERNED|IS_STR_PERSISTENT)))
#define ZSTR_EMPTY_ALLOC() CG(empty_string)
@@ -94,7 +95,7 @@ static zend_always_inline void zend_string_forget_hash_val(zend_string *s)
static zend_always_inline uint32_t zend_string_refcount(const zend_string *s)
{
- if (!ZSTR_IS_INTERNED(s)) {
+ if (ZSTR_IS_REFCOUNTED(s)) {
return GC_REFCOUNT(s);
}
return 1;
@@ -102,7 +103,7 @@ static zend_always_inline uint32_t zend_string_refcount(const zend_string *s)
static zend_always_inline uint32_t zend_string_addref(zend_string *s)
{
- if (!ZSTR_IS_INTERNED(s)) {
+ if (ZSTR_IS_REFCOUNTED(s)) {
return ++GC_REFCOUNT(s);
}
return 1;
@@ -110,7 +111,7 @@ static zend_always_inline uint32_t zend_string_addref(zend_string *s)
static zend_always_inline uint32_t zend_string_delref(zend_string *s)
{
- if (!ZSTR_IS_INTERNED(s)) {
+ if (ZSTR_IS_REFCOUNTED(s)) {
return --GC_REFCOUNT(s);
}
return 1;
@@ -163,7 +164,7 @@ static zend_always_inline zend_string *zend_string_init(const char *str, size_t
static zend_always_inline zend_string *zend_string_copy(zend_string *s)
{
- if (!ZSTR_IS_INTERNED(s)) {
+ if (ZSTR_IS_REFCOUNTED(s)) {
GC_REFCOUNT(s)++;
}
return s;
@@ -171,7 +172,7 @@ static zend_always_inline zend_string *zend_string_copy(zend_string *s)
static zend_always_inline zend_string *zend_string_dup(zend_string *s, int persistent)
{
- if (ZSTR_IS_INTERNED(s)) {
+ if (!ZSTR_IS_REFCOUNTED(s)) {
return s;
} else {
return zend_string_init(ZSTR_VAL(s), ZSTR_LEN(s), persistent);
@@ -182,7 +183,7 @@ static zend_always_inline zend_string *zend_string_realloc(zend_string *s, size_
{
zend_string *ret;
- if (!ZSTR_IS_INTERNED(s)) {
+ if (ZSTR_IS_REFCOUNTED(s)) {
if (EXPECTED(GC_REFCOUNT(s) == 1)) {
ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(len)), persistent);
ZSTR_LEN(ret) = len;
@@ -202,7 +203,7 @@ static zend_always_inline zend_string *zend_string_extend(zend_string *s, size_t
zend_string *ret;
ZEND_ASSERT(len >= ZSTR_LEN(s));
- if (!ZSTR_IS_INTERNED(s)) {
+ if (ZSTR_IS_REFCOUNTED(s)) {
if (EXPECTED(GC_REFCOUNT(s) == 1)) {
ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(len)), persistent);
ZSTR_LEN(ret) = len;
@@ -222,7 +223,7 @@ static zend_always_inline zend_string *zend_string_truncate(zend_string *s, size
zend_string *ret;
ZEND_ASSERT(len <= ZSTR_LEN(s));
- if (!ZSTR_IS_INTERNED(s)) {
+ if (ZSTR_IS_REFCOUNTED(s)) {
if (EXPECTED(GC_REFCOUNT(s) == 1)) {
ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(len)), persistent);
ZSTR_LEN(ret) = len;
@@ -241,7 +242,7 @@ static zend_always_inline zend_string *zend_string_safe_realloc(zend_string *s,
{
zend_string *ret;
- if (!ZSTR_IS_INTERNED(s)) {
+ if (ZSTR_IS_REFCOUNTED(s)) {
if (GC_REFCOUNT(s) == 1) {
ret = (zend_string *)safe_perealloc(s, n, m, ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(l)), persistent);
ZSTR_LEN(ret) = (n * m) + l;
@@ -266,7 +267,7 @@ static zend_always_inline void zend_string_free(zend_string *s)
static zend_always_inline void zend_string_release(zend_string *s)
{
- if (!ZSTR_IS_INTERNED(s)) {
+ if (ZSTR_IS_REFCOUNTED(s)) {
if (--GC_REFCOUNT(s) == 0) {
pefree(s, GC_FLAGS(s) & IS_STR_PERSISTENT);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment