Skip to content

Commit 8efb4da

Browse files
authored
gh-160147: Move test_set_type_size() to Modules/_testcapi/object.c (#163042)
The test was in Modules/_testcapi/set.c, whereas it's unrelated to set objects. The test was in the wrong file because its name contains "set", but in fact it tests the PyObject API.
1 parent 5f4aeba commit 8efb4da

2 files changed

Lines changed: 24 additions & 23 deletions

File tree

‎Modules/_testcapi/object.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
#include "parts.h"
22
#include "util.h"
33

4+
// Test Py_SET_TYPE() and Py_SET_SIZE().
5+
static PyObject*
6+
test_set_type_size(PyObject *self, PyObject *Py_UNUSED(ignored))
7+
{
8+
PyObject *obj = PyList_New(0);
9+
if (obj == NULL) {
10+
return NULL;
11+
}
12+
13+
// Ensure that following tests don't modify the object,
14+
// to ensure that Py_DECREF() will not crash.
15+
assert(Py_TYPE(obj) == &PyList_Type);
16+
assert(Py_SIZE(obj) == 0);
17+
18+
// bpo-39573: Test Py_SET_TYPE() and Py_SET_SIZE() functions.
19+
Py_SET_TYPE(obj, &PyList_Type);
20+
Py_SET_SIZE(obj, 0);
21+
22+
Py_DECREF(obj);
23+
Py_RETURN_NONE;
24+
}
25+
26+
427
static PyObject *
528
call_pyobject_print(PyObject *self, PyObject * args)
629
{
@@ -357,6 +380,7 @@ pysentinel_checkexact(PyObject *self, PyObject *obj)
357380

358381

359382
static PyMethodDef test_methods[] = {
383+
{"test_set_type_size", test_set_type_size, METH_NOARGS},
360384
{"call_pyobject_print", call_pyobject_print, METH_VARARGS},
361385
{"pyobject_print_null", pyobject_print_null, METH_O},
362386
{"pyobject_print_noref_object", pyobject_print_noref_object, METH_O},

‎Modules/_testcapi/set.c‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,8 @@ set_get_size(PyObject *self, PyObject *obj)
99
}
1010

1111

12-
static PyObject*
13-
test_set_type_size(PyObject *self, PyObject *Py_UNUSED(ignored))
14-
{
15-
PyObject *obj = PyList_New(0);
16-
if (obj == NULL) {
17-
return NULL;
18-
}
19-
20-
// Ensure that following tests don't modify the object,
21-
// to ensure that Py_DECREF() will not crash.
22-
assert(Py_TYPE(obj) == &PyList_Type);
23-
assert(Py_SIZE(obj) == 0);
24-
25-
// bpo-39573: Test Py_SET_TYPE() and Py_SET_SIZE() functions.
26-
Py_SET_TYPE(obj, &PyList_Type);
27-
Py_SET_SIZE(obj, 0);
28-
29-
Py_DECREF(obj);
30-
Py_RETURN_NONE;
31-
}
32-
33-
3412
static PyMethodDef test_methods[] = {
3513
{"set_get_size", set_get_size, METH_O},
36-
{"test_set_type_size", test_set_type_size, METH_NOARGS},
3714
{NULL},
3815
};
3916

0 commit comments

Comments
 (0)