array.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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. #include "array.h"
  31. #include <Zend/zend_API.h>
  32. #include <Zend/zend_interfaces.h>
  33. #include <ext/spl/spl_iterators.h>
  34. // This is not self-contained: it must be after other Zend includes.
  35. #include <Zend/zend_exceptions.h>
  36. #include "arena.h"
  37. #include "convert.h"
  38. #include "def.h"
  39. #include "php-upb.h"
  40. #include "protobuf.h"
  41. static void RepeatedFieldIter_make(zval *val, zval *repeated_field);
  42. // -----------------------------------------------------------------------------
  43. // RepeatedField
  44. // -----------------------------------------------------------------------------
  45. typedef struct {
  46. zend_object std;
  47. zval arena;
  48. upb_array *array;
  49. upb_fieldtype_t type;
  50. const Descriptor* desc; // When values are messages.
  51. } RepeatedField;
  52. zend_class_entry *RepeatedField_class_entry;
  53. static zend_object_handlers RepeatedField_object_handlers;
  54. // PHP Object Handlers /////////////////////////////////////////////////////////
  55. /**
  56. * RepeatedField_create()
  57. *
  58. * PHP class entry function to allocate and initialize a new RepeatedField
  59. * object.
  60. */
  61. static zend_object* RepeatedField_create(zend_class_entry *class_type) {
  62. RepeatedField *intern = emalloc(sizeof(RepeatedField));
  63. zend_object_std_init(&intern->std, class_type);
  64. intern->std.handlers = &RepeatedField_object_handlers;
  65. Arena_Init(&intern->arena);
  66. intern->array = NULL;
  67. intern->desc = NULL;
  68. // Skip object_properties_init(), we don't allow derived classes.
  69. return &intern->std;
  70. }
  71. /**
  72. * RepeatedField_dtor()
  73. *
  74. * Object handler to destroy a RepeatedField. This releases all resources
  75. * associated with the message. Note that it is possible to access a destroyed
  76. * object from PHP in rare cases.
  77. */
  78. static void RepeatedField_destructor(zend_object* obj) {
  79. RepeatedField* intern = (RepeatedField*)obj;
  80. ObjCache_Delete(intern->array);
  81. zval_ptr_dtor(&intern->arena);
  82. zend_object_std_dtor(&intern->std);
  83. }
  84. static HashTable *RepeatedField_GetProperties(zval *object TSRMLS_DC) {
  85. return NULL; // We do not have a properties table.
  86. }
  87. static zval *RepeatedField_GetPropertyPtrPtr(zval *object, zval *member,
  88. int type, void **cache_slot) {
  89. return NULL; // We don't offer direct references to our properties.
  90. }
  91. // C Functions from array.h ////////////////////////////////////////////////////
  92. // These are documented in the header file.
  93. void RepeatedField_GetPhpWrapper(zval *val, upb_array *arr,
  94. const upb_fielddef *f, zval *arena) {
  95. if (!arr) {
  96. ZVAL_NULL(val);
  97. return;
  98. }
  99. if (!ObjCache_Get(arr, val)) {
  100. RepeatedField *intern = emalloc(sizeof(RepeatedField));
  101. zend_object_std_init(&intern->std, RepeatedField_class_entry);
  102. intern->std.handlers = &RepeatedField_object_handlers;
  103. ZVAL_COPY(&intern->arena, arena);
  104. intern->array = arr;
  105. intern->type = upb_fielddef_type(f);
  106. intern->desc = Descriptor_GetFromFieldDef(f);
  107. // Skip object_properties_init(), we don't allow derived classes.
  108. ObjCache_Add(intern->array, &intern->std);
  109. ZVAL_OBJ(val, &intern->std);
  110. }
  111. }
  112. upb_array *RepeatedField_GetUpbArray(zval *val, const upb_fielddef *f,
  113. upb_arena *arena) {
  114. if (Z_ISREF_P(val)) {
  115. ZVAL_DEREF(val);
  116. }
  117. if (Z_TYPE_P(val) == IS_ARRAY) {
  118. // Auto-construct, eg. [1, 2, 3] -> upb_array([1, 2, 3]).
  119. upb_array *arr = upb_array_new(arena, upb_fielddef_type(f));
  120. HashTable *table = HASH_OF(val);
  121. HashPosition pos;
  122. upb_fieldtype_t type = upb_fielddef_type(f);
  123. const Descriptor *desc = Descriptor_GetFromFieldDef(f);
  124. zend_hash_internal_pointer_reset_ex(table, &pos);
  125. while (true) {
  126. zval *zv = zend_hash_get_current_data_ex(table, &pos);
  127. upb_msgval val;
  128. if (!zv) return arr;
  129. if (!Convert_PhpToUpbAutoWrap(zv, &val, type, desc, arena)) {
  130. return NULL;
  131. }
  132. upb_array_append(arr, val, arena);
  133. zend_hash_move_forward_ex(table, &pos);
  134. }
  135. } else if (Z_TYPE_P(val) == IS_OBJECT &&
  136. Z_OBJCE_P(val) == RepeatedField_class_entry) {
  137. // Unwrap existing RepeatedField object to get the upb_array* inside.
  138. RepeatedField *intern = (RepeatedField*)Z_OBJ_P(val);
  139. const Descriptor *desc = Descriptor_GetFromFieldDef(f);
  140. if (intern->type != upb_fielddef_type(f) || intern->desc != desc) {
  141. php_error_docref(NULL, E_USER_ERROR,
  142. "Wrong type for this repeated field.");
  143. }
  144. upb_arena_fuse(arena, Arena_Get(&intern->arena));
  145. return intern->array;
  146. } else {
  147. php_error_docref(NULL, E_USER_ERROR, "Must be a repeated field");
  148. return NULL;
  149. }
  150. }
  151. // RepeatedField PHP methods ///////////////////////////////////////////////////
  152. /**
  153. * RepeatedField::__construct()
  154. *
  155. * Constructs an instance of RepeatedField.
  156. * @param long Type of the stored element.
  157. * @param string Message/Enum class.
  158. */
  159. PHP_METHOD(RepeatedField, __construct) {
  160. RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
  161. upb_arena *arena = Arena_Get(&intern->arena);
  162. zend_long type;
  163. zend_class_entry* klass = NULL;
  164. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|C", &type, &klass) != SUCCESS) {
  165. return;
  166. }
  167. intern->type = pbphp_dtype_to_type(type);
  168. intern->desc = Descriptor_GetFromClassEntry(klass);
  169. if (intern->type == UPB_TYPE_MESSAGE && klass == NULL) {
  170. php_error_docref(NULL, E_USER_ERROR,
  171. "Message/enum type must have concrete class.");
  172. return;
  173. }
  174. intern->array = upb_array_new(arena, intern->type);
  175. ObjCache_Add(intern->array, &intern->std);
  176. }
  177. /**
  178. * RepeatedField::append()
  179. *
  180. * Append element to the end of the repeated field.
  181. * @param object The element to be added.
  182. */
  183. PHP_METHOD(RepeatedField, append) {
  184. RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
  185. upb_arena *arena = Arena_Get(&intern->arena);
  186. zval *php_val;
  187. upb_msgval msgval;
  188. if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &php_val) != SUCCESS ||
  189. !Convert_PhpToUpb(php_val, &msgval, intern->type, intern->desc, arena)) {
  190. return;
  191. }
  192. upb_array_append(intern->array, msgval, arena);
  193. }
  194. /**
  195. * RepeatedField::offsetExists()
  196. *
  197. * Implements the ArrayAccess interface. Invoked when PHP code calls:
  198. *
  199. * isset($arr[$idx]);
  200. * empty($arr[$idx]);
  201. *
  202. * @param long The index to be checked.
  203. * @return bool True if the element at the given index exists.
  204. */
  205. PHP_METHOD(RepeatedField, offsetExists) {
  206. RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
  207. zend_long index;
  208. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
  209. return;
  210. }
  211. RETURN_BOOL(index >= 0 && index < upb_array_size(intern->array));
  212. }
  213. /**
  214. * RepeatedField::offsetGet()
  215. *
  216. * Implements the ArrayAccess interface. Invoked when PHP code calls:
  217. *
  218. * $x = $arr[$idx];
  219. *
  220. * @param long The index of the element to be fetched.
  221. * @return object The stored element at given index.
  222. * @exception Invalid type for index.
  223. * @exception Non-existing index.
  224. */
  225. PHP_METHOD(RepeatedField, offsetGet) {
  226. RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
  227. zend_long index;
  228. upb_msgval msgval;
  229. zval ret;
  230. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
  231. return;
  232. }
  233. if (index < 0 || index >= upb_array_size(intern->array)) {
  234. zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
  235. return;
  236. }
  237. msgval = upb_array_get(intern->array, index);
  238. Convert_UpbToPhp(msgval, &ret, intern->type, intern->desc, &intern->arena);
  239. RETURN_ZVAL(&ret, 0, 1);
  240. }
  241. /**
  242. * RepeatedField::offsetSet()
  243. *
  244. * Implements the ArrayAccess interface. Invoked when PHP code calls:
  245. *
  246. * $arr[$idx] = $x;
  247. * $arr []= $x; // Append
  248. *
  249. * @param long The index of the element to be assigned.
  250. * @param object The element to be assigned.
  251. * @exception Invalid type for index.
  252. * @exception Non-existing index.
  253. * @exception Incorrect type of the element.
  254. */
  255. PHP_METHOD(RepeatedField, offsetSet) {
  256. RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
  257. upb_arena *arena = Arena_Get(&intern->arena);
  258. size_t size = upb_array_size(intern->array);
  259. zval *offset, *val;
  260. int64_t index;
  261. upb_msgval msgval;
  262. if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &offset, &val) != SUCCESS) {
  263. return;
  264. }
  265. if (Z_TYPE_P(offset) == IS_NULL) {
  266. index = size;
  267. } else if (!Convert_PhpToInt64(offset, &index)) {
  268. return;
  269. }
  270. if (!Convert_PhpToUpb(val, &msgval, intern->type, intern->desc, arena)) {
  271. return;
  272. }
  273. if (index > size) {
  274. zend_error(E_USER_ERROR, "Element at index %ld doesn't exist.\n", index);
  275. } else if (index == size) {
  276. upb_array_append(intern->array, msgval, Arena_Get(&intern->arena));
  277. } else {
  278. upb_array_set(intern->array, index, msgval);
  279. }
  280. }
  281. /**
  282. * RepeatedField::offsetUnset()
  283. *
  284. * Implements the ArrayAccess interface. Invoked when PHP code calls:
  285. *
  286. * unset($arr[$idx]);
  287. *
  288. * @param long The index of the element to be removed.
  289. * @exception Invalid type for index.
  290. * @exception The element to be removed is not at the end of the RepeatedField.
  291. */
  292. PHP_METHOD(RepeatedField, offsetUnset) {
  293. RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
  294. zend_long index;
  295. zend_long size = upb_array_size(intern->array);
  296. // Only the element at the end of the array can be removed.
  297. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) != SUCCESS) {
  298. return;
  299. }
  300. if (size == 0 || index != size - 1) {
  301. php_error_docref(NULL, E_USER_ERROR, "Cannot remove element at %ld.\n",
  302. index);
  303. return;
  304. }
  305. upb_array_resize(intern->array, size - 1, Arena_Get(&intern->arena));
  306. }
  307. /**
  308. * RepeatedField::count()
  309. *
  310. * Implements the Countable interface. Invoked when PHP code calls:
  311. *
  312. * $len = count($arr);
  313. * Return the number of stored elements.
  314. * This will also be called for: count($arr)
  315. * @return long The number of stored elements.
  316. */
  317. PHP_METHOD(RepeatedField, count) {
  318. RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
  319. if (zend_parse_parameters_none() == FAILURE) {
  320. return;
  321. }
  322. RETURN_LONG(upb_array_size(intern->array));
  323. }
  324. /**
  325. * RepeatedField::getIterator()
  326. *
  327. * Implements the IteratorAggregate interface. Invoked when PHP code calls:
  328. *
  329. * foreach ($arr) {}
  330. *
  331. * @return object Beginning iterator.
  332. */
  333. PHP_METHOD(RepeatedField, getIterator) {
  334. zval ret;
  335. RepeatedFieldIter_make(&ret, getThis());
  336. RETURN_ZVAL(&ret, 0, 1);
  337. }
  338. ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
  339. ZEND_ARG_INFO(0, index)
  340. ZEND_END_ARG_INFO()
  341. ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2)
  342. ZEND_ARG_INFO(0, index)
  343. ZEND_ARG_INFO(0, newval)
  344. ZEND_END_ARG_INFO()
  345. ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
  346. ZEND_END_ARG_INFO()
  347. static zend_function_entry repeated_field_methods[] = {
  348. PHP_ME(RepeatedField, __construct, NULL, ZEND_ACC_PUBLIC)
  349. PHP_ME(RepeatedField, append, NULL, ZEND_ACC_PUBLIC)
  350. PHP_ME(RepeatedField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC)
  351. PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
  352. PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
  353. PHP_ME(RepeatedField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC)
  354. PHP_ME(RepeatedField, count, arginfo_void, ZEND_ACC_PUBLIC)
  355. PHP_ME(RepeatedField, getIterator, arginfo_void, ZEND_ACC_PUBLIC)
  356. ZEND_FE_END
  357. };
  358. // -----------------------------------------------------------------------------
  359. // PHP RepeatedFieldIter
  360. // -----------------------------------------------------------------------------
  361. typedef struct {
  362. zend_object std;
  363. zval repeated_field;
  364. zend_long position;
  365. } RepeatedFieldIter;
  366. zend_class_entry *RepeatedFieldIter_class_entry;
  367. static zend_object_handlers repeated_field_iter_object_handlers;
  368. /**
  369. * RepeatedFieldIter_create()
  370. *
  371. * PHP class entry function to allocate and initialize a new RepeatedFieldIter
  372. * object.
  373. */
  374. zend_object* RepeatedFieldIter_create(zend_class_entry *class_type) {
  375. RepeatedFieldIter *intern = emalloc(sizeof(RepeatedFieldIter));
  376. zend_object_std_init(&intern->std, class_type);
  377. intern->std.handlers = &repeated_field_iter_object_handlers;
  378. ZVAL_NULL(&intern->repeated_field);
  379. intern->position = 0;
  380. // Skip object_properties_init(), we don't allow derived classes.
  381. return &intern->std;
  382. }
  383. /**
  384. * RepeatedFieldIter_dtor()
  385. *
  386. * Object handler to destroy a RepeatedFieldIter. This releases all resources
  387. * associated with the message. Note that it is possible to access a destroyed
  388. * object from PHP in rare cases.
  389. */
  390. static void RepeatedFieldIter_dtor(zend_object* obj) {
  391. RepeatedFieldIter* intern = (RepeatedFieldIter*)obj;
  392. zval_ptr_dtor(&intern->repeated_field);
  393. zend_object_std_dtor(&intern->std);
  394. }
  395. /**
  396. * RepeatedFieldIter_make()
  397. *
  398. * C function to create a RepeatedFieldIter.
  399. */
  400. static void RepeatedFieldIter_make(zval *val, zval *repeated_field) {
  401. RepeatedFieldIter *iter;
  402. ZVAL_OBJ(val, RepeatedFieldIter_class_entry->create_object(
  403. RepeatedFieldIter_class_entry));
  404. iter = (RepeatedFieldIter*)Z_OBJ_P(val);
  405. ZVAL_COPY(&iter->repeated_field, repeated_field);
  406. }
  407. /*
  408. * When a user writes:
  409. *
  410. * foreach($arr as $key => $val) {}
  411. *
  412. * PHP's iterator protocol is:
  413. *
  414. * $iter = $arr->getIterator();
  415. * for ($iter->rewind(); $iter->valid(); $iter->next()) {
  416. * $key = $iter->key();
  417. * $val = $iter->current();
  418. * }
  419. */
  420. /**
  421. * RepeatedFieldIter::rewind()
  422. *
  423. * Implements the Iterator interface. Sets the iterator to the first element.
  424. */
  425. PHP_METHOD(RepeatedFieldIter, rewind) {
  426. RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
  427. intern->position = 0;
  428. }
  429. /**
  430. * RepeatedFieldIter::current()
  431. *
  432. * Implements the Iterator interface. Returns the current value.
  433. */
  434. PHP_METHOD(RepeatedFieldIter, current) {
  435. RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
  436. RepeatedField *field = (RepeatedField*)Z_OBJ_P(&intern->repeated_field);
  437. upb_array *array = field->array;
  438. zend_long index = intern->position;
  439. upb_msgval msgval;
  440. zval ret;
  441. if (index < 0 || index >= upb_array_size(array)) {
  442. zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
  443. }
  444. msgval = upb_array_get(array, index);
  445. Convert_UpbToPhp(msgval, &ret, field->type, field->desc, &field->arena);
  446. RETURN_ZVAL(&ret, 0, 1);
  447. }
  448. /**
  449. * RepeatedFieldIter::key()
  450. *
  451. * Implements the Iterator interface. Returns the current key.
  452. */
  453. PHP_METHOD(RepeatedFieldIter, key) {
  454. RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
  455. RETURN_LONG(intern->position);
  456. }
  457. /**
  458. * RepeatedFieldIter::next()
  459. *
  460. * Implements the Iterator interface. Advances to the next element.
  461. */
  462. PHP_METHOD(RepeatedFieldIter, next) {
  463. RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
  464. ++intern->position;
  465. }
  466. /**
  467. * RepeatedFieldIter::valid()
  468. *
  469. * Implements the Iterator interface. Returns true if this is a valid element.
  470. */
  471. PHP_METHOD(RepeatedFieldIter, valid) {
  472. RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
  473. RepeatedField *field = (RepeatedField*)Z_OBJ_P(&intern->repeated_field);
  474. RETURN_BOOL(intern->position < upb_array_size(field->array));
  475. }
  476. static zend_function_entry repeated_field_iter_methods[] = {
  477. PHP_ME(RepeatedFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC)
  478. PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC)
  479. PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC)
  480. PHP_ME(RepeatedFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC)
  481. PHP_ME(RepeatedFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC)
  482. ZEND_FE_END
  483. };
  484. // -----------------------------------------------------------------------------
  485. // Module init.
  486. // -----------------------------------------------------------------------------
  487. /**
  488. * Array_ModuleInit()
  489. *
  490. * Called when the C extension is loaded to register all types.
  491. */
  492. void Array_ModuleInit() {
  493. zend_class_entry tmp_ce;
  494. zend_object_handlers *h;
  495. // RepeatedField.
  496. INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\RepeatedField",
  497. repeated_field_methods);
  498. RepeatedField_class_entry = zend_register_internal_class(&tmp_ce);
  499. zend_class_implements(RepeatedField_class_entry, 3, spl_ce_ArrayAccess,
  500. zend_ce_aggregate, spl_ce_Countable);
  501. RepeatedField_class_entry->ce_flags |= ZEND_ACC_FINAL;
  502. RepeatedField_class_entry->create_object = RepeatedField_create;
  503. h = &RepeatedField_object_handlers;
  504. memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
  505. h->dtor_obj = RepeatedField_destructor;
  506. h->get_properties = RepeatedField_GetProperties;
  507. h->get_property_ptr_ptr = RepeatedField_GetPropertyPtrPtr;
  508. // RepeatedFieldIter
  509. INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\RepeatedFieldIter",
  510. repeated_field_iter_methods);
  511. RepeatedFieldIter_class_entry = zend_register_internal_class(&tmp_ce);
  512. zend_class_implements(RepeatedFieldIter_class_entry, 1, zend_ce_iterator);
  513. RepeatedFieldIter_class_entry->ce_flags |= ZEND_ACC_FINAL;
  514. RepeatedFieldIter_class_entry->create_object = RepeatedFieldIter_create;
  515. h = &repeated_field_iter_object_handlers;
  516. memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
  517. h->dtor_obj = RepeatedFieldIter_dtor;
  518. }