Skip to content

Commit 0797f31

Browse files
committed
Add webidl_binder patches for future reference
1 parent a8de6c7 commit 0797f31

4 files changed

+272
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
From d9b7e2738213d631810ace5e5f47cc8bc210fa8c Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Thiago=20Fran=C3=A7a=20da=20Silva?=
3+
<tfsthiagobr98@outlook.com>
4+
Date: Fri, 18 Feb 2022 21:18:04 -0300
5+
Subject: [PATCH 1/4] WebIDL: Add headers and make it work under
6+
SubtitlesOctopus project
7+
8+
---
9+
build/WebIDL.py | 3 +++
10+
build/tempfiles.py | 3 +++
11+
build/webidl_binder.py | 20 ++++++++++----------
12+
3 files changed, 16 insertions(+), 10 deletions(-)
13+
14+
diff --git a/build/WebIDL.py b/build/WebIDL.py
15+
index 14689cb..8892616 100644
16+
--- a/build/WebIDL.py
17+
+++ b/build/WebIDL.py
18+
@@ -1,3 +1,6 @@
19+
+## JavascriptSubtitlesOctopus
20+
+## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/third_party/WebIDL.py
21+
+
22+
# from https://hg.mozilla.org/mozilla-central/file/tip/dom/bindings/parser/WebIDL.py
23+
# rev 501baeb3a034
24+
25+
diff --git a/build/tempfiles.py b/build/tempfiles.py
26+
index e1c9dcc..6487516 100644
27+
--- a/build/tempfiles.py
28+
+++ b/build/tempfiles.py
29+
@@ -1,3 +1,6 @@
30+
+## JavascriptSubtitlesOctopus
31+
+## From https://github.com/emscripten-core/emscripten/blob/c834ef7d69ccb4100239eeba0b0f6573fed063bc/tools/tempfiles.py
32+
+
33+
# Copyright 2013 The Emscripten Authors. All rights reserved.
34+
# Emscripten is available under two separate licenses, the MIT license and the
35+
# University of Illinois/NCSA Open Source License. Both these licenses can be
36+
diff --git a/build/webidl_binder.py b/build/webidl_binder.py
37+
index da864f8..687a5ba 100644
38+
--- a/build/webidl_binder.py
39+
+++ b/build/webidl_binder.py
40+
@@ -1,3 +1,6 @@
41+
+## JavascriptSubtitlesOctopus
42+
+## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/tools/webidl_binder.py
43+
+
44+
# Copyright 2014 The Emscripten Authors. All rights reserved.
45+
# Emscripten is available under two separate licenses, the MIT license and the
46+
# University of Illinois/NCSA Open Source License. Both these licenses can be
47+
@@ -10,15 +13,12 @@ https://emscripten.org/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.
48+
49+
import os
50+
import sys
51+
+from tempfiles import try_delete
52+
53+
-__scriptdir__ = os.path.dirname(os.path.abspath(__file__))
54+
-__rootdir__ = os.path.dirname(__scriptdir__)
55+
-sys.path.append(__rootdir__)
56+
-
57+
-from tools import shared, utils
58+
+def path_from_root(*pathelems):
59+
+ return os.path.join(os.path.join('/', 'emsdk', 'upstream', 'emscripten'), *pathelems)
60+
61+
-sys.path.append(utils.path_from_root('third_party'))
62+
-sys.path.append(utils.path_from_root('third_party/ply'))
63+
+sys.path.append(path_from_root('third_party', 'ply'))
64+
65+
import WebIDL
66+
67+
@@ -50,14 +50,14 @@ class Dummy:
68+
input_file = sys.argv[1]
69+
output_base = sys.argv[2]
70+
71+
-shared.try_delete(output_base + '.cpp')
72+
-shared.try_delete(output_base + '.js')
73+
+try_delete(output_base + '.cpp')
74+
+try_delete(output_base + '.js')
75+
76+
p = WebIDL.Parser()
77+
p.parse(r'''
78+
interface VoidPtr {
79+
};
80+
-''' + utils.read_file(input_file))
81+
+''' + open(input_file).read())
82+
data = p.finish()
83+
84+
interfaces = {}
85+
--
86+
2.35.1
87+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
From 2e7bb7592195c94853c4e3b6718d47677e1555bf Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Thiago=20Fran=C3=A7a=20da=20Silva?=
3+
<tfsthiagobr98@outlook.com>
4+
Date: Fri, 18 Feb 2022 21:19:20 -0300
5+
Subject: [PATCH 2/4] WebIDL: Implement Integer Pointer type (IntPtr)
6+
7+
This allows compatibility with `changed` parameter of the `renderImage` function
8+
---
9+
build/WebIDL.py | 15 +++++++++++++++
10+
build/webidl_binder.py | 4 ++++
11+
2 files changed, 19 insertions(+)
12+
13+
diff --git a/build/WebIDL.py b/build/WebIDL.py
14+
index 8892616..d140f8f 100644
15+
--- a/build/WebIDL.py
16+
+++ b/build/WebIDL.py
17+
@@ -1,4 +1,6 @@
18+
## JavascriptSubtitlesOctopus
19+
+## Patched to:
20+
+## - add integer pointers (IntPtr)
21+
## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/third_party/WebIDL.py
22+
23+
# from https://hg.mozilla.org/mozilla-central/file/tip/dom/bindings/parser/WebIDL.py
24+
@@ -2165,6 +2167,7 @@ class IDLBuiltinType(IDLType):
25+
'date',
26+
'void',
27+
# Funny stuff
28+
+ 'IntPtr',
29+
'ArrayBuffer',
30+
'ArrayBufferView',
31+
'Int8Array',
32+
@@ -2184,6 +2187,7 @@ class IDLBuiltinType(IDLType):
33+
Types.short: IDLType.Tags.int16,
34+
Types.unsigned_short: IDLType.Tags.uint16,
35+
Types.long: IDLType.Tags.int32,
36+
+ Types.IntPtr: IDLType.Tags.int32,
37+
Types.unsigned_long: IDLType.Tags.uint32,
38+
Types.long_long: IDLType.Tags.int64,
39+
Types.unsigned_long_long: IDLType.Tags.uint64,
40+
@@ -2380,6 +2384,9 @@ BuiltinTypes = {
41+
IDLBuiltinType.Types.any:
42+
IDLBuiltinType(BuiltinLocation("<builtin type>"), "Any",
43+
IDLBuiltinType.Types.any),
44+
+ IDLBuiltinType.Types.IntPtr:
45+
+ IDLBuiltinType(BuiltinLocation("<builtin type>"), "IntPtr",
46+
+ IDLBuiltinType.Types.IntPtr),
47+
IDLBuiltinType.Types.domstring:
48+
IDLBuiltinType(BuiltinLocation("<builtin type>"), "String",
49+
IDLBuiltinType.Types.domstring),
50+
@@ -3622,6 +3629,7 @@ class Tokenizer(object):
51+
"...": "ELLIPSIS",
52+
"::": "SCOPE",
53+
"Date": "DATE",
54+
+ "IntPtr": "INTPTR",
55+
"DOMString": "DOMSTRING",
56+
"ByteString": "BYTESTRING",
57+
"any": "ANY",
58+
@@ -4507,6 +4515,7 @@ class Parser(Tokenizer):
59+
| DATE
60+
| DOMSTRING
61+
| BYTESTRING
62+
+ | INTPTR
63+
| ANY
64+
| ATTRIBUTE
65+
| BOOLEAN
66+
@@ -4573,6 +4582,12 @@ class Parser(Tokenizer):
67+
"""
68+
p[0] = self.handleModifiers(BuiltinTypes[IDLBuiltinType.Types.any], p[2])
69+
70+
+ def p_SingleTypeIntPtrType(self, p):
71+
+ """
72+
+ SingleType : INTPTR TypeSuffixStartingWithArray
73+
+ """
74+
+ p[0] = self.handleModifiers(BuiltinTypes[IDLBuiltinType.Types.IntPtr], p[2])
75+
+
76+
def p_UnionType(self, p):
77+
"""
78+
UnionType : LPAREN UnionMemberType OR UnionMemberType UnionMemberTypes RPAREN
79+
diff --git a/build/webidl_binder.py b/build/webidl_binder.py
80+
index 687a5ba..e9a56e5 100644
81+
--- a/build/webidl_binder.py
82+
+++ b/build/webidl_binder.py
83+
@@ -1,4 +1,6 @@
84+
## JavascriptSubtitlesOctopus
85+
+## Patched to:
86+
+## - add integer pointers (IntPtr)
87+
## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/tools/webidl_binder.py
88+
89+
# Copyright 2014 The Emscripten Authors. All rights reserved.
90+
@@ -337,6 +339,8 @@ def type_to_c(t, non_pointing=False):
91+
ret = 'bool'
92+
elif t == 'Any' or t == 'VoidPtr':
93+
ret = 'void*'
94+
+ elif t == 'IntPtr':
95+
+ ret = 'int*'
96+
elif t in interfaces:
97+
ret = (interfaces[t].getExtendedAttribute('Prefix') or [''])[0] + t + ('' if non_pointing else '*')
98+
else:
99+
--
100+
2.35.1
101+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
From ea9c45b10d807966510711da723ea1ae558efd45 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Thiago=20Fran=C3=A7a=20da=20Silva?=
3+
<tfsthiagobr98@outlook.com>
4+
Date: Mon, 14 Feb 2022 22:27:57 -0300
5+
Subject: [PATCH 3/4] WebIDL: Implement ByteString type
6+
7+
This allows compatibility with `bitmap` attribute of the ASS_Image struct
8+
---
9+
build/webidl_binder.py | 3 +++
10+
1 file changed, 3 insertions(+)
11+
12+
diff --git a/build/webidl_binder.py b/build/webidl_binder.py
13+
index e9a56e5..faedf10 100644
14+
--- a/build/webidl_binder.py
15+
+++ b/build/webidl_binder.py
16+
@@ -1,6 +1,7 @@
17+
## JavascriptSubtitlesOctopus
18+
## Patched to:
19+
## - add integer pointers (IntPtr)
20+
+## - implement ByteString type
21+
## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/tools/webidl_binder.py
22+
23+
# Copyright 2014 The Emscripten Authors. All rights reserved.
24+
@@ -327,6 +328,8 @@ def type_to_c(t, non_pointing=False):
25+
ret = 'char'
26+
elif t == 'Octet':
27+
ret = 'unsigned char'
28+
+ elif t == 'ByteString':
29+
+ ret = 'unsigned char*'
30+
elif t == 'Void':
31+
ret = 'void'
32+
elif t == 'String':
33+
--
34+
2.35.1
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
From 27aa9cd061851ea092516774326150dee2e8385f Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Thiago=20Fran=C3=A7a=20da=20Silva?=
3+
<tfsthiagobr98@outlook.com>
4+
Date: Mon, 14 Feb 2022 22:30:32 -0300
5+
Subject: [PATCH 4/4] WebIDL: Use malloc/strcpy on Struct String setters, fix
6+
#77
7+
8+
From @TheOneric:
9+
For most libass APIs the char* strings remain owned by the caller with libass doing
10+
internal copies if needed. This means the caller must if necessary free the memory
11+
at some point after the libass API call finished. The track and event modification/creation
12+
APIs are different because they work close to library internals (which is also why their usage
13+
comes with more restrictions/obligations than other APIs and why they don't sensibly work with
14+
ass.h alone).
15+
16+
Since we transfer ownership of the pointer to libass, this is unlikely to cause memory leaks.
17+
---
18+
build/webidl_binder.py | 8 +++++++-
19+
1 file changed, 7 insertions(+), 1 deletion(-)
20+
21+
diff --git a/build/webidl_binder.py b/build/webidl_binder.py
22+
index faedf10..a8218e7 100644
23+
--- a/build/webidl_binder.py
24+
+++ b/build/webidl_binder.py
25+
@@ -2,6 +2,7 @@
26+
## Patched to:
27+
## - add integer pointers (IntPtr)
28+
## - implement ByteString type
29+
+## - fix string setter for structs
30+
## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/tools/webidl_binder.py
31+
32+
# Copyright 2014 The Emscripten Authors. All rights reserved.
33+
@@ -723,7 +724,12 @@ for name in names:
34+
get_sigs = {0: []}
35+
set_sigs = {1: [Dummy({'type': m.type})]}
36+
get_call_content = take_addr_if_nonpointer(m) + 'self->' + attr
37+
- set_call_content = 'self->' + attr + ' = ' + deref_if_nonpointer(m) + 'arg0'
38+
+ if m.type.isDOMString():
39+
+ set_call_content = """char* copy = (char*)malloc(strlen(%s) + 1);
40+
+ strcpy(copy, %s);
41+
+ self->%s = copy""" % (deref_if_nonpointer(m) + 'arg0', deref_if_nonpointer(m) + 'arg0', attr)
42+
+ else:
43+
+ set_call_content = 'self->' + attr + ' = ' + deref_if_nonpointer(m) + 'arg0'
44+
45+
get_name = 'get_' + attr
46+
mid_js += [r'''
47+
--
48+
2.35.1
49+

0 commit comments

Comments
 (0)