summaryrefslogtreecommitdiff
path: root/core/variant/variant_setget.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-05-17 15:11:48 +0200
committerGitHub <noreply@github.com>2022-05-17 15:11:48 +0200
commit35004aea48011296b9461c3c4e14100b8d686191 (patch)
tree2fecdaad9cf65bada3849922cded9034dc99df36 /core/variant/variant_setget.cpp
parent5b02415fd0a603f76368212e829fc4f839200064 (diff)
parente6c443a353cb3923b80f4fa112667a08159ee971 (diff)
Merge pull request #61087 from reduz/readonly-dictionary
Implement read-only dictionaries.
Diffstat (limited to 'core/variant/variant_setget.cpp')
-rw-r--r--core/variant/variant_setget.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp
index 6023e4d129..6514922d01 100644
--- a/core/variant/variant_setget.cpp
+++ b/core/variant/variant_setget.cpp
@@ -766,11 +766,20 @@ struct VariantIndexedSetGet_String {
PtrToArg<Variant>::encode(*ptr, member); \
} \
static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) { \
+ if (VariantGetInternalPtr<m_base_type>::get_ptr(base)->is_read_only()) { \
+ *valid = false; \
+ *oob = true; \
+ return; \
+ } \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index] = *value; \
*oob = false; \
*valid = true; \
} \
static void validated_set(Variant *base, int64_t index, const Variant *value, bool *oob) { \
+ if (VariantGetInternalPtr<m_base_type>::get_ptr(base)->is_read_only()) { \
+ *oob = true; \
+ return; \
+ } \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index] = *value; \
*oob = false; \
} \
@@ -946,6 +955,10 @@ struct VariantKeyedSetGetDictionary {
PtrToArg<Variant>::encode(*ptr, value);
}
static void set(Variant *base, const Variant *key, const Variant *value, bool *r_valid) {
+ if (VariantGetInternalPtr<Dictionary>::get_ptr(base)->is_read_only()) {
+ *r_valid = false;
+ return;
+ }
(*VariantGetInternalPtr<Dictionary>::get_ptr(base))[*key] = *value;
*r_valid = true;
}