5
5
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
6
6
#include "pycore_object.h"
7
7
8
+ #define _PyCell_CAST (op ) _Py_CAST(PyCellObject*, (op))
9
+
8
10
PyObject *
9
11
PyCell_New (PyObject * obj )
10
12
{
@@ -72,8 +74,9 @@ PyCell_Set(PyObject *op, PyObject *value)
72
74
}
73
75
74
76
static void
75
- cell_dealloc (PyCellObject * op )
77
+ cell_dealloc (PyObject * self )
76
78
{
79
+ PyCellObject * op = _PyCell_CAST (self );
77
80
_PyObject_GC_UNTRACK (op );
78
81
Py_XDECREF (op -> ob_ref );
79
82
PyObject_GC_Del (op );
@@ -100,51 +103,55 @@ cell_richcompare(PyObject *a, PyObject *b, int op)
100
103
}
101
104
102
105
static PyObject *
103
- cell_repr (PyCellObject * op )
106
+ cell_repr (PyObject * self )
104
107
{
105
- if (op -> ob_ref == NULL )
108
+ PyCellObject * op = _PyCell_CAST (self );
109
+ if (op -> ob_ref == NULL ) {
106
110
return PyUnicode_FromFormat ("<cell at %p: empty>" , op );
111
+ }
107
112
108
113
return PyUnicode_FromFormat ("<cell at %p: %.80s object at %p>" ,
109
114
op , Py_TYPE (op -> ob_ref )-> tp_name ,
110
115
op -> ob_ref );
111
116
}
112
117
113
118
static int
114
- cell_traverse (PyCellObject * op , visitproc visit , void * arg )
119
+ cell_traverse (PyObject * self , visitproc visit , void * arg )
115
120
{
121
+ PyCellObject * op = _PyCell_CAST (self );
116
122
Py_VISIT (op -> ob_ref );
117
123
return 0 ;
118
124
}
119
125
120
126
static int
121
- cell_clear (PyCellObject * op )
127
+ cell_clear (PyObject * self )
122
128
{
129
+ PyCellObject * op = _PyCell_CAST (self );
123
130
Py_CLEAR (op -> ob_ref );
124
131
return 0 ;
125
132
}
126
133
127
134
static PyObject *
128
- cell_get_contents (PyCellObject * op , void * closure )
135
+ cell_get_contents (PyObject * self , void * closure )
129
136
{
130
- if ( op -> ob_ref == NULL )
131
- {
137
+ PyCellObject * op = _PyCell_CAST ( self );
138
+ if ( op -> ob_ref == NULL ) {
132
139
PyErr_SetString (PyExc_ValueError , "Cell is empty" );
133
140
return NULL ;
134
141
}
135
142
return Py_NewRef (op -> ob_ref );
136
143
}
137
144
138
145
static int
139
- cell_set_contents (PyCellObject * op , PyObject * obj , void * Py_UNUSED (ignored ))
146
+ cell_set_contents (PyObject * self , PyObject * obj , void * Py_UNUSED (ignored ))
140
147
{
148
+ PyCellObject * op = _PyCell_CAST (self );
141
149
Py_XSETREF (op -> ob_ref , Py_XNewRef (obj ));
142
150
return 0 ;
143
151
}
144
152
145
153
static PyGetSetDef cell_getsetlist [] = {
146
- {"cell_contents" , (getter )cell_get_contents ,
147
- (setter )cell_set_contents , NULL },
154
+ {"cell_contents" , cell_get_contents , cell_set_contents , NULL },
148
155
{NULL } /* sentinel */
149
156
};
150
157
@@ -153,12 +160,12 @@ PyTypeObject PyCell_Type = {
153
160
"cell" ,
154
161
sizeof (PyCellObject ),
155
162
0 ,
156
- ( destructor ) cell_dealloc , /* tp_dealloc */
163
+ cell_dealloc , /* tp_dealloc */
157
164
0 , /* tp_vectorcall_offset */
158
165
0 , /* tp_getattr */
159
166
0 , /* tp_setattr */
160
167
0 , /* tp_as_async */
161
- ( reprfunc ) cell_repr , /* tp_repr */
168
+ cell_repr , /* tp_repr */
162
169
0 , /* tp_as_number */
163
170
0 , /* tp_as_sequence */
164
171
0 , /* tp_as_mapping */
@@ -170,8 +177,8 @@ PyTypeObject PyCell_Type = {
170
177
0 , /* tp_as_buffer */
171
178
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC , /* tp_flags */
172
179
cell_new_doc , /* tp_doc */
173
- ( traverseproc ) cell_traverse , /* tp_traverse */
174
- ( inquiry ) cell_clear , /* tp_clear */
180
+ cell_traverse , /* tp_traverse */
181
+ cell_clear , /* tp_clear */
175
182
cell_richcompare , /* tp_richcompare */
176
183
0 , /* tp_weaklistoffset */
177
184
0 , /* tp_iter */
@@ -186,6 +193,6 @@ PyTypeObject PyCell_Type = {
186
193
0 , /* tp_dictoffset */
187
194
0 , /* tp_init */
188
195
0 , /* tp_alloc */
189
- ( newfunc ) cell_new , /* tp_new */
196
+ cell_new , /* tp_new */
190
197
0 , /* tp_free */
191
198
};
0 commit comments