From 55e845c5dd3127880ff62ba26478d9eaf470b7b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 10 Nov 2023 16:35:09 +0100 Subject: [PATCH] Add JS_GetVersion --- CMakeLists.txt | 3 --- Makefile | 2 +- VERSION | 1 - qjs.c | 4 ++-- qjsc.c | 3 ++- quickjs.c | 18 +++++++++++++++--- quickjs.h | 10 ++++++++++ run-test262.c | 5 +++-- 8 files changed, 33 insertions(+), 13 deletions(-) delete mode 100644 VERSION diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fec54e..7c36112 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,9 +53,6 @@ set(qjs_sources list(APPEND qjs_defines _GNU_SOURCE) -file(STRINGS "VERSION" QJS_VERSION_STR) -list(APPEND qjs_defines CONFIG_VERSION="${QJS_VERSION_STR}") - add_library(qjs STATIC ${qjs_sources}) target_compile_definitions(qjs PUBLIC QJS_VERSION_STR="${QJS_VERSION_STR}" diff --git a/Makefile b/Makefile index c2673a5..64ebb27 100644 --- a/Makefile +++ b/Makefile @@ -112,7 +112,7 @@ STRIP=$(CROSS_PREFIX)strip ifdef CONFIG_WERROR CFLAGS+=-Werror endif -DEFINES:=-D_GNU_SOURCE -DCONFIG_VERSION=\"$(shell cat VERSION)\" +DEFINES:=-D_GNU_SOURCE ifdef CONFIG_WIN32 DEFINES+=-D__USE_MINGW_ANSI_STDIO # for standard snprintf behavior endif diff --git a/VERSION b/VERSION deleted file mode 100644 index 22ffec1..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -2021-03-27 diff --git a/qjs.c b/qjs.c index ee6f8b5..66ff4c6 100644 --- a/qjs.c +++ b/qjs.c @@ -269,7 +269,7 @@ static const JSMallocFunctions trace_mf = { void help(void) { - printf("QuickJS version " CONFIG_VERSION "\n" + printf("QuickJS version %s\n" "usage: " PROG_NAME " [options] [file [args]]\n" "-h --help list options\n" "-e --eval EXPR evaluate EXPR\n" @@ -283,7 +283,7 @@ void help(void) " --memory-limit n limit the memory usage to 'n' bytes\n" " --stack-size n limit the stack size to 'n' bytes\n" " --unhandled-rejection dump unhandled promise rejections\n" - "-q --quit just instantiate the interpreter and quit\n"); + "-q --quit just instantiate the interpreter and quit\n", JS_GetVersion()); exit(1); } diff --git a/qjsc.c b/qjsc.c index 381c8ed..19cbc2b 100644 --- a/qjsc.c +++ b/qjsc.c @@ -339,7 +339,7 @@ static const char main_c_template2[] = void help(void) { - printf("QuickJS Compiler version " CONFIG_VERSION "\n" + printf("QuickJS Compiler version %s\n" "usage: " PROG_NAME " [options] [files]\n" "\n" "options are:\n" @@ -353,6 +353,7 @@ void help(void) "-x byte swapped output\n" "-p prefix set the prefix of the generated C names\n" "-S n set the maximum stack size to 'n' bytes (default=%d)\n", + JS_GetVersion(), JS_DEFAULT_STACK_SIZE); #ifdef CONFIG_LTO { diff --git a/quickjs.c b/quickjs.c index da7f60a..88eff06 100644 --- a/quickjs.c +++ b/quickjs.c @@ -107,6 +107,19 @@ #include #endif +#define STRINGIFY_(x) #x +#define STRINGIFY(x) STRINGIFY_(x) + +#define QJS_VERSION_STRING \ + STRINGIFY(QJS_VERSION_MAJOR) "." STRINGIFY(QJS_VERSION_MINOR) "." STRINGIFY(QJS_VERSION_PATCH) QJS_VERSION_SUFFIX + +const char* JS_GetVersion(void) { + return QJS_VERSION_STRING; +} + +#undef STRINFIGY_ +#undef STRINGIFY + enum { /* classid tag */ /* union usage | properties */ JS_CLASS_OBJECT = 1, /* must be first */ @@ -5920,9 +5933,8 @@ void JS_ComputeMemoryUsage(JSRuntime *rt, JSMemoryUsage *s) void JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt) { - fprintf(fp, "QuickJS memory usage -- " - CONFIG_VERSION " version, %d-bit, malloc limit: %"PRId64"\n\n", - (int)sizeof(void *) * 8, (int64_t)(ssize_t)s->malloc_limit); + fprintf(fp, "QuickJS memory usage -- %s version, %d-bit, malloc limit: %"PRId64"\n\n", + JS_GetVersion(), (int)sizeof(void *) * 8, (int64_t)(ssize_t)s->malloc_limit); #if 1 if (rt) { static const struct { diff --git a/quickjs.h b/quickjs.h index 1617f8b..86f2f95 100644 --- a/quickjs.h +++ b/quickjs.h @@ -1009,6 +1009,16 @@ typedef enum JSPromiseStateEnum { JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValue promise); JSValue JS_PromiseResult(JSContext *ctx, JSValue promise); +/* Version */ + +#define QJS_VERSION_MAJOR 0 +#define QJS_VERSION_MINOR 1 +#define QJS_VERSION_PATCH 0 +#define QJS_VERSION_SUFFIX "" + +const char* JS_GetVersion(void); + + #undef js_unlikely #undef js_force_inline diff --git a/run-test262.c b/run-test262.c index 4061376..cbac594 100644 --- a/run-test262.c +++ b/run-test262.c @@ -1945,7 +1945,7 @@ void run_test_dir_list(namelist_t *lp, int start_index, int stop_index) void help(void) { - printf("run-test262 version " CONFIG_VERSION "\n" + printf("run-test262 version %s\n" "usage: run-test262 [options] {-f file ... | [dir_list] [index range]}\n" "-h help\n" "-a run tests in strict and nostrict modes\n" @@ -1962,7 +1962,8 @@ void help(void) "-e file load the known errors from 'file'\n" "-f file execute single test from 'file'\n" "-r file set the report file name (default=none)\n" - "-x file exclude tests listed in 'file'\n"); + "-x file exclude tests listed in 'file'\n", + JS_GetVersion()); exit(1); }