Skip to content

Commit af80d8a

Browse files
committed
Add more argument types to stubs
Closes GH-5943
1 parent 3bb1830 commit af80d8a

34 files changed

+418
-309
lines changed

UPGRADING.INTERNALS

+4
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ PHP 8.0 INTERNALS UPGRADE NOTES
174174
- zend_set_hash_symbol()
175175
5. Argument zval* to zend_object* in Zend Engine 4.0:
176176
- zend_get_closure_method_def()
177+
- zend_throw_exception_hook()
178+
- zend_throw_exception_internal()
179+
6. Argument zval* to zend_long in Zend Engine 4.0:
180+
- _php_math_longtobase()
177181

178182
u. Instead of overwriting zend_error_cb extensions with debugging, monitoring
179183
use-cases catching Errors/Exceptions are strongly encouraged to use

Zend/zend_exceptions.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ZEND_API zend_class_entry *zend_ce_unhandled_match_error;
4545
/* Internal pseudo-exception that is not exposed to userland. */
4646
static zend_class_entry zend_ce_unwind_exit;
4747

48-
ZEND_API void (*zend_throw_exception_hook)(zval *ex);
48+
ZEND_API void (*zend_throw_exception_hook)(zend_object *ex);
4949

5050
static zend_object_handlers default_exception_handlers;
5151

@@ -144,12 +144,12 @@ void zend_exception_restore(void) /* {{{ */
144144
}
145145
/* }}} */
146146

147-
ZEND_API ZEND_COLD void zend_throw_exception_internal(zval *exception) /* {{{ */
147+
ZEND_API ZEND_COLD void zend_throw_exception_internal(zend_object *exception) /* {{{ */
148148
{
149149
#ifdef HAVE_DTRACE
150150
if (DTRACE_EXCEPTION_THROWN_ENABLED()) {
151151
if (exception != NULL) {
152-
DTRACE_EXCEPTION_THROWN(ZSTR_VAL(Z_OBJ_P(exception)->ce->name));
152+
DTRACE_EXCEPTION_THROWN(ZSTR_VAL(exception->ce->name));
153153
} else {
154154
DTRACE_EXCEPTION_THROWN(NULL);
155155
}
@@ -158,14 +158,14 @@ ZEND_API ZEND_COLD void zend_throw_exception_internal(zval *exception) /* {{{ */
158158

159159
if (exception != NULL) {
160160
zend_object *previous = EG(exception);
161-
zend_exception_set_previous(Z_OBJ_P(exception), EG(exception));
162-
EG(exception) = Z_OBJ_P(exception);
161+
zend_exception_set_previous(exception, EG(exception));
162+
EG(exception) = exception;
163163
if (previous) {
164164
return;
165165
}
166166
}
167167
if (!EG(current_execute_data)) {
168-
if (exception && (Z_OBJCE_P(exception) == zend_ce_parse_error || Z_OBJCE_P(exception) == zend_ce_compile_error)) {
168+
if (exception && (exception->ce == zend_ce_parse_error || exception->ce == zend_ce_compile_error)) {
169169
return;
170170
}
171171
if (EG(exception)) {
@@ -854,7 +854,8 @@ static zend_object *zend_throw_exception_zstr(zend_class_entry *exception_ce, ze
854854
zend_update_property_ex(exception_ce, &ex, ZSTR_KNOWN(ZEND_STR_CODE), &tmp);
855855
}
856856

857-
zend_throw_exception_internal(&ex);
857+
zend_throw_exception_internal(Z_OBJ(ex));
858+
858859
return Z_OBJ(ex);
859860
}
860861
/* }}} */
@@ -987,20 +988,19 @@ ZEND_API ZEND_COLD int zend_exception_error(zend_object *ex, int severity) /* {{
987988

988989
ZEND_API ZEND_COLD void zend_throw_exception_object(zval *exception) /* {{{ */
989990
{
990-
zend_class_entry *exception_ce;
991-
992991
if (exception == NULL || Z_TYPE_P(exception) != IS_OBJECT) {
993992
zend_error_noreturn(E_CORE_ERROR, "Need to supply an object when throwing an exception");
994993
}
995994

996-
exception_ce = Z_OBJCE_P(exception);
995+
zend_class_entry *exception_ce = Z_OBJCE_P(exception);
997996

998997
if (!exception_ce || !instanceof_function(exception_ce, zend_ce_throwable)) {
999998
zend_throw_error(NULL, "Cannot throw objects that do not implement Throwable");
1000999
zval_ptr_dtor(exception);
10011000
return;
10021001
}
1003-
zend_throw_exception_internal(exception);
1002+
1003+
zend_throw_exception_internal(Z_OBJ_P(exception));
10041004
}
10051005
/* }}} */
10061006

Zend/zend_exceptions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ZEND_API void zend_exception_set_previous(zend_object *exception, zend_object *a
4141
ZEND_API void zend_exception_save(void);
4242
ZEND_API void zend_exception_restore(void);
4343

44-
ZEND_API ZEND_COLD void zend_throw_exception_internal(zval *exception);
44+
ZEND_API ZEND_COLD void zend_throw_exception_internal(zend_object *exception);
4545

4646
void zend_register_default_exception(void);
4747

@@ -64,7 +64,7 @@ ZEND_API void zend_clear_exception(void);
6464

6565
ZEND_API zend_object *zend_throw_error_exception(zend_class_entry *exception_ce, zend_string *message, zend_long code, int severity);
6666

67-
extern ZEND_API void (*zend_throw_exception_hook)(zval *ex);
67+
extern ZEND_API void (*zend_throw_exception_hook)(zend_object *ex);
6868

6969
/* show an exception using zend_error(severity,...), severity should be E_ERROR */
7070
ZEND_API ZEND_COLD int zend_exception_error(zend_object *exception, int severity);

ext/sockets/sockets.stub.php

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function socket_strerror(int $errno): string {}
4848

4949
function socket_bind(Socket $socket, string $addr, int $port = 0): bool {}
5050

51+
/** @param string|null $buf */
5152
function socket_recv(Socket $socket, &$buf, int $len, int $flags): int|false {}
5253

5354
function socket_send(Socket $socket, string $buf, int $len, int $flags): int|false {}

ext/sockets/sockets_arginfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 3256069f3943ec6dac1db915d737324962dda7c4 */
2+
* Stub hash: 8d03ee514902490691aa4a9b8801fbc10b5b9c26 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_socket_select, 0, 4, MAY_BE_LONG|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(1, read_fds, IS_ARRAY, 1)

ext/standard/assert.c

+24-29
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,29 @@ PHP_MINFO_FUNCTION(assert) /* {{{ */
139139
PHP_FUNCTION(assert)
140140
{
141141
zval *assertion;
142-
zval *description = NULL;
142+
zend_string *description_str = NULL;
143+
zend_object *description_obj = NULL;
143144

144-
if (! ASSERTG(active)) {
145+
if (!ASSERTG(active)) {
145146
RETURN_TRUE;
146147
}
147148

148149
ZEND_PARSE_PARAMETERS_START(1, 2)
149150
Z_PARAM_ZVAL(assertion)
150151
Z_PARAM_OPTIONAL
151-
Z_PARAM_ZVAL(description)
152+
Z_PARAM_STR_OR_OBJ_OF_CLASS_OR_NULL(description_str, description_obj, zend_ce_throwable)
152153
ZEND_PARSE_PARAMETERS_END();
153154

154155
if (zend_is_true(assertion)) {
155156
RETURN_TRUE;
156157
}
157158

159+
if (description_obj) {
160+
GC_ADDREF(description_obj);
161+
zend_throw_exception_internal(description_obj);
162+
RETURN_THROWS();
163+
}
164+
158165
if (Z_TYPE(ASSERTG(callback)) == IS_UNDEF && ASSERTG(cb)) {
159166
ZVAL_STRING(&ASSERTG(callback), ASSERTG(cb));
160167
}
@@ -171,15 +178,14 @@ PHP_FUNCTION(assert)
171178

172179
ZVAL_FALSE(&retval);
173180

174-
/* XXX do we want to check for error here? */
175-
if (!description) {
176-
call_user_function(NULL, NULL, &ASSERTG(callback), &retval, 3, args);
181+
if (description_str) {
182+
ZVAL_STR(&args[3], description_str);
183+
call_user_function(NULL, NULL, &ASSERTG(callback), &retval, 4, args);
184+
zval_ptr_dtor(&(args[3]));
177185
zval_ptr_dtor(&(args[2]));
178186
zval_ptr_dtor(&(args[0]));
179187
} else {
180-
ZVAL_STR(&args[3], zval_get_string(description));
181-
call_user_function(NULL, NULL, &ASSERTG(callback), &retval, 4, args);
182-
zval_ptr_dtor(&(args[3]));
188+
call_user_function(NULL, NULL, &ASSERTG(callback), &retval, 3, args);
183189
zval_ptr_dtor(&(args[2]));
184190
zval_ptr_dtor(&(args[0]));
185191
}
@@ -188,25 +194,9 @@ PHP_FUNCTION(assert)
188194
}
189195

190196
if (ASSERTG(exception)) {
191-
if (!description) {
192-
zend_throw_exception(assertion_error_ce, NULL, E_ERROR);
193-
} else if (Z_TYPE_P(description) == IS_OBJECT &&
194-
instanceof_function(Z_OBJCE_P(description), zend_ce_throwable)) {
195-
Z_ADDREF_P(description);
196-
zend_throw_exception_object(description);
197-
} else {
198-
zend_string *str = zval_get_string(description);
199-
zend_throw_exception(assertion_error_ce, ZSTR_VAL(str), E_ERROR);
200-
zend_string_release_ex(str, 0);
201-
}
197+
zend_throw_exception(assertion_error_ce, description_str ? ZSTR_VAL(description_str) : NULL, E_ERROR);
202198
} else if (ASSERTG(warning)) {
203-
if (!description) {
204-
php_error_docref(NULL, E_WARNING, "Assertion failed");
205-
} else {
206-
zend_string *str = zval_get_string(description);
207-
php_error_docref(NULL, E_WARNING, "%s failed", ZSTR_VAL(str));
208-
zend_string_release_ex(str, 0);
209-
}
199+
php_error_docref(NULL, E_WARNING, "%s failed", description_str ? ZSTR_VAL(description_str) : "Assertion failed");
210200
}
211201

212202
if (ASSERTG(bail)) {
@@ -289,9 +279,14 @@ PHP_FUNCTION(assert_options)
289279
} else {
290280
RETVAL_NULL();
291281
}
282+
292283
if (ac == 2) {
293284
zval_ptr_dtor(&ASSERTG(callback));
294-
ZVAL_COPY(&ASSERTG(callback), value);
285+
if (Z_TYPE_P(value) == IS_NULL) {
286+
ZVAL_UNDEF(&ASSERTG(callback));
287+
} else {
288+
ZVAL_COPY(&ASSERTG(callback), value);
289+
}
295290
}
296291
return;
297292

@@ -312,7 +307,7 @@ PHP_FUNCTION(assert_options)
312307
break;
313308

314309
default:
315-
zend_argument_value_error(1, "must have a valid value");
310+
zend_argument_value_error(1, "must be an ASSERT_* constant");
316311
RETURN_THROWS();
317312
}
318313
}

ext/standard/basic_functions.c

+4-7
Original file line numberDiff line numberDiff line change
@@ -2460,23 +2460,20 @@ PHP_FUNCTION(register_tick_function)
24602460
/* {{{ Unregisters a tick callback function */
24612461
PHP_FUNCTION(unregister_tick_function)
24622462
{
2463-
zval *function;
24642463
user_tick_function_entry tick_fe;
2464+
zend_fcall_info fci;
2465+
zend_fcall_info_cache fci_cache;
24652466

24662467
ZEND_PARSE_PARAMETERS_START(1, 1)
2467-
Z_PARAM_ZVAL(function)
2468+
Z_PARAM_FUNC(fci, fci_cache)
24682469
ZEND_PARSE_PARAMETERS_END();
24692470

24702471
if (!BG(user_tick_functions)) {
24712472
return;
24722473
}
24732474

2474-
if (Z_TYPE_P(function) != IS_ARRAY && Z_TYPE_P(function) != IS_OBJECT) {
2475-
convert_to_string(function);
2476-
}
2477-
24782475
tick_fe.arguments = (zval *) emalloc(sizeof(zval));
2479-
ZVAL_COPY_VALUE(&tick_fe.arguments[0], function);
2476+
ZVAL_COPY_VALUE(&tick_fe.arguments[0], &fci.function_name);
24802477
tick_fe.arg_count = 1;
24812478
zend_llist_del_element(BG(user_tick_functions), &tick_fe, (int (*)(void *, void *)) user_tick_function_compare);
24822479
efree(tick_fe.arguments);

0 commit comments

Comments
 (0)