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.
This commit is contained in:
Marc-André Lemburg 2000-09-19 21:04:18 +00:00
parent f8d071332a
commit d1ba443206
8 changed files with 127 additions and 20 deletions

View file

@ -103,6 +103,21 @@ extern DL_IMPORT(PyObject*) PyString_AsEncodedString(
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