1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Use interned strings for persistent stream wrappers and filters

This commit is contained in:
Dmitry Stogov
2017-10-31 18:51:35 +03:00
parent 5b044aacbe
commit bbfd0df9d3
7 changed files with 34 additions and 21 deletions

View File

@@ -549,6 +549,7 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int
{
uint32_t j;
Bucket *p, *q;
HashTable *ht;
/* empty string */
zend_empty_string = new_interned_string(zend_empty_string);
@@ -680,6 +681,20 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int
entry->orig_value = new_interned_string(entry->orig_value);
}
} ZEND_HASH_FOREACH_END();
ht = php_get_stream_filters_hash_global();
ZEND_HASH_FOREACH_BUCKET(ht, p) {
if (p->key) {
p->key = new_interned_string(p->key);
}
} ZEND_HASH_FOREACH_END();
ht = php_stream_get_url_stream_wrappers_hash_global();
ZEND_HASH_FOREACH_BUCKET(ht, p) {
if (p->key) {
p->key = new_interned_string(p->key);
}
} ZEND_HASH_FOREACH_END();
}
static zend_string *accel_replace_string_by_shm_permanent(zend_string *str)

View File

@@ -587,7 +587,7 @@ PHP_FUNCTION(stream_filter_register)
fdat->classname = zend_string_copy(classname);
if (zend_hash_add_ptr(BG(user_filter_map), filtername, fdat) != NULL &&
php_stream_filter_register_factory_volatile(ZSTR_VAL(filtername), &user_filter_factory) == SUCCESS) {
php_stream_filter_register_factory_volatile(filtername, &user_filter_factory) == SUCCESS) {
RETVAL_TRUE;
} else {
zend_string_release(classname);

View File

@@ -563,8 +563,8 @@ PHP_RSHUTDOWN_FUNCTION(streams);
BEGIN_EXTERN_C()
PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper);
PHPAPI int php_unregister_url_stream_wrapper(const char *protocol);
PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper);
PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol);
PHPAPI int php_register_url_stream_wrapper_volatile(zend_string *protocol, php_stream_wrapper *wrapper);
PHPAPI int php_unregister_url_stream_wrapper_volatile(zend_string *protocol);
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);
PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options);
PHPAPI const char *php_stream_locate_eol(php_stream *stream, zend_string *buf);

View File

@@ -46,7 +46,8 @@ PHPAPI HashTable *_php_get_stream_filters_hash(void)
/* API for registering GLOBAL filters */
PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory)
{
return zend_hash_str_add_ptr(&stream_filters_hash, filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE;
zend_string *str = zend_string_init_interned(filterpattern, strlen(filterpattern), 1);
return zend_hash_add_ptr(&stream_filters_hash, str, factory) ? SUCCESS : FAILURE;
}
PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern)
@@ -55,15 +56,15 @@ PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern)
}
/* API for registering VOLATILE wrappers */
PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory)
PHPAPI int php_stream_filter_register_factory_volatile(zend_string *filterpattern, php_stream_filter_factory *factory)
{
if (!FG(stream_filters)) {
ALLOC_HASHTABLE(FG(stream_filters));
zend_hash_init(FG(stream_filters), zend_hash_num_elements(&stream_filters_hash), NULL, NULL, 0);
zend_hash_init(FG(stream_filters), zend_hash_num_elements(&stream_filters_hash) + 1, NULL, NULL, 0);
zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL);
}
return zend_hash_str_add_ptr(FG(stream_filters), (char*)filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE;
return zend_hash_add_ptr(FG(stream_filters), filterpattern, factory) ? SUCCESS : FAILURE;
}
/* Buckets */

View File

@@ -148,7 +148,7 @@ typedef struct _php_stream_filter_factory {
BEGIN_EXTERN_C()
PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory);
PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern);
PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory);
PHPAPI int php_stream_filter_register_factory_volatile(zend_string *filterpattern, php_stream_filter_factory *factory);
PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, uint8_t persistent);
END_EXTERN_C()

View File

@@ -1691,11 +1691,9 @@ static void clone_wrapper_hash(void)
}
/* API for registering VOLATILE wrappers */
PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper)
PHPAPI int php_register_url_stream_wrapper_volatile(zend_string *protocol, php_stream_wrapper *wrapper)
{
unsigned int protocol_len = (unsigned int)strlen(protocol);
if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) {
if (php_stream_wrapper_scheme_validate(ZSTR_VAL(protocol), ZSTR_LEN(protocol)) == FAILURE) {
return FAILURE;
}
@@ -1703,16 +1701,16 @@ PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_st
clone_wrapper_hash();
}
return zend_hash_str_add_ptr(FG(stream_wrappers), protocol, protocol_len, wrapper) ? SUCCESS : FAILURE;
return zend_hash_add_ptr(FG(stream_wrappers), protocol, wrapper) ? SUCCESS : FAILURE;
}
PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol)
PHPAPI int php_unregister_url_stream_wrapper_volatile(zend_string *protocol)
{
if (!FG(stream_wrappers)) {
clone_wrapper_hash();
}
return zend_hash_str_del(FG(stream_wrappers), protocol, strlen(protocol));
return zend_hash_del(FG(stream_wrappers), protocol);
}
/* }}} */

View File

@@ -514,7 +514,7 @@ PHP_FUNCTION(stream_wrapper_register)
rsrc = zend_register_resource(uwrap, le_protocols);
if ((uwrap->ce = zend_lookup_class(classname)) != NULL) {
if (php_register_url_stream_wrapper_volatile(ZSTR_VAL(protocol), &uwrap->wrapper) == SUCCESS) {
if (php_register_url_stream_wrapper_volatile(protocol, &uwrap->wrapper) == SUCCESS) {
RETURN_TRUE;
} else {
/* We failed. But why? */
@@ -538,10 +538,9 @@ PHP_FUNCTION(stream_wrapper_register)
Unregister a wrapper for the life of the current request. */
PHP_FUNCTION(stream_wrapper_unregister)
{
char *protocol;
size_t protocol_len;
zend_string *protocol;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &protocol, &protocol_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &protocol) == FAILURE) {
RETURN_FALSE;
}
@@ -579,9 +578,9 @@ PHP_FUNCTION(stream_wrapper_restore)
}
/* A failure here could be okay given that the protocol might have been merely unregistered */
php_unregister_url_stream_wrapper_volatile(ZSTR_VAL(protocol));
php_unregister_url_stream_wrapper_volatile(protocol);
if (php_register_url_stream_wrapper_volatile(ZSTR_VAL(protocol), wrapper) == FAILURE) {
if (php_register_url_stream_wrapper_volatile(protocol, wrapper) == FAILURE) {
php_error_docref(NULL, E_WARNING, "Unable to restore original %s:// wrapper", ZSTR_VAL(protocol));
RETURN_FALSE;
}