summaryrefslogtreecommitdiff
path: root/source4/pidl/lib/Parse/Pidl/Samba4
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-05-24 19:49:54 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-05-24 19:49:54 +0200
commite3bbe61d8162ebb5bf4ef2d3702587b39b0c4284 (patch)
tree6589a3eeb39a2fb39573b547a1b79d73a9d9174e /source4/pidl/lib/Parse/Pidl/Samba4
parentf76697ce89606aa4e5ba1bb13f1fda6e33998695 (diff)
downloadsamba-e3bbe61d8162ebb5bf4ef2d3702587b39b0c4284.tar.gz
samba-e3bbe61d8162ebb5bf4ef2d3702587b39b0c4284.tar.bz2
samba-e3bbe61d8162ebb5bf4ef2d3702587b39b0c4284.zip
Only provide __ndr_pack__ / __ndr_unpack__ if the push/pull functions are public.
(This used to be commit dd43bdcb880d08013a600f81d40e5280db74c534)
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl/Samba4')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/Python.pm103
1 files changed, 55 insertions, 48 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 56d54d3d36..b83f9a5360 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -227,54 +227,61 @@ sub PythonStruct($$$$$$)
$self->pidl("}");
$self->pidl("");
- $self->pidl("static PyObject *py_$name\_ndr_pack(PyObject *py_obj)");
- $self->pidl("{");
- $self->indent;
- $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);");
- $self->pidl("DATA_BLOB blob;");
- $self->pidl("enum ndr_err_code err;");
- $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, ndr_push_$name);");
- $self->pidl("if (err != NDR_ERR_SUCCESS) {");
- $self->indent;
- $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr pack\");");
- $self->pidl("return NULL;");
- $self->deindent;
- $self->pidl("}");
- $self->pidl("");
- $self->pidl("return PyString_FromStringAndSize((char *)blob.data, blob.length);");
- $self->deindent;
- $self->pidl("}");
- $self->pidl("");
+ my $py_methods = "NULL";
- $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)");
- $self->pidl("{");
- $self->indent;
- $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);");
- $self->pidl("DATA_BLOB blob;");
- $self->pidl("enum ndr_err_code err;");
- $self->pidl("if (!PyArg_ParseTuple(args, \"s#\", &blob.data, &blob.length))");
- $self->pidl("\treturn NULL;");
- $self->pidl("");
- $self->pidl("err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, ndr_pull_$name);");
- $self->pidl("if (err != NDR_ERR_SUCCESS) {");
- $self->indent;
- $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr unpack\");");
- $self->pidl("return NULL;");
- $self->deindent;
- $self->pidl("}");
- $self->pidl("");
- $self->pidl("return Py_None;");
- $self->deindent;
- $self->pidl("}");
- $self->pidl("");
- $self->pidl("static PyMethodDef py_$name\_methods[] = {");
- $self->indent;
- $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_NOARGS, \"S.pack() -> blob\\nNDR pack\" },");
- $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_VARARGS, \"S.unpack(blob) -> None\\nNDR unpack\" },");
- $self->pidl("{ NULL, NULL, 0, NULL }");
- $self->deindent;
- $self->pidl("};");
- $self->pidl("");
+ # If the struct is not public there ndr_pull/ndr_push functions will
+ # be static so not callable from here
+ if (has_property($d, "public")) {
+ $self->pidl("static PyObject *py_$name\_ndr_pack(PyObject *py_obj)");
+ $self->pidl("{");
+ $self->indent;
+ $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);");
+ $self->pidl("DATA_BLOB blob;");
+ $self->pidl("enum ndr_err_code err;");
+ $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_push_flags_fn_t)ndr_push_$name);");
+ $self->pidl("if (err != NDR_ERR_SUCCESS) {");
+ $self->indent;
+ $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr pack\");");
+ $self->pidl("return NULL;");
+ $self->deindent;
+ $self->pidl("}");
+ $self->pidl("");
+ $self->pidl("return PyString_FromStringAndSize((char *)blob.data, blob.length);");
+ $self->deindent;
+ $self->pidl("}");
+ $self->pidl("");
+
+ $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)");
+ $self->pidl("{");
+ $self->indent;
+ $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);");
+ $self->pidl("DATA_BLOB blob;");
+ $self->pidl("enum ndr_err_code err;");
+ $self->pidl("if (!PyArg_ParseTuple(args, \"(s#):__ndr_unpack__\", &blob.data, &blob.length))");
+ $self->pidl("\treturn NULL;");
+ $self->pidl("");
+ $self->pidl("err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_pull_flags_fn_t)ndr_pull_$name);");
+ $self->pidl("if (err != NDR_ERR_SUCCESS) {");
+ $self->indent;
+ $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr unpack\");");
+ $self->pidl("return NULL;");
+ $self->deindent;
+ $self->pidl("}");
+ $self->pidl("");
+ $self->pidl("return Py_None;");
+ $self->deindent;
+ $self->pidl("}");
+ $self->pidl("");
+ $py_methods = "py_$name\_methods";
+ $self->pidl("static PyMethodDef $py_methods\[] = {");
+ $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->pidl("{ NULL, NULL, 0, NULL }");
+ $self->deindent;
+ $self->pidl("};");
+ $self->pidl("");
+ }
$self->pidl_hdr("PyAPI_DATA(PyTypeObject) $name\_Type;\n");
$self->pidl_hdr("#define $name\_Check(op) PyObject_TypeCheck(op, &$name\_Type)\n");
@@ -291,7 +298,7 @@ sub PythonStruct($$$$$$)
$self->pidl(".tp_getset = $getsetters,");
$self->pidl(".tp_repr = py_talloc_default_repr,");
$self->pidl(".tp_doc = $docstring,");
- $self->pidl(".tp_methods = py_$name\_methods,");
+ $self->pidl(".tp_methods = $py_methods,");
$self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,");
$self->pidl(".tp_new = py_$name\_new,");
$self->deindent;