summaryrefslogtreecommitdiff
path: root/source4/build/pidl
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2004-09-12 02:37:15 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:58:40 -0500
commit67c37a3b8ed9a0c9b5cc95ba03a921cf32e3cf3f (patch)
tree8234295a649dd5f012abdd959af7b6be64d9c223 /source4/build/pidl
parent7cbd43a1f7fed869703ab93ae0eee8a180a91c74 (diff)
downloadsamba-67c37a3b8ed9a0c9b5cc95ba03a921cf32e3cf3f.tar.gz
samba-67c37a3b8ed9a0c9b5cc95ba03a921cf32e3cf3f.tar.bz2
samba-67c37a3b8ed9a0c9b5cc95ba03a921cf32e3cf3f.zip
r2289: Autogenerate some more attractive looking stubs for converting
function argument structures and idl structures to and from Python dictionaries. (This used to be commit e4729949c61a8df23b5132c6136ae8c3777c348a)
Diffstat (limited to 'source4/build/pidl')
-rw-r--r--source4/build/pidl/swig.pm82
1 files changed, 61 insertions, 21 deletions
diff --git a/source4/build/pidl/swig.pm b/source4/build/pidl/swig.pm
index 459826dd9d..59eb493bf2 100644
--- a/source4/build/pidl/swig.pm
+++ b/source4/build/pidl/swig.pm
@@ -15,27 +15,52 @@ sub ParseFunction($)
{
my($fn) = shift;
+ $res .= "%{\n\n";
+
+ $res .= "/* Convert Python dict to struct $fn->{NAME}.in */\n\n";
+
+ $res .= "int python_to_$fn->{NAME}(TALLOC_CTX *mem_ctx, struct $fn->{NAME} *s, PyObject *obj)\n";
+ $res .= "{\n";
+
+ foreach my $e (@{$fn->{DATA}}) {
+ if (util::has_property($e, "in")) {
+ $res .= "\t// $e->{TYPE} $e->{NAME}\n";
+ }
+ }
+
+ $res .= "\n";
+ $res .= "\treturn True;\n";
+ $res .= "}\n\n";
+
+ $res .= "/* Convert struct $fn->{NAME}.out to Python dict */\n\n";
+
+ $res .= "int $fn->{NAME}_to_python(TALLOC_CTX *mem_ctx, PyObject *obj, struct $fn->{NAME} *s)\n";
+ $res .= "{\n";
+
+ foreach my $e (@{$fn->{DATA}}) {
+ if (util::has_property($e, "out")) {
+ $res .= "\t// $e->{TYPE} $e->{NAME}\n";
+ }
+ }
+
+ $res .= "\n";
+ $res .= "\treturn True;\n";
+ $res .= "}\n\n";
+
+ $res .= "%}\n\n";
+
# Input typemap
$res .= "%typemap(in) struct $fn->{NAME} * (struct $fn->{NAME} temp) {\n";
-# $res .= "\tif (!PyDict_Check(\$input)) {\n";
-# $res .= "\t\tPyErr_SetString(PyExc_TypeError, \"dict arg expected\");\n";
-# $res .= "\t\treturn NULL;\n";
-# $res .= "\t}\n\n";
- $res .= "\tmemset(&temp, 0, sizeof(temp));\n";
-# foreach my $e (@{$fn->{DATA}}) {
-# if (util::has_property($e, "in")) {
-# $res .= "\ttemp.in.$e->{NAME} = $e->{TYPE}_from_python(PyDict_GetItem(\$input, PyString_FromString(\"$e->{NAME}\")));\n";
-# }
-# }
-
-# $res .= "\n";
+ $res .= "\tTALLOC_CTX *mem_ctx = talloc_init(\"typemap(int) $fn->{NAME}\");\n\n";
+ $res .= "\tpython_to_$fn->{NAME}(mem_ctx, &temp, \$input);\n";
$res .= "\t\$1 = &temp;\n";
$res .= "}\n\n";
# Output typemap
$res .= "%typemap(argout) struct $fn->{NAME} * {\n";
+ $res .= "\tTALLOC_CTX *mem_ctx = talloc_init(\"typemap(argout) $fn->{NAME}\");\n\n";
$res .= "\tlong status = PyLong_AsLong(resultobj);\n";
$res .= "\tPyObject *dict;\n";
$res .= "\n";
@@ -46,14 +71,8 @@ sub ParseFunction($)
$res .= "\n";
$res .= "\tdict = PyDict_New();\n";
-# foreach my $e (@{$fn->{DATA}}) {
-# if (util::has_property($e, "out")) {
-# $res .= "\t// PyDict_SetItem(dict, PyString_FromString(\"$e->{NAME}\"),\n";
-# $res .= "\t//\t$e->{TYPE}_to_python(\$1->out.$e->{NAME}));\n";
-# }
-# }
+ $res .= "\t$fn->{NAME}_to_python(mem_ctx, dict, \$1);\n";
- $res .= "\n";
$res .= "\tresultobj = dict;\n";
$res .= "}\n\n";
@@ -68,11 +87,32 @@ sub ParseStruct($)
my($s) = shift;
$res .= "%{\n\n";
- $res .= "\t/* $s->{NAME} */\n\n";
+ $res .= "/* Convert Python dict to struct $s->{NAME} */\n\n";
+ $res .= "int python_to_$s->{NAME}(TALLOC_CTX *mem_ctx, struct $s->{NAME} *s, PyObject *obj)\n";
+ $res .= "{\n";
+
foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
+ $res .= "\t// $e->{TYPE} $e->{NAME}\n";
}
+ $res .= "\n";
+ $res .= "\treturn TRUE;\n";
+ $res .= "}\n\n";
+
+ $res .= "/* Convert struct $s->{NAME} to Python dict */\n\n";
+
+ $res .= "int $s->{NAME}_to_python(TALLOC_CTX *mem_ctx, PyObject *obj, struct $s->{NAME} *s)\n";
+ $res .= "{\n";
+
+ foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
+ $res .= "\t// $e->{TYPE} $e->{NAME}\n";
+ }
+
+ $res .= "\n";
+ $res .= "\treturn TRUE;\n";
+ $res .= "}\n";
+
$res .= "\n%}\n\n";
}
@@ -111,7 +151,7 @@ sub ParseHeader($)
sub Parse($)
{
my($idl) = shift;
-
+
$res = "/* auto-generated by pidl */\n\n";
foreach my $x (@{$idl}) {