From 1a9de00f24739a487991f6a2e660655ec42779ac Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 5 Dec 2014 11:26:18 +0100 Subject: [PATCH] userland test --- php_raphf.c | 13 ++-- php_raphf.h | 2 +- php_raphf_test.c | 16 ++++- raphf_test.php | 37 ----------- tests/test.phpt | 158 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 180 insertions(+), 46 deletions(-) delete mode 100644 raphf_test.php create mode 100644 tests/test.phpt diff --git a/php_raphf.c b/php_raphf.c index 8b89669..dcb6904 100644 --- a/php_raphf.c +++ b/php_raphf.c @@ -20,7 +20,7 @@ #include "php_raphf.h" #ifndef PHP_RAPHF_TEST -# define PHP_RAPHF_TEST 1 +# define PHP_RAPHF_TEST 0 #endif struct php_persistent_handle_globals { @@ -137,8 +137,8 @@ static int php_persistent_handle_apply_stat(zval *p TSRMLS_DC, int argc, zval zsubentry, *zentry = va_arg(argv, zval *); array_init(&zsubentry); - add_assoc_long_ex(&zsubentry, ZEND_STRS("used"), list->used); - add_assoc_long_ex(&zsubentry, ZEND_STRS("free"), + 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); @@ -315,7 +315,7 @@ ZEND_RESULT_CODE php_persistent_handle_provide(const char *name_str, ZVAL_PTR(&p, provider); if (zend_symtable_str_update(&PHP_RAPHF_G->persistent_handle.hash, - name_str, name_len + 1, &p)) { + name_str, name_len, &p)) { return SUCCESS; } php_resource_factory_dtor(&provider->rf); @@ -340,7 +340,7 @@ php_persistent_handle_factory_t *php_persistent_handle_concede( memset(a, 0, sizeof(*a)); a->provider = zend_symtable_str_find_ptr(&PHP_RAPHF_G->persistent_handle.hash, - name_str, name_len+1); + name_str, name_len); if (a->provider) { a->ident.str = estrndup(ident_str, ident_len); @@ -474,7 +474,7 @@ void php_persistent_handle_cleanup(const char *name_str, size_t name_len, if (name_str && name_len) { provider = zend_symtable_str_find_ptr(&PHP_RAPHF_G->persistent_handle.hash, - name_str, name_len+1); + name_str, name_len); if (provider) { if (ident_str && ident_len) { @@ -570,6 +570,7 @@ static const zend_function_entry raphf_functions[] = { 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) diff --git a/php_raphf.h b/php_raphf.h index e58273a..dcf1594 100644 --- a/php_raphf.h +++ b/php_raphf.h @@ -129,7 +129,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 diff --git a/php_raphf_test.c b/php_raphf_test.c index 6d59789..3bf7c5d 100644 --- a/php_raphf_test.c +++ b/php_raphf_test.c @@ -46,7 +46,6 @@ static void raphf_user_dtor(void *opaque) { struct raphf_user *ru = opaque; - fprintf(stderr, "Freeing raphf_user struct\n"); 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); @@ -141,8 +140,20 @@ static PHP_FUNCTION(raphf_provide) 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) @@ -186,7 +197,7 @@ static PHP_FUNCTION(raphf_dispute) return; } - zend_list_close(Z_RES_P(zrf)); + RETURN_BOOL(SUCCESS == zend_list_close(Z_RES_P(zrf))); } static PHP_FUNCTION(raphf_handle_ctor) @@ -231,6 +242,7 @@ static PHP_FUNCTION(raphf_handle_dtor) 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; diff --git a/raphf_test.php b/raphf_test.php deleted file mode 100644 index 70b06de..0000000 --- a/raphf_test.php +++ /dev/null @@ -1,37 +0,0 @@ - +--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) -- 2.30.2