Revision | 4e2c950b0cf6150d4fa521cb705e503394600ada (tree) |
---|---|
Time | 2019-02-10 22:18:14 |
Author | dhrname <dhrname@user...> |
Commiter | dhrname |
Modify the alloca_tokens function
@@ -1350,6 +1350,19 @@ uint_fast64_t ST_readFile(ST_Char *name, ST_File_Call callback) | ||
1350 | 1350 | return (uint_fast64_t)filelength; |
1351 | 1351 | } |
1352 | 1352 | |
1353 | +/*alloca_tokens 関数 | |
1354 | + * トークン配列を作るためのアロケータ*/ | |
1355 | +static inline ST_Token_Mode* alloca_tokens(uint_fast64_t filelength) | |
1356 | +{ | |
1357 | + ST_Token_Mode* s; | |
1358 | + s = (ST_Token_Mode*) ST_emalloc(sizeof(ST_Token_Mode) * filelength); | |
1359 | + for (uint_fast64_t i = 0; i<filelength; i++) | |
1360 | + { | |
1361 | + s[i] = ST_UNKNOWN_TOKEN; | |
1362 | + } | |
1363 | + return s; | |
1364 | +} | |
1365 | + | |
1353 | 1366 | /*ST_main 関数 |
1354 | 1367 | * 引数sはソースコードの文字列。 |
1355 | 1368 | * 引数filelengthはsの長さ |
@@ -1357,7 +1370,7 @@ uint_fast64_t ST_readFile(ST_Char *name, ST_File_Call callback) | ||
1357 | 1370 | void ST_main(ST_Char* s, uint_fast64_t filelength) |
1358 | 1371 | { |
1359 | 1372 | |
1360 | - ST_Token_Mode tokens[100] = {0}; | |
1373 | + ST_Token_Mode* tokens = alloca_tokens(filelength); | |
1361 | 1374 | size_t length = sizeof(tokens) / sizeof(tokens[0]); |
1362 | 1375 | ST_Ordered_Pair *varlist = ST_tokenize(s, tokens); |
1363 | 1376 |
@@ -913,6 +913,8 @@ int tests_invalid() { | ||
913 | 913 | |
914 | 914 | assert(ST_FILE_FAIL == ST_readFile(NULL, tests_callback_file)); |
915 | 915 | |
916 | + ST_main(u8"w\np\n", 1048576); | |
917 | + | |
916 | 918 | printf("ended error test...\n"); |
917 | 919 | |
918 | 920 | return 0; |