mirror of
https://github.com/python/cpython.git
synced 2025-10-28 17:13:08 +00:00
Py_USING_UNICODE is no longer defined on Windows (on posix it is still
in pyconfig.h). Remove the workaround for the broken (in Python 2.3) PyUnicode_(From|As)WideChar functions.
This commit is contained in:
parent
e409b97950
commit
5fa3f0517b
2 changed files with 1 additions and 80 deletions
|
|
@ -4828,72 +4828,6 @@ init_ctypes(void)
|
||||||
init_callbacks_in_module(m);
|
init_callbacks_in_module(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************
|
|
||||||
* replacements for broken Python api functions (in Python 2.3).
|
|
||||||
* See #1047269 Buffer overwrite in PyUnicode_AsWideChar
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_WCHAR_H
|
|
||||||
|
|
||||||
PyObject *My_PyUnicode_FromWideChar(register const wchar_t *w,
|
|
||||||
Py_ssize_t size)
|
|
||||||
{
|
|
||||||
PyUnicodeObject *unicode;
|
|
||||||
|
|
||||||
if (w == NULL) {
|
|
||||||
PyErr_BadInternalCall();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
unicode = (PyUnicodeObject *)PyUnicode_FromUnicode(NULL, size);
|
|
||||||
if (!unicode)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/* Copy the wchar_t data into the new object */
|
|
||||||
#ifdef HAVE_USABLE_WCHAR_T
|
|
||||||
memcpy(unicode->str, w, size * sizeof(wchar_t));
|
|
||||||
#else
|
|
||||||
{
|
|
||||||
register Py_UNICODE *u;
|
|
||||||
register int i;
|
|
||||||
u = PyUnicode_AS_UNICODE(unicode);
|
|
||||||
/* In Python, the following line has a one-off error */
|
|
||||||
for (i = size; i > 0; i--)
|
|
||||||
*u++ = *w++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return (PyObject *)unicode;
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_ssize_t My_PyUnicode_AsWideChar(PyUnicodeObject *unicode,
|
|
||||||
register wchar_t *w,
|
|
||||||
Py_ssize_t size)
|
|
||||||
{
|
|
||||||
if (unicode == NULL) {
|
|
||||||
PyErr_BadInternalCall();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (size > PyUnicode_GET_SIZE(unicode))
|
|
||||||
size = PyUnicode_GET_SIZE(unicode);
|
|
||||||
#ifdef HAVE_USABLE_WCHAR_T
|
|
||||||
memcpy(w, unicode->str, size * sizeof(wchar_t));
|
|
||||||
#else
|
|
||||||
{
|
|
||||||
register Py_UNICODE *u;
|
|
||||||
register int i;
|
|
||||||
u = PyUnicode_AS_UNICODE(unicode);
|
|
||||||
/* In Python, the following line has a one-off error */
|
|
||||||
for (i = size; i > 0; i--)
|
|
||||||
*w++ = *u++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Local Variables:
|
Local Variables:
|
||||||
compile-command: "cd .. && python setup.py -q build -g && python setup.py -q build install --home ~"
|
compile-command: "cd .. && python setup.py -q build -g && python setup.py -q build install --home ~"
|
||||||
|
|
|
||||||
|
|
@ -368,24 +368,11 @@ extern char *conversion_mode_errors;
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Python's PyUnicode_*WideChar functions are broken ... */
|
#if defined(HAVE_WCHAR_H)
|
||||||
#if defined(Py_USING_UNICODE) && defined(HAVE_WCHAR_H)
|
|
||||||
# define CTYPES_UNICODE
|
# define CTYPES_UNICODE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef CTYPES_UNICODE
|
|
||||||
# undef PyUnicode_FromWideChar
|
|
||||||
# define PyUnicode_FromWideChar My_PyUnicode_FromWideChar
|
|
||||||
|
|
||||||
# undef PyUnicode_AsWideChar
|
|
||||||
# define PyUnicode_AsWideChar My_PyUnicode_AsWideChar
|
|
||||||
|
|
||||||
extern PyObject *My_PyUnicode_FromWideChar(const wchar_t *, Py_ssize_t);
|
|
||||||
extern Py_ssize_t My_PyUnicode_AsWideChar(PyUnicodeObject *, wchar_t *, Py_ssize_t);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern void FreeClosure(void *);
|
extern void FreeClosure(void *);
|
||||||
extern void *MallocClosure(void);
|
extern void *MallocClosure(void);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue