typo
[m6w6/ext-raphf] / php_raphf.c
index f9f354a2cd8503a49f2feaeec80bbc05922aec97..1de0fc0c2bc780bad5b1f9815b9f021cc1f6d1c2 100644 (file)
 #include "ext/standard/info.h"
 #include "php_raphf.h"
 
+struct php_persistent_handle_globals {
+       ulong limit;
+       HashTable hash;
+};
+
+ZEND_BEGIN_MODULE_GLOBALS(raphf)
+       struct php_persistent_handle_globals persistent_handle;
+ZEND_END_MODULE_GLOBALS(raphf)
+
+#ifdef ZTS
+#      define PHP_RAPHF_G ((zend_raphf_globals *) \
+               (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(raphf_globals_id)])
+#else
+#      define PHP_RAPHF_G (&raphf_globals)
+#endif
+
 ZEND_DECLARE_MODULE_GLOBALS(raphf)
 
-typedef int STATUS;
+#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
@@ -31,9 +54,8 @@ typedef int STATUS;
 #      define inline
 #endif
 
-PHP_RAPHF_API php_resource_factory_t *php_resource_factory_init(
-               php_resource_factory_t *f, php_resource_factory_ops_t *fops, void *data,
-               void (*dtor)(void *data))
+php_resource_factory_t *php_resource_factory_init(php_resource_factory_t *f,
+               php_resource_factory_ops_t *fops, void *data, void (*dtor)(void *data))
 {
        if (!f) {
                f = emalloc(sizeof(*f));
@@ -50,12 +72,12 @@ PHP_RAPHF_API php_resource_factory_t *php_resource_factory_init(
        return f;
 }
 
-PHP_RAPHF_API unsigned php_resource_factory_addref(php_resource_factory_t *rf)
+unsigned php_resource_factory_addref(php_resource_factory_t *rf)
 {
        return ++rf->refcount;
 }
 
-PHP_RAPHF_API void php_resource_factory_dtor(php_resource_factory_t *f)
+void php_resource_factory_dtor(php_resource_factory_t *f)
 {
        --f->refcount;
 
@@ -66,7 +88,7 @@ PHP_RAPHF_API void php_resource_factory_dtor(php_resource_factory_t *f)
        }
 }
 
-PHP_RAPHF_API void php_resource_factory_free(php_resource_factory_t **f)
+void php_resource_factory_free(php_resource_factory_t **f)
 {
        if (*f) {
                php_resource_factory_dtor(*f);
@@ -77,7 +99,7 @@ PHP_RAPHF_API void php_resource_factory_free(php_resource_factory_t **f)
        }
 }
 
-PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f,
+void *php_resource_factory_handle_ctor(php_resource_factory_t *f,
                void *init_arg TSRMLS_DC)
 {
        if (f->fops.ctor) {
@@ -86,7 +108,7 @@ PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f,
        return NULL;
 }
 
-PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f,
+void *php_resource_factory_handle_copy(php_resource_factory_t *f,
                void *handle TSRMLS_DC)
 {
        if (f->fops.copy) {
@@ -95,7 +117,7 @@ PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f,
        return NULL;
 }
 
-PHP_RAPHF_API void php_resource_factory_handle_dtor(php_resource_factory_t *f,
+void php_resource_factory_handle_dtor(php_resource_factory_t *f,
                void *handle TSRMLS_DC)
 {
        if (f->fops.dtor) {
@@ -103,6 +125,20 @@ PHP_RAPHF_API void php_resource_factory_handle_dtor(php_resource_factory_t *f,
        }
 }
 
+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)
 {
@@ -225,7 +261,7 @@ static inline php_persistent_handle_list_t *php_persistent_handle_list_find(
                size_t ident_len TSRMLS_DC)
 {
        php_persistent_handle_list_t **list, *new_list;
-       STATUS rv = zend_symtable_find(&provider->list.free, ident_str,
+       ZEND_RESULT_CODE rv = zend_symtable_find(&provider->list.free, ident_str,
                        ident_len + 1, (void *) &list);
 
        if (SUCCESS == rv) {
@@ -286,11 +322,11 @@ static void php_persistent_handle_hash_dtor(void *p)
        php_resource_factory_dtor(&provider->rf);
 }
 
-PHP_RAPHF_API STATUS php_persistent_handle_provide(const char *name_str,
+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)
 {
-       STATUS status = FAILURE;
+       ZEND_RESULT_CODE status = FAILURE;
        php_persistent_handle_provider_t provider;
 
        if (php_persistent_handle_list_init(&provider.list)) {
@@ -311,13 +347,13 @@ PHP_RAPHF_API STATUS php_persistent_handle_provide(const char *name_str,
        return status;
 }
 
-PHP_RAPHF_API php_persistent_handle_factory_t *php_persistent_handle_concede(
+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_wakeup_t wakeup,
                php_persistent_handle_retire_t retire TSRMLS_DC)
 {
-       STATUS status = FAILURE;
+       ZEND_RESULT_CODE status = FAILURE;
        php_persistent_handle_factory_t *free_a = NULL;
 
        if (!a) {
@@ -369,11 +405,11 @@ PHP_RAPHF_API void php_persistent_handle_abandon(
        }
 }
 
-PHP_RAPHF_API void *php_persistent_handle_acquire(
+void *php_persistent_handle_acquire(
                php_persistent_handle_factory_t *a, void *init_arg  TSRMLS_DC)
 {
        int key;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
        ulong index;
        void **handle_ptr, *handle = NULL;
        php_persistent_handle_list_t *list;
@@ -406,7 +442,7 @@ PHP_RAPHF_API void *php_persistent_handle_acquire(
        return handle;
 }
 
-PHP_RAPHF_API void *php_persistent_handle_accrete(
+void *php_persistent_handle_accrete(
                php_persistent_handle_factory_t *a, void *handle TSRMLS_DC)
 {
        void *new_handle = NULL;
@@ -426,7 +462,7 @@ PHP_RAPHF_API void *php_persistent_handle_accrete(
        return new_handle;
 }
 
-PHP_RAPHF_API void php_persistent_handle_release(
+void php_persistent_handle_release(
                php_persistent_handle_factory_t *a, void *handle TSRMLS_DC)
 {
        php_persistent_handle_list_t *list;
@@ -453,12 +489,12 @@ PHP_RAPHF_API void php_persistent_handle_release(
        }
 }
 
-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)
+void php_persistent_handle_cleanup(const char *name_str, size_t name_len,
+               const char *ident_str, size_t ident_len TSRMLS_DC)
 {
        php_persistent_handle_provider_t *provider;
        php_persistent_handle_list_t *list;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        if (name_str && name_len) {
                rv = zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash, name_str,
@@ -487,7 +523,7 @@ PHP_RAPHF_API void php_persistent_handle_cleanup(const char *name_str,
        }
 }
 
-PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC)
+HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC)
 {
        if (zend_hash_num_elements(&PHP_RAPHF_G->persistent_handle.hash)) {
                if (!ht) {
@@ -510,8 +546,7 @@ static php_resource_factory_ops_t php_persistent_handle_resource_factory_ops = {
        (php_resource_factory_handle_dtor_t) php_persistent_handle_release
 };
 
-PHP_RAPHF_API php_resource_factory_ops_t *
-php_persistent_handle_get_resource_factory_ops(void)
+php_resource_factory_ops_t *php_persistent_handle_get_resource_factory_ops(void)
 {
        return &php_persistent_handle_resource_factory_ops;
 }
@@ -564,7 +599,7 @@ PHP_INI_END()
 
 static HashTable *php_persistent_handles_global_hash;
 
-static void php_raphf_globals_init(zend_raphf_globals *raphf_globals)
+static PHP_GINIT_FUNCTION(raphf)
 {
        raphf_globals->persistent_handle.limit = -1;
 
@@ -577,17 +612,14 @@ static void php_raphf_globals_init(zend_raphf_globals *raphf_globals)
        }
 }
 
-static void php_raphf_globals_dtor(zend_raphf_globals *raphf_globals)
+static PHP_GSHUTDOWN_FUNCTION(raphf)
 {
        zend_hash_destroy(&raphf_globals->persistent_handle.hash);
 }
 
 PHP_MINIT_FUNCTION(raphf)
 {
-       ZEND_INIT_MODULE_GLOBALS(raphf, php_raphf_globals_init,
-                       php_raphf_globals_dtor);
        php_persistent_handles_global_hash = &PHP_RAPHF_G->persistent_handle.hash;
-
        REGISTER_INI_ENTRIES();
        return SUCCESS;
 }
@@ -595,6 +627,7 @@ PHP_MINIT_FUNCTION(raphf)
 PHP_MSHUTDOWN_FUNCTION(raphf)
 {
        UNREGISTER_INI_ENTRIES();
+       php_persistent_handles_global_hash = NULL;
        return SUCCESS;
 }
 
@@ -659,7 +692,11 @@ zend_module_entry raphf_module_entry = {
        NULL,
        PHP_MINFO(raphf),
        PHP_RAPHF_VERSION,
-       STANDARD_MODULE_PROPERTIES
+       ZEND_MODULE_GLOBALS(raphf),
+       PHP_GINIT(raphf),
+       PHP_GSHUTDOWN(raphf),
+       NULL,
+       STANDARD_MODULE_PROPERTIES_EX
 };
 /* }}} */