]> gitweb.factorcode.org Git - factor.git/commitdiff
fix segfault, clean up code
authorSlava Pestov <slava@factorcode.org>
Wed, 13 Jul 2005 19:14:57 +0000 (19:14 +0000)
committerSlava Pestov <slava@factorcode.org>
Wed, 13 Jul 2005 19:14:57 +0000 (19:14 +0000)
native/cards.c
native/debug.c
native/factor.c
native/gc.c
native/gc.h
native/memory.c
native/run.h

index 7fbcc30ff806a3b91573ae356d361ddcec954806..850e74c6a1e85138eb59c2b3ff233780e1f0da0b 100644 (file)
@@ -61,6 +61,6 @@ void clear_cards(CELL from, CELL to)
 void collect_cards(CELL gen)
 {
        int i;
-       for(i = gen + 1; i < gc_generations; i++)
+       for(i = gen + 1; i < gen_count; i++)
                collect_gen_cards(i);
 }
index 47839b5a035fd59bb805ccc5eaf499e5a7e2c59e..674eb1c6ecc3661b90a374da144d1b1368ded8f3 100644 (file)
@@ -203,7 +203,7 @@ void dump_generation(ZONE *z)
 void dump_generations(void)
 {
        int i;
-       for(i = 0; i < gc_generations; i++)
+       for(i = 0; i < gen_count; i++)
        {
                fprintf(stderr,"Generation %d: ",i);
                dump_generation(&generations[i]);
index e01edc3dabf751cfa694909d01e7bd235acd21bf..44197b90b54983224ecba1f425b4fe8cf8988975 100644 (file)
@@ -1,14 +1,14 @@
 #include "factor.h"
 
 void init_factor(char* image, CELL ds_size, CELL cs_size,
-       CELL generations,
+       CELL gen_count,
        CELL young_size, CELL aging_size,
        CELL code_size, CELL literal_size)
 {
        /* initialize random number generator */
        srand((unsigned)time(NULL));
        init_ffi();
-       init_arena(generations,young_size,aging_size);
+       init_arena(gen_count,young_size,aging_size);
        init_compiler(code_size);
        load_image(image,literal_size);
        init_stacks(ds_size,cs_size);
@@ -17,7 +17,7 @@ void init_factor(char* image, CELL ds_size, CELL cs_size,
        init_errors();
        userenv[CPU_ENV] = tag_object(from_c_string(FACTOR_CPU_STRING));
        userenv[OS_ENV] = tag_object(from_c_string(FACTOR_OS_STRING));
-       userenv[GEN_ENV] = tag_fixnum(gc_generations);
+       userenv[GEN_ENV] = tag_fixnum(gen_count);
        userenv[CARD_OFF_ENV] = tag_cell(cards_offset);
 }
 
index 91640c497f9e5ccbecce19d09dac503446fa7afe..891aceee052d59e6cd2d1b75a9efbd0cad5a9413 100644 (file)
@@ -19,17 +19,20 @@ there are two reasons for this:
 - the nursery grows into the guard page, so allot() does not have to
 check for out of memory, whereas allot_zone() (used by the GC) longjmp()s
 back to collecting a higher generation */
-void init_arena(CELL gen_count, CELL young_size, CELL aging_size)
+void init_arena(CELL gens, CELL young_size, CELL aging_size)
 {
        int i;
        CELL alloter;
 
-       CELL total_size = (gc_generations - 1) * young_size + 2 * aging_size;
+       CELL total_size = (gens - 1) * young_size + 2 * aging_size;
        CELL cards_size = total_size / CARD_SIZE;
 
-       gc_generations = gen_count;
+       gen_count = gens;
        generations = malloc(sizeof(ZONE) * gen_count);
 
+       if(generations == 0)
+               fatal_error("Cannot allocate zone head array",0);
+
        heap_start = (CELL)alloc_guarded(total_size);
        heap_end = heap_start + total_size;
 
@@ -40,12 +43,12 @@ void init_arena(CELL gen_count, CELL young_size, CELL aging_size)
        alloter = heap_start;
 
        if(heap_start == 0)
-               fatal_error("Cannot allocate data heap",total_size);
+               fatal_error("Cannot allocate data heap",0);
 
        alloter = init_zone(&tenured,aging_size,alloter);
        alloter = init_zone(&prior,aging_size,alloter);
 
-       for(i = gc_generations - 2; i >= 0; i--)
+       for(i = gen_count - 2; i >= 0; i--)
                alloter = init_zone(&generations[i],young_size,alloter);
 
        clear_cards(NURSERY,TENURED);
index 7814e8d463577e625489ffd2fa02c3362acde6e9..75f4d1882432bda652b925f9419ba3d54c5c1f9d 100644 (file)
@@ -11,12 +11,12 @@ typedef struct {
 } ZONE;
 
 /* total number of generations. */
-CELL gc_generations;
+CELL gen_count;
 
 /* the 0th generation is where new objects are allocated. */
 #define NURSERY 0
 /* the oldest generation */
-#define TENURED (gc_generations-1)
+#define TENURED (gen_count-1)
 
 ZONE *generations;
 
index a5d4617e95e17badbe57d8b48f3332c4fc2138df..cde16bb442774f7149c95cd8c0b87a4dd94b3963 100644 (file)
@@ -146,7 +146,7 @@ void primitive_room(void)
        box_signed_cell(compiling.limit - compiling.base);
        box_signed_cell(cards_end - cards);
        box_signed_cell(prior.limit - prior.base);
-       for(gen = gc_generations - 1; gen >= 0; gen--)
+       for(gen = gen_count - 1; gen >= 0; gen--)
        {
                ZONE *z = &generations[gen];
                list = cons(cons(
index 2e61967f08987aacca141dce289f84e6eab748ad..c8041d5b37e34ccc5ad0b002fe1fb04047635d75 100644 (file)
@@ -14,7 +14,7 @@
 #define ERROR_ENV      12 /* a marker consed onto kernel errors */
 #define IN_ENV         13
 #define OUT_ENV        14
-#define GEN_ENV        15 /* set to gc_generations */
+#define GEN_ENV        15 /* set to gen_count */
 
 /* TAGGED user environment data; see getenv/setenv prims */
 DLLEXPORT CELL userenv[USER_ENV];