#include "php_raphf.h"
#ifndef PHP_RAPHF_TEST
-# define PHP_RAPHF_TEST 1
+# define PHP_RAPHF_TEST 0
#endif
struct php_persistent_handle_globals {
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);
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);
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);
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) {
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)
/**
* 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
{
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);
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)
return;
}
- zend_list_close(Z_RES_P(zrf));
+ RETURN_BOOL(SUCCESS == zend_list_close(Z_RES_P(zrf)));
}
static PHP_FUNCTION(raphf_handle_ctor)
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;
+++ /dev/null
-<?php
-function dumper($id) {
- return function() use ($id) {
- echo "### back '$id':\n";
- for ($i=0; $i<func_num_args(); ++$i) {
- echo "#### arg $i: ";
- var_dump(func_get_arg($i));
- }
- /* relay arguments back */
- return func_get_args();
- };
-}
-
-echo "## call provide:\n";
-var_dump(raphf\provide("test",dumper("ctor"),dumper("copy"),dumper("dtor"),"data value",dumper("data_dtor")));
-
-echo "## call concede:\n";
-var_dump($rf = raphf\concede("test","1"));
-
-echo "## call handle_ctor:\n";
-var_dump($h = raphf\handle_ctor($rf, 1));
-
-echo "## call handle_copy:\n";
-var_dump($h2 = raphf\handle_copy($rf, $h));
-
-var_dump(raphf\stat_persistent_handles());
-
-echo "## call handle_dtor:\n";
-var_dump(raphf\handle_dtor($rf, $h));
-var_dump(raphf\stat_persistent_handles());
-
-echo "## call handle_dtor:\n";
-var_dump(raphf\handle_dtor($rf, $h2));
-var_dump(raphf\stat_persistent_handles());
-
-var_dump(raphf\dispute($rf), $rf);
-
--- /dev/null
+--TEST--
+raphf test
+--SKIPIF--
+<?php
+if (!extension_loaded("raphf")) {
+ die("skip need ext/raphf");
+}
+if (!defined("RAPHF_TEST")) {
+ die("skip need RAPHF_TEST defined (-DPHP_RAPHF_TEST=1)");
+}
+?>
+--INI--
+raphf.persistent_handle.limit=0
+--FILE--
+<?php
+
+function dumper($id) {
+ return function() use ($id) {
+ echo "### back '$id':\n";
+ for ($i=0; $i<func_num_args(); ++$i) {
+ echo "#### arg $i: ";
+ var_dump(func_get_arg($i));
+ }
+ /* relay arguments back */
+ return func_get_args();
+ };
+}
+
+echo "## call provide:\n";
+var_dump(raphf\provide("test",dumper("ctor"),dumper("copy"),dumper("dtor"),"data value",dumper("data_dtor")));
+
+echo "## call concede:\n";
+var_dump($rf = raphf\concede("test","1"));
+
+echo "## call handle_ctor:\n";
+var_dump($h = raphf\handle_ctor($rf, 1));
+
+echo "## call handle_copy:\n";
+var_dump($h2 = raphf\handle_copy($rf, $h));
+var_dump(raphf\stat_persistent_handles());
+
+echo "## call handle_dtor:\n";
+var_dump(raphf\handle_dtor($rf, $h));
+var_dump(raphf\stat_persistent_handles());
+
+echo "## call handle_dtor:\n";
+var_dump(raphf\handle_dtor($rf, $h2));
+var_dump(raphf\stat_persistent_handles());
+
+echo "## cleanup:\n";
+var_dump(raphf\dispute($rf), $rf);
+var_dump(raphf\conceal("test"));
+var_dump(raphf\stat_persistent_handles());
+
+?>
+--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)