userland test
[m6w6/ext-raphf] / php_raphf.c
index 2c785dd72c00201f2e21d4377fa7a7abf520d6ef..dcb69040ae0c358c4afccd07b58be9dbe2067859 100644 (file)
 #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;
@@ -133,11 +137,14 @@ 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));
-       add_assoc_zval_ex(zentry, key->key->val, key->key->len, &zsubentry);
-
+       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;
 }
 
@@ -152,7 +159,12 @@ static int php_persistent_handle_apply_statall(zval *p TSRMLS_DC, int argc,
 
        zend_hash_apply_with_arguments(&provider->list.free TSRMLS_CC,
                        php_persistent_handle_apply_stat, 1, &zentry);
-       zend_symtable_update(ht, key->key, &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;
 }
@@ -226,8 +238,7 @@ static inline php_persistent_handle_list_t *php_persistent_handle_list_find(
 {
        php_persistent_handle_list_t *list;
 
-       list = zend_symtable_str_find_ptr(&provider->list.free, ident_str,
-                       ident_len + 1);
+       list = zend_symtable_str_find_ptr(&provider->list.free, ident_str, ident_len);
 
        if (list) {
 #if PHP_RAPHF_DEBUG_PHANDLES
@@ -314,6 +325,7 @@ ZEND_RESULT_CODE php_persistent_handle_provide(const char *name_str,
        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,
@@ -328,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);
@@ -462,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) {
@@ -545,6 +557,10 @@ static PHP_FUNCTION(raphf_clean_persistent_handles)
        }
 }
 
+#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),
@@ -552,6 +568,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}
 };
 
@@ -583,12 +608,21 @@ 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;
@@ -667,7 +701,6 @@ zend_module_entry raphf_module_entry = {
 ZEND_GET_MODULE(raphf)
 #endif
 
-
 /*
  * Local variables:
  * tab-width: 4