diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2008-12-21 21:10:40 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2008-12-21 21:10:40 +0100 |
commit | 7e651c7ef3afb4effa045fa84ee3a87ab8226995 (patch) | |
tree | 150c341474848f8e2bcc39c78c64dfc8f7925db9 /pidl | |
parent | 38a4749d2cf9266164527e2b3c14bc7e47b72326 (diff) | |
download | samba-7e651c7ef3afb4effa045fa84ee3a87ab8226995.tar.gz samba-7e651c7ef3afb4effa045fa84ee3a87ab8226995.tar.bz2 samba-7e651c7ef3afb4effa045fa84ee3a87ab8226995.zip |
Simplify customization of pidl-generated Python modules.
Diffstat (limited to 'pidl')
-rw-r--r-- | pidl/lib/Parse/Pidl/Samba4/Python.pm | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm index 69365416a5..73ae8350b1 100644 --- a/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -24,7 +24,7 @@ sub new($) { my ($class) = @_; my $self = { res => "", res_hdr => "", tabs => "", constants => {}, module_methods => [], module_objects => [], ready_types => [], - readycode => [] }; + patch_type_calls => [], readycode => [] }; bless($self, $class); } @@ -38,7 +38,9 @@ sub pidl($$) { my ($self, $d) = @_; if ($d) { - $self->{res} .= $self->{tabs}; + if ((!($d =~ /^#/))) { + $self->{res} .= $self->{tabs}; + } $self->{res} .= $d; } $self->{res} .= "\n"; @@ -279,11 +281,6 @@ sub PythonStruct($$$$$$) $self->indent; $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_NOARGS, \"S.pack() -> blob\\nNDR pack\" },"); $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS, \"S.unpack(blob) -> None\\nNDR unpack\" },"); - $self->deindent; - $self->pidl("#ifdef ".uc("py_$name\_extra_methods")); - $self->pidl("\t" .uc("py_$name\_extra_methods")); - $self->pidl("#endif"); - $self->indent; $self->pidl("{ NULL, NULL, 0, NULL }"); $self->deindent; $self->pidl("};"); @@ -294,11 +291,8 @@ sub PythonStruct($$$$$$) $self->pidl_hdr("#define $name\_Check(op) PyObject_TypeCheck(op, &$name\_Type)\n"); $self->pidl_hdr("#define $name\_CheckExact(op) ((op)->ob_type == &$name\_Type)\n"); $self->pidl_hdr("\n"); - $self->pidl("#ifndef ".uc("py_$name\_repr")); - $self->pidl("#define ".uc("py_$name\_repr") . " py_talloc_default_repr"); - $self->pidl("#endif"); $self->pidl(""); - my $docstring = ($self->DocString($d, $name) or "NULL"); + my $docstring = $self->DocString($d, $name); my $typeobject = "$name\_Type"; $self->pidl("PyTypeObject $typeobject = {"); $self->indent; @@ -307,8 +301,10 @@ sub PythonStruct($$$$$$) $self->pidl(".tp_basicsize = sizeof(py_talloc_Object),"); $self->pidl(".tp_dealloc = py_talloc_dealloc,"); $self->pidl(".tp_getset = $getsetters,"); - $self->pidl(".tp_repr = ".uc("py_$name\_repr").","); - $self->pidl(".tp_doc = $docstring,"); + $self->pidl(".tp_repr = py_talloc_default_repr,"); + if ($docstring) { + $self->pidl(".tp_doc = $docstring,"); + } $self->pidl(".tp_methods = $py_methods,"); $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); $self->pidl(".tp_new = py_$name\_new,"); @@ -815,6 +811,8 @@ sub register_module_typeobject($$$) $self->register_module_object($name, "(PyObject *)$py_name"); $self->check_ready_type($py_name); + + $self->register_patch_type_call($name, $py_name); } sub check_ready_type($$) @@ -823,6 +821,14 @@ sub check_ready_type($$) push (@{$self->{ready_types}}, $py_name) unless (grep(/^$py_name$/,@{$self->{ready_types}})); } +sub register_patch_type_call($$$) +{ + my ($self, $typename, $cvar) = @_; + + push(@{$self->{patch_type_calls}}, [$typename, $cvar]); + +} + sub register_module_readycode($$) { my ($self, $code) = @_; @@ -1184,12 +1190,6 @@ sub Parse($$$$$) $self->pidl("{ \"$fn_name\", (PyCFunction)$pyfn_name, $flags, $doc },"); } - $self->deindent; - $self->pidl("#ifdef ".uc("py_mod_$basename\_extra_methods")); - $self->pidl("\t" .uc("py_mod_$basename\_extra_methods")); - $self->pidl("#endif"); - $self->indent; - $self->pidl("{ NULL, NULL, 0, NULL }"); $self->deindent; $self->pidl("};"); @@ -1209,6 +1209,13 @@ sub Parse($$$$$) $self->pidl($_) foreach (@{$self->{readycode}}); + foreach (@{$self->{patch_type_calls}}) { + my ($typename, $cvar) = @$_; + $self->pidl("#ifdef PY_".uc($typename)."_PATCH"); + $self->pidl("PY_".uc($typename)."_PATCH($cvar);"); + $self->pidl("#endif"); + } + $self->pidl(""); $self->pidl("m = Py_InitModule3(\"$basename\", $basename\_methods, \"$basename DCE/RPC\");"); @@ -1235,6 +1242,10 @@ sub Parse($$$$$) $self->pidl("PyModule_AddObject(m, \"$object_name\", $c_name);"); } + $self->pidl("#ifdef PY_MOD_".uc($basename)."_PATCH"); + $self->pidl("PY_MOD_".uc($basename)."_PATCH(m);"); + $self->pidl("#endif"); + $self->pidl(""); $self->deindent; $self->pidl("}"); |