aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2022-12-15 16:23:48 -0800
committerEli Schwartz <eschwartz93@gmail.com>2023-01-18 17:55:41 -0500
commite0efc7603e3f3a84f9f940d06a8058ec0b48b62b (patch)
tree1081752e6294a2f0a8639d0b63f430081dbe0208 /mesonbuild
parent42bfe534464c724f756cc326cb47cf4f3e01f3c4 (diff)
downloadmeson-e0efc7603e3f3a84f9f940d06a8058ec0b48b62b.zip
meson-e0efc7603e3f3a84f9f940d06a8058ec0b48b62b.tar.gz
meson-e0efc7603e3f3a84f9f940d06a8058ec0b48b62b.tar.bz2
coredata: Make a deepcopy of global state before mutating
When a compiler is initialized, it adds specific options that it supports, but taking some global UserOption objects and adding them to itself. When it does so, it mutates then if necessary. This means that each compiler initialized mutates global state, this is bad. This is worse because in our test suite we do in process testing, so these mutations are preserved *between tests*, potentially leading to incorrect results. The simple fix is to do the right thing, and copy the UserOption before mutating. A deepcopy is required because the option might be an ArrayOption, and a shallow copy is not sufficient in that case.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/coredata.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 58c0949..fd8b4b2 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import copy
+
from . import mlog, mparser
import pickle, os, uuid
import sys
@@ -886,7 +888,7 @@ class CoreData:
for key in comp.base_options:
if key in self.options:
continue
- oobj = compilers.base_options[key]
+ oobj = copy.deepcopy(compilers.base_options[key])
if key in env.options:
oobj.set_value(env.options[key])
enabled_opts.append(key)