1. 22
  1. 2

    Interesting design decision to avoid any heap allocation, even at the cost of performance.

    Thinking about performance, I started to idly wonder just how much of the work could be done at compile time, if you had a better meta programming framework than C macros.

    1. 4

      The costs appear much greater than performance. It looks like providing an invalid regex results in memory corruption: https://github.com/kokke/tiny-regex-c/issues/30

      1. 3

        Yeah, when I saw this library I considered all the potential bugs possible when implementing something as fiddly as regexes in a language as unsafe as C; then I backed slowly away.

        1. 1

          I mean, just because it’s in C doesn’t mean it’s untrustworthy. GNU Grep is written in C (over 3K lines, not including external helpers) and seems to work pretty well.

        2. 1

          That issue was closed as “fixed” a year ago, about 6 months after it was opened. The code now passes analysis by KLEE.

          1. 2

            The response from the maintainer made it seem like it was a design decision. And also, “If you are concerned about security problems, this library is not for you.”

            But good to see that it has been fixed. It looks like the maintainer has gone from “i don’t care about ub” to “let’s do formal analysis to prove it doesn’t happen.” That’s good.

        3. 2

          That decision is probably based on the intended platform:

          Most (all?) of my public projects are designed to be runnable on embedded platforms, and usually that means I make some harsh compromises.

          Static allocation makes it much easier to ensure that code won’t run out of memory on a device with very little of it.

          1. 1

            There is a template-based compile-time regex implementation in C++. I didn’t bookmark it, though; all I remember is it was written by a Russian woman about four years ago.

            I imagine this could be done in Rust, Nim or Zig, too.

            1. 2

              You mean this?