1 /*
2 +----------------------------------------------------------------------+
3 | Copyright (c) 2010 The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | http://www.php.net/license/3_01.txt. |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Andrei Zmievski <andrei@php.net> |
14 | Timandes White <timands@gmail.com> |
15 +----------------------------------------------------------------------+
16 */
17
18 #include <php.h>
19
20 #include "php_zookeeper_callback.h"
21
php_cb_data_new(HashTable * ht,zend_fcall_info * fci,zend_fcall_info_cache * fcc,zend_bool oneshot TSRMLS_DC)22 php_cb_data_t* php_cb_data_new(HashTable *ht, zend_fcall_info *fci, zend_fcall_info_cache *fcc, zend_bool oneshot TSRMLS_DC)
23 {
24 php_cb_data_t *cbd = ecalloc(1, sizeof(php_cb_data_t));
25 cbd->fci = *fci;
26 cbd->fcc = *fcc;
27 cbd->oneshot = oneshot;
28 cbd->h = ht->nNextFreeElement;
29 Z_TRY_ADDREF(cbd->fci.function_name);
30 zend_hash_next_index_insert_ptr(ht, (void*)cbd);
31 cbd->ht = ht;
32 #if ZTS
33 TSRMLS_SET_CTX(cbd->ctx);
34 #endif
35 return cbd;
36 }
37
php_cb_data_destroy(php_cb_data_t * cbd)38 void php_cb_data_destroy(php_cb_data_t *cbd)
39 {
40 if (cbd) {
41 Z_TRY_DELREF(cbd->fci.function_name);
42 efree(cbd);
43 }
44 }
45
php_cb_data_remove(php_cb_data_t * cb_data)46 void php_cb_data_remove(php_cb_data_t *cb_data)
47 {
48 if (cb_data && cb_data->ht) {
49 zend_hash_index_del(cb_data->ht, cb_data->h);
50 }
51 php_cb_data_destroy(cb_data);
52 }
53