X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_raphf.c;h=f867af6d7a13137f17fad2d40d69a542ceb94e10;hb=7a7b4dc3fbcc3d55d536a871b1232ae5750bba49;hp=dcb69040ae0c358c4afccd07b58be9dbe2067859;hpb=1a9de00f24739a487991f6a2e660655ec42779ac;p=m6w6%2Fext-raphf diff --git a/php_raphf.c b/php_raphf.c index dcb6904..f867af6 100644 --- a/php_raphf.c +++ b/php_raphf.c @@ -34,7 +34,7 @@ ZEND_END_MODULE_GLOBALS(raphf) #ifdef ZTS # define PHP_RAPHF_G ((zend_raphf_globals *) \ - (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(raphf_globals_id)]) + (*((void ***) tsrm_get_ls_cache()))[TSRM_UNSHUFFLE_RSRC_ID(raphf_globals_id)]) #else # define PHP_RAPHF_G (&raphf_globals) #endif @@ -92,32 +92,42 @@ void php_resource_factory_free(php_resource_factory_t **f) } } -void *php_resource_factory_handle_ctor(php_resource_factory_t *f, - void *init_arg TSRMLS_DC) +void *php_resource_factory_handle_ctor(php_resource_factory_t *f, void *init_arg) { if (f->fops.ctor) { - return f->fops.ctor(f->data, init_arg TSRMLS_CC); + return f->fops.ctor(f->data, init_arg); } return NULL; } -void *php_resource_factory_handle_copy(php_resource_factory_t *f, - void *handle TSRMLS_DC) +void *php_resource_factory_handle_copy(php_resource_factory_t *f, void *handle) { if (f->fops.copy) { - return f->fops.copy(f->data, handle TSRMLS_CC); + return f->fops.copy(f->data, handle); } return NULL; } -void php_resource_factory_handle_dtor(php_resource_factory_t *f, - void *handle TSRMLS_DC) +void php_resource_factory_handle_dtor(php_resource_factory_t *f, void *handle) { if (f->fops.dtor) { - f->fops.dtor(f->data, handle TSRMLS_CC); + f->fops.dtor(f->data, handle); } } +php_resource_factory_t *php_persistent_handle_resource_factory_init( + php_resource_factory_t *a, php_persistent_handle_factory_t *pf) +{ + return php_resource_factory_init(a, + php_persistent_handle_get_resource_factory_ops(), pf, + (void(*)(void*)) php_persistent_handle_abandon); +} + +zend_bool php_resource_factory_is_persistent(php_resource_factory_t *a) +{ + return a->dtor == (void(*)(void *)) php_persistent_handle_abandon; +} + static inline php_persistent_handle_list_t *php_persistent_handle_list_init( php_persistent_handle_list_t *list) { @@ -130,8 +140,8 @@ static inline php_persistent_handle_list_t *php_persistent_handle_list_init( return list; } -static int php_persistent_handle_apply_stat(zval *p TSRMLS_DC, int argc, - va_list argv, zend_hash_key *key) +static int php_persistent_handle_apply_stat(zval *p, int argc, va_list argv, + zend_hash_key *key) { php_persistent_handle_list_t *list = Z_PTR_P(p); zval zsubentry, *zentry = va_arg(argv, zval *); @@ -148,8 +158,8 @@ static int php_persistent_handle_apply_stat(zval *p TSRMLS_DC, int argc, return ZEND_HASH_APPLY_KEEP; } -static int php_persistent_handle_apply_statall(zval *p TSRMLS_DC, int argc, - va_list argv, zend_hash_key *key) +static int php_persistent_handle_apply_statall(zval *p, int argc, va_list argv, + zend_hash_key *key) { php_persistent_handle_provider_t *provider = Z_PTR_P(p); HashTable *ht = va_arg(argv, HashTable *); @@ -157,7 +167,7 @@ static int php_persistent_handle_apply_statall(zval *p TSRMLS_DC, int argc, array_init(&zentry); - zend_hash_apply_with_arguments(&provider->list.free TSRMLS_CC, + zend_hash_apply_with_arguments(&provider->list.free, php_persistent_handle_apply_stat, 1, &zentry); if (key->key) { @@ -169,7 +179,7 @@ static int php_persistent_handle_apply_statall(zval *p TSRMLS_DC, int argc, return ZEND_HASH_APPLY_KEEP; } -static int php_persistent_handle_apply_cleanup_ex(zval *p, void *arg TSRMLS_DC) +static int php_persistent_handle_apply_cleanup_ex(zval *p, void *arg) { php_resource_factory_t *rf = arg; void *handle = Z_PTR_P(p); @@ -177,17 +187,17 @@ static int php_persistent_handle_apply_cleanup_ex(zval *p, void *arg TSRMLS_DC) #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "DESTROY: %p\n", handle); #endif - php_resource_factory_handle_dtor(rf, handle TSRMLS_CC); + php_resource_factory_handle_dtor(rf, handle); return ZEND_HASH_APPLY_REMOVE; } -static int php_persistent_handle_apply_cleanup(zval *p, void *arg TSRMLS_DC) +static int php_persistent_handle_apply_cleanup(zval *p, void *arg) { php_resource_factory_t *rf = arg; php_persistent_handle_list_t *list = Z_PTR_P(p); zend_hash_apply_with_argument(&list->free, - php_persistent_handle_apply_cleanup_ex, rf TSRMLS_CC); + php_persistent_handle_apply_cleanup_ex, rf); if (list->used) { return ZEND_HASH_APPLY_KEEP; } @@ -201,21 +211,21 @@ static int php_persistent_handle_apply_cleanup(zval *p, void *arg TSRMLS_DC) static inline void php_persistent_handle_list_dtor( php_persistent_handle_list_t *list, - php_persistent_handle_provider_t *provider TSRMLS_DC) + php_persistent_handle_provider_t *provider) { #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "LSTDTOR: %p\n", list); #endif zend_hash_apply_with_argument(&list->free, - php_persistent_handle_apply_cleanup_ex, &provider->rf TSRMLS_CC); + php_persistent_handle_apply_cleanup_ex, &provider->rf); zend_hash_destroy(&list->free); } static inline void php_persistent_handle_list_free( php_persistent_handle_list_t **list, - php_persistent_handle_provider_t *provider TSRMLS_DC) + php_persistent_handle_provider_t *provider) { - php_persistent_handle_list_dtor(*list, provider TSRMLS_CC); + php_persistent_handle_list_dtor(*list, provider); #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "LSTFREE: %p\n", *list); #endif @@ -223,24 +233,22 @@ static inline void php_persistent_handle_list_free( *list = NULL; } -static int php_persistent_handle_list_apply_dtor(zval *p, - void *provider TSRMLS_DC) +static int php_persistent_handle_list_apply_dtor(zval *p, void *provider) { php_persistent_handle_list_t *list = Z_PTR_P(p); - php_persistent_handle_list_free(&list, provider TSRMLS_CC); + + php_persistent_handle_list_free(&list, provider ); ZVAL_PTR(p, NULL); return ZEND_HASH_APPLY_REMOVE; } static inline php_persistent_handle_list_t *php_persistent_handle_list_find( - php_persistent_handle_provider_t *provider, const char *ident_str, - size_t ident_len TSRMLS_DC) + php_persistent_handle_provider_t *provider, zend_string *ident) { php_persistent_handle_list_t *list; + zval *zlist = zend_symtable_find(&provider->list.free, ident); - list = zend_symtable_str_find_ptr(&provider->list.free, ident_str, ident_len); - - if (list) { + if (zlist && (list = Z_PTR_P(zlist))) { #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "LSTFIND: %p\n", list); #endif @@ -248,40 +256,42 @@ static inline php_persistent_handle_list_t *php_persistent_handle_list_find( } if ((list = php_persistent_handle_list_init(NULL))) { - zval p; + zval p, *rv; + zend_string *id; ZVAL_PTR(&p, list); - if (zend_symtable_str_update(&provider->list.free, ident_str, ident_len, - &p)) { + id = zend_string_init(ident->val, ident->len, 1); + rv = zend_symtable_update(&provider->list.free, id, &p); + zend_string_release(id); + + if (rv) { #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "LSTFIND: %p (new)\n", list); #endif return list; } - php_persistent_handle_list_free(&list, provider TSRMLS_CC); + php_persistent_handle_list_free(&list, provider); } return NULL; } -static int php_persistent_handle_apply_cleanup_all(zval *p TSRMLS_DC, int argc, +static int php_persistent_handle_apply_cleanup_all(zval *p, int argc, va_list argv, zend_hash_key *key) { php_persistent_handle_provider_t *provider = Z_PTR_P(p); - const char *ident_str = va_arg(argv, const char *); - size_t ident_len = va_arg(argv, size_t); + zend_string *ident = va_arg(argv, zend_string *); php_persistent_handle_list_t *list; - if (ident_str && ident_len) { - if ((list = php_persistent_handle_list_find(provider, ident_str, - ident_len TSRMLS_CC))) { + if (ident && ident->len) { + if ((list = php_persistent_handle_list_find(provider, ident))) { zend_hash_apply_with_argument(&list->free, php_persistent_handle_apply_cleanup_ex, - &provider->rf TSRMLS_CC); + &provider->rf); } } else { zend_hash_apply_with_argument(&provider->list.free, - php_persistent_handle_apply_cleanup, &provider->rf TSRMLS_CC); + php_persistent_handle_apply_cleanup, &provider->rf); } return ZEND_HASH_APPLY_KEEP; @@ -290,32 +300,34 @@ static int php_persistent_handle_apply_cleanup_all(zval *p TSRMLS_DC, int argc, static void php_persistent_handle_hash_dtor(zval *p) { php_persistent_handle_provider_t *provider = Z_PTR_P(p); - TSRMLS_FETCH(); zend_hash_apply_with_argument(&provider->list.free, - php_persistent_handle_list_apply_dtor, provider TSRMLS_CC); + php_persistent_handle_list_apply_dtor, provider); zend_hash_destroy(&provider->list.free); php_resource_factory_dtor(&provider->rf); pefree(provider, 1); } -ZEND_RESULT_CODE php_persistent_handle_provide(const char *name_str, - size_t name_len, php_resource_factory_ops_t *fops, void *data, - void (*dtor)(void *) TSRMLS_DC) +ZEND_RESULT_CODE php_persistent_handle_provide(zend_string *name, + php_resource_factory_ops_t *fops, void *data, void (*dtor)(void *)) { php_persistent_handle_provider_t *provider = pemalloc(sizeof(*provider), 1); if (php_persistent_handle_list_init(&provider->list)) { if (php_resource_factory_init(&provider->rf, fops, data, dtor)) { - zval p; + zval p, *rv; + zend_string *ns; #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "PROVIDE: %p %s\n", PHP_RAPHF_G, name_str); #endif ZVAL_PTR(&p, provider); - if (zend_symtable_str_update(&PHP_RAPHF_G->persistent_handle.hash, - name_str, name_len, &p)) { + ns = zend_string_init(name->val, name->len, 1); + rv = zend_symtable_update(&PHP_RAPHF_G->persistent_handle.hash, ns, &p); + zend_string_release(ns); + + if (rv) { return SUCCESS; } php_resource_factory_dtor(&provider->rf); @@ -327,41 +339,33 @@ ZEND_RESULT_CODE php_persistent_handle_provide(const char *name_str, php_persistent_handle_factory_t *php_persistent_handle_concede( - php_persistent_handle_factory_t *a, const char *name_str, - size_t name_len, const char *ident_str, size_t ident_len, + php_persistent_handle_factory_t *a, + zend_string *name, zend_string *ident, php_persistent_handle_wakeup_t wakeup, - php_persistent_handle_retire_t retire TSRMLS_DC) + php_persistent_handle_retire_t retire) { - php_persistent_handle_factory_t *free_a = NULL; - - if (!a) { - free_a = a = emalloc(sizeof(*a)); - } - memset(a, 0, sizeof(*a)); + zval *zprovider = zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash, name); - a->provider = zend_symtable_str_find_ptr(&PHP_RAPHF_G->persistent_handle.hash, - name_str, name_len); + if (zprovider) { + zend_bool free_a = 0; - if (a->provider) { - a->ident.str = estrndup(ident_str, ident_len); - a->ident.len = ident_len; + if ((free_a = !a)) { + a = emalloc(sizeof(*a)); + } + memset(a, 0, sizeof(*a)); + a->provider = Z_PTR_P(zprovider); + a->ident = zend_string_copy(ident); a->wakeup = wakeup; a->retire = retire; - - if (free_a) { - a->free_on_abandon = 1; - } + a->free_on_abandon = free_a; } else { - if (free_a) { - efree(free_a); - } a = NULL; } #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "CONCEDE: %p %p (%s) (%s)\n", PHP_RAPHF_G, - a ? a->provider : NULL, name_str, ident_str); + a ? a->provider : NULL, name->val, ident->val); #endif return a; @@ -375,39 +379,34 @@ void php_persistent_handle_abandon(php_persistent_handle_factory_t *a) fprintf(stderr, "ABANDON: %p\n", a->provider); #endif - if (a->ident.str) { - efree(a->ident.str); - } + zend_string_release(a->ident); memset(a, 0, sizeof(*a)); if (f) { efree(a); } } -void *php_persistent_handle_acquire(php_persistent_handle_factory_t *a, - void *init_arg TSRMLS_DC) +void *php_persistent_handle_acquire(php_persistent_handle_factory_t *a, void *init_arg) { int key; zval *p; - ulong index; + zend_ulong index; void *handle = NULL; php_persistent_handle_list_t *list; - list = php_persistent_handle_list_find(a->provider, a->ident.str, - a->ident.len TSRMLS_CC); + list = php_persistent_handle_list_find(a->provider, a->ident); if (list) { zend_hash_internal_pointer_end(&list->free); - key = zend_hash_get_current_key(&list->free, NULL, &index, 0); + key = zend_hash_get_current_key(&list->free, NULL, &index); p = zend_hash_get_current_data(&list->free); if (p && HASH_KEY_NON_EXISTENT != key) { handle = Z_PTR_P(p); if (a->wakeup) { - a->wakeup(a, &handle TSRMLS_CC); + a->wakeup(a, &handle); } zend_hash_index_del(&list->free, index); } else { - handle = php_resource_factory_handle_ctor(&a->provider->rf, - init_arg TSRMLS_CC); + handle = php_resource_factory_handle_ctor(&a->provider->rf, init_arg); } #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "CREATED: %p\n", handle); @@ -421,17 +420,14 @@ void *php_persistent_handle_acquire(php_persistent_handle_factory_t *a, return handle; } -void *php_persistent_handle_accrete(php_persistent_handle_factory_t *a, - void *handle TSRMLS_DC) +void *php_persistent_handle_accrete(php_persistent_handle_factory_t *a, void *handle) { void *new_handle = NULL; php_persistent_handle_list_t *list; - new_handle = php_resource_factory_handle_copy(&a->provider->rf, - handle TSRMLS_CC); + new_handle = php_resource_factory_handle_copy(&a->provider->rf, handle); if (handle) { - list = php_persistent_handle_list_find(a->provider, a->ident.str, - a->ident.len TSRMLS_CC); + list = php_persistent_handle_list_find(a->provider, a->ident); if (list) { ++list->used; } @@ -441,22 +437,20 @@ void *php_persistent_handle_accrete(php_persistent_handle_factory_t *a, return new_handle; } -void php_persistent_handle_release(php_persistent_handle_factory_t *a, - void *handle TSRMLS_DC) +void php_persistent_handle_release(php_persistent_handle_factory_t *a, void *handle) { php_persistent_handle_list_t *list; - list = php_persistent_handle_list_find(a->provider, a->ident.str, - a->ident.len TSRMLS_CC); + list = php_persistent_handle_list_find(a->provider, a->ident); if (list) { if (a->provider->list.used >= PHP_RAPHF_G->persistent_handle.limit) { #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "DESTROY: %p\n", handle); #endif - php_resource_factory_handle_dtor(&a->provider->rf, handle TSRMLS_CC); + php_resource_factory_handle_dtor(&a->provider->rf, handle); } else { if (a->retire) { - a->retire(a, &handle TSRMLS_CC); + a->retire(a, &handle); } zend_hash_next_index_insert_ptr(&list->free, handle); } @@ -466,40 +460,37 @@ void php_persistent_handle_release(php_persistent_handle_factory_t *a, } } -void php_persistent_handle_cleanup(const char *name_str, size_t name_len, - const char *ident_str, size_t ident_len TSRMLS_DC) +void php_persistent_handle_cleanup(zend_string *name, zend_string *ident) { php_persistent_handle_provider_t *provider; php_persistent_handle_list_t *list; - if (name_str && name_len) { - provider = zend_symtable_str_find_ptr(&PHP_RAPHF_G->persistent_handle.hash, - name_str, name_len); + if (name) { + zval *zprovider = zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash, + name); - if (provider) { - if (ident_str && ident_len) { - list = php_persistent_handle_list_find(provider, ident_str, - ident_len TSRMLS_CC); + if (zprovider && (provider = Z_PTR_P(zprovider))) { + if (ident) { + list = php_persistent_handle_list_find(provider, ident); if (list) { zend_hash_apply_with_argument(&list->free, php_persistent_handle_apply_cleanup_ex, - &provider->rf TSRMLS_CC); + &provider->rf); } } else { zend_hash_apply_with_argument(&provider->list.free, php_persistent_handle_apply_cleanup, - &provider->rf TSRMLS_CC); + &provider->rf); } } } else { zend_hash_apply_with_arguments( - &PHP_RAPHF_G->persistent_handle.hash TSRMLS_CC, - php_persistent_handle_apply_cleanup_all, 2, ident_str, - ident_len); + &PHP_RAPHF_G->persistent_handle.hash, + php_persistent_handle_apply_cleanup_all, 1, ident); } } -HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC) +HashTable *php_persistent_handle_statall(HashTable *ht) { if (zend_hash_num_elements(&PHP_RAPHF_G->persistent_handle.hash)) { if (!ht) { @@ -507,7 +498,7 @@ HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC) zend_hash_init(ht, 0, NULL, ZVAL_PTR_DTOR, 0); } zend_hash_apply_with_arguments( - &PHP_RAPHF_G->persistent_handle.hash TSRMLS_CC, + &PHP_RAPHF_G->persistent_handle.hash, php_persistent_handle_apply_statall, 1, ht); } else if (ht) { ht = NULL; @@ -533,7 +524,7 @@ static PHP_FUNCTION(raphf_stat_persistent_handles) { if (SUCCESS == zend_parse_parameters_none()) { object_init(return_value); - if (php_persistent_handle_statall(HASH_OF(return_value) TSRMLS_CC)) { + if (php_persistent_handle_statall(HASH_OF(return_value))) { return; } zval_dtor(return_value); @@ -547,13 +538,10 @@ ZEND_BEGIN_ARG_INFO_EX(ai_raphf_clean_persistent_handles, 0, 0, 0) ZEND_END_ARG_INFO(); static PHP_FUNCTION(raphf_clean_persistent_handles) { - char *name_str = NULL, *ident_str = NULL; - int name_len = 0, ident_len = 0; + zend_string *name = NULL, *ident = NULL; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!", - &name_str, &name_len, &ident_str, &ident_len)) { - php_persistent_handle_cleanup(name_str, name_len, ident_str, - ident_len TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|S!S!", &name, &ident)) { + php_persistent_handle_cleanup(name, ident); } } @@ -628,7 +616,7 @@ PHP_MSHUTDOWN_FUNCTION(raphf) return SUCCESS; } -static int php_persistent_handle_apply_info_ex(zval *p TSRMLS_DC, int argc, +static int php_persistent_handle_apply_info_ex(zval *p, int argc, va_list argv, zend_hash_key *key) { php_persistent_handle_list_t *list = Z_PTR_P(p); @@ -643,12 +631,12 @@ static int php_persistent_handle_apply_info_ex(zval *p TSRMLS_DC, int argc, return ZEND_HASH_APPLY_KEEP; } -static int php_persistent_handle_apply_info(zval *p TSRMLS_DC, int argc, +static int php_persistent_handle_apply_info(zval *p, int argc, va_list argv, zend_hash_key *key) { php_persistent_handle_provider_t *provider = Z_PTR_P(p); - zend_hash_apply_with_arguments(&provider->list.free TSRMLS_CC, + zend_hash_apply_with_arguments(&provider->list.free, php_persistent_handle_apply_info_ex, 1, key); return ZEND_HASH_APPLY_KEEP; @@ -672,7 +660,7 @@ PHP_MINFO_FUNCTION(raphf) ); php_info_print_table_header(4, "Provider", "Ident", "Used", "Free"); zend_hash_apply_with_arguments( - &PHP_RAPHF_G->persistent_handle.hash TSRMLS_CC, + &PHP_RAPHF_G->persistent_handle.hash, php_persistent_handle_apply_info, 0); php_info_print_table_end();