From: Michael Wallner Date: Wed, 30 Sep 2015 12:54:08 +0000 (+0200) Subject: Merge branch 'v1.1.x' X-Git-Tag: release-2.0.0RC1~6 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-raphf;a=commitdiff_plain;h=7b963303fb7d67bcdeefde14eb9c0f9346ff50a4;hp=32a1bb34907be47e7d062c6633419c6e7fa38a16 Merge branch 'v1.1.x' --- diff --git a/README.md b/README.md index 63b3f63..785297b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ext-raphf -[![Build Status](https://travis-ci.org/m6w6/ext-raphf.svg?branch=v1.1.x)](https://travis-ci.org/m6w6/ext-raphf) +[![Build Status](https://travis-ci.org/m6w6/ext-raphf.svg?branch=master)](https://travis-ci.org/m6w6/ext-raphf) The "Resource and Persistent Handle Factory" extension provides facilities to manage those in a convenient manner. diff --git a/package.xml b/package.xml index ac6920e..afee51f 100644 --- a/package.xml +++ b/package.xml @@ -21,8 +21,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> 2015-07-28 - 1.1.0 - 1.0.0 + 2.0.0-dev + 2.0.0 stable @@ -30,8 +30,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> BSD, revised @@ -53,9 +51,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - @@ -67,9 +62,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - 5.3.0 - 7.0.0 - 7.0.0 + 7.0.0 1.4.0 diff --git a/php_raphf.h b/php_raphf.h index b084581..6e785be 100644 --- a/php_raphf.h +++ b/php_raphf.h @@ -16,7 +16,7 @@ extern zend_module_entry raphf_module_entry; #define phpext_raphf_ptr &raphf_module_entry -#define PHP_RAPHF_VERSION "1.1.0" +#define PHP_RAPHF_VERSION "2.0.0dev" #ifdef PHP_WIN32 # define PHP_RAPHF_API __declspec(dllexport) diff --git a/php_raphf_test.c b/php_raphf_test.c new file mode 100644 index 0000000..3bf7c5d --- /dev/null +++ b/php_raphf_test.c @@ -0,0 +1,263 @@ +/* + +--------------------------------------------------------------------+ + | PECL :: raphf | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted provided that the conditions mentioned | + | in the accompanying LICENSE file are met. | + +--------------------------------------------------------------------+ + | Copyright (c) 2014, Michael Wallner | + +--------------------------------------------------------------------+ +*/ + +#include + +struct user_cb { + zend_fcall_info fci; + zend_fcall_info_cache fcc; +}; + +struct raphf_user { + struct user_cb ctor; + struct user_cb copy; + struct user_cb dtor; + struct { + struct user_cb dtor; + zval data; + } data; +}; + +static inline void user_cb_addref(struct user_cb *cb) +{ + Z_ADDREF(cb->fci.function_name); + if (cb->fci.object) { + Z_ADDREF_P((zval *) cb->fci.object); + } +} + +static inline void user_cb_delref(struct user_cb *cb) +{ + if (cb->fci.object) { + Z_DELREF_P((zval *) cb->fci.object); + } +} + +static void raphf_user_dtor(void *opaque) +{ + struct raphf_user *ru = opaque; + + zend_fcall_info_argn(&ru->data.dtor.fci, 1, &ru->data.data); + zend_fcall_info_call(&ru->data.dtor.fci, &ru->data.dtor.fcc, NULL, NULL); + zend_fcall_info_args_clear(&ru->data.dtor.fci, 1); + user_cb_delref(&ru->data.dtor); + zend_fcall_info_args_clear(&ru->ctor.fci, 1); + user_cb_delref(&ru->ctor); + zend_fcall_info_args_clear(&ru->copy.fci, 1); + user_cb_delref(&ru->copy); + zend_fcall_info_args_clear(&ru->dtor.fci, 1); + user_cb_delref(&ru->dtor); + memset(ru, 0, sizeof(*ru)); + efree(ru); +} + +static void *user_ctor(void *opaque, void *init_arg TSRMLS_DC) +{ + struct raphf_user *ru = opaque; + zval *zinit_arg = init_arg, *retval = ecalloc(1, sizeof(*retval)); + + zend_fcall_info_argn(&ru->ctor.fci, 2, &ru->data.data, zinit_arg); + zend_fcall_info_call(&ru->ctor.fci, &ru->ctor.fcc, retval, NULL); + zend_fcall_info_args_clear(&ru->ctor.fci, 0); + + return retval; +} + +static void *user_copy(void *opaque, void *handle TSRMLS_DC) +{ + struct raphf_user *ru = opaque; + zval *zhandle = handle, *retval = ecalloc(1, sizeof(*retval)); + + zend_fcall_info_argn(&ru->copy.fci, 2, &ru->data.data, zhandle); + zend_fcall_info_call(&ru->copy.fci, &ru->copy.fcc, retval, NULL); + zend_fcall_info_args_clear(&ru->copy.fci, 0); + + return retval; +} + +static void user_dtor(void *opaque, void *handle TSRMLS_DC) +{ + struct raphf_user *ru = opaque; + zval *zhandle = handle, retval; + + ZVAL_UNDEF(&retval); + zend_fcall_info_argn(&ru->dtor.fci, 2, &ru->data.data, zhandle); + zend_fcall_info_call(&ru->dtor.fci, &ru->dtor.fcc, &retval, NULL); + zend_fcall_info_args_clear(&ru->dtor.fci, 0); + if (!Z_ISUNDEF(retval)) { + zval_ptr_dtor(&retval); + } +} + +static php_resource_factory_ops_t user_ops = { + user_ctor, + user_copy, + user_dtor +}; + +static int raphf_user_le; + +static void raphf_user_res_dtor(zend_resource *res TSRMLS_DC) +{ + php_resource_factory_free((void *) &res->ptr); +} + +static PHP_FUNCTION(raphf_provide) +{ + struct raphf_user *ru; + char *name_str; + size_t name_len; + zval *zdata; + + ru = ecalloc(1, sizeof(*ru)); + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sfffzf", + &name_str, &name_len, + &ru->ctor.fci, &ru->ctor.fcc, + &ru->copy.fci, &ru->copy.fcc, + &ru->dtor.fci, &ru->dtor.fcc, + &zdata, + &ru->data.dtor.fci, &ru->data.dtor.fcc)) { + efree(ru); + return; + } + + user_cb_addref(&ru->ctor); + user_cb_addref(&ru->copy); + user_cb_addref(&ru->dtor); + user_cb_addref(&ru->data.dtor); + + ZVAL_COPY(&ru->data.data, zdata); + + if (SUCCESS != php_persistent_handle_provide(name_str, name_len, + &user_ops, ru, raphf_user_dtor)) { + RETURN_FALSE; + } + RETURN_TRUE; +} + +static PHP_FUNCTION(raphf_conceal) +{ + zend_string *name; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &name)) { + return; + } + + RETURN_BOOL(FAILURE != zend_hash_del(&PHP_RAPHF_G->persistent_handle.hash, name)); +} + +static PHP_FUNCTION(raphf_concede) +{ + char *name_str, *id_str; + size_t name_len, id_len; + php_persistent_handle_factory_t *pf; + php_resource_factory_t *rf; + php_resource_factory_ops_t *ops; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", + &name_str, &name_len, &id_str, &id_len)) { + return; + } + + ops = php_persistent_handle_get_resource_factory_ops(); + pf = php_persistent_handle_concede(NULL, name_str, name_len, id_str, id_len, + NULL, NULL TSRMLS_CC); + if (!pf) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "Could not locate persistent handle factory '%s'", name_str); + RETURN_FALSE; + } + rf = php_resource_factory_init(NULL, ops, pf, + (void(*)(void*)) php_persistent_handle_abandon); + if (!rf) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "Could not create resource factory " + "for persistent handle factory '%s'", name_str); + RETURN_FALSE; + } + + zend_register_resource(return_value, rf, raphf_user_le); +} + +static PHP_FUNCTION(raphf_dispute) +{ + zval *zrf; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zrf)) { + return; + } + + RETURN_BOOL(SUCCESS == zend_list_close(Z_RES_P(zrf))); +} + +static PHP_FUNCTION(raphf_handle_ctor) +{ + zval *zrf, *zrv, *zinit_arg; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz", + &zrf, &zinit_arg)) { + return; + } + + zrv = php_resource_factory_handle_ctor(Z_RES_VAL_P(zrf), zinit_arg); + RETVAL_ZVAL(zrv, 0, 0); + efree(zrv); +} + +static PHP_FUNCTION(raphf_handle_copy) +{ + zval *zrf, *zrv, *zhandle; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz", + &zrf, &zhandle)) { + return; + } + + zrv = php_resource_factory_handle_copy(Z_RES_VAL_P(zrf), zhandle); + RETVAL_ZVAL(zrv, 0, 0); + efree(zrv); +} + +static PHP_FUNCTION(raphf_handle_dtor) +{ + zval *zrf, *zhandle; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz", + &zrf, &zhandle)) { + return; + } + + php_resource_factory_handle_dtor(Z_RES_VAL_P(zrf), zhandle); +} + +static PHP_MINIT_FUNCTION(raphf_test) +{ + zend_register_long_constant(ZEND_STRL("RAPHF_TEST"), PHP_RAPHF_TEST, CONST_CS|CONST_PERSISTENT, module_number); + raphf_user_le = zend_register_list_destructors_ex(raphf_user_res_dtor, NULL, + "raphf_user", module_number); + return SUCCESS; +} + +static PHP_MSHUTDOWN_FUNCTION(raphf_test) +{ + php_persistent_handle_cleanup(ZEND_STRL("test"), NULL, 0 TSRMLS_CC); + return SUCCESS; +} +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/php_raphf_api.c b/src/php_raphf_api.c index 1de0fc0..f867af6 100644 --- a/src/php_raphf_api.c +++ b/src/php_raphf_api.c @@ -19,6 +19,10 @@ #include "ext/standard/info.h" #include "php_raphf.h" +#ifndef PHP_RAPHF_TEST +# define PHP_RAPHF_TEST 0 +#endif + struct php_persistent_handle_globals { ulong limit; HashTable hash; @@ -30,22 +34,13 @@ 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 ZEND_DECLARE_MODULE_GLOBALS(raphf) -#if PHP_VERSION_ID < 50500 -#undef SUCCESS -#undef FAILURE -typedef enum { - SUCCESS = 0, - FAILURE = -1 -} ZEND_RESULT_CODE; -#endif - #ifndef PHP_RAPHF_DEBUG_PHANDLES # define PHP_RAPHF_DEBUG_PHANDLES 0 #endif @@ -79,9 +74,7 @@ unsigned php_resource_factory_addref(php_resource_factory_t *rf) void php_resource_factory_dtor(php_resource_factory_t *f) { - --f->refcount; - - if (!f->refcount) { + if (!--f->refcount) { if (f->dtor) { f->dtor(f->data); } @@ -99,29 +92,26 @@ 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); } } @@ -138,110 +128,104 @@ 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) { - int free_list; - - if ((free_list = !list)) { - list = pemalloc(sizeof(php_persistent_handle_list_t), 1); + if (!list) { + list = pemalloc(sizeof(*list), 1); } - list->used = 0; - - if (SUCCESS != zend_hash_init(&list->free, 0, NULL, NULL, 1)) { - if (free_list) { - pefree(list, 1); - } - list = NULL; - } + zend_hash_init(&list->free, 0, NULL, NULL, 1); return list; } -static int php_persistent_handle_apply_stat(void *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 = p; - zval *zsubentry, *zentry = va_arg(argv, zval *); - - MAKE_STD_ZVAL(zsubentry); - array_init(zsubentry); - add_assoc_long_ex(zsubentry, ZEND_STRS("used"), (*list)->used); - add_assoc_long_ex(zsubentry, ZEND_STRS("free"), - zend_hash_num_elements(&(*list)->free)); - add_assoc_zval_ex(zentry, key->arKey, key->nKeyLength, zsubentry); + php_persistent_handle_list_t *list = Z_PTR_P(p); + zval zsubentry, *zentry = va_arg(argv, zval *); + array_init(&zsubentry); + add_assoc_long_ex(&zsubentry, ZEND_STRL("used"), list->used); + add_assoc_long_ex(&zsubentry, ZEND_STRL("free"), + zend_hash_num_elements(&list->free)); + if (key->key) { + add_assoc_zval_ex(zentry, key->key->val, key->key->len, &zsubentry); + } else { + add_index_zval(zentry, key->h, &zsubentry); + } return ZEND_HASH_APPLY_KEEP; } -static int php_persistent_handle_apply_statall(void *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 = p; + php_persistent_handle_provider_t *provider = Z_PTR_P(p); HashTable *ht = va_arg(argv, HashTable *); - zval *zentry; + zval zentry; - MAKE_STD_ZVAL(zentry); - array_init(zentry); + array_init(&zentry); - zend_hash_apply_with_arguments(&provider->list.free TSRMLS_CC, - php_persistent_handle_apply_stat, 1, zentry); - zend_symtable_update(ht, key->arKey, key->nKeyLength, &zentry, - sizeof(zval *), NULL); + zend_hash_apply_with_arguments(&provider->list.free, + php_persistent_handle_apply_stat, 1, &zentry); + + if (key->key) { + zend_hash_update(ht, key->key, &zentry); + } else { + zend_hash_index_update(ht, key->h, &zentry); + } return ZEND_HASH_APPLY_KEEP; } -static int php_persistent_handle_apply_cleanup_ex(void *pp, void *arg TSRMLS_DC) +static int php_persistent_handle_apply_cleanup_ex(zval *p, void *arg) { php_resource_factory_t *rf = arg; - void **handle = pp; + void *handle = Z_PTR_P(p); #if PHP_RAPHF_DEBUG_PHANDLES - fprintf(stderr, "DESTROY: %p\n", *handle); + 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(void *pp, 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 **listp = pp; + php_persistent_handle_list_t *list = Z_PTR_P(p); - zend_hash_apply_with_argument(&(*listp)->free, - php_persistent_handle_apply_cleanup_ex, rf TSRMLS_CC); - if ((*listp)->used) { + zend_hash_apply_with_argument(&list->free, + php_persistent_handle_apply_cleanup_ex, rf); + if (list->used) { return ZEND_HASH_APPLY_KEEP; } - zend_hash_destroy(&(*listp)->free); + zend_hash_destroy(&list->free); #if PHP_RAPHF_DEBUG_PHANDLES - fprintf(stderr, "LSTFREE: %p\n", *listp); + fprintf(stderr, "LSTFREE: %p\n", list); #endif - pefree(*listp, 1); - *listp = NULL; + pefree(list, 1); return ZEND_HASH_APPLY_REMOVE; } 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 @@ -249,148 +233,145 @@ static inline void php_persistent_handle_list_free( *list = NULL; } -static int php_persistent_handle_list_apply_dtor(void *listp, - void *provider TSRMLS_DC) +static int php_persistent_handle_list_apply_dtor(zval *p, void *provider) { - php_persistent_handle_list_free(listp, provider TSRMLS_CC); + php_persistent_handle_list_t *list = Z_PTR_P(p); + + 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, *new_list; - ZEND_RESULT_CODE rv = zend_symtable_find(&provider->list.free, ident_str, - ident_len + 1, (void *) &list); + php_persistent_handle_list_t *list; + zval *zlist = zend_symtable_find(&provider->list.free, ident); - if (SUCCESS == rv) { + if (zlist && (list = Z_PTR_P(zlist))) { #if PHP_RAPHF_DEBUG_PHANDLES - fprintf(stderr, "LSTFIND: %p\n", *list); + fprintf(stderr, "LSTFIND: %p\n", list); #endif - return *list; + return list; } - if ((new_list = php_persistent_handle_list_init(NULL))) { - rv = zend_symtable_update(&provider->list.free, ident_str, ident_len+1, - (void *) &new_list, sizeof(php_persistent_handle_list_t *), - (void *) &list); - if (SUCCESS == rv) { + if ((list = php_persistent_handle_list_init(NULL))) { + zval p, *rv; + zend_string *id; + + ZVAL_PTR(&p, list); + 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); + fprintf(stderr, "LSTFIND: %p (new)\n", list); #endif - return *list; + return list; } - php_persistent_handle_list_free(&new_list, provider TSRMLS_CC); + php_persistent_handle_list_free(&list, provider); } return NULL; } -static int php_persistent_handle_apply_cleanup_all(void *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 = p; - const char *ident_str = va_arg(argv, const char *); - size_t ident_len = va_arg(argv, size_t); + php_persistent_handle_provider_t *provider = Z_PTR_P(p); + 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; } -static void php_persistent_handle_hash_dtor(void *p) +static void php_persistent_handle_hash_dtor(zval *p) { - php_persistent_handle_provider_t *provider; - TSRMLS_FETCH(); + php_persistent_handle_provider_t *provider = Z_PTR_P(p); - provider = (php_persistent_handle_provider_t *) p; 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); } -PHP_RAPHF_API 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 *)) { - ZEND_RESULT_CODE status = FAILURE; - php_persistent_handle_provider_t provider; + 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, *rv; + zend_string *ns; - if (php_persistent_handle_list_init(&provider.list)) { - if (php_resource_factory_init(&provider.rf, fops, data, dtor)) { #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "PROVIDE: %p %s\n", PHP_RAPHF_G, name_str); #endif - status = zend_symtable_update(&PHP_RAPHF_G->persistent_handle.hash, - name_str, name_len+1, (void *) &provider, - sizeof(php_persistent_handle_provider_t), NULL); - if (SUCCESS != status) { - php_resource_factory_dtor(&provider.rf); + ZVAL_PTR(&p, provider); + 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); } } - return status; + return FAILURE; } + 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) { - ZEND_RESULT_CODE status = FAILURE; - php_persistent_handle_factory_t *free_a = NULL; + zval *zprovider = zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash, name); - if (!a) { - free_a = a = emalloc(sizeof(*a)); - } - memset(a, 0, sizeof(*a)); - - status = zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash, name_str, - name_len+1, (void *) &a->provider); + if (zprovider) { + zend_bool free_a = 0; - if (SUCCESS == status) { - 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; } -PHP_RAPHF_API void php_persistent_handle_abandon( - php_persistent_handle_factory_t *a) +void php_persistent_handle_abandon(php_persistent_handle_factory_t *a) { zend_bool f = a->free_on_abandon; @@ -398,40 +379,37 @@ PHP_RAPHF_API void php_persistent_handle_abandon( fprintf(stderr, "ABANDON: %p\n", a->provider); #endif - STR_FREE(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; - ZEND_RESULT_CODE rv; - ulong index; - void **handle_ptr, *handle = NULL; + zval *p; + 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); - rv = zend_hash_get_current_data(&list->free, (void *) &handle_ptr); - if (HASH_KEY_NON_EXISTANT != key && SUCCESS == rv) { - handle = *handle_ptr; + 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); + fprintf(stderr, "CREATED: %p\n", handle); #endif if (handle) { ++a->provider->list.used; @@ -442,17 +420,14 @@ void *php_persistent_handle_acquire( 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; } @@ -462,26 +437,22 @@ void *php_persistent_handle_accrete( 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); + 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(&list->free, (void *) &handle, - sizeof(void *), NULL); + zend_hash_next_index_insert_ptr(&list->free, handle); } --a->provider->list.used; @@ -489,41 +460,37 @@ void php_persistent_handle_release( } } -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; - ZEND_RESULT_CODE rv; - if (name_str && name_len) { - rv = zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash, name_str, - name_len+1, (void *) &provider); + if (name) { + zval *zprovider = zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash, + name); - if (SUCCESS == rv) { - 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) { @@ -531,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; @@ -557,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); @@ -571,16 +538,17 @@ 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); } } +#if PHP_RAPHF_TEST +# include "php_raphf_test.c" +#endif + static const zend_function_entry raphf_functions[] = { ZEND_NS_FENTRY("raphf", stat_persistent_handles, ZEND_FN(raphf_stat_persistent_handles), @@ -588,6 +556,15 @@ static const zend_function_entry raphf_functions[] = { ZEND_NS_FENTRY("raphf", clean_persistent_handles, ZEND_FN(raphf_clean_persistent_handles), ai_raphf_clean_persistent_handles, 0) +#if PHP_RAPHF_TEST + ZEND_NS_FENTRY("raphf", provide, ZEND_FN(raphf_provide), NULL, 0) + ZEND_NS_FENTRY("raphf", conceal, ZEND_FN(raphf_conceal), NULL, 0) + ZEND_NS_FENTRY("raphf", concede, ZEND_FN(raphf_concede), NULL, 0) + ZEND_NS_FENTRY("raphf", dispute, ZEND_FN(raphf_dispute), NULL, 0) + ZEND_NS_FENTRY("raphf", handle_ctor, ZEND_FN(raphf_handle_ctor), NULL, 0) + ZEND_NS_FENTRY("raphf", handle_copy, ZEND_FN(raphf_handle_copy), NULL, 0) + ZEND_NS_FENTRY("raphf", handle_dtor, ZEND_FN(raphf_handle_dtor), NULL, 0) +#endif {0} }; @@ -607,8 +584,7 @@ static PHP_GINIT_FUNCTION(raphf) php_persistent_handle_hash_dtor, 1); if (php_persistent_handles_global_hash) { zend_hash_copy(&raphf_globals->persistent_handle.hash, - php_persistent_handles_global_hash, NULL, NULL, - sizeof(php_persistent_handle_provider_t)); + php_persistent_handles_global_hash, NULL); } } @@ -620,38 +596,47 @@ static PHP_GSHUTDOWN_FUNCTION(raphf) PHP_MINIT_FUNCTION(raphf) { php_persistent_handles_global_hash = &PHP_RAPHF_G->persistent_handle.hash; + +#if PHP_RAPHF_TEST + PHP_MINIT(raphf_test)(INIT_FUNC_ARGS_PASSTHRU); +#endif + REGISTER_INI_ENTRIES(); return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(raphf) { +#if PHP_RAPHF_TEST + PHP_MSHUTDOWN(raphf_test)(SHUTDOWN_FUNC_ARGS_PASSTHRU); +#endif + UNREGISTER_INI_ENTRIES(); php_persistent_handles_global_hash = NULL; return SUCCESS; } -static int php_persistent_handle_apply_info_ex(void *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 = p; + php_persistent_handle_list_t *list = Z_PTR_P(p); zend_hash_key *super_key = va_arg(argv, zend_hash_key *); char used[21], free[21]; - slprintf(used, sizeof(used), "%u", (*list)->used); - slprintf(free, sizeof(free), "%d", zend_hash_num_elements(&(*list)->free)); + slprintf(used, sizeof(used), "%u", list->used); + slprintf(free, sizeof(free), "%d", zend_hash_num_elements(&list->free)); - php_info_print_table_row(4, super_key->arKey, key->arKey, used, free); + php_info_print_table_row(4, super_key->key->val, key->key->val, used, free); return ZEND_HASH_APPLY_KEEP; } -static int php_persistent_handle_apply_info(void *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 = p; + 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; @@ -675,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(); @@ -704,7 +689,6 @@ zend_module_entry raphf_module_entry = { ZEND_GET_MODULE(raphf) #endif - /* * Local variables: * tab-width: 4 diff --git a/src/php_raphf_api.h b/src/php_raphf_api.h index ffc9a03..e9f0581 100644 --- a/src/php_raphf_api.h +++ b/src/php_raphf_api.h @@ -13,6 +13,8 @@ #ifndef PHP_RAPHF_API_H #define PHP_RAPHF_API_H +#include "php_raphf.h" + /** * A resource constructor. * @@ -20,8 +22,7 @@ * @param init_arg is the \a init_arg from php_resource_factory_init() * @return the created (persistent) handle */ -typedef void *(*php_resource_factory_handle_ctor_t)(void *opaque, - void *init_arg TSRMLS_DC); +typedef void *(*php_resource_factory_handle_ctor_t)(void *opaque, void *init_arg); /** * The copy constructor of a resource. @@ -29,8 +30,7 @@ typedef void *(*php_resource_factory_handle_ctor_t)(void *opaque, * @param opaque the factory's data * @param handle the (persistent) handle to copy */ -typedef void *(*php_resource_factory_handle_copy_t)(void *opaque, - void *handle TSRMLS_DC); +typedef void *(*php_resource_factory_handle_copy_t)(void *opaque, void *handle); /** * The destructor of a resource. @@ -38,8 +38,7 @@ typedef void *(*php_resource_factory_handle_copy_t)(void *opaque, * @param opaque the factory's data * @param handle the handle to destroy */ -typedef void (*php_resource_factory_handle_dtor_t)(void *opaque, - void *handle TSRMLS_DC); +typedef void (*php_resource_factory_handle_dtor_t)(void *opaque, void *handle); /** * The resource ops consisting of a ctor, a copy ctor and a dtor. @@ -108,7 +107,7 @@ PHP_RAPHF_API void php_resource_factory_dtor(php_resource_factory_t *f); /** * Destroy and free the resource factory. * - * Calls php_resource_factory_dtor() and frees \æ f if the factory's refcount + * Calls php_resource_factory_dtor() and frees \a f if the factory's refcount * reached 0. * * @param f the resource factory @@ -123,7 +122,7 @@ PHP_RAPHF_API void php_resource_factory_free(php_resource_factory_t **f); * @return the new resource */ PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f, - void *init_arg TSRMLS_DC); + void *init_arg); /** * Create a copy of the resource \a handle @@ -133,7 +132,7 @@ PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f, * @return the copy */ PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f, - void *handle TSRMLS_DC); + void *handle); /** * Destroy (and free) the resource @@ -142,7 +141,7 @@ PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f, * @param handle the resource to destroy */ PHP_RAPHF_API void php_resource_factory_handle_dtor(php_resource_factory_t *f, - void *handle TSRMLS_DC); + void *handle); /** * Persistent handles storage @@ -179,18 +178,18 @@ typedef struct php_persistent_handle_factory php_persistent_handle_factory_t; * Wakeup the persistent handle on re-acquisition. */ typedef void (*php_persistent_handle_wakeup_t)( - php_persistent_handle_factory_t *f, void **handle TSRMLS_DC); + php_persistent_handle_factory_t *f, void **handle); /** * Retire the persistent handle on release. */ typedef void (*php_persistent_handle_retire_t)( - php_persistent_handle_factory_t *f, void **handle TSRMLS_DC); + php_persistent_handle_factory_t *f, void **handle); /** * Definition of a persistent handle factory. * * php_persistent_handle_concede() will return a pointer to a - * php_persistent_handle_factory if a provider for the \a name_str has + * php_persistent_handle_factory if a provider for the \a name has * been registered with php_persistent_handle_provide(). */ struct php_persistent_handle_factory { @@ -202,12 +201,7 @@ struct php_persistent_handle_factory { php_persistent_handle_retire_t retire; /** The ident for which this factory manages resources */ - struct { - /** ident string */ - char *str; - /** ident length */ - size_t len; - } ident; + zend_string *ident; /** Whether it has to be free'd on php_persistent_handle_abandon() */ unsigned free_on_abandon:1; @@ -226,41 +220,38 @@ struct php_persistent_handle_factory { * A php_persistent_handle_factory can then be retrieved by * php_persistent_handle_concede() at runtime. * - * @param name_str the provider name, e.g. "http\Client\Curl" - * @param name_len the provider name length, e.g. strlen("http\Client\Curl") + * @param name the provider name, e.g. "http\Client\Curl" * @param fops the resource factory ops * @param data opaque user data * @param dtor \a data destructor * @return SUCCESS/FAILURE */ -PHP_RAPHF_API int /* SUCCESS|FAILURE */ 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); +PHP_RAPHF_API ZEND_RESULT_CODE php_persistent_handle_provide( + zend_string *name, php_resource_factory_ops_t *fops, + void *data, void (*dtor)(void *)); /** * Retrieve a persistent handle factory at runtime. * - * If a persistent handle provider has been registered for \a name_str, a new - * php_persistent_handle_factory creating resources in the \a ident_str + * If a persistent handle provider has been registered for \a name, a new + * php_persistent_handle_factory creating resources in the \a ident * namespace will be constructed. * * The wakeup routine \a wakeup and the retire routine \a retire will be * assigned to the new php_persistent_handle_factory. * * @param a pointer to a factory; allocated on the heap if NULL - * @param name_str the provider name, e.g. "http\Client\Curl" - * @param name_len the provider name length, e.g. strlen("http\Client\Curl") - * @param ident_str the subsidiary namespace, e.g. "php.net:80" - * @param ident_len the subsidiary namespace lenght, e.g. strlen("php.net:80") + * @param name the provider name, e.g. "http\Client\Curl" + * @param ident the subsidiary namespace, e.g. "php.net:80" * @param wakeup any persistent handle wakeup routine * @param retire any persistent handle retire routine * @return \a a or an allocated persistent handle factory */ PHP_RAPHF_API 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); /** * Abandon the persistent handle factory. @@ -288,7 +279,7 @@ PHP_RAPHF_API void php_persistent_handle_abandon( * @return the acquired resource */ PHP_RAPHF_API void *php_persistent_handle_acquire( - php_persistent_handle_factory_t *a, void *init_arg TSRMLS_DC); + php_persistent_handle_factory_t *a, void *init_arg); /** * Release a persistent handle. @@ -304,7 +295,7 @@ PHP_RAPHF_API void *php_persistent_handle_acquire( * @param handle the handle to release */ PHP_RAPHF_API void php_persistent_handle_release( - php_persistent_handle_factory_t *a, void *handle TSRMLS_DC); + php_persistent_handle_factory_t *a, void *handle); /** * Copy a persistent handle. @@ -315,7 +306,7 @@ PHP_RAPHF_API void php_persistent_handle_release( * @param handle the resource to accrete */ PHP_RAPHF_API void *php_persistent_handle_accrete( - php_persistent_handle_factory_t *a, void *handle TSRMLS_DC); + php_persistent_handle_factory_t *a, void *handle); /** * Retrieve persistent handle resource factory ops. @@ -327,21 +318,19 @@ PHP_RAPHF_API void *php_persistent_handle_accrete( * * Example: * \code{.c} - * php_resource_factory_t *create_my_rf(const char *persistent_id_str, - * size_t persistent_id_len TSRMLS_DC) + * php_resource_factory_t *create_my_rf(zend_string *persistent_id) * { * php_resource_factory_t *rf; * - * if (persistent_id_str) { + * if (persistent_id) { * php_persistent_handle_factory_t *pf; * php_resource_factory_ops_t *ops; + * zend_string *ns = zend_string_init("my", 2, 1); * * ops = php_persistent_handle_get_resource_factory_ops(); - * - * pf = php_persistent_handle_concede(NULL, "my", 2, - * persistent_id_str, persistent_id_len, NULL, NULL TSRMLS_CC); - * + * pf = php_persistent_handle_concede(NULL, ns, persistent_id, NULL, NULL); * rf = php_persistent_handle_resource_factory_init(NULL, pf); + * zend_string_release(ns); * } else { * rf = php_resource_factory_init(NULL, &myops, NULL, NULL); * } @@ -376,29 +365,27 @@ PHP_RAPHF_API zend_bool php_resource_factory_is_persistent( /** * Clean persistent handles up. * - * Destroy persistent handles of provider \a name_str and in subsidiary - * namespace \a ident_str. + * Destroy persistent handles of provider \a name and in subsidiary + * namespace \a ident. * - * If \a name_str is NULL, all persistent handles of all providers with a - * matching \a ident_str will be cleaned up. + * If \a name is NULL, all persistent handles of all providers with a + * matching \a ident will be cleaned up. * - * If \a ident_str is NULL all persistent handles of the provider will be + * If \a identr is NULL all persistent handles of the provider will be * cleaned up. * - * Ergo, if both, \a name_str and \a ident_str are NULL, then all + * Ergo, if both, \a name and \a ident are NULL, then all * persistent handles will be cleaned up. * * You must call this in MSHUTDOWN, if your resource factory ops hold a * registered php_resource_factory::dtor, else the dtor will point to * memory not any more available if the extension has already been unloaded. * - * @param name_str the provider name; may be NULL - * @param name_len the provider name length - * @param ident_str the subsidiary namespace name; may be NULL - * @param ident_len the subsidiary namespace name length + * @param name the provider name; may be NULL + * @param ident the subsidiary namespace name; may be NULL */ -PHP_RAPHF_API void php_persistent_handle_cleanup(const char *name_str, - size_t name_len, const char *ident_str, size_t ident_len TSRMLS_DC); +PHP_RAPHF_API void php_persistent_handle_cleanup(zend_string *name, + zend_string *ident); /** * Retrieve statistics about the current process/thread's persistent handles. @@ -415,7 +402,7 @@ PHP_RAPHF_API void php_persistent_handle_cleanup(const char *name_str, * ] * \endcode */ -PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC); +PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht); #endif /* PHP_RAPHF_API_H */ diff --git a/tests/test.phpt b/tests/test.phpt new file mode 100644 index 0000000..60c87b6 --- /dev/null +++ b/tests/test.phpt @@ -0,0 +1,158 @@ +--TEST-- +raphf test +--SKIPIF-- + +--INI-- +raphf.persistent_handle.limit=0 +--FILE-- + +--EXPECTF-- +## call provide: +bool(true) +## call concede: +resource(4) of type (raphf_user) +## call handle_ctor: +### back 'ctor': +#### arg 0: string(10) "data value" +#### arg 1: int(1) +array(2) { + [0]=> + string(10) "data value" + [1]=> + int(1) +} +## call handle_copy: +### back 'copy': +#### arg 0: string(10) "data value" +#### arg 1: array(2) { + [0]=> + string(10) "data value" + [1]=> + int(1) +} +array(2) { + [0]=> + string(10) "data value" + [1]=> + array(2) { + [0]=> + string(10) "data value" + [1]=> + int(1) + } +} +object(stdClass)#%d (1) { + ["test"]=> + array(1) { + [1]=> + array(2) { + ["used"]=> + int(2) + ["free"]=> + int(0) + } + } +} +## call handle_dtor: +### back 'dtor': +#### arg 0: string(10) "data value" +#### arg 1: array(2) { + [0]=> + string(10) "data value" + [1]=> + int(1) +} +NULL +object(stdClass)#%d (1) { + ["test"]=> + array(1) { + [1]=> + array(2) { + ["used"]=> + int(1) + ["free"]=> + int(0) + } + } +} +## call handle_dtor: +### back 'dtor': +#### arg 0: string(10) "data value" +#### arg 1: array(2) { + [0]=> + string(10) "data value" + [1]=> + array(2) { + [0]=> + string(10) "data value" + [1]=> + int(1) + } +} +NULL +object(stdClass)#%d (1) { + ["test"]=> + array(1) { + [1]=> + array(2) { + ["used"]=> + int(0) + ["free"]=> + int(0) + } + } +} +## cleanup: +bool(true) +resource(4) of type (Unknown) +### back 'data_dtor': +#### arg 0: string(10) "data value" +bool(true) +bool(false)