Skip to content

Commit fbe2070

Browse files
committed
Use fact that if checking that a stream can be cast the return pointer is NULL
1 parent c5c1446 commit fbe2070

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

main/streams/cast.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,6 @@ void php_stream_mode_sanitize_fdopen_fopencookie(php_stream *stream, char *resul
187187
}
188188
/* }}} */
189189

190-
static inline bool is_stream_user_stream(const php_stream *stream)
191-
{
192-
return stream->ops == &php_stream_userspace_ops;
193-
}
194-
195190
/* {{{ php_stream_cast */
196191
PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show_err)
197192
{
@@ -201,10 +196,6 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
201196
/* synchronize our buffer (if possible) */
202197
if (ret && castas != PHP_STREAM_AS_FD_FOR_SELECT) {
203198
php_stream_flush(stream);
204-
/* Do special handling for user streams as they may not implement the cast method */
205-
if (!show_err && is_stream_user_stream(stream)) {
206-
castas |= PHP_STREAM_FLAG_SUPPRESS_ERRORS;
207-
}
208199
if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
209200
zend_off_t dummy;
210201

@@ -223,11 +214,6 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
223214
goto exit_success;
224215
}
225216

226-
/* Do special handling for user streams as they may not implement the cast method */
227-
if (!show_err && is_stream_user_stream(stream)) {
228-
castas |= PHP_STREAM_FLAG_SUPPRESS_ERRORS;
229-
}
230-
231217
/* if the stream is a stdio stream let's give it a chance to respond
232218
* first, to avoid doubling up the layers of stdio with an fopencookie */
233219
if (php_stream_is(stream, PHP_STREAM_IS_STDIO) &&
@@ -282,7 +268,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
282268
} else if (flags & PHP_STREAM_CAST_TRY_HARD) {
283269
php_stream *newstream;
284270

285-
newstream = php_stream_fopen_tmpfile_ex(/* emit errors */ false);
271+
newstream = php_stream_fopen_tmpfile();
286272
if (newstream) {
287273
int retcopy = php_stream_copy_to_stream_ex(stream, newstream, PHP_STREAM_COPY_ALL, NULL);
288274

@@ -314,10 +300,6 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
314300
}
315301
return FAILURE;
316302
} else if (stream->ops->cast) {
317-
/* Do special handling for user streams as they may not implement the cast method */
318-
if (!show_err && is_stream_user_stream(stream)) {
319-
castas |= PHP_STREAM_FLAG_SUPPRESS_ERRORS;
320-
}
321303
if (stream->ops->cast(stream, castas, ret) == SUCCESS) {
322304
goto exit_success;
323305
}

main/streams/userspace.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,8 +1373,6 @@ static int php_userstreamop_rewinddir(php_stream *stream, zend_off_t offset, int
13731373

13741374
}
13751375

1376-
/* The user stream overloads the castas parameter by accepting PHP_STREAM_FLAG_SUPPRESS_ERRORS as a bitmask
1377-
* If present the call is silent, otherwise it will report errors */
13781376
static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
13791377
{
13801378
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
@@ -1384,8 +1382,8 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
13841382
php_stream * intstream = NULL;
13851383
int call_result;
13861384
int ret = FAILURE;
1387-
bool report_errors = !(castas & PHP_STREAM_FLAG_SUPPRESS_ERRORS);
1388-
castas &= ~PHP_STREAM_FLAG_SUPPRESS_ERRORS;
1385+
/* If we a checking if the stream can cast, no return pointer is provided, so do not emit errors */
1386+
bool report_errors = retptr;
13891387

13901388
ZVAL_STRINGL(&func_name, USERSTREAM_CAST, sizeof(USERSTREAM_CAST)-1);
13911389

0 commit comments

Comments
 (0)