X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_raphf.c;h=1de0fc0c2bc780bad5b1f9815b9f021cc1f6d1c2;hb=3233c1f56cfce72c079fc2bc033f16c7f4e3fc68;hp=e2ff95c232c39aa239297651546db6e52a772894;hpb=8ab1490ec9debc23bf85c8b7fd494d05b1abdeaa;p=m6w6%2Fext-raphf diff --git a/php_raphf.c b/php_raphf.c index e2ff95c..1de0fc0 100644 --- a/php_raphf.c +++ b/php_raphf.c @@ -19,9 +19,32 @@ #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; }