[wasm-api] Return success from buffer_contents_realloc
This commit is contained in:
parent
2568890d15
commit
16ecb96922
|
@ -35,35 +35,49 @@ namespace wasm {
|
||||||
static_assert (sizeof (glyph_info_t) == sizeof (hb_glyph_info_t), "");
|
static_assert (sizeof (glyph_info_t) == sizeof (hb_glyph_info_t), "");
|
||||||
static_assert (sizeof (glyph_position_t) == sizeof (hb_glyph_position_t), "");
|
static_assert (sizeof (glyph_position_t) == sizeof (hb_glyph_position_t), "");
|
||||||
|
|
||||||
HB_WASM_API (void, buffer_contents_realloc) (HB_WASM_EXEC_ENV
|
HB_WASM_API (bool_t, buffer_contents_realloc) (HB_WASM_EXEC_ENV
|
||||||
ptr_d(buffer_contents_t, contents),
|
ptr_d(buffer_contents_t, contents),
|
||||||
uint32_t size)
|
uint32_t size)
|
||||||
{
|
{
|
||||||
HB_PTR_PARAM (buffer_contents_t, contents);
|
HB_PTR_PARAM (buffer_contents_t, contents);
|
||||||
if (unlikely (!contents))
|
if (unlikely (!contents))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
if (size <= contents->length)
|
if (size <= contents->length)
|
||||||
return;
|
return true;
|
||||||
|
|
||||||
unsigned bytes;
|
unsigned bytes;
|
||||||
if (hb_unsigned_mul_overflows (size, sizeof (glyph_info_t), &bytes))
|
if (hb_unsigned_mul_overflows (size, sizeof (glyph_info_t), &bytes))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
// TODO bounds check?
|
// TODO bounds check?
|
||||||
uint32_t infoptr = contents->info;
|
uint32_t infoptr = contents->info;
|
||||||
uint32_t posptr = contents->pos;
|
uint32_t posptr = contents->pos;
|
||||||
|
|
||||||
const char *info = (const char *) addr_app_to_native (infoptr);
|
const char *info = (const char *) addr_app_to_native (infoptr);
|
||||||
const char *pos = (const char *) addr_app_to_native (posptr);
|
const char *pos = (const char *) addr_app_to_native (posptr);
|
||||||
|
|
||||||
contents->info = wasm_runtime_module_dup_data (module_inst, info, bytes);
|
uint32_t new_info = wasm_runtime_module_dup_data (module_inst, info, bytes);
|
||||||
contents->pos = wasm_runtime_module_dup_data (module_inst, pos, bytes);
|
uint32_t new_pos = wasm_runtime_module_dup_data (module_inst, pos, bytes);
|
||||||
|
|
||||||
|
if (likely (new_info))
|
||||||
|
{
|
||||||
|
contents->info = new_info;
|
||||||
module_free (infoptr);
|
module_free (infoptr);
|
||||||
|
}
|
||||||
|
if (likely (new_pos))
|
||||||
|
{
|
||||||
|
contents->pos = new_pos;
|
||||||
module_free (posptr);
|
module_free (posptr);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO Check success
|
if (likely (new_info && new_pos))
|
||||||
|
{
|
||||||
contents->length = size;
|
contents->length = size;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
HB_WASM_API (void, buffer_contents_free) (HB_WASM_EXEC_ENV
|
HB_WASM_API (void, buffer_contents_free) (HB_WASM_EXEC_ENV
|
||||||
|
|
|
@ -58,7 +58,7 @@ static NativeSymbol _hb_wasm_native_symbols[] =
|
||||||
|
|
||||||
/* buffer */
|
/* buffer */
|
||||||
NATIVE_SYMBOL ("(i)", buffer_contents_free),
|
NATIVE_SYMBOL ("(i)", buffer_contents_free),
|
||||||
NATIVE_SYMBOL ("(ii)", buffer_contents_realloc),
|
NATIVE_SYMBOL ("(ii)i", buffer_contents_realloc),
|
||||||
NATIVE_SYMBOL ("(ii)", buffer_copy_contents),
|
NATIVE_SYMBOL ("(ii)", buffer_copy_contents),
|
||||||
NATIVE_SYMBOL ("(ii)i", buffer_set_contents),
|
NATIVE_SYMBOL ("(ii)i", buffer_set_contents),
|
||||||
NATIVE_SYMBOL ("(i)i", buffer_get_direction),
|
NATIVE_SYMBOL ("(i)i", buffer_get_direction),
|
||||||
|
|
|
@ -140,7 +140,7 @@ typedef struct
|
||||||
ptr_t(glyph_position_t) pos;
|
ptr_t(glyph_position_t) pos;
|
||||||
} buffer_contents_t;
|
} buffer_contents_t;
|
||||||
|
|
||||||
HB_WASM_API (void, buffer_contents_realloc) (HB_WASM_EXEC_ENV
|
HB_WASM_API (bool_t, buffer_contents_realloc) (HB_WASM_EXEC_ENV
|
||||||
ptr_d(buffer_contents_t, contents),
|
ptr_d(buffer_contents_t, contents),
|
||||||
uint32_t size);
|
uint32_t size);
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,8 @@ shape (void *shape_plan,
|
||||||
};
|
};
|
||||||
|
|
||||||
length = glyph_count;
|
length = glyph_count;
|
||||||
buffer_contents_realloc (&contents, length);
|
if (!buffer_contents_realloc (&contents, length))
|
||||||
|
return false;
|
||||||
cluster_t *clusters = (cluster_t *) malloc (length * sizeof (cluster_t));
|
cluster_t *clusters = (cluster_t *) malloc (length * sizeof (cluster_t));
|
||||||
uint32_t *gids = (uint32_t *) malloc (length * sizeof (uint32_t));
|
uint32_t *gids = (uint32_t *) malloc (length * sizeof (uint32_t));
|
||||||
if (!clusters || !gids)
|
if (!clusters || !gids)
|
||||||
|
|
Loading…
Reference in New Issue