History

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

grischka committed 14 years ago

Commit 4274c441 parent 214564b4 files · +20 −22Browse files

Unified · Split

4 files
  1. tcc.c +7 −9
  2. tcc.h +6 −6
  3. tccpp.c +6 −6
  4. win32/build-tcc.bat +1 −1
tcc.c+7−9
@@ -283,9 +283,9 @@ static int parse_args(TCCState *s, int argc, char **argv) · 282 unmodified lines
283 int was_pthread;283 int was_pthread;
284 284
285 was_pthread = 0; /* is set if commandline contains -pthread key */285 was_pthread = 0; /* is set if commandline contains -pthread key */
286
287 optind = 1;286 optind = 1;
288 cstr_new(&linker_arg);287 cstr_new(&linker_arg);
288
289 while (optind < argc) {289 while (optind < argc) {
290 290
291 r = argv[optind++];291 r = argv[optind++];
@@ -444,12 +444,10 @@ static int parse_args(TCCState *s, int argc, char **argv) · 152 unmodified lines
444 s->rdynamic = 1;444 s->rdynamic = 1;
445 break;445 break;
446 case TCC_OPTION_Wl:446 case TCC_OPTION_Wl:
447 if (!linker_arg.data_allocated)447 if (linker_arg.size)
448 cstr_cat(&linker_arg, optarg);448 --linker_arg.size, cstr_ccat(&linker_arg, ',');
449 else {449 cstr_cat(&linker_arg, optarg);
450 cstr_ccat(&linker_arg, ',');450 cstr_ccat(&linker_arg, '\0');
451 cstr_cat(&linker_arg, optarg);
452 }
453 break;451 break;
454 case TCC_OPTION_E:452 case TCC_OPTION_E:
455 output_type = TCC_OUTPUT_PREPROCESS;453 output_type = TCC_OUTPUT_PREPROCESS;
@@ -471,8 +469,8 @@ static int parse_args(TCCState *s, int argc, char **argv) · 15 unmodified lines
471 }469 }
472 }470 }
473 }471 }
474 if ((r = (char *) tcc_set_linker(s, (char *) linker_arg.data, TRUE)))472 if (NULL != (r1 = tcc_set_linker(s, (char *) linker_arg.data, TRUE)))
475 tcc_error("unsupported linker option '%s'", r);473 tcc_error("unsupported linker option '%s'", r1);
476 /* fixme: these options could be different on your platform */474 /* fixme: these options could be different on your platform */
477 if (was_pthread && output_type != TCC_OUTPUT_OBJ) {475 if (was_pthread && output_type != TCC_OUTPUT_OBJ) {
478 dynarray_add((void ***)&files, &nb_files, "-lpthread");476 dynarray_add((void ***)&files, &nb_files, "-lpthread");
tcc.h+6−6
@@ -51,6 +51,7 @@ · 50 unmodified lines
51#define inp next_inp51#define inp next_inp
52#ifdef LIBTCC_AS_DLL52#ifdef LIBTCC_AS_DLL
53# define LIBTCCAPI __declspec(dllexport)53# define LIBTCCAPI __declspec(dllexport)
54# define PUB_FUNC LIBTCCAPI
54#endif55#endif
55#endif56#endif
56 57
@@ -989,12 +990,11 @@ PUB_FUNC void tcc_error(const char *fmt, ...); · 932 unmodified lines
989PUB_FUNC void tcc_warning(const char *fmt, ...);990PUB_FUNC void tcc_warning(const char *fmt, ...);
990 991
991/* other utilities */992/* other utilities */
992ST_INLN void cstr_ccat(CString *cstr, int ch);993PUB_FUNC void cstr_ccat(CString *cstr, int ch);
993ST_FUNC void cstr_cat(CString *cstr, const char *str);994PUB_FUNC void cstr_cat(CString *cstr, const char *str);
994ST_FUNC void cstr_wccat(CString *cstr, int ch);995PUB_FUNC void cstr_wccat(CString *cstr, int ch);
995ST_FUNC void cstr_new(CString *cstr);996PUB_FUNC void cstr_new(CString *cstr);
996ST_FUNC void cstr_free(CString *cstr);997PUB_FUNC void cstr_free(CString *cstr);
997ST_FUNC void add_char(CString *cstr, int c);
998#define cstr_reset(cstr) cstr_free(cstr)998#define cstr_reset(cstr) cstr_free(cstr)
999 999
1000ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);1000ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
tccpp.c+6−6
@@ -120,7 +120,7 @@ static void cstr_realloc(CString *cstr, int new_size) · 119 unmodified lines
120}120}
121 121
122/* add a byte */122/* add a byte */
123ST_INLN void cstr_ccat(CString *cstr, int ch)123PUB_FUNC void cstr_ccat(CString *cstr, int ch)
124{124{
125 int size;125 int size;
126 size = cstr->size + 1;126 size = cstr->size + 1;
@@ -130,7 +130,7 @@ ST_INLN void cstr_ccat(CString *cstr, int ch) · 3 unmodified lines
130 cstr->size = size;130 cstr->size = size;
131}131}
132 132
133ST_FUNC void cstr_cat(CString *cstr, const char *str)133PUB_FUNC void cstr_cat(CString *cstr, const char *str)
134{134{
135 int c;135 int c;
136 for(;;) {136 for(;;) {
@@ -143,7 +143,7 @@ ST_FUNC void cstr_cat(CString *cstr, const char *str) · 6 unmodified lines
143}143}
144 144
145/* add a wide char */145/* add a wide char */
146ST_FUNC void cstr_wccat(CString *cstr, int ch)146PUB_FUNC void cstr_wccat(CString *cstr, int ch)
147{147{
148 int size;148 int size;
149 size = cstr->size + sizeof(nwchar_t);149 size = cstr->size + sizeof(nwchar_t);
@@ -153,20 +153,20 @@ ST_FUNC void cstr_wccat(CString *cstr, int ch) · 3 unmodified lines
153 cstr->size = size;153 cstr->size = size;
154}154}
155 155
156ST_FUNC void cstr_new(CString *cstr)156PUB_FUNC void cstr_new(CString *cstr)
157{157{
158 memset(cstr, 0, sizeof(CString));158 memset(cstr, 0, sizeof(CString));
159}159}
160 160
161/* free string and reset it to NULL */161/* free string and reset it to NULL */
162ST_FUNC void cstr_free(CString *cstr)162PUB_FUNC void cstr_free(CString *cstr)
163{163{
164 tcc_free(cstr->data_allocated);164 tcc_free(cstr->data_allocated);
165 cstr_new(cstr);165 cstr_new(cstr);
166}166}
167 167
168/* XXX: unicode ? */168/* XXX: unicode ? */
169ST_FUNC void add_char(CString *cstr, int c)169static void add_char(CString *cstr, int c)
170{170{
171 if (c == '\'' || c == '\"' || c == '\\') {171 if (c == '\'' || c == '\"' || c == '\\') {
172 /* XXX: could be more precise if char or string */172 /* XXX: could be more precise if char or string */
win32/build-tcc.bat+1−1
@@ -34,7 +34,7 @@ copy ..\libtcc.h libtcc\libtcc.h · 33 unmodified lines
34tiny_impdef libtcc.dll -o lib/libtcc.def34tiny_impdef libtcc.dll -o lib/libtcc.def
35 35
36:tcc36:tcc
37%CC% %target% -DONE_SOURCE ../tcc.c -o tcc.exe -ltcc -Llibtcc37%CC% %target% ../tcc.c -o tcc.exe -ltcc -Llibtcc
38 38
39:copy_std_includes39:copy_std_includes
40copy ..\include\*.h include40copy ..\include\*.h include

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t