ref: a615514e388f3a6ecd5a91e61579a78d972c8c7a
parent: b2c6861bee0841dbe2d99cc19c2512630094b5a0
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Mon Jan 8 08:02:59 EST 2024
A little neater.
--- a/src/runtime/bfile.c
+++ b/src/runtime/bfile.c
@@ -14,25 +14,25 @@
void (*closeb)(struct BFILE*);
} BFILE;
-static inline int
+static INLINE int
getb(struct BFILE *p)
{return p->getb(p);
}
-static inline void
+static INLINE void
ungetb(int c, struct BFILE *p)
{p->ungetb(c, p);
}
-static inline void
+static INLINE void
putb(int c, struct BFILE *p)
{p->putb(c, p);
}
-static inline void
+static INLINE void
closeb(struct BFILE *p)
{p->closeb(p);
@@ -68,10 +68,25 @@
void
closeb_buf(BFILE *bp)
{- (void)bp; /* shut up warning */
+ FREE(bp);
}
/* There is no open(). Only used with statically allocated buffers. */
+struct BFILE*
+openb_buf(uint8_t *buf, size_t len)
+{+ struct BFILE_buffer *p = MALLOC(sizeof(struct BFILE_buffer));;
+ if (!p)
+ memerr();
+ p->mets.getb = getb_buf;
+ p->mets.ungetb = ungetb_buf;
+ p->mets.putb = 0;
+ p->mets.closeb = closeb_buf;
+ p->b_size = len;
+ p->b_pos = 0;
+ p->b_buffer = buf;
+ return (struct BFILE*)p;
+}
#if WANT_STDIO
/***************** BFILE via FILE *******************/
--- a/src/runtime/eval.c
+++ b/src/runtime/eval.c
@@ -2654,8 +2654,7 @@
if (combexpr) {int c;
- struct BFILE_buffer ibf = { { getb_buf, ungetb_buf, 0, closeb_buf }, combexprlen, 0, combexpr };- BFILE *bf = (BFILE*)&ibf;
+ BFILE *bf = openb_buf(combexpr, combexprlen);
c = getb(bf);
/* Compressed combinators start with a 'Z', otherwise 'v' (for version) */
if (c == 'Z') {--
⑨