Skip to content

consistently use Py_TYPE, Py_REFCNT, and correct initializer macros #3563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/frameobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef struct _frame {

PyAPI_DATA(PyTypeObject) PyFrame_Type;

#define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
#define PyFrame_Check(op) (Py_TYPE(op) == &PyFrame_Type)
#define PyFrame_IsRestricted(f) \
((f)->f_builtins != (f)->f_tstate->interp->builtins)

Expand Down
4 changes: 2 additions & 2 deletions Include/intobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyInt_Type;

#define PyInt_Check(op) \
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_INT_SUBCLASS)
#define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type)
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_INT_SUBCLASS)
#define PyInt_CheckExact(op) (Py_TYPE(op) == &PyInt_Type)

PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
#ifdef Py_USING_UNICODE
Expand Down
2 changes: 1 addition & 1 deletion Modules/_ctypes/ctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ typedef struct {
ffi_type *atypes[1];
} CThunkObject;
extern PyTypeObject PyCThunk_Type;
#define CThunk_CheckExact(v) ((v)->ob_type == &PyCThunk_Type)
#define CThunk_CheckExact(v) (Py_TYPE(v) == &PyCThunk_Type)

typedef struct {
/* First part identical to tagCDataObject */
Expand Down
12 changes: 6 additions & 6 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1661,8 +1661,8 @@ static PyMappingMethods element_as_mapping = {
};

statichere PyTypeObject Element_Type = {
PyObject_HEAD_INIT(NULL)
0, "Element", sizeof(ElementObject), 0,
PyVarObject_HEAD_INIT(NULL, 0)
"Element", sizeof(ElementObject), 0,
/* methods */
(destructor)element_dealloc, /* tp_dealloc */
0, /* tp_print */
Expand Down Expand Up @@ -2031,8 +2031,8 @@ treebuilder_getattr(TreeBuilderObject* self, char* name)
}

statichere PyTypeObject TreeBuilder_Type = {
PyObject_HEAD_INIT(NULL)
0, "TreeBuilder", sizeof(TreeBuilderObject), 0,
PyVarObject_HEAD_INIT(NULL, 0)
"TreeBuilder", sizeof(TreeBuilderObject), 0,
/* methods */
(destructor)treebuilder_dealloc, /* tp_dealloc */
0, /* tp_print */
Expand Down Expand Up @@ -2897,8 +2897,8 @@ xmlparser_getattr(XMLParserObject* self, char* name)
}

statichere PyTypeObject XMLParser_Type = {
PyObject_HEAD_INIT(NULL)
0, "XMLParser", sizeof(XMLParserObject), 0,
PyVarObject_HEAD_INIT(NULL, 0)
"XMLParser", sizeof(XMLParserObject), 0,
/* methods */
(destructor)xmlparser_dealloc, /* tp_dealloc */
0, /* tp_print */
Expand Down
6 changes: 2 additions & 4 deletions Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1767,8 +1767,7 @@ PyDoc_STRVAR(scanner_doc, "JSON scanner object");

static
PyTypeObject PyScannerType = {
PyObject_HEAD_INIT(NULL)
0, /* tp_internal */
PyVarObject_HEAD_INIT(NULL, 0)
"_json.Scanner", /* tp_name */
sizeof(PyScannerObject), /* tp_basicsize */
0, /* tp_itemsize */
Expand Down Expand Up @@ -2344,8 +2343,7 @@ PyDoc_STRVAR(encoder_doc, "_iterencode(obj, _current_indent_level) -> iterable")

static
PyTypeObject PyEncoderType = {
PyObject_HEAD_INIT(NULL)
0, /* tp_internal */
PyVarObject_HEAD_INIT(NULL, 0)
"_json.Encoder", /* tp_name */
sizeof(PyEncoderObject), /* tp_basicsize */
0, /* tp_itemsize */
Expand Down
3 changes: 1 addition & 2 deletions Modules/_lsprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,7 @@ Profiler(custom_timer=None, time_unit=None, subcalls=True, builtins=True)\n\
");

statichere PyTypeObject PyProfiler_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PyVarObject_HEAD_INIT(NULL, 0)
"_lsprof.Profiler", /* tp_name */
sizeof(ProfilerObject), /* tp_basicsize */
0, /* tp_itemsize */
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void pysqlite_connection_dealloc(pysqlite_Connection* self)
Py_XDECREF(self->statements);
Py_XDECREF(self->cursors);

self->ob_type->tp_free((PyObject*)self);
Py_TYPE(self)->tp_free((PyObject*)self);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static void pysqlite_cursor_dealloc(pysqlite_Cursor* self)
PyObject_ClearWeakRefs((PyObject*)self);
}

self->ob_type->tp_free((PyObject*)self);
Py_TYPE(self)->tp_free((PyObject*)self);
}

PyObject* _pysqlite_get_converter(PyObject* key)
Expand Down
8 changes: 4 additions & 4 deletions Modules/_sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -2712,8 +2712,8 @@ static PyMemberDef pattern_members[] = {
};

statichere PyTypeObject Pattern_Type = {
PyObject_HEAD_INIT(NULL)
0, "_" SRE_MODULE ".SRE_Pattern",
PyVarObject_HEAD_INIT(NULL, 0)
"_" SRE_MODULE ".SRE_Pattern",
sizeof(PatternObject), sizeof(SRE_CODE),
(destructor)pattern_dealloc, /*tp_dealloc*/
0, /* tp_print */
Expand Down Expand Up @@ -3952,8 +3952,8 @@ static PyMemberDef scanner_members[] = {
};

statichere PyTypeObject Scanner_Type = {
PyObject_HEAD_INIT(NULL)
0, "_" SRE_MODULE ".SRE_Scanner",
PyVarObject_HEAD_INIT(NULL, 0)
"_" SRE_MODULE ".SRE_Scanner",
sizeof(ScannerObject), 0,
(destructor)scanner_dealloc, /*tp_dealloc*/
0, /* tp_print */
Expand Down
6 changes: 2 additions & 4 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ test_dict_iteration(PyObject* self)
* PyType_Ready if it hasn't already been called
*/
static PyTypeObject _HashInheritanceTester_Type = {
PyObject_HEAD_INIT(NULL)
0, /* Number of items for varobject */
PyVarObject_HEAD_INIT(NULL, 0)
"hashinheritancetester", /* Name of this type */
sizeof(PyObject), /* Basic object size */
0, /* Item size for varobject */
Expand Down Expand Up @@ -315,8 +314,7 @@ static PyBufferProcs memoryviewtester_as_buffer = {
};

static PyTypeObject _MemoryViewTester_Type = {
PyObject_HEAD_INIT(NULL)
0, /* Number of items for varobject */
PyVarObject_HEAD_INIT(NULL, 0)
"memoryviewtester", /* Name of this type */
sizeof(PyObject), /* Basic object size */
0, /* Item size for varobject */
Expand Down
12 changes: 6 additions & 6 deletions Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1292,9 +1292,9 @@ array_tofile(arrayobject *self, PyObject *f)
PyErr_SetString(PyExc_TypeError, "arg must be open file");
return NULL;
}
if (self->ob_size > 0) {
if (Py_SIZE(self) > 0) {
if (fwrite(self->ob_item, self->ob_descr->itemsize,
self->ob_size, fp) != (size_t)self->ob_size) {
Py_SIZE(self), fp) != (size_t)Py_SIZE(self)) {
PyErr_SetFromErrno(PyExc_IOError);
clearerr(fp);
return NULL;
Expand Down Expand Up @@ -1348,7 +1348,7 @@ array_fromlist(arrayobject *self, PyObject *list)
if ((*self->ob_descr->setitem)(self,
Py_SIZE(self) - n + i, v) != 0) {
Py_SIZE(self) -= n;
if (itemsize && (self->ob_size > PY_SSIZE_T_MAX / itemsize)) {
if (itemsize && (Py_SIZE(self) > PY_SSIZE_T_MAX / itemsize)) {
return PyErr_NoMemory();
}
PyMem_RESIZE(item, char,
Expand Down Expand Up @@ -1444,7 +1444,7 @@ values,as if it had been read from a file using the fromfile() method).");
static PyObject *
array_tostring(arrayobject *self, PyObject *unused)
{
if (self->ob_size <= PY_SSIZE_T_MAX / self->ob_descr->itemsize) {
if (Py_SIZE(self) <= PY_SSIZE_T_MAX / self->ob_descr->itemsize) {
return PyString_FromStringAndSize(self->ob_item,
Py_SIZE(self) * self->ob_descr->itemsize);
} else {
Expand Down Expand Up @@ -2289,8 +2289,8 @@ initarray(void)
{
PyObject *m;

Arraytype.ob_type = &PyType_Type;
PyArrayIter_Type.ob_type = &PyType_Type;
Py_TYPE(&Arraytype) = &PyType_Type;
Py_TYPE(&PyArrayIter_Type) = &PyType_Type;
m = Py_InitModule3("array", a_methods, module_doc);
if (m == NULL)
return;
Expand Down
9 changes: 3 additions & 6 deletions Modules/datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3039,8 +3039,7 @@ static char tzinfo_doc[] =
PyDoc_STR("Abstract base class for time zone info objects.");

statichere PyTypeObject PyDateTime_TZInfoType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PyVarObject_HEAD_INIT(NULL, 0)
"datetime.tzinfo", /* tp_name */
sizeof(PyDateTime_TZInfo), /* tp_basicsize */
0, /* tp_itemsize */
Expand Down Expand Up @@ -3564,8 +3563,7 @@ static PyNumberMethods time_as_number = {
};

statichere PyTypeObject PyDateTime_TimeType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PyVarObject_HEAD_INIT(NULL, 0)
"datetime.time", /* tp_name */
sizeof(PyDateTime_Time), /* tp_basicsize */
0, /* tp_itemsize */
Expand Down Expand Up @@ -4692,8 +4690,7 @@ static PyNumberMethods datetime_as_number = {
};

statichere PyTypeObject PyDateTime_DateTimeType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PyVarObject_HEAD_INIT(NULL, 0)
"datetime.datetime", /* tp_name */
sizeof(PyDateTime_DateTime), /* tp_basicsize */
0, /* tp_itemsize */
Expand Down
4 changes: 2 additions & 2 deletions Objects/bufferobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ get_buf(PyBufferObject *self, void **ptr, Py_ssize_t *size,
else {
Py_ssize_t count, offset;
readbufferproc proc = 0;
PyBufferProcs *bp = self->b_base->ob_type->tp_as_buffer;
PyBufferProcs *bp = Py_TYPE(self->b_base)->tp_as_buffer;
if ((*bp->bf_getsegcount)(self->b_base, NULL) != 1) {
PyErr_SetString(PyExc_TypeError,
"single-segment buffer object expected");
Expand All @@ -47,7 +47,7 @@ get_buf(PyBufferObject *self, void **ptr, Py_ssize_t *size,
(buffer_type == ANY_BUFFER))
proc = (readbufferproc)bp->bf_getwritebuffer;
else if (buffer_type == CHAR_BUFFER) {
if (!PyType_HasFeature(self->ob_type,
if (!PyType_HasFeature(Py_TYPE(self),
Py_TPFLAGS_HAVE_GETCHARBUFFER)) {
PyErr_SetString(PyExc_TypeError,
"Py_TPFLAGS_HAVE_GETCHARBUFFER needed");
Expand Down
Loading