svn commit: samba r2289 - in branches/SAMBA_4_0/source/build/pidl: .
tpot at samba.org
tpot at samba.org
Sun Sep 12 02:37:15 GMT 2004
Author: tpot
Date: 2004-09-12 02:37:15 +0000 (Sun, 12 Sep 2004)
New Revision: 2289
WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source/build/pidl&rev=2289&nolog=1
Log:
Autogenerate some more attractive looking stubs for converting
function argument structures and idl structures to and from Python
dictionaries.
Modified:
branches/SAMBA_4_0/source/build/pidl/swig.pm
Changeset:
Modified: branches/SAMBA_4_0/source/build/pidl/swig.pm
===================================================================
--- branches/SAMBA_4_0/source/build/pidl/swig.pm 2004-09-12 02:25:58 UTC (rev 2288)
+++ branches/SAMBA_4_0/source/build/pidl/swig.pm 2004-09-12 02:37:15 UTC (rev 2289)
@@ -15,27 +15,52 @@
{
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 @@
$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 @@
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 Parse($)
{
my($idl) = shift;
-
+
$res = "/* auto-generated by pidl */\n\n";
foreach my $x (@{$idl}) {
More information about the samba-cvs
mailing list