Skip to content

Commit

Permalink
Port #1539 (add the %get_header primitive) (#2088)
Browse files Browse the repository at this point in the history
  • Loading branch information
riaqn committed Nov 29, 2023
1 parent 877f053 commit b63f1ec
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions ocaml/runtime/obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ CAMLprim value caml_obj_make_forward(value blk, value fwd)
return Val_unit;
}

CAMLprim value caml_get_header(value blk)
{
// undefined behaviour if blk is not a block
intnat r = Hd_val(blk);
return caml_copy_nativeint(r);
}

/* [size] is a value encoding a number of blocks */
CAMLprim value caml_obj_block(value tag, value size)
{
Expand Down
12 changes: 8 additions & 4 deletions ocaml/testsuite/tests/lib-obj/get_header.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
(* TEST
* native
reference = "${test_source_directory}/get_header.opt.reference"
* bytecode
reference = "${test_source_directory}/get_header.byte.reference"
*)
reference = "${test_source_directory}/get_header.heap.reference"
* stack-allocation
** native
reference = "${test_source_directory}/get_header.stack.reference"
* no-stack-allocation
** native
reference = "${test_source_directory}/get_header.heap.reference"
*)

(* We're likely to remove %get_header in favour of calls to
caml_obj_is_stack under runtime5 (since testing a block's colour isn't
Expand Down

0 comments on commit b63f1ec

Please sign in to comment.