Hello Simon,
On 23.12.24 16:10, Simon Lundmark wrote:
> Hi,
>
> We are on driver 3.5.7 and migrated fairly recently (august/september).
>
> We have noticed some issues with mappings:
>
> Case one:
> We have an alias mapping in our player object. It's really simple
> string->string mapping. I discovered that using:
> string subst;
> m_contains(&subst, aliases, verb);
>
> Now means that subst is a reference to the actual string IN the
> mapping. So if I modify "subst", the value in the mapping also gets
> changed (in this case, a regexplode() followed by an assignment from
> an implode()-call)
I cannot reproduce this with 3.6.7:
void test_m_contains()
{
int i;
string s;
mapping m = ([ "a": 1, "b": "foo" ]);
printf("%O\n", m);
m_contains(&i, m, "a");
printf("%O\n", i);
i = -1;
printf("%O\n", i);
printf("%O\n", m);
m_contains(&s, m, "b");
printf("%O\n", s);
s = "bar";
printf("%O\n", s);
printf("%O\n", m);
}
prints:
([ /* #1 */
"a": 1,
"b": "foo"
])
1
-1
([ /* #1 */
"a": 1,
"b": "foo"
])
"foo"
"bar"
([ /* #1 */
"a": 1,
"b": "foo"
])
as expected. Also the driver code in src/mapping.c does in fact copy the
value; and that code hasn't been changed in a long time.
Could it be that you stored references in the mapping in the first place?
If I do:
int i = 1;
string s = "foo";
mapping m = ([ "a": &i, "b": &s ]);
the code behaves exactly as you describe (and as expected in this case).
Sidenote: why not just do something like
verb = aliases[verb] || verb;
> Case two:
> We have, in obscure cases, noticed that doing:
> mapping m, a;
> ...
> m = m + a;
>
> Does not yield the expected result. And changing it to m += a; would
> instead yield the expected result.
Again, I cannot reproduce this with 3.6.7:
xc ([ "a": 1, "b": 2 ]) + ([ "a": -1, "c": 3 ])
CCALL: Result = ([ /* #1 */
CCALL: "c": 3,
CCALL: "a": -1,
CCALL: "b": 2
CCALL: ])
as expected and documented in doc/LPC/operators.
cya,
Invis