Skip to content

Commit

Permalink
Stackless issue python#185: rename macros without Stackless prefix
Browse files Browse the repository at this point in the history
Now all macros defined by Stackless start with SLP_ or STACKLESS_ or contain
STACKLESS in their name.
  • Loading branch information
Anselm Kruis authored and Anselm Kruis committed Nov 20, 2018
1 parent 45e1f15 commit 58f239a
Show file tree
Hide file tree
Showing 25 changed files with 129 additions and 123 deletions.
4 changes: 2 additions & 2 deletions Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -3954,9 +3954,9 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
#ifdef STACKLESS
/* but we save the stack after a fixed watermark */
{
/* use a variable, because CSTACK_SAVE_NOW evaluates ts several times. */
/* use a variable, because SLP_CSTACK_SAVE_NOW evaluates ts several times. */
PyThreadState *ts = PyThreadState_GET();
if (CSTACK_SAVE_NOW(ts, self)) {
if (SLP_CSTACK_SAVE_NOW(ts, self)) {
int res;
if (Py_EnterRecursiveCall(" while pickling an object"))
return -1;
Expand Down
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4032,7 +4032,7 @@ PyEval_EvalFrameEx_slp(PyFrameObject *f, int throwflag, PyObject *retval)
* PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
*/

if (CSTACK_SAVE_NOW(tstate, f))
if (SLP_CSTACK_SAVE_NOW(tstate, f))
return slp_eval_frame_newstack(f, throwflag, retval);

/* push frame */
Expand Down
4 changes: 2 additions & 2 deletions Stackless/core/cframeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static PyObject * run_cframe(PyFrameObject *f, int exc, PyObject *retval)
return retval;
}

DEF_INVALID_EXEC(run_cframe)
SLP_DEF_INVALID_EXEC(run_cframe)

PyCFrameObject *
slp_cframe_newfunc(PyObject *func, PyObject *args, PyObject *kwds, unsigned int linked)
Expand Down Expand Up @@ -326,7 +326,7 @@ int slp_init_cframetype(void)
return -1;
/* register the cframe exec func */
return slp_register_execute(&PyCFrame_Type, "run_cframe",
run_cframe, REF_INVALID_EXEC(run_cframe));
run_cframe, SLP_REF_INVALID_EXEC(run_cframe));
}

/* Clear out the free list */
Expand Down
6 changes: 3 additions & 3 deletions Stackless/core/slp_transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#define SLP_SAVE_STATE(stackref, stsizediff) \
intptr_t stsizeb; \
stackref += STACK_MAGIC; \
stackref += SLP_STACK_MAGIC; \
if (_cstprev != NULL) { \
if (slp_cstack_new(_cstprev, (intptr_t *)stackref, _prev) == NULL) __return(-1); \
stsizeb = slp_cstack_save(*_cstprev); \
Expand Down Expand Up @@ -52,10 +52,10 @@ or disable the STACKLESS flag.

SLP_DO_NOT_OPTIMIZE_AWAY_DEFINITIONS

#ifdef EXTERNAL_ASM
#ifdef SLP_EXTERNAL_ASM
/* CCP addition: Make these functions, to be called from assembler.
* The token include file for the given platform should enable the
* EXTERNAL_ASM define so that this is included.
* SLP_EXTERNAL_ASM define so that this is included.
*/

/* There are two cases where slp_save_state would return 0, the
Expand Down
2 changes: 1 addition & 1 deletion Stackless/core/stackless_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C" {
#undef STACKLESS_SPY
/*
* if a platform wants to support self-inspection via _peek,
* it must provide a function or macro CANNOT_READ_MEM(adr, len)
* it must provide a function or macro SLP_CANNOT_READ_MEM(adr, len)
* which allows to spy at memory without causing exceptions.
* This would usually be done in place with the assembly macros.
*/
Expand Down
4 changes: 2 additions & 2 deletions Stackless/core/stackless_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/* This include file is included from internal/pystate.h only */

#include "platf/slp_platformselect.h" /* for CSTACK_SLOTS */
#include "platf/slp_platformselect.h" /* for SLP_CSTACK_SLOTS */

/*
* Stackless runtime state
Expand All @@ -40,7 +40,7 @@ struct _stackless_runtime_state {

/* Used to manage free C-stack objects, see stacklesseval.c */
int cstack_cachecount;
struct _cstack *cstack_cache[CSTACK_SLOTS];
struct _cstack *cstack_cache[SLP_CSTACK_SLOTS];

/*
* Used during a hard switch.
Expand Down
4 changes: 2 additions & 2 deletions Stackless/core/stackless_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ typedef struct _cstack {
struct _tasklet *task;
int nesting_level;
PyThreadState *tstate;
#ifdef _SEH32
#ifdef SLP_SEH32
/* SEH handler on Win32
* The correct type is DWORD, but we do not want to include <windows.h>.
* Instead we use a compile time assertion to ensure, that we use an
Expand All @@ -159,7 +159,7 @@ typedef struct _cstack {
#endif
intptr_t *startaddr;
intptr_t stack[
#if defined(_WINDOWS_) && defined(_SEH32)
#if defined(_WINDOWS_) && defined(SLP_SEH32)
/* Assert the equivalence of DWORD and unsigned long. If <windows.h>
* is included, _WINDOWS_ is defined.
* Py_BUILD_ASSERT_EXPR needs an expression and this is the only one.
Expand Down
26 changes: 13 additions & 13 deletions Stackless/core/stacklesseval.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void slp_cstack_cacheclear(void)
int i;
PyCStackObject *stack;

for (i=0; i < CSTACK_SLOTS; i++) {
for (i=0; i < SLP_CSTACK_SLOTS; i++) {
while ((_PyRuntime.st.cstack_cache)[i] != NULL) {
stack = (_PyRuntime.st.cstack_cache)[i];
(_PyRuntime.st.cstack_cache)[i] = (PyCStackObject *) stack->startaddr;
Expand All @@ -48,11 +48,11 @@ cstack_dealloc(PyCStackObject *cst)
#ifdef Py_REF_DEBUG
PyObject_Del(cst);
#else
if (Py_SIZE(cst) >= CSTACK_SLOTS) {
if (Py_SIZE(cst) >= SLP_CSTACK_SLOTS) {
PyObject_Del(cst);
}
else {
if ((_PyRuntime.st.cstack_cachecount) >= CSTACK_MAXCACHE)
if ((_PyRuntime.st.cstack_cachecount) >= SLP_CSTACK_MAXCACHE)
slp_cstack_cacheclear();
cst->startaddr = (intptr_t *) (_PyRuntime.st.cstack_cache)[Py_SIZE(cst)];
(_PyRuntime.st.cstack_cache)[Py_SIZE(cst)] = cst;
Expand Down Expand Up @@ -91,7 +91,7 @@ slp_cstack_new(PyCStackObject **cst, intptr_t *stackref, PyTaskletObject *task)
(*cst)->task = NULL;
Py_DECREF(*cst);
}
if (size < CSTACK_SLOTS && ((*cst) = (_PyRuntime.st.cstack_cache)[size])) {
if (size < SLP_CSTACK_SLOTS && ((*cst) = (_PyRuntime.st.cstack_cache)[size])) {
/* take stack from cache */
(_PyRuntime.st.cstack_cache)[size] = (PyCStackObject *) (*cst)->startaddr;
--(_PyRuntime.st.cstack_cachecount);
Expand All @@ -108,7 +108,7 @@ slp_cstack_new(PyCStackObject **cst, intptr_t *stackref, PyTaskletObject *task)
(*cst)->task = task;
(*cst)->tstate = ts;
(*cst)->nesting_level = ts->st.nesting_level;
#ifdef _SEH32
#ifdef SLP_SEH32
//save the SEH handler
(*cst)->exception_list = 0;
#endif
Expand All @@ -122,7 +122,7 @@ slp_cstack_save(PyCStackObject *cstprev)

memcpy((cstprev)->stack, (cstprev)->startaddr -
Py_SIZE(cstprev), stsizeb);
#ifdef _SEH32
#ifdef SLP_SEH32
//save the SEH handler
cstprev->exception_list = (DWORD)
__readfsdword(FIELD_OFFSET(NT_TIB, ExceptionList));
Expand All @@ -132,7 +132,7 @@ slp_cstack_save(PyCStackObject *cstprev)
}

void
#ifdef _SEH32
#ifdef SLP_SEH32
#pragma warning(disable:4733) /* disable warning about modifying FS[0] */
#endif
slp_cstack_restore(PyCStackObject *cst)
Expand All @@ -142,7 +142,7 @@ slp_cstack_restore(PyCStackObject *cst)
cst->task = NULL;
memcpy(cst->startaddr - Py_SIZE(cst), &cst->stack,
Py_SIZE(cst) * sizeof(intptr_t));
#ifdef _SEH32
#ifdef SLP_SEH32
//restore the SEH handler
assert(cst->exception_list);
__writefsdword(FIELD_OFFSET(NT_TIB, ExceptionList), (DWORD)(cst->exception_list));
Expand Down Expand Up @@ -343,9 +343,9 @@ slp_eval_frame(PyFrameObject *f)
}

/* mark the stack base */
stackref = STACK_REFPLUS + (intptr_t *) &f;
stackref = SLP_STACK_REFPLUS + (intptr_t *) &f;
if (ts->st.cstack_base == NULL)
ts->st.cstack_base = stackref - CSTACK_GOODGAP;
ts->st.cstack_base = stackref - SLP_CSTACK_GOODGAP;
if (stackref > ts->st.cstack_base) {
PyCStackObject *cst;
retval = climb_stack_and_eval_frame(f);
Expand Down Expand Up @@ -863,7 +863,7 @@ eval_frame_callback(PyFrameObject *f, int exc, PyObject *retval)
* ourselves in an infinite loop of stack spilling.
*/
saved_base = ts->st.cstack_root;
ts->st.cstack_root = STACK_REFPLUS + (intptr_t *) &f;
ts->st.cstack_root = SLP_STACK_REFPLUS + (intptr_t *) &f;

/* pull in the right retval and tempval from the arguments */
Py_SETREF(retval, cf->ob1);
Expand Down Expand Up @@ -926,14 +926,14 @@ slp_eval_frame_newstack(PyFrameObject *f, int exc, PyObject *retval)
* magic here will clear that exception.
*/
intptr_t *old = ts->st.cstack_root;
ts->st.cstack_root = STACK_REFPLUS + (intptr_t *) &f;
ts->st.cstack_root = SLP_STACK_REFPLUS + (intptr_t *) &f;
retval = PyEval_EvalFrameEx_slp(f, exc, retval);
ts->st.cstack_root = old;
return retval;
}
if (ts->st.cstack_root == NULL) {
/* this is a toplevel call. Store the root of stack spilling */
ts->st.cstack_root = STACK_REFPLUS + (intptr_t *) &f;
ts->st.cstack_root = SLP_STACK_REFPLUS + (intptr_t *) &f;
retval = PyEval_EvalFrameEx_slp(f, exc, retval);
/* and reset it. We may reenter stackless at a completely different
* depth later
Expand Down
8 changes: 4 additions & 4 deletions Stackless/module/stacklessmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1405,15 +1405,15 @@ _peek(PyObject *self, PyObject *v)
if (!PyLong_Check(v)) goto noobject;
o = (PyObject*) PyLong_AsVoidPtr(v);
/* this is plain heuristics, use for now */
if (CANNOT_READ_MEM(o, sizeof(PyObject))) goto noobject;
if (IS_ON_STACK(o)) goto noobject;
if (SLP_CANNOT_READ_MEM(o, sizeof(PyObject))) goto noobject;
if (SLP_IS_ON_STACK(o)) goto noobject;
if (Py_REFCNT(o) < 1 || Py_REFCNT(o) > 10000) goto noobject;
t = Py_TYPE(o);
for (i=0; i<100; i++) {
if (t == &PyType_Type)
break;
if (CANNOT_READ_MEM(t, sizeof(PyTypeObject))) goto noobject;
if (IS_ON_STACK(o)) goto noobject;
if (SLP_CANNOT_READ_MEM(t, sizeof(PyTypeObject))) goto noobject;
if (SLP_IS_ON_STACK(o)) goto noobject;
if (Py_REFCNT(t) < 1 || Py_REFCNT(t) > 10000) goto noobject;
if (!(isalpha(t->tp_name[0])||t->tp_name[0]=='_'))
goto noobject;
Expand Down
40 changes: 20 additions & 20 deletions Stackless/pickling/prickelpit.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,15 +835,15 @@ static int init_functype(PyObject * mod)

#define frametuplefmt "O)(OiSOiOOiiOO"

DEF_INVALID_EXEC(eval_frame)
DEF_INVALID_EXEC(eval_frame_value)
DEF_INVALID_EXEC(eval_frame_noval)
DEF_INVALID_EXEC(eval_frame_iter)
DEF_INVALID_EXEC(eval_frame_setup_with)
DEF_INVALID_EXEC(eval_frame_with_cleanup)
DEF_INVALID_EXEC(slp_channel_seq_callback)
DEF_INVALID_EXEC(slp_restore_tracing)
DEF_INVALID_EXEC(slp_tp_init_callback)
SLP_DEF_INVALID_EXEC(eval_frame)
SLP_DEF_INVALID_EXEC(eval_frame_value)
SLP_DEF_INVALID_EXEC(eval_frame_noval)
SLP_DEF_INVALID_EXEC(eval_frame_iter)
SLP_DEF_INVALID_EXEC(eval_frame_setup_with)
SLP_DEF_INVALID_EXEC(eval_frame_with_cleanup)
SLP_DEF_INVALID_EXEC(slp_channel_seq_callback)
SLP_DEF_INVALID_EXEC(slp_restore_tracing)
SLP_DEF_INVALID_EXEC(slp_tp_init_callback)

static PyTypeObject wrap_PyFrame_Type;

Expand Down Expand Up @@ -1193,23 +1193,23 @@ MAKE_WRAPPERTYPE(PyFrame_Type, frame, "frame", frameobject_reduce, frame_new, fr
static int init_frametype(PyObject * mod)
{
return slp_register_execute(&PyFrame_Type, "eval_frame",
PyEval_EvalFrameEx_slp, REF_INVALID_EXEC(eval_frame))
PyEval_EvalFrameEx_slp, SLP_REF_INVALID_EXEC(eval_frame))
|| slp_register_execute(&PyFrame_Type, "eval_frame_value",
slp_eval_frame_value, REF_INVALID_EXEC(eval_frame_value))
slp_eval_frame_value, SLP_REF_INVALID_EXEC(eval_frame_value))
|| slp_register_execute(&PyFrame_Type, "eval_frame_noval",
slp_eval_frame_noval, REF_INVALID_EXEC(eval_frame_noval))
slp_eval_frame_noval, SLP_REF_INVALID_EXEC(eval_frame_noval))
|| slp_register_execute(&PyFrame_Type, "eval_frame_iter",
slp_eval_frame_iter, REF_INVALID_EXEC(eval_frame_iter))
slp_eval_frame_iter, SLP_REF_INVALID_EXEC(eval_frame_iter))
|| slp_register_execute(&PyFrame_Type, "eval_frame_setup_with",
slp_eval_frame_setup_with, REF_INVALID_EXEC(eval_frame_setup_with))
slp_eval_frame_setup_with, SLP_REF_INVALID_EXEC(eval_frame_setup_with))
|| slp_register_execute(&PyFrame_Type, "eval_frame_with_cleanup",
slp_eval_frame_with_cleanup, REF_INVALID_EXEC(eval_frame_with_cleanup))
slp_eval_frame_with_cleanup, SLP_REF_INVALID_EXEC(eval_frame_with_cleanup))
|| slp_register_execute(&PyCFrame_Type, "channel_seq_callback",
slp_channel_seq_callback, REF_INVALID_EXEC(slp_channel_seq_callback))
slp_channel_seq_callback, SLP_REF_INVALID_EXEC(slp_channel_seq_callback))
|| slp_register_execute(&PyCFrame_Type, "slp_restore_tracing",
slp_restore_tracing, REF_INVALID_EXEC(slp_restore_tracing))
slp_restore_tracing, SLP_REF_INVALID_EXEC(slp_restore_tracing))
|| slp_register_execute(&PyCFrame_Type, "slp_tp_init_callback",
slp_tp_init_callback, REF_INVALID_EXEC(slp_tp_init_callback))
slp_tp_init_callback, SLP_REF_INVALID_EXEC(slp_tp_init_callback))
|| init_type(&wrap_PyFrame_Type, initchain, mod);
}
#undef initchain
Expand Down Expand Up @@ -1825,7 +1825,7 @@ gen_setstate(PyObject *self, PyObject *args)
MAKE_WRAPPERTYPE(PyGen_Type, gen, "generator", gen_reduce,
gen_new, gen_setstate)

DEF_INVALID_EXEC(gen_iternext_callback)
SLP_DEF_INVALID_EXEC(gen_iternext_callback)

static int init_generatortype(PyObject * mod)
{
Expand All @@ -1841,7 +1841,7 @@ static int init_generatortype(PyObject * mod)
cbframe = gen->gi_frame->f_back;
res = slp_register_execute(Py_TYPE(cbframe), "gen_iternext_callback",
gen->gi_frame->f_back->f_execute,
REF_INVALID_EXEC(gen_iternext_callback))
SLP_REF_INVALID_EXEC(gen_iternext_callback))
|| init_type(&wrap_PyGen_Type, initchain, mod);

assert(gen_exhausted_frame == NULL);
Expand Down
4 changes: 2 additions & 2 deletions Stackless/pickling/prickelpit.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ PyObject * slp_cannot_execute(PyFrameObject *f, const char *exec_name, PyObject

/* macros to define and use an invalid frame executor */

#define DEF_INVALID_EXEC(procname) \
#define SLP_DEF_INVALID_EXEC(procname) \
static PyObject *\
cannot_##procname(PyFrameObject *f, int exc, PyObject *retval) \
{ \
return slp_cannot_execute(f, #procname, retval); \
}

#define REF_INVALID_EXEC(procname) (cannot_##procname)
#define SLP_REF_INVALID_EXEC(procname) (cannot_##procname)


/* pickling of arrays with nulls */
Expand Down
4 changes: 2 additions & 2 deletions Stackless/pickling/safe_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pickle_callback(PyFrameObject *f, int exc, PyObject *retval)
* ourselves in an infinite loop of stack spilling.
*/
saved_base = ts->st.cstack_root;
ts->st.cstack_root = STACK_REFPLUS + (intptr_t *) &f;
ts->st.cstack_root = SLP_STACK_REFPLUS + (intptr_t *) &f;
if (retval) {
Py_DECREF(retval);
cf->i = cPickle_save(cf->ob1, cf->ob2, cf->n);
Expand Down Expand Up @@ -128,7 +128,7 @@ pickle_M(PyObject *self, PyObject *args, int pers_save)
_self = self;
_args = args;
_pers_save = pers_save;
ts->st.cstack_root = STACK_REFPLUS + (intptr_t *) &self;
ts->st.cstack_root = SLP_STACK_REFPLUS + (intptr_t *) &self;
ret = slp_int_wrapper(slp_eval_frame((PyFrameObject *)cf));
return ret;
}
Expand Down
Loading

0 comments on commit 58f239a

Please sign in to comment.