From aff1261b08a8e106a0e8ccd7be7499b6bb11a078 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Wed, 1 Dec 2021 20:41:27 +0800 Subject: [PATCH] move NULL check to import side --- scripts/generate_header.sh | 10 +++++++++- src/api/system.c | 1 - 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/generate_header.sh b/scripts/generate_header.sh index 3613de17..8d5da527 100755 --- a/scripts/generate_header.sh +++ b/scripts/generate_header.sh @@ -38,6 +38,11 @@ ptrize() { grep '^LUA' | grep -v "$IGNORE_SYM" | sed -e "s/$sym_regex/static\t\2(*\3)\t(\4);/" } +# create a stub function that warns user when calling it +makestub() { + grep '^LUA' | grep -v "$IGNORE_SYM" | sed -e "s/$sym_regex/static\t\2\t__lite_xl_fallback_\3\t(\4) { fputs(\"warning: \3 is a stub\", stderr); }/" +} + import_sym() { grep '^LUA' | grep -v "$IGNORE_SYM" | sed -e "s/$sym_regex/\tIMPORT_SYMBOL(\3, \2, \4);/" } @@ -55,6 +60,8 @@ decl() { ptrize <<< "$header1" # defines (grep '^#' | grep -v "$IGNORE_SYM") <<< "$header" + # stubs + makestub <<< "$header1" } decl_import() { @@ -93,7 +100,7 @@ generate_header() { decl "$LUA_PATH/lauxlib.h" echo - echo "#define IMPORT_SYMBOL(name, ret, ...) name = (ret (*) (__VA_ARGS__)) symbol(#name)" + echo "#define IMPORT_SYMBOL(name, ret, ...) name = (name = (ret (*) (__VA_ARGS__)) symbol(#name), name == NULL ? &__lite_xl_fallback_##name : name)" echo "static void lite_xl_plugin_init(void *XL) {" echo -e "\tvoid* (*symbol)(const char *) = (void* (*) (const char *)) XL;" @@ -134,3 +141,4 @@ main() { } main "$@" +# create a stub function that warns user when calling it diff --git a/src/api/system.c b/src/api/system.c index f42a46d2..70b5b01c 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -699,7 +699,6 @@ static void* api_require(const char* symbol) { if (strcmp(nodes[i].symbol, symbol) == 0) return nodes[i].address; } - fprintf(stderr, "WARNING: %s is not available\n", symbol); return NULL; }