|
22 | 22 |
|
23 | 23 | #include "php.h"
|
24 | 24 | #include "php_assert.h"
|
| 25 | +#include "php_ini.h" |
25 | 26 |
|
26 | 27 | typedef struct {
|
27 | 28 | int active;
|
28 |
| - int exit; |
| 29 | + int bail; |
29 | 30 | int warning;
|
30 | 31 | char *callback;
|
31 | 32 | } php_assert_globals;
|
@@ -71,68 +72,61 @@ zend_module_entry assert_module_entry = {
|
71 | 72 |
|
72 | 73 | #define ASSERT_ACTIVE 1
|
73 | 74 | #define ASSERT_CALLBACK 2
|
74 |
| -#define ASSERT_EXIT 3 |
| 75 | +#define ASSERT_BAIL 3 |
75 | 76 | #define ASSERT_WARNING 4
|
76 | 77 |
|
77 |
| -#ifdef ZTS |
78 |
| -static void php_assert_init_globals(php_assert_globals *assert_globals) |
79 |
| -{ |
80 |
| - ASSERT(active) = 0; |
81 |
| - ASSERT(exit) = 0; |
82 |
| - ASSERT(callback) = 0; |
83 |
| - ASSERT(warning) = 1; |
84 |
| -} |
85 |
| -#endif |
| 78 | +PHP_INI_BEGIN() |
| 79 | + STD_PHP_INI_BOOLEAN("assert.active", "0", PHP_INI_ALL, OnUpdateInt, active, php_assert_globals, assert_globals) |
| 80 | + STD_PHP_INI_BOOLEAN("assert.bail", "0", PHP_INI_ALL, OnUpdateInt, bail, php_assert_globals, assert_globals) |
| 81 | + STD_PHP_INI_BOOLEAN("assert.warning", "1", PHP_INI_ALL, OnUpdateInt, warning, php_assert_globals, assert_globals) |
| 82 | + PHP_INI_ENTRY("assert.callback", NULL, PHP_INI_ALL, NULL) |
| 83 | +PHP_INI_END() |
86 | 84 |
|
87 | 85 | PHP_MINIT_FUNCTION(assert)
|
88 | 86 | {
|
89 | 87 |
|
90 | 88 | #ifdef ZTS
|
91 | 89 | assert_globals_id = ts_allocate_id(sizeof(php_assert_globals), (ts_allocate_ctor) php_assert_init_globals, NULL);
|
92 |
| -#else |
93 |
| - ASSERT(active) = 0; |
94 |
| - ASSERT(exit) = 0; |
95 |
| - ASSERT(callback) = 0; |
96 |
| - ASSERT(warning) = 1; |
97 | 90 | #endif
|
98 | 91 |
|
| 92 | + REGISTER_INI_ENTRIES(); |
| 93 | + |
99 | 94 | REGISTER_LONG_CONSTANT("ASSERT_ACTIVE", ASSERT_ACTIVE, CONST_CS|CONST_PERSISTENT);
|
100 | 95 | REGISTER_LONG_CONSTANT("ASSERT_CALLBACK", ASSERT_CALLBACK, CONST_CS|CONST_PERSISTENT);
|
101 |
| - REGISTER_LONG_CONSTANT("ASSERT_EXIT", ASSERT_EXIT, CONST_CS|CONST_PERSISTENT); |
| 96 | + REGISTER_LONG_CONSTANT("ASSERT_BAIL", ASSERT_BAIL, CONST_CS|CONST_PERSISTENT); |
102 | 97 | REGISTER_LONG_CONSTANT("ASSERT_WARNING", ASSERT_WARNING, CONST_CS|CONST_PERSISTENT);
|
103 | 98 |
|
104 | 99 | return SUCCESS;
|
105 | 100 | }
|
106 | 101 |
|
107 | 102 | PHP_MSHUTDOWN_FUNCTION(assert)
|
108 | 103 | {
|
109 |
| - if (ASSERT(callback)) { |
110 |
| - efree(ASSERT(callback)); |
111 |
| - ASSERT(callback) = NULL; |
112 |
| - } |
113 |
| - |
114 | 104 | return SUCCESS;
|
115 | 105 | }
|
116 | 106 |
|
117 | 107 | PHP_RINIT_FUNCTION(assert)
|
118 | 108 | {
|
| 109 | + ASSERTLS_FETCH(); |
| 110 | + |
| 111 | + ASSERT(callback) = estrdup(INI_STR("assert.callback")); |
| 112 | + |
119 | 113 | return SUCCESS;
|
120 | 114 | }
|
121 | 115 |
|
122 | 116 | PHP_RSHUTDOWN_FUNCTION(assert)
|
123 | 117 | {
|
124 | 118 | ASSERTLS_FETCH();
|
125 |
| - |
126 |
| - if (ASSERT(callback)) { |
127 |
| - efree(ASSERT(callback)); |
128 |
| - ASSERT(callback) = NULL; |
129 |
| - } |
| 119 | + |
| 120 | + if (ASSERT(callback)) efree(ASSERT(callback)); |
130 | 121 |
|
131 | 122 | return SUCCESS;
|
132 | 123 | }
|
133 | 124 |
|
134 | 125 | PHP_MINFO_FUNCTION(assert)
|
135 | 126 | {
|
| 127 | + ASSERTLS_FETCH(); |
| 128 | + |
| 129 | + DISPLAY_INI_ENTRIES(); |
136 | 130 | }
|
137 | 131 |
|
138 | 132 | /* }}} */
|
@@ -221,7 +215,7 @@ PHP_FUNCTION(assert)
|
221 | 215 | }
|
222 | 216 | }
|
223 | 217 |
|
224 |
| - if (ASSERT(exit)) { |
| 218 | + if (ASSERT(bail)) { |
225 | 219 | zend_bailout();
|
226 | 220 | }
|
227 | 221 | }
|
@@ -254,11 +248,11 @@ PHP_FUNCTION(assert_options)
|
254 | 248 | RETURN_LONG(oldint);
|
255 | 249 | break;
|
256 | 250 |
|
257 |
| - case ASSERT_EXIT: |
258 |
| - oldint = ASSERT(exit); |
| 251 | + case ASSERT_BAIL: |
| 252 | + oldint = ASSERT(bail); |
259 | 253 | if (ac == 2) {
|
260 | 254 | convert_to_long_ex(value);
|
261 |
| - ASSERT(exit) = (*value)->value.lval; |
| 255 | + ASSERT(bail) = (*value)->value.lval; |
262 | 256 | }
|
263 | 257 | RETURN_LONG(oldint);
|
264 | 258 | break;
|
|
0 commit comments