Skip to content

Commit eb34c28

Browse files
MaxKellermannGirgias
authored andcommitted
Zend/zend_types.h: move zend_refcounted to zend_refcounted.h
This is necessary for splitting `zend_types.h` further.
1 parent b98f18e commit eb34c28

File tree

2 files changed

+138
-94
lines changed

2 files changed

+138
-94
lines changed

Zend/zend_refcounted.h

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Zend Engine |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 2.00 of the Zend license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available through the world-wide-web at the following url: |
10+
| http://www.zend.com/license/2_00.txt. |
11+
| If you did not receive a copy of the Zend license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
*/
16+
17+
#ifndef ZEND_REFCOUNTED_H
18+
#define ZEND_REFCOUNTED_H
19+
20+
#include "zend_portability.h"
21+
#include "zend_rc_debug.h"
22+
#include "zend_type_code.h"
23+
24+
#include <stdint.h>
25+
26+
#define GC_TYPE_MASK 0x0000000f
27+
#define GC_FLAGS_MASK 0x000003f0
28+
#define GC_INFO_MASK 0xfffffc00
29+
#define GC_FLAGS_SHIFT 0
30+
#define GC_INFO_SHIFT 10
31+
32+
/* zval_gc_flags(zval.value->gc.u.type_info) (common flags) */
33+
#define GC_NOT_COLLECTABLE (1<<4)
34+
#define GC_PROTECTED (1<<5) /* used for recursion detection */
35+
#define GC_IMMUTABLE (1<<6) /* can't be changed in place */
36+
#define GC_PERSISTENT (1<<7) /* allocated using malloc */
37+
#define GC_PERSISTENT_LOCAL (1<<8) /* persistent, but thread-local */
38+
39+
#define GC_TYPE_INFO(p) (p)->gc.u.type_info
40+
#define GC_TYPE(p) zval_gc_type(GC_TYPE_INFO(p))
41+
#define GC_FLAGS(p) zval_gc_flags(GC_TYPE_INFO(p))
42+
#define GC_INFO(p) zval_gc_info(GC_TYPE_INFO(p))
43+
44+
#define GC_ADD_FLAGS(p, flags) do { \
45+
GC_TYPE_INFO(p) |= (flags) << GC_FLAGS_SHIFT; \
46+
} while (0)
47+
#define GC_DEL_FLAGS(p, flags) do { \
48+
GC_TYPE_INFO(p) &= ~((flags) << GC_FLAGS_SHIFT); \
49+
} while (0)
50+
51+
#define GC_REFCOUNT(p) zend_gc_refcount(&(p)->gc)
52+
#define GC_SET_REFCOUNT(p, rc) zend_gc_set_refcount(&(p)->gc, rc)
53+
#define GC_ADDREF(p) zend_gc_addref(&(p)->gc)
54+
#define GC_DELREF(p) zend_gc_delref(&(p)->gc)
55+
#define GC_ADDREF_EX(p, rc) zend_gc_addref_ex(&(p)->gc, rc)
56+
#define GC_DELREF_EX(p, rc) zend_gc_delref_ex(&(p)->gc, rc)
57+
#define GC_TRY_ADDREF(p) zend_gc_try_addref(&(p)->gc)
58+
#define GC_TRY_DELREF(p) zend_gc_try_delref(&(p)->gc)
59+
60+
#define GC_NULL (IS_NULL | (GC_NOT_COLLECTABLE << GC_FLAGS_SHIFT))
61+
#define GC_STRING (IS_STRING | (GC_NOT_COLLECTABLE << GC_FLAGS_SHIFT))
62+
#define GC_ARRAY IS_ARRAY
63+
#define GC_OBJECT IS_OBJECT
64+
#define GC_RESOURCE (IS_RESOURCE | (GC_NOT_COLLECTABLE << GC_FLAGS_SHIFT))
65+
#define GC_REFERENCE (IS_REFERENCE | (GC_NOT_COLLECTABLE << GC_FLAGS_SHIFT))
66+
#define GC_CONSTANT_AST (IS_CONSTANT_AST | (GC_NOT_COLLECTABLE << GC_FLAGS_SHIFT))
67+
68+
typedef struct _zend_refcounted_h {
69+
uint32_t refcount; /* reference counter 32-bit */
70+
union {
71+
uint32_t type_info;
72+
} u;
73+
} zend_refcounted_h;
74+
75+
typedef struct _zend_refcounted {
76+
zend_refcounted_h gc;
77+
} zend_refcounted;
78+
79+
static zend_always_inline uint8_t zval_gc_type(uint32_t gc_type_info) {
80+
return (gc_type_info & GC_TYPE_MASK);
81+
}
82+
83+
static zend_always_inline uint32_t zval_gc_flags(uint32_t gc_type_info) {
84+
return (gc_type_info >> GC_FLAGS_SHIFT) & (GC_FLAGS_MASK >> GC_FLAGS_SHIFT);
85+
}
86+
87+
static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
88+
return (gc_type_info >> GC_INFO_SHIFT);
89+
}
90+
91+
static zend_always_inline uint32_t zend_gc_refcount(const zend_refcounted_h *p) {
92+
return p->refcount;
93+
}
94+
95+
static zend_always_inline uint32_t zend_gc_set_refcount(zend_refcounted_h *p, uint32_t rc) {
96+
p->refcount = rc;
97+
return p->refcount;
98+
}
99+
100+
static zend_always_inline uint32_t zend_gc_addref(zend_refcounted_h *p) {
101+
ZEND_RC_MOD_CHECK(p);
102+
return ++(p->refcount);
103+
}
104+
105+
static zend_always_inline void zend_gc_try_addref(zend_refcounted_h *p) {
106+
if (!(p->u.type_info & GC_IMMUTABLE)) {
107+
ZEND_RC_MOD_CHECK(p);
108+
++p->refcount;
109+
}
110+
}
111+
112+
static zend_always_inline void zend_gc_try_delref(zend_refcounted_h *p) {
113+
if (!(p->u.type_info & GC_IMMUTABLE)) {
114+
ZEND_RC_MOD_CHECK(p);
115+
--p->refcount;
116+
}
117+
}
118+
119+
static zend_always_inline uint32_t zend_gc_delref(zend_refcounted_h *p) {
120+
ZEND_ASSERT(p->refcount > 0);
121+
ZEND_RC_MOD_CHECK(p);
122+
return --(p->refcount);
123+
}
124+
125+
static zend_always_inline uint32_t zend_gc_addref_ex(zend_refcounted_h *p, uint32_t rc) {
126+
ZEND_RC_MOD_CHECK(p);
127+
p->refcount += rc;
128+
return p->refcount;
129+
}
130+
131+
static zend_always_inline uint32_t zend_gc_delref_ex(zend_refcounted_h *p, uint32_t rc) {
132+
ZEND_RC_MOD_CHECK(p);
133+
p->refcount -= rc;
134+
return p->refcount;
135+
}
136+
137+
#endif /* ZEND_REFCOUNTED_H */

Zend/zend_types.h

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "zend_portability.h"
2626
#include "zend_long.h"
2727
#include "zend_rc_debug.h"
28+
#include "zend_refcounted.h"
2829
#include "zend_result.h"
2930
#include "zend_type_code.h"
3031

@@ -83,7 +84,6 @@ typedef struct _zend_execute_data zend_execute_data;
8384

8485
typedef struct _zval_struct zval;
8586

86-
typedef struct _zend_refcounted zend_refcounted;
8787
typedef struct _zend_string zend_string;
8888
typedef struct _zend_array zend_array;
8989
typedef struct _zend_object zend_object;
@@ -333,17 +333,6 @@ struct _zval_struct {
333333
} u2;
334334
};
335335

336-
typedef struct _zend_refcounted_h {
337-
uint32_t refcount; /* reference counter 32-bit */
338-
union {
339-
uint32_t type_info;
340-
} u;
341-
} zend_refcounted_h;
342-
343-
struct _zend_refcounted {
344-
zend_refcounted_h gc;
345-
};
346-
347336
struct _zend_string {
348337
zend_refcounted_h gc;
349338
zend_ulong h; /* hash value */
@@ -588,33 +577,12 @@ static zend_always_inline uint8_t zval_get_type(const zval* pz) {
588577

589578
#define Z_TYPE_FLAGS_SHIFT 8
590579

591-
#define GC_REFCOUNT(p) zend_gc_refcount(&(p)->gc)
592-
#define GC_SET_REFCOUNT(p, rc) zend_gc_set_refcount(&(p)->gc, rc)
593-
#define GC_ADDREF(p) zend_gc_addref(&(p)->gc)
594-
#define GC_DELREF(p) zend_gc_delref(&(p)->gc)
595-
#define GC_ADDREF_EX(p, rc) zend_gc_addref_ex(&(p)->gc, rc)
596-
#define GC_DELREF_EX(p, rc) zend_gc_delref_ex(&(p)->gc, rc)
597-
#define GC_TRY_ADDREF(p) zend_gc_try_addref(&(p)->gc)
598-
#define GC_TRY_DELREF(p) zend_gc_try_delref(&(p)->gc)
599-
600580
#define GC_TYPE_MASK 0x0000000f
601581
#define GC_FLAGS_MASK 0x000003f0
602582
#define GC_INFO_MASK 0xfffffc00
603583
#define GC_FLAGS_SHIFT 0
604584
#define GC_INFO_SHIFT 10
605585

606-
static zend_always_inline uint8_t zval_gc_type(uint32_t gc_type_info) {
607-
return (gc_type_info & GC_TYPE_MASK);
608-
}
609-
610-
static zend_always_inline uint32_t zval_gc_flags(uint32_t gc_type_info) {
611-
return (gc_type_info >> GC_FLAGS_SHIFT) & (GC_FLAGS_MASK >> GC_FLAGS_SHIFT);
612-
}
613-
614-
static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
615-
return (gc_type_info >> GC_INFO_SHIFT);
616-
}
617-
618586
#define GC_TYPE_INFO(p) (p)->gc.u.type_info
619587
#define GC_TYPE(p) zval_gc_type(GC_TYPE_INFO(p))
620588
#define GC_FLAGS(p) zval_gc_flags(GC_TYPE_INFO(p))
@@ -638,21 +606,6 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
638606
#define Z_GC_TYPE_INFO(zval) GC_TYPE_INFO(Z_COUNTED(zval))
639607
#define Z_GC_TYPE_INFO_P(zval_p) Z_GC_TYPE_INFO(*(zval_p))
640608

641-
/* zval_gc_flags(zval.value->gc.u.type_info) (common flags) */
642-
#define GC_NOT_COLLECTABLE (1<<4)
643-
#define GC_PROTECTED (1<<5) /* used for recursion detection */
644-
#define GC_IMMUTABLE (1<<6) /* can't be changed in place */
645-
#define GC_PERSISTENT (1<<7) /* allocated using malloc */
646-
#define GC_PERSISTENT_LOCAL (1<<8) /* persistent, but thread-local */
647-
648-
#define GC_NULL (IS_NULL | (GC_NOT_COLLECTABLE << GC_FLAGS_SHIFT))
649-
#define GC_STRING (IS_STRING | (GC_NOT_COLLECTABLE << GC_FLAGS_SHIFT))
650-
#define GC_ARRAY IS_ARRAY
651-
#define GC_OBJECT IS_OBJECT
652-
#define GC_RESOURCE (IS_RESOURCE | (GC_NOT_COLLECTABLE << GC_FLAGS_SHIFT))
653-
#define GC_REFERENCE (IS_REFERENCE | (GC_NOT_COLLECTABLE << GC_FLAGS_SHIFT))
654-
#define GC_CONSTANT_AST (IS_CONSTANT_AST | (GC_NOT_COLLECTABLE << GC_FLAGS_SHIFT))
655-
656609
/* zval.u1.v.type_flags */
657610
#define IS_TYPE_REFCOUNTED (1<<0)
658611
#define IS_TYPE_COLLECTABLE (1<<1)
@@ -1134,52 +1087,6 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
11341087
do { } while (0)
11351088
#endif
11361089

1137-
static zend_always_inline uint32_t zend_gc_refcount(const zend_refcounted_h *p) {
1138-
return p->refcount;
1139-
}
1140-
1141-
static zend_always_inline uint32_t zend_gc_set_refcount(zend_refcounted_h *p, uint32_t rc) {
1142-
p->refcount = rc;
1143-
return p->refcount;
1144-
}
1145-
1146-
static zend_always_inline uint32_t zend_gc_addref(zend_refcounted_h *p) {
1147-
ZEND_RC_MOD_CHECK(p);
1148-
return ++(p->refcount);
1149-
}
1150-
1151-
static zend_always_inline void zend_gc_try_addref(zend_refcounted_h *p) {
1152-
if (!(p->u.type_info & GC_IMMUTABLE)) {
1153-
ZEND_RC_MOD_CHECK(p);
1154-
++p->refcount;
1155-
}
1156-
}
1157-
1158-
static zend_always_inline void zend_gc_try_delref(zend_refcounted_h *p) {
1159-
if (!(p->u.type_info & GC_IMMUTABLE)) {
1160-
ZEND_RC_MOD_CHECK(p);
1161-
--p->refcount;
1162-
}
1163-
}
1164-
1165-
static zend_always_inline uint32_t zend_gc_delref(zend_refcounted_h *p) {
1166-
ZEND_ASSERT(p->refcount > 0);
1167-
ZEND_RC_MOD_CHECK(p);
1168-
return --(p->refcount);
1169-
}
1170-
1171-
static zend_always_inline uint32_t zend_gc_addref_ex(zend_refcounted_h *p, uint32_t rc) {
1172-
ZEND_RC_MOD_CHECK(p);
1173-
p->refcount += rc;
1174-
return p->refcount;
1175-
}
1176-
1177-
static zend_always_inline uint32_t zend_gc_delref_ex(zend_refcounted_h *p, uint32_t rc) {
1178-
ZEND_RC_MOD_CHECK(p);
1179-
p->refcount -= rc;
1180-
return p->refcount;
1181-
}
1182-
11831090
static zend_always_inline uint32_t zval_refcount_p(const zval* pz) {
11841091
#if ZEND_DEBUG
11851092
ZEND_ASSERT(Z_REFCOUNTED_P(pz) || Z_TYPE_P(pz) == IS_ARRAY);

0 commit comments

Comments
 (0)