bpo-39573: Convert Py_TYPE() and Py_SIZE() back to macros (GH-23366) · python/cpython@0e2ac21 (original) (raw)
`@@ -5612,6 +5612,30 @@ pynumber_tobase(PyObject *module, PyObject *args)
`
5612
5612
``
5613
5613
`static PyObject *test_buildvalue_issue38913(PyObject *, PyObject *);
`
5614
5614
``
``
5615
+
``
5616
`+
static PyObject*
`
``
5617
`+
test_set_type_size(PyObject* self, PyObject* ignored)
`
``
5618
`+
{
`
``
5619
`+
PyObject *obj = PyList_New(0);
`
``
5620
`+
if (obj == NULL) {
`
``
5621
`+
return NULL;
`
``
5622
`+
}
`
``
5623
+
``
5624
`+
// Ensure that following tests don't modify the object,
`
``
5625
`+
// to ensure that Py_DECREF() will not crash.
`
``
5626
`+
assert(Py_TYPE(obj) == &PyList_Type);
`
``
5627
`+
assert(Py_SIZE(obj) == 0);
`
``
5628
+
``
5629
`+
// bpo-39573: Check that Py_TYPE() and Py_SIZE() can be used
`
``
5630
`+
// as l-values to set an object type and size.
`
``
5631
`+
Py_TYPE(obj) = &PyList_Type;
`
``
5632
`+
Py_SIZE(obj) = 0;
`
``
5633
+
``
5634
`+
Py_DECREF(obj);
`
``
5635
`+
Py_RETURN_NONE;
`
``
5636
`+
}
`
``
5637
+
``
5638
+
5615
5639
`static PyMethodDef TestMethods[] = {
`
5616
5640
` {"raise_exception", raise_exception, METH_VARARGS},
`
5617
5641
` {"raise_memoryerror", raise_memoryerror, METH_NOARGS},
`
`@@ -5883,6 +5907,7 @@ static PyMethodDef TestMethods[] = {
`
5883
5907
` {"meth_fastcall_keywords", (PyCFunction)(void(*)(void))meth_fastcall_keywords, METH_FASTCALL|METH_KEYWORDS},
`
5884
5908
` {"pynumber_tobase", pynumber_tobase, METH_VARARGS},
`
5885
5909
` {"without_gc", without_gc, METH_O},
`
``
5910
`+
{"test_set_type_size", test_set_type_size, METH_NOARGS},
`
5886
5911
` {NULL, NULL} /* sentinel */
`
5887
5912
`};
`
5888
5913
``