* renamed ik_alloc to ik_unsafe_alloc since it was unsafe to call it

in general (it did not collect on heap overflow).
This commit is contained in:
Abdulaziz Ghuloum 2007-11-18 09:12:00 -05:00
parent 90759047b3
commit 1afade6d43
8 changed files with 99 additions and 99 deletions

View File

@ -198,7 +198,7 @@ ikp ik_cstring_to_symbol(char*, ikpcb*);
ikp ik_asm_enter(ikpcb*, ikp code_object, ikp arg);
ikp ik_asm_reenter(ikpcb*, ikp code_object, ikp val);
ikp ik_underflow_handler(ikpcb*);
ikp ik_alloc(ikpcb* pcb, int size);
ikp ik_unsafe_alloc(ikpcb* pcb, int size);
#define IK_FASL_HEADER "#@IK01"

View File

@ -43,7 +43,7 @@ ikp ik_exec_code(ikpcb* pcb, ikp code_ptr){
exit(-1);
}
if(framesize < k->size){
cont* nk = (cont*) ik_alloc(pcb, sizeof(cont));
cont* nk = (cont*) ik_unsafe_alloc(pcb, sizeof(cont));
nk->tag = k->tag;
nk->next = k->next;
nk->top = top + framesize;

View File

@ -342,7 +342,7 @@ static ikp do_read(ikpcb* pcb, fasl_port* p){
return code+vector_tag;
}
else if(c == 'P'){
ikp pair = ik_alloc(pcb, pair_size) + pair_tag;
ikp pair = ik_unsafe_alloc(pcb, pair_size) + pair_tag;
if(put_mark_index){
p->marks[put_mark_index] = pair;
}
@ -364,7 +364,7 @@ static ikp do_read(ikpcb* pcb, fasl_port* p){
int len;
fasl_read_buf(p, &len, sizeof(int));
int size = align(len*string_char_size + disp_string_data);
ikp str = ik_alloc(pcb, size) + string_tag;
ikp str = ik_unsafe_alloc(pcb, size) + string_tag;
ref(str, off_string_length) = fix(len);
fasl_read_buf(p, str+off_string_data, len);
{
@ -386,7 +386,7 @@ static ikp do_read(ikpcb* pcb, fasl_port* p){
int len;
fasl_read_buf(p, &len, sizeof(int));
int size = align(len*string_char_size + disp_string_data);
ikp str = ik_alloc(pcb, size) + string_tag;
ikp str = ik_unsafe_alloc(pcb, size) + string_tag;
ref(str, off_string_length) = fix(len);
int i;
for(i=0; i<len; i++){
@ -405,7 +405,7 @@ static ikp do_read(ikpcb* pcb, fasl_port* p){
int len;
fasl_read_buf(p, &len, sizeof(int));
int size = align(len * wordsize + disp_vector_data);
ikp vec = ik_alloc(pcb, size) + vector_tag;
ikp vec = ik_unsafe_alloc(pcb, size) + vector_tag;
if(put_mark_index){
p->marks[put_mark_index] = vec;
}
@ -453,7 +453,7 @@ static ikp do_read(ikpcb* pcb, fasl_port* p){
if(n == 0){
fields = null_object;
} else {
fields = ik_alloc(pcb, n * align(pair_size)) + pair_tag;
fields = ik_unsafe_alloc(pcb, n * align(pair_size)) + pair_tag;
ikp ptr = fields;
for(i=0; i<n; i++){
ref(ptr, off_car) = do_read(pcb, p);
@ -466,7 +466,7 @@ static ikp do_read(ikpcb* pcb, fasl_port* p){
ikp gensym_val = ref(symb, off_symbol_record_value);
ikp rtd;
if(gensym_val == unbound_object){
rtd = ik_alloc(pcb, align(rtd_size)) + vector_tag;
rtd = ik_unsafe_alloc(pcb, align(rtd_size)) + vector_tag;
ikp base_rtd = pcb->base_rtd;
ref(rtd, off_rtd_rtd) = base_rtd;
ref(rtd, off_rtd_name) = name;
@ -485,7 +485,7 @@ static ikp do_read(ikpcb* pcb, fasl_port* p){
return rtd;
}
else if(c == 'Q'){ /* thunk */
ikp proc = ik_alloc(pcb, align(disp_closure_data)) + closure_tag;
ikp proc = ik_unsafe_alloc(pcb, align(disp_closure_data)) + closure_tag;
if(put_mark_index){
p->marks[put_mark_index] = proc;
}
@ -517,7 +517,7 @@ static ikp do_read(ikpcb* pcb, fasl_port* p){
int len;
fasl_read_buf(p, &len, sizeof(int));
int size = align(len + disp_bytevector_data + 1);
ikp x = ik_alloc(pcb, size) + bytevector_tag;
ikp x = ik_unsafe_alloc(pcb, size) + bytevector_tag;
ref(x, off_bytevector_length) = fix(len);
fasl_read_buf(p, x+off_bytevector_data, len);
x[off_bytevector_data+len] = 0;
@ -532,7 +532,7 @@ static ikp do_read(ikpcb* pcb, fasl_port* p){
fprintf(stderr, "invalid len=%d\n", len);
exit(-1);
}
ikp pair = ik_alloc(pcb, pair_size * (len+1)) + pair_tag;
ikp pair = ik_unsafe_alloc(pcb, pair_size * (len+1)) + pair_tag;
if(put_mark_index){
p->marks[put_mark_index] = pair;
}
@ -553,7 +553,7 @@ static ikp do_read(ikpcb* pcb, fasl_port* p){
fprintf(stderr, "invalid len=%d\n", len);
exit(-1);
}
ikp pair = ik_alloc(pcb, pair_size * (len+1)) + pair_tag;
ikp pair = ik_unsafe_alloc(pcb, pair_size * (len+1)) + pair_tag;
if(put_mark_index){
p->marks[put_mark_index] = pair;
}
@ -568,7 +568,7 @@ static ikp do_read(ikpcb* pcb, fasl_port* p){
return pair;
}
else if(c == 'f'){
ikp x = ik_alloc(pcb, flonum_size) + vector_tag;
ikp x = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(x, -vector_tag) = flonum_tag;
fasl_read_buf(p, x+disp_flonum_data-vector_tag, 8);
if(put_mark_index){
@ -595,7 +595,7 @@ static ikp do_read(ikpcb* pcb, fasl_port* p){
}
unsigned int tag = bignum_tag | (sign << bignum_sign_shift) |
((len >> 2) << bignum_length_shift);
ikp x = ik_alloc(pcb, align(len + disp_bignum_data)) + vector_tag;
ikp x = ik_unsafe_alloc(pcb, align(len + disp_bignum_data)) + vector_tag;
ref(x, -vector_tag) = (ikp) tag;
fasl_read_buf(p, x+off_bignum_data, len);
if(put_mark_index){

View File

@ -48,7 +48,7 @@ ikrt_flfl_expt(ikp a, ikp b, ikp z){
ikp
ikrt_bytevector_to_flonum(ikp x, ikpcb* pcb){
double v = strtod((char*)x+off_bytevector_data, NULL);
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = v;
return r;
@ -57,7 +57,7 @@ ikrt_bytevector_to_flonum(ikp x, ikpcb* pcb){
ikp
ikrt_fl_plus(ikp x, ikp y,ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = flonum_data(x) + flonum_data(y);
return r;
@ -65,7 +65,7 @@ ikrt_fl_plus(ikp x, ikp y,ikpcb* pcb){
ikp
ikrt_fl_minus(ikp x, ikp y,ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = flonum_data(x) - flonum_data(y);
return r;
@ -73,7 +73,7 @@ ikrt_fl_minus(ikp x, ikp y,ikpcb* pcb){
ikp
ikrt_fl_times(ikp x, ikp y,ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = flonum_data(x) * flonum_data(y);
return r;
@ -81,7 +81,7 @@ ikrt_fl_times(ikp x, ikp y,ikpcb* pcb){
ikp
ikrt_fl_div(ikp x, ikp y,ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = flonum_data(x) / flonum_data(y);
return r;
@ -89,7 +89,7 @@ ikrt_fl_div(ikp x, ikp y,ikpcb* pcb){
ikp
ikrt_fl_invert(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = 1.0 / flonum_data(x);
return r;
@ -97,7 +97,7 @@ ikrt_fl_invert(ikp x, ikpcb* pcb){
ikp
ikrt_fl_sin(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = sin(flonum_data(x));
return r;
@ -105,7 +105,7 @@ ikrt_fl_sin(ikp x, ikpcb* pcb){
ikp
ikrt_fl_cos(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = cos(flonum_data(x));
return r;
@ -113,7 +113,7 @@ ikrt_fl_cos(ikp x, ikpcb* pcb){
ikp
ikrt_fl_tan(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = tan(flonum_data(x));
return r;
@ -121,7 +121,7 @@ ikrt_fl_tan(ikp x, ikpcb* pcb){
ikp
ikrt_fl_asin(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = asin(flonum_data(x));
return r;
@ -129,7 +129,7 @@ ikrt_fl_asin(ikp x, ikpcb* pcb){
ikp
ikrt_fl_acos(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = acos(flonum_data(x));
return r;
@ -137,7 +137,7 @@ ikrt_fl_acos(ikp x, ikpcb* pcb){
ikp
ikrt_fl_atan(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = atan(flonum_data(x));
return r;
@ -148,7 +148,7 @@ ikrt_fl_atan(ikp x, ikpcb* pcb){
ikp
ikrt_fl_sqrt(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = sqrt(flonum_data(x));
return r;
@ -156,7 +156,7 @@ ikrt_fl_sqrt(ikp x, ikpcb* pcb){
ikp
ikrt_fl_log(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = log(flonum_data(x));
return r;
@ -165,7 +165,7 @@ ikrt_fl_log(ikp x, ikpcb* pcb){
ikp
ikrt_fx_sin(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = sin(unfix(x));
return r;
@ -173,7 +173,7 @@ ikrt_fx_sin(ikp x, ikpcb* pcb){
ikp
ikrt_fx_cos(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = cos(unfix(x));
return r;
@ -181,7 +181,7 @@ ikrt_fx_cos(ikp x, ikpcb* pcb){
ikp
ikrt_fx_tan(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = tan(unfix(x));
return r;
@ -189,7 +189,7 @@ ikrt_fx_tan(ikp x, ikpcb* pcb){
ikp
ikrt_fx_asin(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = asin(unfix(x));
return r;
@ -197,7 +197,7 @@ ikrt_fx_asin(ikp x, ikpcb* pcb){
ikp
ikrt_fx_acos(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = acos(unfix(x));
return r;
@ -205,7 +205,7 @@ ikrt_fx_acos(ikp x, ikpcb* pcb){
ikp
ikrt_fx_atan(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = atan(unfix(x));
return r;
@ -213,7 +213,7 @@ ikrt_fx_atan(ikp x, ikpcb* pcb){
ikp
ikrt_fx_sqrt(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = sqrt(unfix(x));
return r;
@ -222,7 +222,7 @@ ikrt_fx_sqrt(ikp x, ikpcb* pcb){
ikp
ikrt_fx_log(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = log(unfix(x));
return r;
@ -231,7 +231,7 @@ ikrt_fx_log(ikp x, ikpcb* pcb){
ikp
ikrt_fixnum_to_flonum(ikp x, ikpcb* pcb){
ikp r = ik_alloc(pcb, flonum_size) + vector_tag;
ikp r = ik_unsafe_alloc(pcb, flonum_size) + vector_tag;
ref(r, -vector_tag) = (ikp)flonum_tag;
flonum_data(r) = unfix(x);
return r;

View File

@ -154,7 +154,7 @@ int main(int argc, char** argv){
while(i > 0){
char* s = argv[i];
int n = strlen(s);
ikp str = ik_alloc(pcb, align(n*string_char_size+disp_string_data+1))
ikp str = ik_unsafe_alloc(pcb, align(n*string_char_size+disp_string_data+1))
+ string_tag;
ref(str, off_string_length) = fix(n);
{
@ -163,7 +163,7 @@ int main(int argc, char** argv){
string_set(str, i, integer_to_char(s[i]));
}
}
ikp p = ik_alloc(pcb, pair_size);
ikp p = ik_unsafe_alloc(pcb, pair_size);
ref(p, disp_car) = str;
ref(p, disp_cdr) = arg_list;
arg_list = p+pair_tag;

View File

@ -128,7 +128,7 @@ ikrt_fxfxplus(ikp x, ikp y, ikpcb* pcb){
return q;
}
else {
ikp bn = ik_alloc(pcb, align(disp_bignum_data + wordsize));
ikp bn = ik_unsafe_alloc(pcb, align(disp_bignum_data + wordsize));
if(r > 0){
ref(bn, 0) = (ikp)(bignum_tag | (1 << bignum_length_shift));
ref(bn, disp_bignum_data) = (ikp)r;
@ -153,7 +153,7 @@ ikrt_fxbnplus(ikp x, ikp y, ikpcb* pcb){
if(intx > 0){
if((bignum_sign_mask & (int)fst) == 0){
/* positive fx + positive bn = even bigger positive */
ikp r = ik_alloc(pcb, align(disp_bignum_data+(limb_count+1)*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+(limb_count+1)*wordsize));
int carry = mpn_add_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(y - vector_tag + disp_bignum_data),
limb_count,
@ -176,7 +176,7 @@ ikrt_fxbnplus(ikp x, ikp y, ikpcb* pcb){
else {
//fprintf(stderr, "this case 0x%08x\n", intx);
/* positive fx + negative bn = smaller negative bn */
ikp r = ik_alloc(pcb, align(disp_bignum_data+limb_count*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+limb_count*wordsize));
int borrow = mpn_sub_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(y - vector_tag + disp_bignum_data),
limb_count,
@ -209,7 +209,7 @@ ikrt_fxbnplus(ikp x, ikp y, ikpcb* pcb){
else {
if((bignum_sign_mask & (int)fst) == 0){
/* negative fx + positive bn = smaller positive */
ikp r = ik_alloc(pcb, align(disp_bignum_data+limb_count*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+limb_count*wordsize));
int borrow = mpn_sub_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(y - vector_tag + disp_bignum_data),
limb_count,
@ -239,7 +239,7 @@ ikrt_fxbnplus(ikp x, ikp y, ikpcb* pcb){
return verify_bignum(r+vector_tag, "fxbn+4");
} else {
/* negative fx + negative bn = larger negative */
ikp r = ik_alloc(pcb, align(disp_bignum_data+(limb_count+1)*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+(limb_count+1)*wordsize));
int carry = mpn_add_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(y - vector_tag + disp_bignum_data),
limb_count,
@ -281,7 +281,7 @@ ikrt_bnbnplus(ikp x, ikp y, ikpcb* pcb){
} else {
n1 = ylimbs; n2 = xlimbs; s1 = y; s2 = x;
}
ikp res = ik_alloc(pcb, align(disp_bignum_data + (n1+1)*wordsize));
ikp res = ik_unsafe_alloc(pcb, align(disp_bignum_data + (n1+1)*wordsize));
mp_limb_t carry = mpn_add((mp_limb_t*) (res+disp_bignum_data),
(mp_limb_t*) (s1-vector_tag+disp_bignum_data),
n1,
@ -329,7 +329,7 @@ ikrt_bnbnplus(ikp x, ikp y, ikpcb* pcb){
}
}
/* |s1| > |s2| */
ikp res = ik_alloc(pcb, align(disp_bignum_data + n1 * wordsize));
ikp res = ik_unsafe_alloc(pcb, align(disp_bignum_data + n1 * wordsize));
int burrow = mpn_sub((mp_limb_t*) (res + disp_bignum_data),
(mp_limb_t*) (s1 - vector_tag + disp_bignum_data),
n1,
@ -388,7 +388,7 @@ ikrt_fxfxminus(ikp x, ikp y, ikpcb* pcb){
if(((unsigned int)r) <= most_positive_fixnum){
return fix(r);
} else {
ikp bn = ik_alloc(pcb, align(disp_bignum_data + wordsize));
ikp bn = ik_unsafe_alloc(pcb, align(disp_bignum_data + wordsize));
ref(bn, 0) = (ikp) (bignum_tag | (1 << bignum_length_shift));
ref(bn, disp_bignum_data) = (ikp)r;
return verify_bignum(bn+vector_tag,"fxfx-1");
@ -398,7 +398,7 @@ ikrt_fxfxminus(ikp x, ikp y, ikpcb* pcb){
if(unfix(fxr) == r){
return fxr;
} else {
ikp bn = ik_alloc(pcb, align(disp_bignum_data + wordsize));
ikp bn = ik_unsafe_alloc(pcb, align(disp_bignum_data + wordsize));
ref(bn, 0) = (ikp)
(bignum_tag |
(1 << bignum_sign_shift) |
@ -423,7 +423,7 @@ ikrt_bnnegate(ikp x, ikpcb* pcb){
}
}
}
ikp bn = ik_alloc(pcb, align(disp_bignum_data + limb_count * wordsize));
ikp bn = ik_unsafe_alloc(pcb, align(disp_bignum_data + limb_count * wordsize));
memcpy(bn+disp_bignum_data,
x-vector_tag+disp_bignum_data,
limb_count*wordsize);
@ -443,7 +443,7 @@ ikrt_fxbnminus(ikp x, ikp y, ikpcb* pcb){
if(intx > 0){
if(bignum_sign_mask & (int)fst){
/* positive fx - negative bn = positive bn */
ikp r = ik_alloc(pcb, align(disp_bignum_data+(limb_count+1)*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+(limb_count+1)*wordsize));
int carry = mpn_add_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(y - vector_tag + disp_bignum_data),
limb_count,
@ -465,7 +465,7 @@ ikrt_fxbnminus(ikp x, ikp y, ikpcb* pcb){
}
else {
/* positive fx - positive bn = smaller negative bn/fx */
ikp r = ik_alloc(pcb, align(disp_bignum_data+limb_count*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+limb_count*wordsize));
int borrow = mpn_sub_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(y - vector_tag + disp_bignum_data),
limb_count,
@ -498,7 +498,7 @@ ikrt_fxbnminus(ikp x, ikp y, ikpcb* pcb){
else {
if(bignum_sign_mask & (int)fst){
/* negative fx - negative bn = smaller positive */
ikp r = ik_alloc(pcb, align(disp_bignum_data+limb_count*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+limb_count*wordsize));
int borrow = mpn_sub_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(y - vector_tag + disp_bignum_data),
limb_count,
@ -528,7 +528,7 @@ ikrt_fxbnminus(ikp x, ikp y, ikpcb* pcb){
return verify_bignum(r+vector_tag,"fxbn-");
} else {
/* negative fx - positive bn = larger negative */
ikp r = ik_alloc(pcb, align(disp_bignum_data+(limb_count+1)*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+(limb_count+1)*wordsize));
int carry = mpn_add_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(y - vector_tag + disp_bignum_data),
limb_count,
@ -560,7 +560,7 @@ ikrt_bnfxminus(ikp x, ikp y, ikpcb* pcb){
if(inty < 0){
if((bignum_sign_mask & (int)fst) == 0){
/* - negative fx + positive bn = positive bn */
ikp r = ik_alloc(pcb, align(disp_bignum_data+(limb_count+1)*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+(limb_count+1)*wordsize));
int carry = mpn_add_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(x - vector_tag + disp_bignum_data),
limb_count,
@ -582,7 +582,7 @@ ikrt_bnfxminus(ikp x, ikp y, ikpcb* pcb){
}
else {
/* - negative fx + negative bn = smaller negative bn/fx */
ikp r = ik_alloc(pcb, align(disp_bignum_data+limb_count*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+limb_count*wordsize));
int borrow = mpn_sub_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(x - vector_tag + disp_bignum_data),
limb_count,
@ -615,7 +615,7 @@ ikrt_bnfxminus(ikp x, ikp y, ikpcb* pcb){
else {
if((bignum_sign_mask & (int)fst) == 0){
/* - positive fx + positive bn = smaller positive */
ikp r = ik_alloc(pcb, align(disp_bignum_data+limb_count*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+limb_count*wordsize));
int borrow = mpn_sub_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(x - vector_tag + disp_bignum_data),
limb_count,
@ -645,7 +645,7 @@ ikrt_bnfxminus(ikp x, ikp y, ikpcb* pcb){
return verify_bignum(r+vector_tag, "bnfx-");
} else {
/* - positive fx + negative bn = larger negative */
ikp r = ik_alloc(pcb, align(disp_bignum_data+(limb_count+1)*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+(limb_count+1)*wordsize));
int carry = mpn_add_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(x - vector_tag + disp_bignum_data),
limb_count,
@ -687,7 +687,7 @@ ikrt_bnbnminus(ikp x, ikp y, ikpcb* pcb){
} else {
n1 = ylimbs; n2 = xlimbs; s1 = y; s2 = x;
}
ikp res = ik_alloc(pcb, align(disp_bignum_data + (n1+1)*wordsize));
ikp res = ik_unsafe_alloc(pcb, align(disp_bignum_data + (n1+1)*wordsize));
mp_limb_t carry = mpn_add((mp_limb_t*) (res+disp_bignum_data),
(mp_limb_t*) (s1-vector_tag+disp_bignum_data),
n1,
@ -737,7 +737,7 @@ ikrt_bnbnminus(ikp x, ikp y, ikpcb* pcb){
}
}
/* |s1| > |s2| */
ikp res = ik_alloc(pcb, align(disp_bignum_data + n1 * wordsize));
ikp res = ik_unsafe_alloc(pcb, align(disp_bignum_data + n1 * wordsize));
int burrow = mpn_sub((mp_limb_t*) (res + disp_bignum_data),
(mp_limb_t*) (s1 - vector_tag + disp_bignum_data),
n1,
@ -812,7 +812,7 @@ ikrt_fxfxmult(ikp x, ikp y, ikpcb* pcb){
return fix((int)lo);
}
}
ikp r = ik_alloc(pcb, disp_bignum_data + wordsize);
ikp r = ik_unsafe_alloc(pcb, disp_bignum_data + wordsize);
ref(r, 0) = (ikp)
(bignum_tag |
(sign << bignum_sign_shift) |
@ -820,7 +820,7 @@ ikrt_fxfxmult(ikp x, ikp y, ikpcb* pcb){
ref(r, disp_bignum_data) = (ikp)lo;
return BN(r+vector_tag);
} else {
ikp r = ik_alloc(pcb, align(disp_bignum_data + 2*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + 2*wordsize));
ref(r, 0) = (ikp)
(bignum_tag |
(sign << bignum_sign_shift) |
@ -861,7 +861,7 @@ ikrt_fxbnmult(ikp x, ikp y, ikpcb* pcb){
mp_limb_t s2 = (n2>0) ? n2 : (- n2);
ikp fst = ref(y, -vector_tag);
int limb_count = ((unsigned int) fst) >> bignum_length_shift;
ikp r = ik_alloc(pcb, align(disp_bignum_data + (limb_count+1)*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + (limb_count+1)*wordsize));
mp_limb_t hi = mpn_mul_1((mp_limb_t*)(r+disp_bignum_data),
(mp_limb_t*)(y-vector_tag+disp_bignum_data),
limb_count,
@ -881,7 +881,7 @@ ikrt_bnbnmult(ikp x, ikp y, ikpcb* pcb){
int n1 = ((unsigned int)f1) >> bignum_length_shift;
int n2 = ((unsigned int)f2) >> bignum_length_shift;
int nr = n1 + n2;
ikp bn = ik_alloc(pcb, align(disp_bignum_data + nr*wordsize));
ikp bn = ik_unsafe_alloc(pcb, align(disp_bignum_data + nr*wordsize));
mp_limb_t r;
if(n1 >= n2){
r = mpn_mul((mp_limb_t*)(bn+disp_bignum_data),
@ -992,7 +992,7 @@ ikrt_fxbnlogand(ikp x, ikp y, ikpcb* pcb){
if((len == 1) && (nn <= most_negative_fixnum)){
return fix(-nn);
}
ikp r = ik_alloc(pcb, align(disp_bignum_data + len * wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + len * wordsize));
ref(r, 0) = fst;
ref(r, disp_bignum_data) = (ikp) nn;
int i;
@ -1004,7 +1004,7 @@ ikrt_fxbnlogand(ikp x, ikp y, ikpcb* pcb){
} else {
/* y is positive */
int len = (((unsigned int) fst) >> bignum_length_shift);
ikp r = ik_alloc(pcb, align(disp_bignum_data + len * wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + len * wordsize));
ref(r, 0) = fst;
ref(r, disp_bignum_data) = (ikp)
(((int)ref(y, disp_bignum_data - vector_tag)) & n1);
@ -1093,7 +1093,7 @@ ikrt_bnlognot(ikp x, ikpcb* pcb){
unsigned int* s1 = ((unsigned int*)(x+disp_bignum_data-vector_tag));
if(bignum_sign_mask & (unsigned int) fst){
/* negative */
ikp r = ik_alloc(pcb, align(disp_bignum_data + n*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + n*wordsize));
unsigned int* rd = (unsigned int*)(r+disp_bignum_data);
int i;
for(i=0; (i<n) && (s1[i] == 0); i++) {
@ -1109,14 +1109,14 @@ ikrt_bnlognot(ikp x, ikpcb* pcb){
int i;
for(i=0; (i<n) && (s1[i] == -1); i++) {/*nothing*/}
if(i==n){
ikp r = ik_alloc(pcb, align(disp_bignum_data + (n+1)*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + (n+1)*wordsize));
bzero(r+disp_bignum_data, n*wordsize);
((unsigned int*)(r+disp_bignum_data))[n] = 1;
ref(r, 0) = (ikp)
(bignum_tag | (1<<bignum_sign_shift) | ((n+1) << bignum_length_shift));
return r+vector_tag;
} else {
ikp r = ik_alloc(pcb, align(disp_bignum_data + n*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + n*wordsize));
unsigned int* rd = (unsigned int*)(r+disp_bignum_data);
int j;
for(j=0; j<i; j++){ rd[j] = 0; }
@ -1141,7 +1141,7 @@ ikrt_bnbnlogand(ikp x, ikp y, ikpcb* pcb){
unsigned int* s1 = ((unsigned int*)(x+disp_bignum_data-vector_tag));
unsigned int* s2 = ((unsigned int*)(y+disp_bignum_data-vector_tag));
if(n1 >= n2){
ikp r = ik_alloc(pcb, align(disp_bignum_data + n1*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + n1*wordsize));
unsigned int* s = ((unsigned int*)(r+disp_bignum_data));
bits_compliment(s1, s, n1);
bits_compliment_logand(s2, s, s, n2);
@ -1159,7 +1159,7 @@ ikrt_bnbnlogand(ikp x, ikp y, ikpcb* pcb){
/* the result is at most n1 words long */
unsigned int* s1 = ((unsigned int*)(x+disp_bignum_data-vector_tag));
unsigned int* s2 = ((unsigned int*)(y+disp_bignum_data-vector_tag));
ikp r = ik_alloc(pcb, align(disp_bignum_data + n1*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + n1*wordsize));
unsigned int* s = ((unsigned int*)(r+disp_bignum_data));
bits_compliment_logand(s2, s1, s, n1);
return normalize_bignum(n1, 0, r);
@ -1177,7 +1177,7 @@ ikrt_bnbnlogand(ikp x, ikp y, ikpcb* pcb){
if((i == 0) && (last < most_positive_fixnum)){
return fix(last);
}
ikp r = ik_alloc(pcb, align(disp_bignum_data+(i+1)*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data+(i+1)*wordsize));
ref(r, 0) = (ikp) (bignum_tag | ((i+1)<<bignum_length_shift));
ref(r, disp_bignum_data + i*wordsize) = (ikp)last;
int j;
@ -1237,7 +1237,7 @@ ikrt_bignum_shift_right(ikp x, ikp y, ikpcb* pcb){
return fix(-1);
}
if(bit_shift == 0){
ikp r = ik_alloc(pcb, align(disp_bignum_data + new_limb_count * wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + new_limb_count * wordsize));
bits_compliment_with_carry(
(unsigned int*)(x+off_bignum_data+whole_limb_shift*wordsize),
(unsigned int*)(r+disp_bignum_data),
@ -1249,7 +1249,7 @@ ikrt_bignum_shift_right(ikp x, ikp y, ikpcb* pcb){
new_limb_count);
return normalize_bignum(new_limb_count, 1 << bignum_sign_shift, r);
} else {
ikp r = ik_alloc(pcb, align(disp_bignum_data + new_limb_count * wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + new_limb_count * wordsize));
bits_compliment_with_carry(
(unsigned int*)(x+off_bignum_data+whole_limb_shift*wordsize),
(unsigned int*)(r+disp_bignum_data),
@ -1275,13 +1275,13 @@ ikrt_bignum_shift_right(ikp x, ikp y, ikpcb* pcb){
return 0;
}
if(bit_shift == 0){
ikp r = ik_alloc(pcb, align(disp_bignum_data + new_limb_count * wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + new_limb_count * wordsize));
memcpy(r+disp_bignum_data,
x+off_bignum_data+whole_limb_shift*wordsize,
new_limb_count * wordsize);
return normalize_bignum(new_limb_count, 0, r);
} else {
ikp r = ik_alloc(pcb, align(disp_bignum_data + new_limb_count * wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + new_limb_count * wordsize));
copy_bits_shifting_right(
(unsigned int*)(x+off_bignum_data+whole_limb_shift*wordsize),
(unsigned int*)(r+disp_bignum_data),
@ -1299,7 +1299,7 @@ ikrt_fixnum_shift_left(ikp x, ikp y, ikpcb* pcb){
int n = unfix(x);
int limb_count = (m >> 5) + 2; /* FIXME: 5 are the bits in 32-bit num */
int bit_shift = m & 31;
ikp r = ik_alloc(pcb, align(disp_bignum_data + limb_count * wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + limb_count * wordsize));
unsigned int* s = (unsigned int*)(r+disp_bignum_data);
bzero(s, limb_count * wordsize);
if(n >= 0){
@ -1326,14 +1326,14 @@ ikrt_bignum_shift_left(ikp x, ikp y, ikpcb* pcb){
int bit_shift = m & 31;
if(bit_shift == 0){
int limb_count = n + whole_limb_shift;
ikp r = ik_alloc(pcb, align(disp_bignum_data + limb_count * wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + limb_count * wordsize));
unsigned int* s = (unsigned int*)(r+disp_bignum_data);
bzero(s, whole_limb_shift*wordsize);
memcpy(s+whole_limb_shift, x+off_bignum_data, n*wordsize);
return normalize_bignum(limb_count, (unsigned int)fst & bignum_sign_mask, r);
} else {
int limb_count = n + whole_limb_shift + 1;
ikp r = ik_alloc(pcb, align(disp_bignum_data + limb_count * wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + limb_count * wordsize));
unsigned int* s = (unsigned int*)(r+disp_bignum_data);
bzero(s, whole_limb_shift*wordsize);
copy_bits_shifting_left(
@ -1374,15 +1374,15 @@ ikrt_bnbndivrem(ikp x, ikp y, ikpcb* pcb){
mp_size_t yn = ((unsigned int) yfst) >> bignum_length_shift;
if(xn < yn){
/* quotient is zero, remainder is x */
ikp rv = ik_alloc(pcb, pair_size);
ikp rv = ik_unsafe_alloc(pcb, pair_size);
ref(rv, disp_car) = 0;
ref(rv, disp_cdr) = x;
return rv+pair_tag;
}
mp_size_t qn = xn - yn + 1;
mp_size_t rn = yn;
ikp q = ik_alloc(pcb, align(disp_bignum_data + qn*wordsize));
ikp r = ik_alloc(pcb, align(disp_bignum_data + rn*wordsize));
ikp q = ik_unsafe_alloc(pcb, align(disp_bignum_data + qn*wordsize));
ikp r = ik_unsafe_alloc(pcb, align(disp_bignum_data + rn*wordsize));
mpn_tdiv_qr (
(mp_limb_t*)(q+disp_bignum_data),
(mp_limb_t*)(r+disp_bignum_data),
@ -1409,7 +1409,7 @@ ikrt_bnbndivrem(ikp x, ikp y, ikpcb* pcb){
int sign = (((unsigned int)xfst) & bignum_sign_mask);
q = normalize_bignum(qn, sign, q);
}
ikp rv = ik_alloc(pcb, pair_size);
ikp rv = ik_unsafe_alloc(pcb, pair_size);
ref(rv, disp_car) = q;
ref(rv, disp_cdr) = r;
return rv+pair_tag;
@ -1440,7 +1440,7 @@ ikrt_bnfxdivrem(ikp x, ikp y, ikpcb* pcb){
mp_limb_t* s2p = (mp_limb_t*)(x+off_bignum_data);
ikp fst = ref(x, -vector_tag);
mp_size_t s2n = ((unsigned int) fst) >> bignum_length_shift;
ikp quot = ik_alloc(pcb,
ikp quot = ik_unsafe_alloc(pcb,
align(s2n*wordsize + disp_bignum_data));
mp_limb_t rv = mpn_divrem_1(
(mp_limb_t*)(quot+disp_bignum_data),
@ -1471,7 +1471,7 @@ ikrt_bnfxdivrem(ikp x, ikp y, ikpcb* pcb){
} else {
rem = fix(rv);
}
ikp p = ik_alloc(pcb, pair_size);
ikp p = ik_unsafe_alloc(pcb, pair_size);
ref(p, disp_car) = quot;
ref(p, disp_cdr) = rem;
return p+pair_tag;
@ -1542,7 +1542,7 @@ ikrt_bignum_to_bytevector(ikp x, ikpcb* pcb){
string_start++;
bytes--;
}
ikp bv = ik_alloc(pcb, align(bytes + disp_bytevector_data + (sign_bit?1:0)));
ikp bv = ik_unsafe_alloc(pcb, align(bytes + disp_bytevector_data + (sign_bit?1:0)));
ref(bv, 0) = fix(bytes + (sign_bit?1:0));
ikp dest = bv + disp_bytevector_data;
if(sign_bit){

View File

@ -344,7 +344,7 @@ ikpcb* ik_make_pcb(){
}
/* initialize base rtd */
{
ikp r = ik_alloc(pcb, align(rtd_size)) + rtd_tag;
ikp r = ik_unsafe_alloc(pcb, align(rtd_size)) + rtd_tag;
ref(r, off_rtd_rtd) = r;
ref(r, off_rtd_length) = (ikp) (rtd_size-wordsize);
ref(r, off_rtd_name) = 0;
@ -396,7 +396,7 @@ void ik_delete_pcb(ikpcb* pcb){
ikp
ik_alloc(ikpcb* pcb, int size){
ik_unsafe_alloc(ikpcb* pcb, int size){
assert(size == align(size));
ikp ap = pcb->allocation_pointer;
ikp ep = pcb->heap_base + pcb->heap_size;
@ -460,7 +460,7 @@ void ik_stack_overflow(ikpcb* pcb){
fprintf(stderr, "underflow_handler = 0x%08x\n", (int)underflow_handler);
#endif
/* capture continuation and set it as next_k */
ikp k = ik_alloc(pcb, align(continuation_size)) + vector_tag;
ikp k = ik_unsafe_alloc(pcb, align(continuation_size)) + vector_tag;
ref(k, -vector_tag) = continuation_tag;
ref(k, off_continuation_top) = pcb->frame_pointer;
ref(k, off_continuation_size) =
@ -946,7 +946,7 @@ ikrt_register_guardian_pair(ikp p0, ikpcb* pcb){
ikp
ikrt_register_guardian(ikp tc, ikp obj, ikpcb* pcb){
ikp p0 = ik_alloc(pcb, pair_size) + pair_tag;
ikp p0 = ik_unsafe_alloc(pcb, pair_size) + pair_tag;
ref(p0, off_car) = tc;
ref(p0, off_cdr) = obj;
return ikrt_register_guardian_pair(p0, pcb);
@ -1013,13 +1013,13 @@ ikrt_getenv(ikp str, ikpcb* pcb){
char* v = getenv((char*)str + off_bytevector_data);
if(v){
int n = strlen(v);
ikp s = ik_alloc(pcb, align(n+disp_string_data+1)) + string_tag;
ikp s = ik_unsafe_alloc(pcb, align(n+disp_string_data+1)) + string_tag;
ref(s, -string_tag) = fix(n);
memcpy(s+off_string_data, v, n+1);
return s;
}
else {
ikp s = ik_alloc(pcb, align(disp_string_data+1)) + string_tag;
ikp s = ik_unsafe_alloc(pcb, align(disp_string_data+1)) + string_tag;
ref(s, -string_tag) = fix(0);
ref(s, off_string_data) = 0;
return s;
@ -1050,10 +1050,10 @@ ikrt_environ(ikpcb* pcb){
ikp ac = null_object;
for(i=0; (e=es[i]); i++){
int n = strlen(e);
ikp s = ik_alloc(pcb, align(n+disp_string_data+1)) + string_tag;
ikp s = ik_unsafe_alloc(pcb, align(n+disp_string_data+1)) + string_tag;
ref(s, -string_tag) = fix(n);
memcpy(s+off_string_data, e, n+1);
ikp p = ik_alloc(pcb, pair_size) + pair_tag;
ikp p = ik_unsafe_alloc(pcb, pair_size) + pair_tag;
ref(p, off_cdr) = ac;
ref(p, off_car) = s;
ac = p;

View File

@ -66,7 +66,7 @@ static int strings_eqp(ikp str1, ikp str2){
#if 0
static ikp
ik_make_symbol(ikp str, ikp ustr, ikpcb* pcb){
ikp sym = ik_alloc(pcb, symbol_size) + symbol_tag;
ikp sym = ik_unsafe_alloc(pcb, symbol_size) + symbol_tag;
ref(sym, off_symbol_string) = str;
ref(sym, off_symbol_ustring) = ustr;
ref(sym, off_symbol_value) = unbound_object;
@ -81,7 +81,7 @@ ik_make_symbol(ikp str, ikp ustr, ikpcb* pcb){
static ikp
ik_make_symbol(ikp str, ikp ustr, ikpcb* pcb){
ikp sym = ik_alloc(pcb, symbol_record_size) + record_tag;
ikp sym = ik_unsafe_alloc(pcb, symbol_record_size) + record_tag;
ref(sym, -record_tag) = symbol_record_tag;
ref(sym, off_symbol_record_string) = str;
ref(sym, off_symbol_record_ustring) = ustr;
@ -108,7 +108,7 @@ intern_string(ikp str, ikp st, ikpcb* pcb){
b = ref(b, off_cdr);
}
ikp sym = ik_make_symbol(str, false_object, pcb);
b = ik_alloc(pcb, pair_size) + pair_tag;
b = ik_unsafe_alloc(pcb, pair_size) + pair_tag;
ref(b, off_car) = sym;
ref(b, off_cdr) = bckt;
ref(st, off_vector_data + idx*wordsize) = b;
@ -131,7 +131,7 @@ intern_unique_string(ikp str, ikp ustr, ikp st, ikpcb* pcb){
b = ref(b, off_cdr);
}
ikp sym = ik_make_symbol(str, ustr, pcb);
b = ik_alloc(pcb, pair_size) + pair_tag;
b = ik_unsafe_alloc(pcb, pair_size) + pair_tag;
ref(b, off_car) = sym;
ref(b, off_cdr) = bckt;
ref(st, off_vector_data + idx*wordsize) = b;
@ -159,7 +159,7 @@ ikrt_intern_gensym(ikp sym, ikpcb* pcb){
}
b = ref(b, off_cdr);
}
b = ik_alloc(pcb, pair_size) + pair_tag;
b = ik_unsafe_alloc(pcb, pair_size) + pair_tag;
ref(b, off_car) = sym;
ref(b, off_cdr) = bckt;
ref(st, off_vector_data + idx*wordsize) = b;
@ -201,7 +201,7 @@ ikp
ik_cstring_to_symbol(char* str, ikpcb* pcb){
int n = strlen(str);
int size = n + disp_string_data + 1;
ikp s = ik_alloc(pcb, align(size)) + string_tag;
ikp s = ik_unsafe_alloc(pcb, align(size)) + string_tag;
ref(s, off_string_length) = fix(n);
memcpy(s+off_string_data, str, n+1);
ikp sym = ikrt_string_to_symbol(s, pcb);