Skip site navigation (1) Skip section navigation (2)

Re: BUG #1044: snprintf() shipped with PostgreSQL is not

From: "Denis N(dot) Stepanov" <D(dot)N(dot)Stepanov(at)inp(dot)nsk(dot)su>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>,PostgreSQL Bugs List <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #1044: snprintf() shipped with PostgreSQL is not
Date: 2004-01-09 06:10:46
Message-ID: Pine.LNX.4.33.0401091111040.14170-100000@Linda.inp.nsk.su (view raw or flat)
Thread:
Lists: pgsql-bugs
On Thu, 8 Jan 2004, Tom Lane wrote:

TL> "PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org> writes:
TL> > Some OSes lack proper snprintf()/vsnprintf() fuctions so PostgreSQL includes
TL> > its own version (src/port/snprintf.c) during building. Unfortunately, this
TL> > version of snprintf() is not reentrant (it uses global vars to keep internal
TL> > state), so for example running libpq-based concurrent applications (threads)
TL> > causes libpq fuctions to fail sometimes.
TL>
TL> What platforms have workable thread support but not snprintf?  I think
TL> this change is not likely to accomplish much except clutter the snprintf
TL> code ...

I discovered this problem while porting libpq (client interface) on
RTEMS OS (rtems.org). This is an embedded OS and as many other embedded OSes it
lacks non-ANSI C functions (at least RTEMS image from my vendor does not have
them). snprintf()/vsnprintf() functions are not ANSI-compliant so they should be
used with care. This OS has POSIX thread support though I did not use it (i.e. I
keep all PgSQL activity in one thread, so the code was compiled without
--enable-thread-safety). The difficulty I observed is: if even I keep PgSQL
calls serialized, calling bare snprintf() from some other thread would likely
cause concurrent PgSQL call to fail. Quite a strange result for such an
inoffensive action, don't you think so?

Anyway, I have fixed this for my code but if you think that the change is
inappropriate for the main stream then let it be. I guess you would hear some
more complaints as there will be more ports on embedded platforms.

TL>
TL> 			regards, tom lane
TL>

-- 
 Thanks,
             Denis.




In response to

Responses

pgsql-bugs by date

Next:From: Kris JurkaDate: 2004-01-09 08:46:04
Subject: Re: jdbc1.AbstractJdbc1Statement.setBinaryStream bug and
Previous:From: Jonathan PurvisDate: 2004-01-09 03:01:34
Subject: JDBC driver doesn't handle NaN values

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group