Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fdd12f6

Browse files
committed
Refactor future feature handling
Replace individual slots in PyFutureFeatures with a single bitmask with one field per feature. The flags for this bitmask are the same as the flags used in the co_flags slot of a code object. XXX This means we waste several bits, because they are used for co_flags but have no meaning for future statements. Don't think this is an issue. Remove the NESTED_SCOPES_DEFAULT define and others. Not sure what they were for anyway. Remove all the PyCF_xxx flags, but define PyCF_MASK in terms of the CO_xxx flags that are relevant for this release. Change definition of PyCompilerFlags so that cf_flags matches co_flags.
1 parent 11ee902 commit fdd12f6

2 files changed

Lines changed: 3 additions & 16 deletions

File tree

Include/compile.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ typedef struct {
4141
effect, this passes on the "from __future__ import generators" state
4242
in effect when the code block was compiled. */
4343
#define CO_GENERATOR_ALLOWED 0x1000
44-
/* XXX Ditto for future division */
4544
#define CO_FUTURE_DIVISION 0x2000
4645

4746
extern DL_IMPORT(PyTypeObject) PyCode_Type;
@@ -64,22 +63,15 @@ DL_IMPORT(int) PyCode_Addr2Line(PyCodeObject *, int);
6463
typedef struct {
6564
int ff_found_docstring;
6665
int ff_last_lineno;
67-
int ff_nested_scopes;
68-
int ff_generators;
69-
int ff_division;
66+
int ff_features;
7067
} PyFutureFeatures;
7168

7269
DL_IMPORT(PyFutureFeatures *) PyNode_Future(struct _node *, char *);
7370
DL_IMPORT(PyCodeObject *) PyNode_CompileFlags(struct _node *, char *,
7471
PyCompilerFlags *);
7572

76-
#define NESTED_SCOPES_DEFAULT 1
7773
#define FUTURE_NESTED_SCOPES "nested_scopes"
78-
79-
#define GENERATORS_DEFAULT 0
8074
#define FUTURE_GENERATORS "generators"
81-
82-
#define DIVISION_DEFAULT 0
8375
#define FUTURE_DIVISION "division"
8476

8577
/* for internal use only */

Include/pythonrun.h

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

10-
/* These flags are named after the __future__ statements that introduced
11-
them. May not remain true for later additions, so fiddle this comment
12-
accordingly then. */
13-
#define PyCF_NESTED_SCOPES (0x00000001UL)
14-
#define PyCF_GENERATORS (0x00000002UL)
15-
#define PyCF_DIVISION (0x00000004UL)
10+
#define PyCF_MASK (CO_GENERATOR_ALLOWED | CO_FUTURE_DIVISION)
1611
typedef struct {
17-
unsigned long cf_flags; /* bitmask of PyCF_xxx flags */
12+
int cf_flags; /* bitmask of CO_xxx flags relevant to future */
1813
} PyCompilerFlags;
1914

2015
DL_IMPORT(void) Py_SetProgramName(char *);

0 commit comments

Comments
 (0)