[wasm-api] Add blob_free

This commit is contained in:
Behdad Esfahbod 2023-02-23 14:54:46 -07:00
parent 3bec8dca1c
commit cbd5c554fb
7 changed files with 59 additions and 2 deletions

49
src/hb-wasm-api-blob.hh Normal file
View File

@ -0,0 +1,49 @@
/*
* Copyright © 2023 Behdad Esfahbod
*
* This is part of HarfBuzz, a text shaping library.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
#ifndef HB_WASM_API_BLOB_HH
#define HB_WASM_API_BLOB_HH
#include "hb-wasm-api.hh"
namespace hb {
namespace wasm {
void
blob_free (HB_WASM_EXEC_ENV
ptr_t(blob_t) blobptr)
{
if (unlikely (!validate_app_addr (blobptr, sizeof (blob_t))))
return;
blob_t *blob = (blob_t *) addr_app_to_native (blobptr);
module_free (blob->data);
}
}}
#endif /* HB_WASM_API_BLOB_HH */

View File

@ -51,6 +51,9 @@ static void debugprint4 (HB_WASM_EXEC_ENV char *str, int32_t i1, int32_t i2, int
static NativeSymbol _hb_wasm_native_symbols[] =
{
/* blob */
NATIVE_SYMBOL ("(i)", blob_free),
/* buffer */
NATIVE_SYMBOL ("(ii)", buffer_copy_contents),

View File

@ -27,6 +27,7 @@
#define module_inst wasm_runtime_get_module_inst (exec_env)
#include "hb-wasm-api-blob.hh"
#include "hb-wasm-api-buffer.hh"
#include "hb-wasm-api-face.hh"
#include "hb-wasm-api-font.hh"

View File

@ -91,7 +91,8 @@ typedef struct
ptr_t(char) data;
} blob_t;
/* TODO blob_free */
HB_WASM_API (void, blob_free) (HB_WASM_EXEC_ENV
ptr_t(blob_t) blob);
/* buffer */

View File

@ -327,6 +327,7 @@ hb_graphite2_headers = files('hb-graphite2.h')
hb_wasm_sources = files(
'hb-wasm-api.cc',
'hb-wasm-api.hh',
'hb-wasm-api-blob.hh',
'hb-wasm-api-buffer.hh',
'hb-wasm-api-face.hh',
'hb-wasm-api-font.hh',

View File

@ -16,3 +16,5 @@ all: test.wasm.ttf
clean:
$(RM) test.wasm.ttf shape.so
.PRECIOUS: shape.so

View File

@ -16,7 +16,7 @@ shape (font_t font, buffer_t buffer)
debugprint1 ("cmap length", blob.length);
free (blob.data);
blob_free (&blob);
buffer_contents_t contents = buffer_copy_contents (buffer);