diff options
author | Hai Shi <shihai1992@gmail.com> | 2020-11-10 20:53:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 20:53:46 (GMT) |
commit | a13b26cac1519dad7bbc8651de7b826df7389d75 (patch) | |
tree | 7dd13059bdf2e8489aa87626c7699da7a3cc658a /Modules/_testcapimodule.c | |
parent | ace3f9a0ce7b9fe8ae757fdd614f1e7a171f92b0 (diff) | |
download | cpython-a13b26cac1519dad7bbc8651de7b826df7389d75.zip cpython-a13b26cac1519dad7bbc8651de7b826df7389d75.tar.gz cpython-a13b26cac1519dad7bbc8651de7b826df7389d75.tar.bz2 |
bpo-41073: PyType_GetSlot() can now accept static types. (GH-21931)
PyType_GetSlot() can now accept static types.
Co-Authored-By: Petr Viktorin <encukou@gmail.com>
Automerge-Triggered-By: GH:encukou
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 4382b64..7b6da1e 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1019,6 +1019,62 @@ test_buildvalue_N(PyObject *self, PyObject *Py_UNUSED(ignored)) static PyObject * +test_get_statictype_slots(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + newfunc tp_new = PyType_GetSlot(&PyLong_Type, Py_tp_new); + if (PyLong_Type.tp_new != tp_new) { + PyErr_SetString(PyExc_AssertionError, "mismatch: tp_new of long"); + return NULL; + } + + reprfunc tp_repr = PyType_GetSlot(&PyLong_Type, Py_tp_repr); + if (PyLong_Type.tp_repr != tp_repr) { + PyErr_SetString(PyExc_AssertionError, "mismatch: tp_repr of long"); + return NULL; + } + + ternaryfunc tp_call = PyType_GetSlot(&PyLong_Type, Py_tp_call); + if (tp_call != NULL) { + PyErr_SetString(PyExc_AssertionError, "mismatch: tp_call of long"); + return NULL; + } + + binaryfunc nb_add = PyType_GetSlot(&PyLong_Type, Py_nb_add); + if (PyLong_Type.tp_as_number->nb_add != nb_add) { + PyErr_SetString(PyExc_AssertionError, "mismatch: nb_add of long"); + return NULL; + } + + lenfunc mp_length = PyType_GetSlot(&PyLong_Type, Py_mp_length); + if (mp_length != NULL) { + PyErr_SetString(PyExc_AssertionError, "mismatch: mp_length of long"); + return NULL; + } + + void *over_value = PyType_GetSlot(&PyLong_Type, Py_bf_releasebuffer + 1); + if (over_value != NULL) { + PyErr_SetString(PyExc_AssertionError, "mismatch: max+1 of long"); + return NULL; + } + + tp_new = PyType_GetSlot(&PyLong_Type, 0); + if (tp_new != NULL) { + PyErr_SetString(PyExc_AssertionError, "mismatch: slot 0 of long"); + return NULL; + } + if (PyErr_ExceptionMatches(PyExc_SystemError)) { + // This is the right exception + PyErr_Clear(); + } + else { + return NULL; + } + + Py_RETURN_NONE; +} + + +static PyObject * get_args(PyObject *self, PyObject *args) { if (args == NULL) { @@ -5627,8 +5683,10 @@ static PyMethodDef TestMethods[] = { {"PyBuffer_SizeFromFormat", test_PyBuffer_SizeFromFormat, METH_VARARGS}, {"test_buildvalue_N", test_buildvalue_N, METH_NOARGS}, {"test_buildvalue_issue38913", test_buildvalue_issue38913, METH_NOARGS}, - {"get_args", get_args, METH_VARARGS}, - {"get_kwargs", (PyCFunction)(void(*)(void))get_kwargs, METH_VARARGS|METH_KEYWORDS}, + {"get_args", get_args, METH_VARARGS}, + {"test_get_statictype_slots", test_get_statictype_slots, METH_NOARGS}, + {"get_kwargs", (PyCFunction)(void(*)(void))get_kwargs, + METH_VARARGS|METH_KEYWORDS}, {"getargs_tuple", getargs_tuple, METH_VARARGS}, {"getargs_keywords", (PyCFunction)(void(*)(void))getargs_keywords, METH_VARARGS|METH_KEYWORDS}, |