+ {
+ const char *test_str;
+ const char *talloc_str;
+ PyObject *unicode = NULL;
+ if (PyUnicode_Check(py_s1)) {
+ unicode = PyUnicode_AsEncodedString(py_s1, "utf-8", "ignore");
+ if (unicode == NULL) {
+ PyErr_NoMemory();
+ return false;
+ }
+ test_str = PyString_AS_STRING(unicode);
+ } else if (PyString_Check(py_s1)) {
+ test_str = PyString_AS_STRING(py_s1);
+ } else {
+ PyErr_Format(PyExc_TypeError, "Expected string or unicode object, got %s", Py_TYPE(py_s1)->tp_name);
+ return false;
+ }
+ talloc_str = talloc_strdup(r, test_str);
+ if (unicode != NULL) {
+ Py_DECREF(unicode);
+ }
+ if (talloc_str == NULL) {
+ PyErr_NoMemory();
+ return false;
+ }
+ r->in.s1 = talloc_str;
+ }