Rename some internal symbols to avoid collisions

This commit is contained in:
KaruroChori 2024-12-15 10:01:16 +00:00 committed by GitHub
parent 7e292050a2
commit 374915ad0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 31 additions and 30 deletions

1
.gitignore vendored
View file

@ -10,3 +10,4 @@ cmake-*
out/ out/
CMakeUserPresets.json CMakeUserPresets.json
fuzz fuzz
.vscode/

View file

@ -41,7 +41,7 @@
#pragma GCC visibility push(default) #pragma GCC visibility push(default)
#endif #endif
void pstrcpy(char *buf, int buf_size, const char *str) void js__pstrcpy(char *buf, int buf_size, const char *str)
{ {
int c; int c;
char *q = buf; char *q = buf;
@ -59,16 +59,16 @@ void pstrcpy(char *buf, int buf_size, const char *str)
} }
/* strcat and truncate. */ /* 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; int len;
len = strlen(buf); len = strlen(buf);
if (len < buf_size) if (len < buf_size)
pstrcpy(buf + len, buf_size - len, s); js__pstrcpy(buf + len, buf_size - len, s);
return buf; 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; const char *p, *q;
p = str; p = str;
@ -84,7 +84,7 @@ int strstart(const char *str, const char *val, const char **ptr)
return 1; 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 len = strlen(str);
size_t slen = strlen(suffix); size_t slen = strlen(suffix);

View file

@ -133,10 +133,10 @@ enum {
}; };
#endif #endif
void pstrcpy(char *buf, int buf_size, const char *str); void js__pstrcpy(char *buf, int buf_size, const char *str);
char *pstrcat(char *buf, int buf_size, const char *s); char *js__pstrcat(char *buf, int buf_size, const char *s);
int strstart(const char *str, const char *val, const char **ptr); int js__strstart(const char *str, const char *val, const char **ptr);
int has_suffix(const char *str, const char *suffix); int js__has_suffix(const char *str, const char *suffix);
static inline uint8_t is_be(void) { static inline uint8_t is_be(void) {
union { union {

View file

@ -1821,7 +1821,7 @@ uint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size,
error: error:
dbuf_free(&s->byte_code); dbuf_free(&s->byte_code);
dbuf_free(&s->group_names); 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; *plen = 0;
return NULL; return NULL;
} }

2
qjs.c
View file

@ -146,7 +146,7 @@ static int eval_file(JSContext *ctx, const char *filename, int module)
} }
if (module < 0) { if (module < 0) {
module = (has_suffix(filename, ".mjs") || module = (js__has_suffix(filename, ".mjs") ||
JS_DetectModule((const char *)buf, buf_len)); JS_DetectModule((const char *)buf, buf_len));
} }
if (module) if (module)

16
qjsc.c
View file

@ -126,7 +126,7 @@ static void get_c_name(char *buf, size_t buf_size, const char *file)
len = strlen(p); len = strlen(p);
else else
len = r - p; len = r - p;
pstrcpy(buf, buf_size, c_ident_prefix); js__pstrcpy(buf, buf_size, c_ident_prefix);
q = buf + strlen(buf); q = buf + strlen(buf);
for(i = 0; i < len; i++) { for(i = 0; i < len; i++) {
c = p[i]; c = p[i];
@ -218,7 +218,7 @@ static void find_unique_cname(char *cname, size_t cname_size)
break; break;
suffix_num++; suffix_num++;
} }
pstrcpy(cname, cname_size, cname1); js__pstrcpy(cname, cname_size, cname1);
} }
JSModuleDef *jsc_module_loader(JSContext *ctx, 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); namelist_add(&init_module_list, e->name, e->short_name, 0);
/* create a dummy module */ /* create a dummy module */
m = JS_NewCModule(ctx, module_name, js_module_dummy_init); 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", JS_ThrowReferenceError(ctx, "%s: dynamically linking to shared libraries not supported",
module_name); module_name);
return NULL; return NULL;
@ -289,7 +289,7 @@ static void compile_file(JSContext *ctx, FILE *fo,
} }
eval_flags = JS_EVAL_FLAG_COMPILE_ONLY; eval_flags = JS_EVAL_FLAG_COMPILE_ONLY;
if (module < 0) { if (module < 0) {
module = (has_suffix(filename, ".mjs") || module = (js__has_suffix(filename, ".mjs") ||
JS_DetectModule((const char *)buf, buf_len)); JS_DetectModule((const char *)buf, buf_len));
} }
if (module) if (module)
@ -303,7 +303,7 @@ static void compile_file(JSContext *ctx, FILE *fo,
} }
js_free(ctx, buf); js_free(ctx, buf);
if (c_name1) { if (c_name1) {
pstrcpy(c_name, sizeof(c_name), c_name1); js__pstrcpy(c_name, sizeof(c_name), c_name1);
} else { } else {
get_c_name(c_name, sizeof(c_name), filename); get_c_name(c_name, sizeof(c_name), filename);
} }
@ -422,11 +422,11 @@ int main(int argc, char **argv)
char *p; char *p;
char path[1024]; char path[1024];
char cname[1024]; char cname[1024];
pstrcpy(path, sizeof(path), optarg); js__pstrcpy(path, sizeof(path), optarg);
p = strchr(path, ','); p = strchr(path, ',');
if (p) { if (p) {
*p = '\0'; *p = '\0';
pstrcpy(cname, sizeof(cname), p + 1); js__pstrcpy(cname, sizeof(cname), p + 1);
} else { } else {
get_c_name(cname, sizeof(cname), path); get_c_name(cname, sizeof(cname), path);
} }
@ -459,7 +459,7 @@ int main(int argc, char **argv)
if (!out_filename) if (!out_filename)
out_filename = "out.c"; out_filename = "out.c";
pstrcpy(cfilename, sizeof(cfilename), out_filename); js__pstrcpy(cfilename, sizeof(cfilename), out_filename);
if (output_type == OUTPUT_RAW) if (output_type == OUTPUT_RAW)
fo = fopen(cfilename, "wb"); fo = fopen(cfilename, "wb");

View file

@ -672,10 +672,10 @@ int js_module_set_import_meta(JSContext *ctx, JSValue func_val,
} else } else
#endif #endif
{ {
pstrcat(buf, sizeof(buf), module_name); js__pstrcat(buf, sizeof(buf), module_name);
} }
} else { } else {
pstrcpy(buf, sizeof(buf), module_name); js__pstrcpy(buf, sizeof(buf), module_name);
} }
JS_FreeCString(ctx, module_name); JS_FreeCString(ctx, module_name);
@ -697,7 +697,7 @@ JSModuleDef *js_module_loader(JSContext *ctx,
{ {
JSModuleDef *m; 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); m = js_module_loader_so(ctx, module_name);
} else { } else {
size_t buf_len; size_t buf_len;

View file

@ -10497,7 +10497,7 @@ static JSValue js_atof(JSContext *ctx, const char *p, size_t len,
} }
} }
} else { } 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; d = INF;
if (sign == '-') if (sign == '-')
d = -d; d = -d;
@ -26496,8 +26496,8 @@ static char *js_default_module_normalize_name(JSContext *ctx,
} }
} }
if (filename[0] != '\0') if (filename[0] != '\0')
pstrcat(filename, cap, "/"); js__pstrcat(filename, cap, "/");
pstrcat(filename, cap, r); js__pstrcat(filename, cap, r);
// printf("normalize: %s %s -> %s\n", base_name, name, filename); // printf("normalize: %s %s -> %s\n", base_name, name, filename);
return filename; return filename;
} }

View file

@ -398,7 +398,7 @@ void namelist_free(namelist_t *lp)
static int add_test_file(const char *filename) static int add_test_file(const char *filename)
{ {
namelist_t *lp = &test_list; 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); namelist_add(lp, NULL, filename);
return 0; return 0;
} }
@ -472,7 +472,7 @@ static JSValue js_print_262(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION; return JS_EXCEPTION;
if (!strcmp(str, "Test262:AsyncTestComplete")) { if (!strcmp(str, "Test262:AsyncTestComplete")) {
tls->async_done++; 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 */ tls->async_done = 2; /* force an error */
} }
if (outfile) { if (outfile) {
@ -1062,7 +1062,7 @@ void update_exclude_dirs(void)
/* split directpries from exclude_list */ /* split directpries from exclude_list */
for (count = i = 0; i < ep->count; i++) { for (count = i = 0; i < ep->count; i++) {
name = ep->array[i]; name = ep->array[i];
if (has_suffix(name, "/")) { if (js__has_suffix(name, "/")) {
namelist_add(dp, NULL, name); namelist_add(dp, NULL, name);
free(name); free(name);
} else { } else {
@ -1265,7 +1265,7 @@ char *find_error(const char *filename, int *pline, int is_strict)
q++; q++;
} }
/* check strict mode indicator */ /* check strict mode indicator */
if (!strstart(q, "strict mode: ", &q) != !is_strict) if (!js__strstart(q, "strict mode: ", &q) != !is_strict)
continue; continue;
r = q = skip_prefix(q, "unexpected error: "); r = q = skip_prefix(q, "unexpected error: ");
r += strcspn(r, "\n"); 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 (ret == 0) {
if (msg && s && if (msg && s &&
(str_equal(s, "expected error") || (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 str_equal(s, msg))) { // did not have error yet
if (!has_error_line) { if (!has_error_line) {
longest_match(buf, msg, pos, &pos, pos_line, &error_line); longest_match(buf, msg, pos, &pos, pos_line, &error_line);