-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
/
Copy pathset.c
44 lines (35 loc) · 941 Bytes
/
set.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "parts.h"
#include "util.h"
static PyObject *
set_get_size(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
RETURN_SIZE(PySet_GET_SIZE(obj));
}
static PyObject*
test_set_type_size(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *obj = PyList_New(0);
if (obj == NULL) {
return NULL;
}
// Ensure that following tests don't modify the object,
// to ensure that Py_DECREF() will not crash.
assert(Py_TYPE(obj) == &PyList_Type);
assert(Py_SIZE(obj) == 0);
// bpo-39573: Test Py_SET_TYPE() and Py_SET_SIZE() functions.
Py_SET_TYPE(obj, &PyList_Type);
Py_SET_SIZE(obj, 0);
Py_DECREF(obj);
Py_RETURN_NONE;
}
static PyMethodDef test_methods[] = {
{"set_get_size", set_get_size, METH_O},
{"test_set_type_size", test_set_type_size, METH_NOARGS},
{NULL},
};
int
_PyTestCapi_Init_Set(PyObject *m)
{
return PyModule_AddFunctions(m, test_methods);
}