Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit baa1780

Browse filesBrowse files
committed
ready
1 parent 8e2aab7 commit baa1780
Copy full SHA for baa1780

File tree

Expand file treeCollapse file tree

1 file changed

+26
-39
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+26
-39
lines changed

‎Modules/_ctypes/_ctypes.c

Copy file name to clipboardExpand all lines: Modules/_ctypes/_ctypes.c
+26-39Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,33 +1948,25 @@ PyCSimpleType_paramfunc(CDataObject *self)
19481948
return parg;
19491949
}
19501950

1951-
static PyObject *
1952-
PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1951+
static int
1952+
PyCSimpleType_init(PyObject *self, PyObject *args, PyObject *kwds)
19531953
{
1954-
PyTypeObject *result;
19551954
StgDictObject *stgdict;
19561955
PyObject *proto;
19571956
const char *proto_str;
19581957
Py_ssize_t proto_len;
19591958
PyMethodDef *ml;
19601959
struct fielddesc *fmt;
19611960

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;
19701963
}
19711964
if (!proto) {
19721965
PyErr_SetString(PyExc_AttributeError,
19731966
"class must define a '_type_' attribute");
19741967
error:
19751968
Py_XDECREF(proto);
1976-
Py_DECREF(result);
1977-
return NULL;
1969+
return -1;
19781970
}
19791971
if (PyUnicode_Check(proto)) {
19801972
proto_str = PyUnicode_AsUTF8AndSize(proto, &proto_len);
@@ -2023,15 +2015,14 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
20232015
stgdict->format = _ctypes_alloc_format_string_for_type(proto_str[0], 0);
20242016
#endif
20252017
if (stgdict->format == NULL) {
2026-
Py_DECREF(result);
20272018
Py_DECREF(proto);
20282019
Py_DECREF((PyObject *)stgdict);
2029-
return NULL;
2020+
return -1;
20302021
}
20312022

20322023
stgdict->paramfunc = PyCSimpleType_paramfunc;
20332024
/*
2034-
if (result->tp_base != st->Simple_Type) {
2025+
if (self->tp_base != st->Simple_Type) {
20352026
stgdict->setfunc = NULL;
20362027
stgdict->getfunc = NULL;
20372028
}
@@ -2041,17 +2032,16 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
20412032
stgdict->proto = proto;
20422033

20432034
/* 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)) {
20462036
Py_DECREF((PyObject *)stgdict);
2047-
return NULL;
2037+
return -1;
20482038
}
2049-
Py_SETREF(result->tp_dict, (PyObject *)stgdict);
2039+
Py_SETREF(((PyTypeObject *)self)->tp_dict, (PyObject *)stgdict);
20502040

20512041
/* Install from_param class methods in ctypes base classes.
20522042
Overrides the PyCSimpleType_from_param generic method.
20532043
*/
2054-
if (result->tp_base == st->Simple_Type) {
2044+
if (((PyTypeObject *)self)->tp_base == st->Simple_Type) {
20552045
switch (*proto_str) {
20562046
case 'z': /* c_char_p */
20572047
ml = &c_char_p_method;
@@ -2079,22 +2069,21 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
20792069
if (ml) {
20802070
PyObject *meth;
20812071
int x;
2082-
meth = PyDescr_NewClassMethod(result, ml);
2072+
meth = PyDescr_NewClassMethod((PyTypeObject*)self, ml);
20832073
if (!meth) {
2084-
Py_DECREF(result);
2085-
return NULL;
2074+
return -1;
20862075
}
2087-
x = PyDict_SetItemString(result->tp_dict,
2076+
x = PyDict_SetItemString(((PyTypeObject*)self)->tp_dict,
20882077
ml->ml_name,
20892078
meth);
20902079
Py_DECREF(meth);
20912080
if (x == -1) {
2092-
Py_DECREF(result);
2093-
return NULL;
2081+
return -1;
20942082
}
20952083
}
20962084
}
20972085

2086+
PyTypeObject *type = Py_TYPE(self);
20982087
if (type == st->PyCSimpleType_Type
20992088
&& fmt->setfunc_swapped
21002089
&& fmt->getfunc_swapped)
@@ -2103,33 +2092,31 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
21032092
proto, fmt);
21042093
StgDictObject *sw_dict;
21052094
if (swapped == NULL) {
2106-
Py_DECREF(result);
2107-
return NULL;
2095+
return -1;
21082096
}
21092097
sw_dict = PyType_stgdict(swapped);
21102098
#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);
21142102
PyObject_SetAttrString(swapped, "__ctype_le__", swapped);
21152103
/* We are creating the type for the OTHER endian */
21162104
sw_dict->format = _ctypes_alloc_format_string("<", stgdict->format+1);
21172105
#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);
21212109
PyObject_SetAttrString(swapped, "__ctype_be__", swapped);
21222110
/* We are creating the type for the OTHER endian */
21232111
sw_dict->format = _ctypes_alloc_format_string(">", stgdict->format+1);
21242112
#endif
21252113
Py_DECREF(swapped);
21262114
if (PyErr_Occurred()) {
2127-
Py_DECREF(result);
2128-
return NULL;
2115+
return -1;
21292116
}
21302117
};
21312118

2132-
return (PyObject *)result;
2119+
return 0;
21332120
}
21342121

21352122
/*
@@ -2218,7 +2205,7 @@ static PyMethodDef PyCSimpleType_methods[] = {
22182205
static PyType_Slot pycsimple_type_slots[] = {
22192206
{Py_tp_doc, PyDoc_STR("metatype for the PyCSimpleType Objects")},
22202207
{Py_tp_methods, PyCSimpleType_methods},
2221-
{Py_tp_new, PyCSimpleType_new},
2208+
{Py_tp_init, PyCSimpleType_init},
22222209
{Py_tp_traverse, CDataType_traverse},
22232210
{Py_tp_clear, CDataType_clear},
22242211

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.