ref: ee5be0d4d45549d727f46c720158a75b02d53ade
parent: b55b1f31e139271852c3581924ddc92a10f54883
author: Jacob Moody <moody@posixcafe.org>
date: Sat Mar 25 15:24:01 EDT 2023
cpp: correct #pragma once uniqueness check
--- a/sys/src/cmd/cpp/cpp.c
+++ b/sys/src/cmd/cpp/cpp.c
@@ -86,6 +86,7 @@
Nlist *np;
Token *tp;
Dir *d;
+ Once n;
tp = trp->tp;
if (tp->type!=NAME) {
@@ -157,7 +158,10 @@
d = dirfstat(cursource->fd);
if (d == nil)
error(FATAL, "Out of memory from dirfstat");
- incblocked[nblocked++] = d->qid;
+ n.qid = d->qid;
+ n.type = d->type;
+ n.dev = d->dev;
+ incblocked[nblocked++] = n;
free(d);
break;
--- a/sys/src/cmd/cpp/cpp.h
+++ b/sys/src/cmd/cpp/cpp.h
@@ -73,6 +73,12 @@
char flag; /* is defined, is pp name */
} Nlist;
+typedef struct nonce {
+ Qid qid;
+ uint type;
+ uint dev;
+} Once;
+
typedef struct includelist {
char deleted;
char always;
@@ -154,6 +160,6 @@
extern int Cplusplus;
extern Nlist *kwdefined;
extern Includelist includelist[NINCLUDE];
-extern Qid incblocked[NONCE];
+extern Once incblocked[NONCE];
extern int nblocked;
extern char wd[];
--- a/sys/src/cmd/cpp/include.c
+++ b/sys/src/cmd/cpp/include.c
@@ -6,9 +6,21 @@
char *objname;
-Qid incblocked[NONCE];
+Once incblocked[NONCE];
int nblocked = 0;
+static int
+oncecmp(Once *a, Once *b)
+{
+ if(a->qid.path == b->qid.path)
+ if(a->qid.vers == b->qid.vers)
+ if(a->qid.type == b->qid.type)
+ if(a->dev == b->dev)
+ if(a->type == b->type)
+ return 0;
+ return 1;
+}
+
void
doinclude(Tokenrow *trp)
{
@@ -16,6 +28,7 @@
Includelist *ip;
int angled, len, fd, i;
Dir *d;
+ Once n;
trp->tp += 1;
if (trp->tp>=trp->lp)
@@ -94,12 +107,13 @@
d = dirfstat(fd);
if (d == nil)
error(FATAL, "Out of memory from dirfstat");
+ n.qid = d->qid;
+ n.type = d->type;
+ n.dev = d->dev;
+ free(d);
for (i=0; i<nblocked; i++)
- if (incblocked[i].path == d->qid.path && incblocked[i].type == d->qid.type) {
- free(d);
+ if (oncecmp(incblocked+i, &n) == 0)
return;
- }
- free(d);
if (++incdepth > 20)
error(FATAL, "#include too deeply nested");
setsource((char*)newstring((uchar*)iname, strlen(iname), 0), fd, NULL);