Skip to content

Commit

Permalink
msetup: fix regression under py3.13 causing profile.runctx to not wri…
Browse files Browse the repository at this point in the history
…te 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.

Bug: python/cpython#115153
  • Loading branch information
eli-schwartz committed May 13, 2024
1 parent 4ce8326 commit 242ace9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mesonbuild/msetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,11 @@ def _generate(self, env: environment.Environment, capture: bool, vslite_ctx: T.O

self.finalize_postconf_hooks(b, intr)
if self.options.profile:
localvars = locals()
fname = f'profile-{intr.backend.name}-backend.log'
fname = os.path.join(self.build_dir, 'meson-logs', fname)
profile.runctx('gen_result = intr.backend.generate(capture, vslite_ctx)', globals(), locals(), filename=fname)
captured_compile_args = locals()['gen_result']
profile.runctx('gen_result = intr.backend.generate(capture, vslite_ctx)', globals(), localvars, filename=fname)
captured_compile_args = localvars['gen_result']
assert captured_compile_args is None or isinstance(captured_compile_args, dict)
else:
captured_compile_args = intr.backend.generate(capture, vslite_ctx)
Expand Down

0 comments on commit 242ace9

Please sign in to comment.