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

Skip to content

Commit e2c18e9

Browse files
committed
ceval, PyEval_MergeCompilerFlags: wasn't merging in the
CO_FUTURE_DIVISION flag. Redid this to use Jeremy's PyCF_MASK #define instead, so we dont have to remember to fiddle individual feature names here again. pythonrun.h: Also #define a PyCF_MASK_OBSOLETE mask. This isn't used yet, but will be as part of the PEP 264 implementation (compile() mustn't raise an error just because old code uses a flag name that's become obsolete; a warning may be appropriate, but not an error; so compile() has to know about obsolete flags too, but nobody is going to remember to update compile() with individual obsolete flag names across releases either -- i.e., this is the flip side of PyEval_MergeCompilerFlags's oversight).
1 parent 9676b22 commit e2c18e9

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

Include/pythonrun.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern "C" {
88
#endif
99

1010
#define PyCF_MASK (CO_GENERATOR_ALLOWED | CO_FUTURE_DIVISION)
11+
#define PyCF_MASK_OBSOLETE (CO_NESTED)
12+
1113
typedef struct {
1214
int cf_flags; /* bitmask of CO_xxx flags relevant to future */
1315
} PyCompilerFlags;

Python/ceval.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,13 +2928,10 @@ PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
29282928

29292929
if (current_frame != NULL) {
29302930
const int codeflags = current_frame->f_code->co_flags;
2931-
if (codeflags & CO_NESTED) {
2931+
const int compilerflags = codeflags & PyCF_MASK;
2932+
if (compilerflags) {
29322933
result = 1;
2933-
cf->cf_flags |= CO_NESTED;
2934-
}
2935-
if (codeflags & CO_GENERATOR_ALLOWED) {
2936-
result = 1;
2937-
cf->cf_flags |= CO_GENERATOR_ALLOWED;
2934+
cf->cf_flags |= compilerflags;
29382935
}
29392936
}
29402937
return result;

0 commit comments

Comments
 (0)