Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit b705967

Browse files
committed
[[ Stubs ]] Use MCLog in generated stubs files
This patch changes the stubs file maker to use `MCLog` instead of `fprintf` to `stderr`. This is mainly helpful on Windows where `stderr` is not sent to the debugger output console. However, on all platforms it has the advantager of including the file name and line number in the output automatically.
1 parent c4ede1d commit b705967

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

util/weak_stub_maker.pl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ sub trim
8787
output "typedef void *handler_t;";
8888
output ;
8989

90+
output "#ifdef _DEBUG";
91+
output "#include <stdint.h>";
92+
output "extern void __MCLog(const char *file, uint32_t line, const char *format, ...);";
93+
output "#define MCLog(...) __MCLog(__FILE__, __LINE__, __VA_ARGS__)";
94+
output "#else";
95+
output "#define MCLog(...) (void) (__VA_ARGS__)";
96+
output "#endif";
97+
9098

9199
# MCSupportLibraryLoad and friends have engine dependency - for example
92100
# when weak linking to the crypto library we rely on revsecurity living
@@ -201,7 +209,7 @@ sub trim
201209
output ;
202210
output " snprintf(error, 65536, \"Failed to load library \\\'%s\\\' (tried %s)\", libname, liblist);";
203211
output " snprintf(command, 65536, \"TITLE=\\\"LiveCode startup error\\\" TEXT=\\\"%s\\\" /bin/sh -c \\\'%s\\\' &\", error, dialog);";
204-
output " fprintf(stderr, \"Fatal: failed to load library \\\'%s\\\' (tried %s)\\n\", libname, liblist);";
212+
output " MCLog( \"Fatal: failed to load library \\\'%s\\\' (tried %s)\\n\", libname, liblist);";
205213
output " int ignored = system(command); (void)ignored;";
206214
output " exit(-1);";
207215
output "}";
@@ -286,7 +294,7 @@ sub generateModule
286294
output " if (!module_load(p_path, &module_$module))";
287295
output " {";
288296
output " #ifdef _DEBUG";
289-
output " fprintf(stderr, \"Unable to load library: %s\\n\", p_path);";
297+
output " MCLog( \"Unable to load library: %s\\n\", p_path);";
290298
output " #endif";
291299
output " goto err;";
292300
output " }";
@@ -302,7 +310,7 @@ sub generateModule
302310
output " if (!module_resolve(module_$module, SYMBOL_PREFIX \"" . symbolName($symbol) . "\", (handler_t *)&" . symbolName($symbol) . "_ptr))";
303311
output "{";
304312
output "#ifdef _DEBUG";
305-
output "fprintf(stderr, \"Unable to load: " . symbolName($symbol) . "\\n\");";
313+
output "MCLog( \"Unable to load: " . symbolName($symbol) . "\\n\");";
306314
output "#endif";
307315
output "goto err; ";
308316
output "}";
@@ -337,7 +345,7 @@ sub generateModule
337345

338346
output "{";
339347
output "#ifdef _DEBUG";
340-
output " fprintf(stderr, \"Warning: could not load library: $unixLibrary\\n\");";
348+
output " MCLog( \"Warning: could not load library: $unixLibrary\\n\");";
341349
output "#endif";
342350
output "return 0;";
343351
output "}";

0 commit comments

Comments
 (0)