mirror of
https://github.com/danog/ext-pq.git
synced 2024-12-11 17:09:39 +01:00
transform event handlers to zvals;
ignore gc for now, until sorted out
This commit is contained in:
parent
6c83802195
commit
4be7248e55
@ -38,6 +38,23 @@ void php_pq_callback_addref(php_pq_callback_t *cb)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zval *php_pq_callback_to_zval(php_pq_callback_t *cb)
|
||||||
|
{
|
||||||
|
zval *zcb;
|
||||||
|
|
||||||
|
php_pq_callback_addref(cb);
|
||||||
|
|
||||||
|
if (cb->fci.object_ptr) {
|
||||||
|
MAKE_STD_ZVAL(zcb);
|
||||||
|
array_init_size(zcb, 2);
|
||||||
|
add_next_index_zval(zcb, cb->fci.object_ptr);
|
||||||
|
add_next_index_zval(zcb, cb->fci.function_name);
|
||||||
|
} else {
|
||||||
|
zcb = cb->fci.function_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return zcb;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
* tab-width: 4
|
* tab-width: 4
|
||||||
|
@ -23,6 +23,7 @@ typedef struct php_pq_callback {
|
|||||||
|
|
||||||
void php_pq_callback_dtor(php_pq_callback_t *cb);
|
void php_pq_callback_dtor(php_pq_callback_t *cb);
|
||||||
void php_pq_callback_addref(php_pq_callback_t *cb);
|
void php_pq_callback_addref(php_pq_callback_t *cb);
|
||||||
|
zval *php_pq_callback_to_zval(php_pq_callback_t *cb);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -99,6 +99,13 @@ HashTable *php_pq_object_properties(zval *object TSRMLS_DC)
|
|||||||
return ht;
|
return ht;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HashTable *php_pq_object_gc(zval *object, zval ***gc_argv, int *gc_argc TSRMLS_DC)
|
||||||
|
{
|
||||||
|
*gc_argv = NULL;
|
||||||
|
*gc_argc = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
zend_class_entry *ancestor(zend_class_entry *ce)
|
zend_class_entry *ancestor(zend_class_entry *ce)
|
||||||
{
|
{
|
||||||
while (ce->parent) {
|
while (ce->parent) {
|
||||||
|
@ -33,6 +33,7 @@ void php_pq_object_addref(void *o TSRMLS_DC);
|
|||||||
void php_pq_object_delref(void *o TSRMLS_DC);
|
void php_pq_object_delref(void *o TSRMLS_DC);
|
||||||
HashTable *php_pq_object_debug_info(zval *object, int *temp TSRMLS_DC);
|
HashTable *php_pq_object_debug_info(zval *object, int *temp TSRMLS_DC);
|
||||||
HashTable *php_pq_object_properties(zval *object TSRMLS_DC);
|
HashTable *php_pq_object_properties(zval *object TSRMLS_DC);
|
||||||
|
HashTable *php_pq_object_gc(zval *object, zval ***gc_argv, int *gc_argc TSRMLS_DC);
|
||||||
zend_class_entry *ancestor(zend_class_entry *ce);
|
zend_class_entry *ancestor(zend_class_entry *ce);
|
||||||
zval *php_pq_object_read_prop(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC);
|
zval *php_pq_object_read_prop(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC);
|
||||||
void php_pq_object_write_prop(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC);
|
void php_pq_object_write_prop(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC);
|
||||||
|
@ -311,12 +311,40 @@ static void php_pqconn_object_read_options(zval *object, void *o, zval *return_v
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int apply_read_event_handler_ex(void *p, void *arg TSRMLS_DC)
|
||||||
|
{
|
||||||
|
HashTable *rv = arg;
|
||||||
|
zval *zcb = php_pq_callback_to_zval(p);
|
||||||
|
|
||||||
|
zend_hash_next_index_insert(rv, &zcb, sizeof(zval *), NULL);
|
||||||
|
|
||||||
|
return ZEND_HASH_APPLY_KEEP;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int apply_read_event_handlers(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
|
||||||
|
{
|
||||||
|
HashTable *evhs = p, *rv = va_arg(argv, HashTable *);
|
||||||
|
zval *entry, **entry_ptr;
|
||||||
|
|
||||||
|
MAKE_STD_ZVAL(entry);
|
||||||
|
array_init_size(entry, zend_hash_num_elements(evhs));
|
||||||
|
|
||||||
|
if (key->nKeyLength) {
|
||||||
|
zend_hash_add(rv, key->arKey, key->nKeyLength, &entry, sizeof(zval *), (void *) &entry_ptr);
|
||||||
|
} else {
|
||||||
|
zend_hash_index_update(rv, key->h, &entry, sizeof(zval *), (void *) &entry_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
zend_hash_apply_with_argument(evhs, apply_read_event_handler_ex, Z_ARRVAL_PP(entry_ptr) TSRMLS_CC);
|
||||||
|
|
||||||
|
return ZEND_HASH_APPLY_KEEP;
|
||||||
|
}
|
||||||
static void php_pqconn_object_read_event_handlers(zval *object, void *o, zval *return_value TSRMLS_DC)
|
static void php_pqconn_object_read_event_handlers(zval *object, void *o, zval *return_value TSRMLS_DC)
|
||||||
{
|
{
|
||||||
php_pqconn_object_t *obj = o;
|
php_pqconn_object_t *obj = o;
|
||||||
|
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
zend_hash_copy(Z_ARRVAL_P(return_value), &obj->intern->eventhandlers, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
|
zend_hash_apply_with_arguments(&obj->intern->eventhandlers TSRMLS_CC, apply_read_event_handlers, 1, Z_ARRVAL_P(return_value) TSRMLS_CC);
|
||||||
}
|
}
|
||||||
|
|
||||||
static STATUS php_pqconn_update_socket(zval *this_ptr, php_pqconn_object_t *obj TSRMLS_DC)
|
static STATUS php_pqconn_update_socket(zval *this_ptr, php_pqconn_object_t *obj TSRMLS_DC)
|
||||||
@ -1502,6 +1530,7 @@ PHP_MINIT_FUNCTION(pqconn)
|
|||||||
php_pqconn_object_handlers.write_property = php_pq_object_write_prop;
|
php_pqconn_object_handlers.write_property = php_pq_object_write_prop;
|
||||||
php_pqconn_object_handlers.clone_obj = NULL;
|
php_pqconn_object_handlers.clone_obj = NULL;
|
||||||
php_pqconn_object_handlers.get_property_ptr_ptr = NULL;
|
php_pqconn_object_handlers.get_property_ptr_ptr = NULL;
|
||||||
|
php_pqconn_object_handlers.get_gc = php_pq_object_gc;
|
||||||
php_pqconn_object_handlers.get_properties = php_pq_object_properties;
|
php_pqconn_object_handlers.get_properties = php_pq_object_properties;
|
||||||
php_pqconn_object_handlers.get_debug_info = php_pq_object_debug_info;
|
php_pqconn_object_handlers.get_debug_info = php_pq_object_debug_info;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user