Skip to content

Commit

Permalink
Rename some internal symbols to avoid collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
KaruroChori authored Dec 15, 2024
1 parent 7e29205 commit 374915a
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ cmake-*
out/
CMakeUserPresets.json
fuzz
.vscode/
10 changes: 5 additions & 5 deletions cutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions cutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion libregexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion qjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions qjsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions quickjs-libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions run-test262.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 374915a

Please sign in to comment.