Skip to content

Commit

Permalink
WebIDL: Workaround ensureCache in Struct Setters, fix libass#77
Browse files Browse the repository at this point in the history
Currently the ensureCache create a temporary pointer that will
transfer the value to the WASM/C part and recycle it with to use in the
next value, but since the libass struct pointers are owned by the
library, the pointers can't be recycled or freed or can lead into
an undefined behavior.

This patch allocate new memory and copy the pointer before set into struct
attribute.

To avoid creating complex code, I decided to fix it in the webidl binder, but
i plan to make a way to mark if the attribute need to copy the pointer.
  • Loading branch information
TFSThiagoBR98 committed Mar 11, 2022
1 parent d1072f3 commit a73a8df
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion build/webidl_binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Patched to:
## - add integer pointers (IntPtr)
## - implement ByteString type
## - fix string setter for structs
## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/tools/webidl_binder.py

# Copyright 2014 The Emscripten Authors. All rights reserved.
Expand Down Expand Up @@ -723,7 +724,12 @@ def render_function(class_name, func_name, sigs, return_type, non_pointer,
get_sigs = {0: []}
set_sigs = {1: [Dummy({'type': m.type})]}
get_call_content = take_addr_if_nonpointer(m) + 'self->' + attr
set_call_content = 'self->' + attr + ' = ' + deref_if_nonpointer(m) + 'arg0'
if m.type.isDOMString():
set_call_content = """char* copy = (char*)malloc(strlen(%s) + 1);
strcpy(copy, %s);
self->%s = copy""" % (deref_if_nonpointer(m) + 'arg0', deref_if_nonpointer(m) + 'arg0', attr)
else:
set_call_content = 'self->' + attr + ' = ' + deref_if_nonpointer(m) + 'arg0'

get_name = 'get_' + attr
mid_js += [r'''
Expand Down

0 comments on commit a73a8df

Please sign in to comment.