mirror of
https://github.com/frida/tinycc
synced 2025-02-26 20:24:02 +03:00
tcc.c: fix previous commit "Use CString to concat linker options"
- remove redunant else branch - zero-terminate linker_arg - declare cstr_xxx as PUB_FUNC (which are functions used in tcc.c but not in the libtcc API. Useful for a tcc(.exe) that uses the libtcc.(so/dll)) - while at it, export PUB_FUNCs from dll
This commit is contained in:
parent
214564b1dc
commit
4274c44de7
16
tcc.c
16
tcc.c
@ -283,9 +283,9 @@ static int parse_args(TCCState *s, int argc, char **argv)
|
||||
int was_pthread;
|
||||
|
||||
was_pthread = 0; /* is set if commandline contains -pthread key */
|
||||
|
||||
optind = 1;
|
||||
cstr_new(&linker_arg);
|
||||
|
||||
while (optind < argc) {
|
||||
|
||||
r = argv[optind++];
|
||||
@ -444,12 +444,10 @@ static int parse_args(TCCState *s, int argc, char **argv)
|
||||
s->rdynamic = 1;
|
||||
break;
|
||||
case TCC_OPTION_Wl:
|
||||
if (!linker_arg.data_allocated)
|
||||
cstr_cat(&linker_arg, optarg);
|
||||
else {
|
||||
cstr_ccat(&linker_arg, ',');
|
||||
cstr_cat(&linker_arg, optarg);
|
||||
}
|
||||
if (linker_arg.size)
|
||||
--linker_arg.size, cstr_ccat(&linker_arg, ',');
|
||||
cstr_cat(&linker_arg, optarg);
|
||||
cstr_ccat(&linker_arg, '\0');
|
||||
break;
|
||||
case TCC_OPTION_E:
|
||||
output_type = TCC_OUTPUT_PREPROCESS;
|
||||
@ -471,8 +469,8 @@ static int parse_args(TCCState *s, int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((r = (char *) tcc_set_linker(s, (char *) linker_arg.data, TRUE)))
|
||||
tcc_error("unsupported linker option '%s'", r);
|
||||
if (NULL != (r1 = tcc_set_linker(s, (char *) linker_arg.data, TRUE)))
|
||||
tcc_error("unsupported linker option '%s'", r1);
|
||||
/* fixme: these options could be different on your platform */
|
||||
if (was_pthread && output_type != TCC_OUTPUT_OBJ) {
|
||||
dynarray_add((void ***)&files, &nb_files, "-lpthread");
|
||||
|
12
tcc.h
12
tcc.h
@ -51,6 +51,7 @@
|
||||
#define inp next_inp
|
||||
#ifdef LIBTCC_AS_DLL
|
||||
# define LIBTCCAPI __declspec(dllexport)
|
||||
# define PUB_FUNC LIBTCCAPI
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -989,12 +990,11 @@ PUB_FUNC void tcc_error(const char *fmt, ...);
|
||||
PUB_FUNC void tcc_warning(const char *fmt, ...);
|
||||
|
||||
/* other utilities */
|
||||
ST_INLN void cstr_ccat(CString *cstr, int ch);
|
||||
ST_FUNC void cstr_cat(CString *cstr, const char *str);
|
||||
ST_FUNC void cstr_wccat(CString *cstr, int ch);
|
||||
ST_FUNC void cstr_new(CString *cstr);
|
||||
ST_FUNC void cstr_free(CString *cstr);
|
||||
ST_FUNC void add_char(CString *cstr, int c);
|
||||
PUB_FUNC void cstr_ccat(CString *cstr, int ch);
|
||||
PUB_FUNC void cstr_cat(CString *cstr, const char *str);
|
||||
PUB_FUNC void cstr_wccat(CString *cstr, int ch);
|
||||
PUB_FUNC void cstr_new(CString *cstr);
|
||||
PUB_FUNC void cstr_free(CString *cstr);
|
||||
#define cstr_reset(cstr) cstr_free(cstr)
|
||||
|
||||
ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
|
||||
|
12
tccpp.c
12
tccpp.c
@ -120,7 +120,7 @@ static void cstr_realloc(CString *cstr, int new_size)
|
||||
}
|
||||
|
||||
/* add a byte */
|
||||
ST_INLN void cstr_ccat(CString *cstr, int ch)
|
||||
PUB_FUNC void cstr_ccat(CString *cstr, int ch)
|
||||
{
|
||||
int size;
|
||||
size = cstr->size + 1;
|
||||
@ -130,7 +130,7 @@ ST_INLN void cstr_ccat(CString *cstr, int ch)
|
||||
cstr->size = size;
|
||||
}
|
||||
|
||||
ST_FUNC void cstr_cat(CString *cstr, const char *str)
|
||||
PUB_FUNC void cstr_cat(CString *cstr, const char *str)
|
||||
{
|
||||
int c;
|
||||
for(;;) {
|
||||
@ -143,7 +143,7 @@ ST_FUNC void cstr_cat(CString *cstr, const char *str)
|
||||
}
|
||||
|
||||
/* add a wide char */
|
||||
ST_FUNC void cstr_wccat(CString *cstr, int ch)
|
||||
PUB_FUNC void cstr_wccat(CString *cstr, int ch)
|
||||
{
|
||||
int size;
|
||||
size = cstr->size + sizeof(nwchar_t);
|
||||
@ -153,20 +153,20 @@ ST_FUNC void cstr_wccat(CString *cstr, int ch)
|
||||
cstr->size = size;
|
||||
}
|
||||
|
||||
ST_FUNC void cstr_new(CString *cstr)
|
||||
PUB_FUNC void cstr_new(CString *cstr)
|
||||
{
|
||||
memset(cstr, 0, sizeof(CString));
|
||||
}
|
||||
|
||||
/* free string and reset it to NULL */
|
||||
ST_FUNC void cstr_free(CString *cstr)
|
||||
PUB_FUNC void cstr_free(CString *cstr)
|
||||
{
|
||||
tcc_free(cstr->data_allocated);
|
||||
cstr_new(cstr);
|
||||
}
|
||||
|
||||
/* XXX: unicode ? */
|
||||
ST_FUNC void add_char(CString *cstr, int c)
|
||||
static void add_char(CString *cstr, int c)
|
||||
{
|
||||
if (c == '\'' || c == '\"' || c == '\\') {
|
||||
/* XXX: could be more precise if char or string */
|
||||
|
@ -34,7 +34,7 @@ copy ..\libtcc.h libtcc\libtcc.h
|
||||
tiny_impdef libtcc.dll -o lib/libtcc.def
|
||||
|
||||
:tcc
|
||||
%CC% %target% -DONE_SOURCE ../tcc.c -o tcc.exe -ltcc -Llibtcc
|
||||
%CC% %target% ../tcc.c -o tcc.exe -ltcc -Llibtcc
|
||||
|
||||
:copy_std_includes
|
||||
copy ..\include\*.h include
|
||||
|
Loading…
x
Reference in New Issue
Block a user