@@ -18,46 +18,23 @@ function convert(i, j, t)
18
18
19
19
for (i = 0 ; i < t; i++ ) { tabs = tabs " \t " }
20
20
21
- if (type == " int" ) {
22
- x = tabs " convert_to_long_ex(" name ext " );\n " \
23
- (ext? tabs name " = Z_LVAL_PP(" name ext " );\n " : " " )
24
- ints = ints " \t int " name " ;\n "
21
+ if (type == " int" || type == " long" ) {
22
+ longs = longs " \t long " name " ;\n "
25
23
} else if (type == " bool" ) {
26
- x = tabs " convert_to_long_ex(" name ext " );\n " \
27
- (ext? tabs name " = Z_LVAL_PP(" name ext " );\n " : " " )
28
- ints = ints " \t int " name " ;\n "
29
- } else if (type == " double" ) {
30
- x = tabs " convert_to_double_ex(" name ext " );\n " \
31
- (ext? tabs name " = Z_DVAL_PP(" name ext " );\n " : " " )
24
+ bools = bools " \t zend_bool " name " ;\n "
25
+ } else if (type == " double" || type == " float" ) {
32
26
doubles = doubles " \t double " name " ;\n "
33
- } else if (type == " float" ) {
34
- x = tabs " convert_to_double_ex(" name ext " );\n " \
35
- (ext? tabs name " = (float) Z_DVAL_PP(" name ext " );\n " : " " )
36
- floats = floats " \t float " name " ;\n "
37
27
} else if (type == " string" ) {
38
- x = tabs " convert_to_string_ex(" name ext " );\n " \
39
- (ext? tabs name " = Z_STRVAL_PP(" name ext " );\n " : " " )
40
- (ext ? strings = strings " \t char *" name " = NULL;\n " : 0 )
41
- if (string_lens) {
42
- x = x tabs name " _len = Z_STRLEN_PP(" name ext " );\n "
43
- ints = ints " \t int " name " _len;\n "
44
- }
45
- } else if (type == " array" ) {
46
- x = " convert_to_array_ex(" name ext " );\n "
28
+ strings = strings " \t char *" name " = NULL;\n "
29
+ ints = ints " \t int " name " _len;\n "
30
+ } else if (type == " array" || type == " object" || type == " mixed" ) {
31
+ zvals = zvals " \t zval *" name " = NULL;\n "
47
32
} else if (type == " resource" ) {
48
- if (opt && i > - 1 ) {
49
- resources = resources " \t if (argc < " j+ 1 " ) {\n " \
50
- comment(" \t\t /* Argument not given, do something before\n\t\t trying to fetch resource " name " . */\n " ) \
51
- " \t }\n\t ZEND_FETCH_RESOURCE(???, ???, " name ext " , " name " _id, \" ???\" , ???_rsrc_id);\n "
52
- } else {
53
- resources = resources " \t ZEND_FETCH_RESOURCE(???, ???, " name ext " , " name " _id, \" ???\" , ???_rsrc_id);\n "
54
- }
33
+ zvals = zvals " \t zval *" name " = NULL;\n "
34
+ resources = resources " \t if (" name " ) {\n " \
35
+ " \t\t ZEND_FETCH_RESOURCE(???, ???, " name " , " name " _id, \" ???\" , ???_rsrc_id);\n\t }\n "
55
36
ints = ints " \t int " name " _id = -1;\n "
56
- } else {
57
- x = comment(tabs " /* Write your own code here to handle argument " name " . */\n " )
58
37
}
59
-
60
- if (x) return x
61
38
}
62
39
63
40
function comment (s )
@@ -71,10 +48,16 @@ function comment(s)
71
48
72
49
BEGIN {
73
50
name = " [_A-Za-z][_A-Za-z0-9]*"
74
- type = " int|double|float|string|bool|array|object|resource|mixed|void"
51
+ type = " int|long|double|float|string|bool|array|object|resource|mixed|void"
52
+ spec = " l|l|d|d|s|b|a|o|r|z|"
75
53
num_funcs = 0
76
54
77
- if (assign_params) ext = " _arg"
55
+ # create a map from type name to the spec
56
+ split (type, type_array, " \|" )
57
+ split (spec, spec_array, " \|" )
58
+ for (i in type_array) {
59
+ spec_map[ type_array[ i]] = spec_array[ i]
60
+ }
78
61
79
62
if (xml && xml != " yes" ) {
80
63
xmldoc = xml
@@ -111,8 +94,9 @@ BEGIN {
111
94
}
112
95
113
96
{
114
- args_max = args_min = optional = i = 0
97
+ args_max = args_min = optional = i = spec_opt = 0
115
98
line = $0
99
+ spec_str = " \" "
116
100
117
101
func_type = gobble(type);
118
102
func_name = gobble(name);
@@ -130,6 +114,7 @@ BEGIN {
130
114
argnames[ num_funcs,args_max] = arg_name
131
115
132
116
args_max++
117
+ spec_str = spec_str spec_map[ arg_type]
133
118
if (optional) {
134
119
optionals[ num_funcs,i] = optional
135
120
if (arg_type != " resource" ) {
@@ -140,12 +125,15 @@ BEGIN {
140
125
}
141
126
142
127
if (x = gobble(" \\ [" )) {
128
+ if (! spec_opt) {
129
+ spec_str = spec_str " |"
130
+ spec_opt = 1
131
+ }
143
132
optional++
144
133
}
145
134
146
135
y = gobble(" ," )
147
136
if (! x && y && optional) {
148
- check_argc_in_switch[ num_funcs] = 1
149
137
grouped_optional_param[ num_funcs,i] = 1
150
138
}
151
139
i++
@@ -159,10 +147,13 @@ BEGIN {
159
147
fcomments[ num_funcs] = line
160
148
# }
161
149
150
+ spec_str = spec_str " \" "
151
+
162
152
funcs[ num_funcs] = func_name
163
153
types[ num_funcs] = func_type
164
154
maxargs[ num_funcs] = args_max
165
155
minargs[ num_funcs] = args_min
156
+ specs[ num_funcs] = spec_str
166
157
167
158
num_funcs++
168
159
}
@@ -172,7 +163,7 @@ END {
172
163
for (i = 0 ; i < num_funcs; i++ ) {
173
164
compareargc = maxargs[ i] - minargs[ i]
174
165
closefetch = fetchargs = zvals = xmlparams = funcvals = resources = handleargs = closeopts = " "
175
- ints = doubles = floats = strings = arrays = " "
166
+ ints = longs = doubles = strings = bools = zvals = " "
176
167
177
168
proto = " /* {{{ proto " types[ i] " " funcs[ i] " ("
178
169
@@ -189,33 +180,18 @@ END {
189
180
" <funcprototype>\n " \
190
181
" <funcdef>" types[ i] " <function>" funcs[ i] " </function></funcdef>\n "
191
182
192
- if (maxargs[ i] > 0 ) {
193
- zvals = " \t zval "
194
- if (compareargc) {
195
- if (minargs[ i] ) {
196
- fetchargs = " \t int argc = ZEND_NUM_ARGS();\n\t if (argc < " \
197
- minargs[ i] " || argc > " maxargs[ i] \
198
- " || zend_get_parameters_ex(argc, "
199
- } else {
200
- fetchargs = " \t int argc = ZEND_NUM_ARGS();\n\t if (argc > " \
201
- maxargs[ i] " || (argc && zend_get_parameters_ex(argc, "
202
- closefetch = " )"
203
- }
204
- } else {
205
- fetchargs = " \t if (ZEND_NUM_ARGS() != " maxargs[ i] \
206
- " || zend_get_parameters_ex(" maxargs[ i] " , "
207
- }
208
- }
183
+ fetchargs = " \t if (zend_parse_parameters(ZEND_NUM_ARGS, " specs[ i] " , "
209
184
210
185
for (j = 0 ; j < maxargs[ i] ; j++ ) {
211
186
212
187
if (j) {
213
- zvals = zvals " , "
214
188
fetchargs = fetchargs " , "
215
189
}
216
190
217
- zvals = zvals " **" argnames[ i,j] ext
218
- fetchargs = fetchargs " &" argnames[ i,j] ext
191
+ fetchargs = fetchargs " &" argnames[ i,j]
192
+ if (argtypes[ i,j] == " string" ) {
193
+ fetchargs = fetchargs " , &" argnames[ i,j] " _len"
194
+ }
219
195
220
196
xmlparams = xmlparams " <paramdef>" argtypes[ i,j]
221
197
if (j > minargs[ i] - 1 ) {
@@ -237,56 +213,12 @@ END {
237
213
if (j > 0 ) proto = proto " , "
238
214
proto = proto argtypes[ i,j] " " argnames[ i,j]
239
215
240
- # Clean up this mess...
241
-
242
- if (useswitch[ i] ) {
243
- if (grouped_optional_param[ i,j] && code) {
244
- handleargs = convert(i, j, 3 ) \
245
- ((grouped_optional_param[ i,j- 1 ] ) ? " " : comment(" \t\t\t /* Fall-through. */\n " )) \
246
- handleargs
247
- } else {
248
- if (j > minargs[ i] - 1 ) {
249
- if (code = convert(i, j, 3 )) {
250
- handleargs = " \t\t case " j+ 1 " :\n " code \
251
- ((grouped_optional_param[ i,j- 1 ] ) ? " " : comment(" \t\t\t /* Fall-through. */\n " )) \
252
- handleargs
253
- } else {
254
- handleargs = " \t\t case " j+ 1 " :" \
255
- comment(" \t /* Fall-through. */" ) \
256
- " \n " handleargs
257
- }
258
- } else if (j >= minargs[ i] - 1 ) {
259
- if (code = convert(i, j, 3 )) {
260
- handleargs = " \t\t case " j+ 1 " :\n " code handleargs
261
- } else {
262
- handleargs = " \t\t case " j+ 1 " :\n " handleargs
263
- }
264
- } else {
265
- if (code = convert(i, j, 3 )) handleargs = code handleargs
266
- }
267
- }
268
- } else {
269
- if (code = convert(i, j, 1 )) handleargs = handleargs code
270
- }
216
+ convert(i, j, 1 )
271
217
}
272
218
273
219
proto = proto closeopts " )\n " fcomments[ i] " */\n PHP_FUNCTION(" funcs[ i] " )\n {"
274
- if (maxargs[ i] ) {
275
- zvals = zvals " ;"
276
- fetchargs = fetchargs " ) == FAILURE)" closefetch " {\n\t\t ZEND_WRONG_PARAM_COUNT();\n\t }\n "
277
- }
278
- if (assign_params) funcvals = ints doubles floats strings
279
- if (useswitch[ i] ) {
280
- if (check_argc_in_switch[ i] ) {
281
- check_argc = " \t\t default:\n\t\t\t ZEND_WRONG_PARAM_COUNT();\n "
282
- } else {
283
- check_argc = " "
284
- }
285
- handleargs = " \t switch (argc) {\n " \
286
- handleargs \
287
- (minargs[ i] ? " " : " \t\t case 0:\n " ) \
288
- " \t\t\t break;\n " check_argc " \t }"
289
- }
220
+ fetchargs = fetchargs " ) == FAILURE)" closefetch " \n\t\t return;\n "
221
+ funcvals = strings ints longs doubles bools zvals
290
222
xmlstr = xmlstr xmlparams \
291
223
" </funcprototype>\n " \
292
224
" </funcsynopsis>\n " \
@@ -296,16 +228,14 @@ END {
296
228
" </refentry>\n "
297
229
298
230
print proto > stubfile
299
- if (zvals) print zvals > stubfile
300
231
if (funcvals) print funcvals > stubfile
301
232
if (fetchargs) print fetchargs > stubfile
302
233
if (resources) {
303
234
print resources > stubfile
304
235
if (! stubs) print " " > extname " /function_warning"
305
236
}
306
- if (handleargs) print handleargs > stubfile
307
237
if (! i_know_what_to_do_shut_up_i_dont_need_your_help_mode) {
308
- print " \n\ t php_error(E_WARNING, \" " funcs[ i] " : not yet implemented\" );" > stubfile
238
+ print " \t php_error(E_WARNING, \" " funcs[ i] " : not yet implemented\" );" > stubfile
309
239
}
310
240
print " }\n /* }}} */\n " > stubfile
311
241
0 commit comments