-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdanai.c
163 lines (140 loc) · 3.99 KB
/
danai.c
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
159
160
161
162
#include "php_danai.h"
PHP_FUNCTION(danai_hola_mundo)
{
php_printf("Hola mundo!\n");
}
PHP_FUNCTION(danai_print_refcount)
{
zval *arg;
if (zend_get_parameters(ZEND_NUM_ARGS(), 1, &arg) == FAILURE) {
RETURN_NULL();
}
if (!arg->is_ref) {
return;
}
php_printf("Referenciado %d veces.\n", arg->refcount);
}
PHP_FUNCTION(danai_print_type)
{
zval *arg;
if (zend_get_parameters(ZEND_NUM_ARGS(), 1, &arg) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Falta el parámetro.");
RETURN_NULL();
}
switch (arg->type) {
case IS_NULL:
php_printf("Tipo: IS_NULL\n");
break;
case IS_BOOL:
php_printf("Tipo: IS_BOOL\n");
break;
case IS_LONG:
php_printf("Tipo: IS_LONG\n");
break;
case IS_DOUBLE:
php_printf("Tipo : IS_DOUBLE\n");
break;
case IS_STRING:
php_printf("Tipo : IS_STRING\n");
break;
case IS_ARRAY:
php_printf("Tipo : IS_ARRAY\n");
break;
case IS_OBJECT:
php_printf("Tipo : IS_OBJECT\n");
break;
case IS_RESOURCE:
php_printf("Tipo: IS_RESOURCE\n");
break;
default:
php_printf("Otro tipo\n");
}
}
void php_danai_print_var_hash(HashTable *arrht)
{
for(zend_hash_internal_pointer_reset(arrht);
zend_hash_has_more_elements(arrht) == SUCCESS;
zend_hash_move_forward(arrht)) {
char *key;
uint keylen;
ulong idx;
int type;
zval **ppzval, tmpcopy;
type = zend_hash_get_current_key_ex(arrht, &key, &keylen,
&idx, 0, NULL);
if (zend_hash_get_current_data(arrht, (void**)&ppzval) == FAILURE) {
/* Should never actually fail
* since the key is known to exist. */
continue;
}
/* Duplicate the zval so that
* the orignal's contents are not destroyed */
tmpcopy = **ppzval;
zval_copy_ctor(&tmpcopy);
/* Reset refcount & Convert */
INIT_PZVAL(&tmpcopy);
convert_to_string(&tmpcopy);
/* Output */
php_printf("The value of ");
if (type == HASH_KEY_IS_STRING) {
/* String Key / Associative */
PHPWRITE(key, keylen);
} else {
/* Numeric Key */
php_printf("%ld", idx);
}
php_printf(" is: ");
PHPWRITE(Z_STRVAL(tmpcopy), Z_STRLEN(tmpcopy));
php_printf("\n");
/* Toss out old copy */
zval_dtor(&tmpcopy);
}
}
PHP_FUNCTION(danai_dump_globalsymtable)
{
php_printf("Tabla de simbolos global : \n\n");
php_danai_print_var_hash(&(EG(symbol_table)));
}
PHP_FUNCTION(danai_dump_currentsymtable)
{
php_printf("Tabla de simbolos actualmente activa : \n\n");
php_danai_print_var_hash(EG(active_symbol_table));
}
PHP_FUNCTION(danai_dump_symtables)
{
int i = 0;
php_printf("El tamaño de la cache es %d\n", SYMTABLE_CACHE_SIZE);
php_printf("Ahora mismo hay %d tablas de símbolos.\n", EG(symtable_cache_limit));
while (i <= *(EG(symtable_cache_limit))) {
php_printf("%d\n",i);
//php_danai_print_var_hash(EG(symtable_cache[1]));
i++;
}
}
static function_entry php_danai_functions[] = {
PHP_FE(danai_print_refcount, php_danai_byref_arginfo)
PHP_FE(danai_print_type, NULL)
PHP_FE(danai_dump_globalsymtable, NULL)
PHP_FE(danai_dump_currentsymtable, NULL)
PHP_FE(danai_dump_symtables, NULL)
{ NULL, NULL, NULL }
};
zend_module_entry danai_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
PHP_DANAI_EXTNAME,
php_danai_functions, /* Functions */
NULL, /* MINIT */
NULL, /* MSHUTDOWN */
NULL, /* RINIT */
NULL, /* RSHUTDOWN */
NULL, /* MINFO */
#if ZEND_MODULE_API_NO >= 20010901
PHP_DANAI_EXTVER,
#endif
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_DANAI
ZEND_GET_MODULE(danai)
#endif