(repost) pgtcl: restore 8.0 compatibility for large obj fix

Started by ljbover 22 years ago6 messagespatches
Jump to latest
#1ljb
ljb220@mindspring.com

This is a repost of my 29 Oct 2003 message, which didn't seem to make it all
the way in. It restores Tcl 8.0 compatibility, which was lost in my patch to
fix corrupt binary data transfer in pg_lo_read and pg_lo_write. Sorry, this
is against PostgreSQL-7.4beta5 which was the latest when I did this up. If it
can't be applied to RC1, I can redo it against RC1 in a few days.

...

I don't think Tcl 8.0.x will have the problem with binary data, as the
trouble started with internationalization at 8.1. So here's my patch
resubmitted with some conditional ugliness:

===================================================================
--- src/interfaces/libpgtcl/pgtclCmds.c.orig	2003-08-03 22:40:16.000000000 -0400
+++ src/interfaces/libpgtcl/pgtclCmds.c	2003-10-29 14:37:48.000000000 -0500
@@ -1215,7 +1215,11 @@
 	buf = ckalloc(len + 1);
 	nbytes = lo_read(conn, fd, buf, len);
+#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1 || TCL_MAJOR_VERSION > 8
+	bufObj = Tcl_NewByteArrayObj(buf, nbytes);
+#else
 	bufObj = Tcl_NewStringObj(buf, nbytes);
+#endif

if (Tcl_ObjSetVar2(interp, bufVar, NULL, bufObj,
TCL_LEAVE_ERR_MSG | TCL_PARSE_PART1) == NULL)
@@ -1307,7 +1311,11 @@
if (Tcl_GetIntFromObj(interp, objv[2], &fd) != TCL_OK)
return TCL_ERROR;

+#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1 || TCL_MAJOR_VERSION > 8
+	buf = Tcl_GetByteArrayFromObj(objv[3], &nbytes);
+#else
 	buf = Tcl_GetStringFromObj(objv[3], &nbytes);
+#endif

if (Tcl_GetIntFromObj(interp, objv[4], &len) != TCL_OK)
return TCL_ERROR;
===================================================================

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: ljb (#1)
Re: (repost) pgtcl: restore 8.0 compatibility for large obj fix

ljb <ljb220@mindspring.com> writes:

+#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1 || TCL_MAJOR_VERSION > 8
+	bufObj = Tcl_NewByteArrayObj(buf, nbytes);
+#else
bufObj = Tcl_NewStringObj(buf, nbytes);
+#endif

Hmm. We could certainly do it like that, but does this actually fix the
problem for Tcl 8.0.*? Or will the unwanted character set translation
happen anyway in that version? I don't see any value in letting the
code compile against 8.0.* if the behavior will be wrong ...

regards, tom lane

#3ljb
ljb220@mindspring.com
In reply to: ljb (#1)
Re: (repost) pgtcl: restore 8.0 compatibility for large obj fix

tgl@sss.pgh.pa.us wrote:

ljb <ljb220@mindspring.com> writes:

+#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1 || TCL_MAJOR_VERSION > 8
+	bufObj = Tcl_NewByteArrayObj(buf, nbytes);
+#else
bufObj = Tcl_NewStringObj(buf, nbytes);
+#endif

Hmm. We could certainly do it like that, but does this actually fix the
problem for Tcl 8.0.*? Or will the unwanted character set translation
happen anyway in that version? I don't see any value in letting the
code compile against 8.0.* if the behavior will be wrong ...

What I wrote was:

I don't think Tcl 8.0.x will have the problem with binary data, as the
trouble started with internationalization at 8.1.

Meaning: Tcl 8.0 added "binary strings", and handled binary data in String
objects. Tcl 8.1 internationalized those strings to make them store UTF-8,
and introduced ByteArray objects to hold binary data. So the original code
should work fine in Tcl 8.0, and the changes are only needed at 8.1 and up.
I'm guessing, though, so I'll go dust off a copy of Tcl 8.0.x and try it.

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: ljb (#3)
Re: (repost) pgtcl: restore 8.0 compatibility for large obj fix

ljb <ljb220@mindspring.com> writes:

Meaning: Tcl 8.0 added "binary strings", and handled binary data in String
objects. Tcl 8.1 internationalized those strings to make them store UTF-8,
and introduced ByteArray objects to hold binary data. So the original code
should work fine in Tcl 8.0, and the changes are only needed at 8.1 and up.
I'm guessing, though, so I'll go dust off a copy of Tcl 8.0.x and try it.

Please. I'm willing to apply the patch, but this close to release
there's no room for error. Double-checking is good.

regards, tom lane

#5ljb
ljb220@mindspring.com
In reply to: ljb (#1)
Patch 7.4RC1 pgtcl to restore Tcl-8.0 compatibility for large obj fix

Here's the patch to restore libpgtcl compatibility with Tcl-8.0, which was
lost in 7.4RC1 with my other patch to fix corrupt binary large-object reads
and writes. This patch is against PostgreSQL-7.4RC1. I've tested it with
Tcl-8.0.5 (minimally, since tcltest doesn't work with Tcl-8.0). At least I
can say it builds and handles binary large object data OK with Tcl-8.0.5.
Of course, it also builds and works with Tcl-8.4.4.

*** src/interfaces/libpgtcl/pgtclCmds.c.orig	Thu Oct 30 19:18:55 2003
--- src/interfaces/libpgtcl/pgtclCmds.c	Thu Nov  6 21:02:26 2003
***************
*** 1218,1224 ****
--- 1218,1228 ----
  	if (nbytes >= 0)
  	{
+ #if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1 || TCL_MAJOR_VERSION > 8
  		bufObj = Tcl_NewByteArrayObj(buf, nbytes);
+ #else
+ 		bufObj = Tcl_NewStringObj(buf, nbytes);
+ #endif
  		if (Tcl_ObjSetVar2(interp, bufVar, NULL, bufObj,
  						   TCL_LEAVE_ERR_MSG | TCL_PARSE_PART1) == NULL)
***************
*** 1313,1319 ****
--- 1317,1327 ----
  	if (Tcl_GetIntFromObj(interp, objv[2], &fd) != TCL_OK)
  		return TCL_ERROR;
+ #if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1 || TCL_MAJOR_VERSION > 8
  	buf = Tcl_GetByteArrayFromObj(objv[3], &nbytes);
+ #else
+ 	buf = Tcl_GetStringFromObj(objv[3], &nbytes);
+ #endif

if (Tcl_GetIntFromObj(interp, objv[4], &len) != TCL_OK)
return TCL_ERROR;

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: ljb (#5)
Re: Patch 7.4RC1 pgtcl to restore Tcl-8.0 compatibility for large obj fix

ljb <ljb220@mindspring.com> writes:

Here's the patch to restore libpgtcl compatibility with Tcl-8.0, which was
lost in 7.4RC1 with my other patch to fix corrupt binary large-object reads
and writes. This patch is against PostgreSQL-7.4RC1.

Applied. Many thanks for double-checking it.

regards, tom lane