Skip to content

Commit 45e1f15

Browse files
Anselm KruisAnselm Kruis
authored andcommitted
Stackless issue python#185: various cleanups
Move type definitions to stackless_structs.h Move API declarations to stackless_api.h Move declarations of pickle functions to prickelpit.h Include frameobject.h only if needed.
1 parent ee3b4b5 commit 45e1f15

File tree

8 files changed

+72
-83
lines changed

8 files changed

+72
-83
lines changed

Modules/_pickle.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010

1111
#ifdef STACKLESS
1212
#define SLP_BUILD_CORE
13-
#include "core/stackless_impl.h"
13+
#include "stackless_api.h"
14+
#include "pickling/prickelpit.h"
1415
#include "platf/slp_platformselect.h" /* for stack saving */
15-
/* rename these because otherwise we will conflict with windows.h */
16-
#define FLOAT OP_FLOAT
17-
#define INT OP_INT
18-
#define LONG OP_LONG
1916
#endif
2017

2118
PyDoc_STRVAR(pickle_module_doc,

Stackless/core/slp_transfer.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
21
#include "Python.h"
32
#include <stddef.h> /* For ptrdiff_t */
43

54
#ifdef STACKLESS
65

7-
#ifndef STACKLESS
8-
**********
9-
If you see this error message,
10-
your operating system is not supported yet.
11-
Please provide an implementation of the switch_XXX.h
12-
or disable the STACKLESS flag.
13-
**********
14-
#endif
15-
166
#include "stackless_impl.h"
177

188
/*
@@ -51,6 +41,15 @@ or disable the STACKLESS flag.
5141
#endif
5242
#include "platf/slp_platformselect.h"
5343

44+
#ifndef STACKLESS
45+
**********
46+
If you see this error message,
47+
your operating system is not supported yet.
48+
Please provide an implementation of the switch_XXX.h
49+
or disable the STACKLESS flag.
50+
**********
51+
#endif
52+
5453
SLP_DO_NOT_OPTIMIZE_AWAY_DEFINITIONS
5554

5655
#ifdef EXTERNAL_ASM

Stackless/core/stackless_impl.h

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,19 @@
77
extern "C" {
88
#endif
99

10+
#ifdef STACKLESS
11+
1012
#if defined(Py_BUILD_CORE) && !defined(SLP_BUILD_CORE)
1113
#define SLP_BUILD_CORE
1214
#endif
1315

14-
#ifdef STACKLESS
15-
16-
#ifdef Py_BUILD_CORE
17-
#include "internal/pystate.h" /* for _PyRuntime */
18-
#endif /* #ifdef Py_BUILD_CORE */
19-
20-
#include "core/stackless_structs.h"
2116
#include "stackless_api.h"
2217

23-
/* CPython added these two macros in object.h for 2.7 and 3.5 */
24-
#ifndef Py_SETREF
25-
#define Py_SETREF(op, op2) \
26-
do { \
27-
PyObject *_py_tmp = (PyObject *)(op); \
28-
(op) = (op2); \
29-
Py_DECREF(_py_tmp); \
30-
} while (0)
31-
#endif
18+
#ifdef SLP_BUILD_CORE
3219

33-
#ifndef Py_XSETREF
34-
#define Py_XSETREF(op, op2) \
35-
do { \
36-
PyObject *_py_tmp = (PyObject *)(op); \
37-
(op) = (op2); \
38-
Py_XDECREF(_py_tmp); \
39-
} while (0)
20+
#ifdef Py_BUILD_CORE
21+
#include "internal/pystate.h" /* for _PyRuntime */
4022
#endif
41-
42-
#ifdef SLP_BUILD_CORE
4323
#include "pickling/prickelpit.h"
4424

4525
#undef STACKLESS_SPY
@@ -405,22 +385,6 @@ PyObject * slp_tp_init_callback(PyFrameObject *f, int exc, PyObject *retval);
405385
/* functions related to pickling */
406386
PyObject * slp_reduce_frame(PyFrameObject * frame);
407387

408-
/* rebirth of software stack avoidance */
409-
410-
typedef struct _unwindobject {
411-
PyObject_HEAD
412-
} PyUnwindObject;
413-
414-
#else /* #ifdef SLP_BUILD_CORE */
415-
416-
typedef struct _unwindobject PyUnwindObject;
417-
418-
#endif /* #ifdef SLP_BUILD_CORE */
419-
420-
PyAPI_DATA(PyUnwindObject *) Py_UnwindToken;
421-
422-
#ifdef SLP_BUILD_CORE
423-
424388
/* frame cloning both needed in tasklets and generators */
425389

426390
struct _frame * slp_clone_frame(struct _frame *f);
@@ -443,12 +407,10 @@ PyTaskletObject * slp_get_watchdog(PyThreadState *ts, int interrupt);
443407
retval = (tstate)->st.unwinding_retval, \
444408
(tstate)->st.unwinding_retval = NULL, retval))
445409

446-
#endif /* #ifdef SLP_BUILD_CORE */
447-
410+
#if 0 /* defined in stackless_api.h */
448411
#define STACKLESS_UNWINDING(obj) \
449412
((PyObject *) (obj) == (PyObject *) Py_UnwindToken)
450-
451-
#ifdef SLP_BUILD_CORE
413+
#endif
452414

453415
/* an arbitrary positive number */
454416
#define STACKLESS_UNWINDING_MAGIC 0x7fedcba9
@@ -757,17 +719,6 @@ PyObject * slp_runtime_error(const char *msg);
757719
PyObject * slp_value_error(const char *msg);
758720
PyObject * slp_null_error(void);
759721

760-
/* this seems to be needed for gcc */
761-
762-
/* Define NULL pointer value */
763-
764-
#undef NULL
765-
#ifdef __cplusplus
766-
#define NULL 0
767-
#else
768-
#define NULL ((void *)0)
769-
#endif
770-
771722
#define TYPE_ERROR(str, ret) return (slp_type_error(str), ret)
772723
#define RUNTIME_ERROR(str, ret) return (slp_runtime_error(str), ret)
773724
#define VALUE_ERROR(str, ret) return (slp_value_error(str), ret)
@@ -790,11 +741,6 @@ int slp_resurrect_and_kill(PyObject *self,
790741
void(*killer)(PyObject *));
791742

792743
/* stackless pickling support */
793-
int slp_safe_pickling(int(*save)(PyObject *, PyObject *, int),
794-
PyObject *self, PyObject *args,
795-
int pers_save);
796-
797-
PyObject * PyStackless_Pickle_ModuleDict(PyObject *pickler, PyObject *self);
798744
int slp_async_gen_init_hooks(PyAsyncGenObject *o);
799745
PyObject * slp_async_gen_asend_reduce(PyObject *o, PyTypeObject * wrapper_type);
800746
PyObject * slp_async_gen_asend_new(PyAsyncGenObject *gen);

Stackless/core/stackless_structs.h

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
extern "C" {
66
#endif
77

8+
#ifdef STACKLESS
9+
810
#if defined(Py_BUILD_CORE) && !defined(SLP_BUILD_CORE)
911
#define SLP_BUILD_CORE
1012
#endif
1113

12-
#include "frameobject.h"
13-
14-
#ifdef STACKLESS
1514
#ifdef SLP_BUILD_CORE
1615

16+
#include "frameobject.h"
17+
#include "platf/slp_platformselect.h"
18+
1719
/*** important structures: tasklet ***/
1820

1921

@@ -148,10 +150,24 @@ typedef struct _cstack {
148150
int nesting_level;
149151
PyThreadState *tstate;
150152
#ifdef _SEH32
151-
DWORD exception_list; /* SEH handler on Win32 */
153+
/* SEH handler on Win32
154+
* The correct type is DWORD, but we do not want to include <windows.h>.
155+
* Instead we use a compile time assertion to ensure, that we use an
156+
* equivalent type.
157+
*/
158+
unsigned long exception_list;
152159
#endif
153160
intptr_t *startaddr;
154-
intptr_t stack[1];
161+
intptr_t stack[
162+
#if defined(_WINDOWS_) && defined(_SEH32)
163+
/* Assert the equivalence of DWORD and unsigned long. If <windows.h>
164+
* is included, _WINDOWS_ is defined.
165+
* Py_BUILD_ASSERT_EXPR needs an expression and this is the only one.
166+
*/
167+
Py_BUILD_ASSERT_EXPR(sizeof(unsigned long) == sizeof(DWORD)) +
168+
Py_BUILD_ASSERT_EXPR(((DWORD)-1) > 0) + /* signedness */
169+
#endif
170+
1];
155171
} PyCStackObject;
156172

157173

@@ -239,6 +255,9 @@ typedef struct _cframe {
239255
void *any2;
240256
} PyCFrameObject;
241257

258+
typedef struct _unwindobject {
259+
PyObject_HEAD
260+
} PyUnwindObject;
242261

243262

244263
/*** associated type objects ***/
@@ -266,6 +285,7 @@ PyAPI_DATA(PyTypeObject) PyChannel_Type;
266285
typedef struct _channel PyChannelObject;
267286
typedef struct _cframe PyCFrameObject;
268287
typedef struct _tasklet PyTaskletObject;
288+
typedef struct _unwindobject PyUnwindObject;
269289

270290
#endif /* #ifdef SLP_BUILD_CORE */
271291
#endif /* #ifdef STACKLESS */

Stackless/core/stackless_tstate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ typedef struct {
3636
uint8_t pickleflags; /* flags for pickling / unpickling */
3737
} PyStacklessInterpreterState;
3838

39+
#ifdef Py_BUILD_CORE
3940
#define SLP_INITIAL_TSTATE(tstate) \
4041
(assert(tstate), \
4142
assert((tstate)->interp->st.initial_tstate), \
@@ -64,6 +65,8 @@ typedef struct {
6465
(interp)->st.enable_softswitch = 1; \
6566
(interp)->st.pickleflags = 0;
6667

68+
#endif /* #ifdef Py_BUILD_CORE */
69+
6770
struct _frame; /* Avoid including frameobject.h */
6871

6972
typedef struct _sts {

Stackless/module/_teststackless.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include "Python.h"
19+
#include "frameobject.h"
1920
#include "stackless_api.h"
2021
#ifdef MS_WINDOWS
2122
#include "malloc.h" /* for alloca */

Stackless/pickling/prickelpit.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,19 @@ Py_ssize_t slp_from_tuple_with_nulls(PyObject **start, PyObject *tup);
5454

5555
PyObject * slp_pickle_moduledict(PyObject *self, PyObject *args);
5656
extern char slp_pickle_moduledict__doc__[];
57+
PyObject * PyStackless_Pickle_ModuleDict(PyObject *pickler, PyObject *self);
5758

5859
/* initialization */
5960

6061
PyObject *slp_init_prickelpit(void);
6162

63+
/* pickle with stack spilling */
64+
int slp_safe_pickling(int(*save)(PyObject *, PyObject *, int),
65+
PyObject *self, PyObject *args,
66+
int pers_save);
67+
68+
69+
6270
#ifdef __cplusplus
6371
}
6472
#endif

Stackless/stackless_api.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ extern "C" {
3434
3535
******************************************************/
3636

37-
#include "core/stackless_impl.h"
38-
3937
#ifdef STACKLESS
38+
39+
#include "core/stackless_structs.h"
40+
4041
/*
4142
* create a new tasklet object.
4243
* type must be derived from PyTasklet_Type or NULL.
@@ -394,6 +395,20 @@ PyAPI_FUNC(int) PyStackless_SetScheduleCallback(PyObject *callable);
394395
*/
395396
PyAPI_FUNC(void) PyStackless_SetScheduleFastcallback(slp_schedule_hook_func func);
396397

398+
/******************************************************
399+
400+
other functions
401+
402+
******************************************************/
403+
404+
405+
/*
406+
* Stack unwinding
407+
*/
408+
PyAPI_DATA(PyUnwindObject *) Py_UnwindToken;
409+
#define STACKLESS_UNWINDING(obj) \
410+
((PyObject *) (obj) == (PyObject *) Py_UnwindToken)
411+
397412
/******************************************************
398413
399414
interface functions

0 commit comments

Comments
 (0)