Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions main/php_streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,14 @@ static zend_always_inline bool php_stream_zend_parse_arg_into_stream(
PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclosed);
PHPAPI int php_stream_free_enclosed(php_stream *stream_enclosed, int close_options);

PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream);
#define PHP_STREAM_PERSISTENT_SUCCESS 0 /* id exists */
#define PHP_STREAM_PERSISTENT_FAILURE 1 /* id exists but is not a stream! */
#define PHP_STREAM_PERSISTENT_NOT_EXIST 2 /* id does not exist */

C23_ENUM(php_stream_persistent_status, uint8_t) {
PHP_STREAM_PERSISTENT_SUCCESS = 0, /* id exists */
PHP_STREAM_PERSISTENT_FAILURE = 1, /* id exists but is not a stream! */
PHP_STREAM_PERSISTENT_NOT_EXIST = 2, /* id does not exist */
};

PHPAPI php_stream_persistent_status php_stream_from_persistent_id(const char *persistent_id, php_stream **stream);

#define PHP_STREAM_FREE_CALL_DTOR 1 /* call ops->close */
#define PHP_STREAM_FREE_RELEASE_STREAM 2 /* pefree(stream) */
Expand Down
3 changes: 3 additions & 0 deletions main/streams/plain_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,9 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen
case PHP_STREAM_PERSISTENT_FAILURE:
efree(persistent_id);
return ret;
case PHP_STREAM_PERSISTENT_NOT_EXIST:
/* Fallthrough to open new stream */
break;
}
}
#ifdef PHP_WIN32
Expand Down
22 changes: 11 additions & 11 deletions main/streams/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclos
return orig;
}

PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream)
PHPAPI php_stream_persistent_status php_stream_from_persistent_id(const char *persistent_id, php_stream **stream)
{
zend_resource *le;

Expand Down Expand Up @@ -250,8 +250,8 @@ static int php_stream_flush_ex(php_stream *stream, bool closing);
PHPAPI int php_stream_free(php_stream *stream, int close_options) /* {{{ */
{
int ret = 1;
int preserve_handle = close_options & PHP_STREAM_FREE_PRESERVE_HANDLE ? 1 : 0;
int release_cast = 1;
bool preserve_handle = (close_options & PHP_STREAM_FREE_PRESERVE_HANDLE) ? true : false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: line 275, preserve_handle still sets to 1

bool release_cast = true;
php_stream_context *context;

/* During shutdown resources may be released before other resources still holding them.
Expand All @@ -270,7 +270,7 @@ PHPAPI int php_stream_free(php_stream *stream, int close_options) /* {{{ */

if ((stream->flags & PHP_STREAM_FLAG_NO_CLOSE) ||
((stream->flags & PHP_STREAM_FLAG_NO_RSCR_DTOR_CLOSE) && (close_options & PHP_STREAM_FREE_RSRC_DTOR))) {
preserve_handle = 1;
preserve_handle = true;
}

#if STREAM_DEBUG
Expand Down Expand Up @@ -322,7 +322,7 @@ PHPAPI int php_stream_free(php_stream *stream, int close_options) /* {{{ */
return 0;
}
/* otherwise, make sure that we don't close the FILE* from a cast */
release_cast = 0;
release_cast = false;
}

#if STREAM_DEBUG
Expand Down Expand Up @@ -372,7 +372,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
php_io_poll_stream_notify_close(stream);
}

ret = stream->ops->close(stream, preserve_handle ? 0 : 1);
ret = stream->ops->close(stream, !preserve_handle);
if (!ret) {
ret = flush_result;
}
Expand Down Expand Up @@ -866,11 +866,11 @@ PHPAPI char *php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
size_t avail = 0;
size_t current_buf_size = 0;
size_t total_copied = 0;
int grow_mode = 0;
bool grow_mode = false;
char *bufstart = buf;

if (buf == NULL) {
grow_mode = 1;
grow_mode = true;
} else if (maxlen == 0) {
return NULL;
}
Expand All @@ -895,14 +895,14 @@ PHPAPI char *php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
size_t cpysz = 0;
char *readptr;
const char *eol;
int done = 0;
bool done = false;

readptr = (char*)stream->readbuf + stream->readpos;
eol = php_stream_locate_eol(stream, NULL);

if (eol) {
cpysz = eol - readptr + 1;
done = 1;
done = true;
} else {
cpysz = avail;
}
Expand All @@ -924,7 +924,7 @@ PHPAPI char *php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
} else {
if (cpysz >= maxlen - 1) {
cpysz = maxlen - 1;
done = 1;
done = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion main/streams/transports.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
/* fall through */

case PHP_STREAM_PERSISTENT_FAILURE:
default:
case PHP_STREAM_PERSISTENT_NOT_EXIST:
/* failed; get a new one */
;
}
Expand Down
Loading