[wasm-api] Add macros for ref handling

This commit is contained in:
Behdad Esfahbod 2023-02-23 10:29:04 -07:00
parent 4c8a414a10
commit 62f3c7cf67
2 changed files with 16 additions and 6 deletions

View File

@ -41,7 +41,15 @@
#undef HB_WASM_BEGIN_DECLS
#undef HB_WASM_END_DECLS
#define nullref 0
#define module_inst wasm_runtime_get_module_inst (exec_env)
#define HB_REF2OBJ(obj) \
hb_##obj##_t *obj = nullptr; \
(void) wasm_externref_ref2obj (obj##ref, (void **) &obj)
#define HB_OBJ2REF(obj) \
uint32_t obj##ref = nullref; \
(void) wasm_externref_obj2ref (module_inst, obj, &obj##ref)
#include "hb-wasm-font.hh"
@ -57,9 +65,12 @@ debugprint (HB_WASM_EXEC_ENV
}}
#endif
#undef nullref
#undef module_inst
#undef HB_WASM_EXEC_ENV
#undef HB_REF2OBJ
#undef HB_OBJ2REF
/* Define an array of NativeSymbol for the APIs to be exported.

View File

@ -35,14 +35,13 @@ face_t
font_get_face (HB_WASM_EXEC_ENV
font_t fontref)
{
hb_font_t *font;
if (unlikely (!wasm_externref_ref2obj (fontref, (void **) &font)))
return 0;
HB_REF2OBJ (font);
if (unlikely (!font))
return nullref;
hb_face_t *face = hb_font_get_face (font);
uint32_t faceref = 0;
(void) wasm_externref_obj2ref (module_inst, face, &faceref);
HB_OBJ2REF (face);
return faceref;
}