functions.
PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
const char **buffer,
- Py_ssize_t *buffer_len);
+ Py_ssize_t *buffer_len)
+ Py_DEPRECATED(3.0);
/*
Takes an arbitrary object which must support the (character,
an exception set.
*/
- PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);
+ PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj)
+ Py_DEPRECATED(3.0);
/*
Checks whether an arbitrary object supports the (character,
PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
const void **buffer,
- Py_ssize_t *buffer_len);
+ Py_ssize_t *buffer_len)
+ Py_DEPRECATED(3.0);
/*
Same as PyObject_AsCharBuffer() except that this API expects
PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
void **buffer,
- Py_ssize_t *buffer_len);
+ Py_ssize_t *buffer_len)
+ Py_DEPRECATED(3.0);
/*
Takes an arbitrary object which must support the (writable,
#ifndef Py_LIMITED_API
PyAPI_FUNC(void) _PyEval_FiniThreads(void);
#endif /* !Py_LIMITED_API */
-PyAPI_FUNC(void) PyEval_AcquireLock(void);
-PyAPI_FUNC(void) PyEval_ReleaseLock(void);
+PyAPI_FUNC(void) PyEval_AcquireLock(void) Py_DEPRECATED(3.2);
+PyAPI_FUNC(void) PyEval_ReleaseLock(void) /* Py_DEPRECATED(3.2) */;
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
PyAPI_FUNC(void) PyEval_ReInitThreads(void);
PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
#ifndef Py_LIMITED_API
-PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
+PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int) Py_DEPRECATED(3.3);
PyAPI_FUNC(PyObject *) PyLong_FromUnicodeObject(PyObject *u, int base);
PyAPI_FUNC(PyObject *) _PyLong_FromBytes(const char *, Py_ssize_t, int);
#endif
PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *);
PyAPI_FUNC(PyObject *) PyModule_GetNameObject(PyObject *);
PyAPI_FUNC(const char *) PyModule_GetName(PyObject *);
-PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *);
+PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *) Py_DEPRECATED(3.2);
PyAPI_FUNC(PyObject *) PyModule_GetFilenameObject(PyObject *);
#ifndef Py_LIMITED_API
PyAPI_FUNC(void) _PyModule_Clear(PyObject *);
);
#if defined(MS_WINDOWS) && !defined(Py_LIMITED_API)
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
- PyObject *, const Py_UNICODE *);
+ PyObject *, const Py_UNICODE *) Py_DEPRECATED(3.3);
#endif /* MS_WINDOWS */
PyAPI_FUNC(PyObject *) PyErr_Format(
#ifndef Py_LIMITED_API
/* XXX redeclare to use WSTRING */
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
- int, const Py_UNICODE *);
+ int, const Py_UNICODE *) Py_DEPRECATED(3.3);
#endif
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
);
#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
- PyObject *,int, const Py_UNICODE *);
+ PyObject *,int, const Py_UNICODE *) Py_DEPRECATED(3.3);
#endif
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
#endif /* MS_WINDOWS */
Py_ssize_t start,
Py_ssize_t end,
const char *reason /* UTF-8 encoded string */
- );
+ ) Py_DEPRECATED(3.3);
#endif
/* create a UnicodeTranslateError object */
Py_ssize_t start,
Py_ssize_t end,
const char *reason /* UTF-8 encoded string */
- );
+ ) Py_DEPRECATED(3.3);
PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
PyObject *object,
Py_ssize_t start,
#ifndef Py_LIMITED_API
#define PY_UNICODE_TYPE wchar_t
-typedef wchar_t Py_UNICODE;
+typedef wchar_t Py_UNICODE /* Py_DEPRECATED(3.3) */;
#endif
/* If the compiler provides a wchar_t type we try to support it
((void)PyUnicode_AsUnicode((PyObject *)(op)), \
assert(((PyASCIIObject *)(op))->wstr), \
PyUnicode_WSTR_LENGTH(op)))
+ /* Py_DEPRECATED(3.3) */
#define PyUnicode_GET_DATA_SIZE(op) \
(PyUnicode_GET_SIZE(op) * Py_UNICODE_SIZE)
+ /* Py_DEPRECATED(3.3) */
/* Alias for PyUnicode_AsUnicode(). This will create a wchar_t/Py_UNICODE
representation on demand. Using this macro is very inefficient now,
(assert(PyUnicode_Check(op)), \
(((PyASCIIObject *)(op))->wstr) ? (((PyASCIIObject *)(op))->wstr) : \
PyUnicode_AsUnicode((PyObject *)(op)))
+ /* Py_DEPRECATED(3.3) */
#define PyUnicode_AS_DATA(op) \
((const char *)(PyUnicode_AS_UNICODE(op)))
+ /* Py_DEPRECATED(3.3) */
/* --- Flexible String Representation Helper Macros (PEP 393) -------------- */
PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
const Py_UNICODE *u, /* Unicode buffer */
Py_ssize_t size /* size of buffer */
- );
+ ) /* Py_DEPRECATED(3.3) */;
#endif
/* Similar to PyUnicode_FromUnicode(), but u points to UTF-8 encoded bytes */
#ifndef Py_LIMITED_API
PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(
PyObject *unicode /* Unicode object */
- );
+ ) /* Py_DEPRECATED(3.3) */;
#endif
/* Return a read-only pointer to the Unicode object's internal
PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize(
PyObject *unicode, /* Unicode object */
Py_ssize_t *size /* location where to save the length */
- );
+ ) /* Py_DEPRECATED(3.3) */;
#endif
/* Get the length of the Unicode object. */
PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
PyObject *unicode /* Unicode object */
- );
+ ) Py_DEPRECATED(3.3);
/* Read a character from the string. */
#ifndef Py_LIMITED_API
/* Get the maximum ordinal for a Unicode character. */
-PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void);
+PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void) Py_DEPRECATED(3.3);
#endif
/* Resize a Unicode object. The length is the number of characters, except
Py_ssize_t size, /* number of Py_UNICODE chars to encode */
const char *encoding, /* encoding */
const char *errors /* error handling */
- );
+ ) Py_DEPRECATED(3.3);
#endif
/* Encodes a Unicode object and returns the result as Python
int base64SetO, /* Encode RFC2152 Set O characters in base64 */
int base64WhiteSpace, /* Encode whitespace (sp, ht, nl, cr) in base64 */
const char *errors /* error handling */
- );
+ ) Py_DEPRECATED(3.3);
PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF7(
PyObject *unicode, /* Unicode object */
int base64SetO, /* Encode RFC2152 Set O characters in base64 */
const Py_UNICODE *data, /* Unicode char buffer */
Py_ssize_t length, /* number of Py_UNICODE chars to encode */
const char *errors /* error handling */
- );
+ ) Py_DEPRECATED(3.3);
#endif
/* --- UTF-32 Codecs ------------------------------------------------------ */
Py_ssize_t length, /* number of Py_UNICODE chars to encode */
const char *errors, /* error handling */
int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */
- );
+ ) Py_DEPRECATED(3.3);
PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF32(
PyObject *object, /* Unicode object */
const char *errors, /* error handling */
Py_ssize_t length, /* number of Py_UNICODE chars to encode */
const char *errors, /* error handling */
int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */
- );
+ ) Py_DEPRECATED(3.3);
PyAPI_FUNC(PyObject*) _PyUnicode_EncodeUTF16(
PyObject* unicode, /* Unicode object */
const char *errors, /* error handling */
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape(
const Py_UNICODE *data, /* Unicode char buffer */
Py_ssize_t length /* Number of Py_UNICODE chars to encode */
- );
+ ) Py_DEPRECATED(3.3);
#endif
/* --- Raw-Unicode-Escape Codecs ------------------------------------------ */
PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape(
const Py_UNICODE *data, /* Unicode char buffer */
Py_ssize_t length /* Number of Py_UNICODE chars to encode */
- );
+ ) Py_DEPRECATED(3.3);
#endif
/* --- Unicode Internal Codec ---------------------------------------------
const Py_UNICODE *data, /* Unicode char buffer */
Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
const char *errors /* error handling */
- );
+ ) Py_DEPRECATED(3.3);
#endif
/* --- ASCII Codecs -------------------------------------------------------
const Py_UNICODE *data, /* Unicode char buffer */
Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
const char *errors /* error handling */
- );
+ ) Py_DEPRECATED(3.3);
#endif
/* --- Character Map Codecs -----------------------------------------------
PyObject *mapping, /* character mapping
(unicode ordinal -> char ordinal) */
const char *errors /* error handling */
- );
+ ) Py_DEPRECATED(3.3);
PyAPI_FUNC(PyObject*) _PyUnicode_EncodeCharmap(
PyObject *unicode, /* Unicode object */
PyObject *mapping, /* character mapping
Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
PyObject *table, /* Translate table */
const char *errors /* error handling */
- );
+ ) Py_DEPRECATED(3.3);
#endif
#ifdef MS_WINDOWS
const Py_UNICODE *data, /* Unicode char buffer */
Py_ssize_t length, /* number of Py_UNICODE chars to encode */
const char *errors /* error handling */
- );
+ ) Py_DEPRECATED(3.3);
#endif
PyAPI_FUNC(PyObject*) PyUnicode_EncodeCodePage(
Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
char *output, /* Output buffer; must have size >= length */
const char *errors /* error handling */
- );
+ ) /* Py_DEPRECATED(3.3) */;
#endif
/* Transforms code points that have decimal digit property to the
PyAPI_FUNC(PyObject*) PyUnicode_TransformDecimalToASCII(
Py_UNICODE *s, /* Unicode buffer */
Py_ssize_t length /* Number of Py_UNICODE chars to transform */
- );
+ ) /* Py_DEPRECATED(3.3) */;
#endif
/* Similar to PyUnicode_TransformDecimalToASCII(), but takes a PyObject
PyAPI_FUNC(Py_UCS4) _PyUnicode_ToLowercase(
Py_UCS4 ch /* Unicode character */
- );
+ ) /* Py_DEPRECATED(3.3) */;
PyAPI_FUNC(Py_UCS4) _PyUnicode_ToUppercase(
Py_UCS4 ch /* Unicode character */
- );
+ ) /* Py_DEPRECATED(3.3) */;
PyAPI_FUNC(Py_UCS4) _PyUnicode_ToTitlecase(
Py_UCS4 ch /* Unicode character */
- );
+ ) Py_DEPRECATED(3.3);
PyAPI_FUNC(int) _PyUnicode_ToLowerFull(
Py_UCS4 ch, /* Unicode character */
PyAPI_FUNC(size_t) Py_UNICODE_strlen(
const Py_UNICODE *u
- );
+ ) Py_DEPRECATED(3.3);
PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcpy(
Py_UNICODE *s1,
- const Py_UNICODE *s2);
+ const Py_UNICODE *s2) Py_DEPRECATED(3.3);
PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcat(
- Py_UNICODE *s1, const Py_UNICODE *s2);
+ Py_UNICODE *s1, const Py_UNICODE *s2) Py_DEPRECATED(3.3);
PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strncpy(
Py_UNICODE *s1,
const Py_UNICODE *s2,
- size_t n);
+ size_t n) Py_DEPRECATED(3.3);
PyAPI_FUNC(int) Py_UNICODE_strcmp(
const Py_UNICODE *s1,
const Py_UNICODE *s2
- );
+ ) Py_DEPRECATED(3.3);
PyAPI_FUNC(int) Py_UNICODE_strncmp(
const Py_UNICODE *s1,
const Py_UNICODE *s2,
size_t n
- );
+ ) Py_DEPRECATED(3.3);
PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr(
const Py_UNICODE *s,
Py_UNICODE c
- );
+ ) Py_DEPRECATED(3.3);
PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr(
const Py_UNICODE *s,
Py_UNICODE c
- );
+ ) Py_DEPRECATED(3.3);
PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int);
PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy(
PyObject *unicode
- );
+ ) Py_DEPRECATED(3.3);
#endif /* Py_LIMITED_API */
#if defined(Py_DEBUG) && !defined(Py_LIMITED_API)
C API
-----
+- Issue #19569: Compiler warnings are now emitted if use most of deprecated
+ functions.
+
- Issue #28426: Deprecated undocumented functions PyUnicode_AsEncodedObject(),
PyUnicode_AsDecodedObject(), PyUnicode_AsDecodedUnicode() and
PyUnicode_AsEncodedUnicode().
getargs_u(PyObject *self, PyObject *args)
{
Py_UNICODE *str;
- Py_ssize_t size;
if (!PyArg_ParseTuple(args, "u", &str))
return NULL;
- size = Py_UNICODE_strlen(str);
- return PyUnicode_FromUnicode(str, size);
+ return PyUnicode_FromWideChar(str, -1);
}
static PyObject *
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "u#", &str, &size))
return NULL;
- return PyUnicode_FromUnicode(str, size);
+ return PyUnicode_FromWideChar(str, size);
}
static PyObject *
getargs_Z(PyObject *self, PyObject *args)
{
Py_UNICODE *str;
- Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Z", &str))
return NULL;
if (str != NULL) {
- size = Py_UNICODE_strlen(str);
- return PyUnicode_FromUnicode(str, size);
+ return PyUnicode_FromWideChar(str, -1);
} else
Py_RETURN_NONE;
}
if (!PyArg_ParseTuple(args, "Z#", &str, &size))
return NULL;
if (str != NULL)
- return PyUnicode_FromUnicode(str, size);
+ return PyUnicode_FromWideChar(str, size);
else
Py_RETURN_NONE;
}
static PyObject *
u_getitem(arrayobject *ap, Py_ssize_t i)
{
- return PyUnicode_FromUnicode(&((Py_UNICODE *) ap->ob_item)[i], 1);
+ return PyUnicode_FromOrdinal(((Py_UNICODE *) ap->ob_item)[i]);
}
static int
"tounicode() may only be called on unicode type arrays");
return NULL;
}
- return PyUnicode_FromUnicode((Py_UNICODE *) self->ob_item, Py_SIZE(self));
+ return PyUnicode_FromWideChar((Py_UNICODE *) self->ob_item, Py_SIZE(self));
}
/*[clinic input]
/* We release the buffer right after use of this function which could
cause issues later on. Don't use these functions in new code.
*/
-int
-PyObject_AsCharBuffer(PyObject *obj,
- const char **buffer,
- Py_ssize_t *buffer_len)
-{
- return PyObject_AsReadBuffer(obj, (const void **)buffer, buffer_len);
-}
-
int
PyObject_CheckReadBuffer(PyObject *obj)
{
return 1;
}
-int PyObject_AsReadBuffer(PyObject *obj,
- const void **buffer,
- Py_ssize_t *buffer_len)
+static int
+as_read_buffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len)
{
Py_buffer view;
return 0;
}
+int
+PyObject_AsCharBuffer(PyObject *obj,
+ const char **buffer,
+ Py_ssize_t *buffer_len)
+{
+ return as_read_buffer(obj, (const void **)buffer, buffer_len);
+}
+
+int PyObject_AsReadBuffer(PyObject *obj,
+ const void **buffer,
+ Py_ssize_t *buffer_len)
+{
+ return as_read_buffer(obj, buffer, buffer_len);
+}
+
int PyObject_AsWriteBuffer(PyObject *obj,
void **buffer,
Py_ssize_t *buffer_len)
return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"),
it->it_seq, it->it_index);
} else {
- PyObject *u = PyUnicode_FromUnicode(NULL, 0);
- if (u == NULL)
- return NULL;
- return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), u);
+ return Py_BuildValue("N(())", _PyObject_GetBuiltin("iter"));
}
}
return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"),
it->it_seq, it->it_index);
} else {
- PyObject *u = PyUnicode_FromUnicode(NULL, 0);
- if (u == NULL)
- return NULL;
- return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), u);
+ return Py_BuildValue("N(())", _PyObject_GetBuiltin("iter"));
}
}
/* Check argument types */
if (argcount < 0 || kwonlyargcount < 0 || nlocals < 0 ||
- code == NULL ||
+ code == NULL || !PyBytes_Check(code) ||
consts == NULL || !PyTuple_Check(consts) ||
names == NULL || !PyTuple_Check(names) ||
varnames == NULL || !PyTuple_Check(varnames) ||
cellvars == NULL || !PyTuple_Check(cellvars) ||
name == NULL || !PyUnicode_Check(name) ||
filename == NULL || !PyUnicode_Check(filename) ||
- lnotab == NULL || !PyBytes_Check(lnotab) ||
- !PyObject_CheckReadBuffer(code)) {
+ lnotab == NULL || !PyBytes_Check(lnotab)) {
PyErr_BadInternalCall();
return NULL;
}
PyObject *
PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
{
- PyObject *v, *unicode = PyUnicode_FromUnicode(u, length);
+ PyObject *v, *unicode = PyUnicode_FromWideChar(u, length);
if (unicode == NULL)
return NULL;
v = PyLong_FromUnicodeObject(unicode, base);
PyObject *
PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size)
+{
+ if (u == NULL)
+ return (PyObject*)_PyUnicode_New(size);
+
+ if (size < 0) {
+ PyErr_BadInternalCall();
+ return NULL;
+ }
+
+ return PyUnicode_FromWideChar(u, size);
+}
+
+PyObject *
+PyUnicode_FromWideChar(const wchar_t *u, Py_ssize_t size)
{
PyObject *unicode;
Py_UCS4 maxchar = 0;
Py_ssize_t num_surrogates;
- if (u == NULL)
- return (PyObject*)_PyUnicode_New(size);
+ if (u == NULL && size != 0) {
+ PyErr_BadInternalCall();
+ return NULL;
+ }
+
+ if (size == -1) {
+ size = wcslen(u);
+ }
/* If the Unicode data is known at construction time, we can apply
some optimizations which share commonly used objects. */
return as_ucs4(string, NULL, 0, 1);
}
-#ifdef HAVE_WCHAR_H
-
-PyObject *
-PyUnicode_FromWideChar(const wchar_t *w, Py_ssize_t size)
-{
- if (w == NULL) {
- if (size == 0)
- _Py_RETURN_UNICODE_EMPTY();
- PyErr_BadInternalCall();
- return NULL;
- }
-
- if (size == -1) {
- size = wcslen(w);
- }
-
- return PyUnicode_FromUnicode(w, size);
-}
-
-#endif /* HAVE_WCHAR_H */
-
/* maximum number of characters required for output of %lld or %p.
We need at most ceil(log10(256)*SIZEOF_LONG_LONG) digits,
plus 1 for the sign. 53/22 is an upper bound for log10(256). */
{
PyObject *v, *unicode;
- unicode = PyUnicode_FromUnicode(s, size);
+ unicode = PyUnicode_FromWideChar(s, size);
if (unicode == NULL)
return NULL;
v = PyUnicode_AsEncodedString(unicode, encoding, errors);
PyErr_BadArgument();
goto onError;
}
- return PyUnicode_GET_SIZE(unicode);
+ if (_PyUnicode_WSTR(unicode) == NULL) {
+ if (PyUnicode_AsUnicode(unicode) == NULL)
+ goto onError;
+ }
+ return PyUnicode_WSTR_LENGTH(unicode);
onError:
return -1;
const char *errors)
{
PyObject *result;
- PyObject *tmp = PyUnicode_FromUnicode(s, size);
+ PyObject *tmp = PyUnicode_FromWideChar(s, size);
if (tmp == NULL)
return NULL;
result = _PyUnicode_EncodeUTF7(tmp, base64SetO,
{
PyObject *v, *unicode;
- unicode = PyUnicode_FromUnicode(s, size);
+ unicode = PyUnicode_FromWideChar(s, size);
if (unicode == NULL)
return NULL;
v = _PyUnicode_AsUTF8String(unicode, errors);
int byteorder)
{
PyObject *result;
- PyObject *tmp = PyUnicode_FromUnicode(s, size);
+ PyObject *tmp = PyUnicode_FromWideChar(s, size);
if (tmp == NULL)
return NULL;
result = _PyUnicode_EncodeUTF32(tmp, errors, byteorder);
int byteorder)
{
PyObject *result;
- PyObject *tmp = PyUnicode_FromUnicode(s, size);
+ PyObject *tmp = PyUnicode_FromWideChar(s, size);
if (tmp == NULL)
return NULL;
result = _PyUnicode_EncodeUTF16(tmp, errors, byteorder);
Py_ssize_t size)
{
PyObject *result;
- PyObject *tmp = PyUnicode_FromUnicode(s, size);
+ PyObject *tmp = PyUnicode_FromWideChar(s, size);
if (tmp == NULL) {
return NULL;
}
Py_ssize_t size)
{
PyObject *result;
- PyObject *tmp = PyUnicode_FromUnicode(s, size);
+ PyObject *tmp = PyUnicode_FromWideChar(s, size);
if (tmp == NULL)
return NULL;
result = PyUnicode_AsRawUnicodeEscapeString(tmp);
const char *errors)
{
PyObject *result;
- PyObject *unicode = PyUnicode_FromUnicode(p, size);
+ PyObject *unicode = PyUnicode_FromWideChar(p, size);
if (unicode == NULL)
return NULL;
result = unicode_encode_ucs1(unicode, errors, 256);
const char *errors)
{
PyObject *result;
- PyObject *unicode = PyUnicode_FromUnicode(p, size);
+ PyObject *unicode = PyUnicode_FromWideChar(p, size);
if (unicode == NULL)
return NULL;
result = unicode_encode_ucs1(unicode, errors, 128);
const char *errors)
{
PyObject *unicode, *res;
- unicode = PyUnicode_FromUnicode(p, size);
+ unicode = PyUnicode_FromWideChar(p, size);
if (unicode == NULL)
return NULL;
res = encode_code_page(CP_ACP, unicode, errors);
const char *errors)
{
PyObject *result;
- PyObject *unicode = PyUnicode_FromUnicode(p, size);
+ PyObject *unicode = PyUnicode_FromWideChar(p, size);
if (unicode == NULL)
return NULL;
result = _PyUnicode_EncodeCharmap(unicode, mapping, errors);
const char *errors)
{
PyObject *result;
- PyObject *unicode = PyUnicode_FromUnicode(p, size);
+ PyObject *unicode = PyUnicode_FromWideChar(p, size);
if (!unicode)
return NULL;
result = _PyUnicode_TranslateCharmap(unicode, mapping, errors);
return -1;
}
- unicode = PyUnicode_FromUnicode(s, length);
+ unicode = PyUnicode_FromWideChar(s, length);
if (unicode == NULL)
return -1;
- if (PyUnicode_READY(unicode) == -1) {
- Py_DECREF(unicode);
- return -1;
- }
kind = PyUnicode_KIND(unicode);
data = PyUnicode_DATA(unicode);
return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"),
it->it_seq, it->it_index);
} else {
- PyObject *u = PyUnicode_FromUnicode(NULL, 0);
+ PyObject *u = (PyObject *)_PyUnicode_New(0);
if (u == NULL)
return NULL;
return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), u);
size_t
Py_UNICODE_strlen(const Py_UNICODE *u)
{
- int res = 0;
- while(*u++)
- res++;
- return res;
+ return wcslen(u);
}
Py_UNICODE*
Py_UNICODE_strcat(Py_UNICODE *s1, const Py_UNICODE *s2)
{
Py_UNICODE *u1 = s1;
- u1 += Py_UNICODE_strlen(u1);
- Py_UNICODE_strcpy(u1, s2);
+ u1 += wcslen(u1);
+ while ((*u1++ = *s2++));
return s1;
}
Py_UNICODE_strrchr(const Py_UNICODE *s, Py_UNICODE c)
{
const Py_UNICODE *p;
- p = s + Py_UNICODE_strlen(s);
+ p = s + wcslen(s);
while (p != s) {
p--;
if (*p == c)
PyObject *
PyErr_SetFromErrnoWithUnicodeFilename(PyObject *exc, const Py_UNICODE *filename)
{
- PyObject *name = filename ?
- PyUnicode_FromUnicode(filename, wcslen(filename)) :
- NULL;
+ PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL;
PyObject *result = PyErr_SetFromErrnoWithFilenameObjects(exc, name, NULL);
Py_XDECREF(name);
return result;
int ierr,
const Py_UNICODE *filename)
{
- PyObject *name = filename ?
- PyUnicode_FromUnicode(filename, wcslen(filename)) :
- NULL;
+ PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL;
PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObjects(exc,
ierr,
name,
int ierr,
const Py_UNICODE *filename)
{
- PyObject *name = filename ?
- PyUnicode_FromUnicode(filename, wcslen(filename)) :
- NULL;
+ PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL;
PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObjects(
PyExc_OSError,
ierr, name, NULL);
*p = PyUnicode_AsUnicodeAndSize(arg, &len);
if (*p == NULL)
RETURN_ERR_OCCURRED;
- if (Py_UNICODE_strlen(*p) != (size_t)len) {
+ if (wcslen(*p) != (size_t)len) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
RETURN_ERR_OCCURRED;
}
(PyBytes_Check(arg) || PyByteArray_Check(arg))) {
s = arg;
Py_INCREF(s);
- if (PyObject_AsCharBuffer(s, &ptr, &size) < 0)
- return converterr("(AsCharBuffer failed)",
- arg, msgbuf, bufsize);
+ if (PyBytes_Check(arg)) {
+ size = PyBytes_GET_SIZE(s);
+ ptr = PyBytes_AS_STRING(s);
+ }
+ else {
+ size = PyByteArray_GET_SIZE(s);
+ ptr = PyByteArray_AS_STRING(s);
+ }
}
else if (PyUnicode_Check(arg)) {
/* Encode object; use default error handling */
}
else {
if (n < 0)
- n = Py_UNICODE_strlen(u);
- v = PyUnicode_FromUnicode(u, n);
+ n = wcslen(u);
+ v = PyUnicode_FromWideChar(u, n);
}
return v;
}