zend_iterators.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Wez Furlong <wez@thebrainroom.com> |
  16. | Marcus Boerger <helly@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #include "zend.h"
  20. #include "zend_API.h"
  21. static zend_class_entry zend_iterator_class_entry;
  22. static void iter_wrapper_free(zend_object *object);
  23. static void iter_wrapper_dtor(zend_object *object);
  24. static const zend_object_handlers iterator_object_handlers = {
  25. 0,
  26. iter_wrapper_free,
  27. iter_wrapper_dtor,
  28. NULL,
  29. NULL, /* prop read */
  30. NULL, /* prop write */
  31. NULL, /* read dim */
  32. NULL, /* write dim */
  33. NULL,
  34. NULL, /* get */
  35. NULL, /* set */
  36. NULL, /* has prop */
  37. NULL, /* unset prop */
  38. NULL, /* has dim */
  39. NULL, /* unset dim */
  40. NULL, /* props get */
  41. NULL, /* method get */
  42. NULL, /* call */
  43. NULL, /* get ctor */
  44. NULL, /* get class name */
  45. NULL, /* compare */
  46. NULL, /* cast */
  47. NULL, /* count */
  48. NULL, /* get_debug_info */
  49. NULL, /* get_closure */
  50. NULL, /* get_gc */
  51. NULL, /* do_operation */
  52. NULL /* compare */
  53. };
  54. ZEND_API void zend_register_iterator_wrapper(void)
  55. {
  56. INIT_CLASS_ENTRY(zend_iterator_class_entry, "__iterator_wrapper", NULL);
  57. }
  58. static void iter_wrapper_free(zend_object *object)
  59. {
  60. zend_object_iterator *iter = (zend_object_iterator*)object;
  61. iter->funcs->dtor(iter);
  62. }
  63. static void iter_wrapper_dtor(zend_object *object)
  64. {
  65. }
  66. ZEND_API void zend_iterator_init(zend_object_iterator *iter)
  67. {
  68. zend_object_std_init(&iter->std, &zend_iterator_class_entry);
  69. iter->std.handlers = &iterator_object_handlers;
  70. }
  71. ZEND_API void zend_iterator_dtor(zend_object_iterator *iter)
  72. {
  73. if (GC_DELREF(&iter->std) > 0) {
  74. return;
  75. }
  76. zend_objects_store_del(&iter->std);
  77. }
  78. ZEND_API zend_object_iterator* zend_iterator_unwrap(zval *array_ptr)
  79. {
  80. ZEND_ASSERT(Z_TYPE_P(array_ptr) == IS_OBJECT);
  81. if (Z_OBJ_HT_P(array_ptr) == &iterator_object_handlers) {
  82. return (zend_object_iterator *)Z_OBJ_P(array_ptr);
  83. }
  84. return NULL;
  85. }
  86. /*
  87. * Local variables:
  88. * tab-width: 4
  89. * c-basic-offset: 4
  90. * indent-tabs-mode: t
  91. * End:
  92. * vim600: sw=4 ts=4 fdm=marker
  93. * vim<600: sw=4 ts=4
  94. */