mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-19 05:39:17 +02:00
Added checks for immutable flag
This commit is contained in:
parent
4bc8bf1899
commit
3cb234402d
2 changed files with 17 additions and 2 deletions
|
@ -64,6 +64,8 @@ void gc_init_heap(long heap_size);
|
|||
} \
|
||||
}
|
||||
|
||||
#define Cyc_verify_mutable(data, obj) { \
|
||||
if (immutable(obj)) Cyc_immutable_obj_error(data, obj); }
|
||||
#define Cyc_check_type(data, fnc_test, tag, obj) { \
|
||||
if ((boolean_f == fnc_test(obj))) Cyc_invalid_type_error(data, tag, obj); }
|
||||
#define Cyc_check_type2(data, fnc_test, tag, obj) { \
|
||||
|
@ -84,6 +86,7 @@ void gc_init_heap(long heap_size);
|
|||
#define Cyc_check_cond_var(d,obj) Cyc_check_type(d,Cyc_is_cond_var, cond_var_tag, obj)
|
||||
#define Cyc_check_opaque(d,obj) Cyc_check_type(d,Cyc_is_opaque, c_opaque_tag, obj)
|
||||
void Cyc_invalid_type_error(void *data, int tag, object found);
|
||||
void Cyc_immutable_obj_error(void *data, object obj);
|
||||
void Cyc_check_obj(void *data, int tag, object obj);
|
||||
void Cyc_check_bounds(void *data, const char *label, int len, int index);
|
||||
/**@}*/
|
||||
|
|
16
runtime.c
16
runtime.c
|
@ -72,6 +72,11 @@ void Cyc_invalid_type_error(void *data, int tag, object found)
|
|||
Cyc_rt_raise2(data, buf, found);
|
||||
}
|
||||
|
||||
void Cyc_immutable_obj_error(void *data, object obj)
|
||||
{
|
||||
Cyc_rt_raise2(data, "Unable to modify immutable object ", obj);
|
||||
}
|
||||
|
||||
void Cyc_check_obj(void *data, int tag, object obj)
|
||||
{
|
||||
if (!is_object_type(obj)) {
|
||||
|
@ -1869,8 +1874,10 @@ object Cyc_set_cell(void *data, object l, object val)
|
|||
|
||||
object Cyc_set_car(void *data, object l, object val)
|
||||
{
|
||||
if (Cyc_is_pair(l) == boolean_f)
|
||||
if (Cyc_is_pair(l) == boolean_f) {
|
||||
Cyc_invalid_type_error(data, pair_tag, l);
|
||||
}
|
||||
Cyc_verify_mutable(data, l);
|
||||
gc_mut_update((gc_thread_data *) data, car(l), val);
|
||||
car(l) = val;
|
||||
add_mutation(data, l, -1, val);
|
||||
|
@ -1879,8 +1886,10 @@ object Cyc_set_car(void *data, object l, object val)
|
|||
|
||||
object Cyc_set_cdr(void *data, object l, object val)
|
||||
{
|
||||
if (Cyc_is_pair(l) == boolean_f)
|
||||
if (Cyc_is_pair(l) == boolean_f) {
|
||||
Cyc_invalid_type_error(data, pair_tag, l);
|
||||
}
|
||||
Cyc_verify_mutable(data, l);
|
||||
gc_mut_update((gc_thread_data *) data, cdr(l), val);
|
||||
cdr(l) = val;
|
||||
add_mutation(data, l, -1, val);
|
||||
|
@ -1892,6 +1901,7 @@ object Cyc_vector_set(void *data, object v, object k, object obj)
|
|||
int idx;
|
||||
Cyc_check_vec(data, v);
|
||||
Cyc_check_fixnum(data, k);
|
||||
Cyc_verify_mutable(data, v);
|
||||
idx = unbox_number(k);
|
||||
|
||||
if (idx < 0 || idx >= ((vector) v)->num_elements) {
|
||||
|
@ -2352,6 +2362,7 @@ object Cyc_string_set(void *data, object str, object k, object chr)
|
|||
|
||||
Cyc_check_str(data, str);
|
||||
Cyc_check_fixnum(data, k);
|
||||
Cyc_verify_mutable(data, str);
|
||||
|
||||
if (boolean_t != Cyc_is_char(chr)) {
|
||||
Cyc_rt_raise2(data, "Expected char but received", chr);
|
||||
|
@ -3011,6 +3022,7 @@ object Cyc_bytevector_u8_set(void *data, object bv, object k, object b)
|
|||
Cyc_check_bvec(data, bv);
|
||||
Cyc_check_fixnum(data, k);
|
||||
Cyc_check_fixnum(data, b);
|
||||
Cyc_verify_mutable(data, bv);
|
||||
|
||||
buf = ((bytevector) bv)->data;
|
||||
idx = unbox_number(k);
|
||||
|
|
Loading…
Add table
Reference in a new issue