diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-01-28 17:49:54 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-01-28 17:49:54 (GMT) |
commit | c8241fdde7bce66f74363f8240e1b29d75fab3f8 (patch) | |
tree | f62183b6ba2135ce7d96591cc4d68e6432e45ed7 /Modules | |
parent | 22532ac2eb4440ff40ceefe510069a4927ab63ee (diff) | |
download | cpython-c8241fdde7bce66f74363f8240e1b29d75fab3f8.zip cpython-c8241fdde7bce66f74363f8240e1b29d75fab3f8.tar.gz cpython-c8241fdde7bce66f74363f8240e1b29d75fab3f8.tar.bz2 |
Issue #26198: Added tests for "es", "et", "es#", "et#" and "C" format units
of PyArg_Parse*() functions.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testcapimodule.c | 94 |
1 files changed, 93 insertions, 1 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 9a03648..71aa419 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1088,7 +1088,16 @@ getargs_c(PyObject *self, PyObject *args) char c; if (!PyArg_ParseTuple(args, "c", &c)) return NULL; - return PyBytes_FromStringAndSize(&c, 1); + return PyLong_FromLong((unsigned char)c); +} + +static PyObject * +getargs_C(PyObject *self, PyObject *args) +{ + int c; + if (!PyArg_ParseTuple(args, "C", &c)) + return NULL; + return PyLong_FromLong(c); } static PyObject * @@ -1243,6 +1252,84 @@ getargs_Z_hash(PyObject *self, PyObject *args) Py_RETURN_NONE; } +static PyObject * +getargs_es(PyObject *self, PyObject *args) +{ + PyObject *arg, *result; + const char *encoding = NULL; + char *str; + + if (!PyArg_ParseTuple(args, "O|s", &arg, &encoding)) + return NULL; + if (!PyArg_Parse(arg, "es", encoding, &str)) + return NULL; + result = PyBytes_FromString(str); + PyMem_Free(str); + return result; +} + +static PyObject * +getargs_et(PyObject *self, PyObject *args) +{ + PyObject *arg, *result; + const char *encoding = NULL; + char *str; + + if (!PyArg_ParseTuple(args, "O|s", &arg, &encoding)) + return NULL; + if (!PyArg_Parse(arg, "et", encoding, &str)) + return NULL; + result = PyBytes_FromString(str); + PyMem_Free(str); + return result; +} + +static PyObject * +getargs_es_hash(PyObject *self, PyObject *args) +{ + PyObject *arg, *result; + const char *encoding = NULL; + PyByteArrayObject *buffer = NULL; + char *str = NULL; + Py_ssize_t size; + + if (!PyArg_ParseTuple(args, "O|sY", &arg, &encoding, &buffer)) + return NULL; + if (buffer != NULL) { + str = PyByteArray_AS_STRING(buffer); + size = PyByteArray_GET_SIZE(buffer); + } + if (!PyArg_Parse(arg, "es#", encoding, &str, &size)) + return NULL; + result = PyBytes_FromStringAndSize(str, size); + if (buffer == NULL) + PyMem_Free(str); + return result; +} + +static PyObject * +getargs_et_hash(PyObject *self, PyObject *args) +{ + PyObject *arg, *result; + const char *encoding = NULL; + PyByteArrayObject *buffer = NULL; + char *str = NULL; + Py_ssize_t size; + + if (!PyArg_ParseTuple(args, "O|sY", &arg, &encoding, &buffer)) + return NULL; + if (buffer != NULL) { + str = PyByteArray_AS_STRING(buffer); + size = PyByteArray_GET_SIZE(buffer); + } + if (!PyArg_Parse(arg, "et#", encoding, &str, &size)) + return NULL; + result = PyBytes_FromStringAndSize(str, size); + if (buffer == NULL) + PyMem_Free(str); + return result; +} + /* Test the s and z codes for PyArg_ParseTuple. */ static PyObject * @@ -3588,6 +3675,7 @@ static PyMethodDef TestMethods[] = { {"test_L_code", (PyCFunction)test_L_code, METH_NOARGS}, #endif {"getargs_c", getargs_c, METH_VARARGS}, + {"getargs_C", getargs_C, METH_VARARGS}, {"getargs_s", getargs_s, METH_VARARGS}, {"getargs_s_star", getargs_s_star, METH_VARARGS}, {"getargs_s_hash", getargs_s_hash, METH_VARARGS}, @@ -3602,6 +3690,10 @@ static PyMethodDef TestMethods[] = { {"getargs_Z", getargs_Z, METH_VARARGS}, {"getargs_Z_hash", getargs_Z_hash, METH_VARARGS}, {"getargs_w_star", getargs_w_star, METH_VARARGS}, + {"getargs_es", getargs_es, METH_VARARGS}, + {"getargs_et", getargs_et, METH_VARARGS}, + {"getargs_es_hash", getargs_es_hash, METH_VARARGS}, + {"getargs_et_hash", getargs_et_hash, METH_VARARGS}, {"codec_incrementalencoder", (PyCFunction)codec_incrementalencoder, METH_VARARGS}, {"codec_incrementaldecoder", |