Index: D:/Work/ocaml/ancient/ancient_c.c =================================================================== --- D:/Work/ocaml/ancient/ancient_c.c (revision 88) +++ D:/Work/ocaml/ancient/ancient_c.c (revision 89) @@ -43,7 +43,7 @@ // Area is an expandable buffer, allocated on the C heap. typedef struct area { - void *ptr; // Start of area. + char *ptr; // Start of area. size_t n; // Current position. size_t size; // Allocated size. @@ -145,11 +145,16 @@ static size_t _mark (value obj, area *ptr, area *restore, area *fixups) { + char *header; + size_t offset, bytes; + int can_scan; + struct restore_item restore_item; + // XXX This assertion might fail if someone tries to mark an object // which is already ancient. assert (Is_young (obj) || Is_in_heap (obj)); - char *header = Hp_val (obj); + header = Hp_val (obj); // If we've already visited this object, just return its offset // in the out-of-heap memory. @@ -162,15 +167,15 @@ assert (Wosize_hp (header) > 0); // Offset where we will store this object in the out-of-heap memory. - size_t offset = ptr->n; + offset = ptr->n; // Copy the object out of the OCaml heap. - size_t bytes = Bhsize_hp (header); + bytes = Bhsize_hp (header); if (area_append (ptr, header, bytes) == -1) return -1; // Error out of memory. // Scan the fields looking for pointers to blocks. - int can_scan = Tag_val (obj) < No_scan_tag; + can_scan = Tag_val (obj) < No_scan_tag; if (can_scan) { mlsize_t nr_words = Wosize_hp (header); mlsize_t i; @@ -181,19 +186,22 @@ if (Is_block (field) && (Is_young (field) || Is_in_heap (field))) { size_t field_offset = _mark (field, ptr, restore, fixups); + char *obj_copy_header; + value obj_copy; + size_t fixup; if (field_offset == -1) return -1; // Propagate out of memory errors. // Since the recursive call to mark above can reallocate the // area, we need to recompute these each time round the loop. - char *obj_copy_header = ptr->ptr + offset; - value obj_copy = Val_hp (obj_copy_header); + obj_copy_header = (char*)ptr->ptr + offset; + obj_copy = Val_hp (obj_copy_header); // Don't store absolute pointers yet because realloc will // move the memory around. Store a fake pointer instead. // We'll fix up these fake pointers afterwards in do_fixups. Field (obj_copy, i) = field_offset + sizeof (header_t); - size_t fixup = (void *)&Field(obj_copy, i) - ptr->ptr; + fixup = (char *)&Field(obj_copy, i) - ptr->ptr; area_append (fixups, &fixup, sizeof fixup); } } @@ -212,7 +220,6 @@ // we've visited (but see notes on 'static header_t visited' above). // (4) All objects in OCaml are at least one word long (XXX - actually // this is not true). - struct restore_item restore_item; restore_item.header = header; restore_item.field_zero = Field (obj, 0); area_append (restore, &restore_item, sizeof restore_item); @@ -232,12 +239,15 @@ { struct restore_item *restore_item = (struct restore_item *)(restore->ptr + i); + value obj; + size_t offset; + char *obj_copy_header; assert (memcmp (restore_item->header, &visited, sizeof visited) == 0); - value obj = Val_hp (restore_item->header); - size_t offset = Long_val (Field (obj, 0)); + obj = Val_hp (restore_item->header); + offset = Long_val (Field (obj, 0)); - char *obj_copy_header = ptr->ptr + offset; + obj_copy_header = ptr->ptr + offset; //value obj_copy = Val_hp (obj_copy_header); // Restore the original header. @@ -271,10 +281,10 @@ size_t *r_size) { area ptr; // This will be the out of heap area. + area restore; // Headers to be fixed up after. + area fixups; // List of fake pointers to be fixed up. area_init_custom (&ptr, realloc, free, data); - area restore; // Headers to be fixed up after. area_init (&restore); - area fixups; // List of fake pointers to be fixed up. area_init (&fixups); if (_mark (obj, &ptr, &restore, &fixups) == -1) { @@ -309,7 +319,7 @@ static void my_free (void *data __attribute__((unused)), void *ptr) { - return free (ptr); + free (ptr); } CAMLprim value @@ -392,6 +402,31 @@ CAMLreturn (v); } +#ifdef _WIN32 + +value ancient_attach (value fdv, value baseaddrv) +{ + failwith("ancient_attach: not supported"); + return Val_unit; +} +value ancient_detach (value mdv) +{ + failwith("ancient_detach: not supported"); + return Val_unit; +} +value ancient_share_info (value mdv, value keyv, value obj) +{ + failwith("ancient_share_info: not supported"); + return Val_unit; +} +value ancient_get (value mdv, value keyv) +{ + failwith("ancient_get: not supported"); + return Val_unit; +} + +#else + CAMLprim value ancient_attach (value fdv, value baseaddrv) { @@ -440,6 +475,8 @@ void *md = (void *) Field (mdv, 0); int key = Int_val (keyv); + size_t size; + void *ptr; // Get the key table. struct keytable *keytable = mmalloc_getkey (md, 0); @@ -461,16 +498,15 @@ if (key >= keytable->allocated) { int allocated = keytable->allocated == 0 ? 32 : keytable->allocated * 2; void **keys = mrealloc (md, keytable->keys, allocated * sizeof (void *)); + int i; if (keys == 0) caml_failwith ("out of memory"); - int i; for (i = keytable->allocated; i < allocated; ++i) keys[i] = 0; keytable->keys = keys; keytable->allocated = allocated; } // Do the mark. - size_t size; - void *ptr = mark (obj, mrealloc, mfree, md, &size); + ptr = mark (obj, mrealloc, mfree, md, &size); // Add the key to the keytable. keytable->keys[key] = ptr; @@ -498,12 +534,13 @@ void *md = (void *) Field (mdv, 0); int key = Int_val (keyv); + void *ptr; // Key exists? struct keytable *keytable = mmalloc_getkey (md, 0); if (keytable == 0 || key >= keytable->allocated || keytable->keys[key] == 0) caml_raise_not_found (); - void *ptr = keytable->keys[key]; + ptr = keytable->keys[key]; // Return the proxy. proxy = caml_alloc (1, Abstract_tag); @@ -511,3 +548,5 @@ CAMLreturn (proxy); } + +#endif // _WIN32