Skip to content

Commit f02ec0f

Browse files
author
Anselm Kruis
committed
Stackless issue python#70: stackless specific handling of C-return values
If a C-function checks a return value of another C-function of type PyObject*, it must handle the case of unwinding. This commit fixes PyObject_Call in abstract.c and simplifies checks in ceval.c. https://bitbucket.org/stackless-dev/stackless/issues/70
1 parent 8d26499 commit f02ec0f

File tree

3 files changed

+5
-28
lines changed

3 files changed

+5
-28
lines changed

Objects/abstract.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,14 +2054,14 @@ PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw)
20542054
#endif
20552055
Py_LeaveRecursiveCall();
20562056
#ifdef NDEBUG
2057-
if (result == NULL && !PyErr_Occurred()) {
2057+
if (STACKLESS_RETVAL(result) == NULL && !PyErr_Occurred()) {
20582058
PyErr_SetString(
20592059
PyExc_SystemError,
20602060
"NULL result without error in PyObject_Call");
20612061
}
20622062
#else
2063-
assert((result != NULL && !PyErr_Occurred())
2064-
|| (result == NULL && PyErr_Occurred()));
2063+
assert((STACKLESS_RETVAL(result) != NULL && !PyErr_Occurred())
2064+
|| (STACKLESS_RETVAL(result) == NULL && PyErr_Occurred()));
20652065
#endif
20662066
return result;
20672067
}

Python/ceval.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,13 +3838,8 @@ PyEval_EvalFrame_value(PyFrameObject *f, int throwflag, PyObject *retval)
38383838
if (why != WHY_RETURN)
38393839
retval = NULL;
38403840

3841-
#ifdef STACKLESS
38423841
assert((STACKLESS_RETVAL(retval) != NULL && !PyErr_Occurred())
38433842
|| (STACKLESS_RETVAL(retval) == NULL && PyErr_Occurred()));
3844-
#else
3845-
assert((retval != NULL && !PyErr_Occurred())
3846-
|| (retval == NULL && PyErr_Occurred()));
3847-
#endif
38483843

38493844
fast_yield:
38503845
if (co->co_flags & CO_GENERATOR) {
@@ -4901,13 +4896,8 @@ PyEval_CallObjectWithKeywords(PyObject *func, PyObject *arg, PyObject *kw)
49014896
STACKLESS_ASSERT();
49024897
Py_DECREF(arg);
49034898

4904-
#ifdef STACKLESS
49054899
assert((STACKLESS_RETVAL(result) != NULL && !PyErr_Occurred())
49064900
|| (STACKLESS_RETVAL(result) == NULL && PyErr_Occurred()));
4907-
#else
4908-
assert((result != NULL && !PyErr_Occurred())
4909-
|| (result == NULL && PyErr_Occurred()));
4910-
#endif
49114901
return result;
49124902
}
49134903

@@ -5062,13 +5052,8 @@ call_function(PyObject ***pp_stack, int oparg
50625052
READ_TIMESTAMP(*pintr1);
50635053
Py_DECREF(func);
50645054
}
5065-
#ifdef STACKLESS
50665055
assert((STACKLESS_RETVAL(x) != NULL && !PyErr_Occurred())
50675056
|| (STACKLESS_RETVAL(x) == NULL && PyErr_Occurred()));
5068-
#else
5069-
assert((x != NULL && !PyErr_Occurred())
5070-
|| (x == NULL && PyErr_Occurred()));
5071-
#endif
50725057

50735058
/* Clear the stack of the function object. Also removes
50745059
the arguments in case they weren't consumed already
@@ -5080,13 +5065,8 @@ call_function(PyObject ***pp_stack, int oparg
50805065
PCALL(PCALL_POP);
50815066
}
50825067

5083-
#ifdef STACKLESS
50845068
assert((STACKLESS_RETVAL(x) != NULL && !PyErr_Occurred())
50855069
|| (STACKLESS_RETVAL(x) == NULL && PyErr_Occurred()));
5086-
#else
5087-
assert((x != NULL && !PyErr_Occurred())
5088-
|| (x == NULL && PyErr_Occurred()));
5089-
#endif
50905070
return x;
50915071
}
50925072

@@ -5386,13 +5366,8 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
53865366
Py_XDECREF(callargs);
53875367
Py_XDECREF(kwdict);
53885368
Py_XDECREF(stararg);
5389-
#ifdef STACKLESS
53905369
assert((STACKLESS_RETVAL(result) != NULL && !PyErr_Occurred())
53915370
|| (STACKLESS_RETVAL(result) == NULL && PyErr_Occurred()));
5392-
#else
5393-
assert((result != NULL && !PyErr_Occurred())
5394-
|| (result == NULL && PyErr_Occurred()));
5395-
#endif
53965371
return result;
53975372
}
53985373

Stackless/core/stackless_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ PyObject * slp_get_channel_callback(void);
554554
#define STACKLESS_RETRACT() assert(1)
555555
#define STACKLESS_ASSERT() assert(1)
556556

557+
#define STACKLESS_RETVAL(obj) (obj)
558+
557559
#define STACKLESS_DECLARE_METHOD(type, meth)
558560

559561
#endif /* STACKLESS */

0 commit comments

Comments
 (0)