Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 1 | // Protocol Buffers - Google's data interchange format |
| 2 | // Copyright 2008 Google Inc. All rights reserved. |
| 3 | // https://developers.google.com/protocol-buffers/ |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
| 8 | // |
| 9 | // * Redistributions of source code must retain the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer. |
| 11 | // * Redistributions in binary form must reproduce the above |
| 12 | // copyright notice, this list of conditions and the following disclaimer |
| 13 | // in the documentation and/or other materials provided with the |
| 14 | // distribution. |
| 15 | // * Neither the name of Google Inc. nor the names of its |
| 16 | // contributors may be used to endorse or promote products derived from |
| 17 | // this software without specific prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | #ifndef __GOOGLE_PROTOBUF_PHP_PROTOBUF_H__ |
| 32 | #define __GOOGLE_PROTOBUF_PHP_PROTOBUF_H__ |
| 33 | |
| 34 | #include <php.h> |
| 35 | |
| 36 | // ubp.h has to be placed after php.h. Othwise, php.h will introduce NDEBUG. |
| 37 | #include "upb.h" |
| 38 | |
| 39 | #define PHP_PROTOBUF_EXTNAME "protobuf" |
| 40 | #define PHP_PROTOBUF_VERSION "3.6.1" |
| 41 | |
| 42 | #define MAX_LENGTH_OF_INT64 20 |
| 43 | #define SIZEOF_INT64 8 |
| 44 | |
| 45 | // ----------------------------------------------------------------------------- |
| 46 | // PHP7 Wrappers |
| 47 | // ---------------------------------------------------------------------------- |
| 48 | |
| 49 | #if PHP_VERSION_ID < 70300 |
| 50 | #define GC_ADDREF(h) ++GC_REFCOUNT(h) |
| 51 | #define GC_DELREF(h) --GC_REFCOUNT(h) |
| 52 | #endif |
| 53 | |
| 54 | #if PHP_MAJOR_VERSION < 7 |
| 55 | |
| 56 | #define php_proto_zend_literal const zend_literal* |
| 57 | #define PHP_PROTO_CASE_IS_BOOL IS_BOOL |
| 58 | #define PHP_PROTO_SIZE int |
| 59 | #define PHP_PROTO_LONG long |
| 60 | #define PHP_PROTO_TSRMLS_DC TSRMLS_DC |
| 61 | #define PHP_PROTO_TSRMLS_CC TSRMLS_CC |
| 62 | |
| 63 | // PHP String |
| 64 | |
| 65 | #define PHP_PROTO_ZVAL_STRING(zval_ptr, s, copy) \ |
| 66 | ZVAL_STRING(zval_ptr, s, copy) |
| 67 | #define PHP_PROTO_ZVAL_STRINGL(zval_ptr, s, len, copy) \ |
| 68 | ZVAL_STRINGL(zval_ptr, s, len, copy) |
| 69 | #define PHP_PROTO_RETURN_STRING(s, copy) RETURN_STRING(s, copy) |
| 70 | #define PHP_PROTO_RETURN_STRINGL(s, len, copy) RETURN_STRINGL(s, len, copy) |
| 71 | #define PHP_PROTO_RETVAL_STRINGL(s, len, copy) RETVAL_STRINGL(s, len, copy) |
| 72 | #define php_proto_zend_make_printable_zval(from, to) \ |
| 73 | { \ |
| 74 | int use_copy; \ |
| 75 | zend_make_printable_zval(from, to, &use_copy); \ |
| 76 | } |
| 77 | |
| 78 | // PHP Array |
| 79 | |
| 80 | #define PHP_PROTO_HASH_OF(array) Z_ARRVAL_P(array) |
| 81 | |
| 82 | #define php_proto_zend_hash_index_update_zval(ht, h, pData) \ |
| 83 | zend_hash_index_update(ht, h, &(pData), sizeof(void*), NULL) |
| 84 | |
| 85 | #define php_proto_zend_hash_update_zval(ht, key, key_len, value) \ |
| 86 | zend_hash_update(ht, key, key_len, value, sizeof(void*), NULL) |
| 87 | |
| 88 | #define php_proto_zend_hash_update(ht, key, key_len) \ |
| 89 | zend_hash_update(ht, key, key_len, 0, 0, NULL) |
| 90 | |
| 91 | #define php_proto_zend_hash_index_update_mem(ht, h, pData, nDataSize, pDest) \ |
| 92 | zend_hash_index_update(ht, h, pData, nDataSize, pDest) |
| 93 | |
| 94 | #define php_proto_zend_hash_update_mem(ht, key, key_len, pData, nDataSize, \ |
| 95 | pDest) \ |
| 96 | zend_hash_update(ht, key, key_len, pData, nDataSize, pDest) |
| 97 | |
| 98 | #define php_proto_zend_hash_index_find_zval(ht, h, pDest) \ |
| 99 | zend_hash_index_find(ht, h, pDest) |
| 100 | |
| 101 | #define php_proto_zend_hash_find(ht, key, key_len, pDest) \ |
| 102 | zend_hash_find(ht, key, key_len, pDest) |
| 103 | |
| 104 | #define php_proto_zend_hash_index_find_mem(ht, h, pDest) \ |
| 105 | zend_hash_index_find(ht, h, pDest) |
| 106 | |
| 107 | #define php_proto_zend_hash_find_zval(ht, key, key_len, pDest) \ |
| 108 | zend_hash_find(ht, key, key_len, pDest) |
| 109 | |
| 110 | #define php_proto_zend_hash_find_mem(ht, key, key_len, pDest) \ |
| 111 | zend_hash_find(ht, key, key_len, pDest) |
| 112 | |
| 113 | #define php_proto_zend_hash_next_index_insert_zval(ht, pData) \ |
| 114 | zend_hash_next_index_insert(ht, pData, sizeof(void*), NULL) |
| 115 | |
| 116 | #define php_proto_zend_hash_next_index_insert_mem(ht, pData, nDataSize, pDest) \ |
| 117 | zend_hash_next_index_insert(ht, pData, nDataSize, pDest) |
| 118 | |
| 119 | #define php_proto_zend_hash_get_current_data_ex(ht, pDest, pos) \ |
| 120 | zend_hash_get_current_data_ex(ht, pDest, pos) |
| 121 | |
| 122 | // PHP Object |
| 123 | |
| 124 | #define PHP_PROTO_WRAP_OBJECT_START(name) \ |
| 125 | struct name { \ |
| 126 | zend_object std; |
| 127 | #define PHP_PROTO_WRAP_OBJECT_END \ |
| 128 | }; |
| 129 | |
| 130 | #define PHP_PROTO_INIT_SUBMSGCLASS_START(CLASSNAME, CAMELNAME, LOWWERNAME) \ |
| 131 | void LOWWERNAME##_init(TSRMLS_D) { \ |
| 132 | zend_class_entry class_type; \ |
| 133 | const char* class_name = CLASSNAME; \ |
| 134 | INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME), \ |
| 135 | LOWWERNAME##_methods); \ |
| 136 | LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); \ |
| 137 | LOWWERNAME##_type->create_object = message_create; |
| 138 | #define PHP_PROTO_INIT_SUBMSGCLASS_END \ |
| 139 | } |
| 140 | |
| 141 | #define PHP_PROTO_INIT_ENUMCLASS_START(CLASSNAME, CAMELNAME, LOWWERNAME) \ |
| 142 | void LOWWERNAME##_init(TSRMLS_D) { \ |
| 143 | zend_class_entry class_type; \ |
| 144 | const char* class_name = CLASSNAME; \ |
| 145 | INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME), \ |
| 146 | LOWWERNAME##_methods); \ |
| 147 | LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); |
| 148 | #define PHP_PROTO_INIT_ENUMCLASS_END \ |
| 149 | } |
| 150 | |
| 151 | #define PHP_PROTO_INIT_CLASS_START(CLASSNAME, CAMELNAME, LOWWERNAME) \ |
| 152 | void LOWWERNAME##_init(TSRMLS_D) { \ |
| 153 | zend_class_entry class_type; \ |
| 154 | const char* class_name = CLASSNAME; \ |
| 155 | INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME), \ |
| 156 | LOWWERNAME##_methods); \ |
| 157 | LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); \ |
| 158 | LOWWERNAME##_type->create_object = LOWWERNAME##_create; \ |
| 159 | LOWWERNAME##_handlers = PEMALLOC(zend_object_handlers); \ |
| 160 | memcpy(LOWWERNAME##_handlers, zend_get_std_object_handlers(), \ |
| 161 | sizeof(zend_object_handlers)); |
| 162 | #define PHP_PROTO_INIT_CLASS_END \ |
| 163 | } |
| 164 | |
| 165 | #define PHP_PROTO_OBJECT_CREATE_START(NAME, LOWWERNAME) \ |
| 166 | static zend_object_value LOWWERNAME##_create( \ |
| 167 | zend_class_entry* ce TSRMLS_DC) { \ |
| 168 | PHP_PROTO_ALLOC_CLASS_OBJECT(NAME, ce); \ |
| 169 | zend_object_std_init(&intern->std, ce TSRMLS_CC); \ |
| 170 | object_properties_init(&intern->std, ce); |
| 171 | #define PHP_PROTO_OBJECT_CREATE_END(NAME, LOWWERNAME) \ |
| 172 | PHP_PROTO_FREE_CLASS_OBJECT(NAME, LOWWERNAME##_free, LOWWERNAME##_handlers); \ |
| 173 | } |
| 174 | |
| 175 | #define PHP_PROTO_OBJECT_FREE_START(classname, lowername) \ |
| 176 | void lowername##_free(void* object TSRMLS_DC) { \ |
| 177 | classname* intern = object; |
| 178 | #define PHP_PROTO_OBJECT_FREE_END \ |
| 179 | zend_object_std_dtor(&intern->std TSRMLS_CC); \ |
| 180 | efree(intern); \ |
| 181 | } |
| 182 | |
| 183 | #define PHP_PROTO_OBJECT_DTOR_START(classname, lowername) |
| 184 | #define PHP_PROTO_OBJECT_DTOR_END |
| 185 | |
| 186 | #define CACHED_VALUE zval* |
| 187 | #define CACHED_TO_ZVAL_PTR(VALUE) (VALUE) |
| 188 | #define CACHED_PTR_TO_ZVAL_PTR(VALUE) (*VALUE) |
| 189 | #define ZVAL_PTR_TO_CACHED_PTR(VALUE) (&VALUE) |
| 190 | #define ZVAL_PTR_TO_CACHED_VALUE(VALUE) (VALUE) |
| 191 | #define ZVAL_TO_CACHED_VALUE(VALUE) (&VALUE) |
| 192 | |
| 193 | #define CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(zval_ptr, class_type) \ |
| 194 | ZVAL_OBJ(zval_ptr, class_type->create_object(class_type TSRMLS_CC)); |
| 195 | |
| 196 | #define PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(value) \ |
| 197 | SEPARATE_ZVAL_IF_NOT_REF(value) |
| 198 | |
| 199 | #define PHP_PROTO_GLOBAL_UNINITIALIZED_ZVAL EG(uninitialized_zval_ptr) |
| 200 | |
| 201 | #define OBJ_PROP(OBJECT, OFFSET) &((OBJECT)->properties_table[OFFSET]) |
| 202 | |
| 203 | #define php_proto_zval_ptr_dtor(zval_ptr) \ |
| 204 | zval_ptr_dtor(&(zval_ptr)) |
| 205 | |
| 206 | #define PHP_PROTO_ALLOC_CLASS_OBJECT(class_object, class_type) \ |
| 207 | class_object* intern; \ |
| 208 | intern = (class_object*)emalloc(sizeof(class_object)); \ |
| 209 | memset(intern, 0, sizeof(class_object)); |
| 210 | |
| 211 | #define PHP_PROTO_FREE_CLASS_OBJECT(class_object, class_object_free, handler) \ |
| 212 | zend_object_value retval = {0}; \ |
| 213 | retval.handle = zend_objects_store_put( \ |
| 214 | intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, \ |
| 215 | class_object_free, NULL TSRMLS_CC); \ |
| 216 | retval.handlers = handler; \ |
| 217 | return retval; |
| 218 | |
| 219 | #define PHP_PROTO_ALLOC_ARRAY(zval_ptr) \ |
| 220 | ALLOC_HASHTABLE(Z_ARRVAL_P(zval_ptr)); \ |
| 221 | Z_TYPE_P(zval_ptr) = IS_ARRAY; |
| 222 | |
| 223 | #define ZVAL_OBJ(zval_ptr, call_create) \ |
| 224 | Z_TYPE_P(zval_ptr) = IS_OBJECT; \ |
| 225 | Z_OBJVAL_P(zval_ptr) = call_create; |
| 226 | |
| 227 | #define UNBOX(class_name, val) \ |
| 228 | (class_name*)zend_object_store_get_object(val TSRMLS_CC); |
| 229 | |
| 230 | #define UNBOX_HASHTABLE_VALUE(class_name, val) UNBOX(class_name, val) |
| 231 | |
| 232 | #define HASHTABLE_VALUE_DTOR ZVAL_PTR_DTOR |
| 233 | |
| 234 | #define PHP_PROTO_HASHTABLE_VALUE zval* |
| 235 | #define HASHTABLE_VALUE_CE(val) Z_OBJCE_P(val) |
| 236 | |
| 237 | #define CREATE_HASHTABLE_VALUE(OBJ, WRAPPED_OBJ, OBJ_TYPE, OBJ_CLASS_ENTRY) \ |
| 238 | OBJ_TYPE* OBJ; \ |
| 239 | PHP_PROTO_HASHTABLE_VALUE WRAPPED_OBJ; \ |
| 240 | MAKE_STD_ZVAL(WRAPPED_OBJ); \ |
| 241 | ZVAL_OBJ(WRAPPED_OBJ, \ |
| 242 | OBJ_CLASS_ENTRY->create_object(OBJ_CLASS_ENTRY TSRMLS_CC)); \ |
| 243 | OBJ = UNBOX_HASHTABLE_VALUE(OBJ_TYPE, WRAPPED_OBJ); \ |
| 244 | Z_DELREF_P(desc_php); |
| 245 | |
| 246 | #define PHP_PROTO_CE_DECLARE zend_class_entry** |
| 247 | #define PHP_PROTO_CE_UNREF(ce) (*ce) |
| 248 | |
| 249 | #define php_proto_zend_lookup_class(name, name_length, ce) \ |
| 250 | zend_lookup_class(name, name_length, ce TSRMLS_CC) |
| 251 | |
| 252 | #define PHP_PROTO_RETVAL_ZVAL(value) ZVAL_ZVAL(return_value, value, 1, 0) |
| 253 | |
| 254 | #else // PHP_MAJOR_VERSION >= 7 |
| 255 | |
| 256 | #define php_proto_zend_literal void** |
| 257 | #define PHP_PROTO_CASE_IS_BOOL IS_TRUE: case IS_FALSE |
| 258 | #define PHP_PROTO_SIZE size_t |
| 259 | #define PHP_PROTO_LONG zend_long |
| 260 | #define PHP_PROTO_TSRMLS_DC |
| 261 | #define PHP_PROTO_TSRMLS_CC |
| 262 | |
| 263 | // PHP String |
| 264 | |
| 265 | #define PHP_PROTO_ZVAL_STRING(zval_ptr, s, copy) \ |
| 266 | ZVAL_STRING(zval_ptr, s) |
| 267 | #define PHP_PROTO_ZVAL_STRINGL(zval_ptr, s, len, copy) \ |
| 268 | ZVAL_STRINGL(zval_ptr, s, len) |
| 269 | #define PHP_PROTO_RETURN_STRING(s, copy) RETURN_STRING(s) |
| 270 | #define PHP_PROTO_RETURN_STRINGL(s, len, copy) RETURN_STRINGL(s, len) |
| 271 | #define PHP_PROTO_RETVAL_STRINGL(s, len, copy) RETVAL_STRINGL(s, len) |
| 272 | #define php_proto_zend_make_printable_zval(from, to) \ |
| 273 | zend_make_printable_zval(from, to) |
| 274 | |
| 275 | // PHP Array |
| 276 | |
| 277 | #define PHP_PROTO_HASH_OF(array) Z_ARRVAL_P(&array) |
| 278 | |
| 279 | static inline int php_proto_zend_hash_index_update_zval(HashTable* ht, ulong h, |
| 280 | zval* pData) { |
| 281 | void* result = NULL; |
| 282 | result = zend_hash_index_update(ht, h, pData); |
| 283 | return result != NULL ? SUCCESS : FAILURE; |
| 284 | } |
| 285 | |
| 286 | static inline int php_proto_zend_hash_update(HashTable* ht, const char* key, |
| 287 | size_t key_len) { |
| 288 | void* result = NULL; |
| 289 | zval temp; |
| 290 | ZVAL_LONG(&temp, 0); |
| 291 | result = zend_hash_str_update(ht, key, key_len, &temp); |
| 292 | return result != NULL ? SUCCESS : FAILURE; |
| 293 | } |
| 294 | |
| 295 | static inline int php_proto_zend_hash_index_update_mem(HashTable* ht, ulong h, |
| 296 | void* pData, uint nDataSize, |
| 297 | void** pDest) { |
| 298 | void* result = NULL; |
| 299 | result = zend_hash_index_update_mem(ht, h, pData, nDataSize); |
| 300 | if (pDest != NULL) *pDest = result; |
| 301 | return result != NULL ? SUCCESS : FAILURE; |
| 302 | } |
| 303 | |
| 304 | static inline int php_proto_zend_hash_update_zval(HashTable* ht, |
| 305 | const char* key, uint key_len, |
| 306 | zval* pData) { |
| 307 | zend_string* internal_key = zend_string_init(key, key_len, 0); |
| 308 | zend_hash_update(ht, internal_key, pData); |
| 309 | } |
| 310 | |
| 311 | static inline int php_proto_zend_hash_update_mem(HashTable* ht, const char* key, |
| 312 | uint key_len, void* pData, |
| 313 | uint nDataSize, void** pDest) { |
| 314 | zend_string* internal_key = zend_string_init(key, key_len, 0); |
| 315 | void* result = zend_hash_update_mem(ht, internal_key, pData, nDataSize); |
| 316 | zend_string_release(internal_key); |
| 317 | if (pDest != NULL) *pDest = result; |
| 318 | return result != NULL ? SUCCESS : FAILURE; |
| 319 | } |
| 320 | |
| 321 | static inline int php_proto_zend_hash_index_find_zval(const HashTable* ht, |
| 322 | ulong h, void** pDest) { |
| 323 | zval* result = zend_hash_index_find(ht, h); |
| 324 | if (pDest != NULL) *pDest = result; |
| 325 | return result != NULL ? SUCCESS : FAILURE; |
| 326 | } |
| 327 | |
| 328 | static inline int php_proto_zend_hash_find(const HashTable* ht, const char* key, |
| 329 | size_t key_len, void** pDest) { |
| 330 | void* result = NULL; |
| 331 | result = zend_hash_str_find(ht, key, key_len); |
| 332 | return result != NULL ? SUCCESS : FAILURE; |
| 333 | } |
| 334 | |
| 335 | static inline int php_proto_zend_hash_index_find_mem(const HashTable* ht, |
| 336 | ulong h, void** pDest) { |
| 337 | void* result = NULL; |
| 338 | result = zend_hash_index_find_ptr(ht, h); |
| 339 | if (pDest != NULL) *pDest = result; |
| 340 | return result != NULL ? SUCCESS : FAILURE; |
| 341 | } |
| 342 | |
| 343 | static inline int php_proto_zend_hash_find_zval(const HashTable* ht, |
| 344 | const char* key, uint key_len, |
| 345 | void** pDest) { |
| 346 | zend_string* internal_key = zend_string_init(key, key_len, 1); |
| 347 | zval* result = zend_hash_find(ht, internal_key); |
| 348 | if (pDest != NULL) *pDest = result; |
| 349 | return result != NULL ? SUCCESS : FAILURE; |
| 350 | } |
| 351 | |
| 352 | static inline int php_proto_zend_hash_find_mem(const HashTable* ht, |
| 353 | const char* key, uint key_len, |
| 354 | void** pDest) { |
| 355 | zend_string* internal_key = zend_string_init(key, key_len, 1); |
| 356 | void* result = zend_hash_find_ptr(ht, internal_key); |
| 357 | zend_string_release(internal_key); |
| 358 | if (pDest != NULL) *pDest = result; |
| 359 | return result != NULL ? SUCCESS : FAILURE; |
| 360 | } |
| 361 | |
| 362 | static inline int php_proto_zend_hash_next_index_insert_zval(HashTable* ht, |
| 363 | void* pData) { |
| 364 | zval tmp; |
| 365 | ZVAL_OBJ(&tmp, *(zend_object**)pData); |
| 366 | zval* result = zend_hash_next_index_insert(ht, &tmp); |
| 367 | return result != NULL ? SUCCESS : FAILURE; |
| 368 | } |
| 369 | |
| 370 | static inline int php_proto_zend_hash_next_index_insert_mem(HashTable* ht, |
| 371 | void* pData, |
| 372 | uint nDataSize, |
| 373 | void** pDest) { |
| 374 | void* result = NULL; |
| 375 | result = zend_hash_next_index_insert_mem(ht, pData, nDataSize); |
| 376 | if (pDest != NULL) *pDest = result; |
| 377 | return result != NULL ? SUCCESS : FAILURE; |
| 378 | } |
| 379 | |
| 380 | static inline int php_proto_zend_hash_get_current_data_ex(HashTable* ht, |
| 381 | void** pDest, |
| 382 | HashPosition* pos) { |
| 383 | void* result = NULL; |
| 384 | result = zend_hash_get_current_data_ex(ht, pos); |
| 385 | if (pDest != NULL) *pDest = result; |
| 386 | return result != NULL ? SUCCESS : FAILURE; |
| 387 | } |
| 388 | |
| 389 | // PHP Object |
| 390 | |
| 391 | #define PHP_PROTO_WRAP_OBJECT_START(name) struct name { |
| 392 | #define PHP_PROTO_WRAP_OBJECT_END \ |
| 393 | zend_object std; \ |
| 394 | }; |
| 395 | |
| 396 | #define PHP_PROTO_INIT_SUBMSGCLASS_START(CLASSNAME, CAMELNAME, LOWWERNAME) \ |
| 397 | void LOWWERNAME##_init(TSRMLS_D) { \ |
| 398 | zend_class_entry class_type; \ |
| 399 | const char* class_name = CLASSNAME; \ |
| 400 | INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME), \ |
| 401 | LOWWERNAME##_methods); \ |
| 402 | LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); \ |
| 403 | LOWWERNAME##_type->create_object = message_create; |
| 404 | #define PHP_PROTO_INIT_SUBMSGCLASS_END \ |
| 405 | } |
| 406 | |
| 407 | #define PHP_PROTO_INIT_ENUMCLASS_START(CLASSNAME, CAMELNAME, LOWWERNAME) \ |
| 408 | void LOWWERNAME##_init(TSRMLS_D) { \ |
| 409 | zend_class_entry class_type; \ |
| 410 | const char* class_name = CLASSNAME; \ |
| 411 | INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME), \ |
| 412 | LOWWERNAME##_methods); \ |
| 413 | LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); |
| 414 | #define PHP_PROTO_INIT_ENUMCLASS_END \ |
| 415 | } |
| 416 | |
| 417 | #define PHP_PROTO_INIT_CLASS_START(CLASSNAME, CAMELNAME, LOWWERNAME) \ |
| 418 | void LOWWERNAME##_init(TSRMLS_D) { \ |
| 419 | zend_class_entry class_type; \ |
| 420 | const char* class_name = CLASSNAME; \ |
| 421 | INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME), \ |
| 422 | LOWWERNAME##_methods); \ |
| 423 | LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); \ |
| 424 | LOWWERNAME##_type->create_object = LOWWERNAME##_create; \ |
| 425 | LOWWERNAME##_handlers = PEMALLOC(zend_object_handlers); \ |
| 426 | memcpy(LOWWERNAME##_handlers, zend_get_std_object_handlers(), \ |
| 427 | sizeof(zend_object_handlers)); \ |
| 428 | LOWWERNAME##_handlers->free_obj = LOWWERNAME##_free; \ |
| 429 | LOWWERNAME##_handlers->dtor_obj = LOWWERNAME##_dtor; \ |
| 430 | LOWWERNAME##_handlers->offset = XtOffsetOf(CAMELNAME, std); |
| 431 | #define PHP_PROTO_INIT_CLASS_END \ |
| 432 | } |
| 433 | |
| 434 | #define PHP_PROTO_OBJECT_FREE_START(classname, lowername) \ |
| 435 | void lowername##_free(zend_object* object) { \ |
| 436 | classname* intern = \ |
| 437 | (classname*)((char*)object - XtOffsetOf(classname, std)); |
| 438 | #define PHP_PROTO_OBJECT_FREE_END \ |
| 439 | } |
| 440 | |
| 441 | #define PHP_PROTO_OBJECT_DTOR_START(classname, lowername) \ |
| 442 | void lowername##_dtor(zend_object* object) { \ |
| 443 | classname* intern = \ |
| 444 | (classname*)((char*)object - XtOffsetOf(classname, std)); |
| 445 | #define PHP_PROTO_OBJECT_DTOR_END \ |
| 446 | zend_object_std_dtor(object TSRMLS_CC); \ |
| 447 | } |
| 448 | |
| 449 | #define PHP_PROTO_OBJECT_CREATE_START(NAME, LOWWERNAME) \ |
| 450 | static zend_object* LOWWERNAME##_create(zend_class_entry* ce TSRMLS_DC) { \ |
| 451 | PHP_PROTO_ALLOC_CLASS_OBJECT(NAME, ce); \ |
| 452 | zend_object_std_init(&intern->std, ce TSRMLS_CC); \ |
| 453 | object_properties_init(&intern->std, ce); |
| 454 | #define PHP_PROTO_OBJECT_CREATE_END(NAME, LOWWERNAME) \ |
| 455 | PHP_PROTO_FREE_CLASS_OBJECT(NAME, LOWWERNAME##_free, LOWWERNAME##_handlers); \ |
| 456 | } |
| 457 | |
| 458 | #define CACHED_VALUE zval |
| 459 | #define CACHED_TO_ZVAL_PTR(VALUE) (&VALUE) |
| 460 | #define CACHED_PTR_TO_ZVAL_PTR(VALUE) (VALUE) |
| 461 | #define ZVAL_PTR_TO_CACHED_PTR(VALUE) (VALUE) |
| 462 | #define ZVAL_PTR_TO_CACHED_VALUE(VALUE) (*VALUE) |
| 463 | #define ZVAL_TO_CACHED_VALUE(VALUE) (VALUE) |
| 464 | |
| 465 | #define CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(zval_ptr, class_type) \ |
| 466 | ZVAL_OBJ(zval_ptr, class_type->create_object(class_type)); |
| 467 | |
| 468 | #define PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(value) ; |
| 469 | |
| 470 | #define PHP_PROTO_GLOBAL_UNINITIALIZED_ZVAL &EG(uninitialized_zval) |
| 471 | |
| 472 | #define php_proto_zval_ptr_dtor(zval_ptr) \ |
| 473 | zval_ptr_dtor(zval_ptr) |
| 474 | |
| 475 | #define PHP_PROTO_ALLOC_CLASS_OBJECT(class_object, class_type) \ |
| 476 | class_object* intern; \ |
| 477 | int size = sizeof(class_object) + zend_object_properties_size(class_type); \ |
| 478 | intern = ecalloc(1, size); \ |
| 479 | memset(intern, 0, size); |
| 480 | |
| 481 | #define PHP_PROTO_FREE_CLASS_OBJECT(class_object, class_object_free, handler) \ |
| 482 | intern->std.handlers = handler; \ |
| 483 | return &intern->std; |
| 484 | |
| 485 | #define PHP_PROTO_ALLOC_ARRAY(zval_ptr) \ |
| 486 | ZVAL_NEW_ARR(zval_ptr) |
| 487 | |
| 488 | #define UNBOX(class_name, val) \ |
| 489 | (class_name*)((char*)Z_OBJ_P(val) - XtOffsetOf(class_name, std)); |
| 490 | |
| 491 | #define UNBOX_HASHTABLE_VALUE(class_name, val) \ |
| 492 | (class_name*)((char*)val - XtOffsetOf(class_name, std)) |
| 493 | |
| 494 | #define HASHTABLE_VALUE_DTOR php_proto_hashtable_descriptor_release |
| 495 | |
| 496 | #define PHP_PROTO_HASHTABLE_VALUE zend_object* |
| 497 | #define HASHTABLE_VALUE_CE(val) val->ce |
| 498 | |
| 499 | #define CREATE_HASHTABLE_VALUE(OBJ, WRAPPED_OBJ, OBJ_TYPE, OBJ_CLASS_ENTRY) \ |
| 500 | OBJ_TYPE* OBJ; \ |
| 501 | PHP_PROTO_HASHTABLE_VALUE WRAPPED_OBJ; \ |
| 502 | WRAPPED_OBJ = OBJ_CLASS_ENTRY->create_object(OBJ_CLASS_ENTRY); \ |
| 503 | OBJ = UNBOX_HASHTABLE_VALUE(OBJ_TYPE, WRAPPED_OBJ); \ |
| 504 | GC_DELREF(WRAPPED_OBJ); |
| 505 | |
| 506 | #define PHP_PROTO_CE_DECLARE zend_class_entry* |
| 507 | #define PHP_PROTO_CE_UNREF(ce) (ce) |
| 508 | |
| 509 | static inline int php_proto_zend_lookup_class( |
| 510 | const char* name, int name_length, zend_class_entry** ce TSRMLS_DC) { |
| 511 | zend_string *zstr_name = zend_string_init(name, name_length, 0); |
| 512 | *ce = zend_lookup_class(zstr_name); |
| 513 | zend_string_release(zstr_name); |
| 514 | return *ce != NULL ? SUCCESS : FAILURE; |
| 515 | } |
| 516 | |
| 517 | #define PHP_PROTO_RETVAL_ZVAL(value) ZVAL_COPY(return_value, value) |
| 518 | |
| 519 | #endif // PHP_MAJOR_VERSION >= 7 |
| 520 | |
| 521 | #if PHP_MAJOR_VERSION < 7 || (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 0) |
| 522 | #define PHP_PROTO_FAKE_SCOPE_BEGIN(klass) \ |
| 523 | zend_class_entry* old_scope = EG(scope); \ |
| 524 | EG(scope) = klass; |
| 525 | #define PHP_PROTO_FAKE_SCOPE_RESTART(klass) \ |
| 526 | old_scope = EG(scope); \ |
| 527 | EG(scope) = klass; |
| 528 | #define PHP_PROTO_FAKE_SCOPE_END EG(scope) = old_scope; |
| 529 | #else |
| 530 | #define PHP_PROTO_FAKE_SCOPE_BEGIN(klass) \ |
| 531 | zend_class_entry* old_scope = EG(fake_scope); \ |
| 532 | EG(fake_scope) = klass; |
| 533 | #define PHP_PROTO_FAKE_SCOPE_RESTART(klass) \ |
| 534 | old_scope = EG(fake_scope); \ |
| 535 | EG(fake_scope) = klass; |
| 536 | #define PHP_PROTO_FAKE_SCOPE_END EG(fake_scope) = old_scope; |
| 537 | #endif |
| 538 | |
| 539 | // Define PHP class |
| 540 | #define DEFINE_PROTOBUF_INIT_CLASS(CLASSNAME, CAMELNAME, LOWERNAME) \ |
| 541 | PHP_PROTO_INIT_CLASS_START(CLASSNAME, CAMELNAME, LOWERNAME) \ |
| 542 | PHP_PROTO_INIT_CLASS_END |
| 543 | |
| 544 | #define DEFINE_PROTOBUF_CREATE(NAME, LOWERNAME) \ |
| 545 | PHP_PROTO_OBJECT_CREATE_START(NAME, LOWERNAME) \ |
| 546 | LOWERNAME##_init_c_instance(intern TSRMLS_CC); \ |
| 547 | PHP_PROTO_OBJECT_CREATE_END(NAME, LOWERNAME) |
| 548 | |
| 549 | #define DEFINE_PROTOBUF_FREE(CAMELNAME, LOWERNAME) \ |
| 550 | PHP_PROTO_OBJECT_FREE_START(CAMELNAME, LOWERNAME) \ |
| 551 | LOWERNAME##_free_c(intern TSRMLS_CC); \ |
| 552 | PHP_PROTO_OBJECT_FREE_END |
| 553 | |
| 554 | #define DEFINE_PROTOBUF_DTOR(CAMELNAME, LOWERNAME) \ |
| 555 | PHP_PROTO_OBJECT_DTOR_START(CAMELNAME, LOWERNAME) \ |
| 556 | PHP_PROTO_OBJECT_DTOR_END |
| 557 | |
| 558 | #define DEFINE_CLASS(NAME, LOWERNAME, string_name) \ |
| 559 | zend_class_entry *LOWERNAME##_type; \ |
| 560 | zend_object_handlers *LOWERNAME##_handlers; \ |
| 561 | DEFINE_PROTOBUF_FREE(NAME, LOWERNAME) \ |
| 562 | DEFINE_PROTOBUF_DTOR(NAME, LOWERNAME) \ |
| 563 | DEFINE_PROTOBUF_CREATE(NAME, LOWERNAME) \ |
| 564 | DEFINE_PROTOBUF_INIT_CLASS(string_name, NAME, LOWERNAME) |
| 565 | |
| 566 | // ----------------------------------------------------------------------------- |
| 567 | // Forward Declaration |
| 568 | // ---------------------------------------------------------------------------- |
| 569 | |
| 570 | struct Any; |
| 571 | struct Api; |
| 572 | struct BoolValue; |
| 573 | struct BytesValue; |
| 574 | struct Descriptor; |
| 575 | struct DescriptorPool; |
| 576 | struct DoubleValue; |
| 577 | struct Duration; |
| 578 | struct Enum; |
| 579 | struct EnumDescriptor; |
| 580 | struct EnumValue; |
| 581 | struct EnumValueDescriptor; |
| 582 | struct Field; |
| 583 | struct FieldDescriptor; |
| 584 | struct FieldMask; |
| 585 | struct Field_Cardinality; |
| 586 | struct Field_Kind; |
| 587 | struct FloatValue; |
| 588 | struct GPBEmpty; |
| 589 | struct Int32Value; |
| 590 | struct Int64Value; |
| 591 | struct InternalDescriptorPool; |
| 592 | struct ListValue; |
| 593 | struct Map; |
| 594 | struct MapIter; |
| 595 | struct MessageField; |
| 596 | struct MessageHeader; |
| 597 | struct MessageLayout; |
| 598 | struct Method; |
| 599 | struct Mixin; |
| 600 | struct NullValue; |
| 601 | struct Oneof; |
| 602 | struct Option; |
| 603 | struct RepeatedField; |
| 604 | struct RepeatedFieldIter; |
| 605 | struct SourceContext; |
| 606 | struct StringValue; |
| 607 | struct Struct; |
| 608 | struct Syntax; |
| 609 | struct Timestamp; |
| 610 | struct Type; |
| 611 | struct UInt32Value; |
| 612 | struct UInt64Value; |
| 613 | struct Value; |
| 614 | |
| 615 | typedef struct Any Any; |
| 616 | typedef struct Api Api; |
| 617 | typedef struct BoolValue BoolValue; |
| 618 | typedef struct BytesValue BytesValue; |
| 619 | typedef struct Descriptor Descriptor; |
| 620 | typedef struct DescriptorPool DescriptorPool; |
| 621 | typedef struct DoubleValue DoubleValue; |
| 622 | typedef struct Duration Duration; |
| 623 | typedef struct EnumDescriptor EnumDescriptor; |
| 624 | typedef struct Enum Enum; |
| 625 | typedef struct EnumValueDescriptor EnumValueDescriptor; |
| 626 | typedef struct EnumValue EnumValue; |
| 627 | typedef struct Field_Cardinality Field_Cardinality; |
| 628 | typedef struct FieldDescriptor FieldDescriptor; |
| 629 | typedef struct Field Field; |
| 630 | typedef struct Field_Kind Field_Kind; |
| 631 | typedef struct FieldMask FieldMask; |
| 632 | typedef struct FloatValue FloatValue; |
| 633 | typedef struct GPBEmpty GPBEmpty; |
| 634 | typedef struct Int32Value Int32Value; |
| 635 | typedef struct Int64Value Int64Value; |
| 636 | typedef struct InternalDescriptorPool InternalDescriptorPool; |
| 637 | typedef struct ListValue ListValue; |
| 638 | typedef struct MapIter MapIter; |
| 639 | typedef struct Map Map; |
| 640 | typedef struct MessageField MessageField; |
| 641 | typedef struct MessageHeader MessageHeader; |
| 642 | typedef struct MessageLayout MessageLayout; |
| 643 | typedef struct Method Method; |
| 644 | typedef struct Mixin Mixin; |
| 645 | typedef struct NullValue NullValue; |
| 646 | typedef struct Oneof Oneof; |
| 647 | typedef struct Option Option; |
| 648 | typedef struct RepeatedFieldIter RepeatedFieldIter; |
| 649 | typedef struct RepeatedField RepeatedField; |
| 650 | typedef struct SourceContext SourceContext; |
| 651 | typedef struct StringValue StringValue; |
| 652 | typedef struct Struct Struct; |
| 653 | typedef struct Syntax Syntax; |
| 654 | typedef struct Timestamp Timestamp; |
| 655 | typedef struct Type Type; |
| 656 | typedef struct UInt32Value UInt32Value; |
| 657 | typedef struct UInt64Value UInt64Value; |
| 658 | typedef struct Value Value; |
| 659 | |
| 660 | // ----------------------------------------------------------------------------- |
| 661 | // Globals. |
| 662 | // ----------------------------------------------------------------------------- |
| 663 | |
| 664 | ZEND_BEGIN_MODULE_GLOBALS(protobuf) |
| 665 | ZEND_END_MODULE_GLOBALS(protobuf) |
| 666 | |
| 667 | // Init module and PHP classes. |
| 668 | void any_init(TSRMLS_D); |
| 669 | void api_init(TSRMLS_D); |
| 670 | void bool_value_init(TSRMLS_D); |
| 671 | void bytes_value_init(TSRMLS_D); |
| 672 | void descriptor_init(TSRMLS_D); |
| 673 | void descriptor_pool_init(TSRMLS_D); |
| 674 | void double_value_init(TSRMLS_D); |
| 675 | void duration_init(TSRMLS_D); |
| 676 | void empty_init(TSRMLS_D); |
| 677 | void enum_descriptor_init(TSRMLS_D); |
| 678 | void enum_init(TSRMLS_D); |
| 679 | void enum_value_init(TSRMLS_D); |
| 680 | void field_cardinality_init(TSRMLS_D); |
| 681 | void field_descriptor_init(TSRMLS_D); |
| 682 | void field_init(TSRMLS_D); |
| 683 | void field_kind_init(TSRMLS_D); |
| 684 | void field_mask_init(TSRMLS_D); |
| 685 | void float_value_init(TSRMLS_D); |
| 686 | void gpb_type_init(TSRMLS_D); |
| 687 | void int32_value_init(TSRMLS_D); |
| 688 | void int64_value_init(TSRMLS_D); |
| 689 | void internal_descriptor_pool_init(TSRMLS_D); |
| 690 | void list_value_init(TSRMLS_D); |
| 691 | void map_field_init(TSRMLS_D); |
| 692 | void map_field_iter_init(TSRMLS_D); |
| 693 | void message_init(TSRMLS_D); |
| 694 | void method_init(TSRMLS_D); |
| 695 | void mixin_init(TSRMLS_D); |
| 696 | void null_value_init(TSRMLS_D); |
| 697 | void oneof_descriptor_init(TSRMLS_D); |
| 698 | void option_init(TSRMLS_D); |
| 699 | void repeated_field_init(TSRMLS_D); |
| 700 | void repeated_field_iter_init(TSRMLS_D); |
| 701 | void source_context_init(TSRMLS_D); |
| 702 | void string_value_init(TSRMLS_D); |
| 703 | void struct_init(TSRMLS_D); |
| 704 | void syntax_init(TSRMLS_D); |
| 705 | void timestamp_init(TSRMLS_D); |
| 706 | void type_init(TSRMLS_D); |
| 707 | void uint32_value_init(TSRMLS_D); |
| 708 | void uint64_value_init(TSRMLS_D); |
| 709 | void util_init(TSRMLS_D); |
| 710 | void value_init(TSRMLS_D); |
| 711 | |
| 712 | void gpb_metadata_any_init(TSRMLS_D); |
| 713 | void gpb_metadata_api_init(TSRMLS_D); |
| 714 | void gpb_metadata_duration_init(TSRMLS_D); |
| 715 | void gpb_metadata_field_mask_init(TSRMLS_D); |
| 716 | void gpb_metadata_empty_init(TSRMLS_D); |
| 717 | void gpb_metadata_source_context_init(TSRMLS_D); |
| 718 | void gpb_metadata_struct_init(TSRMLS_D); |
| 719 | void gpb_metadata_timestamp_init(TSRMLS_D); |
| 720 | void gpb_metadata_type_init(TSRMLS_D); |
| 721 | void gpb_metadata_wrappers_init(TSRMLS_D); |
| 722 | |
| 723 | // Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor |
| 724 | // instances. |
| 725 | void add_def_obj(const void* def, PHP_PROTO_HASHTABLE_VALUE value); |
| 726 | PHP_PROTO_HASHTABLE_VALUE get_def_obj(const void* def); |
| 727 | |
| 728 | // Global map from PHP class entries to wrapper Descriptor/EnumDescriptor |
| 729 | // instances. |
| 730 | void add_ce_obj(const void* ce, PHP_PROTO_HASHTABLE_VALUE value); |
| 731 | PHP_PROTO_HASHTABLE_VALUE get_ce_obj(const void* ce); |
| 732 | bool class_added(const void* ce); |
| 733 | |
| 734 | // Global map from message/enum's proto fully-qualified name to corresponding |
| 735 | // wrapper Descriptor/EnumDescriptor instances. |
| 736 | void add_proto_obj(const char* proto, PHP_PROTO_HASHTABLE_VALUE value); |
| 737 | PHP_PROTO_HASHTABLE_VALUE get_proto_obj(const char* proto); |
| 738 | |
| 739 | extern zend_class_entry* map_field_type; |
| 740 | extern zend_class_entry* repeated_field_type; |
| 741 | |
| 742 | // ----------------------------------------------------------------------------- |
| 743 | // Descriptor. |
| 744 | // ----------------------------------------------------------------------------- |
| 745 | |
| 746 | PHP_PROTO_WRAP_OBJECT_START(DescriptorPool) |
| 747 | InternalDescriptorPool* intern; |
| 748 | PHP_PROTO_WRAP_OBJECT_END |
| 749 | |
| 750 | PHP_METHOD(DescriptorPool, getGeneratedPool); |
| 751 | PHP_METHOD(DescriptorPool, getDescriptorByClassName); |
| 752 | PHP_METHOD(DescriptorPool, getEnumDescriptorByClassName); |
| 753 | |
| 754 | PHP_PROTO_WRAP_OBJECT_START(InternalDescriptorPool) |
| 755 | upb_symtab* symtab; |
| 756 | HashTable* pending_list; |
| 757 | PHP_PROTO_WRAP_OBJECT_END |
| 758 | |
| 759 | PHP_METHOD(InternalDescriptorPool, getGeneratedPool); |
| 760 | PHP_METHOD(InternalDescriptorPool, internalAddGeneratedFile); |
| 761 | |
| 762 | void internal_add_generated_file(const char* data, PHP_PROTO_SIZE data_len, |
| 763 | InternalDescriptorPool* pool TSRMLS_DC); |
| 764 | void init_generated_pool_once(TSRMLS_D); |
| 765 | |
| 766 | // wrapper of generated pool |
| 767 | #if PHP_MAJOR_VERSION < 7 |
| 768 | extern zval* generated_pool_php; |
| 769 | extern zval* internal_generated_pool_php; |
| 770 | void descriptor_pool_free(void* object TSRMLS_DC); |
| 771 | void internal_descriptor_pool_free(void* object TSRMLS_DC); |
| 772 | #else |
| 773 | extern zend_object *generated_pool_php; |
| 774 | extern zend_object *internal_generated_pool_php; |
| 775 | void descriptor_pool_free(zend_object* object); |
| 776 | void internal_descriptor_pool_free(zend_object* object); |
| 777 | #endif |
| 778 | extern InternalDescriptorPool* generated_pool; // The actual generated pool |
| 779 | |
| 780 | PHP_PROTO_WRAP_OBJECT_START(Descriptor) |
| 781 | const upb_msgdef* msgdef; |
| 782 | MessageLayout* layout; |
| 783 | zend_class_entry* klass; // begins as NULL |
| 784 | const upb_handlers* fill_handlers; |
| 785 | const upb_pbdecodermethod* fill_method; |
| 786 | const upb_json_parsermethod* json_fill_method; |
| 787 | const upb_handlers* pb_serialize_handlers; |
| 788 | const upb_handlers* json_serialize_handlers; |
| 789 | const upb_handlers* json_serialize_handlers_preserve; |
| 790 | PHP_PROTO_WRAP_OBJECT_END |
| 791 | |
| 792 | PHP_METHOD(Descriptor, getClass); |
| 793 | PHP_METHOD(Descriptor, getFullName); |
| 794 | PHP_METHOD(Descriptor, getField); |
| 795 | PHP_METHOD(Descriptor, getFieldCount); |
| 796 | PHP_METHOD(Descriptor, getOneofDecl); |
| 797 | PHP_METHOD(Descriptor, getOneofDeclCount); |
| 798 | |
| 799 | extern zend_class_entry* descriptor_type; |
| 800 | |
| 801 | void descriptor_name_set(Descriptor *desc, const char *name); |
| 802 | |
| 803 | PHP_PROTO_WRAP_OBJECT_START(FieldDescriptor) |
| 804 | const upb_fielddef* fielddef; |
| 805 | PHP_PROTO_WRAP_OBJECT_END |
| 806 | |
| 807 | PHP_METHOD(FieldDescriptor, getName); |
| 808 | PHP_METHOD(FieldDescriptor, getNumber); |
| 809 | PHP_METHOD(FieldDescriptor, getLabel); |
| 810 | PHP_METHOD(FieldDescriptor, getType); |
| 811 | PHP_METHOD(FieldDescriptor, isMap); |
| 812 | PHP_METHOD(FieldDescriptor, getEnumType); |
| 813 | PHP_METHOD(FieldDescriptor, getMessageType); |
| 814 | |
| 815 | extern zend_class_entry* field_descriptor_type; |
| 816 | |
| 817 | PHP_PROTO_WRAP_OBJECT_START(EnumDescriptor) |
| 818 | const upb_enumdef* enumdef; |
| 819 | zend_class_entry* klass; // begins as NULL |
| 820 | PHP_PROTO_WRAP_OBJECT_END |
| 821 | |
| 822 | PHP_METHOD(EnumDescriptor, getValue); |
| 823 | PHP_METHOD(EnumDescriptor, getValueCount); |
| 824 | |
| 825 | extern zend_class_entry* enum_descriptor_type; |
| 826 | |
| 827 | PHP_PROTO_WRAP_OBJECT_START(EnumValueDescriptor) |
| 828 | const char* name; |
| 829 | int32_t number; |
| 830 | PHP_PROTO_WRAP_OBJECT_END |
| 831 | |
| 832 | PHP_METHOD(EnumValueDescriptor, getName); |
| 833 | PHP_METHOD(EnumValueDescriptor, getNumber); |
| 834 | |
| 835 | extern zend_class_entry* enum_value_descriptor_type; |
| 836 | |
| 837 | // ----------------------------------------------------------------------------- |
| 838 | // Message class creation. |
| 839 | // ----------------------------------------------------------------------------- |
| 840 | |
| 841 | void* message_data(MessageHeader* msg); |
| 842 | void custom_data_init(const zend_class_entry* ce, |
| 843 | MessageHeader* msg PHP_PROTO_TSRMLS_DC); |
| 844 | |
| 845 | // Build PHP class for given descriptor. Instead of building from scratch, this |
| 846 | // function modifies existing class which has been partially defined in PHP |
| 847 | // code. |
| 848 | void build_class_from_descriptor( |
| 849 | PHP_PROTO_HASHTABLE_VALUE php_descriptor TSRMLS_DC); |
| 850 | |
| 851 | extern zend_class_entry* message_type; |
| 852 | extern zend_object_handlers* message_handlers; |
| 853 | |
| 854 | // ----------------------------------------------------------------------------- |
| 855 | // Message layout / storage. |
| 856 | // ----------------------------------------------------------------------------- |
| 857 | |
| 858 | /* |
| 859 | * In c extension, each protobuf message is a zval instance. The zval instance |
| 860 | * is like union, which can be used to store int, string, zend_object_value and |
| 861 | * etc. For protobuf message, the zval instance is used to store the |
| 862 | * zend_object_value. |
| 863 | * |
| 864 | * The zend_object_value is composed of handlers and a handle to look up the |
| 865 | * actual stored data. The handlers are pointers to functions, e.g., read, |
| 866 | * write, and etc, to access properties. |
| 867 | * |
| 868 | * The actual data of protobuf messages is stored as MessageHeader in zend |
| 869 | * engine's central repository. Each MessageHeader instance is composed of a |
| 870 | * zend_object, a Descriptor instance and the real message data. |
| 871 | * |
| 872 | * For the reason that PHP's native types may not be large enough to store |
| 873 | * protobuf message's field (e.g., int64), all message's data is stored in |
| 874 | * custom memory layout and is indexed by the Descriptor instance. |
| 875 | * |
| 876 | * The zend_object contains the zend class entry and the properties table. The |
| 877 | * zend class entry contains all information about protobuf message's |
| 878 | * corresponding PHP class. The most useful information is the offset table of |
| 879 | * properties. Because read access to properties requires returning zval |
| 880 | * instance, we need to convert data from the custom layout to zval instance. |
| 881 | * Instead of creating zval instance for every read access, we use the zval |
| 882 | * instances in the properties table in the zend_object as cache. When |
| 883 | * accessing properties, the offset is needed to find the zval property in |
| 884 | * zend_object's properties table. These properties will be updated using the |
| 885 | * data from custom memory layout only when reading these properties. |
| 886 | * |
| 887 | * zval |
| 888 | * |-zend_object_value obj |
| 889 | * |-zend_object_handlers* handlers -> |-read_property_handler |
| 890 | * | |-write_property_handler |
| 891 | * | ++++++++++++++++++++++ |
| 892 | * |-zend_object_handle handle -> + central repository + |
| 893 | * ++++++++++++++++++++++ |
| 894 | * MessageHeader <-----------------| |
| 895 | * |-zend_object std |
| 896 | * | |-class_entry* ce -> class_entry |
| 897 | * | | |-HashTable properties_table (name->offset) |
| 898 | * | |-zval** properties_table <------------------------------| |
| 899 | * | |------> zval* property(cache) |
| 900 | * |-Descriptor* desc (name->offset) |
| 901 | * |-void** data <-----------| |
| 902 | * |-----------------------> void* property(data) |
| 903 | * |
| 904 | */ |
| 905 | |
| 906 | #define MESSAGE_FIELD_NO_CASE ((size_t)-1) |
| 907 | |
| 908 | struct MessageField { |
| 909 | size_t offset; |
| 910 | int cache_index; // Each field except oneof field has a zval cache to avoid |
| 911 | // multiple creation when being accessed. |
| 912 | size_t case_offset; // for oneofs, a uint32. Else, MESSAGE_FIELD_NO_CASE. |
| 913 | }; |
| 914 | |
| 915 | struct MessageLayout { |
| 916 | const upb_msgdef* msgdef; |
| 917 | MessageField* fields; |
| 918 | size_t size; |
| 919 | }; |
| 920 | |
| 921 | PHP_PROTO_WRAP_OBJECT_START(MessageHeader) |
| 922 | void* data; // Point to the real message data. |
| 923 | // Place needs to be consistent with map_parse_frame_data_t. |
| 924 | Descriptor* descriptor; // Kept alive by self.class.descriptor reference. |
| 925 | PHP_PROTO_WRAP_OBJECT_END |
| 926 | |
| 927 | MessageLayout* create_layout(const upb_msgdef* msgdef); |
| 928 | void layout_init(MessageLayout* layout, void* storage, |
| 929 | zend_object* object PHP_PROTO_TSRMLS_DC); |
| 930 | zval* layout_get(MessageLayout* layout, const void* storage, |
| 931 | const upb_fielddef* field, CACHED_VALUE* cache TSRMLS_DC); |
| 932 | void layout_set(MessageLayout* layout, MessageHeader* header, |
| 933 | const upb_fielddef* field, zval* val TSRMLS_DC); |
| 934 | void layout_merge(MessageLayout* layout, MessageHeader* from, |
| 935 | MessageHeader* to TSRMLS_DC); |
| 936 | const char* layout_get_oneof_case(MessageLayout* layout, const void* storage, |
| 937 | const upb_oneofdef* oneof TSRMLS_DC); |
| 938 | void free_layout(MessageLayout* layout); |
| 939 | void* slot_memory(MessageLayout* layout, const void* storage, |
| 940 | const upb_fielddef* field); |
| 941 | |
| 942 | PHP_METHOD(Message, clear); |
| 943 | PHP_METHOD(Message, mergeFrom); |
| 944 | PHP_METHOD(Message, readOneof); |
| 945 | PHP_METHOD(Message, writeOneof); |
| 946 | PHP_METHOD(Message, whichOneof); |
| 947 | PHP_METHOD(Message, __construct); |
| 948 | |
| 949 | // ----------------------------------------------------------------------------- |
| 950 | // Encode / Decode. |
| 951 | // ----------------------------------------------------------------------------- |
| 952 | |
| 953 | // Maximum depth allowed during encoding, to avoid stack overflows due to |
| 954 | // cycles. |
| 955 | #define ENCODE_MAX_NESTING 63 |
| 956 | |
| 957 | // Constructs the upb decoder method for parsing messages of this type. |
| 958 | // This is called from the message class creation code. |
| 959 | const upb_pbdecodermethod *new_fillmsg_decodermethod(Descriptor *desc, |
| 960 | const void *owner); |
| 961 | void serialize_to_string(zval* val, zval* return_value TSRMLS_DC); |
| 962 | void merge_from_string(const char* data, int data_len, const Descriptor* desc, |
| 963 | MessageHeader* msg); |
| 964 | |
| 965 | PHP_METHOD(Message, serializeToString); |
| 966 | PHP_METHOD(Message, mergeFromString); |
| 967 | PHP_METHOD(Message, serializeToJsonString); |
| 968 | PHP_METHOD(Message, mergeFromJsonString); |
| 969 | PHP_METHOD(Message, discardUnknownFields); |
| 970 | |
| 971 | // ----------------------------------------------------------------------------- |
| 972 | // Type check / conversion. |
| 973 | // ----------------------------------------------------------------------------- |
| 974 | |
| 975 | bool protobuf_convert_to_int32(zval* from, int32_t* to); |
| 976 | bool protobuf_convert_to_uint32(zval* from, uint32_t* to); |
| 977 | bool protobuf_convert_to_int64(zval* from, int64_t* to); |
| 978 | bool protobuf_convert_to_uint64(zval* from, uint64_t* to); |
| 979 | bool protobuf_convert_to_float(zval* from, float* to); |
| 980 | bool protobuf_convert_to_double(zval* from, double* to); |
| 981 | bool protobuf_convert_to_bool(zval* from, int8_t* to); |
| 982 | bool protobuf_convert_to_string(zval* from); |
| 983 | |
| 984 | void check_repeated_field(const zend_class_entry* klass, PHP_PROTO_LONG type, |
| 985 | zval* val, zval* return_value); |
| 986 | void check_map_field(const zend_class_entry* klass, PHP_PROTO_LONG key_type, |
| 987 | PHP_PROTO_LONG value_type, zval* val, zval* return_value); |
| 988 | |
| 989 | PHP_METHOD(Util, checkInt32); |
| 990 | PHP_METHOD(Util, checkUint32); |
| 991 | PHP_METHOD(Util, checkInt64); |
| 992 | PHP_METHOD(Util, checkUint64); |
| 993 | PHP_METHOD(Util, checkEnum); |
| 994 | PHP_METHOD(Util, checkFloat); |
| 995 | PHP_METHOD(Util, checkDouble); |
| 996 | PHP_METHOD(Util, checkBool); |
| 997 | PHP_METHOD(Util, checkString); |
| 998 | PHP_METHOD(Util, checkBytes); |
| 999 | PHP_METHOD(Util, checkMessage); |
| 1000 | PHP_METHOD(Util, checkMapField); |
| 1001 | PHP_METHOD(Util, checkRepeatedField); |
| 1002 | |
| 1003 | // ----------------------------------------------------------------------------- |
| 1004 | // Native slot storage abstraction. |
| 1005 | // ----------------------------------------------------------------------------- |
| 1006 | |
| 1007 | #define NATIVE_SLOT_MAX_SIZE sizeof(uint64_t) |
| 1008 | |
| 1009 | size_t native_slot_size(upb_fieldtype_t type); |
| 1010 | bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass, |
| 1011 | void* memory, zval* value TSRMLS_DC); |
| 1012 | // String/Message is stored differently in array/map from normal message fields. |
| 1013 | // So we need to make a special method to handle that. |
| 1014 | bool native_slot_set_by_array(upb_fieldtype_t type, |
| 1015 | const zend_class_entry* klass, void* memory, |
| 1016 | zval* value TSRMLS_DC); |
| 1017 | bool native_slot_set_by_map(upb_fieldtype_t type, const zend_class_entry* klass, |
| 1018 | void* memory, zval* value TSRMLS_DC); |
| 1019 | void native_slot_init(upb_fieldtype_t type, void* memory, CACHED_VALUE* cache); |
| 1020 | // For each property, in order to avoid conversion between the zval object and |
| 1021 | // the actual data type during parsing/serialization, the containing message |
| 1022 | // object use the custom memory layout to store the actual data type for each |
| 1023 | // property inside of it. To access a property from php code, the property |
| 1024 | // needs to be converted to a zval object. The message object is not responsible |
| 1025 | // for providing such a zval object. Instead the caller needs to provide one |
| 1026 | // (cache) and update it with the actual data (memory). |
| 1027 | void native_slot_get(upb_fieldtype_t type, const void* memory, |
| 1028 | CACHED_VALUE* cache TSRMLS_DC); |
| 1029 | // String/Message is stored differently in array/map from normal message fields. |
| 1030 | // So we need to make a special method to handle that. |
| 1031 | void native_slot_get_by_array(upb_fieldtype_t type, const void* memory, |
| 1032 | CACHED_VALUE* cache TSRMLS_DC); |
| 1033 | void native_slot_get_by_map_key(upb_fieldtype_t type, const void* memory, |
| 1034 | int length, CACHED_VALUE* cache TSRMLS_DC); |
| 1035 | void native_slot_get_by_map_value(upb_fieldtype_t type, const void* memory, |
| 1036 | CACHED_VALUE* cache TSRMLS_DC); |
| 1037 | void native_slot_get_default(upb_fieldtype_t type, |
| 1038 | CACHED_VALUE* cache TSRMLS_DC); |
| 1039 | |
| 1040 | // ----------------------------------------------------------------------------- |
| 1041 | // Map Field. |
| 1042 | // ----------------------------------------------------------------------------- |
| 1043 | |
| 1044 | extern zend_object_handlers* map_field_handlers; |
| 1045 | extern zend_object_handlers* map_field_iter_handlers; |
| 1046 | |
| 1047 | PHP_PROTO_WRAP_OBJECT_START(Map) |
| 1048 | upb_fieldtype_t key_type; |
| 1049 | upb_fieldtype_t value_type; |
| 1050 | const zend_class_entry* msg_ce; // class entry for value message |
| 1051 | upb_strtable table; |
| 1052 | PHP_PROTO_WRAP_OBJECT_END |
| 1053 | |
| 1054 | PHP_PROTO_WRAP_OBJECT_START(MapIter) |
| 1055 | Map* self; |
| 1056 | upb_strtable_iter it; |
| 1057 | PHP_PROTO_WRAP_OBJECT_END |
| 1058 | |
| 1059 | void map_begin(zval* self, MapIter* iter TSRMLS_DC); |
| 1060 | void map_next(MapIter* iter); |
| 1061 | bool map_done(MapIter* iter); |
| 1062 | const char* map_iter_key(MapIter* iter, int* len); |
| 1063 | upb_value map_iter_value(MapIter* iter, int* len); |
| 1064 | |
| 1065 | // These operate on a map-entry msgdef. |
| 1066 | const upb_fielddef* map_entry_key(const upb_msgdef* msgdef); |
| 1067 | const upb_fielddef* map_entry_value(const upb_msgdef* msgdef); |
| 1068 | |
| 1069 | void map_field_create_with_field(const zend_class_entry* ce, |
| 1070 | const upb_fielddef* field, |
| 1071 | CACHED_VALUE* map_field PHP_PROTO_TSRMLS_DC); |
| 1072 | void map_field_create_with_type(const zend_class_entry* ce, |
| 1073 | upb_fieldtype_t key_type, |
| 1074 | upb_fieldtype_t value_type, |
| 1075 | const zend_class_entry* msg_ce, |
| 1076 | CACHED_VALUE* map_field PHP_PROTO_TSRMLS_DC); |
| 1077 | void* upb_value_memory(upb_value* v); |
| 1078 | |
| 1079 | #define MAP_KEY_FIELD 1 |
| 1080 | #define MAP_VALUE_FIELD 2 |
| 1081 | |
| 1082 | // These operate on a map field (i.e., a repeated field of submessages whose |
| 1083 | // submessage type is a map-entry msgdef). |
| 1084 | bool is_map_field(const upb_fielddef* field); |
| 1085 | const upb_fielddef* map_field_key(const upb_fielddef* field); |
| 1086 | const upb_fielddef* map_field_value(const upb_fielddef* field); |
| 1087 | |
| 1088 | bool map_index_set(Map *intern, const char* keyval, int length, upb_value v); |
| 1089 | |
| 1090 | PHP_METHOD(MapField, __construct); |
| 1091 | PHP_METHOD(MapField, offsetExists); |
| 1092 | PHP_METHOD(MapField, offsetGet); |
| 1093 | PHP_METHOD(MapField, offsetSet); |
| 1094 | PHP_METHOD(MapField, offsetUnset); |
| 1095 | PHP_METHOD(MapField, count); |
| 1096 | PHP_METHOD(MapField, getIterator); |
| 1097 | |
| 1098 | PHP_METHOD(MapFieldIter, rewind); |
| 1099 | PHP_METHOD(MapFieldIter, current); |
| 1100 | PHP_METHOD(MapFieldIter, key); |
| 1101 | PHP_METHOD(MapFieldIter, next); |
| 1102 | PHP_METHOD(MapFieldIter, valid); |
| 1103 | |
| 1104 | // ----------------------------------------------------------------------------- |
| 1105 | // Repeated Field. |
| 1106 | // ----------------------------------------------------------------------------- |
| 1107 | |
| 1108 | extern zend_object_handlers* repeated_field_handlers; |
| 1109 | extern zend_object_handlers* repeated_field_iter_handlers; |
| 1110 | |
| 1111 | PHP_PROTO_WRAP_OBJECT_START(RepeatedField) |
| 1112 | #if PHP_MAJOR_VERSION < 7 |
| 1113 | zval* array; |
| 1114 | #else |
| 1115 | zval array; |
| 1116 | #endif |
| 1117 | upb_fieldtype_t type; |
| 1118 | const zend_class_entry* msg_ce; // class entry for containing message |
| 1119 | // (for message field only). |
| 1120 | PHP_PROTO_WRAP_OBJECT_END |
| 1121 | |
| 1122 | PHP_PROTO_WRAP_OBJECT_START(RepeatedFieldIter) |
| 1123 | RepeatedField* repeated_field; |
| 1124 | long position; |
| 1125 | PHP_PROTO_WRAP_OBJECT_END |
| 1126 | |
| 1127 | void repeated_field_create_with_field( |
| 1128 | zend_class_entry* ce, const upb_fielddef* field, |
| 1129 | CACHED_VALUE* repeated_field PHP_PROTO_TSRMLS_DC); |
| 1130 | void repeated_field_create_with_type( |
| 1131 | zend_class_entry* ce, upb_fieldtype_t type, const zend_class_entry* msg_ce, |
| 1132 | CACHED_VALUE* repeated_field PHP_PROTO_TSRMLS_DC); |
| 1133 | // Return the element at the index position from the repeated field. There is |
| 1134 | // not restriction on the type of stored elements. |
| 1135 | void *repeated_field_index_native(RepeatedField *intern, int index TSRMLS_DC); |
| 1136 | // Add the element to the end of the repeated field. There is not restriction on |
| 1137 | // the type of stored elements. |
| 1138 | void repeated_field_push_native(RepeatedField *intern, void *value); |
| 1139 | |
| 1140 | PHP_METHOD(RepeatedField, __construct); |
| 1141 | PHP_METHOD(RepeatedField, append); |
| 1142 | PHP_METHOD(RepeatedField, offsetExists); |
| 1143 | PHP_METHOD(RepeatedField, offsetGet); |
| 1144 | PHP_METHOD(RepeatedField, offsetSet); |
| 1145 | PHP_METHOD(RepeatedField, offsetUnset); |
| 1146 | PHP_METHOD(RepeatedField, count); |
| 1147 | PHP_METHOD(RepeatedField, getIterator); |
| 1148 | |
| 1149 | PHP_METHOD(RepeatedFieldIter, rewind); |
| 1150 | PHP_METHOD(RepeatedFieldIter, current); |
| 1151 | PHP_METHOD(RepeatedFieldIter, key); |
| 1152 | PHP_METHOD(RepeatedFieldIter, next); |
| 1153 | PHP_METHOD(RepeatedFieldIter, valid); |
| 1154 | |
| 1155 | // ----------------------------------------------------------------------------- |
| 1156 | // Oneof Field. |
| 1157 | // ----------------------------------------------------------------------------- |
| 1158 | |
| 1159 | PHP_PROTO_WRAP_OBJECT_START(Oneof) |
| 1160 | upb_oneofdef* oneofdef; |
| 1161 | int index; // Index of field in oneof. -1 if not set. |
| 1162 | char value[NATIVE_SLOT_MAX_SIZE]; |
| 1163 | PHP_PROTO_WRAP_OBJECT_END |
| 1164 | |
| 1165 | PHP_METHOD(Oneof, getName); |
| 1166 | PHP_METHOD(Oneof, getField); |
| 1167 | PHP_METHOD(Oneof, getFieldCount); |
| 1168 | |
| 1169 | extern zend_class_entry* oneof_descriptor_type; |
| 1170 | |
| 1171 | // Oneof case slot value to indicate that no oneof case is set. The value `0` is |
| 1172 | // safe because field numbers are used as case identifiers, and no field can |
| 1173 | // have a number of 0. |
| 1174 | #define ONEOF_CASE_NONE 0 |
| 1175 | |
| 1176 | // ----------------------------------------------------------------------------- |
| 1177 | // Well Known Type. |
| 1178 | // ----------------------------------------------------------------------------- |
| 1179 | |
| 1180 | extern bool is_inited_file_any; |
| 1181 | extern bool is_inited_file_api; |
| 1182 | extern bool is_inited_file_duration; |
| 1183 | extern bool is_inited_file_field_mask; |
| 1184 | extern bool is_inited_file_empty; |
| 1185 | extern bool is_inited_file_source_context; |
| 1186 | extern bool is_inited_file_struct; |
| 1187 | extern bool is_inited_file_timestamp; |
| 1188 | extern bool is_inited_file_type; |
| 1189 | extern bool is_inited_file_wrappers; |
| 1190 | |
| 1191 | PHP_METHOD(GPBMetadata_Any, initOnce); |
| 1192 | PHP_METHOD(GPBMetadata_Api, initOnce); |
| 1193 | PHP_METHOD(GPBMetadata_Duration, initOnce); |
| 1194 | PHP_METHOD(GPBMetadata_FieldMask, initOnce); |
| 1195 | PHP_METHOD(GPBMetadata_Empty, initOnce); |
| 1196 | PHP_METHOD(GPBMetadata_SourceContext, initOnce); |
| 1197 | PHP_METHOD(GPBMetadata_Struct, initOnce); |
| 1198 | PHP_METHOD(GPBMetadata_Timestamp, initOnce); |
| 1199 | PHP_METHOD(GPBMetadata_Type, initOnce); |
| 1200 | PHP_METHOD(GPBMetadata_Wrappers, initOnce); |
| 1201 | |
| 1202 | PHP_METHOD(Any, __construct); |
| 1203 | PHP_METHOD(Any, getTypeUrl); |
| 1204 | PHP_METHOD(Any, setTypeUrl); |
| 1205 | PHP_METHOD(Any, getValue); |
| 1206 | PHP_METHOD(Any, setValue); |
| 1207 | PHP_METHOD(Any, unpack); |
| 1208 | PHP_METHOD(Any, pack); |
| 1209 | PHP_METHOD(Any, is); |
| 1210 | |
| 1211 | PHP_METHOD(Duration, __construct); |
| 1212 | PHP_METHOD(Duration, getSeconds); |
| 1213 | PHP_METHOD(Duration, setSeconds); |
| 1214 | PHP_METHOD(Duration, getNanos); |
| 1215 | PHP_METHOD(Duration, setNanos); |
| 1216 | |
| 1217 | PHP_METHOD(Timestamp, __construct); |
| 1218 | PHP_METHOD(Timestamp, fromDateTime); |
| 1219 | PHP_METHOD(Timestamp, toDateTime); |
| 1220 | PHP_METHOD(Timestamp, getSeconds); |
| 1221 | PHP_METHOD(Timestamp, setSeconds); |
| 1222 | PHP_METHOD(Timestamp, getNanos); |
| 1223 | PHP_METHOD(Timestamp, setNanos); |
| 1224 | |
| 1225 | PHP_METHOD(Api, __construct); |
| 1226 | PHP_METHOD(Api, getName); |
| 1227 | PHP_METHOD(Api, setName); |
| 1228 | PHP_METHOD(Api, getMethods); |
| 1229 | PHP_METHOD(Api, setMethods); |
| 1230 | PHP_METHOD(Api, getOptions); |
| 1231 | PHP_METHOD(Api, setOptions); |
| 1232 | PHP_METHOD(Api, getVersion); |
| 1233 | PHP_METHOD(Api, setVersion); |
| 1234 | PHP_METHOD(Api, getSourceContext); |
| 1235 | PHP_METHOD(Api, setSourceContext); |
| 1236 | PHP_METHOD(Api, getMixins); |
| 1237 | PHP_METHOD(Api, setMixins); |
| 1238 | PHP_METHOD(Api, getSyntax); |
| 1239 | PHP_METHOD(Api, setSyntax); |
| 1240 | |
| 1241 | PHP_METHOD(BoolValue, __construct); |
| 1242 | PHP_METHOD(BoolValue, getValue); |
| 1243 | PHP_METHOD(BoolValue, setValue); |
| 1244 | |
| 1245 | PHP_METHOD(BytesValue, __construct); |
| 1246 | PHP_METHOD(BytesValue, getValue); |
| 1247 | PHP_METHOD(BytesValue, setValue); |
| 1248 | |
| 1249 | PHP_METHOD(DoubleValue, __construct); |
| 1250 | PHP_METHOD(DoubleValue, getValue); |
| 1251 | PHP_METHOD(DoubleValue, setValue); |
| 1252 | |
| 1253 | PHP_METHOD(Enum, __construct); |
| 1254 | PHP_METHOD(Enum, getName); |
| 1255 | PHP_METHOD(Enum, setName); |
| 1256 | PHP_METHOD(Enum, getEnumvalue); |
| 1257 | PHP_METHOD(Enum, setEnumvalue); |
| 1258 | PHP_METHOD(Enum, getOptions); |
| 1259 | PHP_METHOD(Enum, setOptions); |
| 1260 | PHP_METHOD(Enum, getSourceContext); |
| 1261 | PHP_METHOD(Enum, setSourceContext); |
| 1262 | PHP_METHOD(Enum, getSyntax); |
| 1263 | PHP_METHOD(Enum, setSyntax); |
| 1264 | |
| 1265 | PHP_METHOD(EnumValue, __construct); |
| 1266 | PHP_METHOD(EnumValue, getName); |
| 1267 | PHP_METHOD(EnumValue, setName); |
| 1268 | PHP_METHOD(EnumValue, getNumber); |
| 1269 | PHP_METHOD(EnumValue, setNumber); |
| 1270 | PHP_METHOD(EnumValue, getOptions); |
| 1271 | PHP_METHOD(EnumValue, setOptions); |
| 1272 | |
| 1273 | PHP_METHOD(FieldMask, __construct); |
| 1274 | PHP_METHOD(FieldMask, getPaths); |
| 1275 | PHP_METHOD(FieldMask, setPaths); |
| 1276 | |
| 1277 | PHP_METHOD(Field, __construct); |
| 1278 | PHP_METHOD(Field, getKind); |
| 1279 | PHP_METHOD(Field, setKind); |
| 1280 | PHP_METHOD(Field, getCardinality); |
| 1281 | PHP_METHOD(Field, setCardinality); |
| 1282 | PHP_METHOD(Field, getNumber); |
| 1283 | PHP_METHOD(Field, setNumber); |
| 1284 | PHP_METHOD(Field, getName); |
| 1285 | PHP_METHOD(Field, setName); |
| 1286 | PHP_METHOD(Field, getTypeUrl); |
| 1287 | PHP_METHOD(Field, setTypeUrl); |
| 1288 | PHP_METHOD(Field, getOneofIndex); |
| 1289 | PHP_METHOD(Field, setOneofIndex); |
| 1290 | PHP_METHOD(Field, getPacked); |
| 1291 | PHP_METHOD(Field, setPacked); |
| 1292 | PHP_METHOD(Field, getOptions); |
| 1293 | PHP_METHOD(Field, setOptions); |
| 1294 | PHP_METHOD(Field, getJsonName); |
| 1295 | PHP_METHOD(Field, setJsonName); |
| 1296 | PHP_METHOD(Field, getDefaultValue); |
| 1297 | PHP_METHOD(Field, setDefaultValue); |
| 1298 | |
| 1299 | PHP_METHOD(FloatValue, __construct); |
| 1300 | PHP_METHOD(FloatValue, getValue); |
| 1301 | PHP_METHOD(FloatValue, setValue); |
| 1302 | |
| 1303 | PHP_METHOD(GPBEmpty, __construct); |
| 1304 | |
| 1305 | PHP_METHOD(Int32Value, __construct); |
| 1306 | PHP_METHOD(Int32Value, getValue); |
| 1307 | PHP_METHOD(Int32Value, setValue); |
| 1308 | |
| 1309 | PHP_METHOD(Int64Value, __construct); |
| 1310 | PHP_METHOD(Int64Value, getValue); |
| 1311 | PHP_METHOD(Int64Value, setValue); |
| 1312 | |
| 1313 | PHP_METHOD(ListValue, __construct); |
| 1314 | PHP_METHOD(ListValue, getValues); |
| 1315 | PHP_METHOD(ListValue, setValues); |
| 1316 | |
| 1317 | PHP_METHOD(Method, __construct); |
| 1318 | PHP_METHOD(Method, getName); |
| 1319 | PHP_METHOD(Method, setName); |
| 1320 | PHP_METHOD(Method, getRequestTypeUrl); |
| 1321 | PHP_METHOD(Method, setRequestTypeUrl); |
| 1322 | PHP_METHOD(Method, getRequestStreaming); |
| 1323 | PHP_METHOD(Method, setRequestStreaming); |
| 1324 | PHP_METHOD(Method, getResponseTypeUrl); |
| 1325 | PHP_METHOD(Method, setResponseTypeUrl); |
| 1326 | PHP_METHOD(Method, getResponseStreaming); |
| 1327 | PHP_METHOD(Method, setResponseStreaming); |
| 1328 | PHP_METHOD(Method, getOptions); |
| 1329 | PHP_METHOD(Method, setOptions); |
| 1330 | PHP_METHOD(Method, getSyntax); |
| 1331 | PHP_METHOD(Method, setSyntax); |
| 1332 | |
| 1333 | PHP_METHOD(Mixin, __construct); |
| 1334 | PHP_METHOD(Mixin, getName); |
| 1335 | PHP_METHOD(Mixin, setName); |
| 1336 | PHP_METHOD(Mixin, getRoot); |
| 1337 | PHP_METHOD(Mixin, setRoot); |
| 1338 | |
| 1339 | PHP_METHOD(Option, __construct); |
| 1340 | PHP_METHOD(Option, getName); |
| 1341 | PHP_METHOD(Option, setName); |
| 1342 | PHP_METHOD(Option, getValue); |
| 1343 | PHP_METHOD(Option, setValue); |
| 1344 | |
| 1345 | PHP_METHOD(SourceContext, __construct); |
| 1346 | PHP_METHOD(SourceContext, getFileName); |
| 1347 | PHP_METHOD(SourceContext, setFileName); |
| 1348 | |
| 1349 | PHP_METHOD(StringValue, __construct); |
| 1350 | PHP_METHOD(StringValue, getValue); |
| 1351 | PHP_METHOD(StringValue, setValue); |
| 1352 | |
| 1353 | PHP_METHOD(Struct, __construct); |
| 1354 | PHP_METHOD(Struct, getFields); |
| 1355 | PHP_METHOD(Struct, setFields); |
| 1356 | |
| 1357 | PHP_METHOD(Type, __construct); |
| 1358 | PHP_METHOD(Type, getName); |
| 1359 | PHP_METHOD(Type, setName); |
| 1360 | PHP_METHOD(Type, getFields); |
| 1361 | PHP_METHOD(Type, setFields); |
| 1362 | PHP_METHOD(Type, getOneofs); |
| 1363 | PHP_METHOD(Type, setOneofs); |
| 1364 | PHP_METHOD(Type, getOptions); |
| 1365 | PHP_METHOD(Type, setOptions); |
| 1366 | PHP_METHOD(Type, getSourceContext); |
| 1367 | PHP_METHOD(Type, setSourceContext); |
| 1368 | PHP_METHOD(Type, getSyntax); |
| 1369 | PHP_METHOD(Type, setSyntax); |
| 1370 | |
| 1371 | PHP_METHOD(UInt32Value, __construct); |
| 1372 | PHP_METHOD(UInt32Value, getValue); |
| 1373 | PHP_METHOD(UInt32Value, setValue); |
| 1374 | |
| 1375 | PHP_METHOD(UInt64Value, __construct); |
| 1376 | PHP_METHOD(UInt64Value, getValue); |
| 1377 | PHP_METHOD(UInt64Value, setValue); |
| 1378 | |
| 1379 | PHP_METHOD(Value, __construct); |
| 1380 | PHP_METHOD(Value, getNullValue); |
| 1381 | PHP_METHOD(Value, setNullValue); |
| 1382 | PHP_METHOD(Value, getNumberValue); |
| 1383 | PHP_METHOD(Value, setNumberValue); |
| 1384 | PHP_METHOD(Value, getStringValue); |
| 1385 | PHP_METHOD(Value, setStringValue); |
| 1386 | PHP_METHOD(Value, getBoolValue); |
| 1387 | PHP_METHOD(Value, setBoolValue); |
| 1388 | PHP_METHOD(Value, getStructValue); |
| 1389 | PHP_METHOD(Value, setStructValue); |
| 1390 | PHP_METHOD(Value, getListValue); |
| 1391 | PHP_METHOD(Value, setListValue); |
| 1392 | PHP_METHOD(Value, getKind); |
| 1393 | |
| 1394 | extern zend_class_entry* any_type; |
| 1395 | extern zend_class_entry* api_type; |
| 1396 | extern zend_class_entry* bool_value_type; |
| 1397 | extern zend_class_entry* bytes_value_type; |
| 1398 | extern zend_class_entry* double_value_type; |
| 1399 | extern zend_class_entry* duration_type; |
| 1400 | extern zend_class_entry* empty_type; |
| 1401 | extern zend_class_entry* enum_type; |
| 1402 | extern zend_class_entry* enum_value_type; |
| 1403 | extern zend_class_entry* field_cardinality_type; |
| 1404 | extern zend_class_entry* field_kind_type; |
| 1405 | extern zend_class_entry* field_mask_type; |
| 1406 | extern zend_class_entry* field_type; |
| 1407 | extern zend_class_entry* float_value_type; |
| 1408 | extern zend_class_entry* int32_value_type; |
| 1409 | extern zend_class_entry* int64_value_type; |
| 1410 | extern zend_class_entry* list_value_type; |
| 1411 | extern zend_class_entry* method_type; |
| 1412 | extern zend_class_entry* mixin_type; |
| 1413 | extern zend_class_entry* null_value_type; |
| 1414 | extern zend_class_entry* option_type; |
| 1415 | extern zend_class_entry* source_context_type; |
| 1416 | extern zend_class_entry* string_value_type; |
| 1417 | extern zend_class_entry* struct_type; |
| 1418 | extern zend_class_entry* syntax_type; |
| 1419 | extern zend_class_entry* timestamp_type; |
| 1420 | extern zend_class_entry* type_type; |
| 1421 | extern zend_class_entry* uint32_value_type; |
| 1422 | extern zend_class_entry* uint64_value_type; |
| 1423 | extern zend_class_entry* value_type; |
| 1424 | |
| 1425 | // ----------------------------------------------------------------------------- |
| 1426 | // Upb. |
| 1427 | // ----------------------------------------------------------------------------- |
| 1428 | |
| 1429 | upb_fieldtype_t to_fieldtype(upb_descriptortype_t type); |
| 1430 | const zend_class_entry* field_type_class( |
| 1431 | const upb_fielddef* field PHP_PROTO_TSRMLS_DC); |
| 1432 | |
| 1433 | // ----------------------------------------------------------------------------- |
| 1434 | // Utilities. |
| 1435 | // ----------------------------------------------------------------------------- |
| 1436 | |
| 1437 | // Memory management |
| 1438 | #define ALLOC(class_name) (class_name*) emalloc(sizeof(class_name)) |
| 1439 | #define PEMALLOC(class_name) (class_name*) pemalloc(sizeof(class_name), 1) |
| 1440 | #define ALLOC_N(class_name, n) (class_name*) emalloc(sizeof(class_name) * n) |
| 1441 | #define FREE(object) efree(object) |
| 1442 | #define PEFREE(object) pefree(object, 1) |
| 1443 | |
| 1444 | // String argument. |
| 1445 | #define STR(str) (str), strlen(str) |
| 1446 | |
| 1447 | // Zend Value |
| 1448 | #if PHP_MAJOR_VERSION < 7 |
| 1449 | #define Z_OBJ_P(zval_p) \ |
| 1450 | ((zend_object*)(EG(objects_store) \ |
| 1451 | .object_buckets[Z_OBJ_HANDLE_P(zval_p)] \ |
| 1452 | .bucket.obj.object)) |
| 1453 | #endif |
| 1454 | |
| 1455 | // Message handler |
| 1456 | static inline zval* php_proto_message_read_property( |
| 1457 | zval* msg, zval* member PHP_PROTO_TSRMLS_DC) { |
| 1458 | #if PHP_MAJOR_VERSION < 7 |
| 1459 | return message_handlers->read_property(msg, member, BP_VAR_R, |
| 1460 | NULL PHP_PROTO_TSRMLS_CC); |
| 1461 | #else |
| 1462 | return message_handlers->read_property(msg, member, BP_VAR_R, NULL, |
| 1463 | NULL PHP_PROTO_TSRMLS_CC); |
| 1464 | #endif |
| 1465 | } |
| 1466 | |
| 1467 | // Reserved name |
| 1468 | bool is_reserved_name(const char* name); |
| 1469 | bool is_valid_constant_name(const char* name); |
| 1470 | |
| 1471 | #endif // __GOOGLE_PROTOBUF_PHP_PROTOBUF_H__ |