/* Converts a python string (8-bit or unicode) to a target string in the host's charset. Returns NULL on error, with a python exception set. */ gdb::unique_xmalloc_ptr<char> python_string_to_host_string (PyObject *obj) { gdbpy_ref<> str (python_string_to_unicode (obj)); if (str == NULL) return NULL; return unicode_to_encoded_string (str.get (), host_charset ()); }
/* Converts a python string (8-bit or unicode) to a target string in the target's charset. Returns NULL on error, with a python exception set. In Python 3, the returned object is a "bytes" object (not a string). */ PyObject * python_string_to_target_python_string (PyObject *obj) { gdbpy_ref<> str (python_string_to_unicode (obj)); if (str == NULL) return NULL; return unicode_to_target_python_string (str.get ()); }
/* Converts a python string (8-bit or unicode) to a target string in the host's charset. Returns NULL on error, with a python exception set. The caller is responsible for xfree'ing the string. */ char * python_string_to_host_string (PyObject *obj) { PyObject *str; char *result; str = python_string_to_unicode (obj); if (str == NULL) return NULL; result = unicode_to_encoded_string (str, host_charset ()); Py_DECREF (str); return result; }
/* Converts a python string (8-bit or unicode) to a target string in the target's charset. Returns NULL on error, with a python exception set. The caller is responsible for xfree'ing the string. */ char * python_string_to_target_string (PyObject *obj) { PyObject *str; char *result; str = python_string_to_unicode (obj); if (str == NULL) return NULL; result = unicode_to_target_string (str); Py_DECREF (str); return result; }