diff options
author | Stefan Krah <skrah@bytereef.org> | 2012-11-02 13:44:20 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2012-11-02 13:44:20 (GMT) |
commit | e6996ed5d9c3ce149a8384a625521ab5a0820ae3 (patch) | |
tree | 3a650836587ea15ec283efa03418422da466e384 /Modules/_testcapimodule.c | |
parent | ed71918d1297c9d478e497c783520d46b2bc0ee4 (diff) | |
download | cpython-e6996ed5d9c3ce149a8384a625521ab5a0820ae3.zip cpython-e6996ed5d9c3ce149a8384a625521ab5a0820ae3.tar.gz cpython-e6996ed5d9c3ce149a8384a625521ab5a0820ae3.tar.bz2 |
Issue #16145: Support legacy strings in the _csv module.
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index ab11f51..2f43813 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1521,6 +1521,29 @@ unicode_transformdecimaltoascii(PyObject *self, PyObject *args) } static PyObject * +unicode_legacy_string(PyObject *self, PyObject *args) +{ + Py_UNICODE *data; + Py_ssize_t len; + PyObject *u; + + if (!PyArg_ParseTuple(args, "u#", &data, &len)) + return NULL; + + u = PyUnicode_FromUnicode(NULL, len); + if (u == NULL) + return NULL; + + memcpy(PyUnicode_AS_UNICODE(u), data, len * sizeof(Py_UNICODE)); + + if (len > 0) { /* The empty string is always ready. */ + assert(!PyUnicode_IS_READY(u)); + } + + return u; +} + +static PyObject * getargs_w_star(PyObject *self, PyObject *args) { Py_buffer buffer; @@ -2506,6 +2529,7 @@ static PyMethodDef TestMethods[] = { {"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS}, {"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS}, {"unicode_transformdecimaltoascii", unicode_transformdecimaltoascii, METH_VARARGS}, + {"unicode_legacy_string", unicode_legacy_string, METH_VARARGS}, #ifdef WITH_THREAD {"_test_thread_state", test_thread_state, METH_VARARGS}, {"_pending_threadfunc", pending_threadfunc, METH_VARARGS}, |