Re: proposed PQconnectdbParams macros (was Re: [BUGS] BUG #5304: psql using conninfo fails in connecting to the server) - Mailing list pgsql-hackers

From Tom Lane
Subject Re: proposed PQconnectdbParams macros (was Re: [BUGS] BUG #5304: psql using conninfo fails in connecting to the server)
Date
Msg-id 22663.1265245829@sss.pgh.pa.us
Whole thread Raw
In response to proposed PQconnectdbParams macros (was Re: [BUGS] BUG #5304: psql using conninfo fails in connecting to the server)  (Joe Conway <mail@joeconway.com>)
List pgsql-hackers
Joe Conway <mail@joeconway.com> writes:
> Any objection if I add these two macros to libpq-fe.h?
> -------------------
> + /* Useful macros for PQconnectdbParams() and PQconnectStartParams() */
> + #define DECL_PARAMS_ARRAYS(PARAMS_ARRAY_SIZE) \
> +       const char **keywords = pg_malloc(PARAMS_ARRAY_SIZE * \
> +                                         sizeof(*keywords)); \
> +       const char **values = pg_malloc(PARAMS_ARRAY_SIZE * \
> +                                       sizeof(*values))
> + #define SET_PARAMS_ARRAYS(__kv_idx__,__kv_kw__,__kv_v__) \
> +       keywords[__kv_idx__]    = __kv_kw__; \
> +       values[__kv_idx__]      = __kv_v__

Yes.  Exposing pg_malloc is 100% wrong, and would be even if you'd
remembered the subsequent free() ;-)

It does not seem especially useful either.  In most cases the array size
is constant and there's no reason to not just make it a local in the
calling function.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Joe Conway
Date:
Subject: proposed PQconnectdbParams macros (was Re: [BUGS] BUG #5304: psql using conninfo fails in connecting to the server)
Next
From: Robert Haas
Date:
Subject: Re: Add on_trusted_init and on_untrusted_init to plperl UPDATED [PATCH]