Skip to content

Commit

Permalink
- Fix incorrect code creation when an optional argument is resource t…
Browse files Browse the repository at this point in the history
…ype.
  • Loading branch information
Jouni Ahto committed Jun 10, 2000
1 parent 77f4e1c commit 8842639
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
3 changes: 0 additions & 3 deletions README.EXT_SKEL
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 19 additions & 9 deletions ext/skeleton/create_stubs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ 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"
else if (t == "string") x = "convert_to_string_ex(" n ");\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"
Expand All @@ -31,7 +35,7 @@ BEGIN {
}

{
args_max = args_min = optional = 0
args_max = args_min = optional = i = 0
line = $0

func_type = gobble(type);
Expand All @@ -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++
}
}

Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 8842639

Please sign in to comment.