| 1 |
#include "parts.h" |
| 2 |
#include "util.h" |
| 3 |
|
| 4 |
static PyObject * |
| 5 |
set_get_size(PyObject *self, PyObject *obj) |
| 6 |
{ |
| 7 |
NULLABLE(obj); |
| 8 |
RETURN_SIZE(PySet_GET_SIZE(obj)); |
| 9 |
} |
| 10 |
|
| 11 |
|
| 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 |
|
| 34 |
static PyMethodDef test_methods[] = { |
| 35 |
{"set_get_size", set_get_size, METH_O}, |
| 36 |
{"test_set_type_size", test_set_type_size, METH_NOARGS}, |
| 37 |
{NULL}, |
| 38 |
}; |
| 39 |
|
| 40 |
int |
| 41 |
_PyTestCapi_Init_Set(PyObject *m) |
| 42 |
{ |
| 43 |
return PyModule_AddFunctions(m, test_methods); |
| 44 |
} |