@@ -494,8 +494,10 @@ static PyCodeObject *optimize_and_assemble(struct compiler *, int addNone);
494494
495495static int
496496compiler_setup (struct compiler * c , mod_ty mod , PyObject * filename ,
497- PyCompilerFlags flags , int optimize , PyArena * arena )
497+ PyCompilerFlags * flags , int optimize , PyArena * arena )
498498{
499+ PyCompilerFlags local_flags = _PyCompilerFlags_INIT ;
500+
499501 c -> c_const_cache = PyDict_New ();
500502 if (!c -> c_const_cache ) {
501503 return ERROR ;
@@ -511,10 +513,13 @@ compiler_setup(struct compiler *c, mod_ty mod, PyObject *filename,
511513 if (!_PyFuture_FromAST (mod , filename , & c -> c_future )) {
512514 return ERROR ;
513515 }
514- int merged = c -> c_future .ff_features | flags .cf_flags ;
516+ if (!flags ) {
517+ flags = & local_flags ;
518+ }
519+ int merged = c -> c_future .ff_features | flags -> cf_flags ;
515520 c -> c_future .ff_features = merged ;
516- flags . cf_flags = merged ;
517- c -> c_flags = flags ;
521+ flags -> cf_flags = merged ;
522+ c -> c_flags = * flags ;
518523 c -> c_optimize = (optimize == -1 ) ? _Py_GetConfig ()-> optimization_level : optimize ;
519524 c -> c_nestlevel = 0 ;
520525
@@ -535,12 +540,11 @@ static struct compiler*
535540new_compiler (mod_ty mod , PyObject * filename , PyCompilerFlags * pflags ,
536541 int optimize , PyArena * arena )
537542{
538- PyCompilerFlags flags = pflags ? * pflags : _PyCompilerFlags_INIT ;
539543 struct compiler * c = PyMem_Calloc (1 , sizeof (struct compiler ));
540544 if (c == NULL ) {
541545 return NULL ;
542546 }
543- if (compiler_setup (c , mod , filename , flags , optimize , arena ) < 0 ) {
547+ if (compiler_setup (c , mod , filename , pflags , optimize , arena ) < 0 ) {
544548 compiler_free (c );
545549 return NULL ;
546550 }
0 commit comments