This repository was archived by the owner on Aug 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patharraydebug.c
More file actions
158 lines (127 loc) · 3.69 KB
/
Copy patharraydebug.c
File metadata and controls
158 lines (127 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* arraydebug extension for PHP */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "ext/standard/info.h"
#include "php_arraydebug.h"
#include "arraydebug_arginfo.h"
/* {{{ */
PHP_FUNCTION(array_debuginfo) {
HashTable* ht;
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1)
Z_PARAM_ARRAY_HT(ht)
ZEND_PARSE_PARAMETERS_END();
array_init(return_value);
#define add_output(field_name) add_assoc_long(return_value, #field_name, ht->field_name)
add_output(nTableMask);
add_output(nNumUsed);
add_output(nNumOfElements);
add_output(nTableSize);
add_output(nInternalPointer);
add_output(nNextFreeElement);
#undef add_output
}
static void array_hash_distribution(zval* return_value, HashTable* ht) {
uint32_t nTableMask;
Bucket* bucket;
uint32_t actualIndex;
array_init(return_value);
#if PHP_VERSION_ID >= 80200
if ((HT_FLAGS(ht) & HASH_FLAG_PACKED) == 0) {
#endif
//ignore table mask for packed arrays, it's not used
nTableMask = HT_FLAGS(ht) & HASH_FLAG_PACKED ? 0 : ht->nTableMask;
ZEND_HASH_FOREACH_BUCKET(ht, bucket) {
HashTable* hKeys;
actualIndex = bucket->h | nTableMask;
zval* zExistingKeys = zend_hash_index_find(Z_ARRVAL_P(return_value), actualIndex);
if (zExistingKeys != NULL) {
hKeys = Z_ARRVAL_P(zExistingKeys);
} else {
zval zNewKeys;
array_init(&zNewKeys);
zend_hash_index_add(Z_ARRVAL_P(return_value), actualIndex, &zNewKeys);
hKeys = Z_ARRVAL(zNewKeys);
}
zval zv;
ZVAL_COPY(&zv, &bucket->val);
if (bucket->key != NULL) {
zend_hash_add(hKeys, bucket->key, &zv);
} else {
zend_hash_index_add(hKeys, bucket->h, &zv);
}
} ZEND_HASH_FOREACH_END();
#if PHP_VERSION_ID >= 80200
} else {
zend_ulong key;
zval* val;
ZEND_HASH_PACKED_FOREACH_KEY_VAL(ht, key, val) {
zval zNewKeys;
zval zv;
ZVAL_COPY(&zv, val);
array_init_size(&zNewKeys, 1);
zend_hash_index_add(Z_ARRVAL(zNewKeys), key, &zv);
zend_hash_index_add(Z_ARRVAL_P(return_value), key, &zNewKeys);
} ZEND_HASH_FOREACH_END();
}
#endif
}
/* {{{ */
PHP_FUNCTION(array_hash_distribution) {
HashTable* ht;
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1)
Z_PARAM_ARRAY_HT(ht)
ZEND_PARSE_PARAMETERS_END();
array_hash_distribution(return_value, ht);
} /* }}} */
PHP_FUNCTION(array_load_factor) {
HashTable* ht;
zval distribution;
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1)
Z_PARAM_ARRAY_HT(ht)
ZEND_PARSE_PARAMETERS_END();
if (HT_FLAGS(ht) & HASH_FLAG_PACKED) {
RETURN_DOUBLE(1.0);
}
array_hash_distribution(&distribution, ht);
RETVAL_DOUBLE(((double)zend_array_count(ht)) / ((double) zend_array_count(Z_ARRVAL(distribution))));
zval_dtor(&distribution);
}
/* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(arraydebug)
{
#if defined(ZTS) && defined(COMPILE_DL_ARRAYDEBUG)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(arraydebug)
{
php_info_print_table_start();
php_info_print_table_header(2, "arraydebug support", "enabled");
php_info_print_table_end();
}
/* }}} */
/* {{{ arraydebug_module_entry */
zend_module_entry arraydebug_module_entry = {
STANDARD_MODULE_HEADER,
"arraydebug", /* Extension name */
ext_functions, /* zend_function_entry */
NULL, /* PHP_MINIT - Module initialization */
NULL, /* PHP_MSHUTDOWN - Module shutdown */
PHP_RINIT(arraydebug), /* PHP_RINIT - Request initialization */
NULL, /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(arraydebug), /* PHP_MINFO - Module info */
PHP_ARRAYDEBUG_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_ARRAYDEBUG
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(arraydebug)
#endif