Re: [HACKERS] PQescapeBytea on Win32

2003-03-24 Thread Peter Eisentraut
Bruce Momjian writes:

 The problem with that is the new versions are still going to reference
 PQfreeNotify, and then we still can't remove it. I think we need the
 macro for PQfreeNotify pointing to PQfreemem, but keep the PQfreeNotify
 function around for a release or two, then remove it, and remove all
 documentation about it in 7.4.

Too complicated.  Just implement PQfreemem independently and tell people
to use it.  Please don't remove documentation just because a feature is
deprecated.  How are people supposed to do the conversion if they can't
find information about what they are supposed to convert from?

-- 
Peter Eisentraut   [EMAIL PROTECTED]


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] PQescapeBytea on Win32

2003-03-24 Thread Bruce Momjian
Peter Eisentraut wrote:
 Bruce Momjian writes:
 
  The problem with that is the new versions are still going to reference
  PQfreeNotify, and then we still can't remove it. I think we need the
  macro for PQfreeNotify pointing to PQfreemem, but keep the PQfreeNotify
  function around for a release or two, then remove it, and remove all
  documentation about it in 7.4.
 
 Too complicated.  Just implement PQfreemem independently and tell people
 to use it.  Please don't remove documentation just because a feature is
 deprecated.  How are people supposed to do the conversion if they can't
 find information about what they are supposed to convert from?

OK, I will keep the docs around and point to PGfreemem.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073


---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Re: [HACKERS] PQescapeBytea on Win32

2003-03-24 Thread Bruce Momjian

OK, patch applied to document PQfreemem() for notify.

PQfreeNotify wasn't even documented, but I kept it in for binary
compatibility, and added a #define to map it to PQfreemem().

I updated various interfaces to use PQfreemem() rather than free().

---

Peter Eisentraut wrote:
 Bruce Momjian writes:
 
  The problem with that is the new versions are still going to reference
  PQfreeNotify, and then we still can't remove it. I think we need the
  macro for PQfreeNotify pointing to PQfreemem, but keep the PQfreeNotify
  function around for a release or two, then remove it, and remove all
  documentation about it in 7.4.
 
 Too complicated.  Just implement PQfreemem independently and tell people
 to use it.  Please don't remove documentation just because a feature is
 deprecated.  How are people supposed to do the conversion if they can't
 find information about what they are supposed to convert from?
 
 -- 
 Peter Eisentraut   [EMAIL PROTECTED]
 
 
 ---(end of broadcast)---
 TIP 4: Don't 'kill -9' the postmaster
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: doc/src/sgml/libpq.sgml
===
RCS file: /cvsroot/pgsql-server/doc/src/sgml/libpq.sgml,v
retrieving revision 1.115
diff -c -c -r1.115 libpq.sgml
*** doc/src/sgml/libpq.sgml 24 Mar 2003 18:33:52 -  1.115
--- doc/src/sgml/libpq.sgml 25 Mar 2003 02:40:07 -
***
*** 1049,1056 
  functionPQescapeString/ performs this operation.
  /para
  para
! The
! parameter parameterfrom/ points to the first character of the string that
  is to be escaped, and the parameterlength/ parameter counts the
  number of characters in this string.  (A terminating zero byte is
  neither necessary nor counted.)  parameterto/ shall point to a
--- 1049,1055 
  functionPQescapeString/ performs this operation.
  /para
  para
! The parameter parameterfrom/ points to the first character of the string that
  is to be escaped, and the parameterlength/ parameter counts the
  number of characters in this string.  (A terminating zero byte is
  neither necessary nor counted.)  parameterto/ shall point to a
***
*** 1117,1123 
  
para
 functionPQescapeBytea/ returns an escaped version of the
!parameterfrom/parameter parameter binary string in memory allocated with 
functionmalloc()/.
 The return string has all special characters replaced
 so that they can be properly processed by the PostgreSQL string literal
 parser, and the typebytea/type input function. A terminating zero
--- 1116,1124 
  
para
 functionPQescapeBytea/ returns an escaped version of the
!parameterfrom/parameter parameter binary string in memory
!allocated with functionmalloc()/, and must be freed using
!functionPQfreemem()/.
 The return string has all special characters replaced
 so that they can be properly processed by the PostgreSQL string literal
 parser, and the typebytea/type input function. A terminating zero
***
*** 1143,1150 
 such as might be returned by functionPQgetvalue/function when applied to a
 typebytea/type column. functionPQunescapeBytea/function converts
 this string representation into its binary representation.
!It returns a pointer to a buffer allocated with functionmalloc()/function, or 
null on error, and puts the size
!of the buffer in parameterto_length/parameter.
/para
/listitem
/varlistentry
--- 1144,1154 
 such as might be returned by functionPQgetvalue/function when applied to a
 typebytea/type column. functionPQunescapeBytea/function converts
 this string representation into its binary representation.
!It returns a pointer to a buffer allocated with
!functionmalloc()/function, or null on error, and puts the size of
!the buffer in parameterto_length/parameter. The memory must be
!freed using functionPQfreemem()/.
! 
/para
/listitem
/varlistentry
***
*** 1161,1167 
  
  para
 Frees memory allocated by applicationlibpq/, particularly
!functionPQescapeBytea/function and functionPQunescapeBytea/function.
 It is needed by Win32, which can not free memory across
 DLL's, unless multithreaded DLL's (/MD in VC6) are used.
/para
--- 1165,1173 
  
  para
 Frees memory allocated by applicationlibpq/, particularly
!functionPQescapeBytea/function,
!functionPQunescapeBytea/function,
!and functionPQnotifies/function.
 It is needed by Win32, which can not free memory across
 DLL's, unless multithreaded DLL's (/MD in VC6) are used.
/para

Re: [HACKERS] PQescapeBytea on Win32

2003-03-22 Thread Bruce Momjian
Tom Lane wrote:
 Bruce Momjian [EMAIL PROTECTED] writes:
  Tom Lane wrote:
  Doesn't this duplicate a function that we already invented for PQnotify
  structs?
 
  What do you recommend?  Do we depricate PQfreeNotify?
 
 I dunno.  In hindsight it was shortsightedly named.  But I don't suppose
 we want to tell people to use PQfreeNotify to free the result of
 PQescapeBytea ... so deprecation seems to be the order of the day.
 
 Do we really want PQfreemem either?  Maybe it should be PQfree?

I am a little concerned that PQfree would be confused with PQclear.

Could we have PQfreeNotify() be a macro to PQfreemem in 7.4?

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly


Re: [HACKERS] PQescapeBytea on Win32

2003-03-22 Thread Bruce Momjian
Bruce Momjian wrote:
 Tom Lane wrote:
  Bruce Momjian [EMAIL PROTECTED] writes:
   Tom Lane wrote:
   Doesn't this duplicate a function that we already invented for PQnotify
   structs?
  
   What do you recommend?  Do we depricate PQfreeNotify?
  
  I dunno.  In hindsight it was shortsightedly named.  But I don't suppose
  we want to tell people to use PQfreeNotify to free the result of
  PQescapeBytea ... so deprecation seems to be the order of the day.
  
  Do we really want PQfreemem either?  Maybe it should be PQfree?
 
 I am a little concerned that PQfree would be confused with PQclear.
 
 Could we have PQfreeNotify() be a macro to PQfreemem in 7.4?

The only place I see PQfreeNotify() used in our code is libpgtcl, aside
from libpq, and a macro would work fine.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] PQescapeBytea on Win32

2003-03-22 Thread Tom Lane
Bruce Momjian [EMAIL PROTECTED] writes:
 Do we really want PQfreemem either?  Maybe it should be PQfree?

 I am a little concerned that PQfree would be confused with PQclear.

Good point --- nevermind that suggestion.

 Could we have PQfreeNotify() be a macro to PQfreemem in 7.4?

I'd like to do that but I doubt we can get away with it; it'd be
an incompatible change at the binary API level, forcing a major
version bump on libpq.so.  (On the other hand, we might wind up
doing one anyway; not sure.)

You could do it the other way: PQfreemem a macro for PQfreeNotify.
That would stay binary-compatible with existing clients.  We could
switch which one is a macro at the next occasion for a major
version bump on the shlib, and then eventually remove PQfreeNotify
when we feel it's been deprecated for long enough.

regards, tom lane


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] PQescapeBytea on Win32

2003-03-22 Thread Bruce Momjian
Tom Lane wrote:
 Bruce Momjian [EMAIL PROTECTED] writes:
  Do we really want PQfreemem either?  Maybe it should be PQfree?
 
  I am a little concerned that PQfree would be confused with PQclear.
 
 Good point --- nevermind that suggestion.
 
  Could we have PQfreeNotify() be a macro to PQfreemem in 7.4?
 
 I'd like to do that but I doubt we can get away with it; it'd be
 an incompatible change at the binary API level, forcing a major
 version bump on libpq.so.  (On the other hand, we might wind up
 doing one anyway; not sure.)

Right.  We changed the Notify internal structure and got bitten on that
in 7.3 -- don't want that to happen again.

 You could do it the other way: PQfreemem a macro for PQfreeNotify.
 That would stay binary-compatible with existing clients.  We could
 switch which one is a macro at the next occasion for a major
 version bump on the shlib, and then eventually remove PQfreeNotify
 when we feel it's been deprecated for long enough.

The problem with that is the new versions are still going to reference
PQfreeNotify, and then we still can't remove it. I think we need the
macro for PQfreeNotify pointing to PQfreemem, but keep the PQfreeNotify
function around for a release or two, then remove it, and remove all
documentation about it in 7.4.

I now see that psql doesn't use that call, though it should if it is
running on Win32:

static void
PrintNotifications(void)
{
PGnotify   *notify;

while ((notify = PQnotifies(pset.db)))
{
fprintf(pset.queryFout, gettext(Asynchronous NOTIFY '%s' from backend 
w
ith pid %d received.\n),
notify-relname, notify-be_pid);
free(notify);
fflush(pset.queryFout);
}
}

I will clean that up too, and check any other interfaces/apps.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073


---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [HACKERS] PQescapeBytea on Win32

2003-03-22 Thread Tom Lane
Bruce Momjian [EMAIL PROTECTED] writes:
 The problem with that is the new versions are still going to reference
 PQfreeNotify, and then we still can't remove it. I think we need the
 macro for PQfreeNotify pointing to PQfreemem, but keep the PQfreeNotify
 function around for a release or two, then remove it, and remove all
 documentation about it in 7.4.

Hm.  You could possibly do that with some judicious #undef'ing ...

regards, tom lane


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] PQescapeBytea on Win32

2003-03-22 Thread Bruce Momjian
Tom Lane wrote:
 Bruce Momjian [EMAIL PROTECTED] writes:
  The problem with that is the new versions are still going to reference
  PQfreeNotify, and then we still can't remove it. I think we need the
  macro for PQfreeNotify pointing to PQfreemem, but keep the PQfreeNotify
  function around for a release or two, then remove it, and remove all
  documentation about it in 7.4.
 
 Hm.  You could possibly do that with some judicious #undef'ing ...

Exactly!

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073


---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Re: [HACKERS] PQescapeBytea on Win32

2003-03-21 Thread Bruce Momjian

I have modified the patch to call it PQfreemem(), in case there are other
cases we need to free libpq memory.

Patch attached and applied.

---

Zeugswetter Andreas SB SD wrote:
 
  Actually this isn't even working for me. I just compiled the libpq dll with 
  /MT (multithreaded), and I still get corruption in my app. I even tried 
  libpq compiled with multithreaded-debug (/MTd), which my app is using now, 
  and still same problem.
 
 No, you need to use multithreaded DLL (/MD in VC6) for both the dll and your 
 program, 
 then it works.
 But since that is not optimal (can't use debug runtime unless you have a second 
 debug dll (/MDd)), I also think a callback function would be good to have in 
 addition 
 to linking libpq.dll with /MD.
 
 Informix e.g. supplies SqlFreeMem( void * MemAddr, int FreeType ); 
 
 Andreas
 
 ---(end of broadcast)---
 TIP 3: if posting/reading through Usenet, please send an appropriate
 subscribe-nomail command to [EMAIL PROTECTED] so that your
 message can get through to the mailing list cleanly
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: doc/src/sgml/libpq.sgml
===
RCS file: /cvsroot/pgsql-server/doc/src/sgml/libpq.sgml,v
retrieving revision 1.113
diff -c -c -r1.113 libpq.sgml
*** doc/src/sgml/libpq.sgml 20 Mar 2003 06:23:30 -  1.113
--- doc/src/sgml/libpq.sgml 22 Mar 2003 03:27:47 -
***
*** 1151,1156 
--- 1151,1175 
/para
/listitem
/varlistentry
+ 
+   varlistentry
+   termfunctionPQfreemem/function/term
+   listitem
+   para
+Frees memory allocated by applicationlibpq/
+ synopsis
+ void PQfreemem(void *ptr);
+ /synopsis
+ /para
+ 
+ para
+Frees memory allocated by applicationlibpq/, particularly
+functionPQescapeBytea/function and functionPQunescapeBytea/function.
+It is needed by Win32, which can not free memory across
+DLL's, unless multithreaded DLL's (/MD in VC6) are used.
+   /para
+   /listitem
+   /varlistentry
/variablelist
 
   /sect2
Index: src/interfaces/libpq/fe-exec.c
===
RCS file: /cvsroot/pgsql-server/src/interfaces/libpq/fe-exec.c,v
retrieving revision 1.126
diff -c -c -r1.126 fe-exec.c
*** src/interfaces/libpq/fe-exec.c  10 Mar 2003 22:28:21 -  1.126
--- src/interfaces/libpq/fe-exec.c  22 Mar 2003 03:27:53 -
***
*** 284,289 
--- 284,302 
return buffer;
  }
  
+ 
+ /*
+  *PQfreemem - safely frees memory allocated
+  *
+  * Needed mostly by Win32, unless multithreaded DLL (/MD in VC6)
+  * Used for freeing memory from PQescapeByte()a/PQunescapeBytea()
+  */
+ void PQfreemem(void *ptr)
+ {
+   free(ptr);
+ }
+ 
+ 
  /* 
   * Space management for PGresult.
   *
Index: src/interfaces/libpq/libpq-fe.h
===
RCS file: /cvsroot/pgsql-server/src/interfaces/libpq/libpq-fe.h,v
retrieving revision 1.89
diff -c -c -r1.89 libpq-fe.h
*** src/interfaces/libpq/libpq-fe.h 20 Mar 2003 06:23:30 -  1.89
--- src/interfaces/libpq/libpq-fe.h 22 Mar 2003 03:27:54 -
***
*** 254,259 
--- 254,260 
  size_t *bytealen);
  extern unsigned char *PQunescapeBytea(const unsigned char *strtext,
size_t *retbuflen);
+ extern void PQfreemem(void *ptr);
  
  
  /* Simple synchronous query */

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


[HACKERS] PQescapeBytea on Win32

2003-03-17 Thread Key88 SF
Hi - there is a problem with PQescapeBytea for Win32. Since libpq is a DLL, 
all memory allocated from within the DLL needs to be freed from within the 
dll.

PQescapeBytea allocates memory, but there is no function call back into the 
DLL to free this memory. This causes heap corruption when the main program 
tries to free the memory itself. The alternative is to just leak the memory 
and never free it. Also bad

-Dave Brown
[EMAIL PROTECTED]
_
Add photos to your messages with MSN 8. Get 2 months FREE*.  
http://join.msn.com/?page=features/featuredemail

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly


Re: [HACKERS] PQescapeBytea on Win32

2003-03-17 Thread Bruce Momjian

Yes, I am aware of that limitation.  If you link libpq as a
Multithreaded DLL, it will not link libc into each DLL, but have only
one libc that can free from anywhere. 

Is that acceptable or do we need a Win32 specific memory free function?

---

Key88 SF wrote:
 
 Hi - there is a problem with PQescapeBytea for Win32. Since libpq is a DLL, 
 all memory allocated from within the DLL needs to be freed from within the 
 dll.
 
 PQescapeBytea allocates memory, but there is no function call back into the 
 DLL to free this memory. This causes heap corruption when the main program 
 tries to free the memory itself. The alternative is to just leak the memory 
 and never free it. Also bad
 
 -Dave Brown
 [EMAIL PROTECTED]
 
 
 _
 Add photos to your messages with MSN 8. Get 2 months FREE*.  
 http://join.msn.com/?page=features/featuredemail
 
 
 ---(end of broadcast)---
 TIP 3: if posting/reading through Usenet, please send an appropriate
 subscribe-nomail command to [EMAIL PROTECTED] so that your
 message can get through to the mailing list cleanly
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]