Skip to content

Commit 3ec1400

Browse files
committed
Remove UNDEF checks in userstream implementation
I don't see how object can be UNDEF here -- and just passing NULL in that case is not going to do anything reasonable either. It would fall back to global functions with the same name.
1 parent a93e12f commit 3ec1400

File tree

2 files changed

+25
-90
lines changed

2 files changed

+25
-90
lines changed

Zend/zend_execute_API.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,12 @@ zend_result _call_user_function_impl(zval *object, zval *function_name, zval *re
686686
zend_fcall_info fci;
687687

688688
fci.size = sizeof(fci);
689-
fci.object = object ? Z_OBJ_P(object) : NULL;
689+
if (object) {
690+
ZEND_ASSERT(Z_TYPE_P(object) == IS_OBJECT);
691+
fci.object = Z_OBJ_P(object);
692+
} else {
693+
fci.object = NULL;
694+
}
690695
ZVAL_COPY_VALUE(&fci.function_name, function_name);
691696
fci.retval = retval_ptr;
692697
fci.param_count = param_count;

main/streams/userspace.c

Lines changed: 19 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
350350
ZVAL_STRING(&zfuncname, USERSTREAM_OPEN);
351351

352352
zend_try {
353-
call_result = call_user_function(NULL,
354-
Z_ISUNDEF(us->object)? NULL : &us->object,
355-
&zfuncname,
356-
&zretval,
357-
4, args);
353+
call_result = call_user_function(NULL, &us->object, &zfuncname, &zretval, 4, args);
358354
} zend_catch {
359355
FG(user_stream_current_filename) = NULL;
360356
zend_bailout();
@@ -428,11 +424,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char
428424

429425
ZVAL_STRING(&zfuncname, USERSTREAM_DIR_OPEN);
430426

431-
call_result = call_user_function(NULL,
432-
Z_ISUNDEF(us->object)? NULL : &us->object,
433-
&zfuncname,
434-
&zretval,
435-
2, args);
427+
call_result = call_user_function(NULL, &us->object, &zfuncname, &zretval, 2, args);
436428

437429
if (call_result == SUCCESS && Z_TYPE(zretval) != IS_UNDEF && zval_is_true(&zretval)) {
438430
/* the stream is now open! */
@@ -571,11 +563,7 @@ static ssize_t php_userstreamop_write(php_stream *stream, const char *buf, size_
571563

572564
ZVAL_STRINGL(&args[0], (char*)buf, count);
573565

574-
call_result = call_user_function(NULL,
575-
Z_ISUNDEF(us->object)? NULL : &us->object,
576-
&func_name,
577-
&retval,
578-
1, args);
566+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 1, args);
579567
zval_ptr_dtor(&args[0]);
580568
zval_ptr_dtor(&func_name);
581569

@@ -624,11 +612,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
624612

625613
ZVAL_LONG(&args[0], count);
626614

627-
call_result = call_user_function(NULL,
628-
Z_ISUNDEF(us->object)? NULL : &us->object,
629-
&func_name,
630-
&retval,
631-
1, args);
615+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 1, args);
632616

633617
zval_ptr_dtor(&args[0]);
634618
zval_ptr_dtor(&func_name);
@@ -667,11 +651,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
667651
/* since the user stream has no way of setting the eof flag directly, we need to ask it if we hit eof */
668652

669653
ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1);
670-
call_result = call_user_function(NULL,
671-
Z_ISUNDEF(us->object)? NULL : &us->object,
672-
&func_name,
673-
&retval,
674-
0, NULL);
654+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 0, NULL);
675655
zval_ptr_dtor(&func_name);
676656

677657
if (EG(exception)) {
@@ -704,11 +684,7 @@ static int php_userstreamop_close(php_stream *stream, int close_handle)
704684

705685
ZVAL_STRINGL(&func_name, USERSTREAM_CLOSE, sizeof(USERSTREAM_CLOSE)-1);
706686

707-
call_user_function(NULL,
708-
Z_ISUNDEF(us->object)? NULL : &us->object,
709-
&func_name,
710-
&retval,
711-
0, NULL);
687+
call_user_function(NULL, &us->object, &func_name, &retval, 0, NULL);
712688

713689
zval_ptr_dtor(&retval);
714690
zval_ptr_dtor(&func_name);
@@ -732,11 +708,7 @@ static int php_userstreamop_flush(php_stream *stream)
732708

733709
ZVAL_STRINGL(&func_name, USERSTREAM_FLUSH, sizeof(USERSTREAM_FLUSH)-1);
734710

735-
call_result = call_user_function(NULL,
736-
Z_ISUNDEF(us->object)? NULL : &us->object,
737-
&func_name,
738-
&retval,
739-
0, NULL);
711+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 0, NULL);
740712

741713
if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF && zval_is_true(&retval))
742714
call_result = 0;
@@ -764,11 +736,7 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
764736
ZVAL_LONG(&args[0], offset);
765737
ZVAL_LONG(&args[1], whence);
766738

767-
call_result = call_user_function(NULL,
768-
Z_ISUNDEF(us->object)? NULL : &us->object,
769-
&func_name,
770-
&retval,
771-
2, args);
739+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 2, args);
772740

773741
zval_ptr_dtor(&args[0]);
774742
zval_ptr_dtor(&args[1]);
@@ -798,11 +766,7 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
798766
/* now determine where we are */
799767
ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1);
800768

801-
call_result = call_user_function(NULL,
802-
Z_ISUNDEF(us->object)? NULL : &us->object,
803-
&func_name,
804-
&retval,
805-
0, NULL);
769+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 0, NULL);
806770

807771
if (call_result == SUCCESS && Z_TYPE(retval) == IS_LONG) {
808772
*newoffs = Z_LVAL(retval);
@@ -868,11 +832,7 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb)
868832

869833
ZVAL_STRINGL(&func_name, USERSTREAM_STAT, sizeof(USERSTREAM_STAT)-1);
870834

871-
call_result = call_user_function(NULL,
872-
Z_ISUNDEF(us->object)? NULL : &us->object,
873-
&func_name,
874-
&retval,
875-
0, NULL);
835+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 0, NULL);
876836

877837
if (call_result == SUCCESS && Z_TYPE(retval) == IS_ARRAY) {
878838
if (SUCCESS == statbuf_from_array(&retval, ssb))
@@ -902,7 +862,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
902862
switch (option) {
903863
case PHP_STREAM_OPTION_CHECK_LIVENESS:
904864
ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1);
905-
call_result = call_user_function(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL);
865+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 0, NULL);
906866
if (call_result == SUCCESS && (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE)) {
907867
ret = zval_is_true(&retval) ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK;
908868
} else {
@@ -936,11 +896,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
936896
/* TODO wouldblock */
937897
ZVAL_STRINGL(&func_name, USERSTREAM_LOCK, sizeof(USERSTREAM_LOCK)-1);
938898

939-
call_result = call_user_function(NULL,
940-
Z_ISUNDEF(us->object)? NULL : &us->object,
941-
&func_name,
942-
&retval,
943-
1, args);
899+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 1, args);
944900

945901
if (call_result == SUCCESS && (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE)) {
946902
ret = (Z_TYPE(retval) == IS_FALSE);
@@ -965,9 +921,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
965921

966922
switch (value) {
967923
case PHP_STREAM_TRUNCATE_SUPPORTED:
968-
if (zend_is_callable_ex(&func_name,
969-
Z_ISUNDEF(us->object)? NULL : Z_OBJ(us->object),
970-
0, NULL, NULL, NULL))
924+
if (zend_is_callable_ex(&func_name, Z_OBJ(us->object), 0, NULL, NULL, NULL))
971925
ret = PHP_STREAM_OPTION_RETURN_OK;
972926
else
973927
ret = PHP_STREAM_OPTION_RETURN_ERR;
@@ -977,11 +931,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
977931
ptrdiff_t new_size = *(ptrdiff_t*) ptrparam;
978932
if (new_size >= 0 && new_size <= (ptrdiff_t)LONG_MAX) {
979933
ZVAL_LONG(&args[0], (zend_long)new_size);
980-
call_result = call_user_function(NULL,
981-
Z_ISUNDEF(us->object)? NULL : &us->object,
982-
&func_name,
983-
&retval,
984-
1, args);
934+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 1, args);
985935
if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
986936
if (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE) {
987937
ret = (Z_TYPE(retval) == IS_TRUE) ? PHP_STREAM_OPTION_RETURN_OK :
@@ -1041,11 +991,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
1041991
break;
1042992
}
1043993

1044-
call_result = call_user_function(NULL,
1045-
Z_ISUNDEF(us->object)? NULL : &us->object,
1046-
&func_name,
1047-
&retval,
1048-
3, args);
994+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 3, args);
1049995

1050996
if (call_result == FAILURE) {
1051997
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_SET_OPTION " is not implemented!",
@@ -1388,11 +1334,7 @@ static ssize_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t co
13881334

13891335
ZVAL_STRINGL(&func_name, USERSTREAM_DIR_READ, sizeof(USERSTREAM_DIR_READ)-1);
13901336

1391-
call_result = call_user_function(NULL,
1392-
Z_ISUNDEF(us->object)? NULL : &us->object,
1393-
&func_name,
1394-
&retval,
1395-
0, NULL);
1337+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 0, NULL);
13961338

13971339
if (call_result == SUCCESS && Z_TYPE(retval) != IS_FALSE && Z_TYPE(retval) != IS_TRUE) {
13981340
convert_to_string(&retval);
@@ -1420,11 +1362,7 @@ static int php_userstreamop_closedir(php_stream *stream, int close_handle)
14201362

14211363
ZVAL_STRINGL(&func_name, USERSTREAM_DIR_CLOSE, sizeof(USERSTREAM_DIR_CLOSE)-1);
14221364

1423-
call_user_function(NULL,
1424-
Z_ISUNDEF(us->object)? NULL : &us->object,
1425-
&func_name,
1426-
&retval,
1427-
0, NULL);
1365+
call_user_function(NULL, &us->object, &func_name, &retval, 0, NULL);
14281366

14291367
zval_ptr_dtor(&retval);
14301368
zval_ptr_dtor(&func_name);
@@ -1444,11 +1382,7 @@ static int php_userstreamop_rewinddir(php_stream *stream, zend_off_t offset, int
14441382

14451383
ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1);
14461384

1447-
call_user_function(NULL,
1448-
Z_ISUNDEF(us->object)? NULL : &us->object,
1449-
&func_name,
1450-
&retval,
1451-
0, NULL);
1385+
call_user_function(NULL, &us->object, &func_name, &retval, 0, NULL);
14521386

14531387
zval_ptr_dtor(&retval);
14541388
zval_ptr_dtor(&func_name);
@@ -1478,11 +1412,7 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
14781412
break;
14791413
}
14801414

1481-
call_result = call_user_function(NULL,
1482-
Z_ISUNDEF(us->object)? NULL : &us->object,
1483-
&func_name,
1484-
&retval,
1485-
1, args);
1415+
call_result = call_user_function(NULL, &us->object, &func_name, &retval, 1, args);
14861416

14871417
do {
14881418
if (call_result == FAILURE) {

0 commit comments

Comments
 (0)