"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
Re: simplify template APIs
To:
gameoftrees@openbsd.org
Date:
Wed, 13 Sep 2023 00:07:01 +0200

Download raw body.

Thread
The Subject should have been something along the lines of "move
buffering in the template APIs"; don't know how i come up with
"simplify template APIs" since I'm actually extending them... ^^"

On 2023/09/12 20:31:20 +0200, Omar Polo <op@omarpolo.com> wrote:
> TL;DR: this moves the buffering from the fastcgi code to the template,
> reducing the indirections in fcgi.c and with a net negative.
> 
> 				-*-*-
> 
> When I was first tinkering with template(1) I wrote its API around two
> primitives, putc and puts, because I was dealing with code that looped
> over strings one char at the time to do the escaping and so it was
> natural to build on top of that.  The template assumed buffering is
> done at a lower level, which we already had.
> 
> Having the template code doing the buffering instead allows for a
> simpler usage / setup and to get rid of a few layer of functions in
> fcgi.c.
> 
> Caching at the fcgi level is okish but not great, see the special case
> in fcgi_gen_binary_response to avoid wasting all of our time in
> memcpy().
> 
> The only downside of moving the buffering is that now we have to
> remember to call template_flush() in a few places to flush what could
> remain in the template' cache.
> 
> The changes in gotweb.c are mechanical, just replace the fcgi_*() with
> tmpl_*().  gotwebd.h and sockets.c are trivial, as well as the regress
> changes.  The codegen changes in template/parse.y should also be
> trivial.  The only 'magic' is in introducing a few more functions in
> tmpl.c and dropping some layer of outputting in fcgi.c.
> 
> A minor change in the codegen (template/parse.y) is that now we
> compute the string length at 'compile' time when possible, doing fewer
> strlen() at runtime which is nice :-)
> 
> (i have this running on my instance)
> 
> 
> diffstat /home/op/w/got
>  M  gotwebd/fcgi.c              |   9+  90-
>  M  gotwebd/gotweb.c            |  33+  31-
>  M  gotwebd/gotwebd.h           |   1+   8-
>  M  gotwebd/sockets.c           |   1+   1-
>  M  regress/template/runbase.c  |  12+  20-
>  M  regress/template/runlist.c  |  11+  19-
>  M  template/parse.y            |   6+   5-
>  M  template/tmpl.c             |  74+  12-
>  M  template/tmpl.h             |  13+   8-
> 
> 9 files changed, 160 insertions(+), 194 deletions(-)