forked from datastax/php-driver
-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathphp_driver.h
220 lines (157 loc) · 12.1 KB
/
php_driver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#pragma once
#include <cassandra.h>
#include <gmp.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <version.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include <inttypes.h>
#include <math.h>
#include <string.h>
#include <php.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>
#include <Zend/zend_types.h>
#if PHP_VERSION_ID < 80100
#error PHP 8.1.0 or later is required in order to build the driver
#endif
#define PHP_DRIVER_NAMESPACE "Cassandra"
#define PHP_DRIVER_NAMESPACE_ZEND_ARG_OBJ_INFO(pass_by_ref, name, classname, allow_null) \
ZEND_ARG_OBJ_INFO(pass_by_ref, name, Cassandra\\classname, allow_null)
#define PHP_DRIVER_CORE_METHOD(name) PHP_METHOD(Cassandra, name)
#define PHP_DRIVER_CORE_ME(name, arg_info, flags) PHP_ME(Cassandra, name, arg_info, flags)
#define SAFE_STR(a) ((a) ? a : "")
#define SAFE_ZEND_STRING(a) ((a != NULL) ? ZSTR_VAL(a) : "")
#ifdef ZTS
#include "TSRM.h"
#endif
#ifdef ZTS
#define PHP_DRIVER_G(v) TSRMG(php_driver_globals_id, zend_php_driver_globals *, v)
#else
#define PHP_DRIVER_G(v) (php_driver_globals.v)
#endif
#define CPP_DRIVER_VERSION(major, minor, patch) (((major) << 16) + ((minor) << 8) + (patch))
#define CURRENT_CPP_DRIVER_VERSION CPP_DRIVER_VERSION(CASS_VERSION_MAJOR, CASS_VERSION_MINOR, CASS_VERSION_PATCH)
typedef unsigned long ulong;
#define PHP5TO7_ZEND_OBJECT_GET(type_name, object) php_driver_##type_name##_object_fetch(object)
#define PHP5TO7_SMART_STR_VAL(ss) ((ss).s ? (ss).s->val : NULL)
#define PHP5TO7_SMART_STR_LEN(ss) ((ss).s ? (ss).s->len : 0)
#define PHP5TO7_ZEND_OBJECT_ECALLOC(type_name, ce) \
(php_driver_##type_name *)ecalloc(1, sizeof(php_driver_##type_name) + zend_object_properties_size(ce))
#define PHP5TO7_ZEND_OBJECT_INIT(type_name, self, ce) PHP5TO7_ZEND_OBJECT_INIT_EX(type_name, type_name, self, ce)
#define PHP5TO7_ZEND_OBJECT_INIT_EX(type_name, name, self, ce) \
do \
{ \
zend_object_std_init(&self->zendObject, ce); \
((zend_object_handlers *)&php_driver_##name##_handlers)->offset = XtOffsetOf(php_driver_##type_name, zendObject); \
((zend_object_handlers *)&php_driver_##name##_handlers)->free_obj = php_driver_##name##_free; \
self->zendObject.handlers = (zend_object_handlers *)&php_driver_##name##_handlers; \
return &self->zendObject; \
} while (0)
#define PHP5TO7_ADD_ASSOC_ZVAL_EX(zv, key, len, val) add_assoc_zval_ex((zv), (key), (size_t)(len - 1), val)
#define PHP5TO7_ADD_ASSOC_STRINGL_EX(zv, key, key_len, str, str_len) \
add_assoc_stringl_ex((zv), (key), (size_t)(key_len - 1), (char *)(str), (size_t)(str_len))
#define PHP5TO7_ADD_NEXT_INDEX_STRING(zv, str) add_next_index_string((zv), (char *)(str));
#define PHP5TO7_ZEND_HASH_FOREACH_VAL(ht, _val) ZEND_HASH_FOREACH_VAL(ht, _val)
#define PHP5TO7_ZEND_HASH_FOREACH_NUM_KEY_VAL(ht, _h, _val) ZEND_HASH_FOREACH_NUM_KEY_VAL(ht, _h, _val)
#if PHP_VERSION_ID >= 80200
#define PHP5TO7_ZEND_HASH_FOREACH_STR_KEY_VAL(ht, _key, _val) \
ZEND_HASH_FOREACH(ht, 0); \
if (__key) \
{ \
(_key) = ZSTR_VAL(__key); \
} \
else \
{ \
(_key) = NULL; \
} \
_val = _z;
#else
#define PHP5TO7_ZEND_HASH_FOREACH_STR_KEY_VAL(ht, _key, _val) \
ZEND_HASH_FOREACH(ht, 0); \
if (_p->key) \
{ \
(_key) = _p->key->val; \
} \
else \
{ \
(_key) = NULL; \
} \
_val = _z;
#endif
#define PHP5TO7_ZEND_HASH_FOREACH_END(ht) ZEND_HASH_FOREACH_END()
#define PHP5TO7_ZEND_HASH_GET_CURRENT_DATA(ht, res) ((res = zend_hash_get_current_data((ht))) != NULL)
#define PHP5TO7_ZEND_HASH_GET_CURRENT_DATA_EX(ht, res, pos) ((res = zend_hash_get_current_data_ex((ht), (pos))) != NULL)
#define PHP5TO7_ZEND_HASH_GET_CURRENT_DATA_EX(ht, res, pos) ((res = zend_hash_get_current_data_ex((ht), (pos))) != NULL)
#define PHP5TO7_ZEND_HASH_GET_CURRENT_KEY(ht, str_index, num_index) \
zend_hash_get_current_key((ht), (str_index), (num_index))
#define PHP5TO7_ZEND_HASH_GET_CURRENT_KEY_EX(ht, str_index, num_index, pos) \
zend_hash_get_current_key_ex((ht), (str_index), (num_index), pos)
#define PHP5TO7_ZEND_HASH_EXISTS(ht, key, len) zend_hash_str_exists((ht), (key), (size_t)(len - 1))
#define PHP5TO7_ZEND_HASH_FIND(ht, key, len, res) ((res = zend_hash_str_find((ht), (key), (size_t)(len - 1))) != NULL)
#define PHP5TO7_ZEND_HASH_INDEX_FIND(ht, index, res) \
((res = zend_hash_index_find((ht), (zend_ulong)(index))) != NULL)
#define PHP5TO7_ZEND_HASH_NEXT_INDEX_INSERT(ht, val, val_size) ((void)zend_hash_next_index_insert((ht), (val)))
#define PHP5TO7_ZEND_HASH_UPDATE(ht, key, len, val, val_size) \
((void)zend_hash_str_update((ht), (key), (size_t)(len - 1), (val)))
#define PHP5TO7_ZEND_HASH_INDEX_UPDATE(ht, index, val, val_size) ((void)zend_hash_index_update((ht), (index), (val)))
#define PHP5TO7_ZEND_HASH_ADD(ht, key, len, val, val_size) \
((void)zend_hash_str_add((ht), (key), (size_t)(len - 1), (val)))
#define PHP5TO7_ZEND_HASH_DEL(ht, key, len) ((zend_hash_str_del((ht), (key), (size_t)(len - 1))) == SUCCESS)
#define PHP5TO7_ZEND_HASH_ZVAL_COPY(dst, src) zend_hash_copy((dst), (src), (copy_ctor_func_t)zval_add_ref);
#define PHP_SCYLLADB_Z_IS_BOOL_P(zv) (Z_TYPE_P(zv) == IS_TRUE || Z_TYPE_P(zv) == IS_FALSE)
#define PHP_SCYLLADB_Z_IS_FALSE_P(zv) (Z_TYPE_P(zv) == IS_FALSE)
#define PHP_SCYLLADB_Z_IS_TRUE_P(zv) (Z_TYPE_P(zv) == IS_TRUE)
#define PHP5TO7_ZVAL_MAYBE_DESTROY(zv) \
do \
{ \
if (!Z_ISUNDEF(zv)) \
{ \
zval_ptr_dtor(&(zv)); \
ZVAL_UNDEF(&(zv)); \
} \
} while (0)
extern zend_module_entry php_driver_module_entry;
#define phpext_cassandra_ptr &php_driver_module_entry
PHP_MINIT_FUNCTION(php_driver);
PHP_MSHUTDOWN_FUNCTION(php_driver);
PHP_RINIT_FUNCTION(php_driver);
PHP_RSHUTDOWN_FUNCTION(php_driver);
PHP_MINFO_FUNCTION(php_driver);
PHP_INI_MH(OnUpdateLogLevel);
PHP_INI_MH(OnUpdateLog);
zend_class_entry *exception_class(CassError rc);
void throw_invalid_argument(const zval *object, const char *object_name, const char *expected_type);
#define INVALID_ARGUMENT(object, expected) \
do \
{ \
throw_invalid_argument(object, #object, expected); \
return; \
} while (0)
#define INVALID_ARGUMENT_VALUE(object, expected, failed_value) \
do \
{ \
throw_invalid_argument(object, #object, expected); \
return failed_value; \
} while (0)
#define ASSERT_SUCCESS_BLOCK(rc, block) \
do \
{ \
if (rc != CASS_OK) \
{ \
zend_throw_exception_ex(exception_class(rc), rc, "%s", cass_error_desc(rc)); \
block \
} \
} while (0)
#define ASSERT_SUCCESS(rc) ASSERT_SUCCESS_BLOCK(rc, return;)
#define ASSERT_SUCCESS_VALUE(rc, value) ASSERT_SUCCESS_BLOCK(rc, return value;)
#define PHP_DRIVER_DEFAULT_CONSISTENCY CASS_CONSISTENCY_LOCAL_ONE
#define PHP_DRIVER_DEFAULT_LOG PHP_DRIVER_NAME ".log"
#define PHP_DRIVER_DEFAULT_LOG_LEVEL "ERROR"
#ifdef __cplusplus
}
#endif