aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap/parse.c')
-rw-r--r--bootstrap/parse.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/bootstrap/parse.c b/bootstrap/parse.c
index 2340182..427f0f2 100644
--- a/bootstrap/parse.c
+++ b/bootstrap/parse.c
@@ -2358,7 +2358,7 @@ parsefn(struct decl *decl, struct parser *P) {
lexexpect(P, '(');
while (!lexmatch(P, &tok, ')')) {
- struct fnparam param;
+ struct fnparam param = {0};
if (lexmatch(P, &tok, '...')) {
fn->variadic = 1;
} else {
@@ -2743,14 +2743,30 @@ parseagg(struct parser *P, const char *name, int kind, struct decl **retdecl) {
}
}
+static const char *
+getbasedir(const char *path) {
+ static char res[PATH_MAX];
+ int i;
+ for (i = strlen(path); i > 0 && path[i] != '/'; --i)
+ ;
+ if (!i)
+ return ".";
+ memcpy(res, path, i);
+ res[i] = '\0';
+ return res;
+}
+
static struct comfile
doimport(struct parser *P, const char *path) {
static vec_t(const char *) seen;
- char _rpath[PATH_MAX], *rpath;
+ char path2[PATH_MAX], _rpath[PATH_MAX], *rpath;
struct comfile cf = {0};
struct parser P2;
+ const char *basedir = getbasedir(P->curfile);
+ snprintf(path2, sizeof path2 - 1, "%s/%s", basedir, path);
+ epri("path2= %q\n", path2);
- if (!(rpath = realpath(path, _rpath)))
+ 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], rpath))
@@ -2759,7 +2775,7 @@ doimport(struct parser *P, const char *path) {
vec_push(&seen, rpath);
// P2.primenv = P->primenv;
- initparser(&P2, path);
+ initparser(&P2, xstrdup(path2));
P2.is_header = 1;
parse(&cf, &P2);
return cf;
@@ -2955,6 +2971,7 @@ parsedecl(decl_yielder_t yield, void *yarg, struct parser *P, bool toplevel) {
assert(toplevel);
path = lexexpect(P, TKstrlit).str;
cf = doimport(P, path);
+ free((void *)path);
for (int i = 0; i < cf.decls.n; ++i) {
struct decl *decl = putdecl(P, tok.span, cf.decls.d[i]);
if (yield)