This allows passing colon separated paths to tcc_add_library_path tcc_add_sysinclude_path tcc_add_include_path Also there are new configure variables CONFIG_TCC_LIBPATH CONFIG_TCC_SYSINCLUDE_PATHS which define the lib/sysinclude paths all in one and can be overridden from configure/make For TCC_TARGET_PE semicolons (;) are used as separators Also, \b in the path string is replaced by s->tcc_lib_path (CONFIG_TCCDIR rsp. -B option)
Unified · Split
| @@ -159,10 +159,15 @@ tcc$(EXESUF): tcc.o $(LIBTCC) · 158 unmodified lines | |||
| 159 | %-tcc$(EXESUF): | 159 | %-tcc$(EXESUF): |
| 160 | $(CC) -o $@ tcc.c -DONE_SOURCE $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS) | 160 | $(CC) -o $@ tcc.c -DONE_SOURCE $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS) |
| 161 | 161 | ||
| 162 | $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 -DCONFIG_TCCDIR="\"$(tccdir)/i386\"" | 162 | $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \ |
| 163 | -DCONFIG_TCCDIR="\"$(tccdir)/i386\"" | ||
| 163 | $(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64 | 164 | $(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64 |
| 164 | $(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" -DCONFIG_TCC_CROSSLIB="\"lib/32\"" | 165 | $(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \ |
| 165 | $(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" -DCONFIG_TCC_CROSSLIB="\"lib/64\"" | 166 | -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \ |
| 167 | -DCONFIG_TCC_LIBPATH="\"\b/lib/32;\b/lib\"" | ||
| 168 | $(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \ | ||
| 169 | -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \ | ||
| 170 | -DCONFIG_TCC_LIBPATH="\"\b/lib/64;\b/lib\"" | ||
| 166 | $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE | 171 | $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE |
| 167 | $(C67_CROSS): DEFINES = -DTCC_TARGET_C67 | 172 | $(C67_CROSS): DEFINES = -DTCC_TARGET_C67 |
| 168 | $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM | 173 | $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM |
| @@ -111,6 +111,13 @@ static void tcc_set_lib_path_w32(TCCState *s) · 110 unmodified lines | |||
| 111 | tcc_set_lib_path(s, path); | 111 | tcc_set_lib_path(s, path); |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | static void tcc_add_systemdir(TCCState *s) | ||
| 115 | { | ||
| 116 | char buf[1000]; | ||
| 117 | GetSystemDirectory(buf, sizeof buf); | ||
| 118 | tcc_add_library_path(s, buf); | ||
| 119 | } | ||
| 120 | |||
| 114 | #ifndef CONFIG_TCC_STATIC | 121 | #ifndef CONFIG_TCC_STATIC |
| 115 | void dlclose(void *p) | 122 | void dlclose(void *p) |
| 116 | { | 123 | { |
| @@ -159,11 +166,18 @@ PUB_FUNC char *pstrcat(char *buf, int buf_size, const char *s) · 42 unmodified lines | |||
| 159 | return buf; | 166 | return buf; |
| 160 | } | 167 | } |
| 161 | 168 | ||
| 169 | PUB_FUNC char *pstrncpy(char *out, const char *in, size_t num) | ||
| 170 | { | ||
| 171 | memcpy(out, in, num); | ||
| 172 | out[num] = '\0'; | ||
| 173 | return out; | ||
| 174 | } | ||
| 175 | |||
| 162 | /* extract the basename of a file */ | 176 | /* extract the basename of a file */ |
| 163 | PUB_FUNC char *tcc_basename(const char *name) | 177 | PUB_FUNC char *tcc_basename(const char *name) |
| 164 | { | 178 | { |
| 165 | char *p = strchr(name, 0); | 179 | char *p = strchr(name, 0); |
| 166 | while (p > name && !IS_PATHSEP(p[-1])) | 180 | while (p > name && !IS_DIRSEP(p[-1])) |
| 167 | --p; | 181 | --p; |
| 168 | return p; | 182 | return p; |
| 169 | } | 183 | } |
| @@ -293,39 +307,37 @@ PUB_FUNC void dynarray_reset(void *pp, int *n) · 123 unmodified lines | |||
| 293 | } | 307 | } |
| 294 | 308 | ||
| 295 | /* out must not point to a valid dynarray since a new one is created */ | 309 | /* out must not point to a valid dynarray since a new one is created */ |
| 296 | PUB_FUNC int tcc_split_path(const char *in, const char * const *prefixs, | 310 | static void tcc_split_path(TCCState *s, void ***p_ary, int *p_nb_ary, const char *in) |
| 297 | int nb_prefixs, char ***out) | ||
| 298 | { | 311 | { |
| 299 | int i, nb_comps = 0; | 312 | const char *p; |
| 300 | char *path; | ||
| 301 | const char *end; | ||
| 302 | size_t size; | ||
| 303 | |||
| 304 | *out = NULL; | ||
| 305 | do { | 313 | do { |
| 306 | end = in; | 314 | const char *r = NULL; |
| 307 | while (*end && *end != ':') | 315 | int c; |
| 308 | ++end; | 316 | CString str; |
| 309 | for (i = 0; i < nb_prefixs; i++) { | 317 | |
| 310 | size = (strlen(prefixs[i]) + 1) * sizeof(char) | 318 | cstr_new(&str); |
| 311 | + (end - in); | 319 | for (p = in;;) { |
| 312 | path = tcc_malloc(size); | 320 | if (r) { |
| 313 | pstrcpy(path, size, prefixs[i]); | 321 | if ((c = *r++) == 0) { |
| 314 | pstrcat(path, size, in); | 322 | r = NULL; |
| 315 | dynarray_add((void ***) out, &nb_comps, path); | 323 | continue; |
| 324 | } | ||
| 325 | } else if ((c = *p++) == 0) { | ||
| 326 | ; | ||
| 327 | } else if (c == PATHSEP) { | ||
| 328 | c = 0; | ||
| 329 | } else if (c == '\b') { | ||
| 330 | r = s->tcc_lib_path; | ||
| 331 | continue; | ||
| 332 | } | ||
| 333 | cstr_ccat(&str, c); | ||
| 334 | if (0 == c) | ||
| 335 | break; | ||
| 316 | } | 336 | } |
| 317 | in = end + 1; | 337 | //printf("path: %s\n", (char*)str.data); |
| 318 | } while (*end); | 338 | dynarray_add(p_ary, p_nb_ary, str.data); |
| 319 | return nb_comps; | 339 | in = p; |
| 320 | } | 340 | } while (p[-1]); |
| 321 | |||
| 322 | /* we use our own 'finite' function to avoid potential problems with | ||
| 323 | non standard math libs */ | ||
| 324 | /* XXX: endianness dependent */ | ||
| 325 | ST_FUNC int ieee_finite(double d) | ||
| 326 | { | ||
| 327 | int *p = (int *)&d; | ||
| 328 | return ((unsigned)((p[1] | 0x800fffff) + 1)) >> 31; | ||
| 329 | } | 341 | } |
| 330 | 342 | ||
| 331 | /********************************************************/ | 343 | /********************************************************/ |
| @@ -994,27 +1006,7 @@ LIBTCCAPI TCCState *tcc_new(void) · 662 unmodified lines | |||
| 994 | 1006 | ||
| 995 | #ifndef TCC_TARGET_PE | 1007 | #ifndef TCC_TARGET_PE |
| 996 | /* default library paths */ | 1008 | /* default library paths */ |
| 997 | tcc_add_library_path(s, CONFIG_TCC_CRT_PREFIX); | 1009 | tcc_add_library_path(s, CONFIG_TCC_LIBPATH); |
| 998 | tcc_add_library_path(s, CONFIG_SYSROOT CONFIG_TCC_LDDIR); | ||
| 999 | tcc_add_library_path(s, CONFIG_SYSROOT "/usr/local"CONFIG_TCC_LDDIR); | ||
| 1000 | #ifdef CONFIG_TCC_EXTRA_LDDIR | ||
| 1001 | { | ||
| 1002 | int i, nb_extra_lddirs, nb_prefixs; | ||
| 1003 | char **extra_lddirs; | ||
| 1004 | char extra_lddir_str[] = CONFIG_TCC_EXTRA_LDDIR; | ||
| 1005 | const char lddir_prefix1[] = CONFIG_SYSROOT; | ||
| 1006 | const char lddir_prefix2[] = CONFIG_SYSROOT "/usr/local"; | ||
| 1007 | const char * const lddir_prefixs[] = {lddir_prefix1, lddir_prefix2}; | ||
| 1008 | |||
| 1009 | nb_prefixs = sizeof lddir_prefixs / sizeof *lddir_prefixs; | ||
| 1010 | nb_extra_lddirs = tcc_split_path(CONFIG_TCC_EXTRA_LDDIR, | ||
| 1011 | lddir_prefixs, nb_prefixs, | ||
| 1012 | &extra_lddirs); | ||
| 1013 | for (i = 0; i < nb_extra_lddirs; i++) | ||
| 1014 | tcc_add_library_path(s, extra_lddirs[i]); | ||
| 1015 | dynarray_reset(&extra_lddirs, &nb_extra_lddirs); | ||
| 1016 | } | ||
| 1017 | #endif | ||
| 1018 | #endif | 1010 | #endif |
| 1019 | 1011 | ||
| 1020 | /* no section zero */ | 1012 | /* no section zero */ |
| @@ -1101,21 +1093,15 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 80 unmodified lines | |||
| 1101 | tcc_free(s1); | 1093 | tcc_free(s1); |
| 1102 | } | 1094 | } |
| 1103 | 1095 | ||
| 1104 | LIBTCCAPI int tcc_add_include_path(TCCState *s1, const char *pathname) | 1096 | LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname) |
| 1105 | { | 1097 | { |
| 1106 | char *pathname1; | 1098 | tcc_split_path(s, (void ***)&s->include_paths, &s->nb_include_paths, pathname); |
| 1107 | |||
| 1108 | pathname1 = tcc_strdup(pathname); | ||
| 1109 | dynarray_add((void ***)&s1->include_paths, &s1->nb_include_paths, pathname1); | ||
| 1110 | return 0; | 1099 | return 0; |
| 1111 | } | 1100 | } |
| 1112 | 1101 | ||
| 1113 | LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s1, const char *pathname) | 1102 | LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname) |
| 1114 | { | 1103 | { |
| 1115 | char *pathname1; | 1104 | tcc_split_path(s, (void ***)&s->sysinclude_paths, &s->nb_sysinclude_paths, pathname); |
| 1116 | |||
| 1117 | pathname1 = tcc_strdup(pathname); | ||
| 1118 | dynarray_add((void ***)&s1->sysinclude_paths, &s1->nb_sysinclude_paths, pathname1); | ||
| 1119 | return 0; | 1105 | return 0; |
| 1120 | } | 1106 | } |
| 1121 | 1107 | ||
| @@ -1252,10 +1238,7 @@ LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename) · 130 unmodified lines | |||
| 1252 | 1238 | ||
| 1253 | LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname) | 1239 | LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname) |
| 1254 | { | 1240 | { |
| 1255 | char *pathname1; | 1241 | tcc_split_path(s, (void ***)&s->library_paths, &s->nb_library_paths, pathname); |
| 1256 | |||
| 1257 | pathname1 = tcc_strdup(pathname); | ||
| 1258 | dynarray_add((void ***)&s->library_paths, &s->nb_library_paths, pathname1); | ||
| 1259 | return 0; | 1242 | return 0; |
| 1260 | } | 1243 | } |
| 1261 | 1244 | ||
| @@ -1318,37 +1301,12 @@ LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val) · 56 unmodified lines | |||
| 1318 | 1301 | ||
| 1319 | LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) | 1302 | LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) |
| 1320 | { | 1303 | { |
| 1321 | char buf[1024]; | ||
| 1322 | |||
| 1323 | s->output_type = output_type; | 1304 | s->output_type = output_type; |
| 1324 | 1305 | ||
| 1325 | if (!s->nostdinc) { | 1306 | if (!s->nostdinc) { |
| 1326 | /* default include paths */ | 1307 | /* default include paths */ |
| 1327 | /* -isystem paths have already been handled */ | 1308 | /* -isystem paths have already been handled */ |
| 1328 | #ifndef TCC_TARGET_PE | 1309 | tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDE_PATHS); |
| 1329 | { | ||
| 1330 | int i, nb_extra_incdirs, nb_prefixs; | ||
| 1331 | char **extra_incdirs; | ||
| 1332 | const char incdir_prefix1[] = CONFIG_SYSROOT "/usr/local/include"; | ||
| 1333 | const char incdir_prefix2[] = CONFIG_SYSROOT "/usr/include"; | ||
| 1334 | const char * const incdir_prefixs[] = {incdir_prefix1, | ||
| 1335 | incdir_prefix2}; | ||
| 1336 | |||
| 1337 | nb_prefixs = sizeof incdir_prefixs / sizeof *incdir_prefixs; | ||
| 1338 | nb_extra_incdirs = tcc_split_path(CONFIG_TCC_INCSUBDIR, | ||
| 1339 | incdir_prefixs, nb_prefixs, | ||
| 1340 | &extra_incdirs); | ||
| 1341 | for (i = 0; i < nb_extra_incdirs; i++) | ||
| 1342 | tcc_add_sysinclude_path(s, extra_incdirs[i]); | ||
| 1343 | dynarray_reset(&extra_incdirs, &nb_extra_incdirs); | ||
| 1344 | } | ||
| 1345 | #endif | ||
| 1346 | snprintf(buf, sizeof(buf), "%s/include", s->tcc_lib_path); | ||
| 1347 | tcc_add_sysinclude_path(s, buf); | ||
| 1348 | #ifdef TCC_TARGET_PE | ||
| 1349 | snprintf(buf, sizeof(buf), "%s/include/winapi", s->tcc_lib_path); | ||
| 1350 | tcc_add_sysinclude_path(s, buf); | ||
| 1351 | #endif | ||
| 1352 | } | 1310 | } |
| 1353 | 1311 | ||
| 1354 | /* if bound checking, then add corresponding sections */ | 1312 | /* if bound checking, then add corresponding sections */ |
| @@ -1381,7 +1339,12 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 26 unmodified lines | |||
| 1381 | } | 1339 | } |
| 1382 | 1340 | ||
| 1383 | /* add libc crt1/crti objects */ | 1341 | /* add libc crt1/crti objects */ |
| 1384 | #ifndef TCC_TARGET_PE | 1342 | #ifdef TCC_TARGET_PE |
| 1343 | tcc_add_library_path(s, CONFIG_TCC_LIBPATH); | ||
| 1344 | # ifdef _WIN32 | ||
| 1345 | tcc_add_systemdir(s); | ||
| 1346 | # endif | ||
| 1347 | #else | ||
| 1385 | if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) && | 1348 | if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) && |
| 1386 | !s->nostdlib) { | 1349 | !s->nostdlib) { |
| 1387 | if (output_type != TCC_OUTPUT_DLL) | 1350 | if (output_type != TCC_OUTPUT_DLL) |
| @@ -1389,20 +1352,6 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 1 unmodified line | |||
| 1389 | tcc_add_file(s, CONFIG_TCC_CRT_PREFIX "/crti.o"); | 1352 | tcc_add_file(s, CONFIG_TCC_CRT_PREFIX "/crti.o"); |
| 1390 | } | 1353 | } |
| 1391 | #endif | 1354 | #endif |
| 1392 | |||
| 1393 | #ifdef TCC_TARGET_PE | ||
| 1394 | #ifdef CONFIG_TCC_CROSSLIB | ||
| 1395 | snprintf(buf, sizeof(buf), "%s/" CONFIG_TCC_CROSSLIB, s->tcc_lib_path); | ||
| 1396 | tcc_add_library_path(s, buf); | ||
| 1397 | #endif | ||
| 1398 | snprintf(buf, sizeof(buf), "%s/lib", s->tcc_lib_path); | ||
| 1399 | tcc_add_library_path(s, buf); | ||
| 1400 | #ifdef _WIN32 | ||
| 1401 | if (GetSystemDirectory(buf, sizeof buf)) | ||
| 1402 | tcc_add_library_path(s, buf); | ||
| 1403 | #endif | ||
| 1404 | #endif | ||
| 1405 | |||
| 1406 | return 0; | 1355 | return 0; |
| 1407 | } | 1356 | } |
| 1408 | 1357 | ||
| @@ -139,9 +139,6 @@ · 138 unmodified lines | |||
| 139 | #define true 1 | 139 | #define true 1 |
| 140 | typedef int BOOL; | 140 | typedef int BOOL; |
| 141 | 141 | ||
| 142 | /* path to find crt1.o, crti.o and crtn.o. Only needed when generating | ||
| 143 | executables or dlls */ | ||
| 144 | |||
| 145 | #ifndef CONFIG_TCC_LDDIR | 142 | #ifndef CONFIG_TCC_LDDIR |
| 146 | #if defined(TCC_TARGET_X86_64_CENTOS) | 143 | #if defined(TCC_TARGET_X86_64_CENTOS) |
| 147 | #define CONFIG_TCC_LDDIR "/lib64" | 144 | #define CONFIG_TCC_LDDIR "/lib64" |
| @@ -149,9 +146,29 @@ typedef int BOOL; · 1 unmodified line | |||
| 149 | #define CONFIG_TCC_LDDIR "/lib" | 146 | #define CONFIG_TCC_LDDIR "/lib" |
| 150 | #endif | 147 | #endif |
| 151 | #endif | 148 | #endif |
| 152 | #define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr" CONFIG_TCC_LDDIR | 149 | |
| 153 | #ifndef CONFIG_TCC_INCSUBDIR | 150 | /* path to find crt1.o, crti.o and crtn.o */ |
| 154 | #define CONFIG_TCC_INCSUBDIR "" | 151 | #ifndef CONFIG_TCC_CRT_PREFIX |
| 152 | # define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr" CONFIG_TCC_LDDIR | ||
| 153 | #endif | ||
| 154 | |||
| 155 | #ifndef CONFIG_TCC_SYSINCLUDE_PATHS | ||
| 156 | # ifdef TCC_TARGET_PE | ||
| 157 | # define CONFIG_TCC_SYSINCLUDE_PATHS "\b/include;\b/include/winapi" | ||
| 158 | # else | ||
| 159 | # define CONFIG_TCC_SYSINCLUDE_PATHS "/usr/local/include:/usr/include:\b/include" | ||
| 160 | # endif | ||
| 161 | #endif | ||
| 162 | |||
| 163 | #ifndef CONFIG_TCC_LIBPATH | ||
| 164 | # ifdef TCC_TARGET_PE | ||
| 165 | # define CONFIG_TCC_LIBPATH "\b/lib" | ||
| 166 | # else | ||
| 167 | # define CONFIG_TCC_LIBPATH \ | ||
| 168 | CONFIG_TCC_CRT_PREFIX \ | ||
| 169 | ":" CONFIG_SYSROOT CONFIG_TCC_LDDIR \ | ||
| 170 | ":" CONFIG_SYSROOT "/usr/local" CONFIG_TCC_LDDIR | ||
| 171 | # endif | ||
| 155 | #endif | 172 | #endif |
| 156 | 173 | ||
| 157 | #define INCLUDE_STACK_SIZE 32 | 174 | #define INCLUDE_STACK_SIZE 32 |
| @@ -843,15 +860,21 @@ extern long double strtold (const char *__nptr, char **__endptr); · 685 unmodified lines | |||
| 843 | #endif | 860 | #endif |
| 844 | 861 | ||
| 845 | #ifdef _WIN32 | 862 | #ifdef _WIN32 |
| 846 | #define IS_PATHSEP(c) (c == '/' || c == '\\') | 863 | #define IS_DIRSEP(c) (c == '/' || c == '\\') |
| 847 | #define IS_ABSPATH(p) (IS_PATHSEP(p[0]) || (p[0] && p[1] == ':' && IS_PATHSEP(p[2]))) | 864 | #define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2]))) |
| 848 | #define PATHCMP stricmp | 865 | #define PATHCMP stricmp |
| 849 | #else | 866 | #else |
| 850 | #define IS_PATHSEP(c) (c == '/') | 867 | #define IS_DIRSEP(c) (c == '/') |
| 851 | #define IS_ABSPATH(p) IS_PATHSEP(p[0]) | 868 | #define IS_ABSPATH(p) IS_DIRSEP(p[0]) |
| 852 | #define PATHCMP strcmp | 869 | #define PATHCMP strcmp |
| 853 | #endif | 870 | #endif |
| 854 | 871 | ||
| 872 | #ifdef TCC_TARGET_PE | ||
| 873 | #define PATHSEP ';' | ||
| 874 | #else | ||
| 875 | #define PATHSEP ':' | ||
| 876 | #endif | ||
| 877 | |||
| 855 | /* space exlcuding newline */ | 878 | /* space exlcuding newline */ |
| 856 | static inline int is_space(int ch) | 879 | static inline int is_space(int ch) |
| 857 | { | 880 | { |
| @@ -912,6 +935,7 @@ ST_DATA void *rt_prog_main; · 54 unmodified lines | |||
| 912 | /* public functions currently used by the tcc main function */ | 935 | /* public functions currently used by the tcc main function */ |
| 913 | PUB_FUNC char *pstrcpy(char *buf, int buf_size, const char *s); | 936 | PUB_FUNC char *pstrcpy(char *buf, int buf_size, const char *s); |
| 914 | PUB_FUNC char *pstrcat(char *buf, int buf_size, const char *s); | 937 | PUB_FUNC char *pstrcat(char *buf, int buf_size, const char *s); |
| 938 | PUB_FUNC char *pstrncpy(char *out, const char *in, size_t num); | ||
| 915 | PUB_FUNC char *tcc_basename(const char *name); | 939 | PUB_FUNC char *tcc_basename(const char *name); |
| 916 | PUB_FUNC char *tcc_fileextension (const char *name); | 940 | PUB_FUNC char *tcc_fileextension (const char *name); |
| 917 | PUB_FUNC void tcc_free(void *ptr); | 941 | PUB_FUNC void tcc_free(void *ptr); |
| @@ -970,8 +994,6 @@ PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value); · 52 unmodified lines | |||
| 970 | PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time); | 994 | PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time); |
| 971 | PUB_FUNC void set_num_callers(int n); | 995 | PUB_FUNC void set_num_callers(int n); |
| 972 | 996 | ||
| 973 | ST_FUNC int ieee_finite(double d); | ||
| 974 | |||
| 975 | /* ------------ tccpp.c ------------ */ | 997 | /* ------------ tccpp.c ------------ */ |
| 976 | 998 | ||
| 977 | ST_DATA struct BufferedFile *file; | 999 | ST_DATA struct BufferedFile *file; |
| @@ -1066,6 +1088,7 @@ ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc · 88 unmodified lines | |||
| 1066 | ST_DATA char *funcname; | 1088 | ST_DATA char *funcname; |
| 1067 | 1089 | ||
| 1068 | ST_INLN int is_float(int t); | 1090 | ST_INLN int is_float(int t); |
| 1091 | ST_FUNC int ieee_finite(double d); | ||
| 1069 | ST_FUNC void test_lvalue(void); | 1092 | ST_FUNC void test_lvalue(void); |
| 1070 | ST_FUNC void swap(int *p, int *q); | 1093 | ST_FUNC void swap(int *p, int *q); |
| 1071 | ST_FUNC void vpushi(int v); | 1094 | ST_FUNC void vpushi(int v); |
| @@ -2857,13 +2857,6 @@ static int ld_next(TCCState *s1, char *name, int name_size) · 2856 unmodified lines | |||
| 2857 | return c; | 2857 | return c; |
| 2858 | } | 2858 | } |
| 2859 | 2859 | ||
| 2860 | char *tcc_strcpy_part(char *out, const char *in, size_t num) | ||
| 2861 | { | ||
| 2862 | memcpy(out, in, num); | ||
| 2863 | out[num] = '\0'; | ||
| 2864 | return out; | ||
| 2865 | } | ||
| 2866 | |||
| 2867 | /* | 2860 | /* |
| 2868 | * Extract the library name from the file name | 2861 | * Extract the library name from the file name |
| 2869 | * Return 0 if the file isn't a library | 2862 | * Return 0 if the file isn't a library |
| @@ -2886,20 +2879,20 @@ static int filename_to_libname(TCCState *s1, const char filename[], char libname · 16 unmodified lines | |||
| 2886 | #ifdef TCC_TARGET_PE | 2879 | #ifdef TCC_TARGET_PE |
| 2887 | if (!strcmp(ext, ".def")) { | 2880 | if (!strcmp(ext, ".def")) { |
| 2888 | size_t len = ext - filename; | 2881 | size_t len = ext - filename; |
| 2889 | tcc_strcpy_part(libname, filename, len); | 2882 | pstrncpy(libname, filename, len); |
| 2890 | return 1; | 2883 | return 1; |
| 2891 | } | 2884 | } |
| 2892 | #else | 2885 | #else |
| 2893 | if (libprefix && (!strcmp(ext, ".so"))) { | 2886 | if (libprefix && (!strcmp(ext, ".so"))) { |
| 2894 | size_t len = ext - filename - 3; | 2887 | size_t len = ext - filename - 3; |
| 2895 | tcc_strcpy_part(libname, filename + 3, len); | 2888 | pstrncpy(libname, filename + 3, len); |
| 2896 | return 1; | 2889 | return 1; |
| 2897 | } | 2890 | } |
| 2898 | #endif | 2891 | #endif |
| 2899 | } else { | 2892 | } else { |
| 2900 | if (libprefix && (!strcmp(ext, ".a"))) { | 2893 | if (libprefix && (!strcmp(ext, ".a"))) { |
| 2901 | size_t len = ext - filename - 3; | 2894 | size_t len = ext - filename - 3; |
| 2902 | tcc_strcpy_part(libname, filename + 3, len); | 2895 | pstrncpy(libname, filename + 3, len); |
| 2903 | return 1; | 2896 | return 1; |
| 2904 | } | 2897 | } |
| 2905 | } | 2898 | } |
| @@ -90,6 +90,15 @@ ST_INLN int is_float(int t) · 89 unmodified lines | |||
| 90 | return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT; | 90 | return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT; |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | /* we use our own 'finite' function to avoid potential problems with | ||
| 94 | non standard math libs */ | ||
| 95 | /* XXX: endianness dependent */ | ||
| 96 | ST_FUNC int ieee_finite(double d) | ||
| 97 | { | ||
| 98 | int *p = (int *)&d; | ||
| 99 | return ((unsigned)((p[1] | 0x800fffff) + 1)) >> 31; | ||
| 100 | } | ||
| 101 | |||
| 93 | ST_FUNC void test_lvalue(void) | 102 | ST_FUNC void test_lvalue(void) |
| 94 | { | 103 | { |
| 95 | if (!(vtop->r & VT_LVAL)) | 104 | if (!(vtop->r & VT_LVAL)) |