bug fixed

a gc bug which causes  fatal error.
add member value collect to make sure that nasal_val is not collected repeatedly.
use builtin_alloc in builtin function to avoid incorrect collection of value in use(gc_alloc).
change free_list to free_list[vm_type_size] to avoid too many calls of new/delete(but seems useless?)
but the most important thing is fixing this bug.
This commit is contained in:
Valk Richard Li
2021-05-31 19:10:59 +08:00
parent aae9395d66
commit a68bf85f04
11 changed files with 234 additions and 195 deletions
+11 -11
View File
@@ -133,7 +133,7 @@ bool nasal_vm::condition(nasal_val* val_addr)
else if(type==vm_str)
{
std::string& str=*val_addr->ptr.str;
double number=trans_string_to_number(str);
double number=str2num(str);
if(std::isnan(number))
return str.length();
return number;
@@ -212,7 +212,7 @@ void nasal_vm::opr_newf()
nasal_val* val=gc.gc_alloc(vm_func);
val->ptr.func->entry=exec_code[pc].num;
if(!gc.local.empty())
val->ptr.func->closure=gc.local.back();
val->ptr.func->closure=gc.local.back();// local contains 'me'
else
val->ptr.func->closure.push_back(gc.nil_addr);// me
*(++stack_top)=val;
@@ -263,7 +263,7 @@ void nasal_vm::opr_unot()
new_val=val->ptr.num?gc.zero_addr:gc.one_addr;
else if(type==vm_str)
{
double number=trans_string_to_number(*val->ptr.str);
double number=str2num(*val->ptr.str);
if(std::isnan(number))
new_val=val->ptr.str->length()?gc.zero_addr:gc.one_addr;
else
@@ -688,15 +688,15 @@ void nasal_vm::opr_callf()
die("callf: special call cannot use dynamic argument");
return;
}
for(auto i=ref_keys.begin();i!=ref_keys.end();++i)
for(auto& i:ref_keys)
{
if(ref_hash.count(i->first))
ref_closure[i->second+ref_func.offset]=ref_hash[i->first];
else if(ref_default[i->second])
ref_closure[i->second+ref_func.offset]=ref_default[i->second];
if(ref_hash.count(i.first))
ref_closure[i.second+ref_func.offset]=ref_hash[i.first];
else if(ref_default[i.second])
ref_closure[i.second+ref_func.offset]=ref_default[i.second];
else
{
die("callf: lack argument(s): \""+i->first+"\"");
die("callf: lack argument(s): \""+i.first+"\"");
return;
}
}
@@ -733,7 +733,7 @@ void nasal_vm::opr_slc()
switch(val->type)
{
case vm_num:num=val->ptr.num;break;
case vm_str:num=trans_string_to_number(*val->ptr.str);break;
case vm_str:num=str2num(*val->ptr.str);break;
default:die("slc: error value type");break;
}
nasal_val* res=(*stack_top)->ptr.vec->get_val((int)num);
@@ -800,7 +800,7 @@ void nasal_vm::opr_mcallv()
switch(val->type)
{
case vm_num:num=(int)val->ptr.num;break;
case vm_str:num=(int)trans_string_to_number(*val->ptr.str);break;
case vm_str:num=(int)str2num(*val->ptr.str);break;
default:die("mcallv: error value type");break;
}
nasal_val** res=(*vec_addr)->ptr.vec->get_mem(num);