#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
# 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));
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;
}
}
-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);
}
}
-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) {
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) {
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) {
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) {
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)) {
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) {
}
}
-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;
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;
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;
}
}
-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,
}
}
-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) {
(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;
}
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;
}
}
-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;
}
PHP_MSHUTDOWN_FUNCTION(raphf)
{
UNREGISTER_INI_ENTRIES();
+ php_persistent_handles_global_hash = NULL;
return SUCCESS;
}
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
};
/* }}} */