From dc1939cde6bf5c9e33fcc25bf7c8812ca41a991f Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Tue, 27 Aug 2024 12:13:21 +0200 Subject: [PATCH] objc: prevent defmacro! from mutating its argument --- impls/objc/step8_macros.m | 2 +- impls/objc/step9_try.m | 2 +- impls/objc/stepA_mal.m | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/impls/objc/step8_macros.m b/impls/objc/step8_macros.m index 94a50d9bef..324ed059a8 100644 --- a/impls/objc/step8_macros.m +++ b/impls/objc/step8_macros.m @@ -104,7 +104,7 @@ BOOL starts_with(NSObject *ast, NSString *sym) { } else if ([(NSString *)a0 isEqualTo:@"quasiquote"]) { ast = quasiquote(alst[1]); // TCO } else if ([a0sym isEqualTo:@"defmacro!"]) { - MalFunc * f = (MalFunc *)EVAL(alst[2], env); + MalFunc * f = [(MalFunc *)EVAL(alst[2], env) copy]; f.isMacro = true; return [env set:alst[1] val:f]; } else if ([a0sym isEqualTo:@"do"]) { diff --git a/impls/objc/step9_try.m b/impls/objc/step9_try.m index 76dff95d79..c2f5c9be9a 100644 --- a/impls/objc/step9_try.m +++ b/impls/objc/step9_try.m @@ -104,7 +104,7 @@ BOOL starts_with(NSObject *ast, NSString *sym) { } else if ([(NSString *)a0 isEqualTo:@"quasiquote"]) { ast = quasiquote(alst[1]); // TCO } else if ([a0sym isEqualTo:@"defmacro!"]) { - MalFunc * f = (MalFunc *)EVAL(alst[2], env); + MalFunc * f = [(MalFunc *)EVAL(alst[2], env) copy]; f.isMacro = true; return [env set:alst[1] val:f]; } else if ([a0sym isEqualTo:@"try*"]) { diff --git a/impls/objc/stepA_mal.m b/impls/objc/stepA_mal.m index a31271b8af..bf463b15e5 100644 --- a/impls/objc/stepA_mal.m +++ b/impls/objc/stepA_mal.m @@ -104,7 +104,7 @@ BOOL starts_with(NSObject *ast, NSString *sym) { } else if ([(NSString *)a0 isEqualTo:@"quasiquote"]) { ast = quasiquote(alst[1]); // TCO } else if ([a0sym isEqualTo:@"defmacro!"]) { - MalFunc * f = (MalFunc *)EVAL(alst[2], env); + MalFunc * f = [(MalFunc *)EVAL(alst[2], env) copy]; f.isMacro = true; return [env set:alst[1] val:f]; } else if ([a0sym isEqualTo:@"try*"]) {