pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: PostgreSQL Developers <pgsql-hackers@postgreSQL.org>
Subject: Re: Poorly-thought-out handling of double variables in pgbench
Date: Fri, 06 May 2016 11:13:40 -0400
Message-ID: <16451.1462547620@sss.pgh.pa.us> (raw)
In-Reply-To: <alpine.DEB.2.10.1605060842120.30701@sto>
References: <9188.1462475559@sss.pgh.pa.us>
	<alpine.DEB.2.10.1605052126560.30701@sto>
	<15599.1462484702@sss.pgh.pa.us>
	<alpine.DEB.2.10.1605060842120.30701@sto>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Fabien COELHO <coelho@cri.ensmp.fr> writes:
> This is a definite improvement.

> I like the lazyness between string & numeric forms, and for sorting, that 
> is what was needed doing to have something clean.

> Applied on head, it works for me.

OK, pushed.

> While testing the patch I found a minor preexisting (mine...) bug: when 
> string-scanning doubles, whether the whole string is consumed or not is 
> not checked. This means that -D x=0one is interpreted as double 0.

> I came up with the attached check, but maybe there is a cleaner way to do 
> that.

I like the way the zic code does it:

  	else /* type should be double */
  	{
  		double dv;
  
! 		if (sscanf(var->value, "%lf", &dv) != 1)
  		{
  			fprintf(stderr,
  					"malformed variable \"%s\" value: \"%s\"\n",
--- 928,936 ----
  	else /* type should be double */
  	{
  		double dv;
+ 		char xs;
  
! 		if (sscanf(var->value, "%lf%c", &dv, &xs) != 1)
  		{
  			fprintf(stderr,
  					"malformed variable \"%s\" value: \"%s\"\n",

This relies on the idea that if there is any trailing junk, one character
will get assigned into "xs" and then sscanf will say it filled two fields.
Otherwise, it'll report filling only one field (or none, if there's
no number either).  This requires only a minimal amount of code and no
extra strlen() calculations.

Neither way allows for trailing whitespace, though.  I don't see that
that's important here.

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (7+ messages)  latest in thread

Message-ID: <16451.1462547620@sss.pgh.pa.us>
Permalink:  ../16451.1462547620@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16451.1462547620@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, coelho@cri.ensmp.fr
  Subject: Re: Poorly-thought-out handling of double variables in pgbench
  In-Reply-To: <16451.1462547620@sss.pgh.pa.us>
  References: <9188.1462475559@sss.pgh.pa.us> <alpine.DEB.2.10.1605052126560.30701@sto> <15599.1462484702@sss.pgh.pa.us> <alpine.DEB.2.10.1605060842120.30701@sto> <16451.1462547620@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox