From 851ef1380aec550e51a4d8055a9c8aef2b57aeeb Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 23 Feb 2023 15:06:18 -0700 Subject: [PATCH] [wasm-api] Add buffer-contents-free --- src/hb-wasm-api-buffer.hh | 13 +++++++++++++ src/hb-wasm-api-list.hh | 1 + src/hb-wasm-api.h | 5 +++-- src/wasm-sample/shape.c | 2 ++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/hb-wasm-api-buffer.hh b/src/hb-wasm-api-buffer.hh index 38ebf7c76..139899a8f 100644 --- a/src/hb-wasm-api-buffer.hh +++ b/src/hb-wasm-api-buffer.hh @@ -33,6 +33,19 @@ namespace hb { namespace wasm { +void +buffer_contents_free (HB_WASM_EXEC_ENV + ptr_t(buffer_contents_t) contentsptr) +{ + if (unlikely (!validate_app_addr (contentsptr, sizeof (buffer_contents_t)))) + return; + + buffer_contents_t *contents = (buffer_contents_t *) addr_app_to_native (contentsptr); + + module_free (contents->info); + module_free (contents->pos); +} + void buffer_copy_contents (HB_WASM_EXEC_ENV_COMPOUND ptr_t(buffer_t) bufferref) diff --git a/src/hb-wasm-api-list.hh b/src/hb-wasm-api-list.hh index 6609c6860..14a1f60ab 100644 --- a/src/hb-wasm-api-list.hh +++ b/src/hb-wasm-api-list.hh @@ -55,6 +55,7 @@ static NativeSymbol _hb_wasm_native_symbols[] = NATIVE_SYMBOL ("(i)", blob_free), /* buffer */ + NATIVE_SYMBOL ("(i)", buffer_contents_free), NATIVE_SYMBOL ("(ii)", buffer_copy_contents), /* face */ diff --git a/src/hb-wasm-api.h b/src/hb-wasm-api.h index 25bd0fc30..1adb4e2c6 100644 --- a/src/hb-wasm-api.h +++ b/src/hb-wasm-api.h @@ -85,7 +85,7 @@ typedef struct } blob_t; HB_WASM_API (void, blob_free) (HB_WASM_EXEC_ENV - ptr_t(blob_t) blob); + ptr_t(blob_t)); /* buffer */ @@ -115,7 +115,8 @@ typedef struct ptr_t(glyph_position_t) pos; } buffer_contents_t; -/* TODO buffer_contents_free */ +HB_WASM_API (void, buffer_contents_free) (HB_WASM_EXEC_ENV + ptr_t(buffer_contents_t)); typedef struct buffer_t buffer_t; diff --git a/src/wasm-sample/shape.c b/src/wasm-sample/shape.c index c2b15ea9a..80486b2b5 100644 --- a/src/wasm-sample/shape.c +++ b/src/wasm-sample/shape.c @@ -25,5 +25,7 @@ shape (font_t *font, buffer_t *buffer) for (unsigned i = 0; i < contents.length; i++) debugprint2 ("Codepoint", i, contents.info[i].codepoint); + buffer_contents_free (&contents); + return 1; }