s4:pyrpc: add py_dcerpc_ndr_pointer_deref/wrap() infrastructure
[gd/samba-autobuild/.git] / source4 / librpc / rpc / pyrpc_util.c
index cc67dfcdc3f6a5e925675ee2f247994084b9c4d3..3a151e1591f4149afeb48bf9f08c70026ed2beb8 100644 (file)
@@ -448,3 +448,32 @@ void *pyrpc_export_union(PyTypeObject *type, TALLOC_CTX *mem_ctx, int level,
        Py_XDECREF(ret_obj);
        return ret;
 }
+
+PyObject *py_dcerpc_ndr_pointer_deref(PyTypeObject *type, PyObject *obj)
+{
+       if (!PyObject_TypeCheck(obj, type)) {
+               PyErr_Format(PyExc_TypeError,
+                            "Expected type '%s' but got type '%s'",
+                            (type)->tp_name, Py_TYPE(obj)->tp_name);
+               return NULL;
+       }
+
+       return PyObject_GetAttrString(obj, discard_const_p(char, "value"));
+}
+
+PyObject *py_dcerpc_ndr_pointer_wrap(PyTypeObject *type, PyObject *obj)
+{
+       PyObject *args = NULL;
+       PyObject *ret_obj = NULL;
+
+       args = PyTuple_New(1);
+       if (args == NULL) {
+               return NULL;
+       }
+       Py_XINCREF(obj);
+       PyTuple_SetItem(args, 0, obj);
+
+       ret_obj = PyObject_Call((PyObject *)type, args, NULL);
+       Py_XDECREF(args);
+       return ret_obj;
+}