diff --git a/src/hb-wasm-api.hh b/src/hb-wasm-api.hh index d7bfd322d..376ba1a7b 100644 --- a/src/hb-wasm-api.hh +++ b/src/hb-wasm-api.hh @@ -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. diff --git a/src/hb-wasm-font.hh b/src/hb-wasm-font.hh index 9a2272ebc..788261bf6 100644 --- a/src/hb-wasm-font.hh +++ b/src/hb-wasm-font.hh @@ -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; }