return PyStr_FromString(str);
}
+const char *pyrpc_PyStr_AsString(TALLOC_CTX *mem_ctx, PyObject *value)
+{
+ const char *test_str = NULL;
+ const char *talloc_str = NULL;
+ PyObject *unicode = NULL;
+
+ if (PyUnicode_Check(value)) {
+ unicode = PyUnicode_AsEncodedString(value, "utf-8", "ignore");
+ if (unicode == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ test_str = PyBytes_AS_STRING(unicode);
+ } else if (PyBytes_Check(value)) {
+ test_str = PyBytes_AS_STRING(value);
+ } else {
+ PyErr_Format(PyExc_TypeError,
+ "Expected string or unicode object, got %s",
+ Py_TYPE(value)->tp_name);
+ return NULL;
+ }
+
+ talloc_str = talloc_strdup(mem_ctx, test_str);
+ if (unicode != NULL) {
+ Py_DECREF(unicode);
+ }
+ if (talloc_str == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ return talloc_str;
+}
+
PyObject *pyrpc_import_union(PyTypeObject *type, TALLOC_CTX *mem_ctx, int level,
const void *in, const char *typename)
{
TALLOC_CTX *r_ctx, void *r);
PyObject *PyString_FromStringOrNULL(const char *str);
+const char *pyrpc_PyStr_AsString(TALLOC_CTX *mem_ctx, PyObject *value);
PyObject *pyrpc_import_union(PyTypeObject *type, TALLOC_CTX *mem_ctx, int level,
const void *in, const char *typename);