Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add release callback #91

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { parseRecordBatch } from "./record-batch";
export { parseSchema } from "./schema";
export { parseVector, parseData } from "./vector";
export { parseTable } from "./table";
export { releaseSchema } from "./release";
10 changes: 10 additions & 0 deletions src/release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function releaseSchema(
buffer: ArrayBuffer,
ptr: number,
funcTable: WebAssembly.Table,
): void {
const dataView = new DataView(buffer);
const releasePtr = dataView.getUint32(ptr + 40, true);
const releaseCallback = funcTable.get(releasePtr);
releaseCallback();
}
19 changes: 19 additions & 0 deletions tests/release.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, it, expect } from "vitest";
import * as wasm from "rust-arrow-ffi";
import { arrowTableToFFI, loadIPCTableFromDisk } from "./utils";
import { releaseSchema } from "../src";

wasm.setPanicHook();

const WASM_MEMORY = wasm.wasmMemory();

describe("test release", (t) => {
it("should release schema", () => {
const TEST_TABLE = loadIPCTableFromDisk("tests/table.arrow");
const FFI_TABLE = arrowTableToFFI(TEST_TABLE);

const funcTable = wasm._functionTable();
const schemaAddr = FFI_TABLE.schemaAddr(0);
releaseSchema(WASM_MEMORY.buffer, schemaAddr, funcTable);
});
});
13 changes: 13 additions & 0 deletions tests/rust-arrow-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ pub fn set_panic_hook() {
// https://github.com/rustwasm/console_error_panic_hook#readme
console_error_panic_hook::set_once();
}

/// Returns a handle to this wasm instance's `WebAssembly.Memory`
#[wasm_bindgen(js_name = wasmMemory)]
pub fn memory() -> JsValue {
wasm_bindgen::memory()
}

/// Returns a handle to this wasm instance's `WebAssembly.Table` which is the indirect function
/// table used by Rust
#[wasm_bindgen(js_name = _functionTable)]
pub fn function_table() -> JsValue {
wasm_bindgen::function_table()
}
Loading