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
master
grischka 2012-04-18 18:32:37 +02:00
parent 214564b1dc
commit 4274c44de7
4 changed files with 20 additions and 22 deletions

16
tcc.c
View File

@ -283,9 +283,9 @@ static int parse_args(TCCState *s, int argc, char **argv)
int was_pthread; int was_pthread;
was_pthread = 0; /* is set if commandline contains -pthread key */ was_pthread = 0; /* is set if commandline contains -pthread key */
optind = 1; optind = 1;
cstr_new(&linker_arg); cstr_new(&linker_arg);
while (optind < argc) { while (optind < argc) {
r = argv[optind++]; r = argv[optind++];
@ -444,12 +444,10 @@ static int parse_args(TCCState *s, int argc, char **argv)
s->rdynamic = 1; s->rdynamic = 1;
break; break;
case TCC_OPTION_Wl: case TCC_OPTION_Wl:
if (!linker_arg.data_allocated) if (linker_arg.size)
cstr_cat(&linker_arg, optarg); --linker_arg.size, cstr_ccat(&linker_arg, ',');
else { cstr_cat(&linker_arg, optarg);
cstr_ccat(&linker_arg, ','); cstr_ccat(&linker_arg, '\0');
cstr_cat(&linker_arg, optarg);
}
break; break;
case TCC_OPTION_E: case TCC_OPTION_E:
output_type = TCC_OUTPUT_PREPROCESS; 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))) if (NULL != (r1 = tcc_set_linker(s, (char *) linker_arg.data, TRUE)))
tcc_error("unsupported linker option '%s'", r); tcc_error("unsupported linker option '%s'", r1);
/* fixme: these options could be different on your platform */ /* fixme: these options could be different on your platform */
if (was_pthread && output_type != TCC_OUTPUT_OBJ) { if (was_pthread && output_type != TCC_OUTPUT_OBJ) {
dynarray_add((void ***)&files, &nb_files, "-lpthread"); dynarray_add((void ***)&files, &nb_files, "-lpthread");

12
tcc.h
View File

@ -51,6 +51,7 @@
#define inp next_inp #define inp next_inp
#ifdef LIBTCC_AS_DLL #ifdef LIBTCC_AS_DLL
# define LIBTCCAPI __declspec(dllexport) # define LIBTCCAPI __declspec(dllexport)
# define PUB_FUNC LIBTCCAPI
#endif #endif
#endif #endif
@ -989,12 +990,11 @@ PUB_FUNC void tcc_error(const char *fmt, ...);
PUB_FUNC void tcc_warning(const char *fmt, ...); PUB_FUNC void tcc_warning(const char *fmt, ...);
/* other utilities */ /* other utilities */
ST_INLN void cstr_ccat(CString *cstr, int ch); PUB_FUNC void cstr_ccat(CString *cstr, int ch);
ST_FUNC void cstr_cat(CString *cstr, const char *str); PUB_FUNC void cstr_cat(CString *cstr, const char *str);
ST_FUNC void cstr_wccat(CString *cstr, int ch); PUB_FUNC void cstr_wccat(CString *cstr, int ch);
ST_FUNC void cstr_new(CString *cstr); PUB_FUNC void cstr_new(CString *cstr);
ST_FUNC void cstr_free(CString *cstr); PUB_FUNC void cstr_free(CString *cstr);
ST_FUNC void add_char(CString *cstr, int c);
#define cstr_reset(cstr) cstr_free(cstr) #define cstr_reset(cstr) cstr_free(cstr)
ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags); ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);

12
tccpp.c
View File

@ -120,7 +120,7 @@ static void cstr_realloc(CString *cstr, int new_size)
} }
/* add a byte */ /* add a byte */
ST_INLN void cstr_ccat(CString *cstr, int ch) PUB_FUNC void cstr_ccat(CString *cstr, int ch)
{ {
int size; int size;
size = cstr->size + 1; size = cstr->size + 1;
@ -130,7 +130,7 @@ ST_INLN void cstr_ccat(CString *cstr, int ch)
cstr->size = size; 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; int c;
for(;;) { for(;;) {
@ -143,7 +143,7 @@ ST_FUNC void cstr_cat(CString *cstr, const char *str)
} }
/* add a wide char */ /* add a wide char */
ST_FUNC void cstr_wccat(CString *cstr, int ch) PUB_FUNC void cstr_wccat(CString *cstr, int ch)
{ {
int size; int size;
size = cstr->size + sizeof(nwchar_t); size = cstr->size + sizeof(nwchar_t);
@ -153,20 +153,20 @@ ST_FUNC void cstr_wccat(CString *cstr, int ch)
cstr->size = size; cstr->size = size;
} }
ST_FUNC void cstr_new(CString *cstr) PUB_FUNC void cstr_new(CString *cstr)
{ {
memset(cstr, 0, sizeof(CString)); memset(cstr, 0, sizeof(CString));
} }
/* free string and reset it to NULL */ /* 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); tcc_free(cstr->data_allocated);
cstr_new(cstr); cstr_new(cstr);
} }
/* XXX: unicode ? */ /* XXX: unicode ? */
ST_FUNC void add_char(CString *cstr, int c) static void add_char(CString *cstr, int c)
{ {
if (c == '\'' || c == '\"' || c == '\\') { if (c == '\'' || c == '\"' || c == '\\') {
/* XXX: could be more precise if char or string */ /* XXX: could be more precise if char or string */

View File

@ -34,7 +34,7 @@ copy ..\libtcc.h libtcc\libtcc.h
tiny_impdef libtcc.dll -o lib/libtcc.def tiny_impdef libtcc.dll -o lib/libtcc.def
:tcc :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_std_includes
copy ..\include\*.h include copy ..\include\*.h include