Skip to content

Commit 786f1fa

Browse files
[3.14] gh-160147: Move test_set_type_size() to Modules/_testcapi/object.c (GH-163042) (#163047)
gh-160147: Move test_set_type_size() to Modules/_testcapi/object.c (GH-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. (cherry picked from commit 8efb4da) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent c06ed31 commit 786f1fa

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
{
@@ -501,6 +524,7 @@ is_uniquely_referenced(PyObject *self, PyObject *op)
501524

502525

503526
static PyMethodDef test_methods[] = {
527+
{"test_set_type_size", test_set_type_size, METH_NOARGS},
504528
{"call_pyobject_print", call_pyobject_print, METH_VARARGS},
505529
{"pyobject_print_null", pyobject_print_null, METH_O},
506530
{"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)