diff options
author | Tim Potter <tpot@samba.org> | 2005-01-29 00:19:23 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:09:19 -0500 |
commit | edf62429fa1594f456440c3afffcb7e9647ba46d (patch) | |
tree | c29f5bdd8ad641c99e36ad987e0d7f79ca7a9e89 /source4/build/pidl | |
parent | ebf1d799868ff4a8658d50463c9111662c31c76d (diff) | |
download | samba-edf62429fa1594f456440c3afffcb7e9647ba46d.tar.gz samba-edf62429fa1594f456440c3afffcb7e9647ba46d.tar.bz2 samba-edf62429fa1594f456440c3afffcb7e9647ba46d.zip |
r5072: oDecrease the amount of autogenerated code (sorry tridge) and use swig's
structure mapping features instead of doing it all ourselves.
This basically works, but has broken all the existing checked in Python
code.
Sample:
pipe = dcerpc.pipe_connect(binding,
dcerpc.DCERPC_SAMR_UUID, int(dcerpc.DCERPC_SAMR_VERSION),
domain, username, password)
r = dcerpc.samr_Connect2()
r.data_in.system_name = 'foo'
r.data_in.access_mask = 0x02000000
result = dcerpc.dcerpc_samr_Connect2(pipe, r)
(This used to be commit c2996ad910a24c977b4c0a1925118d36454514f7)
Diffstat (limited to 'source4/build/pidl')
-rw-r--r-- | source4/build/pidl/swig.pm | 125 |
1 files changed, 62 insertions, 63 deletions
diff --git a/source4/build/pidl/swig.pm b/source4/build/pidl/swig.pm index afb6364721..68d67b4879 100644 --- a/source4/build/pidl/swig.pm +++ b/source4/build/pidl/swig.pm @@ -257,68 +257,6 @@ sub ParseFunction($) $result .= IdlDump::DumpFunction($fn); $result .= "*/\n\n"; - # Generate function to convert Python dict to structure pointer - - $result .= "/* Convert Python dict to struct $fn->{NAME}.in */\n\n"; - - $result .= "struct $fn->{NAME} *$fn->{NAME}_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj, char *name)\n"; - $result .= "{\n"; - - $result .= "\tstruct $fn->{NAME} *s;\n\n"; - - $result .= "\tif (!PyDict_Check(obj)) {\n"; - $result .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for key '%s'\", name);\n"; - $result .= "\t\t\treturn NULL;\n"; - $result .= "\t}\n\n"; - - $result .= "\ts = talloc_p(mem_ctx, struct $fn->{NAME});\n\n"; - - # Remove this when all elements are initialised - $result .= "\tmemset(s, 0, sizeof(struct $fn->{NAME}));\n\n"; - - foreach my $e (@{$fn->{DATA}}) { - if (util::has_property($e, "in")) { - if (util::has_property($e, "ref")) { - $result .= "\tif (PyDict_GetItemString(obj, \"$e->{NAME}\") == Py_None) {\n"; - $result .= "\t\tPyErr_Format(PyExc_ValueError, \"Key '$e->{NAME}' cannot be None\");\n"; - $result .= "\t\treturn NULL;\n"; - $result .= "\t}\n"; - } - $result .= FieldFromPython($e, "in.") ; - } - } - - $result .= "\n"; - $result .= "\treturn s;\n"; - $result .= "}\n\n"; - - # Generate function to convert structure pointer to Python dict - - $result .= "/* Convert struct $fn->{NAME}.out to Python dict */\n\n"; - - $result .= "PyObject *$fn->{NAME}_ptr_to_python(TALLOC_CTX *mem_ctx, struct $fn->{NAME} *s"; - - foreach my $e (@{$fn->{DATA}}) { - if (isunion($e->{TYPE})) { - $result .= ", int $e->{NAME}_switch_is"; - } - } - $result .= ")\n"; - - $result .= "{\n"; - - $result .= "\tPyObject *obj = PyDict_New();\n\n"; - - foreach my $e (@{$fn->{DATA}}) { - $result .= FieldToPython($e, "out.") if util::has_property($e, "out") - } - - $result .= "\n"; - $result .= "\treturn obj;\n"; - $result .= "}\n\n"; - - $result .= "%}\n\n"; - # Input typemap $result .= "%typemap(in) struct $fn->{NAME} * {\n"; @@ -689,7 +627,6 @@ sub ParseInheritedData($) foreach my $e (@{$data}) { $result .= ParseFunction($e) if $e->{TYPE} eq "FUNCTION"; - $result .= ParseTypedef($e) if $e->{TYPE} eq "TYPEDEF"; } return $result; @@ -744,4 +681,66 @@ sub Parse($) return $result; } +sub pidl($) +{ + print OUT shift; +} + +##################################################################### +# rewrite autogenerated header file +sub RewriteHeader($$$) +{ + my($idl) = shift; + my($input) = shift; + my($output) = shift; + + open(IN, "<$input") || die "can't open $input for reading"; + open(OUT, ">$output") || die "can't open $output for writing"; + + pidl "%{\n"; + pidl "#define data_in in\n"; + pidl "#define data_out out\n"; + pidl "%}\n\n"; + + while(<IN>) { + + # Copy structure definitions + + if (/^struct .*? {$/ .. /^\};$/) { + s/\} (in|out);/\} data_$1;/; # "in" is a Python keyword + pidl $_; + next; + } + + # Copy dcerpc functions + + pidl $_ if /^NTSTATUS dcerpc_.*?\(struct dcerpc_pipe/; + + # Copy interface definitions + + pidl $_ + if /^\#define DCERPC_.*?_UUID/ or /^\#define DCERPC_.*?_VERSION/; + } + + close(OUT); +} + +##################################################################### +# rewrite autogenerated header file +sub RewriteC($$$) +{ + my($idl) = shift; + my($input) = shift; + my($output) = shift; + + open(IN, "<$input") || die "can't open $input for reading"; + open(OUT, ">>$output") || die "can't open $output for writing"; + + while(<IN>) { + } + + close(OUT); +} + + 1; |