RPA Toolkit
fixed codemap reallocation in the middle of addition -> crash.
authorMartin Stoilov <martin@rpasearch.com>
Sat, 28 May 2011 05:30:44 +0000 (22:30 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Sat, 28 May 2011 05:30:44 +0000 (22:30 -0700)
rjs/rjscompiler.c
rvm/rvmcodegen.c
rvm/rvmcodemap.c

index 8e5d65b..2d92fe9 100644 (file)
@@ -539,7 +539,6 @@ rint rjs_compiler_rh_stringliteral(rjs_compiler_t *co, rarray_t *records, rlong
        rvmreg_t *strreg;
        rstring_t *s;
        rlong stringidx;
-       rchar temp[256];
 
        rjs_compiler_debughead(co, records, rec);
        co->stringcharacters.str = NULL;
@@ -554,9 +553,7 @@ rint rjs_compiler_rh_stringliteral(rjs_compiler_t *co, rarray_t *records, rlong
        rjs_compiler_debughead(co, records, rec);
 
 /*
-       memset(temp, 0, sizeof(temp));
-       r_snprintf(temp, sizeof(temp), "__%ld__stringliteral", rvm_codegen_getcodesize(co->cg));
-       stringidx = rvm_codegen_adddata_s(co->cg, temp, "hello", 4);
+       stringidx = rvm_codegen_adddata_s(co->cg, NULL, co->stringcharacters.str, co->stringcharacters.size);
        rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_STRING, stringidx, rvm_asma(RVM_MOV, R0, DA, XX, 0, co->stringcharacters.size));
 */
        strreg = rvm_cpu_alloc_global(co->cpu);
@@ -564,7 +561,6 @@ rint rjs_compiler_rh_stringliteral(rjs_compiler_t *co, rarray_t *records, rlong
        rvm_gc_add(co->cpu->gc, (robject_t*)s);
        rvm_reg_setstring(strreg, s);
        rvm_codegen_addins(co->cg, rvm_asmp(RVM_LDRR, R0, DA, XX, strreg));
-
        rjs_compiler_debugtail(co, records, rec);
        return 0;
 }
index b8e3e71..ab3c1ce 100644 (file)
@@ -83,15 +83,13 @@ rsize_t rvm_codegen_addins(rvm_codegen_t *cg, rvm_asmins_t ins)
 
 rlong rvm_codegen_redefinelabel(rvm_codegen_t *cg, rlong index, rulong offset)
 {
+       rlong codeidx = rvm_codemap_lookupadd_s(cg->codemap, ".code");
        rvm_codelabel_t *label = rvm_codemap_label(cg->codemap, index);
 
        if (!label)
                return -1;
-       return rvm_codemap_addoffset(cg->codemap, label->name->str, label->name->size, rvm_codemap_lookupadd_s(cg->codemap, ".code"), RVM_CODE2BYTE_OFFSET(offset));
-
-//  This doesn't work
-//     rvm_codelabel_setoffset(label, rvm_codemap_lookupadd_s(cg->codemap, ".code"), RVM_CODE2BYTE_OFFSET(offset));
-//     return index;
+       rvm_codelabel_setoffset(label, codeidx, RVM_CODE2BYTE_OFFSET(offset));
+       return index;
 }
 
 
@@ -113,11 +111,9 @@ rlong rvm_codegen_redefinepointer(rvm_codegen_t *cg, rlong index, rpointer data)
 
        if (!label)
                return -1;
-       return rvm_codemap_addpointer(cg->codemap, label->name->str, label->name->size, data);
-
-// This doesn't work
-//     rvm_codelabel_setpointer(label, data);
-//     return index;
+//     return rvm_codemap_addpointer(cg->codemap, label->name->str, label->name->size, data);
+       rvm_codelabel_setpointer(label, data);
+       return index;
 }
 
 
index feff70d..5f346ed 100644 (file)
@@ -64,7 +64,7 @@ static rlong rvm_codemap_dolookup(rvm_codemap_t *codemap, const rchar *name, rui
 
 static rlong rvm_codemap_add(rvm_codemap_t *codemap, const rchar *name, ruint namesize)
 {
-       rvm_codelabel_t *label;
+       rvm_codelabel_t *label = NULL;
        rlong labelidx = -1;
 
        labelidx = rvm_codemap_dolookup(codemap, name, namesize);