Unified · Split
| @@ -1569,81 +1569,34 @@ int is_same_file(const file_info_t *fi1, const file_info_t *fi2) · 1568 unmodified lines | ||
| 1569 | 1569 | #endif |
| 1570 | 1570 | } |
| 1571 | 1571 | |
| 1572 | +static void | |
| 1573 | +tcc_normalize_inc_dirs_aux(file_info_t *stats, size_t *pnum, char **path) | |
| 1574 | +{ | |
| 1575 | + size_t i, num = *pnum; | |
| 1576 | + if (get_file_info(*path, &stats[num]) || !is_dir(&stats[num])) | |
| 1577 | + goto remove; | |
| 1578 | + for (i = 0; i < num; i++) | |
| 1579 | + if (is_same_file(&stats[i], &stats[num])) | |
| 1580 | + goto remove; | |
| 1581 | + *pnum = num + 1; | |
| 1582 | + return; | |
| 1583 | + remove: | |
| 1584 | + tcc_free(*path); | |
| 1585 | + *path = 0; | |
| 1586 | +} | |
| 1587 | + | |
| 1588 | +/* Remove non-existent and duplicate directories from include paths. */ | |
| 1572 | 1589 | ST_FUNC void tcc_normalize_inc_dirs(TCCState *s) |
| 1573 | 1590 | { |
| 1574 | −/* check a preprocessor include dirs and remove not | |
| 1575 | − existing dirs and duplicates: | |
| 1576 | − - for each duplicate path keep just the first one | |
| 1577 | − - remove each include_path that exists in sysinclude_paths | |
| 1578 | −*/ | |
| 1579 | − file_info_t sysinc_stats[50]; // we don't use VLA in tcc code | |
| 1580 | − file_info_t inc_stats[50]; | |
| 1581 | − int num_sysinc = s->nb_sysinclude_paths; | |
| 1582 | − int num_inc = s->nb_include_paths; | |
| 1583 | − char** pp; | |
| 1584 | − int i, j, r; | |
| 1585 | − | |
| 1586 | − if ((num_sysinc > 50) || (num_inc > 50)) { | |
| 1587 | − tcc_warning("fix a max number of the inc dirs"); | |
| 1588 | − if (num_sysinc > 50) num_sysinc = 50; | |
| 1589 | − if (num_inc > 50) num_inc = 50; | |
| 1590 | − } | |
| 1591 | − | |
| 1592 | − pp = s->sysinclude_paths; | |
| 1593 | − for (i=0; i < num_sysinc; i++) { | |
| 1594 | − file_info_t *st = &sysinc_stats [i]; | |
| 1595 | − r = get_file_info( pp [i], st); | |
| 1596 | − if (r || !is_dir(st)) { | |
| 1597 | − tcc_free( pp[i] ); | |
| 1598 | − pp[i] = 0; | |
| 1599 | − } | |
| 1600 | − } | |
| 1601 | − pp = s->include_paths; | |
| 1602 | − for (i=0; i < num_inc; i++) { | |
| 1603 | − file_info_t *st = &inc_stats [i]; | |
| 1604 | − r = get_file_info( pp [i], st); | |
| 1605 | − if (r || !is_dir(st)) { | |
| 1606 | − tcc_free( pp[i] ); | |
| 1607 | − pp[i] = 0; | |
| 1608 | − } | |
| 1609 | − } | |
| 1610 | − | |
| 1611 | − for (i=0; i < num_inc; i++) { | |
| 1612 | − file_info_t *st1 = &inc_stats [i]; | |
| 1613 | − for (j=i+1; j < num_inc; j++) { | |
| 1614 | − file_info_t *st2 = &inc_stats [j]; | |
| 1615 | − if (is_same_file(st1, st2)) { | |
| 1616 | − pp = &s->include_paths[j]; | |
| 1617 | − if (*pp) { | |
| 1618 | − tcc_free( *pp ); | |
| 1619 | − *pp = 0; | |
| 1620 | − } | |
| 1621 | − } | |
| 1622 | − } | |
| 1623 | − for (j=0; i < num_sysinc; i++) { | |
| 1624 | − file_info_t *st2 = &sysinc_stats [j]; | |
| 1625 | − if (is_same_file(st1, st2)) { | |
| 1626 | − pp = &s->include_paths[i]; | |
| 1627 | − if (*pp) { | |
| 1628 | − tcc_free( *pp ); | |
| 1629 | − *pp = 0; | |
| 1630 | − } | |
| 1631 | − } | |
| 1632 | − } | |
| 1633 | − } | |
| 1634 | − for (i=0; i < num_sysinc; i++) { | |
| 1635 | − file_info_t *st1 = &sysinc_stats [i]; | |
| 1636 | − for (j=i+1; j < num_sysinc; j++) { | |
| 1637 | − file_info_t *st2 = &sysinc_stats [j]; | |
| 1638 | − if (is_same_file(st1, st2)) { | |
| 1639 | − pp = &s->sysinclude_paths[j]; | |
| 1640 | − if (*pp) { | |
| 1641 | − tcc_free( *pp ); | |
| 1642 | − *pp = 0; | |
| 1643 | − } | |
| 1644 | − } | |
| 1645 | − } | |
| 1646 | − } | |
| 1591 | + file_info_t *stats = | |
| 1592 | + tcc_malloc(((size_t)s->nb_sysinclude_paths + s->nb_include_paths) * | |
| 1593 | + sizeof(*stats)); | |
| 1594 | + size_t i, num = 0; | |
| 1595 | + for (i = 0; i < s->nb_sysinclude_paths; i++) | |
| 1596 | + tcc_normalize_inc_dirs_aux(stats, &num, &s->sysinclude_paths[i]); | |
| 1597 | + for (i = 0; i < s->nb_include_paths; i++) | |
| 1598 | + tcc_normalize_inc_dirs_aux(stats, &num, &s->include_paths[i]); | |
| 1599 | + tcc_free(stats); | |
| 1647 | 1600 | } |
| 1648 | 1601 | |
| 1649 | 1602 | LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) |