Skip to content

Commit

Permalink
WebIDL: Use malloc/strcpy on Struct String setters, fix libass#77
Browse files Browse the repository at this point in the history
From @TheOneric:
  For most libass APIs the char* strings remain owned by the caller with libass doing
  internal copies if needed. This means the caller must if necessary free the memory
  at some point after the libass API call finished. The track and event modification/creation
  APIs are different because they work close to library internals (which is also why their usage
  comes with more restrictions/obligations than other APIs and why they don't sensibly work with
  ass.h alone).

Since we transfer ownership of the pointer to libass, this is unlikely to cause memory leaks.
  • Loading branch information
TFSThiagoBR98 committed Feb 19, 2022
1 parent ed8d9a5 commit 820c132
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 820c132

Please sign in to comment.