summaryrefslogtreecommitdiffstats
path: root/Modules/_codecsmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-11-10 19:56:30 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-11-10 19:56:30 (GMT)
commit9f4b1e9c50da83b51a4b0c7ee7d7dc3ef94a0cf6 (patch)
treedc0742e3af4ceb33102cd7fe0a0deb38588d851f /Modules/_codecsmodule.c
parent240c55f721aee364f7fc341f86c5a25ab5c97095 (diff)
downloadcpython-9f4b1e9c50da83b51a4b0c7ee7d7dc3ef94a0cf6.zip
cpython-9f4b1e9c50da83b51a4b0c7ee7d7dc3ef94a0cf6.tar.gz
cpython-9f4b1e9c50da83b51a4b0c7ee7d7dc3ef94a0cf6.tar.bz2
Fix and deprecated the unicode_internal codec
unicode_internal codec uses Py_UNICODE instead of the real internal representation (PEP 393: Py_UCS1, Py_UCS2 or Py_UCS4) for backward compatibility.
Diffstat (limited to 'Modules/_codecsmodule.c')
-rw-r--r--Modules/_codecsmodule.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index 727cf5e..93cb1b7 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -675,18 +675,30 @@ unicode_internal_encode(PyObject *self,
PyObject *obj;
const char *errors = NULL;
const char *data;
- Py_ssize_t size;
+ Py_ssize_t len, size;
if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode",
&obj, &errors))
return NULL;
if (PyUnicode_Check(obj)) {
+ Py_UNICODE *u;
+
if (PyUnicode_READY(obj) < 0)
return NULL;
- data = PyUnicode_AS_DATA(obj);
- size = PyUnicode_GET_DATA_SIZE(obj);
- return codec_tuple(PyBytes_FromStringAndSize(data, size),
+
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "unicode_internal codecs has been deprecated",
+ 1))
+ return NULL;
+
+ u = PyUnicode_AsUnicodeAndSize(obj, &len);
+ if (u == NULL)
+ return NULL;
+ if (len > PY_SSIZE_T_MAX / sizeof(Py_UNICODE))
+ return PyErr_NoMemory();
+ size = len * sizeof(Py_UNICODE);
+ return codec_tuple(PyBytes_FromStringAndSize((const char*)u, size),
PyUnicode_GET_LENGTH(obj));
}
else {