Skip to content

Commit 920fa00

Browse files
authored
Improve ATXXX hooks injection. NFC (#24026)
This makes these hooks easy to spot in the generated code.
1 parent 1c332ce commit 920fa00

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
52236
1+
52403
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
27108
1+
27275
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
50453
1+
50557

tools/emscripten.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,25 @@ def update_settings_glue(wasm_file, metadata, base_metadata):
161161

162162

163163
def apply_static_code_hooks(forwarded_json, code):
164-
code = shared.do_replace(code, '<<< ATPRERUNS >>>', str(forwarded_json['ATPRERUNS']))
165-
code = shared.do_replace(code, '<<< ATINITS >>>', str(forwarded_json['ATINITS']))
166-
code = shared.do_replace(code, '<<< ATPOSTCTORS >>>', str(forwarded_json['ATPOSTCTORS']))
164+
def inject_code_hooks(name):
165+
nonlocal code
166+
hook_code = forwarded_json[name]
167+
if hook_code:
168+
hook_code = f'// Begin {name} hooks\n {hook_code}\n // End {name} hooks'
169+
else:
170+
hook_code = f'// No {name} hooks'
171+
code = code.replace(f'<<< {name} >>>', hook_code)
172+
173+
inject_code_hooks('ATPRERUNS')
174+
inject_code_hooks('ATINITS')
175+
inject_code_hooks('ATPOSTCTORS')
167176
if settings.HAS_MAIN:
168-
code = shared.do_replace(code, '<<< ATMAINS >>>', str(forwarded_json['ATMAINS']))
177+
inject_code_hooks('ATMAINS')
169178
if not settings.MINIMAL_RUNTIME or settings.HAS_MAIN:
170-
code = shared.do_replace(code, '<<< ATPOSTRUNS >>>', str(forwarded_json['ATPOSTRUNS']))
179+
inject_code_hooks('ATPOSTRUNS')
171180
if settings.EXIT_RUNTIME:
172-
code = shared.do_replace(code, '<<< ATEXITS >>>', str(forwarded_json['ATEXITS']))
181+
inject_code_hooks('ATEXITS')
182+
173183
return code
174184

175185

0 commit comments

Comments
 (0)