Skip to content

Commit

Permalink
Add webidl_binder patches for future reference
Browse files Browse the repository at this point in the history
  • Loading branch information
TFSThiagoBR98 committed Feb 19, 2022
1 parent a8de6c7 commit 0797f31
Show file tree
Hide file tree
Showing 4 changed files with 272 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
From d9b7e2738213d631810ace5e5f47cc8bc210fa8c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thiago=20Fran=C3=A7a=20da=20Silva?=
<[email protected]>
Date: Fri, 18 Feb 2022 21:18:04 -0300
Subject: [PATCH 1/4] WebIDL: Add headers and make it work under
SubtitlesOctopus project

---
build/WebIDL.py | 3 +++
build/tempfiles.py | 3 +++
build/webidl_binder.py | 20 ++++++++++----------
3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/build/WebIDL.py b/build/WebIDL.py
index 14689cb..8892616 100644
--- a/build/WebIDL.py
+++ b/build/WebIDL.py
@@ -1,3 +1,6 @@
+## JavascriptSubtitlesOctopus
+## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/third_party/WebIDL.py
+
# from https://hg.mozilla.org/mozilla-central/file/tip/dom/bindings/parser/WebIDL.py
# rev 501baeb3a034

diff --git a/build/tempfiles.py b/build/tempfiles.py
index e1c9dcc..6487516 100644
--- a/build/tempfiles.py
+++ b/build/tempfiles.py
@@ -1,3 +1,6 @@
+## JavascriptSubtitlesOctopus
+## From https://github.com/emscripten-core/emscripten/blob/c834ef7d69ccb4100239eeba0b0f6573fed063bc/tools/tempfiles.py
+
# Copyright 2013 The Emscripten Authors. All rights reserved.
# Emscripten is available under two separate licenses, the MIT license and the
# University of Illinois/NCSA Open Source License. Both these licenses can be
diff --git a/build/webidl_binder.py b/build/webidl_binder.py
index da864f8..687a5ba 100644
--- a/build/webidl_binder.py
+++ b/build/webidl_binder.py
@@ -1,3 +1,6 @@
+## JavascriptSubtitlesOctopus
+## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/tools/webidl_binder.py
+
# Copyright 2014 The Emscripten Authors. All rights reserved.
# Emscripten is available under two separate licenses, the MIT license and the
# University of Illinois/NCSA Open Source License. Both these licenses can be
@@ -10,15 +13,12 @@ https://emscripten.org/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.

import os
import sys
+from tempfiles import try_delete

-__scriptdir__ = os.path.dirname(os.path.abspath(__file__))
-__rootdir__ = os.path.dirname(__scriptdir__)
-sys.path.append(__rootdir__)
-
-from tools import shared, utils
+def path_from_root(*pathelems):
+ return os.path.join(os.path.join('/', 'emsdk', 'upstream', 'emscripten'), *pathelems)

-sys.path.append(utils.path_from_root('third_party'))
-sys.path.append(utils.path_from_root('third_party/ply'))
+sys.path.append(path_from_root('third_party', 'ply'))

import WebIDL

@@ -50,14 +50,14 @@ class Dummy:
input_file = sys.argv[1]
output_base = sys.argv[2]

-shared.try_delete(output_base + '.cpp')
-shared.try_delete(output_base + '.js')
+try_delete(output_base + '.cpp')
+try_delete(output_base + '.js')

p = WebIDL.Parser()
p.parse(r'''
interface VoidPtr {
};
-''' + utils.read_file(input_file))
+''' + open(input_file).read())
data = p.finish()

interfaces = {}
--
2.35.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
From 2e7bb7592195c94853c4e3b6718d47677e1555bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thiago=20Fran=C3=A7a=20da=20Silva?=
<[email protected]>
Date: Fri, 18 Feb 2022 21:19:20 -0300
Subject: [PATCH 2/4] WebIDL: Implement Integer Pointer type (IntPtr)

This allows compatibility with `changed` parameter of the `renderImage` function
---
build/WebIDL.py | 15 +++++++++++++++
build/webidl_binder.py | 4 ++++
2 files changed, 19 insertions(+)

diff --git a/build/WebIDL.py b/build/WebIDL.py
index 8892616..d140f8f 100644
--- a/build/WebIDL.py
+++ b/build/WebIDL.py
@@ -1,4 +1,6 @@
## JavascriptSubtitlesOctopus
+## Patched to:
+## - add integer pointers (IntPtr)
## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/third_party/WebIDL.py

# from https://hg.mozilla.org/mozilla-central/file/tip/dom/bindings/parser/WebIDL.py
@@ -2165,6 +2167,7 @@ class IDLBuiltinType(IDLType):
'date',
'void',
# Funny stuff
+ 'IntPtr',
'ArrayBuffer',
'ArrayBufferView',
'Int8Array',
@@ -2184,6 +2187,7 @@ class IDLBuiltinType(IDLType):
Types.short: IDLType.Tags.int16,
Types.unsigned_short: IDLType.Tags.uint16,
Types.long: IDLType.Tags.int32,
+ Types.IntPtr: IDLType.Tags.int32,
Types.unsigned_long: IDLType.Tags.uint32,
Types.long_long: IDLType.Tags.int64,
Types.unsigned_long_long: IDLType.Tags.uint64,
@@ -2380,6 +2384,9 @@ BuiltinTypes = {
IDLBuiltinType.Types.any:
IDLBuiltinType(BuiltinLocation("<builtin type>"), "Any",
IDLBuiltinType.Types.any),
+ IDLBuiltinType.Types.IntPtr:
+ IDLBuiltinType(BuiltinLocation("<builtin type>"), "IntPtr",
+ IDLBuiltinType.Types.IntPtr),
IDLBuiltinType.Types.domstring:
IDLBuiltinType(BuiltinLocation("<builtin type>"), "String",
IDLBuiltinType.Types.domstring),
@@ -3622,6 +3629,7 @@ class Tokenizer(object):
"...": "ELLIPSIS",
"::": "SCOPE",
"Date": "DATE",
+ "IntPtr": "INTPTR",
"DOMString": "DOMSTRING",
"ByteString": "BYTESTRING",
"any": "ANY",
@@ -4507,6 +4515,7 @@ class Parser(Tokenizer):
| DATE
| DOMSTRING
| BYTESTRING
+ | INTPTR
| ANY
| ATTRIBUTE
| BOOLEAN
@@ -4573,6 +4582,12 @@ class Parser(Tokenizer):
"""
p[0] = self.handleModifiers(BuiltinTypes[IDLBuiltinType.Types.any], p[2])

+ def p_SingleTypeIntPtrType(self, p):
+ """
+ SingleType : INTPTR TypeSuffixStartingWithArray
+ """
+ p[0] = self.handleModifiers(BuiltinTypes[IDLBuiltinType.Types.IntPtr], p[2])
+
def p_UnionType(self, p):
"""
UnionType : LPAREN UnionMemberType OR UnionMemberType UnionMemberTypes RPAREN
diff --git a/build/webidl_binder.py b/build/webidl_binder.py
index 687a5ba..e9a56e5 100644
--- a/build/webidl_binder.py
+++ b/build/webidl_binder.py
@@ -1,4 +1,6 @@
## JavascriptSubtitlesOctopus
+## Patched to:
+## - add integer pointers (IntPtr)
## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/tools/webidl_binder.py

# Copyright 2014 The Emscripten Authors. All rights reserved.
@@ -337,6 +339,8 @@ def type_to_c(t, non_pointing=False):
ret = 'bool'
elif t == 'Any' or t == 'VoidPtr':
ret = 'void*'
+ elif t == 'IntPtr':
+ ret = 'int*'
elif t in interfaces:
ret = (interfaces[t].getExtendedAttribute('Prefix') or [''])[0] + t + ('' if non_pointing else '*')
else:
--
2.35.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From ea9c45b10d807966510711da723ea1ae558efd45 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thiago=20Fran=C3=A7a=20da=20Silva?=
<[email protected]>
Date: Mon, 14 Feb 2022 22:27:57 -0300
Subject: [PATCH 3/4] WebIDL: Implement ByteString type

This allows compatibility with `bitmap` attribute of the ASS_Image struct
---
build/webidl_binder.py | 3 +++
1 file changed, 3 insertions(+)

diff --git a/build/webidl_binder.py b/build/webidl_binder.py
index e9a56e5..faedf10 100644
--- a/build/webidl_binder.py
+++ b/build/webidl_binder.py
@@ -1,6 +1,7 @@
## JavascriptSubtitlesOctopus
## Patched to:
## - add integer pointers (IntPtr)
+## - implement ByteString type
## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/tools/webidl_binder.py

# Copyright 2014 The Emscripten Authors. All rights reserved.
@@ -327,6 +328,8 @@ def type_to_c(t, non_pointing=False):
ret = 'char'
elif t == 'Octet':
ret = 'unsigned char'
+ elif t == 'ByteString':
+ ret = 'unsigned char*'
elif t == 'Void':
ret = 'void'
elif t == 'String':
--
2.35.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
From 27aa9cd061851ea092516774326150dee2e8385f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thiago=20Fran=C3=A7a=20da=20Silva?=
<[email protected]>
Date: Mon, 14 Feb 2022 22:30:32 -0300
Subject: [PATCH 4/4] WebIDL: Use malloc/strcpy on Struct String setters, fix
#77

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.
---
build/webidl_binder.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/build/webidl_binder.py b/build/webidl_binder.py
index faedf10..a8218e7 100644
--- a/build/webidl_binder.py
+++ b/build/webidl_binder.py
@@ -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.
@@ -723,7 +724,12 @@ for name in names:
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'''
--
2.35.1

0 comments on commit 0797f31

Please sign in to comment.