From: Michael Wallner Date: Fri, 5 Jul 2013 21:02:22 +0000 (+0200) Subject: code alignment X-Git-Tag: release-1.0.0~1 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-raphf;a=commitdiff_plain;h=f706105e1df56286cfeff86c5264270a758fa8f9 code alignment --- diff --git a/package.xml b/package.xml index 5b4ebc2..238c01b 100644 --- a/package.xml +++ b/package.xml @@ -19,18 +19,18 @@ http://pear.php.net/dtd/package-2.0.xsd"> mike@php.net yes - 2013-02-16 + 2013-07-07 - 0.1.0 + 1.0.0 1.0.0 - beta + stable stable BSD, revised diff --git a/php_raphf.c b/php_raphf.c index f540621..f9f354a 100644 --- a/php_raphf.c +++ b/php_raphf.c @@ -31,7 +31,9 @@ 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_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)) { if (!f) { f = emalloc(sizeof(*f)); @@ -75,7 +77,8 @@ 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 *init_arg TSRMLS_DC) +PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f, + void *init_arg TSRMLS_DC) { if (f->fops.ctor) { return f->fops.ctor(f->data, init_arg TSRMLS_CC); @@ -83,7 +86,8 @@ 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 *handle TSRMLS_DC) +PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f, + void *handle TSRMLS_DC) { if (f->fops.copy) { return f->fops.copy(f->data, handle TSRMLS_CC); @@ -91,14 +95,16 @@ 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 *handle TSRMLS_DC) +PHP_RAPHF_API void php_resource_factory_handle_dtor(php_resource_factory_t *f, + void *handle TSRMLS_DC) { if (f->fops.dtor) { f->fops.dtor(f->data, handle TSRMLS_CC); } } -static inline php_persistent_handle_list_t *php_persistent_handle_list_init(php_persistent_handle_list_t *list) +static inline php_persistent_handle_list_t *php_persistent_handle_list_init( + php_persistent_handle_list_t *list) { int free_list; @@ -118,7 +124,8 @@ static inline php_persistent_handle_list_t *php_persistent_handle_list_init(php_ return list; } -static int php_persistent_handle_apply_stat(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key) +static int php_persistent_handle_apply_stat(void *p TSRMLS_DC, int argc, + va_list argv, zend_hash_key *key) { php_persistent_handle_list_t **list = p; zval *zsubentry, *zentry = va_arg(argv, zval *); @@ -126,13 +133,15 @@ static int php_persistent_handle_apply_stat(void *p TSRMLS_DC, int argc, va_list MAKE_STD_ZVAL(zsubentry); array_init(zsubentry); add_assoc_long_ex(zsubentry, ZEND_STRS("used"), (*list)->used); - add_assoc_long_ex(zsubentry, ZEND_STRS("free"), zend_hash_num_elements(&(*list)->free)); + add_assoc_long_ex(zsubentry, ZEND_STRS("free"), + zend_hash_num_elements(&(*list)->free)); add_assoc_zval_ex(zentry, key->arKey, key->nKeyLength, zsubentry); return ZEND_HASH_APPLY_KEEP; } -static int php_persistent_handle_apply_statall(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key) +static int php_persistent_handle_apply_statall(void *p TSRMLS_DC, int argc, + va_list argv, zend_hash_key *key) { php_persistent_handle_provider_t *provider = p; HashTable *ht = va_arg(argv, HashTable *); @@ -141,8 +150,10 @@ static int php_persistent_handle_apply_statall(void *p TSRMLS_DC, int argc, va_l MAKE_STD_ZVAL(zentry); array_init(zentry); - zend_hash_apply_with_arguments(&provider->list.free TSRMLS_CC, php_persistent_handle_apply_stat, 1, zentry); - zend_symtable_update(ht, key->arKey, key->nKeyLength, &zentry, sizeof(zval *), NULL); + zend_hash_apply_with_arguments(&provider->list.free TSRMLS_CC, + php_persistent_handle_apply_stat, 1, zentry); + zend_symtable_update(ht, key->arKey, key->nKeyLength, &zentry, + sizeof(zval *), NULL); return ZEND_HASH_APPLY_KEEP; } @@ -164,7 +175,8 @@ static int php_persistent_handle_apply_cleanup(void *pp, void *arg TSRMLS_DC) php_resource_factory_t *rf = arg; php_persistent_handle_list_t **listp = pp; - zend_hash_apply_with_argument(&(*listp)->free, php_persistent_handle_apply_cleanup_ex, rf TSRMLS_CC); + zend_hash_apply_with_argument(&(*listp)->free, + php_persistent_handle_apply_cleanup_ex, rf TSRMLS_CC); if ((*listp)->used) { return ZEND_HASH_APPLY_KEEP; } @@ -177,16 +189,21 @@ static int php_persistent_handle_apply_cleanup(void *pp, void *arg TSRMLS_DC) return ZEND_HASH_APPLY_REMOVE; } -static inline void php_persistent_handle_list_dtor(php_persistent_handle_list_t *list, php_persistent_handle_provider_t *provider TSRMLS_DC) +static inline void php_persistent_handle_list_dtor( + php_persistent_handle_list_t *list, + php_persistent_handle_provider_t *provider TSRMLS_DC) { #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "LSTDTOR: %p\n", list); #endif - zend_hash_apply_with_argument(&list->free, php_persistent_handle_apply_cleanup_ex, &provider->rf TSRMLS_CC); + zend_hash_apply_with_argument(&list->free, + php_persistent_handle_apply_cleanup_ex, &provider->rf TSRMLS_CC); zend_hash_destroy(&list->free); } -static inline void php_persistent_handle_list_free(php_persistent_handle_list_t **list, php_persistent_handle_provider_t *provider TSRMLS_DC) +static inline void php_persistent_handle_list_free( + php_persistent_handle_list_t **list, + php_persistent_handle_provider_t *provider TSRMLS_DC) { php_persistent_handle_list_dtor(*list, provider TSRMLS_CC); #if PHP_RAPHF_DEBUG_PHANDLES @@ -196,17 +213,22 @@ static inline void php_persistent_handle_list_free(php_persistent_handle_list_t *list = NULL; } -static int php_persistent_handle_list_apply_dtor(void *listp, void *provider TSRMLS_DC) +static int php_persistent_handle_list_apply_dtor(void *listp, + void *provider TSRMLS_DC) { php_persistent_handle_list_free(listp, provider TSRMLS_CC); return ZEND_HASH_APPLY_REMOVE; } -static inline php_persistent_handle_list_t *php_persistent_handle_list_find(php_persistent_handle_provider_t *provider, const char *ident_str, size_t ident_len TSRMLS_DC) +static inline php_persistent_handle_list_t *php_persistent_handle_list_find( + php_persistent_handle_provider_t *provider, const char *ident_str, + size_t ident_len TSRMLS_DC) { php_persistent_handle_list_t **list, *new_list; + STATUS rv = zend_symtable_find(&provider->list.free, ident_str, + ident_len + 1, (void *) &list); - if (SUCCESS == zend_symtable_find(&provider->list.free, ident_str, ident_len + 1, (void *) &list)) { + if (SUCCESS == rv) { #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "LSTFIND: %p\n", *list); #endif @@ -214,7 +236,10 @@ static inline php_persistent_handle_list_t *php_persistent_handle_list_find(php_ } if ((new_list = php_persistent_handle_list_init(NULL))) { - if (SUCCESS == zend_symtable_update(&provider->list.free, ident_str, ident_len + 1, (void *) &new_list, sizeof(php_persistent_handle_list_t *), (void *) &list)) { + rv = zend_symtable_update(&provider->list.free, ident_str, ident_len+1, + (void *) &new_list, sizeof(php_persistent_handle_list_t *), + (void *) &list); + if (SUCCESS == rv) { #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "LSTFIND: %p (new)\n", *list); #endif @@ -226,7 +251,8 @@ static inline php_persistent_handle_list_t *php_persistent_handle_list_find(php_ return NULL; } -static int php_persistent_handle_apply_cleanup_all(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key) +static int php_persistent_handle_apply_cleanup_all(void *p TSRMLS_DC, int argc, + va_list argv, zend_hash_key *key) { php_persistent_handle_provider_t *provider = p; const char *ident_str = va_arg(argv, const char *); @@ -234,11 +260,15 @@ static int php_persistent_handle_apply_cleanup_all(void *p TSRMLS_DC, int argc, php_persistent_handle_list_t *list; if (ident_str && ident_len) { - if ((list = php_persistent_handle_list_find(provider, ident_str, ident_len TSRMLS_CC))) { - zend_hash_apply_with_argument(&list->free, php_persistent_handle_apply_cleanup_ex, &provider->rf TSRMLS_CC); + if ((list = php_persistent_handle_list_find(provider, ident_str, + ident_len TSRMLS_CC))) { + zend_hash_apply_with_argument(&list->free, + php_persistent_handle_apply_cleanup_ex, + &provider->rf TSRMLS_CC); } } else { - zend_hash_apply_with_argument(&provider->list.free, php_persistent_handle_apply_cleanup, &provider->rf TSRMLS_CC); + zend_hash_apply_with_argument(&provider->list.free, + php_persistent_handle_apply_cleanup, &provider->rf TSRMLS_CC); } return ZEND_HASH_APPLY_KEEP; @@ -246,15 +276,19 @@ static int php_persistent_handle_apply_cleanup_all(void *p TSRMLS_DC, int argc, static void php_persistent_handle_hash_dtor(void *p) { - php_persistent_handle_provider_t *provider = (php_persistent_handle_provider_t *) p; + php_persistent_handle_provider_t *provider; TSRMLS_FETCH(); - zend_hash_apply_with_argument(&provider->list.free, php_persistent_handle_list_apply_dtor, provider TSRMLS_CC); + provider = (php_persistent_handle_provider_t *) p; + zend_hash_apply_with_argument(&provider->list.free, + php_persistent_handle_list_apply_dtor, provider TSRMLS_CC); zend_hash_destroy(&provider->list.free); php_resource_factory_dtor(&provider->rf); } -PHP_RAPHF_API STATUS 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) +PHP_RAPHF_API STATUS 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; php_persistent_handle_provider_t provider; @@ -265,9 +299,10 @@ PHP_RAPHF_API STATUS php_persistent_handle_provide(const char *name_str, size_t fprintf(stderr, "PROVIDE: %p %s\n", PHP_RAPHF_G, name_str); #endif - if (SUCCESS == zend_symtable_update(&PHP_RAPHF_G->persistent_handle.hash, name_str, name_len+1, (void *) &provider, sizeof(php_persistent_handle_provider_t), NULL)) { - status = SUCCESS; - } else { + status = zend_symtable_update(&PHP_RAPHF_G->persistent_handle.hash, + name_str, name_len+1, (void *) &provider, + sizeof(php_persistent_handle_provider_t), NULL); + if (SUCCESS != status) { php_resource_factory_dtor(&provider.rf); } } @@ -276,7 +311,11 @@ PHP_RAPHF_API STATUS php_persistent_handle_provide(const char *name_str, size_t return status; } -PHP_RAPHF_API 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) +PHP_RAPHF_API 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; php_persistent_handle_factory_t *free_a = NULL; @@ -286,7 +325,8 @@ PHP_RAPHF_API php_persistent_handle_factory_t *php_persistent_handle_concede(php } memset(a, 0, sizeof(*a)); - status = zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash, name_str, name_len+1, (void *) &a->provider); + status = zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash, name_str, + name_len+1, (void *) &a->provider); if (SUCCESS == status) { a->ident.str = estrndup(ident_str, ident_len); @@ -306,13 +346,15 @@ PHP_RAPHF_API php_persistent_handle_factory_t *php_persistent_handle_concede(php } #if PHP_RAPHF_DEBUG_PHANDLES - fprintf(stderr, "CONCEDE: %p %p (%s) (%s)\n", PHP_RAPHF_G, a ? a->provider : NULL, name_str, ident_str); + fprintf(stderr, "CONCEDE: %p %p (%s) (%s)\n", PHP_RAPHF_G, + a ? a->provider : NULL, name_str, ident_str); #endif return a; } -PHP_RAPHF_API void php_persistent_handle_abandon(php_persistent_handle_factory_t *a) +PHP_RAPHF_API void php_persistent_handle_abandon( + php_persistent_handle_factory_t *a) { zend_bool f = a->free_on_abandon; @@ -327,22 +369,30 @@ PHP_RAPHF_API void php_persistent_handle_abandon(php_persistent_handle_factory_t } } -PHP_RAPHF_API void *php_persistent_handle_acquire(php_persistent_handle_factory_t *a, void *init_arg TSRMLS_DC) +PHP_RAPHF_API void *php_persistent_handle_acquire( + php_persistent_handle_factory_t *a, void *init_arg TSRMLS_DC) { + int key; + STATUS rv; ulong index; void **handle_ptr, *handle = NULL; php_persistent_handle_list_t *list; - if ((list = php_persistent_handle_list_find(a->provider, a->ident.str, a->ident.len TSRMLS_CC))) { + list = php_persistent_handle_list_find(a->provider, a->ident.str, + a->ident.len TSRMLS_CC); + if (list) { zend_hash_internal_pointer_end(&list->free); - if (HASH_KEY_NON_EXISTANT != zend_hash_get_current_key(&list->free, NULL, &index, 0) && SUCCESS == zend_hash_get_current_data(&list->free, (void *) &handle_ptr)) { + key = zend_hash_get_current_key(&list->free, NULL, &index, 0); + rv = zend_hash_get_current_data(&list->free, (void *) &handle_ptr); + if (HASH_KEY_NON_EXISTANT != key && SUCCESS == rv) { handle = *handle_ptr; if (a->wakeup) { a->wakeup(a, &handle TSRMLS_CC); } zend_hash_index_del(&list->free, index); } else { - handle = php_resource_factory_handle_ctor(&a->provider->rf, init_arg TSRMLS_CC); + handle = php_resource_factory_handle_ctor(&a->provider->rf, + init_arg TSRMLS_CC); } #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "CREATED: %p\n", *handle); @@ -356,13 +406,18 @@ PHP_RAPHF_API void *php_persistent_handle_acquire(php_persistent_handle_factory_ return handle; } -PHP_RAPHF_API void *php_persistent_handle_accrete(php_persistent_handle_factory_t *a, void *handle TSRMLS_DC) +PHP_RAPHF_API void *php_persistent_handle_accrete( + php_persistent_handle_factory_t *a, void *handle TSRMLS_DC) { void *new_handle = NULL; php_persistent_handle_list_t *list; - if ((new_handle = php_resource_factory_handle_copy(&a->provider->rf, handle TSRMLS_CC))) { - if ((list = php_persistent_handle_list_find(a->provider, a->ident.str, a->ident.len TSRMLS_CC))) { + new_handle = php_resource_factory_handle_copy(&a->provider->rf, + handle TSRMLS_CC); + if (handle) { + list = php_persistent_handle_list_find(a->provider, a->ident.str, + a->ident.len TSRMLS_CC); + if (list) { ++list->used; } ++a->provider->list.used; @@ -371,21 +426,26 @@ PHP_RAPHF_API void *php_persistent_handle_accrete(php_persistent_handle_factory_ return new_handle; } -PHP_RAPHF_API void php_persistent_handle_release(php_persistent_handle_factory_t *a, void *handle TSRMLS_DC) +PHP_RAPHF_API void php_persistent_handle_release( + php_persistent_handle_factory_t *a, void *handle TSRMLS_DC) { php_persistent_handle_list_t *list; - if ((list = php_persistent_handle_list_find(a->provider, a->ident.str, a->ident.len TSRMLS_CC))) { + list = php_persistent_handle_list_find(a->provider, a->ident.str, + a->ident.len TSRMLS_CC); + if (list) { if (a->provider->list.used >= PHP_RAPHF_G->persistent_handle.limit) { #if PHP_RAPHF_DEBUG_PHANDLES fprintf(stderr, "DESTROY: %p\n", *handle); #endif - php_resource_factory_handle_dtor(&a->provider->rf, handle TSRMLS_CC); + php_resource_factory_handle_dtor(&a->provider->rf, + handle TSRMLS_CC); } else { if (a->retire) { a->retire(a, &handle TSRMLS_CC); } - zend_hash_next_index_insert(&list->free, (void *) &handle, sizeof(void *), NULL); + zend_hash_next_index_insert(&list->free, (void *) &handle, + sizeof(void *), NULL); } --a->provider->list.used; @@ -393,23 +453,37 @@ PHP_RAPHF_API void php_persistent_handle_release(php_persistent_handle_factory_t } } -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) +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) { php_persistent_handle_provider_t *provider; php_persistent_handle_list_t *list; + STATUS rv; if (name_str && name_len) { - if (SUCCESS == zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash, name_str, name_len+1, (void *) &provider)) { + rv = zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash, name_str, + name_len+1, (void *) &provider); + + if (SUCCESS == rv) { if (ident_str && ident_len) { - if ((list = php_persistent_handle_list_find(provider, ident_str, ident_len TSRMLS_CC))) { - zend_hash_apply_with_argument(&list->free, php_persistent_handle_apply_cleanup_ex, &provider->rf TSRMLS_CC); + list = php_persistent_handle_list_find(provider, ident_str, + ident_len TSRMLS_CC); + if (list) { + zend_hash_apply_with_argument(&list->free, + php_persistent_handle_apply_cleanup_ex, + &provider->rf TSRMLS_CC); } } else { - zend_hash_apply_with_argument(&provider->list.free, php_persistent_handle_apply_cleanup, &provider->rf TSRMLS_CC); + zend_hash_apply_with_argument(&provider->list.free, + php_persistent_handle_apply_cleanup, + &provider->rf TSRMLS_CC); } } } else { - zend_hash_apply_with_arguments(&PHP_RAPHF_G->persistent_handle.hash TSRMLS_CC, php_persistent_handle_apply_cleanup_all, 2, ident_str, ident_len); + zend_hash_apply_with_arguments( + &PHP_RAPHF_G->persistent_handle.hash TSRMLS_CC, + php_persistent_handle_apply_cleanup_all, 2, ident_str, + ident_len); } } @@ -420,7 +494,9 @@ PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC) ALLOC_HASHTABLE(ht); zend_hash_init(ht, 0, NULL, ZVAL_PTR_DTOR, 0); } - zend_hash_apply_with_arguments(&PHP_RAPHF_G->persistent_handle.hash TSRMLS_CC, php_persistent_handle_apply_statall, 1, ht); + zend_hash_apply_with_arguments( + &PHP_RAPHF_G->persistent_handle.hash TSRMLS_CC, + php_persistent_handle_apply_statall, 1, ht); } else if (ht) { ht = NULL; } @@ -434,7 +510,8 @@ 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_RAPHF_API php_resource_factory_ops_t * +php_persistent_handle_get_resource_factory_ops(void) { return &php_persistent_handle_resource_factory_ops; } @@ -462,19 +539,27 @@ static PHP_FUNCTION(raphf_clean_persistent_handles) char *name_str = NULL, *ident_str = NULL; int name_len = 0, ident_len = 0; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!", &name_str, &name_len, &ident_str, &ident_len)) { - php_persistent_handle_cleanup(name_str, name_len, ident_str, ident_len TSRMLS_CC); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!", + &name_str, &name_len, &ident_str, &ident_len)) { + php_persistent_handle_cleanup(name_str, name_len, ident_str, + ident_len TSRMLS_CC); } } static const zend_function_entry raphf_functions[] = { - ZEND_NS_FENTRY("raphf", stat_persistent_handles, ZEND_FN(raphf_stat_persistent_handles), ai_raphf_stat_persistent_handles, 0) - ZEND_NS_FENTRY("raphf", clean_persistent_handles, ZEND_FN(raphf_clean_persistent_handles), ai_raphf_clean_persistent_handles, 0) + ZEND_NS_FENTRY("raphf", stat_persistent_handles, + ZEND_FN(raphf_stat_persistent_handles), + ai_raphf_stat_persistent_handles, 0) + ZEND_NS_FENTRY("raphf", clean_persistent_handles, + ZEND_FN(raphf_clean_persistent_handles), + ai_raphf_clean_persistent_handles, 0) {0} }; PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("raphf.persistent_handle.limit", "-1", PHP_INI_SYSTEM, OnUpdateLong, persistent_handle.limit, zend_raphf_globals, raphf_globals) + STD_PHP_INI_ENTRY("raphf.persistent_handle.limit", "-1", PHP_INI_SYSTEM, + OnUpdateLong, persistent_handle.limit, zend_raphf_globals, + raphf_globals) PHP_INI_END() static HashTable *php_persistent_handles_global_hash; @@ -483,9 +568,12 @@ static void php_raphf_globals_init(zend_raphf_globals *raphf_globals) { raphf_globals->persistent_handle.limit = -1; - zend_hash_init(&raphf_globals->persistent_handle.hash, 0, NULL, php_persistent_handle_hash_dtor, 1); + zend_hash_init(&raphf_globals->persistent_handle.hash, 0, NULL, + php_persistent_handle_hash_dtor, 1); if (php_persistent_handles_global_hash) { - zend_hash_copy(&raphf_globals->persistent_handle.hash, php_persistent_handles_global_hash, NULL, NULL, sizeof(php_persistent_handle_provider_t)); + zend_hash_copy(&raphf_globals->persistent_handle.hash, + php_persistent_handles_global_hash, NULL, NULL, + sizeof(php_persistent_handle_provider_t)); } } @@ -496,7 +584,8 @@ static void php_raphf_globals_dtor(zend_raphf_globals *raphf_globals) PHP_MINIT_FUNCTION(raphf) { - ZEND_INIT_MODULE_GLOBALS(raphf, php_raphf_globals_init, php_raphf_globals_dtor); + 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(); @@ -509,7 +598,8 @@ PHP_MSHUTDOWN_FUNCTION(raphf) return SUCCESS; } -static int php_persistent_handle_apply_info_ex(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key) +static int php_persistent_handle_apply_info_ex(void *p TSRMLS_DC, int argc, + va_list argv, zend_hash_key *key) { php_persistent_handle_list_t **list = p; zend_hash_key *super_key = va_arg(argv, zend_hash_key *); @@ -523,11 +613,13 @@ static int php_persistent_handle_apply_info_ex(void *p TSRMLS_DC, int argc, va_l return ZEND_HASH_APPLY_KEEP; } -static int php_persistent_handle_apply_info(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key) +static int php_persistent_handle_apply_info(void *p TSRMLS_DC, int argc, + va_list argv, zend_hash_key *key) { php_persistent_handle_provider_t *provider = p; - zend_hash_apply_with_arguments(&provider->list.free TSRMLS_CC, php_persistent_handle_apply_info_ex, 1, key); + zend_hash_apply_with_arguments(&provider->list.free TSRMLS_CC, + php_persistent_handle_apply_info_ex, 1, key); return ZEND_HASH_APPLY_KEEP; } @@ -535,7 +627,8 @@ static int php_persistent_handle_apply_info(void *p TSRMLS_DC, int argc, va_list PHP_MINFO_FUNCTION(raphf) { php_info_print_table_start(); - php_info_print_table_header(2, "Resource and persistent handle factory support", "enabled"); + php_info_print_table_header(2, + "Resource and persistent handle factory support", "enabled"); php_info_print_table_row(2, "Extension version", PHP_RAPHF_VERSION); php_info_print_table_end(); @@ -548,7 +641,9 @@ PHP_MINFO_FUNCTION(raphf) #endif ); php_info_print_table_header(4, "Provider", "Ident", "Used", "Free"); - zend_hash_apply_with_arguments(&PHP_RAPHF_G->persistent_handle.hash TSRMLS_CC, php_persistent_handle_apply_info, 0); + zend_hash_apply_with_arguments( + &PHP_RAPHF_G->persistent_handle.hash TSRMLS_CC, + php_persistent_handle_apply_info, 0); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); diff --git a/php_raphf.h b/php_raphf.h index 2c356ec..6da1b0f 100644 --- a/php_raphf.h +++ b/php_raphf.h @@ -30,9 +30,12 @@ extern zend_module_entry raphf_module_entry; # include "TSRM.h" #endif -typedef void *(*php_resource_factory_handle_ctor_t)(void *opaque, void *init_arg TSRMLS_DC); -typedef void *(*php_resource_factory_handle_copy_t)(void *opaque, void *handle TSRMLS_DC); -typedef void (*php_resource_factory_handle_dtor_t)(void *opaque, void *handle TSRMLS_DC); +typedef void *(*php_resource_factory_handle_ctor_t)(void *opaque, + void *init_arg TSRMLS_DC); +typedef void *(*php_resource_factory_handle_copy_t)(void *opaque, + void *handle TSRMLS_DC); +typedef void (*php_resource_factory_handle_dtor_t)(void *opaque, + void *handle TSRMLS_DC); typedef struct php_resource_factory_ops { php_resource_factory_handle_ctor_t ctor; @@ -49,14 +52,19 @@ typedef struct php_resource_factory { unsigned refcount; } php_resource_factory_t; -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_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_RAPHF_API unsigned php_resource_factory_addref(php_resource_factory_t *rf); 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); -PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f, void *init_arg TSRMLS_DC); -PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f, void *handle TSRMLS_DC); -PHP_RAPHF_API void php_resource_factory_handle_dtor(php_resource_factory_t *f, void *handle TSRMLS_DC); +PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f, + void *init_arg TSRMLS_DC); +PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f, + void *handle TSRMLS_DC); +PHP_RAPHF_API void php_resource_factory_handle_dtor(php_resource_factory_t *f, + void *handle TSRMLS_DC); typedef struct php_persistent_handle_list { HashTable free; @@ -70,8 +78,10 @@ typedef struct php_persistent_handle_provider { typedef struct php_persistent_handle_factory php_persistent_handle_factory_t; -typedef void (*php_persistent_handle_wakeup_t)(php_persistent_handle_factory_t *f, void **handle TSRMLS_DC); -typedef void (*php_persistent_handle_retire_t)(php_persistent_handle_factory_t *f, void **handle TSRMLS_DC); +typedef void (*php_persistent_handle_wakeup_t)( + php_persistent_handle_factory_t *f, void **handle TSRMLS_DC); +typedef void (*php_persistent_handle_retire_t)( + php_persistent_handle_factory_t *f, void **handle TSRMLS_DC); struct php_persistent_handle_factory { php_persistent_handle_provider_t *provider; @@ -92,16 +102,25 @@ struct php_persistent_handle_globals { HashTable hash; }; -PHP_RAPHF_API int /* SUCCESS|FAILURE */ 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); -PHP_RAPHF_API 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); -PHP_RAPHF_API void php_persistent_handle_abandon(php_persistent_handle_factory_t *a); -PHP_RAPHF_API void *php_persistent_handle_acquire(php_persistent_handle_factory_t *a, void *init_arg TSRMLS_DC); -PHP_RAPHF_API void php_persistent_handle_release(php_persistent_handle_factory_t *a, void *handle TSRMLS_DC); -PHP_RAPHF_API void *php_persistent_handle_accrete(php_persistent_handle_factory_t *a, void *handle TSRMLS_DC); - -PHP_RAPHF_API php_resource_factory_ops_t *php_persistent_handle_get_resource_factory_ops(void); - -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); +PHP_RAPHF_API int /* SUCCESS|FAILURE */ 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); +PHP_RAPHF_API 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); +PHP_RAPHF_API void php_persistent_handle_abandon( + php_persistent_handle_factory_t *a); +PHP_RAPHF_API void *php_persistent_handle_acquire( + php_persistent_handle_factory_t *a, void *init_arg TSRMLS_DC); +PHP_RAPHF_API void php_persistent_handle_release( + php_persistent_handle_factory_t *a, void *handle TSRMLS_DC); +PHP_RAPHF_API void *php_persistent_handle_accrete( + php_persistent_handle_factory_t *a, void *handle TSRMLS_DC); + +PHP_RAPHF_API php_resource_factory_ops_t * +php_persistent_handle_get_resource_factory_ops(void); + +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); PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC); ZEND_BEGIN_MODULE_GLOBALS(raphf) @@ -109,7 +128,8 @@ ZEND_BEGIN_MODULE_GLOBALS(raphf) ZEND_END_MODULE_GLOBALS(raphf) #ifdef ZTS -# define PHP_RAPHF_G ((zend_raphf_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(raphf_globals_id)]) +# 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