Issue #484 - Improve handling of exporting prims

To fixes:
- Prevent segfault setting a global variable to itself
- Do not throw an error when exporting a primitive that is not defined in the current module, as built-ins are always available in any context.
This commit is contained in:
Justin Ethier 2021-12-13 19:05:18 -08:00
parent 6149ec02c7
commit 2e84aaac9c
2 changed files with 11 additions and 4 deletions

View file

@ -347,7 +347,8 @@
(cond
((eq? e 'call/cc) #f) ;; Special case
((and (not module-global?)
(not imported-var?))
(not imported-var?)
(not (prim? e)))
(error "Identifier is exported but not defined" e))
(else
;; Pass throughs are not defined in this module,

View file

@ -351,7 +351,9 @@ object cell_get(object cell)
object Cyc_global_set(void *thd, object identifier, object * glo, object value)
{
gc_mut_update((gc_thread_data *) thd, *glo, value);
if (*glo != value) {
*(glo) = value;
}
((gc_thread_data *) thd)->globals_changed = 1;
return value;
}
@ -362,7 +364,9 @@ static void Cyc_global_set_cps_gc_return(void *data, object cont, int argc, obje
object val = args[1];
object next = args[2];
object *glo = (object *)glo_obj;
if (*glo != val) {
*(glo) = val;
}
closcall1(data, (closure)next, val);
}
@ -386,7 +390,9 @@ object Cyc_global_set_cps(void *thd, object cont, object identifier, object * gl
object buf[3]; buf[0] = (object)glo; buf[1] = value; buf[2] = cont;
GC(data, &clo, buf, 3);
}
if (*glo != value) {
*(glo) = value; // Already have heap objs, do assignment now
}
return value;
}