From d072e9e2ca7df4f53a581156614f0c2658af1f05 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 20 Sep 2004 02:50:43 +0000 Subject: r2426: Handle pointer to scalars converting C to Python. Peeked at parser.pm for some hints at getting array lengths right when the length_is property is present. (This used to be commit a17aaadb7d57dbe4cf0a62634f405c61b79a953f) --- source4/build/pidl/swig.pm | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'source4/build/pidl') diff --git a/source4/build/pidl/swig.pm b/source4/build/pidl/swig.pm index 042587a538..e8928aae53 100644 --- a/source4/build/pidl/swig.pm +++ b/source4/build/pidl/swig.pm @@ -47,14 +47,22 @@ sub ArrayFromPython($$) my($prefix) = shift; my($result) = ""; - my($array_len) = $e->{ARRAY_LEN}; + $result .= "/* " . Dumper($e) . " */\n"; - if ($array_len eq "*") { - $array_len = util::has_property($e, "size_is"); + my($size); + + if (util::has_property($e, "size_is")) { + $size = util::has_property($e, "size_is"); + } else { + $size = $e->{ARRAY_LEN}; } - if (!util::is_constant($array_len)) { - $array_len = "s->$prefix$array_len"; + if (util::has_property($e, "length_is")) { + $size = util::has_property($e, "length_is"); + } + + if (!util::is_constant($size)) { + $size = "s->$prefix$size"; } my($type) = $e->{TYPE}; @@ -64,7 +72,7 @@ sub ArrayFromPython($$) } if (!util::is_constant($e->{ARRAY_LEN})) { - $result .= "\ts->$prefix$e->{NAME} = talloc(mem_ctx, $array_len * sizeof($type));\n"; + $result .= "\ts->$prefix$e->{NAME} = talloc(mem_ctx, $size * sizeof($type));\n"; } $result .= "\tif (!PyDict_GetItemString(obj, \"$e->{NAME}\")) {\n"; @@ -80,7 +88,7 @@ sub ArrayFromPython($$) $result .= "\t{\n"; $result .= "\t\tint i;\n\n"; - $result .= "\t\tfor (i = 0; i < $array_len; i++) {\n"; + $result .= "\t\tfor (i = 0; i < $size; i++) {\n"; if (util::is_scalar_type($e->{TYPE})) { $result .= "\t\t\ts->$prefix$e->{NAME}\[i\] = $e->{TYPE}_from_python(PyList_GetItem(PyDict_GetItemString(obj, \"$e->{NAME}\"), i), \"$e->{NAME}\");\n"; } else { @@ -131,7 +139,11 @@ sub FieldFromPython($$) $result .= "\t$e->{TYPE}_from_python(mem_ctx, &s->$prefix$e->{NAME}, $obj, \"$e->{NAME}\");\n"; } } else { - $result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_ptr_from_python(mem_ctx, $obj, \"$e->{NAME}\");\n"; + if ($e->{ARRAY_LEN} or util::has_property($e, "size_is")) { + $result .= ArrayFromPython($e, $prefix); + } else { + $result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_ptr_from_python(mem_ctx, $obj, \"$e->{NAME}\");\n"; + } } } @@ -207,8 +219,12 @@ sub FieldToPython($$) $result .= "\tPyDict_SetItemString(obj, \"$e->{NAME}\", $e->{TYPE}_to_python(s->$prefix$e->{NAME}));\n"; } } else { - $result .= "\t// Pointer to scalar\n"; - $result .= DebugField($e); + if ($e->{ARRAY_LEN} or util::has_property($e, "size_is")) { + $result .= ArrayToPython($e, $prefix); + } else { + $result .= "\t// Pointer to scalar\n"; + $result .= DebugField($e); + } } } else { if ($e->{POINTERS} == 0) { -- cgit