Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: type-checking for metafiedness? (was: Re: Cores almost on demand in patcompile())

Oliver Kiddle wrote on Sat, Oct 15, 2016 at 01:04:58 +0200:
> Daniel Shahaf wrote:
> > > > This probably is a good idea, although the intermediate state where this
> > > > has been only partly done is likely to be a bit of a mess.
> Starting out with a simple typedef would at least add documentation and
> allow an incremental approach. Would still need to add .v everywhere en
> masse when going to a struct, though.

Does anyone have a way to get type checking that doesn't involve
adding .v everywhere?  The solution doesn't _have_ to be portable; we
can use compiler-specific magic of gcc or clang, for example, so long as
some developers use that compiler routinely.

If we do the typedefs first, then adding .v later should be easy with
something like coccinelle's patching tool.  (It allows doing
search/replace in terms of the C syntax tree.)

> I did some work on a code base that had a convention of uint8_t*
> for UTF-8. Seemed to work well as far as I could tell.

What's the advantage over chars or unsigned chars?

> For the history file we should perhaps consider not using locale
> dependent metafied strings. UTF-8 with an overlong encoding for a null
> perhaps? grep etc might still not like the overlong null but they should
> be rarer.

+1 to making the history file locale-agnostic.

> > allocated relative to each other, e.g., if the code assumes that
> > «ary[1] - ary[0] == 1+strlen(ary[0])» or otherwise uses the values of
> Even with char**, that condition is only likely if the array was
> created with a literal assignment. And it is easy to test for
> problems by forcing the size of the struct and running the test
> cases.

I was thinking of code that allocates multiple elements in a single
malloc() chunk:

    char **array, *storage;
    for (i = 0; i < LENGTH_OF_LIST; i++)
        sum_of_lengths += strlen(list[i]) + 1;
    storage = malloc(sum_of_lengths);
    for (i = 0; i < LENGTH_OF_LIST; i++) {
        array[i] = strcpy(storage, list[i]);
        storage += strlen(array[i]) + 1;

> Oliver

Messages sorted by: Reverse Date, Date, Thread, Author