Skip to content

Commit e509a66

Browse files
MaxKellermannGirgias
authored andcommitted
Zend/zend_rc_debug: convert ZEND_RC_MOD_CHECK() to function
This allows using `ZEND_RC_MOD_CHECK()` without including any additional headers. Performance is not relevant here because this is a debug-only feature. The `zend_refcounted_h` forward declaration is necessary to break a circular header dependency.
1 parent d6e9504 commit e509a66

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

Zend/zend_rc_debug.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,26 @@
1717
#include "zend_rc_debug.h"
1818

1919
#if ZEND_RC_DEBUG
20+
21+
#include "zend_types.h"
22+
2023
ZEND_API bool zend_rc_debug = false;
24+
25+
ZEND_API void ZEND_RC_MOD_CHECK(const zend_refcounted_h *p)
26+
{
27+
if (!zend_rc_debug) {
28+
return;
29+
}
30+
31+
uint8_t type = zval_gc_type(p->u.type_info);
32+
33+
/* Skip checks for OBJECT/NULL type to avoid interpreting the flag incorrectly. */
34+
if (type != IS_OBJECT && type != IS_NULL) {
35+
ZEND_ASSERT(!(zval_gc_flags(p->u.type_info) & GC_IMMUTABLE));
36+
37+
/* The GC_PERSISTENT flag is reused for IS_OBJ_WEAKLY_REFERENCED on objects. */
38+
ZEND_ASSERT((zval_gc_flags(p->u.type_info) & (GC_PERSISTENT|GC_PERSISTENT_LOCAL)) != GC_PERSISTENT);
39+
}
40+
}
41+
2142
#endif

Zend/zend_rc_debug.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,18 @@
3232
#include <stdbool.h>
3333
#include <stdint.h>
3434

35+
#include "zend_portability.h"
36+
37+
typedef struct _zend_refcounted_h zend_refcounted_h;
38+
3539
extern ZEND_API bool zend_rc_debug;
3640

37-
/* The GC_PERSISTENT flag is reused for IS_OBJ_WEAKLY_REFERENCED on objects.
38-
* Skip checks for OBJECT/NULL type to avoid interpreting the flag incorrectly. */
39-
# define ZEND_RC_MOD_CHECK(p) do { \
40-
if (zend_rc_debug) { \
41-
uint8_t type = zval_gc_type((p)->u.type_info); \
42-
if (type != IS_OBJECT && type != IS_NULL) { \
43-
ZEND_ASSERT(!(zval_gc_flags((p)->u.type_info) & GC_IMMUTABLE)); \
44-
ZEND_ASSERT((zval_gc_flags((p)->u.type_info) & (GC_PERSISTENT|GC_PERSISTENT_LOCAL)) != GC_PERSISTENT); \
45-
} \
46-
} \
47-
} while (0)
41+
BEGIN_EXTERN_C()
42+
43+
ZEND_API void ZEND_RC_MOD_CHECK(const zend_refcounted_h *p);
44+
45+
END_EXTERN_C()
46+
4847
#else
4948
# define ZEND_RC_MOD_CHECK(p) \
5049
do { } while (0)

0 commit comments

Comments
 (0)