From fea3ffe03147c35180be09b42caee90a96c61a34 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 24 Feb 2023 12:31:32 -0700 Subject: [PATCH] [wasm-api] Beautify internal API --- src/hb-wasm-api-blob.hh | 2 +- src/hb-wasm-api-buffer.hh | 16 ++++++------ src/hb-wasm-api-face.hh | 4 +-- src/hb-wasm-api-font.hh | 20 +++++++-------- src/hb-wasm-api-shape.hh | 4 +-- src/hb-wasm-api.h | 53 +++++++++++++++++++++------------------ src/hb-wasm-api.hh | 3 ++- 7 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/hb-wasm-api-blob.hh b/src/hb-wasm-api-blob.hh index e3997d168..afcbd2672 100644 --- a/src/hb-wasm-api-blob.hh +++ b/src/hb-wasm-api-blob.hh @@ -33,7 +33,7 @@ namespace wasm { void blob_free (HB_WASM_EXEC_ENV - ptr_t(blob_t) blobptr) + ptr_d(blob_t, blob)) { HB_OUT_PARAM (blob_t, blob); if (unlikely (!blob)) diff --git a/src/hb-wasm-api-buffer.hh b/src/hb-wasm-api-buffer.hh index 1e6edd57e..d75cb6231 100644 --- a/src/hb-wasm-api-buffer.hh +++ b/src/hb-wasm-api-buffer.hh @@ -37,7 +37,7 @@ static_assert (sizeof (glyph_position_t) == sizeof (hb_glyph_position_t), ""); void buffer_contents_free (HB_WASM_EXEC_ENV - ptr_t(buffer_contents_t) contentsptr) + ptr_d(buffer_contents_t, contents)) { HB_OUT_PARAM (buffer_contents_t, contents); if (unlikely (!contents)) @@ -53,7 +53,7 @@ buffer_contents_free (HB_WASM_EXEC_ENV void buffer_contents_realloc (HB_WASM_EXEC_ENV - ptr_t(buffer_contents_t) contentsptr, + ptr_d(buffer_contents_t, contents), uint32_t size) { HB_OUT_PARAM (buffer_contents_t, contents); @@ -85,7 +85,7 @@ void void buffer_copy_contents (HB_WASM_EXEC_ENV_COMPOUND - ptr_t(buffer_t) bufferref) + ptr_d(buffer_t, buffer)) { HB_RETURN_STRUCT (buffer_contents_t, ret); HB_REF2OBJ (buffer); @@ -101,8 +101,8 @@ buffer_copy_contents (HB_WASM_EXEC_ENV_COMPOUND bool_t buffer_set_contents (HB_WASM_EXEC_ENV - ptr_t(buffer_t) bufferref, - ptr_t(const buffer_contents_t) contentsptr) + ptr_d(buffer_t, buffer), + ptr_d(const buffer_contents_t, contents)) { HB_REF2OBJ (buffer); HB_OUT_PARAM (buffer_contents_t, contents); @@ -130,7 +130,7 @@ buffer_set_contents (HB_WASM_EXEC_ENV direction_t buffer_get_direction (HB_WASM_EXEC_ENV - ptr_t(buffer_t) bufferref) + ptr_d(buffer_t, buffer)) { HB_REF2OBJ (buffer); @@ -139,7 +139,7 @@ buffer_get_direction (HB_WASM_EXEC_ENV void buffer_reverse (HB_WASM_EXEC_ENV - ptr_t(buffer_t) bufferref) + ptr_d(buffer_t, buffer)) { HB_REF2OBJ (buffer); @@ -148,7 +148,7 @@ buffer_reverse (HB_WASM_EXEC_ENV void buffer_reverse_clusters (HB_WASM_EXEC_ENV - ptr_t(buffer_t) bufferref) + ptr_d(buffer_t, buffer)) { HB_REF2OBJ (buffer); diff --git a/src/hb-wasm-api-face.hh b/src/hb-wasm-api-face.hh index 918a08682..8e086d140 100644 --- a/src/hb-wasm-api-face.hh +++ b/src/hb-wasm-api-face.hh @@ -33,7 +33,7 @@ namespace wasm { void face_reference_table (HB_WASM_EXEC_ENV_COMPOUND - ptr_t(face_t) faceref, + ptr_d(face_t, face), tag_t table_tag) { HB_RETURN_STRUCT (blob_t, ret); @@ -52,7 +52,7 @@ face_reference_table (HB_WASM_EXEC_ENV_COMPOUND unsigned face_get_upem (HB_WASM_EXEC_ENV - ptr_t(face_t) faceref) + ptr_d(face_t, face)) { HB_REF2OBJ (face); diff --git a/src/hb-wasm-api-font.hh b/src/hb-wasm-api-font.hh index b4b0548dd..89a264bd3 100644 --- a/src/hb-wasm-api-font.hh +++ b/src/hb-wasm-api-font.hh @@ -33,7 +33,7 @@ namespace wasm { ptr_t(face_t) font_get_face (HB_WASM_EXEC_ENV - ptr_t(font_t) fontref) + ptr_d(font_t, font)) { HB_REF2OBJ (font); @@ -45,9 +45,9 @@ font_get_face (HB_WASM_EXEC_ENV void font_get_scale (HB_WASM_EXEC_ENV - ptr_t(font_t) fontref, - ptr_t(int32_t) x_scaleptr, - ptr_t(int32_t) y_scaleptr) + ptr_d(font_t, font), + ptr_d(int32_t, x_scale), + ptr_d(int32_t, y_scale)) { HB_REF2OBJ (font); @@ -59,7 +59,7 @@ font_get_scale (HB_WASM_EXEC_ENV codepoint_t font_get_glyph (HB_WASM_EXEC_ENV - ptr_t(font_t) fontref, + ptr_d(font_t, font), codepoint_t unicode, codepoint_t variation_selector) { @@ -72,7 +72,7 @@ font_get_glyph (HB_WASM_EXEC_ENV hb_position_t font_get_glyph_h_advance (HB_WASM_EXEC_ENV - ptr_t(font_t) fontref, + ptr_d(font_t, font), codepoint_t glyph) { HB_REF2OBJ (font); @@ -81,7 +81,7 @@ font_get_glyph_h_advance (HB_WASM_EXEC_ENV hb_position_t font_get_glyph_v_advance (HB_WASM_EXEC_ENV - ptr_t(font_t) fontref, + ptr_d(font_t, font), codepoint_t glyph) { HB_REF2OBJ (font); @@ -92,9 +92,9 @@ static_assert (sizeof (glyph_extents_t) == sizeof (hb_glyph_extents_t), ""); bool_t font_get_glyph_extents (HB_WASM_EXEC_ENV - ptr_t(font_t) fontref, + ptr_d(font_t, font), codepoint_t glyph, - ptr_t(glyph_extents_t) extentsptr) + ptr_d(glyph_extents_t, extents)) { HB_REF2OBJ (font); HB_OUT_PARAM (glyph_extents_t, extents); @@ -107,7 +107,7 @@ font_get_glyph_extents (HB_WASM_EXEC_ENV void font_glyph_to_string (HB_WASM_EXEC_ENV - ptr_t(font_t) fontref, + ptr_d(font_t, font), codepoint_t glyph, char *s, uint32_t size) { diff --git a/src/hb-wasm-api-shape.hh b/src/hb-wasm-api-shape.hh index 952aeb229..0a65e471b 100644 --- a/src/hb-wasm-api-shape.hh +++ b/src/hb-wasm-api-shape.hh @@ -33,8 +33,8 @@ namespace wasm { bool_t shape_with (HB_WASM_EXEC_ENV - ptr_t(font_t) fontref, - ptr_t(buffer_t) bufferref, + ptr_d(font_t, font), + ptr_d(buffer_t, buffer), const char *shaper) { HB_REF2OBJ (font); diff --git a/src/hb-wasm-api.h b/src/hb-wasm-api.h index 622398f24..d72f4d2ac 100644 --- a/src/hb-wasm-api.h +++ b/src/hb-wasm-api.h @@ -68,6 +68,9 @@ HB_WASM_BEGIN_DECLS #ifndef ptr_t #define ptr_t(type_t) type_t * #endif +#ifndef ptr_d +#define ptr_d(type_t, name) type_t *name +#endif typedef uint32_t codepoint_t; typedef int32_t position_t; @@ -99,7 +102,7 @@ typedef struct } blob_t; HB_WASM_API (void, blob_free) (HB_WASM_EXEC_ENV - ptr_t(blob_t)); + ptr_d(blob_t, blob)); /* buffer */ @@ -130,40 +133,40 @@ typedef struct } buffer_contents_t; HB_WASM_API (void, buffer_contents_realloc) (HB_WASM_EXEC_ENV - ptr_t(buffer_contents_t), + ptr_d(buffer_contents_t, contents), uint32_t size); HB_WASM_API (void, buffer_contents_free) (HB_WASM_EXEC_ENV - ptr_t(buffer_contents_t)); + ptr_d(buffer_contents_t, contents)); typedef struct buffer_t buffer_t; HB_WASM_API_COMPOUND (buffer_contents_t, buffer_copy_contents) (HB_WASM_EXEC_ENV_COMPOUND - ptr_t(buffer_t)); + ptr_d(buffer_t, buffer)); HB_WASM_API (bool_t, buffer_set_contents) (HB_WASM_EXEC_ENV - ptr_t(buffer_t), - ptr_t(const buffer_contents_t)); + ptr_d(buffer_t, buffer), + ptr_d(const buffer_contents_t, contents)); HB_WASM_API (direction_t, buffer_get_direction) (HB_WASM_EXEC_ENV - ptr_t(buffer_t)); + ptr_d(buffer_t, buffer)); HB_WASM_API (void, buffer_reverse) (HB_WASM_EXEC_ENV - ptr_t(buffer_t)); + ptr_d(buffer_t, buffer)); HB_WASM_API (void, buffer_reverse_clusters) (HB_WASM_EXEC_ENV - ptr_t(buffer_t)); + ptr_d(buffer_t, buffer)); /* face */ typedef struct face_t face_t; HB_WASM_API_COMPOUND (blob_t, face_reference_table) (HB_WASM_EXEC_ENV_COMPOUND - ptr_t(face_t), + ptr_d(face_t, face), tag_t table_tag); HB_WASM_API (unsigned, face_get_upem) (HB_WASM_EXEC_ENV - ptr_t(face_t)); + ptr_d(face_t, face)); /* font */ @@ -171,24 +174,24 @@ HB_WASM_API (unsigned, face_get_upem) (HB_WASM_EXEC_ENV typedef struct font_t font_t; HB_WASM_API (ptr_t(face_t), font_get_face) (HB_WASM_EXEC_ENV - ptr_t(font_t)); + ptr_d(font_t, font)); HB_WASM_API (void, font_get_scale) (HB_WASM_EXEC_ENV - ptr_t(font_t), - ptr_t(int32_t) x_scale, - ptr_t(int32_t) y_scale); + ptr_d(font_t, font), + ptr_d(int32_t, x_scale), + ptr_d(int32_t, y_scale)); HB_WASM_API (codepoint_t, font_get_glyph) (HB_WASM_EXEC_ENV - ptr_t(font_t), + ptr_d(font_t, font), codepoint_t unicode, codepoint_t variation_selector); HB_WASM_API (position_t, font_get_glyph_h_advance) (HB_WASM_EXEC_ENV - ptr_t(font_t), + ptr_d(font_t, font), codepoint_t glyph); HB_WASM_API (position_t, font_get_glyph_v_advance) (HB_WASM_EXEC_ENV - ptr_t(font_t), + ptr_d(font_t, font), codepoint_t glyph); typedef struct { @@ -199,12 +202,12 @@ typedef struct { } glyph_extents_t; HB_WASM_API (bool_t, font_get_glyph_extents) (HB_WASM_EXEC_ENV - ptr_t(font_t), + ptr_d(font_t, font), codepoint_t glyph, - ptr_t(glyph_extents_t) extents); + ptr_d(glyph_extents_t, extents)); HB_WASM_API (void, font_glyph_to_string) (HB_WASM_EXEC_ENV - ptr_t(font_t), + ptr_d(font_t, font), codepoint_t glyph, char *s, uint32_t size); @@ -212,16 +215,16 @@ HB_WASM_API (void, font_glyph_to_string) (HB_WASM_EXEC_ENV /* shape */ HB_WASM_INTERFACE (bool_t, shape_with) (HB_WASM_EXEC_ENV - ptr_t(font_t), - ptr_t(buffer_t), + ptr_d(font_t, font), + ptr_d(buffer_t, buffer), const char *shaper); /* shape interface */ HB_WASM_INTERFACE (bool_t, shape) (HB_WASM_EXEC_ENV - ptr_t(font_t), - ptr_t(buffer_t)); + ptr_d(font_t, font), + ptr_d(buffer_t, buffer)); HB_WASM_END_DECLS diff --git a/src/hb-wasm-api.hh b/src/hb-wasm-api.hh index 19570698e..5b99c8030 100644 --- a/src/hb-wasm-api.hh +++ b/src/hb-wasm-api.hh @@ -39,6 +39,7 @@ #define HB_WASM_EXEC_ENV_COMPOUND wasm_exec_env_t exec_env, ptr_t() retptr, #define ptr_t(type_t) uint32_t +#define ptr_d(type_t, name) uint32_t name##ptr #include "hb-wasm-api.h" @@ -61,7 +62,7 @@ HB_INTERNAL extern hb_user_data_key_t _hb_wasm_ref_type_key; #define HB_REF2OBJ(obj) \ hb_##obj##_t *obj = nullptr; \ HB_STMT_START { \ - (void) wasm_externref_ref2obj (obj##ref, (void **) &obj); \ + (void) wasm_externref_ref2obj (obj##ptr, (void **) &obj); \ /* Check object type. */ \ /* This works because all our objects have the same hb_object_t layout. */ \ if (unlikely (hb_##obj##_get_user_data (obj, &_hb_wasm_ref_type_key) != \