Re: libpq docs about PQfreemem - Mailing list pgsql-hackers

From Magnus Hagander
Subject Re: libpq docs about PQfreemem
Date
Msg-id 20070206082247.GF6515@svr2.hagander.net
Whole thread Raw
In response to Re: libpq docs about PQfreemem  (Bruce Momjian <bruce@momjian.us>)
List pgsql-hackers
On Mon, Feb 05, 2007 at 05:21:34PM -0500, Bruce Momjian wrote:
> Magnus Hagander wrote:
> > have this about PQfreemem():
> > 
> > Frees memory allocated by <application>libpq</>, particularly
> >    <function>PQescapeByteaConn</function>,
> >    <function>PQescapeBytea</function>,
> >    <function>PQunescapeBytea</function>,
> >    and <function>PQnotifies</function>.
> >    It is needed by Microsoft Windows, which cannot free memory across
> >    DLLs, unless multithreaded DLLs (<option>/MD</option> in VC6) are used.
> >    On other platforms, this function is the same as the standard library
> > function <function>free()</>.
> >   </para>
> > 
> > 
> > 
> > That's also a very old comment, dating back to when we could build libpq
> > with VC6 only and nothing else. Now we can build with MinGW, Borland,
> > VC2005 and I think also VC2003. Which would add the note that this is
> > also depending on *which compiler* and *which compiler version*.
> > The /MD mention is just one of several different options to select the
> > runtime libraries, so it seems really misplaced.
> > 
> > Now, there are two options for this. Either we fix it (I can put
> > together a patch), or we remove it altogether. To me, it seems to be
> > just an implementation detail and some kind of explanation why we're
> > doing it - which would live better in a source code comment than in the
> > docs.
> > This includes the part about how it's just the same as free() on other
> > platforms. That's just an implementation detail, and I assume we don't
> > want people to rely on that - in case we ever want to change it in the
> > future for some reason. (the doc for the other functions say you have to
> > use PQfreemem without mentioning any exceptions)
> > 
> > Thoughts? Rip out or update?
> 
> Are you saying that almost all Win32 binaries and libraries now can free
> across DLLs?

No, I'm saying that the problem is not just between multithreaded and
not, it's depending on a lot other factors as well. It's actuallyi the
same issue as with PQtrace, which has a better explanation.

FOr example, you can't free() a poniter allocated with the MSVC runtime
library if you're using the Borland runtime librarys version of free().

//Magnus


pgsql-hackers by date:

Previous
From: "Jonathan Gray"
Date:
Subject: Pl/pgsql functions causing crashes in 8.2.2
Next
From: "Zeugswetter Andreas ADI SD"
Date:
Subject: Re: Proposal: Commit timestamp