Skip to content

Commit b842f61

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. (cherry picked from commit c7dcca5)
1 parent 94e7bcf commit b842f61

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
@@ -431,15 +431,15 @@ PyTaskletObject * slp_get_watchdog(PyThreadState *ts, int interrupt);
431431

432432
#define STACKLESS_PROMOTE(func) \
433433
(stackless ? slp_try_stackless = \
434-
(func)->ob_type->tp_flags & Py_TPFLAGS_HAVE_STACKLESS_CALL : 0)
434+
Py_TYPE(func)->tp_flags & Py_TPFLAGS_HAVE_STACKLESS_CALL : 0)
435435

436436
#define STACKLESS_PROMOTE_FLAG(flag) \
437437
(stackless ? slp_try_stackless = (flag) : 0)
438438

439439
#define STACKLESS_PROMOTE_METHOD(obj, meth) do { \
440-
if ((obj->ob_type->tp_flags & Py_TPFLAGS_HAVE_STACKLESS_EXTENSION) && \
441-
obj->ob_type->tp_as_mapping) \
442-
slp_try_stackless = stackless & obj->ob_type->tp_as_mapping->slpflags.meth; \
440+
if ((Py_TYPE(obj)->tp_flags & Py_TPFLAGS_HAVE_STACKLESS_EXTENSION) && \
441+
Py_TYPE(obj)->tp_as_mapping) \
442+
slp_try_stackless = stackless & Py_TYPE(obj)->tp_as_mapping->slpflags.meth; \
443443
} while (0)
444444

445445
#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
@@ -1379,8 +1379,8 @@ _peek(PyObject *self, PyObject *v)
13791379
/* this is plain heuristics, use for now */
13801380
if (CANNOT_READ_MEM(o, sizeof(PyObject))) goto noobject;
13811381
if (IS_ON_STACK(o)) goto noobject;
1382-
if (o->ob_refcnt < 1 || o->ob_refcnt > 10000) goto noobject;
1383-
t = o->ob_type;
1382+
if (Py_REFCNT(o) < 1 || Py_REFCNT(o) > 10000) goto noobject;
1383+
t = Py_TYPE(o);
13841384
for (i=0; i<100; i++) {
13851385
if (t == &PyType_Type)
13861386
break;
@@ -1427,15 +1427,15 @@ _get_refinfo(PyObject *self)
14271427
refchain = PyTuple_New(0)->_ob_next; /* None doesn't work in 2.2 */
14281428
Py_DECREF(refchain->_ob_prev);
14291429
/* find real refchain */
1430-
while (refchain->ob_type != NULL)
1430+
while (Py_TYPE(refchain) != NULL)
14311431
refchain = refchain->_ob_next;
14321432

14331433
for (op = refchain->_ob_next; op != refchain; op = op->_ob_next) {
1434-
if (op->ob_refcnt > max->ob_refcnt)
1434+
if (Py_REFCNT(op) > Py_REFCNT(max))
14351435
max = op;
1436-
computed_total += op->ob_refcnt;
1436+
computed_total += Py_REFCNT(op);
14371437
}
1438-
return Py_BuildValue("(Onnn)", max, max->ob_refcnt, ref_total,
1438+
return Py_BuildValue("(Onnn)", max, Py_REFCNT(max), ref_total,
14391439
computed_total);
14401440
}
14411441

@@ -1449,7 +1449,7 @@ _get_all_objects(PyObject *self)
14491449
lis = PyList_New(0);
14501450
if (lis) {
14511451
ob = lis->_ob_next;
1452-
while (ob != lis && ob->ob_type != NULL) {
1452+
while (ob != lis && Py_TYPE(ob) != NULL) {
14531453
if (PyList_Append(lis, ob))
14541454
return NULL;
14551455
ob = ob->_ob_next;

Stackless/pickling/prickelpit.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ generic_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4343
assert(type->tp_base->tp_new != NULL);
4444
inst = type->tp_base->tp_new(type->tp_base, args, kwds);
4545
if (inst != NULL)
46-
inst->ob_type = type;
46+
Py_TYPE(inst) = type;
4747
return inst;
4848
}
4949

5050
int
5151
generic_init(PyObject *ob, PyObject *args, PyObject *kwds)
5252
{
5353

54-
initproc init = ob->ob_type->tp_base->tp_init;
54+
initproc init = Py_TYPE(ob)->tp_base->tp_init;
5555

5656
if (init)
5757
return init(ob, args, kwds);
@@ -61,8 +61,8 @@ generic_init(PyObject *ob, PyObject *args, PyObject *kwds)
6161
static PyObject *
6262
generic_setstate(PyObject *self, PyObject *args)
6363
{
64-
if (is_wrong_type(self->ob_type)) return NULL;
65-
self->ob_type = self->ob_type->tp_base;
64+
if (is_wrong_type(Py_TYPE(self))) return NULL;
65+
Py_TYPE(self) = Py_TYPE(self)->tp_base;
6666
Py_INCREF(self);
6767
return self;
6868
}
@@ -99,29 +99,29 @@ _new_wrapper(PyObject *self, PyObject *args, PyObject *kwds)
9999
static void
100100
_wrap_dealloc(PyObject *ob)
101101
{
102-
ob->ob_type = ob->ob_type->tp_base;
103-
if (ob->ob_type->tp_dealloc != NULL)
104-
ob->ob_type->tp_dealloc(ob);
102+
Py_TYPE(ob) = Py_TYPE(ob)->tp_base;
103+
if (Py_TYPE(ob)->tp_dealloc != NULL)
104+
Py_TYPE(ob)->tp_dealloc(ob);
105105
}
106106

107107
static int
108108
_wrap_traverse(PyObject *ob, visitproc visit, void *arg)
109109
{
110-
PyTypeObject *type = ob->ob_type;
110+
PyTypeObject *type = Py_TYPE(ob);
111111
int ret = 0;
112-
ob->ob_type = ob->ob_type->tp_base;
113-
if (ob->ob_type->tp_traverse != NULL)
114-
ret = ob->ob_type->tp_traverse(ob, visit, arg);
115-
ob->ob_type = type;
112+
Py_TYPE(ob) = type->tp_base;
113+
if (Py_TYPE(ob)->tp_traverse != NULL)
114+
ret = Py_TYPE(ob)->tp_traverse(ob, visit, arg);
115+
Py_TYPE(ob) = type;
116116
return ret;
117117
}
118118

119119
static void
120120
_wrap_clear(PyObject *ob)
121121
{
122-
ob->ob_type = ob->ob_type->tp_base;
123-
if (ob->ob_type->tp_clear != NULL)
124-
ob->ob_type->tp_clear(ob);
122+
Py_TYPE(ob) = Py_TYPE(ob)->tp_base;
123+
if (Py_TYPE(ob)->tp_clear != NULL)
124+
Py_TYPE(ob)->tp_clear(ob);
125125
}
126126

127127

@@ -604,7 +604,7 @@ cell_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
604604
return NULL;
605605
ob = PyCell_New(NULL);
606606
if (ob != NULL)
607-
ob->ob_type = type;
607+
Py_TYPE(ob) = type;
608608
return ob;
609609
}
610610

@@ -616,14 +616,14 @@ cell_setstate(PyObject *self, PyObject *args)
616616
PyCellObject *cell = (PyCellObject *) self;
617617
PyObject *ob = NULL;
618618

619-
if (is_wrong_type(self->ob_type)) return NULL;
619+
if (is_wrong_type(Py_TYPE(self))) return NULL;
620620
if (!PyArg_ParseTuple (args, "|O", &ob))
621621
return NULL;
622622
Py_XDECREF(cell->ob_ref);
623623
cell->ob_ref = ob;
624624
Py_XINCREF(cell->ob_ref);
625625
Py_INCREF(self);
626-
self->ob_type = self->ob_type->tp_base;
626+
Py_TYPE(self) = Py_TYPE(self)->tp_base;
627627
return self;
628628
}
629629

@@ -675,7 +675,7 @@ func_new(PyTypeObject *type, PyObject *args, PyObject *kewd)
675675
if ((co = Py_CompileString("", "", Py_file_input)) != NULL)
676676
if ((globals = PyDict_New()) != NULL)
677677
if ((ob = PyFunction_New(co, globals)) != NULL)
678-
ob->ob_type = type;
678+
Py_TYPE(ob) = type;
679679
Py_XDECREF(co);
680680
Py_XDECREF(globals);
681681
return ob;
@@ -690,13 +690,13 @@ func_setstate(PyObject *self, PyObject *args)
690690
PyFunctionObject *fu;
691691
PyObject *args2;
692692

693-
if (is_wrong_type(self->ob_type)) return NULL;
694-
self->ob_type = self->ob_type->tp_base;
693+
if (is_wrong_type(Py_TYPE(self))) return NULL;
694+
Py_TYPE(self) = Py_TYPE(self)->tp_base;
695695
args2 = PyTuple_GetSlice(args, 0, 5);
696696
if (args2 == NULL)
697697
return NULL;
698698
fu = (PyFunctionObject *)
699-
self->ob_type->tp_new(self->ob_type, args2, NULL);
699+
Py_TYPE(self)->tp_new(Py_TYPE(self), args2, NULL);
700700
Py_DECREF(args2);
701701
if (fu != NULL) {
702702
PyFunctionObject *target = (PyFunctionObject *) self;
@@ -2072,7 +2072,7 @@ methw_setstate(PyObject *self, PyObject *args)
20722072
PyObject *name, *inst;
20732073
PyObject *w;
20742074

2075-
if (is_wrong_type(self->ob_type)) return NULL;
2075+
if (is_wrong_type(Py_TYPE(self))) return NULL;
20762076
if (!PyArg_ParseTuple(args, "O!O:method-wrapper",
20772077
&PyString_Type, &name,
20782078
&inst))
@@ -2097,7 +2097,7 @@ methw_setstate(PyObject *self, PyObject *args)
20972097
neww->self = oldw->self;
20982098
}
20992099
Py_DECREF(w);
2100-
self->ob_type = self->ob_type->tp_base;
2100+
Py_TYPE(self) = Py_TYPE(self)->tp_base;
21012101
Py_INCREF(self);
21022102
return self;
21032103
}

0 commit comments

Comments
 (0)