Zend/zend_types.h: move zend_rc_debug to zend_rc_debug.h

`zend_rc_debug` is not a type and does not really belong in
`zend_types.h`; this allows using `ZEND_RC_MOD_CHECK()` without
including the huge `zend_types.h` header and allows decoupling
circular header dependencies.
This commit is contained in:
Max Kellermann 2023-01-13 19:22:53 +01:00 committed by George Peter Banyard
parent 9108a32bfe
commit d6e95041e2
11 changed files with 82 additions and 22 deletions

View File

@ -94,10 +94,6 @@ void (*zend_on_timeout)(int seconds);
static void (*zend_message_dispatcher_p)(zend_long message, const void *data); static void (*zend_message_dispatcher_p)(zend_long message, const void *data);
static zval *(*zend_get_configuration_directive_p)(zend_string *name); static zval *(*zend_get_configuration_directive_p)(zend_string *name);
#if ZEND_RC_DEBUG
ZEND_API bool zend_rc_debug = 0;
#endif
static ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */ static ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
{ {
if (!new_value) { if (!new_value) {

View File

@ -32,6 +32,7 @@
#include "zend_ini.h" #include "zend_ini.h"
#include "zend_enum.h" #include "zend_enum.h"
#include "zend_observer.h" #include "zend_observer.h"
#include "zend_rc_debug.h"
#include <stdarg.h> #include <stdarg.h>

21
Zend/zend_rc_debug.c Normal file
View File

@ -0,0 +1,21 @@
/*
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
| Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 2.00 of the Zend license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.zend.com/license/2_00.txt. |
| If you did not receive a copy of the Zend license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@zend.com so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#include "zend_rc_debug.h"
#if ZEND_RC_DEBUG
ZEND_API bool zend_rc_debug = false;
#endif

53
Zend/zend_rc_debug.h Normal file
View File

@ -0,0 +1,53 @@
/*
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
| Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 2.00 of the Zend license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.zend.com/license/2_00.txt. |
| If you did not receive a copy of the Zend license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@zend.com so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef ZEND_RC_DEBUG_H
#define ZEND_RC_DEBUG_H
#ifndef ZEND_RC_DEBUG
# define ZEND_RC_DEBUG 0
#endif
#if ZEND_RC_DEBUG
#ifdef PHP_WIN32
# include "zend_config.w32.h"
#else
# include "zend_config.h"
#endif
#include <stdbool.h>
#include <stdint.h>
extern ZEND_API bool zend_rc_debug;
/* The GC_PERSISTENT flag is reused for IS_OBJ_WEAKLY_REFERENCED on objects.
* Skip checks for OBJECT/NULL type to avoid interpreting the flag incorrectly. */
# define ZEND_RC_MOD_CHECK(p) do { \
if (zend_rc_debug) { \
uint8_t type = zval_gc_type((p)->u.type_info); \
if (type != IS_OBJECT && type != IS_NULL) { \
ZEND_ASSERT(!(zval_gc_flags((p)->u.type_info) & GC_IMMUTABLE)); \
ZEND_ASSERT((zval_gc_flags((p)->u.type_info) & (GC_PERSISTENT|GC_PERSISTENT_LOCAL)) != GC_PERSISTENT); \
} \
} \
} while (0)
#else
# define ZEND_RC_MOD_CHECK(p) \
do { } while (0)
#endif
#endif /* ZEND_RC_DEBUG_H */

View File

@ -18,6 +18,7 @@
#include "zend.h" #include "zend.h"
#include "zend_globals.h" #include "zend_globals.h"
#include "zend_rc_debug.h"
#ifdef HAVE_VALGRIND #ifdef HAVE_VALGRIND
# include "valgrind/callgrind.h" # include "valgrind/callgrind.h"

View File

@ -24,6 +24,7 @@
#include "zend_portability.h" #include "zend_portability.h"
#include "zend_long.h" #include "zend_long.h"
#include "zend_rc_debug.h"
#include "zend_result.h" #include "zend_result.h"
#include <stdbool.h> #include <stdbool.h>
@ -1161,29 +1162,11 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
#define Z_TRY_ADDREF(z) Z_TRY_ADDREF_P(&(z)) #define Z_TRY_ADDREF(z) Z_TRY_ADDREF_P(&(z))
#define Z_TRY_DELREF(z) Z_TRY_DELREF_P(&(z)) #define Z_TRY_DELREF(z) Z_TRY_DELREF_P(&(z))
#ifndef ZEND_RC_DEBUG
# define ZEND_RC_DEBUG 0
#endif
#if ZEND_RC_DEBUG #if ZEND_RC_DEBUG
extern ZEND_API bool zend_rc_debug;
/* The GC_PERSISTENT flag is reused for IS_OBJ_WEAKLY_REFERENCED on objects.
* Skip checks for OBJECT/NULL type to avoid interpreting the flag incorrectly. */
# define ZEND_RC_MOD_CHECK(p) do { \
if (zend_rc_debug) { \
uint8_t type = zval_gc_type((p)->u.type_info); \
if (type != IS_OBJECT && type != IS_NULL) { \
ZEND_ASSERT(!(zval_gc_flags((p)->u.type_info) & GC_IMMUTABLE)); \
ZEND_ASSERT((zval_gc_flags((p)->u.type_info) & (GC_PERSISTENT|GC_PERSISTENT_LOCAL)) != GC_PERSISTENT); \
} \
} \
} while (0)
# define GC_MAKE_PERSISTENT_LOCAL(p) do { \ # define GC_MAKE_PERSISTENT_LOCAL(p) do { \
GC_ADD_FLAGS(p, GC_PERSISTENT_LOCAL); \ GC_ADD_FLAGS(p, GC_PERSISTENT_LOCAL); \
} while (0) } while (0)
#else #else
# define ZEND_RC_MOD_CHECK(p) \
do { } while (0)
# define GC_MAKE_PERSISTENT_LOCAL(p) \ # define GC_MAKE_PERSISTENT_LOCAL(p) \
do { } while (0) do { } while (0)
#endif #endif

View File

@ -1722,6 +1722,7 @@ PHP_ADD_SOURCES(Zend, \
zend_virtual_cwd.c zend_ast.c zend_objects.c zend_object_handlers.c zend_objects_API.c \ zend_virtual_cwd.c zend_ast.c zend_objects.c zend_object_handlers.c zend_objects_API.c \
zend_default_classes.c zend_inheritance.c zend_smart_str.c zend_cpuinfo.c zend_gdb.c \ zend_default_classes.c zend_inheritance.c zend_smart_str.c zend_cpuinfo.c zend_gdb.c \
zend_observer.c zend_system_id.c zend_enum.c zend_fibers.c zend_atomic.c \ zend_observer.c zend_system_id.c zend_enum.c zend_fibers.c zend_atomic.c \
zend_rc_debug.c \
Optimizer/zend_optimizer.c \ Optimizer/zend_optimizer.c \
Optimizer/pass1.c \ Optimizer/pass1.c \
Optimizer/pass3.c \ Optimizer/pass3.c \

View File

@ -71,6 +71,7 @@
#include "zend_ini.h" #include "zend_ini.h"
#include "zend_dtrace.h" #include "zend_dtrace.h"
#include "zend_observer.h" #include "zend_observer.h"
#include "zend_rc_debug.h"
#include "zend_system_id.h" #include "zend_system_id.h"
#include "php_content_types.h" #include "php_content_types.h"

View File

@ -29,6 +29,7 @@
#include "php_version.h" #include "php_version.h"
#include "zend.h" #include "zend.h"
#include "zend_rc_debug.h"
#include "zend_sort.h" #include "zend_sort.h"
#include "php_compat.h" #include "php_compat.h"

View File

@ -22,6 +22,7 @@
#include "ext/standard/dl.h" #include "ext/standard/dl.h"
#include "zend_extensions.h" #include "zend_extensions.h"
#include "zend_highlight.h" #include "zend_highlight.h"
#include "zend_rc_debug.h"
#include "SAPI.h" #include "SAPI.h"
#include "php_main.h" #include "php_main.h"
#include "php_scandir.h" #include "php_scandir.h"

View File

@ -27,6 +27,7 @@
#include "php.h" #include "php.h"
#include "zend_ini_scanner.h" #include "zend_ini_scanner.h"
#include "zend_globals.h" #include "zend_globals.h"
#include "zend_rc_debug.h"
#include "zend_stream.h" #include "zend_stream.h"
#include "SAPI.h" #include "SAPI.h"