Commit 38e57a3
authored
Lua FFI fixes (#657)
* Fix clipboard.get leaking its buffer on every call
clipboard_get returns strndup'd memory but typed it const char *, and
aegisub.internal.ffi's string helper deliberately only frees non-const
char * (const means the native side retains ownership). Type it char *
so the buffer is actually freed.
* Fix leaking the error message when re.compile fails
regex_compile strdups the exception text into the error out-param, but
the moon side read it with ffi.string, which does not free. Use
ffi_util.string, which does.
* Don't let C++ exceptions escape through the FFI boundary in re
boost::regex can throw -- most notably on invalid UTF-8 via the
UTF-8-to-UTF-32 iterators (the crash backtrace in Aegisub#99),
and on regex complexity/backtracking limits -- but only regex_compile
caught anything. An exception unwinding through the LuaJIT interpreter
or JIT frames which called these functions is undefined behavior and
can take down the process.
Catch exceptions in regex_search/regex_match/regex_replace and report
them through a char **err out-param as lfs already does; the moon side
raises them as proper Lua errors.
* Return an error from unicode case conversion on invalid UTF-8
On a bogus conversion the wrapper set the error out-param but then ran
the conversion anyway and returned a result, which the moon side's
error branch never freed. Return null once the error is set; the moon
side already handles a null result plus an error message correctly.
* Check for malloc failure in strndup
Previously OOM meant memcpy through a null pointer. The Lua side
already maps a null return to nil.
* Fix lfs.chdir/mkdir/rmdir/touch always returning nil
The impl functions return a C bool, which LuaJIT's ffi converts to a
Lua boolean, and tonumber(true) is nil -- so these four functions
returned nil, nil on success, indistinguishable from failure to any
caller checking the standard lfs true-or-nil,err convention. Found
because busted's own chdir call refuses to run the automation test
suite against the aegisub lfs.
* Fix swapped error() arguments in lfs.dir
error 2, err raises the number 2 with err as the level; failing to open
a directory should raise the error message.
* Remove the uuid dependency from the lfs tests
It was only used to generate unique names under /tmp, which os.tmpname
does without an external rock (whose API has also drifted: uuid 1.0
refuses to run until an rng is explicitly configured). os.tmpname
creates the file on POSIX, so unlink it and use just the name.
* meson: build aegisub-lua and wire up the automation tests
Builds the standalone Lua host from automation/tests and registers the
busted suite as a meson test when busted is installed through luarocks
for Lua 5.1; nothing has been running these tests since Travis went
away. The suite's fixtures are POSIX-only, so it is only registered on
non-Windows hosts. Run with: meson test --suite automation
* Document that Windows builds require the dynamic CRT
This has been institutional knowledge since the /MT era of the old
Visual Studio build broke automation (2016-2018); write it down where
the next person flipping b_vscrt will find it.
* ci: install busted and run the full test suite
The test step only ran "gtest main" by name, so luajit-52 (and now the
automation suite) never ran in CI. Install busted through luarocks on
Ubuntu and macOS so the automation tests are registered; Windows keeps
skipping them since luarocks has no painless setup there and the meson
gate handles the absence.
* Add test coverage for lfs.dir and invalid UTF-8 handling
lfs.dir had no tests at all; the re specs pin that invalid UTF-8 is
reported as a Lua error, which is the path that previously crashed
(Aegisub#99); the unicode spec pins ICU's substitution
behavior for invalid input. Notably lfs.dir's error branch turns out
to be unreachable: DirectoryIterator swallows construction failures
on every platform and yields an empty iteration instead.
* Fix re.compile raising the module table instead of the error message
real_compile passed the FFI impl module to error() rather than the
message returned from compile, so failed compiles raised a useless
table. The existing invalid-regex test only checked that an error was
raised, so extend it to check the error is actually a string.
* Consolidate the re exception guards into a catch-all wrap helper
Mirror the wrap() idiom lfs.cpp already uses: a single helper with a
catch-all arm, so no exception type can unwind through LuaJIT frames
even if boost throws something not derived from std::exception. Also
check the malloc in regex_search like strndup already does.
* Remove test asserting lfs.dir's silent behavior on unopenable paths
Vanilla lfs errors out from lfs.dir when the directory can't be
opened, and require 'lfs' is transparently redirected to aegisub.lfs,
so the silent empty iteration is a compatibility bug rather than
behavior to enshrine in a test. To be fixed separately.
* ci: pin meson test to our own suites and require the automation suite
Bare meson test also runs the test suites of subproject dependencies
(the uchardet wrap alone adds 111 tests on macOS), so limit it to the
Aegisub project's tests. Since the automation suite is only registered
when the busted probe succeeds at configure time, fail the build if it
silently drops out rather than reporting green without it.1 parent 00a0537 commit 38e57a3
12 files changed
Lines changed: 188 additions & 60 deletions
File tree
- .github/workflows
- automation
- include/aegisub
- tests
- modules
- libaegisub
- include/libaegisub/lua
- lua/modules
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
135 | 139 | | |
136 | 140 | | |
137 | 141 | | |
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
141 | 149 | | |
142 | 150 | | |
143 | 151 | | |
| |||
148 | 156 | | |
149 | 157 | | |
150 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
151 | 166 | | |
152 | 167 | | |
153 | 168 | | |
154 | | - | |
| 169 | + | |
155 | 170 | | |
156 | 171 | | |
157 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 31 | + | |
31 | 32 | | |
32 | | - | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | | - | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
76 | | - | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | | - | |
80 | | - | |
81 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
82 | 83 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
36 | 43 | | |
37 | 44 | | |
38 | 45 | | |
39 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
40 | 49 | | |
41 | 50 | | |
42 | 51 | | |
43 | 52 | | |
44 | 53 | | |
45 | 54 | | |
46 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
47 | 59 | | |
48 | 60 | | |
49 | 61 | | |
50 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
51 | 65 | | |
52 | 66 | | |
53 | 67 | | |
| |||
56 | 70 | | |
57 | 71 | | |
58 | 72 | | |
59 | | - | |
60 | 73 | | |
61 | 74 | | |
62 | 75 | | |
63 | 76 | | |
64 | | - | |
| 77 | + | |
65 | 78 | | |
66 | 79 | | |
67 | 80 | | |
| |||
234 | 247 | | |
235 | 248 | | |
236 | 249 | | |
237 | | - | |
| 250 | + | |
238 | 251 | | |
239 | 252 | | |
240 | 253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| |||
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
47 | | - | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
55 | | - | |
| 58 | + | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
| |||
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
64 | | - | |
| 67 | + | |
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
36 | 41 | | |
37 | 42 | | |
38 | 43 | | |
| |||
326 | 331 | | |
327 | 332 | | |
328 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
55 | 74 | | |
56 | 75 | | |
57 | 76 | | |
| |||
62 | 81 | | |
63 | 82 | | |
64 | 83 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
74 | 96 | | |
75 | 97 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
95 | 119 | | |
96 | 120 | | |
97 | 121 | | |
98 | | - | |
99 | | - | |
| 122 | + | |
| 123 | + | |
100 | 124 | | |
101 | 125 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 126 | + | |
107 | 127 | | |
108 | 128 | | |
109 | 129 | | |
| |||
0 commit comments