Hi all,

Would you find it useful to have an immutable string type in gnulib?

In the simplest case, this would a 'const char *' where the 'const' is
actually checked by the hardware. You allocate it through

   const char *str = iasprintf (...);

You use it like any 'const char *'.

You free it through

   ifree (str);

not free (str). And when you attempt to write into it:

   ((char *) str)[0] = 'x';

it crashes.

The benefits I imagine:
  - no worry about security flaws through multithreaded accesses,
  - in large applications: verification that no part of the application
    is doing side effects that it shouldn't.

The implementation uses mmap() to create a read-only and a read-write
view of the same memory area. The contents of the string is filled through
the read-write view. All other operations are done through the read-only
view, because the address os the string is the one of the read-only view.

This won't work on all platforms, e.g. HP-UX. But it will work on glibc
systems, BSD, and Solaris, at least.

Bruno


Reply via email to