@@ -1948,33 +1948,25 @@ PyCSimpleType_paramfunc(CDataObject *self)
1948
1948
return parg ;
1949
1949
}
1950
1950
1951
- static PyObject *
1952
- PyCSimpleType_new ( PyTypeObject * type , PyObject * args , PyObject * kwds )
1951
+ static int
1952
+ PyCSimpleType_init ( PyObject * self , PyObject * args , PyObject * kwds )
1953
1953
{
1954
- PyTypeObject * result ;
1955
1954
StgDictObject * stgdict ;
1956
1955
PyObject * proto ;
1957
1956
const char * proto_str ;
1958
1957
Py_ssize_t proto_len ;
1959
1958
PyMethodDef * ml ;
1960
1959
struct fielddesc * fmt ;
1961
1960
1962
- /* create the new instance (which is a class,
1963
- since we are a metatype!) */
1964
- result = (PyTypeObject * )PyType_Type .tp_new (type , args , kwds );
1965
- if (result == NULL )
1966
- return NULL ;
1967
-
1968
- if (PyObject_GetOptionalAttr ((PyObject * )result , & _Py_ID (_type_ ), & proto ) < 0 ) {
1969
- return NULL ;
1961
+ if (PyObject_GetOptionalAttr (self , & _Py_ID (_type_ ), & proto ) < 0 ) {
1962
+ return -1 ;
1970
1963
}
1971
1964
if (!proto ) {
1972
1965
PyErr_SetString (PyExc_AttributeError ,
1973
1966
"class must define a '_type_' attribute" );
1974
1967
error :
1975
1968
Py_XDECREF (proto );
1976
- Py_DECREF (result );
1977
- return NULL ;
1969
+ return -1 ;
1978
1970
}
1979
1971
if (PyUnicode_Check (proto )) {
1980
1972
proto_str = PyUnicode_AsUTF8AndSize (proto , & proto_len );
@@ -2023,15 +2015,14 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2023
2015
stgdict -> format = _ctypes_alloc_format_string_for_type (proto_str [0 ], 0 );
2024
2016
#endif
2025
2017
if (stgdict -> format == NULL ) {
2026
- Py_DECREF (result );
2027
2018
Py_DECREF (proto );
2028
2019
Py_DECREF ((PyObject * )stgdict );
2029
- return NULL ;
2020
+ return -1 ;
2030
2021
}
2031
2022
2032
2023
stgdict -> paramfunc = PyCSimpleType_paramfunc ;
2033
2024
/*
2034
- if (result ->tp_base != st->Simple_Type) {
2025
+ if (self ->tp_base != st->Simple_Type) {
2035
2026
stgdict->setfunc = NULL;
2036
2027
stgdict->getfunc = NULL;
2037
2028
}
@@ -2041,17 +2032,16 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2041
2032
stgdict -> proto = proto ;
2042
2033
2043
2034
/* replace the class dict by our updated spam dict */
2044
- if (-1 == PyDict_Update ((PyObject * )stgdict , result -> tp_dict )) {
2045
- Py_DECREF (result );
2035
+ if (-1 == PyDict_Update ((PyObject * )stgdict , ((PyTypeObject * )self )-> tp_dict )) {
2046
2036
Py_DECREF ((PyObject * )stgdict );
2047
- return NULL ;
2037
+ return -1 ;
2048
2038
}
2049
- Py_SETREF (result -> tp_dict , (PyObject * )stgdict );
2039
+ Py_SETREF ((( PyTypeObject * ) self ) -> tp_dict , (PyObject * )stgdict );
2050
2040
2051
2041
/* Install from_param class methods in ctypes base classes.
2052
2042
Overrides the PyCSimpleType_from_param generic method.
2053
2043
*/
2054
- if (result -> tp_base == st -> Simple_Type ) {
2044
+ if ((( PyTypeObject * ) self ) -> tp_base == st -> Simple_Type ) {
2055
2045
switch (* proto_str ) {
2056
2046
case 'z' : /* c_char_p */
2057
2047
ml = & c_char_p_method ;
@@ -2079,22 +2069,21 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2079
2069
if (ml ) {
2080
2070
PyObject * meth ;
2081
2071
int x ;
2082
- meth = PyDescr_NewClassMethod (result , ml );
2072
+ meth = PyDescr_NewClassMethod (( PyTypeObject * ) self , ml );
2083
2073
if (!meth ) {
2084
- Py_DECREF (result );
2085
- return NULL ;
2074
+ return -1 ;
2086
2075
}
2087
- x = PyDict_SetItemString (result -> tp_dict ,
2076
+ x = PyDict_SetItemString ((( PyTypeObject * ) self ) -> tp_dict ,
2088
2077
ml -> ml_name ,
2089
2078
meth );
2090
2079
Py_DECREF (meth );
2091
2080
if (x == -1 ) {
2092
- Py_DECREF (result );
2093
- return NULL ;
2081
+ return -1 ;
2094
2082
}
2095
2083
}
2096
2084
}
2097
2085
2086
+ PyTypeObject * type = Py_TYPE (self );
2098
2087
if (type == st -> PyCSimpleType_Type
2099
2088
&& fmt -> setfunc_swapped
2100
2089
&& fmt -> getfunc_swapped )
@@ -2103,33 +2092,31 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2103
2092
proto , fmt );
2104
2093
StgDictObject * sw_dict ;
2105
2094
if (swapped == NULL ) {
2106
- Py_DECREF (result );
2107
- return NULL ;
2095
+ return -1 ;
2108
2096
}
2109
2097
sw_dict = PyType_stgdict (swapped );
2110
2098
#ifdef WORDS_BIGENDIAN
2111
- PyObject_SetAttrString (( PyObject * ) result , "__ctype_le__" , swapped );
2112
- PyObject_SetAttrString (( PyObject * ) result , "__ctype_be__" , ( PyObject * ) result );
2113
- PyObject_SetAttrString (swapped , "__ctype_be__" , ( PyObject * ) result );
2099
+ PyObject_SetAttrString (self , "__ctype_le__" , swapped );
2100
+ PyObject_SetAttrString (self , "__ctype_be__" , self );
2101
+ PyObject_SetAttrString (swapped , "__ctype_be__" , self );
2114
2102
PyObject_SetAttrString (swapped , "__ctype_le__" , swapped );
2115
2103
/* We are creating the type for the OTHER endian */
2116
2104
sw_dict -> format = _ctypes_alloc_format_string ("<" , stgdict -> format + 1 );
2117
2105
#else
2118
- PyObject_SetAttrString (( PyObject * ) result , "__ctype_be__" , swapped );
2119
- PyObject_SetAttrString (( PyObject * ) result , "__ctype_le__" , ( PyObject * ) result );
2120
- PyObject_SetAttrString (swapped , "__ctype_le__" , ( PyObject * ) result );
2106
+ PyObject_SetAttrString (self , "__ctype_be__" , swapped );
2107
+ PyObject_SetAttrString (self , "__ctype_le__" , self );
2108
+ PyObject_SetAttrString (swapped , "__ctype_le__" , self );
2121
2109
PyObject_SetAttrString (swapped , "__ctype_be__" , swapped );
2122
2110
/* We are creating the type for the OTHER endian */
2123
2111
sw_dict -> format = _ctypes_alloc_format_string (">" , stgdict -> format + 1 );
2124
2112
#endif
2125
2113
Py_DECREF (swapped );
2126
2114
if (PyErr_Occurred ()) {
2127
- Py_DECREF (result );
2128
- return NULL ;
2115
+ return -1 ;
2129
2116
}
2130
2117
};
2131
2118
2132
- return ( PyObject * ) result ;
2119
+ return 0 ;
2133
2120
}
2134
2121
2135
2122
/*
@@ -2218,7 +2205,7 @@ static PyMethodDef PyCSimpleType_methods[] = {
2218
2205
static PyType_Slot pycsimple_type_slots [] = {
2219
2206
{Py_tp_doc , PyDoc_STR ("metatype for the PyCSimpleType Objects" )},
2220
2207
{Py_tp_methods , PyCSimpleType_methods },
2221
- {Py_tp_new , PyCSimpleType_new },
2208
+ {Py_tp_init , PyCSimpleType_init },
2222
2209
{Py_tp_traverse , CDataType_traverse },
2223
2210
{Py_tp_clear , CDataType_clear },
2224
2211
0 commit comments