Skip to content

Commit 722a1e4

Browse files
committed
Stackless issue python#198: Improve the soft-switchable extension functions
Fix a potential uninitialized variable usage and add some comments.
1 parent 35f7fd9 commit 722a1e4

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Stackless/core/cframeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ PyStackless_CallFunction(PyStacklessFunctionDeclarationObject *ssfd, PyObject *a
485485
{
486486
STACKLESS_GETARG();
487487
PyThreadState *ts = PyThreadState_GET();
488-
PyObject *et, *ev, *tb;
488+
PyObject *et=NULL, *ev=NULL, *tb=NULL;
489489

490490
assert(ssfd);
491491
assert(ts->st.main != NULL);

Stackless/module/_teststackless.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ static PyTypeObject SoftSwitchableDemo_Type;
3434

3535
#define SoftSwitchableDemoObject_Check(v) (Py_TYPE(v) == &SoftSwitchableDemo_Type)
3636

37+
/* The documentation includes the following code as an example and needs
38+
* the next comment as marker.
39+
*/
3740
/*DO-NOT-REMOVE-OR-MODIFY-THIS-MARKER:ssf-example-start*/
3841

3942
/*
@@ -78,6 +81,8 @@ demo_soft_switchable(PyObject *retval, long *step, PyObject **ob1,
7881
* Specific vars for this example.
7982
*/
8083
int do_schedule = *n;
84+
if (*step == 0 && *n >= 100)
85+
*step = *n; // n==100: demo for calling back to Python
8186

8287
/*
8388
* Always present: the switch, that is used to jump to the next step.
@@ -87,8 +92,6 @@ demo_soft_switchable(PyObject *retval, long *step, PyObject **ob1,
8792
* (*step) is the number of the next state to enter.
8893
* The initial value of (*step) is 0.
8994
*/
90-
if (*step == 0 && *n >= 100)
91-
*step = *n;
9295
switch(*step) {
9396
case 0:
9497
(*step)++; // set to the next step
@@ -167,6 +170,9 @@ demo_soft_switchable(PyObject *retval, long *step, PyObject **ob1,
167170
Py_SETREF(retval, PyLong_FromLong(*n));
168171
break;
169172

173+
/*
174+
* Demo code for calling back to Python.
175+
*/
170176
case 100:
171177
(*step)++; // set to the next step
172178
/*

0 commit comments

Comments
 (0)