Skip to content

Commit 8d9ed39

Browse files
authored
stream: registering cannot fail, thus voidify function (#22811)
Propagate changes up which means we can also voidify php_init_stream_wrappers() removing an if() check during startup.
1 parent 6210d5c commit 8d9ed39

5 files changed

Lines changed: 14 additions & 22 deletions

File tree

main/main.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,10 +2311,7 @@ zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additi
23112311
/* initialize stream wrappers registry
23122312
* (this uses configuration parameters from php.ini)
23132313
*/
2314-
if (php_init_stream_wrappers(module_number) == FAILURE) {
2315-
fprintf(stderr, "PHP: Unable to initialize stream url wrappers.\n");
2316-
return FAILURE;
2317-
}
2314+
php_init_stream_wrappers(module_number);
23182315

23192316
zuv.html_errors = 1;
23202317
php_startup_auto_globals();

main/php_streams.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ END_EXTERN_C()
629629
/* this flag is only used by include/require functions */
630630
#define STREAM_OPEN_FOR_ZEND_STREAM 0x00010000
631631

632-
zend_result php_init_stream_wrappers(int module_number);
632+
void php_init_stream_wrappers(int module_number);
633633
void php_shutdown_stream_wrappers(int module_number);
634634
void php_shutdown_stream_hashes(void);
635635
PHP_RSHUTDOWN_FUNCTION(streams);

main/streams/php_stream_transport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ typedef php_stream *(php_stream_transport_factory_func)(const char *proto, size_
2929
typedef php_stream_transport_factory_func *php_stream_transport_factory;
3030

3131
BEGIN_EXTERN_C()
32-
PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory);
33-
PHPAPI int php_stream_xport_unregister(const char *protocol);
32+
PHPAPI void php_stream_xport_register(const char *protocol, php_stream_transport_factory factory);
33+
PHPAPI zend_result php_stream_xport_unregister(const char *protocol);
3434

3535
#define STREAM_XPORT_CLIENT 0
3636
#define STREAM_XPORT_SERVER 1

main/streams/streams.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,7 @@ void php_shutdown_stream_hashes(void)
17391739
php_stream_error_state_cleanup();
17401740
}
17411741

1742-
zend_result php_init_stream_wrappers(int module_number)
1742+
void php_init_stream_wrappers(int module_number)
17431743
{
17441744
le_stream = zend_register_list_destructors_ex(stream_resource_regular_dtor, NULL, "stream", module_number);
17451745
le_pstream = zend_register_list_destructors_ex(NULL, stream_resource_persistent_dtor, "persistent stream", module_number);
@@ -1751,16 +1751,12 @@ zend_result php_init_stream_wrappers(int module_number)
17511751
zend_hash_init(php_get_stream_filters_hash_global(), 8, NULL, NULL, 1);
17521752
zend_hash_init(php_stream_xport_get_hash(), 8, NULL, NULL, 1);
17531753

1754-
return (php_stream_xport_register("tcp", php_stream_generic_socket_factory) == SUCCESS
1755-
&&
1756-
php_stream_xport_register("udp", php_stream_generic_socket_factory) == SUCCESS
1754+
php_stream_xport_register("tcp", php_stream_generic_socket_factory);
1755+
php_stream_xport_register("udp", php_stream_generic_socket_factory);
17571756
#if defined(AF_UNIX) && !(defined(PHP_WIN32) || defined(__riscos__))
1758-
&&
1759-
php_stream_xport_register("unix", php_stream_generic_socket_factory) == SUCCESS
1760-
&&
1761-
php_stream_xport_register("udg", php_stream_generic_socket_factory) == SUCCESS
1757+
php_stream_xport_register("unix", php_stream_generic_socket_factory);
1758+
php_stream_xport_register("udg", php_stream_generic_socket_factory);
17621759
#endif
1763-
) ? SUCCESS : FAILURE;
17641760
}
17651761

17661762
void php_shutdown_stream_wrappers(int module_number)

main/streams/transports.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "php.h"
1616
#include "php_streams_int.h"
17-
#include "ext/standard/file.h"
17+
#include "ext/standard/file.h" /* For FG(default_socket_timeout) */
1818

1919
static HashTable xport_hash;
2020

@@ -23,16 +23,15 @@ PHPAPI HashTable *php_stream_xport_get_hash(void)
2323
return &xport_hash;
2424
}
2525

26-
PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory)
26+
PHPAPI void php_stream_xport_register(const char *protocol, php_stream_transport_factory factory)
2727
{
28-
zend_string *str = zend_string_init_interned(protocol, strlen(protocol), 1);
28+
zend_string *str = zend_string_init_interned(protocol, strlen(protocol), true);
2929

3030
zend_hash_update_ptr(&xport_hash, str, factory);
31-
zend_string_release_ex(str, 1);
32-
return SUCCESS;
31+
zend_string_release_ex(str, true);
3332
}
3433

35-
PHPAPI int php_stream_xport_unregister(const char *protocol)
34+
PHPAPI zend_result php_stream_xport_unregister(const char *protocol)
3635
{
3736
return zend_hash_str_del(&xport_hash, protocol, strlen(protocol));
3837
}

0 commit comments

Comments
 (0)