diff options
Diffstat (limited to 'bootstrap/parse.c')
| -rw-r--r-- | bootstrap/parse.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 4a1721d..0c619fc 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -2925,7 +2925,7 @@ getbasedir(const char *path) { static struct comfile doimport(struct parser *P, const char *path) { - static vec_t(struct entry { const char *s; struct comfile cf; }) seen; + static vec_t(struct entry { const char *s; struct comfile cf; bool wip; }) seen; char path2[PATH_MAX], _rpath[PATH_MAX], *rpath; struct comfile cf = {0}; struct parser P2; @@ -2934,16 +2934,23 @@ doimport(struct parser *P, const char *path) { if (!(rpath = realpath(path2, _rpath))) fatal(P, P->tokspan, "import %q: %s", path, strerror(errno)); - for (int i = 0; i < seen.length; ++i) - if (!strcmp(seen.data[i].s, rpath)) - return seen.data[i].cf; + for (int i = 0; i < seen.length; ++i) { + if (!strcmp(seen.data[i].s, rpath)) { + if (seen.data[i].wip) { + epri("warning: \"%s\": circular import detected: \"%s\" being processed\n", + P->curfile, path); + } + return seen.data[i].cf; + } + } rpath = xstrdup(rpath); // P2.primenv = P->primenv; initparser(&P2, rpath); P2.is_header = 1; - vec_push(&seen, ((struct entry) { rpath, cf })); + vec_push(&seen, ((struct entry) { rpath, cf, 1 })); parse(&cf, &P2); + seen.data[seen.length - 1].wip = 0; seen.data[seen.length - 1].cf = cf; return cf; } |