Skip to content

Commit 0c44d00

Browse files
eli-schwartzVolker-Weissmann
authored andcommitted
msetup: fix regression under py3.13 causing profile.runctx to not write locals()
"PEP 667: Consistent views of namespaces" caused locals() to be inconsistent between uses since it is now created afresh every time you invoke it and writes to it are dropped. `sys._getframe().f_locals` is equivalent but preserves writes (it doesn't create a new dict) and unfortunately doesn't help at all as it's documented to be a private implementation detail of CPython that "should be used for internal and specialized purposes only". Work around this by saving locals to a variable reference and both passing it into runctx and reusing it in lookups of the result. This works okay for both new and older versions of python. Per the documentation for locals(): > The contents of this dictionary should not be modified; changes may > not affect the values of local and free variables used by the > interpreter. So... lesson learned? :) This was introduced in commit c34ee37; before that, we still used locals() but only to pass local variables *in*. Bug: python/cpython#115153
1 parent 30d0c7a commit 0c44d00

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mesonbuild/msetup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,11 @@ def _generate(self, env: environment.Environment, capture: bool, vslite_ctx: T.O
242242

243243
self.finalize_postconf_hooks(b, intr)
244244
if self.options.profile:
245+
localvars = locals()
245246
fname = f'profile-{intr.backend.name}-backend.log'
246247
fname = os.path.join(self.build_dir, 'meson-logs', fname)
247-
profile.runctx('gen_result = intr.backend.generate(capture, vslite_ctx)', globals(), locals(), filename=fname)
248-
captured_compile_args = locals()['gen_result']
248+
profile.runctx('gen_result = intr.backend.generate(capture, vslite_ctx)', globals(), localvars, filename=fname)
249+
captured_compile_args = localvars['gen_result']
249250
assert captured_compile_args is None or isinstance(captured_compile_args, dict)
250251
else:
251252
captured_compile_args = intr.backend.generate(capture, vslite_ctx)

0 commit comments

Comments
 (0)