Skip to content

Commit 3240a74

Browse files
committed
Use more specific return type for stream functions
Some void, some zend_result, some bool
1 parent 32f6c61 commit 3240a74

File tree

5 files changed

+34
-39
lines changed

5 files changed

+34
-39
lines changed

ext/standard/streamsfuncs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,8 +1033,8 @@ PHP_FUNCTION(stream_context_set_option)
10331033
zend_argument_value_error(4, "must be provided when argument #2 ($wrapper_or_options) is a string");
10341034
RETURN_THROWS();
10351035
}
1036-
1037-
RETURN_BOOL(php_stream_context_set_option(context, ZSTR_VAL(wrappername), optionname, zvalue) == SUCCESS);
1036+
php_stream_context_set_option(context, ZSTR_VAL(wrappername), optionname, zvalue);
1037+
RETURN_TRUE;
10381038
}
10391039
}
10401040
/* }}} */

main/php_streams.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,15 @@ PHPAPI ssize_t _php_stream_write(php_stream *stream, const char *buf, size_t cou
314314
#define php_stream_write_string(stream, str) _php_stream_write(stream, str, strlen(str))
315315
#define php_stream_write(stream, buf, count) _php_stream_write(stream, (buf), (count))
316316

317-
PHPAPI int _php_stream_fill_read_buffer(php_stream *stream, size_t size);
317+
PHPAPI zend_result _php_stream_fill_read_buffer(php_stream *stream, size_t size);
318318
#define php_stream_fill_read_buffer(stream, size) _php_stream_fill_read_buffer((stream), (size))
319319

320320
PHPAPI ssize_t _php_stream_printf(php_stream *stream, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
321321

322322
/* php_stream_printf macro & function require */
323323
#define php_stream_printf _php_stream_printf
324324

325-
PHPAPI int _php_stream_eof(php_stream *stream);
325+
PHPAPI bool _php_stream_eof(php_stream *stream);
326326
#define php_stream_eof(stream) _php_stream_eof((stream))
327327

328328
PHPAPI int _php_stream_getc(php_stream *stream);
@@ -343,8 +343,8 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
343343
#define php_stream_get_line(stream, buf, maxlen, retlen) _php_stream_get_line((stream), (buf), (maxlen), (retlen))
344344
PHPAPI zend_string *php_stream_get_record(php_stream *stream, size_t maxlen, const char *delim, size_t delim_len);
345345

346-
/* CAREFUL! this is equivalent to puts NOT fputs! */
347-
PHPAPI int _php_stream_puts(php_stream *stream, const char *buf);
346+
/* Returns true if buffer has been appended, false on error */
347+
PHPAPI bool _php_stream_puts(php_stream *stream, const char *buf);
348348
#define php_stream_puts(stream, buf) _php_stream_puts((stream), (buf))
349349

350350
PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb);
@@ -466,7 +466,7 @@ BEGIN_EXTERN_C()
466466
ZEND_ATTRIBUTE_DEPRECATED
467467
PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC);
468468
#define php_stream_copy_to_stream(src, dest, maxlen) _php_stream_copy_to_stream((src), (dest), (maxlen) STREAMS_CC)
469-
PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size_t maxlen, size_t *len STREAMS_DC);
469+
PHPAPI zend_result _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size_t maxlen, size_t *len STREAMS_DC);
470470
#define php_stream_copy_to_stream_ex(src, dest, maxlen, len) _php_stream_copy_to_stream_ex((src), (dest), (maxlen), (len) STREAMS_CC)
471471

472472

@@ -568,15 +568,15 @@ END_EXTERN_C()
568568
#define STREAM_OPEN_FOR_ZEND_STREAM 0x00010000
569569

570570
int php_init_stream_wrappers(int module_number);
571-
int php_shutdown_stream_wrappers(int module_number);
571+
void php_shutdown_stream_wrappers(int module_number);
572572
void php_shutdown_stream_hashes(void);
573573
PHP_RSHUTDOWN_FUNCTION(streams);
574574

575575
BEGIN_EXTERN_C()
576-
PHPAPI int php_register_url_stream_wrapper(const char *protocol, const php_stream_wrapper *wrapper);
577-
PHPAPI int php_unregister_url_stream_wrapper(const char *protocol);
578-
PHPAPI int php_register_url_stream_wrapper_volatile(zend_string *protocol, php_stream_wrapper *wrapper);
579-
PHPAPI int php_unregister_url_stream_wrapper_volatile(zend_string *protocol);
576+
PHPAPI zend_result php_register_url_stream_wrapper(const char *protocol, const php_stream_wrapper *wrapper);
577+
PHPAPI zend_result php_unregister_url_stream_wrapper(const char *protocol);
578+
PHPAPI zend_result php_register_url_stream_wrapper_volatile(zend_string *protocol, php_stream_wrapper *wrapper);
579+
PHPAPI zend_result php_unregister_url_stream_wrapper_volatile(zend_string *protocol);
580580
PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
581581
PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options);
582582
PHPAPI const char *php_stream_locate_eol(php_stream *stream, zend_string *buf);

main/streams/php_stream_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ PHPAPI void php_stream_context_free(php_stream_context *context);
5757
PHPAPI php_stream_context *php_stream_context_alloc(void);
5858
PHPAPI zval *php_stream_context_get_option(php_stream_context *context,
5959
const char *wrappername, const char *optionname);
60-
PHPAPI int php_stream_context_set_option(php_stream_context *context,
60+
PHPAPI void php_stream_context_set_option(php_stream_context *context,
6161
const char *wrappername, const char *optionname, zval *optionvalue);
6262

6363
PHPAPI php_stream_notifier *php_stream_notification_alloc(void);

main/streams/php_streams_int.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,3 @@
6060
* any other function that expects standard modes and you allow non-standard
6161
* ones. result should be a char[5]. */
6262
void php_stream_mode_sanitize_fdopen_fopencookie(php_stream *stream, char *result);
63-
64-
void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper);
65-
void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *path, const char *caption);

main/streams/streams.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static zend_llist *php_get_wrapper_errors_list(php_stream_wrapper *wrapper)
148148
}
149149

150150
/* {{{ wrapper error reporting */
151-
void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *path, const char *caption)
151+
static void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *path, const char *caption)
152152
{
153153
char *tmp;
154154
char *msg;
@@ -218,7 +218,7 @@ void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *
218218
}
219219
}
220220

221-
void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper)
221+
static void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper)
222222
{
223223
if (wrapper && FG(wrapper_errors)) {
224224
zend_hash_str_del(FG(wrapper_errors), (const char*)&wrapper, sizeof(wrapper));
@@ -535,7 +535,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
535535

536536
/* {{{ generic stream operations */
537537

538-
PHPAPI int _php_stream_fill_read_buffer(php_stream *stream, size_t size)
538+
PHPAPI zend_result _php_stream_fill_read_buffer(php_stream *stream, size_t size)
539539
{
540540
/* allocate/fill the buffer */
541541

@@ -776,7 +776,7 @@ PHPAPI zend_string *php_stream_read_to_str(php_stream *stream, size_t len)
776776
return str;
777777
}
778778

779-
PHPAPI int _php_stream_eof(php_stream *stream)
779+
PHPAPI bool _php_stream_eof(php_stream *stream)
780780
{
781781
/* if there is data in the buffer, it's not EOF */
782782
if (stream->writepos - stream->readpos > 0) {
@@ -813,7 +813,7 @@ PHPAPI int _php_stream_getc(php_stream *stream)
813813
return EOF;
814814
}
815815

816-
PHPAPI int _php_stream_puts(php_stream *stream, const char *buf)
816+
PHPAPI bool _php_stream_puts(php_stream *stream, const char *buf)
817817
{
818818
size_t len;
819819
char newline[2] = "\n"; /* is this OK for Win? */
@@ -1034,7 +1034,7 @@ PHPAPI zend_string *php_stream_get_record(php_stream *stream, size_t maxlen, con
10341034
const char *found_delim = NULL;
10351035
size_t buffered_len,
10361036
tent_ret_len; /* tentative returned length */
1037-
int has_delim = delim_len > 0;
1037+
bool has_delim = delim_len > 0;
10381038

10391039
if (maxlen == 0) {
10401040
return NULL;
@@ -1537,7 +1537,7 @@ PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int
15371537
}
15381538

15391539
/* Returns SUCCESS/FAILURE and sets *len to the number of bytes moved */
1540-
PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size_t maxlen, size_t *len STREAMS_DC)
1540+
PHPAPI zend_result _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size_t maxlen, size_t *len STREAMS_DC)
15411541
{
15421542
char buf[CHUNK_SIZE];
15431543
size_t haveread = 0;
@@ -1649,7 +1649,7 @@ ZEND_ATTRIBUTE_DEPRECATED
16491649
PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC)
16501650
{
16511651
size_t len;
1652-
int ret = _php_stream_copy_to_stream_ex(src, dest, maxlen, &len STREAMS_REL_CC);
1652+
zend_result ret = _php_stream_copy_to_stream_ex(src, dest, maxlen, &len STREAMS_REL_CC);
16531653
if (ret == SUCCESS && len == 0 && maxlen != 0) {
16541654
return 1;
16551655
}
@@ -1717,18 +1717,17 @@ int php_init_stream_wrappers(int module_number)
17171717
) ? SUCCESS : FAILURE;
17181718
}
17191719

1720-
int php_shutdown_stream_wrappers(int module_number)
1720+
void php_shutdown_stream_wrappers(int module_number)
17211721
{
17221722
zend_hash_destroy(&url_stream_wrappers_hash);
17231723
zend_hash_destroy(php_get_stream_filters_hash_global());
17241724
zend_hash_destroy(php_stream_xport_get_hash());
1725-
return SUCCESS;
17261725
}
17271726

17281727
/* Validate protocol scheme names during registration
17291728
* Must conform to /^[a-zA-Z0-9+.-]+$/
17301729
*/
1731-
static inline int php_stream_wrapper_scheme_validate(const char *protocol, unsigned int protocol_len)
1730+
static inline zend_result php_stream_wrapper_scheme_validate(const char *protocol, unsigned int protocol_len)
17321731
{
17331732
unsigned int i;
17341733

@@ -1745,10 +1744,10 @@ static inline int php_stream_wrapper_scheme_validate(const char *protocol, unsig
17451744
}
17461745

17471746
/* API for registering GLOBAL wrappers */
1748-
PHPAPI int php_register_url_stream_wrapper(const char *protocol, const php_stream_wrapper *wrapper)
1747+
PHPAPI zend_result php_register_url_stream_wrapper(const char *protocol, const php_stream_wrapper *wrapper)
17491748
{
1750-
unsigned int protocol_len = (unsigned int)strlen(protocol);
1751-
int ret;
1749+
size_t protocol_len = strlen(protocol);
1750+
zend_result ret;
17521751
zend_string *str;
17531752

17541753
if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) {
@@ -1761,7 +1760,7 @@ PHPAPI int php_register_url_stream_wrapper(const char *protocol, const php_strea
17611760
return ret;
17621761
}
17631762

1764-
PHPAPI int php_unregister_url_stream_wrapper(const char *protocol)
1763+
PHPAPI zend_result php_unregister_url_stream_wrapper(const char *protocol)
17651764
{
17661765
return zend_hash_str_del(&url_stream_wrappers_hash, protocol, strlen(protocol));
17671766
}
@@ -1774,7 +1773,7 @@ static void clone_wrapper_hash(void)
17741773
}
17751774

17761775
/* API for registering VOLATILE wrappers */
1777-
PHPAPI int php_register_url_stream_wrapper_volatile(zend_string *protocol, php_stream_wrapper *wrapper)
1776+
PHPAPI zend_result php_register_url_stream_wrapper_volatile(zend_string *protocol, php_stream_wrapper *wrapper)
17781777
{
17791778
if (php_stream_wrapper_scheme_validate(ZSTR_VAL(protocol), ZSTR_LEN(protocol)) == FAILURE) {
17801779
return FAILURE;
@@ -1787,7 +1786,7 @@ PHPAPI int php_register_url_stream_wrapper_volatile(zend_string *protocol, php_s
17871786
return zend_hash_add_ptr(FG(stream_wrappers), protocol, wrapper) ? SUCCESS : FAILURE;
17881787
}
17891788

1790-
PHPAPI int php_unregister_url_stream_wrapper_volatile(zend_string *protocol)
1789+
PHPAPI zend_result php_unregister_url_stream_wrapper_volatile(zend_string *protocol)
17911790
{
17921791
if (!FG(stream_wrappers)) {
17931792
clone_wrapper_hash();
@@ -2250,7 +2249,7 @@ PHPAPI zval *php_stream_context_get_option(php_stream_context *context,
22502249
return zend_hash_str_find(Z_ARRVAL_P(wrapperhash), optionname, strlen(optionname));
22512250
}
22522251

2253-
PHPAPI int php_stream_context_set_option(php_stream_context *context,
2252+
PHPAPI void php_stream_context_set_option(php_stream_context *context,
22542253
const char *wrappername, const char *optionname, zval *optionvalue)
22552254
{
22562255
zval *wrapperhash;
@@ -2266,7 +2265,6 @@ PHPAPI int php_stream_context_set_option(php_stream_context *context,
22662265
Z_TRY_ADDREF_P(optionvalue);
22672266
SEPARATE_ARRAY(wrapperhash);
22682267
zend_hash_str_update(Z_ARRVAL_P(wrapperhash), optionname, strlen(optionname), optionvalue);
2269-
return SUCCESS;
22702268
}
22712269
/* }}} */
22722270

@@ -2295,12 +2293,12 @@ PHPAPI int _php_stream_scandir(const char *dirname, zend_string **namelist[], in
22952293
unsigned int nfiles = 0;
22962294

22972295
if (!namelist) {
2298-
return FAILURE;
2296+
return -1;
22992297
}
23002298

23012299
stream = php_stream_opendir(dirname, REPORT_ERRORS, context);
23022300
if (!stream) {
2303-
return FAILURE;
2301+
return -1;
23042302
}
23052303

23062304
while (php_stream_readdir(stream, &sdp)) {
@@ -2312,7 +2310,7 @@ PHPAPI int _php_stream_scandir(const char *dirname, zend_string **namelist[], in
23122310
/* overflow */
23132311
php_stream_closedir(stream);
23142312
efree(vector);
2315-
return FAILURE;
2313+
return -1;
23162314
}
23172315
vector_size *= 2;
23182316
}
@@ -2326,7 +2324,7 @@ PHPAPI int _php_stream_scandir(const char *dirname, zend_string **namelist[], in
23262324
/* overflow */
23272325
php_stream_closedir(stream);
23282326
efree(vector);
2329-
return FAILURE;
2327+
return -1;
23302328
}
23312329
}
23322330
php_stream_closedir(stream);

0 commit comments

Comments
 (0)