-
Notifications
You must be signed in to change notification settings - Fork 7.9k
streams: Fix php_stream_from_{res|zval}_no_verify() APIs actually throwing TypeErrors #18079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
4c7044e
to
f645513
Compare
f645513
to
e992ebb
Compare
@@ -771,11 +771,17 @@ static xmlParserInputPtr php_libxml_external_entity_loader(const char *URL, | |||
} else if (Z_TYPE(retval) == IS_RESOURCE) { | |||
php_stream *stream; | |||
php_stream_from_zval_no_verify(stream, &retval); | |||
if (stream == NULL) { | |||
if (UNEXPECTED(stream == NULL)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code fragment just looks like a completely different fix (for stable branches as well)?
@@ -282,8 +282,8 @@ END_EXTERN_C() | |||
return; \ | |||
} \ | |||
} while (0) | |||
#define php_stream_from_res_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource2((res), "stream", php_file_le_stream(), php_file_le_pstream()) | |||
#define php_stream_from_zval_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource2_ex((pzval), "stream", php_file_le_stream(), php_file_le_pstream()) | |||
#define php_stream_from_res_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource2((res), NULL, php_file_le_stream(), php_file_le_pstream()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the motivation, the no_verify just means that the macro won't return, so it's just an unclear name.
Also this behaviour change does not seem worth it for extensions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The motivation is to have an API that extension can rely on to get a php_stream
(mainly from a zval) to ease the migration from resource to objects. And we have a bunch of case which use zend_fetch_resource2
with NULL
so they can handle the errors themselves.
I guess I'll just add a new macro/inline function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not doing those incremental changes. Once there is such migration, users will need to handle it anyway.
If we pass a string as the
resource_type_name
parameter instead ofNULL
then a TypeError is emitted.