Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ caml_binaryen_get_memory_segment_byte_offset(value _module, value _name) {
CAMLparam2(_module, _name);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
char* name = Safe_String_val(_name);
CAMLreturn(Val_int(BinaryenGetMemorySegmentByteOffset(module, name)));
if (BinaryenGetMemorySegmentPassive(module, name)) {
CAMLreturn(Val_none);
} else {
int offset = BinaryenGetMemorySegmentByteOffset(module, name);
CAMLreturn(caml_alloc_some(Val_int(offset)));
}
}

CAMLprim value
Expand Down
4 changes: 2 additions & 2 deletions src/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ function caml_binaryen_get_num_memory_segments(wasm_mod) {
}

//Provides: caml_binaryen_get_memory_segment_byte_offset
//Requires: caml_jsstring_of_string
//Requires: caml_jsstring_of_string, to_option
function caml_binaryen_get_memory_segment_byte_offset(wasm_mod, name) {
var info = wasm_mod.getMemorySegmentInfo(caml_jsstring_of_string(name));
return info.offset;
return to_option(info.offset);
}

//Provides: caml_binaryen_get_memory_segment_passive
Expand Down
2 changes: 1 addition & 1 deletion src/memory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ let unlimited = -1
external get_num_segments : Module.t -> int
= "caml_binaryen_get_num_memory_segments"

external get_segment_byte_offset : Module.t -> string -> int
external get_segment_byte_offset : Module.t -> string -> int option
= "caml_binaryen_get_memory_segment_byte_offset"

external get_segment_passive : Module.t -> string -> bool
Expand Down
2 changes: 1 addition & 1 deletion src/memory.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ val is_shared : Module.t -> string -> bool
val is_64 : Module.t -> string -> bool
val unlimited : int
val get_num_segments : Module.t -> int
val get_segment_byte_offset : Module.t -> string -> int
val get_segment_byte_offset : Module.t -> string -> int option
val get_segment_passive : Module.t -> string -> bool
val get_segment_data : Module.t -> string -> bytes
3 changes: 3 additions & 0 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ let _ = Memory.set_memory max_memory_wasm_mod 1 2 "memory" [] false false "0"
let _ = assert (Memory.has_max max_memory_wasm_mod "0" = true)
let _ = assert (Memory.get_max max_memory_wasm_mod "0" = 2)

(* Memory.get_segment_byte_offset Passive *)
let _ = assert (Memory.get_segment_byte_offset wasm_mod "world" = None)

let _ =
assert (
Bytes.equal
Expand Down