aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz93@gmail.com>2024-05-13 16:27:43 -0400
committerEli Schwartz <eschwartz93@gmail.com>2024-06-23 16:15:52 -0400
commit8835ad4e02061bb3ff07293580b0986d2bb2cdb4 (patch)
tree2dcb0d4d4f673512b74d26c27f85a1d86ef1ec11
parent8fe8b1d829f057c556143a658d3f26bc66c69ee8 (diff)
downloadmeson-8835ad4e02061bb3ff07293580b0986d2bb2cdb4.zip
meson-8835ad4e02061bb3ff07293580b0986d2bb2cdb4.tar.gz
meson-8835ad4e02061bb3ff07293580b0986d2bb2cdb4.tar.bz2
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 c34ee374a77fb2dffff90364506ac0cbbb1f00de; before that, we still used locals() but only to pass local variables *in*. Bug: https://github.com/python/cpython/pull/115153
-rw-r--r--mesonbuild/msetup.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/mesonbuild/msetup.py b/mesonbuild/msetup.py
index 931b1eb..47b40af 100644
--- a/mesonbuild/msetup.py
+++ b/mesonbuild/msetup.py
@@ -242,10 +242,11 @@ class MesonApp:
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)