]> granicus.if.org Git - php/commitdiff
- Fix incorrect code creation when an optional argument is resource type.
authorJouni Ahto <jah@php.net>
Sat, 10 Jun 2000 09:45:27 +0000 (09:45 +0000)
committerJouni Ahto <jah@php.net>
Sat, 10 Jun 2000 09:45:27 +0000 (09:45 +0000)
README.EXT_SKEL
ext/skeleton/create_stubs

index 2b0fd48f945d042699f00a4a10ddc45499e0ca48..736bfc52cd1157e1baed640b7d03a41ece19ecf3 100644 (file)
@@ -71,9 +71,6 @@ CURRENT LIMITATIONS AND BUGS
   manually correct the switch construct created. But it's nothing more than
   deleting a few 'case ?:' lines and fixing PHP in-source documentation proto.
 
-  It creates incorrect code to handle arguments passed to function when an
-  optional argument is of type 'resource'.
-
 EXAMPLE
 
   The following _one_ line
index 8e7179cb3050d87fdcf4e7f668676bd2bc0e7e01..6db21ac390975349f6ff63e5c36589fb4ed9a471 100755 (executable)
@@ -9,7 +9,7 @@ function gobble(s, x)
        return x 
 }
 
-function convert(t, n)
+function convert(t, n, o, i)
 {
        if (t == "int") x = "convert_to_long_ex(" n ");\n"
        else if (t == "double") x = "convert_to_double_ex(" n ");\n"
@@ -17,7 +17,11 @@ function convert(t, n)
        else if (t == "array") x = "convert_to_array_ex(" n ");\n"
        else if (t == "resource") {
                x = "/* " n ": fetching resources already handled. */\n"
-               resources = resources "\tZEND_FETCH_RESOURCE(???, ???, " n ", " n "_id, \"???\", ???G());\n"
+               if (o) {
+                               resources = resources "\tif (argc > " i ") {\n\t\tZEND_FETCH_RESOURCE(???, ???, " n ", " n "_id, \"???\", ???G());\n\t}\n"
+               } else {
+                               resources = resources "\tZEND_FETCH_RESOURCE(???, ???, " n ", " n "_id, \"???\", ???G());\n"
+               }
                funcvals = funcvals "\tint " n "_id = -1;\n"
        }
        else x = "/* You must write your own code here to handle argument " n ". */\n"
@@ -31,7 +35,7 @@ BEGIN {
 }
 
 {
-       args_max = args_min = optional = 0
+       args_max = args_min = optional = i = 0
        line = $0
 
        func_type = gobble(type);
@@ -45,10 +49,16 @@ BEGIN {
                        argnames[num_funcs,args_max] = arg_name
 
                        args_max++
-                       if (!optional) args_min++
+                       if (optional) {
+                                       optionals[num_funcs,i] = optional
+                       } else {
+                                       args_min++
+                       }
+
+                       if (gobble("\\[")) optional++
 
-                       if (gobble("\\[")) optional = 1
                        gobble(",")
+                       i++
                }
        }
 
@@ -98,14 +108,14 @@ END {
 
                        if (useswitch) {
                                if (j > minargs[i]-1) {
-                                       handleargs = "\t\tcase " j+1 ":\n\t\t\t" convert(argtypes[i,j], argnames[i,j]) "\t\t\t/* Fall-through. */\n" handleargs
+                                       handleargs = "\t\tcase " j+1 ":\n\t\t\t" convert(argtypes[i,j], argnames[i,j], optionals[i,j], j) "\t\t\t/* Fall-through. */\n" handleargs
                                } else if (j >= minargs[i]-1) {
-                                       handleargs = "\t\tcase " j+1 ":\n\t\t\t" convert(argtypes[i,j], argnames[i,j]) handleargs
+                                       handleargs = "\t\tcase " j+1 ":\n\t\t\t" convert(argtypes[i,j], argnames[i,j], optionals[i,j], j) handleargs
                                } else {
-                                       handleargs = "\t\t\t" convert(argtypes[i,j], argnames[i,j]) handleargs
+                                       handleargs = "\t\t\t" convert(argtypes[i,j], argnames[i,j], optionals[i,j], j) handleargs
                                }
                        } else {
-                               handleargs = handleargs "\t" convert(argtypes[i,j], argnames[i,j])
+                               handleargs = handleargs "\t" convert(argtypes[i,j], argnames[i,j], optionals[i,j], j)
                        }
                }