[wasm-api] Make buffer_copy_contents return success
This commit is contained in:
parent
1023a80d39
commit
b5b577f29f
|
@ -95,22 +95,30 @@ HB_WASM_API (void, buffer_contents_free) (HB_WASM_EXEC_ENV
|
|||
contents->length = 0;
|
||||
}
|
||||
|
||||
HB_WASM_API_COMPOUND (buffer_contents_t, buffer_copy_contents) (HB_WASM_EXEC_ENV_COMPOUND
|
||||
ptr_d(buffer_t, buffer))
|
||||
HB_WASM_API (bool_t, buffer_copy_contents) (HB_WASM_EXEC_ENV
|
||||
ptr_d(buffer_t, buffer),
|
||||
ptr_d(buffer_contents_t, contents))
|
||||
{
|
||||
HB_RETURN_STRUCT (buffer_contents_t, ret);
|
||||
HB_REF2OBJ (buffer);
|
||||
HB_PTR_PARAM (buffer_contents_t, contents);
|
||||
if (unlikely (!contents))
|
||||
return false;
|
||||
|
||||
if (buffer->have_output)
|
||||
buffer->sync ();
|
||||
|
||||
unsigned length = buffer->len;
|
||||
ret.length = length;
|
||||
ret.info = wasm_runtime_module_dup_data (module_inst, (const char *) buffer->info, length * sizeof (buffer->info[0]));
|
||||
ret.pos = wasm_runtime_module_dup_data (module_inst, (const char *) buffer->pos, length * sizeof (buffer->pos[0]));
|
||||
contents->length = length;
|
||||
contents->info = wasm_runtime_module_dup_data (module_inst, (const char *) buffer->info, length * sizeof (buffer->info[0]));
|
||||
contents->pos = wasm_runtime_module_dup_data (module_inst, (const char *) buffer->pos, length * sizeof (buffer->pos[0]));
|
||||
|
||||
if (!ret.info || !ret.pos)
|
||||
ret.length = 0;
|
||||
if (length && (!contents->info || !contents->pos))
|
||||
{
|
||||
contents->length = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
HB_WASM_API (bool_t, buffer_set_contents) (HB_WASM_EXEC_ENV
|
||||
|
|
|
@ -59,7 +59,7 @@ static NativeSymbol _hb_wasm_native_symbols[] =
|
|||
/* buffer */
|
||||
NATIVE_SYMBOL ("(i)", buffer_contents_free),
|
||||
NATIVE_SYMBOL ("(ii)i", buffer_contents_realloc),
|
||||
NATIVE_SYMBOL ("(ii)", buffer_copy_contents),
|
||||
NATIVE_SYMBOL ("(ii)i", buffer_copy_contents),
|
||||
NATIVE_SYMBOL ("(ii)i", buffer_set_contents),
|
||||
NATIVE_SYMBOL ("(i)i", buffer_get_direction),
|
||||
NATIVE_SYMBOL ("(i)i", buffer_get_script),
|
||||
|
|
|
@ -149,8 +149,9 @@ HB_WASM_API (void, buffer_contents_free) (HB_WASM_EXEC_ENV
|
|||
|
||||
typedef struct buffer_t buffer_t;
|
||||
|
||||
HB_WASM_API_COMPOUND (buffer_contents_t, buffer_copy_contents) (HB_WASM_EXEC_ENV_COMPOUND
|
||||
ptr_d(buffer_t, buffer));
|
||||
HB_WASM_API (bool_t, buffer_copy_contents) (HB_WASM_EXEC_ENV
|
||||
ptr_d(buffer_t, buffer),
|
||||
ptr_d(buffer_contents_t, contents));
|
||||
|
||||
HB_WASM_API (bool_t, buffer_set_contents) (HB_WASM_EXEC_ENV
|
||||
ptr_d(buffer_t, buffer),
|
||||
|
|
|
@ -74,8 +74,8 @@ shape (void *shape_plan,
|
|||
direction = DIRECTION_REVERSE (direction);
|
||||
}
|
||||
|
||||
buffer_contents_t contents = buffer_copy_contents (buffer);
|
||||
if (!contents.length)
|
||||
buffer_contents_t contents;
|
||||
if (!buffer_copy_contents (buffer, &contents))
|
||||
return false;
|
||||
|
||||
gr_segment *seg = nullptr;
|
||||
|
|
|
@ -23,7 +23,9 @@ shape (void *shape_plan,
|
|||
|
||||
blob_free (&blob);
|
||||
|
||||
buffer_contents_t contents = buffer_copy_contents (buffer);
|
||||
buffer_contents_t contents;
|
||||
if (!buffer_copy_contents (buffer, &contents))
|
||||
return false;
|
||||
|
||||
debugprint1 ("buffer length", contents.length);
|
||||
|
||||
|
|
Loading…
Reference in New Issue