@@ -2031,6 +2031,16 @@ PyCSimpleType_paramfunc(CDataObject *self)
2031
2031
2032
2032
static PyObject *
2033
2033
PyCSimpleType_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
2034
+ {
2035
+ PyObject * result = PyType_Type .tp_new (type , args , kwds );
2036
+ #if 0
2037
+ printf ("new: %p %p\n" , type , result );
2038
+ #endif
2039
+ return result ;
2040
+ }
2041
+
2042
+ static int
2043
+ PyCSimpleType_init (PyObject * self , PyObject * args , PyObject * kwds )
2034
2044
{
2035
2045
PyTypeObject * result ;
2036
2046
StgDictObject * stgdict ;
@@ -2042,20 +2052,21 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2042
2052
2043
2053
/* create the new instance (which is a class,
2044
2054
since we are a metatype!) */
2045
- result = (PyTypeObject * )PyType_Type .tp_new (type , args , kwds );
2046
- if (result == NULL )
2047
- return NULL ;
2055
+ result = (PyTypeObject * )self ; // by PyType_Type.tp_new()
2056
+ PyTypeObject * type = Py_TYPE (self );
2057
+ #if 0
2058
+ printf ("ini: %p %p\n\n" , type , result );
2059
+ #endif
2048
2060
2049
2061
if (PyObject_GetOptionalAttr ((PyObject * )result , & _Py_ID (_type_ ), & proto ) < 0 ) {
2050
- return NULL ;
2062
+ return -1 ;
2051
2063
}
2052
2064
if (!proto ) {
2053
2065
PyErr_SetString (PyExc_AttributeError ,
2054
2066
"class must define a '_type_' attribute" );
2055
2067
error :
2056
2068
Py_XDECREF (proto );
2057
- Py_DECREF (result );
2058
- return NULL ;
2069
+ return -1 ;
2059
2070
}
2060
2071
if (PyUnicode_Check (proto )) {
2061
2072
proto_str = PyUnicode_AsUTF8AndSize (proto , & proto_len );
@@ -2103,10 +2114,9 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2103
2114
stgdict -> format = _ctypes_alloc_format_string_for_type (proto_str [0 ], 0 );
2104
2115
#endif
2105
2116
if (stgdict -> format == NULL ) {
2106
-
10000
Py_DECREF (result );
2107
2117
Py_DECREF (proto );
2108
2118
Py_DECREF ((PyObject * )stgdict );
2109
- return NULL ;
2119
+ return -1 ;
2110
2120
}
2111
2121
2112
2122
stgdict -> paramfunc = PyCSimpleType_paramfunc ;
@@ -2122,9 +2132,8 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2122
2132
2123
2133
/* replace the class dict by our updated spam dict */
2124
2134
if (-1 == PyDict_Update ((PyObject * )stgdict , result -> tp_dict )) {
2125
- Py_DECREF (result );
2126
2135
Py_DECREF ((PyObject * )stgdict );
2127
- return NULL ;
2136
+ return -1 ;
2128
2137
}
2129
2138
Py_SETREF (result -> tp_dict , (PyObject * )stgdict );
2130
2139
@@ -2161,16 +2170,14 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2161
2170
int x ;
2162
2171
meth = PyDescr_NewClassMethod (result , ml );
2163
2172
if (!meth ) {
2164
- Py_DECREF (result );
2165
- return NULL ;
2173
+ return -1 ;
2166
2174
}
2167
2175
x = PyDict_SetItemString (result -> tp_dict ,
2168
2176
ml -> ml_name ,
2169
2177
meth );
2170
2178
Py_DECREF (meth );
2171
2179
if (x == -1 ) {
2172
- Py_DECREF (result );
2173
- return NULL ;
2180
+ return -1 ;
2174
2181
}
2175
2182
}
2176
2183
}
@@ -2180,8 +2187,7 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2180
2187
proto , fmt );
2181
2188
StgDictObject * sw_dict ;
2182
2189
if (swapped == NULL ) {
2183
- Py_DECREF (result );
2184
- return NULL ;
2190
+ return -1 ;
2185
2191
}
2186
2192
sw_dict = PyType_stgdict (swapped );
2187
2193
#ifdef WORDS_BIGENDIAN
@@ -2201,12 +2207,11 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2201
2207
#endif
2202
2208
Py_DECREF (swapped );
2203
2209
if (PyErr_Occurred ()) {
2204
- Py_DECREF (result );
2205
- return NULL ;
2210
+ return -1 ;
2206
2211
}
2207
2212
};
2208
2213
2209
- return ( PyObject * ) result ;
2214
+ return 0 ;
2210
2215
}
2211
2216
2212
2217
/*
@@ -2328,7 +2333,7 @@ PyTypeObject PyCSimpleType_Type = {
2328
2333
0 , /* tp_descr_get */
2329
2334
0 , /* tp_descr_set */
2330
2335
0 , /* tp_dictoffset */
2331
- 0 , /* tp_init */
2336
+ ( initproc ) PyCSimpleType_init , /* tp_init */
2332
2337
0 , /* tp_alloc */
2333
2338
PyCSimpleType_new , /* tp_new */
2334
2339
0 , /* tp_free */
0 commit comments