@@ -10,27 +10,30 @@ typedef struct {
1010} CustomObject ;
1111
1212static int
13- Custom_traverse (CustomObject * self , visitproc visit , void * arg )
13+ Custom_traverse (PyObject * op , visitproc visit , void * arg )
1414{
15+ CustomObject * self = (CustomObject * )op ;
1516 Py_VISIT (self -> first );
1617 Py_VISIT (self -> last );
1718 return 0 ;
1819}
1920
2021static int
21- Custom_clear (CustomObject * self )
22+ Custom_clear (PyObject * op )
2223{
24+ CustomObject * self = (CustomObject * )op ;
2325 Py_CLEAR (self -> first );
2426 Py_CLEAR (self -> last );
2527 return 0 ;
2628}
2729
2830static void
29- Custom_dealloc (CustomObject * self )
31+ Custom_dealloc (PyObject * op )
3032{
33+ CustomObject * self = (CustomObject * )op ;
3134 PyObject_GC_UnTrack (self );
3235 Custom_clear (self );
33- Py_TYPE (self )-> tp_free (( PyObject * ) self );
36+ Py_TYPE (self )-> tp_free (self );
3437}
3538
3639static PyObject *
@@ -55,8 +58,9 @@ Custom_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
5558}
5659
5760static int
58- Custom_init (CustomObject * self , PyObject * args , PyObject * kwds )
61+ Custom_init (PyObject * op , PyObject * args , PyObject * kwds )
5962{
63+ CustomObject * self = (CustomObject * )op ;
6064 static char * kwlist [] = {"first" , "last" , "number" , NULL };
6165 PyObject * first = NULL , * last = NULL ;
6266
@@ -81,14 +85,16 @@ static PyMemberDef Custom_members[] = {
8185};
8286
8387static PyObject *
84- Custom_getfirst (CustomObject * self , void * closure )
88+ Custom_getfirst (PyObject * op , void * closure )
8589{
90+ CustomObject * self = (CustomObject * )op ;
8691 return Py_NewRef (self -> first );
8792}
8893
8994static int
90- Custom_setfirst (CustomObject * self , PyObject * value , void * closure )
95+ Custom_setfirst (PyObject * op , PyObject * value , void * closure )
9196{
97+ CustomObject * self = (CustomObject * )op ;
9298 if (value == NULL ) {
9399 PyErr_SetString (PyExc_TypeError , "Cannot delete the first attribute" );
94100 return -1 ;
@@ -103,14 +109,16 @@ Custom_setfirst(CustomObject *self, PyObject *value, void *closure)
103109}
104110
105111static PyObject *
106- Custom_getlast (CustomObject * self , void * closure )
112+ Custom_getlast (PyObject * op , void * closure )
107113{
114+ CustomObject * self = (CustomObject * )op ;
108115 return Py_NewRef (self -> last );
109116}
110117
111118static int
112- Custom_setlast (CustomObject * self , PyObject * value , void * closure )
119+ Custom_setlast (PyObject * op , PyObject * value , void * closure )
113120{
121+ CustomObject * self = (CustomObject * )op ;
114122 if (value == NULL ) {
115123 PyErr_SetString (PyExc_TypeError , "Cannot delete the last attribute" );
116124 return -1 ;
@@ -125,21 +133,22 @@ Custom_setlast(CustomObject *self, PyObject *value, void *closure)
125133}
126134
127135static PyGetSetDef Custom_getsetters [] = {
128- {"first" , ( getter ) Custom_getfirst , ( setter ) Custom_setfirst ,
136+ {"first" , Custom_getfirst , Custom_setfirst ,
129137 "first name" , NULL },
130- {"last" , ( getter ) Custom_getlast , ( setter ) Custom_setlast ,
138+ {"last" , Custom_getlast , Custom_setlast ,
131139 "last name" , NULL },
132140 {NULL } /* Sentinel */
133141};
134142
135143static PyObject *
136- Custom_name (CustomObject * self , PyObject * Py_UNUSED (ignored ))
144+ Custom_name (PyObject * op , PyObject * Py_UNUSED (dummy ))
137145{
146+ CustomObject * self = (CustomObject * )op ;
138147 return PyUnicode_FromFormat ("%S %S" , self -> first , self -> last );
139148}
140149
141150static PyMethodDef Custom_methods [] = {
142- {"name" , ( PyCFunction ) Custom_name , METH_NOARGS ,
151+ {"name" , Custom_name , METH_NOARGS ,
143152 "Return the name, combining the first and last name"
144153 },
145154 {NULL } /* Sentinel */
@@ -153,10 +162,10 @@ static PyTypeObject CustomType = {
153162 .tp_itemsize = 0 ,
154163 .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC ,
155164 .tp_new = Custom_new ,
156- .tp_init = ( initproc ) Custom_init ,
157- .tp_dealloc = ( destructor ) Custom_dealloc ,
158- .tp_traverse = ( traverseproc ) Custom_traverse ,
159- .tp_clear = ( inquiry ) Custom_clear ,
165+ .tp_init = Custom_init ,
166+ .tp_dealloc = Custom_dealloc ,
167+ .tp_traverse = Custom_traverse ,
168+ .tp_clear = Custom_clear ,
160169 .tp_members = Custom_members ,
161170 .tp_methods = Custom_methods ,
162171 .tp_getset = Custom_getsetters ,
0 commit comments