diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2021-08-23 18:05:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-23 18:05:07 (GMT) |
commit | 4d689173861257c69adc6dc1dca4171946ddb57f (patch) | |
tree | 999326f40ad54b91981b2c23cb6166c6a649bdd9 /Modules | |
parent | 1a995b0ceefdf7eb59963f3ab395c47d8da226e3 (diff) | |
download | cpython-4d689173861257c69adc6dc1dca4171946ddb57f.zip cpython-4d689173861257c69adc6dc1dca4171946ddb57f.tar.gz cpython-4d689173861257c69adc6dc1dca4171946ddb57f.tar.bz2 |
bpo-44984: Rewrite test_null_strings in _testcapi (GH-27904)
Test also PyObject_Repr(NULL) and PyObject_Bytes(NULL).
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testcapimodule.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index e5f1ad3..68dd285 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2376,16 +2376,22 @@ test_long_numbits(PyObject *self, PyObject *Py_UNUSED(ignored)) Py_RETURN_NONE; } -/* Example passing NULLs to PyObject_Str(NULL). */ +static PyObject * +pyobject_repr_from_null(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + return PyObject_Repr(NULL); +} static PyObject * -test_null_strings(PyObject *self, PyObject *Py_UNUSED(ignored)) +pyobject_str_from_null(PyObject *self, PyObject *Py_UNUSED(ignored)) { - PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Str(NULL); - PyObject *tuple = PyTuple_Pack(2, o1, o2); - Py_XDECREF(o1); - Py_XDECREF(o2); - return tuple; + return PyObject_Str(NULL); +} + +static PyObject * +pyobject_bytes_from_null(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + return PyObject_Bytes(NULL); } static PyObject * @@ -5702,7 +5708,9 @@ static PyMethodDef TestMethods[] = { {"test_k_code", test_k_code, METH_NOARGS}, {"test_empty_argparse", test_empty_argparse, METH_NOARGS}, {"parse_tuple_and_keywords", parse_tuple_and_keywords, METH_VARARGS}, - {"test_null_strings", test_null_strings, METH_NOARGS}, + {"pyobject_repr_from_null", pyobject_repr_from_null, METH_NOARGS}, + {"pyobject_str_from_null", pyobject_str_from_null, METH_NOARGS}, + {"pyobject_bytes_from_null", pyobject_bytes_from_null, METH_NOARGS}, {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS}, {"test_with_docstring", test_with_docstring, METH_NOARGS, PyDoc_STR("This is a pretty normal docstring.")}, |