Coverage Report

Created: 2025-07-23 06:33

/src/php-src/Zend/zend_iterators.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
   +----------------------------------------------------------------------+
3
   | Zend Engine                                                          |
4
   +----------------------------------------------------------------------+
5
   | Copyright (c) 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
20
#include "zend.h"
21
#include "zend_API.h"
22
23
static zend_class_entry zend_iterator_class_entry;
24
25
static void iter_wrapper_free(zend_object *object);
26
static void iter_wrapper_dtor(zend_object *object);
27
static HashTable *iter_wrapper_get_gc(zend_object *object, zval **table, int *n);
28
29
static const zend_object_handlers iterator_object_handlers = {
30
  0,
31
  iter_wrapper_free,
32
  iter_wrapper_dtor,
33
  NULL, /* clone_obj */
34
  NULL, /* clone_obj_with */
35
  NULL, /* prop read */
36
  NULL, /* prop write */
37
  NULL, /* read dim */
38
  NULL, /* write dim */
39
  NULL, /* get_property_ptr_ptr */
40
  NULL, /* has prop */
41
  NULL, /* unset prop */
42
  NULL, /* has dim */
43
  NULL, /* unset dim */
44
  NULL, /* props get */
45
  NULL, /* method get */
46
  NULL, /* get ctor */
47
  NULL, /* get class name */
48
  NULL, /* cast */
49
  NULL, /* count */
50
  NULL, /* get_debug_info */
51
  NULL, /* get_closure */
52
  iter_wrapper_get_gc,
53
  NULL, /* do_operation */
54
  NULL, /* compare */
55
  NULL  /* get_properties_for */
56
};
57
58
ZEND_API void zend_register_iterator_wrapper(void)
59
16
{
60
16
  INIT_CLASS_ENTRY(zend_iterator_class_entry, "__iterator_wrapper", NULL);
61
16
  zend_iterator_class_entry.default_object_handlers = &iterator_object_handlers;
62
16
}
63
64
static void iter_wrapper_free(zend_object *object)
65
1.97k
{
66
1.97k
  zend_object_iterator *iter = (zend_object_iterator*)object;
67
1.97k
  iter->funcs->dtor(iter);
68
1.97k
}
69
70
static void iter_wrapper_dtor(zend_object *object)
71
1.97k
{
72
1.97k
}
73
74
369
static HashTable *iter_wrapper_get_gc(zend_object *object, zval **table, int *n) {
75
369
  zend_object_iterator *iter = (zend_object_iterator*)object;
76
369
  if (iter->funcs->get_gc) {
77
369
    return iter->funcs->get_gc(iter, table, n);
78
369
  }
79
80
0
  *table = NULL;
81
0
  *n = 0;
82
0
  return NULL;
83
369
}
84
85
ZEND_API void zend_iterator_init(zend_object_iterator *iter)
86
1.97k
{
87
1.97k
  zend_object_std_init(&iter->std, &zend_iterator_class_entry);
88
1.97k
}
89
90
ZEND_API void zend_iterator_dtor(zend_object_iterator *iter)
91
394
{
92
394
  if (GC_DELREF(&iter->std) > 0) {
93
1
    return;
94
1
  }
95
96
393
  zend_objects_store_del(&iter->std);
97
393
}
98
99
ZEND_API zend_object_iterator* zend_iterator_unwrap(zval *array_ptr)
100
4.41k
{
101
4.41k
  ZEND_ASSERT(Z_TYPE_P(array_ptr) == IS_OBJECT);
102
4.41k
  if (Z_OBJ_HT_P(array_ptr) == &iterator_object_handlers) {
103
3.74k
    return (zend_object_iterator *)Z_OBJ_P(array_ptr);
104
3.74k
  }
105
667
  return NULL;
106
4.41k
}