Re: Cleaner API for appendStringInfoVA - Mailing list pgsql-patches

From Marko Kreen
Subject Re: Cleaner API for appendStringInfoVA
Date
Msg-id e51f66da0711230936t3ac3d1dby8f2f8a9e1dd2e44e@mail.gmail.com
Whole thread Raw
In response to Re: Cleaner API for appendStringInfoVA  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Cleaner API for appendStringInfoVA  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
On 11/23/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Marko Kreen" <markokr@gmail.com> writes:
> > Attached patch moves decision how much more room to allocate
> > from callers of appendStringInfoVA to inside the function,
> > where more info is available.
>
> This is by no stretch of the imagination "cleaner".

"Cleaner" as in avoiding unnecessary work and avoiding
unnecessary guesswork for callers when in can be done
in function.

Also conforming to current coding standards, see below.

> > On systems with broken vsnprintf() it falls back
> > to doubleing the buffer.
>
> The problem with this is that you are defining one particular vsnprintf
> behavior as "non broken", without any evidence for that opinion.
> (Indeed, one could argue that that behavior is contradictory to what
> the Single Unix Spec says, although the SUS is a bit vague about it.)

FWIW, SUS says that vsnprintf should act like snprintf and snprintf:

 The snprintf() function shall be equivalent to sprintf(), with
 the addition of the n argument which states the size of the
 buffer referred to by s. If n is zero, nothing shall be written
 and s may be a null pointer. Otherwise, output bytes beyond the
 n-1st shall be discarded instead of being written to the array,
 and a null byte is written at the end of the bytes actually
 written into the array.

 RETURN VALUE:

 Upon successful completion, the snprintf() function shall return
 the number of bytes that would be written to s had n been
 sufficiently large excluding the terminating null byte.

> Our own vsnprintf doesn't follow that behavior, for instance, so we
> couldn't even get there by forcing it to be used always.

It's one of those broken implementations then.

> I'd want to see some significant evidence of a performance issue
> before considering hacking this up like this.

*shrug*  It's a minor cleanup.  I think it's worthwhile to remove
historical warts from code but if you are not interested, no problem.

Are you interested in fixing src/port/snprintf.c behaviour?
I can prepare a patch, it does not seem to be very hard.

--
marko

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: parse_expr.c:typecast_expression:return immediate on NULL input
Next
From: "Hannes Eder"
Date:
Subject: Re: parse_expr.c:typecast_expression:return immediate on NULL input