From 374915ad0c38d8a948d492c6d4a735f320339a63 Mon Sep 17 00:00:00 2001 From: KaruroChori Date: Sun, 15 Dec 2024 10:01:16 +0000 Subject: [PATCH] Rename some internal symbols to avoid collisions --- .gitignore | 1 + cutils.c | 10 +++++----- cutils.h | 8 ++++---- libregexp.c | 2 +- qjs.c | 2 +- qjsc.c | 16 ++++++++-------- quickjs-libc.c | 6 +++--- quickjs.c | 6 +++--- run-test262.c | 10 +++++----- 9 files changed, 31 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 7e0bac32..4ad835cf 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ cmake-* out/ CMakeUserPresets.json fuzz +.vscode/ \ No newline at end of file diff --git a/cutils.c b/cutils.c index b17756b6..9f202e52 100644 --- a/cutils.c +++ b/cutils.c @@ -41,7 +41,7 @@ #pragma GCC visibility push(default) #endif -void pstrcpy(char *buf, int buf_size, const char *str) +void js__pstrcpy(char *buf, int buf_size, const char *str) { int c; char *q = buf; @@ -59,16 +59,16 @@ void pstrcpy(char *buf, int buf_size, const char *str) } /* strcat and truncate. */ -char *pstrcat(char *buf, int buf_size, const char *s) +char *js__pstrcat(char *buf, int buf_size, const char *s) { int len; len = strlen(buf); if (len < buf_size) - pstrcpy(buf + len, buf_size - len, s); + js__pstrcpy(buf + len, buf_size - len, s); return buf; } -int strstart(const char *str, const char *val, const char **ptr) +int js__strstart(const char *str, const char *val, const char **ptr) { const char *p, *q; p = str; @@ -84,7 +84,7 @@ int strstart(const char *str, const char *val, const char **ptr) return 1; } -int has_suffix(const char *str, const char *suffix) +int js__has_suffix(const char *str, const char *suffix) { size_t len = strlen(str); size_t slen = strlen(suffix); diff --git a/cutils.h b/cutils.h index 1e96ed68..4ad3f642 100644 --- a/cutils.h +++ b/cutils.h @@ -133,10 +133,10 @@ enum { }; #endif -void pstrcpy(char *buf, int buf_size, const char *str); -char *pstrcat(char *buf, int buf_size, const char *s); -int strstart(const char *str, const char *val, const char **ptr); -int has_suffix(const char *str, const char *suffix); +void js__pstrcpy(char *buf, int buf_size, const char *str); +char *js__pstrcat(char *buf, int buf_size, const char *s); +int js__strstart(const char *str, const char *val, const char **ptr); +int js__has_suffix(const char *str, const char *suffix); static inline uint8_t is_be(void) { union { diff --git a/libregexp.c b/libregexp.c index 799c8f64..b4b0e0cd 100644 --- a/libregexp.c +++ b/libregexp.c @@ -1821,7 +1821,7 @@ uint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size, error: dbuf_free(&s->byte_code); dbuf_free(&s->group_names); - pstrcpy(error_msg, error_msg_size, s->u.error_msg); + js__pstrcpy(error_msg, error_msg_size, s->u.error_msg); *plen = 0; return NULL; } diff --git a/qjs.c b/qjs.c index ba5fd8f5..8671ffbc 100644 --- a/qjs.c +++ b/qjs.c @@ -146,7 +146,7 @@ static int eval_file(JSContext *ctx, const char *filename, int module) } if (module < 0) { - module = (has_suffix(filename, ".mjs") || + module = (js__has_suffix(filename, ".mjs") || JS_DetectModule((const char *)buf, buf_len)); } if (module) diff --git a/qjsc.c b/qjsc.c index 5e2e8aee..52216cb0 100644 --- a/qjsc.c +++ b/qjsc.c @@ -126,7 +126,7 @@ static void get_c_name(char *buf, size_t buf_size, const char *file) len = strlen(p); else len = r - p; - pstrcpy(buf, buf_size, c_ident_prefix); + js__pstrcpy(buf, buf_size, c_ident_prefix); q = buf + strlen(buf); for(i = 0; i < len; i++) { c = p[i]; @@ -218,7 +218,7 @@ static void find_unique_cname(char *cname, size_t cname_size) break; suffix_num++; } - pstrcpy(cname, cname_size, cname1); + js__pstrcpy(cname, cname_size, cname1); } JSModuleDef *jsc_module_loader(JSContext *ctx, @@ -234,7 +234,7 @@ JSModuleDef *jsc_module_loader(JSContext *ctx, namelist_add(&init_module_list, e->name, e->short_name, 0); /* create a dummy module */ m = JS_NewCModule(ctx, module_name, js_module_dummy_init); - } else if (has_suffix(module_name, ".so")) { + } else if (js__has_suffix(module_name, ".so")) { JS_ThrowReferenceError(ctx, "%s: dynamically linking to shared libraries not supported", module_name); return NULL; @@ -289,7 +289,7 @@ static void compile_file(JSContext *ctx, FILE *fo, } eval_flags = JS_EVAL_FLAG_COMPILE_ONLY; if (module < 0) { - module = (has_suffix(filename, ".mjs") || + module = (js__has_suffix(filename, ".mjs") || JS_DetectModule((const char *)buf, buf_len)); } if (module) @@ -303,7 +303,7 @@ static void compile_file(JSContext *ctx, FILE *fo, } js_free(ctx, buf); if (c_name1) { - pstrcpy(c_name, sizeof(c_name), c_name1); + js__pstrcpy(c_name, sizeof(c_name), c_name1); } else { get_c_name(c_name, sizeof(c_name), filename); } @@ -422,11 +422,11 @@ int main(int argc, char **argv) char *p; char path[1024]; char cname[1024]; - pstrcpy(path, sizeof(path), optarg); + js__pstrcpy(path, sizeof(path), optarg); p = strchr(path, ','); if (p) { *p = '\0'; - pstrcpy(cname, sizeof(cname), p + 1); + js__pstrcpy(cname, sizeof(cname), p + 1); } else { get_c_name(cname, sizeof(cname), path); } @@ -459,7 +459,7 @@ int main(int argc, char **argv) if (!out_filename) out_filename = "out.c"; - pstrcpy(cfilename, sizeof(cfilename), out_filename); + js__pstrcpy(cfilename, sizeof(cfilename), out_filename); if (output_type == OUTPUT_RAW) fo = fopen(cfilename, "wb"); diff --git a/quickjs-libc.c b/quickjs-libc.c index 1567dbcf..24e7a843 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -672,10 +672,10 @@ int js_module_set_import_meta(JSContext *ctx, JSValue func_val, } else #endif { - pstrcat(buf, sizeof(buf), module_name); + js__pstrcat(buf, sizeof(buf), module_name); } } else { - pstrcpy(buf, sizeof(buf), module_name); + js__pstrcpy(buf, sizeof(buf), module_name); } JS_FreeCString(ctx, module_name); @@ -697,7 +697,7 @@ JSModuleDef *js_module_loader(JSContext *ctx, { JSModuleDef *m; - if (has_suffix(module_name, QJS_NATIVE_MODULE_SUFFIX)) { + if (js__has_suffix(module_name, QJS_NATIVE_MODULE_SUFFIX)) { m = js_module_loader_so(ctx, module_name); } else { size_t buf_len; diff --git a/quickjs.c b/quickjs.c index 29beb4b2..cc630ab9 100644 --- a/quickjs.c +++ b/quickjs.c @@ -10497,7 +10497,7 @@ static JSValue js_atof(JSContext *ctx, const char *p, size_t len, } } } else { - if (*p == 'I' && (flags & ATOD_ACCEPT_INFINITY) && strstart(p, "Infinity", &p)) { + if (*p == 'I' && (flags & ATOD_ACCEPT_INFINITY) && js__strstart(p, "Infinity", &p)) { d = INF; if (sign == '-') d = -d; @@ -26496,8 +26496,8 @@ static char *js_default_module_normalize_name(JSContext *ctx, } } if (filename[0] != '\0') - pstrcat(filename, cap, "/"); - pstrcat(filename, cap, r); + js__pstrcat(filename, cap, "/"); + js__pstrcat(filename, cap, r); // printf("normalize: %s %s -> %s\n", base_name, name, filename); return filename; } diff --git a/run-test262.c b/run-test262.c index 66ab8980..1b629e79 100644 --- a/run-test262.c +++ b/run-test262.c @@ -398,7 +398,7 @@ void namelist_free(namelist_t *lp) static int add_test_file(const char *filename) { namelist_t *lp = &test_list; - if (has_suffix(filename, ".js") && !has_suffix(filename, "_FIXTURE.js")) + if (js__has_suffix(filename, ".js") && !js__has_suffix(filename, "_FIXTURE.js")) namelist_add(lp, NULL, filename); return 0; } @@ -472,7 +472,7 @@ static JSValue js_print_262(JSContext *ctx, JSValue this_val, return JS_EXCEPTION; if (!strcmp(str, "Test262:AsyncTestComplete")) { tls->async_done++; - } else if (strstart(str, "Test262:AsyncTestFailure", NULL)) { + } else if (js__strstart(str, "Test262:AsyncTestFailure", NULL)) { tls->async_done = 2; /* force an error */ } if (outfile) { @@ -1062,7 +1062,7 @@ void update_exclude_dirs(void) /* split directpries from exclude_list */ for (count = i = 0; i < ep->count; i++) { name = ep->array[i]; - if (has_suffix(name, "/")) { + if (js__has_suffix(name, "/")) { namelist_add(dp, NULL, name); free(name); } else { @@ -1265,7 +1265,7 @@ char *find_error(const char *filename, int *pline, int is_strict) q++; } /* check strict mode indicator */ - if (!strstart(q, "strict mode: ", &q) != !is_strict) + if (!js__strstart(q, "strict mode: ", &q) != !is_strict) continue; r = q = skip_prefix(q, "unexpected error: "); r += strcspn(r, "\n"); @@ -1486,7 +1486,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len, if (ret == 0) { if (msg && s && (str_equal(s, "expected error") || - strstart(s, "unexpected error type:", NULL) || + js__strstart(s, "unexpected error type:", NULL) || str_equal(s, msg))) { // did not have error yet if (!has_error_line) { longest_match(buf, msg, pos, &pos, pos_line, &error_line);