+ Py_DECREF(module);
+ return NULL;
+ }
+
+ result = pytalloc_reference_ex(py_type, r_ctx, r);
+ Py_CLEAR(module);
+ Py_CLEAR(py_type);
+ return result;
+}
+
+PyObject *PyString_FromStringOrNULL(const char *str)
+{
+ if (str == NULL) {
+ Py_RETURN_NONE;
+ }
+ return PyStr_FromString(str);
+}
+
+PyObject *pyrpc_import_union(PyTypeObject *type, TALLOC_CTX *mem_ctx, int level,
+ const void *in, const char *typename)
+{
+ PyObject *mem_ctx_obj = NULL;
+ PyObject *in_obj = NULL;
+ PyObject *ret = NULL;
+
+ mem_ctx_obj = pytalloc_GenericObject_reference(mem_ctx);
+ if (mem_ctx_obj == NULL) {
+ return NULL;
+ }
+
+ in_obj = pytalloc_GenericObject_reference_ex(mem_ctx, discard_const(in));
+ if (in_obj == NULL) {
+ Py_XDECREF(mem_ctx_obj);
+ return NULL;
+ }
+
+ ret = PyObject_CallMethod((PyObject *)type,
+ discard_const_p(char, "__import__"),
+ discard_const_p(char, "OiO"),
+ mem_ctx_obj, level, in_obj);
+ Py_XDECREF(mem_ctx_obj);
+ Py_XDECREF(in_obj);
+ if (ret == NULL) {
+ return NULL;
+ }
+
+ return ret;
+}
+
+void *pyrpc_export_union(PyTypeObject *type, TALLOC_CTX *mem_ctx, int level,
+ PyObject *in, const char *typename)
+{
+ PyObject *mem_ctx_obj = NULL;
+ PyObject *ret_obj = NULL;
+ void *ret = NULL;
+
+ mem_ctx_obj = pytalloc_GenericObject_reference(mem_ctx);
+ if (mem_ctx_obj == NULL) {
+ return NULL;
+ }
+
+ ret_obj = PyObject_CallMethod((PyObject *)type,
+ discard_const_p(char, "__export__"),
+ discard_const_p(char, "OiO"),
+ mem_ctx_obj, level, in);
+ Py_XDECREF(mem_ctx_obj);
+ if (ret_obj == NULL) {
+ return NULL;
+ }
+
+ ret = _pytalloc_get_type(ret_obj, typename);
+ 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) {