]> granicus.if.org Git - php/commitdiff
Use interned strings for persistent stream wrappers and filters
authorDmitry Stogov <dmitry@zend.com>
Tue, 31 Oct 2017 15:51:35 +0000 (18:51 +0300)
committerDmitry Stogov <dmitry@zend.com>
Tue, 31 Oct 2017 15:51:35 +0000 (18:51 +0300)
ext/opcache/ZendAccelerator.c
ext/standard/user_filters.c
main/php_streams.h
main/streams/filter.c
main/streams/php_stream_filter_api.h
main/streams/streams.c
main/streams/userspace.c

index 260ecc9d2d3a1c0cf6b8b070344d306d72be83c6..178f96f67ed7f850c6b09a03d4a1e98b86e153f9 100644 (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)
index 4d9f4f5fbb0be5e835f2ef29d450cc4c29064af8..1f39464a97bb51515db8c6bd1a59a1f41e143179 100644 (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);
index d10d087fb4956550f0d4656117e97043b23137bc..c268295933896e38cba56b9969c315b786414cd2 100644 (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);
index 6014a49661d068e3d55387b1efa2bd6ae557941b..5d8fccfca758df70ac90bb0eb928fe07dffced3f 100644 (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 */
index c109ca99931bfe858a706785531c961618c05219..ad9c541f1de4a7b26a91df628480f5c9d3612b0a 100644 (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()
 
index 15cecff377f34455ae0f8f755515d039728bb2f5..7f130fcb15af4d8b85e3e68349a2b4e345ac6807 100644 (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);
 }
 /* }}} */
 
index 2b838c6ddc09cd8a60cdd7d352d4692df4f2c44f..81ce3d0e19b53ea6af3c786674825d84dff166de 100644 (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;
        }