summaryrefslogtreecommitdiff
path: root/source4/pidl/lib/Parse
diff options
context:
space:
mode:
Diffstat (limited to 'source4/pidl/lib/Parse')
-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;