|
1 | 1 | #include "parts.h" |
2 | 2 |
|
3 | | -static PyObject* |
| 3 | +static PyObject * |
4 | 4 | test_immortal_bool(PyObject *self, PyObject *Py_UNUSED(ignored)) |
5 | 5 | { |
6 | 6 | PyObject* objects[] = {Py_True, Py_False}; |
7 | 7 | Py_ssize_t n = Py_ARRAY_LENGTH(objects); |
8 | | - for(Py_ssize_t i = 0; i < n; i++) { |
| 8 | + for (Py_ssize_t i = 0; i < n; i++) { |
9 | 9 | PyObject* obj = objects[i]; |
10 | | - if (!_Py_IsImmortal(obj)) { |
11 | | - PyErr_Format(PyExc_RuntimeError, "%R should be the immportal object.", obj); |
12 | | - return NULL; |
13 | | - } |
| 10 | + assert(_Py_IsImmortal(obj)); |
14 | 11 | Py_ssize_t old_count = Py_REFCNT(obj); |
15 | 12 | for (int j = 0; j < 10000; j++) { |
16 | 13 | Py_DECREF(obj); |
17 | 14 | } |
18 | 15 | Py_ssize_t current_count = Py_REFCNT(obj); |
19 | | - if (old_count != current_count) { |
20 | | - PyErr_SetString(PyExc_RuntimeError, "Reference count should not be changed."); |
21 | | - return NULL; |
22 | | - } |
| 16 | + assert(old_count == current_count); |
23 | 17 | } |
24 | 18 | Py_RETURN_NONE; |
25 | 19 | } |
26 | 20 |
|
27 | 21 | static PyObject * |
28 | 22 | test_immortal_none(PyObject *self, PyObject *Py_UNUSED(ignored)) |
29 | 23 | { |
30 | | - if (!_Py_IsImmortal(Py_None)) { |
31 | | - PyErr_Format(PyExc_RuntimeError, "%R should be the immportal object.", Py_None); |
32 | | - return NULL; |
33 | | - } |
| 24 | + assert(_Py_IsImmortal(Py_None)); |
34 | 25 | Py_ssize_t old_count = Py_REFCNT(Py_None); |
35 | 26 | for (int i = 0; i < 10000; i++) { |
36 | 27 | Py_DECREF(Py_None); |
37 | 28 | } |
38 | 29 | Py_ssize_t current_count = Py_REFCNT(Py_None); |
39 | | - if (old_count != current_count) { |
40 | | - PyErr_SetString(PyExc_RuntimeError, "Reference count should not be changed."); |
41 | | - return NULL; |
42 | | - } |
| 30 | + assert(old_count == current_count); |
43 | 31 | Py_RETURN_NONE; |
44 | 32 | } |
45 | 33 |
|
46 | 34 | static PyObject * |
47 | 35 | test_immortal_small_ints(PyObject *self, PyObject *Py_UNUSED(ignored)) |
48 | 36 | { |
49 | | - for(int i = -5; i <= 256; i++) { |
| 37 | + for (int i = -5; i <= 256; i++) { |
50 | 38 | PyObject *small_int = PyLong_FromLong(i); |
51 | | - if (!_Py_IsImmortal(small_int)) { |
52 | | - PyErr_Format(PyExc_RuntimeError, "Small int(%d) object should be the immportal object.", i); |
53 | | - return NULL; |
54 | | - } |
| 39 | + assert(_Py_IsImmortal(small_int)); |
55 | 40 | Py_ssize_t old_count = Py_REFCNT(small_int); |
56 | 41 | for (int j = 0; j < 10000; j++) { |
57 | 42 | Py_DECREF(small_int); |
58 | 43 | } |
59 | 44 | Py_ssize_t current_count = Py_REFCNT(small_int); |
60 | | - if (old_count != current_count) { |
61 | | - PyErr_Format(PyExc_RuntimeError, "Reference count of %d should not be changed.", i); |
62 | | - return NULL; |
63 | | - } |
| 45 | + assert(old_count == current_count); |
64 | 46 | } |
65 | 47 | Py_RETURN_NONE; |
66 | 48 | } |
67 | 49 |
|
68 | 50 | static PyObject * |
69 | 51 | test_immortal_ellipsis(PyObject *self, PyObject *Py_UNUSED(ignored)) |
70 | 52 | { |
71 | | - if (!_Py_IsImmortal(Py_Ellipsis)) { |
72 | | - PyErr_SetString(PyExc_RuntimeError, "Ellipsis object should be the immportal object."); |
73 | | - return NULL; |
74 | | - } |
| 53 | + assert(_Py_IsImmortal(Py_Ellipsis)); |
75 | 54 | Py_ssize_t old_count = Py_REFCNT(Py_Ellipsis); |
76 | 55 | for (int i = 0; i < 10000; i++) { |
77 | 56 | Py_DECREF(Py_Ellipsis); |
78 | 57 | } |
79 | 58 | Py_ssize_t current_count = Py_REFCNT(Py_Ellipsis); |
80 | | - if (old_count != current_count) { |
81 | | - PyErr_SetString(PyExc_RuntimeError, "Reference count should not be changed."); |
82 | | - return NULL; |
83 | | - } |
| 59 | + assert(old_count == current_count); |
84 | 60 | Py_RETURN_NONE; |
85 | 61 | } |
86 | 62 |
|
|
0 commit comments