Re: search.c clean-up



Elliott Hughes <enh@xxxxxxxxxxx> wrote:
...
> i like this partial factorization -- even though there's more stuff to
> also come out -- because it's a meaningful chunk of functionality in
> its own right, and deserves a name.
>
> i'd rather see a function than a multi-line macro, though.

I prefer functions too, in general but I don't particularly like
the 6-parameter interface (and even less the 4-param one including
two in/out parameters -- it's bad enough that I've done that in
the macro). What did you have in mind?

The problem with the 4-parameter approach

static void
wrap_pattern (char *pattern, size_t *pattern_len,
char const *prefix, char const *suffix)
{
...
}

is that it works fine when we don't have to free the PATTERN,
but if anyone ever calls it with a malloc'd PATTERN, it will leak.

And the six-parameter function seems like overkill for such a small function:

static void
wrap_pattern (char **new_pattern, size_t *new_len,
char const *pattern, size_t len,
char const *prefix, char const *suffix)
{
...
}

Separating the output parameters isn't pretty either,
but it's probably the lesser evil:

static char *
wrap_pattern (char *pattern, size_t *pattern_len,
char const *prefix, char const *suffix)
{
...
}





...



Privacy