This patch adds a new Python C API called PyString_AsStringAndSize()
which implements the automatic conversion from Unicode to a string
object using the default encoding.
The new API is then put to use to have eval() and exec accept
Unicode objects as code parameter. This closes bugs #110924
and #113890.
As side-effect, the traditional C APIs PyString_Size() and
PyString_AsString() will also accept Unicode objects as
parameters.
diff --git a/Include/stringobject.h b/Include/stringobject.h
index 7afd347..3bba7bc 100644
--- a/Include/stringobject.h
+++ b/Include/stringobject.h
@@ -103,6 +103,21 @@
const char *errors /* error handling */
);
+/* Provides access to the internal data buffer and size of a string
+ object or the default encoded version of an Unicode object. Passing
+ NULL as *len parameter will force the string buffer to be
+ 0-terminated (passing a string with embedded NULL characters will
+ cause an exception). */
+
+extern DL_IMPORT(int) PyString_AsStringAndSize(
+ register PyObject *obj, /* string or Unicode object */
+ register char **s, /* pointer to buffer variable */
+ register int *len /* pointer to length variable or NULL
+ (only possible for 0-terminated
+ strings) */
+ );
+
+
#ifdef __cplusplus
}
#endif