Skip to content

Commit c7dcca5

Browse files
author
Anselm Kruis
committed
Stackless issue python#134: use Py_TYPE, Py_SIZE and Py_REFCNT
Replace the direct access to PyObject members with the preferred macros.
1 parent f845a0f commit c7dcca5

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

Stackless/core/stackless_impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,15 @@ PyTaskletObject * slp_get_watchdog(PyThreadState *ts, int interrupt);
452452

453453
#define STACKLESS_PROMOTE(func) \
454454
(stackless ? slp_try_stackless = \
455-
(func)->ob_type->tp_flags & Py_TPFLAGS_HAVE_STACKLESS_CALL : 0)
455+
Py_TYPE(func)->tp_flags & Py_TPFLAGS_HAVE_STACKLESS_CALL : 0)
456456

457457
#define STACKLESS_PROMOTE_FLAG(flag) \
458458
(stackless ? slp_try_stackless = (flag) : 0)
459459

460460
#define STACKLESS_PROMOTE_METHOD(obj, meth) do { \
461-
if ((obj->ob_type->tp_flags & Py_TPFLAGS_HAVE_STACKLESS_EXTENSION) && \
462-
obj->ob_type->tp_as_mapping) \
463-
slp_try_stackless = stackless & obj->ob_type->tp_as_mapping->slpflags.meth; \
461+
if ((Py_TYPE(obj)->tp_flags & Py_TPFLAGS_HAVE_STACKLESS_EXTENSION) && \
462+
Py_TYPE(obj)->tp_as_mapping) \
463+
slp_try_stackless = stackless & Py_TYPE(obj)->tp_as_mapping->slpflags.meth; \
464464
} while (0)
465465

466466
#define STACKLESS_PROMOTE_WRAPPER(wp) \

Stackless/module/channelobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ channel_dealloc(PyObject *ob)
6767
}
6868
if (ch->chan_weakreflist != NULL)
6969
PyObject_ClearWeakRefs((PyObject *)ch);
70-
ob->ob_type->tp_free(ob);
70+
Py_TYPE(ob)->tp_free(ob);
7171
}
7272

7373
/* see if a tasklet is queued on a channel */

Stackless/module/stacklessmodule.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,8 +1375,8 @@ _peek(PyObject *self, PyObject *v)
13751375
/* this is plain heuristics, use for now */
13761376
if (CANNOT_READ_MEM(o, sizeof(PyObject))) goto noobject;
13771377
if (IS_ON_STACK(o)) goto noobject;
1378-
if (o->ob_refcnt < 1 || o->ob_refcnt > 10000) goto noobject;
1379-
t = o->ob_type;
1378+
if (Py_REFCNT(o) < 1 || Py_REFCNT(o) > 10000) goto noobject;
1379+
t = Py_TYPE(o);
13801380
for (i=0; i<100; i++) {
13811381
if (t == &PyType_Type)
13821382
break;
@@ -1423,15 +1423,15 @@ _get_refinfo(PyObject *self)
14231423
refchain = PyTuple_New(0)->_ob_next; /* None doesn't work in 2.2 */
14241424
Py_DECREF(refchain->_ob_prev);
14251425
/* find real refchain */
1426-
while (refchain->ob_type != NULL)
1426+
while (Py_TYPE(refchain) != NULL)
14271427
refchain = refchain->_ob_next;
14281428

14291429
for (op = refchain->_ob_next; op != refchain; op = op->_ob_next) {
1430-
if (op->ob_refcnt > max->ob_refcnt)
1430+
if (Py_REFCNT(op) > Py_REFCNT(max))
14311431
max = op;
1432-
computed_total += op->ob_refcnt;
1432+
computed_total += Py_REFCNT(op);
14331433
}
1434-
return Py_BuildValue("(Onnn)", max, max->ob_refcnt, ref_total,
1434+
return Py_BuildValue("(Onnn)", max, Py_REFCNT(max), ref_total,
14351435
computed_total);
14361436
}
14371437

@@ -1445,7 +1445,7 @@ _get_all_objects(PyObject *self)
14451445
lis = PyList_New(0);
14461446
if (lis) {
14471447
ob = lis->_ob_next;
1448-
while (ob != lis && ob->ob_type != NULL) {
1448+
while (ob != lis && Py_TYPE(ob) != NULL) {
14491449
if (PyList_Append(lis, ob))
14501450
return NULL;
14511451
ob = ob->_ob_next;

Stackless/pickling/prickelpit.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ generic_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
5656
assert(type->tp_base->tp_new != NULL);
5757
inst = type->tp_base->tp_new(type->tp_base, args, kwds);
5858
if (inst != NULL)
59-
inst->ob_type = type;
59+
Py_TYPE(inst) = type;
6060
return inst;
6161
}
6262

6363
int
6464
generic_init(PyObject *ob, PyObject *args, PyObject *kwds)
6565
{
6666

67-
initproc init = ob->ob_type->tp_base->tp_init;
67+
initproc init = Py_TYPE(ob)->tp_base->tp_init;
6868

6969
if (init)
7070
return init(ob, args, kwds);
@@ -74,8 +74,8 @@ generic_init(PyObject *ob, PyObject *args, PyObject *kwds)
7474
static PyObject *
7575
generic_setstate(PyObject *self, PyObject *args)
7676
{
77-
if (is_wrong_type(self->ob_type)) return NULL;
78-
self->ob_type = self->ob_type->tp_base;
77+
if (is_wrong_type(Py_TYPE(self))) return NULL;
78+
Py_TYPE(self) = Py_TYPE(self)->tp_base;
7979
Py_INCREF(self);
8080
return self;
8181
}
@@ -112,29 +112,29 @@ _new_wrapper(PyObject *self, PyObject *args, PyObject *kwds)
112112
static void
113113
_wrap_dealloc(PyObject *ob)
114114
{
115-
ob->ob_type = ob->ob_type->tp_base;
116-
if (ob->ob_type->tp_dealloc != NULL)
117-
ob->ob_type->tp_dealloc(ob);
115+
Py_TYPE(ob) = Py_TYPE(ob)->tp_base;
116+
if (Py_TYPE(ob)->tp_dealloc != NULL)
117+
Py_TYPE(ob)->tp_dealloc(ob);
118118
}
119119

120120
static int
121121
_wrap_traverse(PyObject *ob, visitproc visit, void *arg)
122122
{
123-
PyTypeObject *type = ob->ob_type;
123+
PyTypeObject *type = Py_TYPE(ob);
124124
int ret = 0;
125-
ob->ob_type = ob->ob_type->tp_base;
126-
if (ob->ob_type->tp_traverse != NULL)
127-
ret = ob->ob_type->tp_traverse(ob, visit, arg);
128-
ob->ob_type = type;
125+
Py_TYPE(ob) = type->tp_base;
126+
if (Py_TYPE(ob)->tp_traverse != NULL)
127+
ret = Py_TYPE(ob)->tp_traverse(ob, visit, arg);
128+
Py_TYPE(ob) = type;
129129
return ret;
130130
}
131131

132132
static void
133133
_wrap_clear(PyObject *ob)
134134
{
135-
ob->ob_type = ob->ob_type->tp_base;
136-
if (ob->ob_type->tp_clear != NULL)
137-
ob->ob_type->tp_clear(ob);
135+
Py_TYPE(ob) = Py_TYPE(ob)->tp_base;
136+
if (Py_TYPE(ob)->tp_clear != NULL)
137+
Py_TYPE(ob)->tp_clear(ob);
138138
}
139139

140140

@@ -699,7 +699,7 @@ cell_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
699699
return NULL;
700700
ob = PyCell_New(NULL);
701701
if (ob != NULL)
702-
ob->ob_type = type;
702+
Py_TYPE(ob) = type;
703703
return ob;
704704
}
705705

@@ -711,14 +711,14 @@ cell_setstate(PyObject *self, PyObject *args)
711711
PyCellObject *cell = (PyCellObject *) self;
712712
PyObject *ob = NULL;
713713

714-
if (is_wrong_type(self->ob_type)) return NULL;
714+
if (is_wrong_type(Py_TYPE(self))) return NULL;
715715
if (!PyArg_ParseTuple (args, "|O", &ob))
716716
return NULL;
717717
Py_XINCREF(ob);
718718
Py_CLEAR(cell->ob_ref);
719719
cell->ob_ref = ob;
720720
Py_INCREF(self);
721-
self->ob_type = self->ob_type->tp_base;
721+
Py_TYPE(self) = Py_TYPE(self)->tp_base;
722722
return self;
723723
}
724724

@@ -770,7 +770,7 @@ func_new(PyTypeObject *type, PyObject *args, PyObject *kewd)
770770
if ((co = Py_CompileString("", "", Py_file_input)) != NULL)
771771
if ((globals = PyDict_New()) != NULL)
772772
if ((ob = PyFunction_New(co, globals)) != NULL)
773-
ob->ob_type = type;
773+
Py_TYPE(ob) = type;
774774
Py_XDECREF(co);
775775
Py_XDECREF(globals);
776776
return ob;
@@ -785,13 +785,13 @@ func_setstate(PyObject *self, PyObject *args)
785785
PyFunctionObject *fu;
786786
PyObject *args2;
787787

788-
if (is_wrong_type(self->ob_type)) return NULL;
789-
self->ob_type = self->ob_type->tp_base;
788+
if (is_wrong_type(Py_TYPE(self))) return NULL;
789+
Py_TYPE(self) = Py_TYPE(self)->tp_base;
790790
args2 = PyTuple_GetSlice(args, 0, 5);
791791
if (args2 == NULL)
792792
return NULL;
793793
fu = (PyFunctionObject *)
794-
self->ob_type->tp_new(self->ob_type, args2, NULL);
794+
Py_TYPE(self)->tp_new(Py_TYPE(self), args2, NULL);
795795
Py_DECREF(args2);
796796
if (fu != NULL) {
797797
PyFunctionObject *target = (PyFunctionObject *) self;
@@ -1650,7 +1650,7 @@ methw_setstate(PyObject *self, PyObject *args)
16501650
PyObject *name, *inst;
16511651
PyObject *w;
16521652

1653-
if (is_wrong_type(self->ob_type)) return NULL;
1653+
if (is_wrong_type(Py_TYPE(self))) return NULL;
16541654
if (!PyArg_ParseTuple(args, "O!O:method-wrapper",
16551655
&PyUnicode_Type, &name,
16561656
&inst))
@@ -1675,7 +1675,7 @@ methw_setstate(PyObject *self, PyObject *args)
16751675
neww->self = oldw->self;
16761676
}
16771677
Py_DECREF(w);
1678-
self->ob_type = self->ob_type->tp_base;
1678+
Py_TYPE(self) = Py_TYPE(self)->tp_base;
16791679
Py_INCREF(self);
16801680
return self;
16811681
}

0 commit comments

Comments
 (0)