From 4274c44de7dfb99a1058a5af515e9865cc9d2ff9 Mon Sep 17 00:00:00 2001 From: grischka Date: Wed, 18 Apr 2012 18:32:37 +0200 Subject: [PATCH] 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 --- tcc.c | 16 +++++++--------- tcc.h | 12 ++++++------ tccpp.c | 12 ++++++------ win32/build-tcc.bat | 2 +- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/tcc.c b/tcc.c index 9f1f7c05..06c61558 100644 --- a/tcc.c +++ b/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"); diff --git a/tcc.h b/tcc.h index cc599127..00fc4bb2 100644 --- a/tcc.h +++ b/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); diff --git a/tccpp.c b/tccpp.c index d1043e0d..f88c030f 100644 --- a/tccpp.c +++ b/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 */ diff --git a/win32/build-tcc.bat b/win32/build-tcc.bat index aceecb72..21bf3a8d 100644 --- a/win32/build-tcc.bat +++ b/win32/build-tcc.bat @@ -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 -- 2.11.4.GIT