Re: [PATCHES] PL/Perl regression tests with use_strict

2005-08-24 Thread Andrew Dunstan
Michael Fuhr said:
 On Tue, Aug 23, 2005 at 10:30:51PM -0600, Michael Fuhr wrote:
 Global symbol $x requires explicit package name at (eval 3) line 1.

 If I'm reading the Perl source code correctly (pp_ctl.c), the number
 following eval comes from a variable named PL_evalseq that's
 incremented each time it appears in one of these messages.  It looks
 like we'd have to munge the error message to get rid of that.

 Hmmm...tests suggest that we might be able to munge $@ in the
 mk*safefunc functions.  That is, instead of doing

  return eval($stuff);

 we might be able to do

  my $retval = eval($stuff);
  $@ =~ s/ \(eval \d+\) / /g if $@;
  return $retval;

 That would convert messages like

  Global symbol $x requires explicit package name at (eval 3) line 1.

 into

  Global symbol $x requires explicit package name at line 1.

 Is that what you're looking for?  So far I've done only simple tests in
 standalone embedded Perl programs, so I don't know if this approach
 would work in PL/Perl or have unintended effects.

It  would probably be more efficient and less convoluted to munge this in a
__DIE__ handler. The we wouldn't need the extra level of eval.

e.g.

$SIG{__DIE__} =
  sub { my $msg = $_[0]; $msg =~ s/\(eval \d+\) //; die $msg; };

cheers

andrew




---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


Re: [PATCHES] PATCH to allow concurrent VACUUMs to not lock each

2005-08-24 Thread Hannu Krosing
On K, 2005-08-17 at 15:40 -0400, Tom Lane wrote:
Saatja: 
 Tom Lane [EMAIL PROTECTED]
   Kellele: 
 Bruce Momjian
 pgman@candle.pha.pa.us, Hannu
 Krosing [EMAIL PROTECTED], Neil Conway
 [EMAIL PROTECTED], pgsql-
 [EMAIL PROTECTED]
 Teema: 
 Re: [PATCHES] PATCH to allow
 concurrent VACUUMs to not lock each
   KuupƤev: 
 Wed, 17 Aug 2005 15:40:53 -0400
 (22:40 EEST)
 
 Just for the archives, attached is as far as I'd gotten with cleaning
 up
 Hannu's patch before I realized that it wasn't doing what it needed to
 do.  This fixes an end-of-transaction race condition (can't unset
 inVacuum before xact end, unless you want OldestXmin going backwards
 from the point of view of other people) and improves the documentation
 of what's going on.  But unless someone can convince me that it's safe
 to mess with GetSnapshotData, it's unlikely this'll ever get applied.
 
 
 

Attached is a patch, based on you last one, which messes with
GetSnapshotData in what I think is a safe way.

It introduces another attribute to PROC , proc-nonInVacuumXmin and
computes this in addition to prox-xmin inside GetSnapshotData.

When (and only when) GetOldestXmin is called with ignoreVacuum=true,
then proc-nonInVacuumXmin is checked instead of prox-xmin.

I believe that this will make this change invisible to all other places
where GetSnapshotData or GetOldestXmin is used.

-- 
Hannu Krosing [EMAIL PROTECTED]





Index: src/backend/access/transam/twophase.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/access/transam/twophase.c,v
retrieving revision 1.10
diff -c -r1.10 twophase.c
*** src/backend/access/transam/twophase.c	20 Aug 2005 23:26:10 -	1.10
--- src/backend/access/transam/twophase.c	24 Aug 2005 12:01:17 -
***
*** 280,285 
--- 280,287 
  	gxact-proc.pid = 0;
  	gxact-proc.databaseId = databaseid;
  	gxact-proc.roleId = owner;
+ 	gxact-proc.inVacuum = false;
+ 	gxact-proc.nonInVacuumXmin = InvalidTransactionId;
  	gxact-proc.lwWaiting = false;
  	gxact-proc.lwExclusive = false;
  	gxact-proc.lwWaitLink = NULL;
Index: src/backend/access/transam/xact.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/access/transam/xact.c,v
retrieving revision 1.214
diff -c -r1.214 xact.c
*** src/backend/access/transam/xact.c	20 Aug 2005 23:45:08 -	1.214
--- src/backend/access/transam/xact.c	24 Aug 2005 12:01:17 -
***
*** 1516,1521 
--- 1516,1523 
  		LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
  		MyProc-xid = InvalidTransactionId;
  		MyProc-xmin = InvalidTransactionId;
+ 		MyProc-inVacuum = false;	/* must be cleared with xid/xmin */
+ 		MyProc-nonInVacuumXmin = InvalidTransactionId; /* this too */
  
  		/* Clear the subtransaction-XID cache too while holding the lock */
  		MyProc-subxids.nxids = 0;
***
*** 1752,1757 
--- 1754,1761 
  	LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
  	MyProc-xid = InvalidTransactionId;
  	MyProc-xmin = InvalidTransactionId;
+ 	MyProc-inVacuum = false;	/* must be cleared with xid/xmin */
+ 	MyProc-nonInVacuumXmin = InvalidTransactionId; /* this too */
  
  	/* Clear the subtransaction-XID cache too while holding the lock */
  	MyProc-subxids.nxids = 0;
***
*** 1915,1920 
--- 1919,1926 
  		LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
  		MyProc-xid = InvalidTransactionId;
  		MyProc-xmin = InvalidTransactionId;
+ 		MyProc-inVacuum = false;	/* must be cleared with xid/xmin */
+ 		MyProc-nonInVacuumXmin = InvalidTransactionId; /* this too */
  
  		/* Clear the subtransaction-XID cache too while holding the lock */
  		MyProc-subxids.nxids = 0;
Index: src/backend/access/transam/xlog.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/access/transam/xlog.c,v
retrieving revision 1.218
diff -c -r1.218 xlog.c
*** src/backend/access/transam/xlog.c	22 Aug 2005 23:59:04 -	1.218
--- src/backend/access/transam/xlog.c	24 Aug 2005 12:01:18 -
***
*** 5303,5309 
  	 * mustn't do this because StartupSUBTRANS hasn't been called yet.
  	 */
  	if (!InRecovery)
! 		TruncateSUBTRANS(GetOldestXmin(true));
  
  	if (!shutdown)
  		ereport(DEBUG2,
--- 5303,5309 
  	 * mustn't do this because StartupSUBTRANS hasn't been called yet.
  	 */
  	if (!InRecovery)
! 		TruncateSUBTRANS(GetOldestXmin(true, false));
  
  	if (!shutdown)
  		ereport(DEBUG2,
Index: src/backend/catalog/index.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/catalog/index.c,v
retrieving revision 1.259
diff -c -r1.259 index.c
*** src/backend/catalog/index.c	12 Aug 2005 01:35:56 -	1.259
--- src/backend/catalog/index.c	24 Aug 2005 12:01:18 -
***
*** 1433,1439 
  	

Re: [PATCHES] PL/Perl regression tests with use_strict

2005-08-24 Thread Andrew Dunstan



I wrote:


Michael Fuhr said:
 


we might be able to do

my $retval = eval($stuff);
$@ =~ s/ \(eval \d+\) / /g if $@;
return $retval;

T


It  would probably be more efficient and less convoluted to munge this in a
__DIE__ handler. The we wouldn't need the extra level of eval.

e.g.

$SIG{__DIE__} =
 sub { my $msg = $_[0]; $msg =~ s/\(eval \d+\) //; die $msg; };


 



Or rather it would do if we didn't carefully avoid the die handler so we 
can get our hands on the message.


Here's an updated patch incorporating Michael's ideas, and this time 
*with* a small regression test that dynamically turns strict mode on/off.


cheers

andrew


Index: src/pl/plperl/plperl.c
===
RCS file: /home/cvsmirror/pgsql/src/pl/plperl/plperl.c,v
retrieving revision 1.90
diff -c -r1.90 plperl.c
*** src/pl/plperl/plperl.c	20 Aug 2005 19:19:21 -	1.90
--- src/pl/plperl/plperl.c	24 Aug 2005 13:41:54 -
***
*** 185,241 
  	/* We don't need to do anything yet when a new backend starts. */
  }
  
  
  static void
  plperl_init_interp(void)
  {
! 	static char	   *loose_embedding[3] = {
! 		, -e,
! 		/* all one string follows (no commas please) */
! 		SPI::bootstrap(); use vars qw(%_SHARED);
! 		sub ::plperl_warn { my $msg = shift; elog(NOTICE, $msg); } 
! 		$SIG{__WARN__} = \\::plperl_warn; 
! 		sub ::mkunsafefunc {return eval(qq[ sub { $_[0] $_[1] } ]); }
! 		sub ::_plperl_to_pg_array
! 		{
! 		  my $arg = shift; ref $arg eq 'ARRAY' || return $arg; 
! 		  my $res = ''; my $first = 1; 
! 		  foreach my $elem (@$arg) 
! 		  { 
! 		$res .= ', ' unless $first; $first = undef; 
! 		if (ref $elem) 
! 		{ 
! 		  $res .= _plperl_to_pg_array($elem); 
! 		} 
! 		else 
! 		{ 
! 		  my $str = qq($elem); 
! 		  $str =~ s/([\])/$1/g; 
! 		  $res .= qq(\$str\); 
! 		} 
! 		  } 
! 		  return qq({$res}); 
! 		} 
  	};
  
  
- 	static char	   *strict_embedding[3] = {
- 		, -e,
- 		/* all one string follows (no commas please) */
- 		SPI::bootstrap(); use vars qw(%_SHARED);
- 		sub ::plperl_warn { my $msg = shift; elog(NOTICE, $msg); } 
- 		$SIG{__WARN__} = \\::plperl_warn; 
- 		sub ::mkunsafefunc {return eval(
- 		qq[ sub { use strict; $_[0] $_[1] } ]); }
- 	};
- 
  	plperl_interp = perl_alloc();
  	if (!plperl_interp)
  		elog(ERROR, could not allocate Perl interpreter);
  
  	perl_construct(plperl_interp);
! 	perl_parse(plperl_interp, plperl_init_shared_libs, 3 ,
! 			   (plperl_use_strict ? strict_embedding : loose_embedding), NULL);
  	perl_run(plperl_interp);
  
  	plperl_proc_hash = newHV();
--- 185,266 
  	/* We don't need to do anything yet when a new backend starts. */
  }
  
+ #define PERLBOOT \
+ SPI::bootstrap(); use vars qw(%_SHARED);\
+ sub ::plperl_warn { my $msg = shift;  \
+$msg =~ s/ \\(eval \\d+\\)//; elog(NOTICE, $msg); }   \
+ 	$SIG{__WARN__} = \\::plperl_warn;  \
+ sub ::plperl_die { my $msg = shift;  \
+$msg =~ s/ \\(eval \\d+\\)//; die $msg; }   \
+ 	$SIG{__DIE__} = \\::plperl_die;  \
+ 	sub ::mkunsafefunc { my $ret = eval(qq[ sub { $_[0] $_[1] } ]);  \
+   $@ =~ s/ \\(eval \\d+\\)// if $@; return $ret; } \
+ use strict;  \
+ 	sub ::mk_strict_unsafefunc { my $ret = eval( \
+ 	  qq[ sub { use strict; $_[0] $_[1] } ]);  \
+   $@ =~ s/ \\(eval \\d+\\)// if $@; return $ret; }  \
+ 	sub ::_plperl_to_pg_array \
+ 	{ \
+ 	  my $arg = shift; ref $arg eq 'ARRAY' || return $arg;  \
+ 	  my $res = ''; my $first = 1;  \
+ 	  foreach my $elem (@$arg)  \
+ 	  {  \
+ 	$res .= ', ' unless $first; $first = undef;  \
+ 	if (ref $elem)  \
+ 	{  \
+ 	  $res .= _plperl_to_pg_array($elem);  \
+ 	}  \
+ 	else  \
+ 	{  \
+ 	  my $str = qq($elem);  \
+ 	  $str =~ s/([\])/$1/g;  \
+ 	  $res .= qq(\$str\);  \
+ 	}  \
+ 	  }  \
+ 	  return qq({$res});  \
+ 	} 
+ 
+ #define SAFE_MODULE require Safe; $Safe::VERSION
+ 
+ #define SAFE_OK \
+ 	use vars qw($PLContainer); $PLContainer = new Safe('PLPerl'); \
+ 	$PLContainer-permit_only(':default'); \
+ 	$PLContainer-permit(qw[:base_math !:base_io sort time]); \
+ 	$PLContainer-share(qw[elog spi_exec_query return_next  \
+ 	spi_query spi_fetchrow  \
+ 	_plperl_to_pg_array  \
+ 	DEBUG LOG INFO NOTICE WARNING ERROR %_SHARED ]); \
+ 	sub ::mksafefunc { my $ret = $PLContainer-reval(qq[  \
+ 	 sub { $_[0] $_[1]}]);  \
+  $@ =~ s/ \\(eval \\d+\\)// if $@; return $ret; } \
+ 	$PLContainer-permit('require');$PLContainer-reval('use strict;'); \
+ 	$PLContainer-deny('require'); \
+ 	sub ::mk_strict_safefunc { my $ret = $PLContainer-reval(qq[  \
+ 	 sub { BEGIN { strict-import(); } $_[0] $_[1]}]);  \
+  $@ =~ s/ \\(eval \\d+\\)// if $@; return $ret; } 
+ 
+ #define SAFE_BAD \
+ 	use vars qw($PLContainer); $PLContainer = new Safe('PLPerl'); \
+ 	$PLContainer-permit_only(':default'); \
+ 	$PLContainer-share(qw[elog 

Re: [PATCHES] PL/Perl regression tests with use_strict

2005-08-24 Thread Michael Fuhr
On Wed, Aug 24, 2005 at 09:50:06AM -0400, Andrew Dunstan wrote:
 Here's an updated patch incorporating Michael's ideas, and this time 
 *with* a small regression test that dynamically turns strict mode on/off.

Shouldn't the $@ munging patterns include the /g flag so they remove
all occurrences of the pattern?

SET plperl.use_strict TO on;

CREATE FUNCTION foo() RETURNS integer AS $$
$x = 1;
$y = 2;
return $x + $y;
$$ LANGUAGE plperl;

ERROR:  creation of Perl function failed: Global symbol $x requires explicit 
package name at line 2.
Global symbol $y requires explicit package name at (eval 10) line 3.
Global symbol $x requires explicit package name at (eval 10) line 4.
Global symbol $y requires explicit package name at (eval 10) line 4.


-- 
Michael Fuhr

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [PATCHES] PATCH to allow concurrent VACUUMs to not lock each

2005-08-24 Thread Bruce Momjian

This has been saved for the 8.2 release:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---

Hannu Krosing wrote:
 On K, 2005-08-17 at 15:40 -0400, Tom Lane wrote:
 Saatja: 
  Tom Lane [EMAIL PROTECTED]
Kellele: 
  Bruce Momjian
  pgman@candle.pha.pa.us, Hannu
  Krosing [EMAIL PROTECTED], Neil Conway
  [EMAIL PROTECTED], pgsql-
  [EMAIL PROTECTED]
  Teema: 
  Re: [PATCHES] PATCH to allow
  concurrent VACUUMs to not lock each
Kuup?ev: 
  Wed, 17 Aug 2005 15:40:53 -0400
  (22:40 EEST)
  
  Just for the archives, attached is as far as I'd gotten with cleaning
  up
  Hannu's patch before I realized that it wasn't doing what it needed to
  do.  This fixes an end-of-transaction race condition (can't unset
  inVacuum before xact end, unless you want OldestXmin going backwards
  from the point of view of other people) and improves the documentation
  of what's going on.  But unless someone can convince me that it's safe
  to mess with GetSnapshotData, it's unlikely this'll ever get applied.
  
  
  
 
 Attached is a patch, based on you last one, which messes with
 GetSnapshotData in what I think is a safe way.
 
 It introduces another attribute to PROC , proc-nonInVacuumXmin and
 computes this in addition to prox-xmin inside GetSnapshotData.
 
 When (and only when) GetOldestXmin is called with ignoreVacuum=true,
 then proc-nonInVacuumXmin is checked instead of prox-xmin.
 
 I believe that this will make this change invisible to all other places
 where GetSnapshotData or GetOldestXmin is used.
 
 -- 
 Hannu Krosing [EMAIL PROTECTED]
 
 
 
 
 

[ Attachment, skipping... ]

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (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 2: Don't 'kill -9' the postmaster


Re: [PATCHES] PL/Perl regression tests with use_strict

2005-08-24 Thread Andrew Dunstan



Michael Fuhr wrote:


On Wed, Aug 24, 2005 at 09:50:06AM -0400, Andrew Dunstan wrote:
 

Here's an updated patch incorporating Michael's ideas, and this time 
*with* a small regression test that dynamically turns strict mode on/off.
   



Shouldn't the $@ munging patterns include the /g flag so they remove
all occurrences of the pattern?

SET plperl.use_strict TO on;

CREATE FUNCTION foo() RETURNS integer AS $$
$x = 1;
$y = 2;
return $x + $y;
$$ LANGUAGE plperl;

ERROR:  creation of Perl function failed: Global symbol $x requires explicit 
package name at line 2.
Global symbol $y requires explicit package name at (eval 10) line 3.
Global symbol $x requires explicit package name at (eval 10) line 4.
Global symbol $y requires explicit package name at (eval 10) line 4.

 



good point.

Here's yet another revision ;-)

cheers

andrew
Index: src/pl/plperl/plperl.c
===
RCS file: /home/cvsmirror/pgsql/src/pl/plperl/plperl.c,v
retrieving revision 1.90
diff -c -r1.90 plperl.c
*** src/pl/plperl/plperl.c	20 Aug 2005 19:19:21 -	1.90
--- src/pl/plperl/plperl.c	24 Aug 2005 14:21:56 -
***
*** 185,241 
  	/* We don't need to do anything yet when a new backend starts. */
  }
  
  
  static void
  plperl_init_interp(void)
  {
! 	static char	   *loose_embedding[3] = {
! 		, -e,
! 		/* all one string follows (no commas please) */
! 		SPI::bootstrap(); use vars qw(%_SHARED);
! 		sub ::plperl_warn { my $msg = shift; elog(NOTICE, $msg); } 
! 		$SIG{__WARN__} = \\::plperl_warn; 
! 		sub ::mkunsafefunc {return eval(qq[ sub { $_[0] $_[1] } ]); }
! 		sub ::_plperl_to_pg_array
! 		{
! 		  my $arg = shift; ref $arg eq 'ARRAY' || return $arg; 
! 		  my $res = ''; my $first = 1; 
! 		  foreach my $elem (@$arg) 
! 		  { 
! 		$res .= ', ' unless $first; $first = undef; 
! 		if (ref $elem) 
! 		{ 
! 		  $res .= _plperl_to_pg_array($elem); 
! 		} 
! 		else 
! 		{ 
! 		  my $str = qq($elem); 
! 		  $str =~ s/([\])/$1/g; 
! 		  $res .= qq(\$str\); 
! 		} 
! 		  } 
! 		  return qq({$res}); 
! 		} 
  	};
  
  
- 	static char	   *strict_embedding[3] = {
- 		, -e,
- 		/* all one string follows (no commas please) */
- 		SPI::bootstrap(); use vars qw(%_SHARED);
- 		sub ::plperl_warn { my $msg = shift; elog(NOTICE, $msg); } 
- 		$SIG{__WARN__} = \\::plperl_warn; 
- 		sub ::mkunsafefunc {return eval(
- 		qq[ sub { use strict; $_[0] $_[1] } ]); }
- 	};
- 
  	plperl_interp = perl_alloc();
  	if (!plperl_interp)
  		elog(ERROR, could not allocate Perl interpreter);
  
  	perl_construct(plperl_interp);
! 	perl_parse(plperl_interp, plperl_init_shared_libs, 3 ,
! 			   (plperl_use_strict ? strict_embedding : loose_embedding), NULL);
  	perl_run(plperl_interp);
  
  	plperl_proc_hash = newHV();
--- 185,266 
  	/* We don't need to do anything yet when a new backend starts. */
  }
  
+ #define PERLBOOT \
+ SPI::bootstrap(); use vars qw(%_SHARED);\
+ sub ::plperl_warn { my $msg = shift;  \
+$msg =~ s/ \\(eval \\d+\\)//g; elog(NOTICE, $msg); }   \
+ 	$SIG{__WARN__} = \\::plperl_warn;  \
+ sub ::plperl_die { my $msg = shift;  \
+$msg =~ s/ \\(eval \\d+\\)//g; die $msg; }   \
+ 	$SIG{__DIE__} = \\::plperl_die;  \
+ 	sub ::mkunsafefunc { my $ret = eval(qq[ sub { $_[0] $_[1] } ]);  \
+   $@ =~ s/ \\(eval \\d+\\)//g if $@; return $ret; } \
+ use strict;  \
+ 	sub ::mk_strict_unsafefunc { my $ret = eval( \
+ 	  qq[ sub { use strict; $_[0] $_[1] } ]);  \
+   $@ =~ s/ \\(eval \\d+\\)//g if $@; return $ret; }  \
+ 	sub ::_plperl_to_pg_array \
+ 	{ \
+ 	  my $arg = shift; ref $arg eq 'ARRAY' || return $arg;  \
+ 	  my $res = ''; my $first = 1;  \
+ 	  foreach my $elem (@$arg)  \
+ 	  {  \
+ 	$res .= ', ' unless $first; $first = undef;  \
+ 	if (ref $elem)  \
+ 	{  \
+ 	  $res .= _plperl_to_pg_array($elem);  \
+ 	}  \
+ 	else  \
+ 	{  \
+ 	  my $str = qq($elem);  \
+ 	  $str =~ s/([\])/$1/g;  \
+ 	  $res .= qq(\$str\);  \
+ 	}  \
+ 	  }  \
+ 	  return qq({$res});  \
+ 	} 
+ 
+ #define SAFE_MODULE require Safe; $Safe::VERSION
+ 
+ #define SAFE_OK \
+ 	use vars qw($PLContainer); $PLContainer = new Safe('PLPerl'); \
+ 	$PLContainer-permit_only(':default'); \
+ 	$PLContainer-permit(qw[:base_math !:base_io sort time]); \
+ 	$PLContainer-share(qw[elog spi_exec_query return_next  \
+ 	spi_query spi_fetchrow  \
+ 	_plperl_to_pg_array  \
+ 	DEBUG LOG INFO NOTICE WARNING ERROR %_SHARED ]); \
+ 	sub ::mksafefunc { my $ret = $PLContainer-reval(qq[  \
+ 	 sub { $_[0] $_[1]}]);  \
+  $@ =~ s/ \\(eval \\d+\\)//g if $@; return $ret; } \
+ 	$PLContainer-permit('require');$PLContainer-reval('use strict;'); \
+ 	$PLContainer-deny('require'); \
+ 	sub ::mk_strict_safefunc { my $ret = $PLContainer-reval(qq[  \
+ 	 sub { BEGIN { strict-import(); } $_[0] $_[1]}]);  \
+  $@ =~ s/ 

Re: [PATCHES] FW: Win32 unicode vs ICU

2005-08-24 Thread Bruce Momjian

This has been saved for the 8.2 release:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---

Magnus Hagander wrote:
 I just realised this mail didn't go through. Probably because it was too
 large for -hackers. So: repost to -patches. Sorry about that. If it's a
 duplicate, even more sorry, but I couldn't find it in the archives.
 
 (This may explain that nobody answered me :P)
 
 //Magnus
  
 
  -Original Message-
  From: Magnus Hagander 
  Sent: Sunday, July 31, 2005 2:09 PM
  To: PostgreSQL-development
  Cc: [EMAIL PROTECTED]
  Subject: Win32 unicode vs ICU
  
  Hi!
  
  I've been working with Palles ICU patch to make it work on 
  win32, and I believe I have it done. While doing it I noticed 
  that ICU basically converts to UTF16 and back - I previously 
  thought it worked on UTF8 strings. Based on this I also tried 
  out an implementation for the win32-unicode problem that does 
  *not* require ICU. It uses the win32 native functions to map 
  to utf16 and back, and then to process the text there. And I 
  got through with much less code than the ICU version, while 
  doing the same thing.
  
  I am unsure of how to proceed. As I see it there are three paths:
  1) Use native win32 functionality only on win32
  2) Use ICU functionality only on win32
  3) Allow both ICU and native functionality, compile time 
  switch --with-icu (same as unix with the ICU patch)
  
  
  The main downsides of ICU vs the native ones are:
  * ICU does not accept win32 locale names. When doing 
  setlocale(sv_se), for example, win32 will return this in 
  later calls as Swedish_Sweden.1252. To get around this in 
  the ICU patch, I had to implement a lookup map that converts 
  it back to sv_se for ICU.
  
  * ICU is yet another build and runtime dependency, and a 
  large one (comes in at 11Mb for the DLL files alone in the 
  win32 download)
  
  
  I guess that the main upside of it is that we'd get 
  constistent behaviour - in case there are issues with either 
  ICU or win32 native they'd otherwise differ. And only one new 
  codepath. But we already live with the platform-inconsistency today...
  
  Another upside is that it handles more encodings in ICU - my 
  native implementation does *only* UTF8 and relies on existing 
  functionality to deal with other encodings. It could of 
  course be extended if necessary, but from what I can tell 
  UTF8 is the big one.
  
  
  
  I have attached both patches. For the native version, only 
  win32_utf8.patch is required.  For the ICU version, 
  icu_win32.patch is needed and also the files 
  localemap.c,localemap.pl, iso639 and iso3166 needs to go in 
  src/backend/port/win32. (the localemap needs to be updated to 
  do a better-than-linear search, but I wanted to include an example)
  
  
  Thoughts on the options?
  
  
  And anohter question - my native patch touches the same 
  functions as the ICU patch. Can somebody who knows the 
  internals confirm or deny that these are all the required 
  locations, or do we need to modify more?
  
  (I have run simple tests in swedish locale and both behave 
  the same and correct, but I'm unsure of exactly how much 
  would be affected)
  
  Finally, the win32 patch also changes the normal path to use 
  strncoll(). The comment above the function states that we'd 
  like to use strncoll but it's not available. Well, on win32 
  it is, so it should provide a speedup on win32. It is 
  currently not included in the ICU patch, but should probably 
  be included whichever path we'd chose.
  
  
  //Magnus
  

Content-Description: win32_utf8.patch

[ Attachment, skipping... ]

Content-Description: icu_win32.patch

[ Attachment, skipping... ]

Content-Description: localemap.pl

[ Attachment, skipping... ]

Content-Description: localemap.c

[ Attachment, skipping... ]

 
 ---(end of broadcast)---
 TIP 4: Have you searched our list archives?
 
http://archives.postgresql.org

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (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 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


[PATCHES] Proposed patch to getaddrinfo.c to support IPv6 on Windows

2005-08-24 Thread Chuck McDevitt








Im proposing this change to /src/port/getaddrinfo.c
to support IPv6 under windows.



10a11,14

 * Windows may or may not have these
routines, so we handle Windows special

 * by dynamically checking for their existence.
If they already exist, we

 * use the Windows native routines, but if
not, we use our own.

 *

31a36,121

 

 #ifdef WIN32

 

 #define WIN32_LEAN_AND_MEAN

 /* Bring in windows.h for LoadLibrary,
FreeLibrary, and GetProcAddress routines */

 #include windows.h

 

 /* 

 * The native routines may or may not
exist on the Windows platform we are on,

 * so we dynamically look up the routines,
and call them via function pointers.

 * Here we need to declare what the
function pointers look like

 */

 typedef

 int

 (__stdcall * getaddrinfo_ptr_t)(const char *
nodename, const char * servname,

 const struct
addrinfo * hints, struct addrinfo ** res);

 

 typedef

 void

 (__stdcall * freeaddrinfo_ptr_t)(struct
addrinfo * ai);

 

 typedef

 int

 (__stdcall * getnameinfo_ptr_t)(const struct
sockaddr * sa, int salen,

 char *
host, int hostlen, char * serv, int servlen, int flags);

 

 /* static pointers to the native Windows IPv6
routines, so we only do the lookup once. */

 static getaddrinfo_ptr_t getaddrinfo_ptr =
NULL;

 static freeaddrinfo_ptr_t freeaddrinfo_ptr =
NULL;

 static getnameinfo_ptr_t getnameinfo_ptr =
NULL;

 

 static

 bool haveNativeWindowsIPv6routines(void)

 {

 void * hLibrary =
NULL;

 static bool
alreadyLookedForIpv6routines = FALSE;

 

 if
(alreadyLookedForIpv6routines)



return (getaddrinfo_ptr != NULL);

 

 /* 

  * For Windows XP and
Windows 2003 (and longhorn/vista), the IPv6

 * routines are
present the WinSock 2 library (ws2_32.dll). Try that first

  */

 

 hLibrary = LoadLibraryA(ws2_32);

 

  if (hLibrary == NULL ||
GetProcAddress(hLibrary, getaddrinfo) == NULL)

  {

  /*
Well, ws2_32 doesn't exist, or more likely doesn't have getaddrinfo. */

  if
(hLibrary != NULL)

  FreeLibrary(hLibrary);

 

  /*
In Windows 2000, there was only the IPv6 Technology
Preview 

  *
look in the IPv6 WinSock library (wship6.dll).

  */

 

  hLibrary
= LoadLibraryA(wship6);

  }

 

  /* If hLibrary is null, we
couldn't find a dll that supports the functions */

 if (hLibrary != NULL)

 {

  /*
We found a dll, so now get the addresses of the routines */

 


getaddrinfo_ptr = GetProcAddress(hLibrary, getaddrinfo);

  freeaddrinfo_ptr
= GetProcAddress(hLibrary, freeaddrinfo);

  getnameinfo_ptr
= GetProcAddress(hLibrary, getnameinfo);

 

  /*
If any one of the routines is missing, let's play it safe and ignore them all
*/


if (getaddrinfo_ptr == NULL || freeaddrinfo_ptr == NULL || getnameinfo_ptr ==
NULL)


{


FreeLibrary(hLibrary);


hLibrary = NULL;

  getaddrinfo_ptr
= NULL;

  freeaddrinfo_ptr
= NULL;

  getnameinfo_ptr
= NULL;


}

 }





alreadyLookedForIpv6routines = TRUE;

 return (getaddrinfo_ptr
!= NULL); 

 }

 #endif 

 

 

49a140,148

 #ifdef WIN32

  /* 

  * If Windows has
native IPv6 support, use the native Windows routine.

  * Otherwise, fall
through and use our own code.

  */

  if (haveNativeWindowsIPv6routines())

  return
(*getaddrinfo_ptr)(node,service,hintp,res);

 #endif

 

162a262,272

 #ifdef WIN32

  /*


  *
If Windows has native IPv6 support, use the native Windows routine.

  *
Otherwise, fall through and use our own code.

  */

  if
(haveNativeWindowsIPv6routines())

  {

  (*freeaddrinfo_ptr)(node,service,hintp,res);

  return;

  }

 #endif

218a329,338

 

 #ifdef WIN32

  /* 

  * If Windows has
native IPv6 support, use the native Windows routine.

  * Otherwise, fall
through and use our own code.

  */

  if
(haveNativeWindowsIPv6routines())

  return
(*getnameinfo_ptr)(sa,salen,node,nodelen,service,servicelen,flags);

 #endif










getaddrinfo.patch
Description: getaddrinfo.patch

---(end of broadcast)---
TIP 1: 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: [PATCHES] Proposed patch to getaddrinfo.c to support IPv6 on Windows

2005-08-24 Thread Bruce Momjian

Context diff, please, diff -c.

---

Chuck McDevitt wrote:
 I'm proposing this change to /src/port/getaddrinfo.c to support IPv6
 under windows.
 
  
 
 10a11,14
 
   * Windows may or may not have these routines, so we handle Windows
 special
 
   * by dynamically checking for their existence.  If they already
 exist, we
 
   * use the Windows native routines, but if not, we use our own.
 
   *
 
 31a36,121
 
  
 
  #ifdef WIN32
 
  
 
  #define WIN32_LEAN_AND_MEAN
 
  /* Bring in windows.h for LoadLibrary, FreeLibrary, and GetProcAddress
 routines */
 
  #include windows.h
 
  
 
  /* 
 
   * The native routines may or may not exist on the Windows platform we
 are on,
 
   * so we dynamically look up the routines, and call them via function
 pointers.
 
   * Here we need to declare what the function pointers look like
 
   */
 
  typedef
 
  int
 
  (__stdcall * getaddrinfo_ptr_t)(const char * nodename, const char *
 servname,
 
   const struct addrinfo * hints, struct addrinfo ** res);
 
  
 
  typedef
 
  void
 
  (__stdcall * freeaddrinfo_ptr_t)(struct addrinfo * ai);
 
  
 
  typedef
 
  int
 
  (__stdcall * getnameinfo_ptr_t)(const struct sockaddr * sa, int salen,
 
   char *  host, int hostlen, char * serv, int servlen, int flags);
 
  
 
  /* static pointers to the native Windows IPv6 routines, so we only do
 the lookup once. */
 
  static getaddrinfo_ptr_t getaddrinfo_ptr = NULL;
 
  static freeaddrinfo_ptr_t freeaddrinfo_ptr = NULL;
 
  static getnameinfo_ptr_t getnameinfo_ptr = NULL;
 
  
 
  static
 
  bool haveNativeWindowsIPv6routines(void)
 
  {
 
  void * hLibrary  = NULL;
 
  static bool  alreadyLookedForIpv6routines= FALSE;
 
 
 
  if (alreadyLookedForIpv6routines)
 
  return (getaddrinfo_ptr != NULL);
 
  
 
  /* 
 
   * For Windows XP and Windows 2003 (and longhorn/vista), the IPv6
 
   * routines are present the WinSock 2 library (ws2_32.dll).  Try
 that first
 
   */
 
  
 
  hLibrary = LoadLibraryA(ws2_32);
 
  
 
  if (hLibrary == NULL || GetProcAddress(hLibrary, getaddrinfo) ==
 NULL)
 
  {
 
/* Well, ws2_32 doesn't exist, or more likely doesn't have
 getaddrinfo. */
 
if (hLibrary != NULL)
 
  FreeLibrary(hLibrary);
 
  
 
/* In Windows 2000, there was only the IPv6 Technology
 Preview
 
 * look in the IPv6 WinSock library (wship6.dll).
 
 */
 
  
 
hLibrary = LoadLibraryA(wship6);
 
  }
 
  
 
  /* If hLibrary is null, we couldn't find a dll that supports the
 functions */
 
  if (hLibrary != NULL)
 
  {
 
/* We found a dll, so now get the addresses of the routines
 */
 
  
 
  getaddrinfo_ptr = GetProcAddress(hLibrary, getaddrinfo);
 
freeaddrinfo_ptr = GetProcAddress(hLibrary, freeaddrinfo);
 
getnameinfo_ptr = GetProcAddress(hLibrary, getnameinfo);
 
  
 
/* If any one of the routines is missing, let's play it safe
 and ignore them all */
 
  if (getaddrinfo_ptr == NULL || freeaddrinfo_ptr == NULL ||
 getnameinfo_ptr == NULL)
 
  {
 
  FreeLibrary(hLibrary);
 
  hLibrary = NULL;
 
  getaddrinfo_ptr = NULL;
 
  freeaddrinfo_ptr = NULL;
 
  getnameinfo_ptr = NULL;
 
  }
 
  }
 
  
 
  alreadyLookedForIpv6routines = TRUE;
 
  return (getaddrinfo_ptr != NULL); 
 
  }
 
  #endif 
 
  
 
  
 
 49a140,148
 
  #ifdef WIN32
 
  /* 
 
   * If Windows has native IPv6 support, use the native Windows
 routine.
 
   * Otherwise, fall through and use our own code.
 
   */
 
  if (haveNativeWindowsIPv6routines())
 
return (*getaddrinfo_ptr)(node,service,hintp,res);
 
  #endif
 
  
 
 162a262,272
 
  #ifdef WIN32
 
/* 
 
 * If Windows has native IPv6 support, use the native
 Windows routine.
 
 * Otherwise, fall through and use our own code.
 
 */
 
if (haveNativeWindowsIPv6routines())
 
{
 
  (*freeaddrinfo_ptr)(node,service,hintp,res);
 
  return;
 
}
 
  #endif
 
 218a329,338
 
  
 
  #ifdef WIN32
 
  /* 
 
   * If Windows has native IPv6 support, use the native Windows
 routine.
 
   * Otherwise, fall through and use our own code.
 
   */
 
  if (haveNativeWindowsIPv6routines())
 
return
 (*getnameinfo_ptr)(sa,salen,node,nodelen,service,servicelen,flags);
 
  #endif
 
  
 

Content-Description: getaddrinfo.patch

[ Attachment, skipping... ]

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

Re: [PATCHES] PL/Perl regression tests with use_strict

2005-08-24 Thread Tom Lane
Michael Fuhr [EMAIL PROTECTED] writes:
 The attached patch allows the PL/Perl regression tests to pass when
 use_strict is enabled.  I've also attached a variant of plperl_elog.out
 to account for an elog() message that shows a different line number
 when run under use_strict.

Now that we've got the use_strict mess sorted, I've applied this.

regards, tom lane

---(end of broadcast)---
TIP 1: 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


[PATCHES] Corrected: Proposed patch to getaddrinfo.c to support IPv6 on Windows

2005-08-24 Thread Chuck McDevitt








Im proposing this change to /src/port/getaddrinfo.c
to support IPv6 under windows.

(this time with a context diff !)





*** \postgresql-snapshot\src\port\getaddrinfo.c Wed
Aug 24 11:54:09 2005

--- \postgresql-patched\src\port\getaddrinfo.c Wed
Aug 24 11:53:05 2005

***

*** 8,18 

 * platform, we'll need to split this file and
provide a separate configure

 * test for getnameinfo().

 *

 *

 * Copyright (c) 2003-2005, PostgreSQL Global
Development Group

 *

 * IDENTIFICATION

! *  $PostgreSQL: pgsql/src/port/getaddrinfo.c,v
1.17 2005/07/28 04:03:14 tgl Exp $

 *

 *-

 */

--- 8,22 

 * platform, we'll need to split this file and
provide a separate configure

 * test for getnameinfo().

 *

+ * Windows may or may not have these routines, so
we handle Windows special

+ * by dynamically checking for their existance.
If they already exist, we

+ * use the Windows native routines, but if not, we
use our own.

+ *

 *

 * Copyright (c) 2003-2005, PostgreSQL Global
Development Group

 *

 * IDENTIFICATION

! *  $PostgreSQL: pgsql/src/port/getaddrinfo.c,v
1.16 2005/01/01 20:44:33 tgl Exp $

 *


*-

 */

***

*** 29,34 

--- 33,124 

 

 #include getaddrinfo.h

 

+ 

+ #ifdef WIN32

+ 

+ #define WIN32_LEAN_AND_MEAN

+ /* Bring in windows.h for LoadLibrary,
FreeLibrary, and GetProcAddress routines */

+ #include windows.h

+ 

+ /* 

+ * The native routines may or may not exist on the
Windows platform we are on,

+ * so we dynamically look up the routines, and
call them via function pointers.

+ * Here we need to declare what the function
pointers look like

+ */

+ typedef

+ int

+ (__stdcall * getaddrinfo_ptr_t)(const char *
nodename, const char * servname,

+ const struct addrinfo * hints, struct
addrinfo ** res);

+ 

+ typedef

+ void

+ (__stdcall * freeaddrinfo_ptr_t)(struct addrinfo *
ai);

+ 

+ typedef

+ int

+ (__stdcall * getnameinfo_ptr_t)(const struct
sockaddr * sa, int salen,

+ char * host, int hostlen, char * serv, int
servlen, int flags);

+ 

+ /* static pointers to the native Windows IPv6
routines, so we only do the lookup once. */

+ static getaddrinfo_ptr_t getaddrinfo_ptr = NULL;

+ static freeaddrinfo_ptr_t freeaddrinfo_ptr = NULL;

+ static getnameinfo_ptr_t getnameinfo_ptr = NULL;

+ 

+ static

+ bool haveNativeWindowsIPv6routines(void)

+ {

+ void * hLibrary = NULL;

+ static bool alreadyLookedForIpv6routines =
FALSE;

+ 

+ if (alreadyLookedForIpv6routines) 

+ return (getaddrinfo_ptr != NULL);

+ 

+ /* 

+  * For Windows XP and Windows 2003 (and
longhorn/vista), the IPv6

+ * routines are present the WinSock 2 library
(ws2_32.dll). Try that first

+  */

+ 

+ hLibrary = LoadLibraryA(ws2_32);

+ 

+  if (hLibrary == NULL ||
GetProcAddress(hLibrary, getaddrinfo) == NULL)

+  {

+  /* Well, ws2_32 doesn't exist, or more
likely doesn't have getaddrinfo. */

+  if (hLibrary != NULL)

+  FreeLibrary(hLibrary);

+ 

+  /* In Windows 2000, there was only the
IPv6 Technology Preview 

+  * look in the IPv6 WinSock library
(wship6.dll).

+  */

+ 

+  hLibrary = LoadLibraryA(wship6);

+  }

+ 

+  /* If hLibrary is null, we couldn't find a dll
that supports the functions */

+ if (hLibrary != NULL)

+ {

+  /* We found a dll, so now get the
addresses of the routines */

+ 

+ getaddrinfo_ptr = GetProcAddress(hLibrary,
getaddrinfo);

+  freeaddrinfo_ptr =
GetProcAddress(hLibrary, freeaddrinfo);

+  getnameinfo_ptr =
GetProcAddress(hLibrary, getnameinfo);

+ 

+  /* If any one of the routines is
missing, let's play it safe and ignore them all */

+ if (getaddrinfo_ptr == NULL ||
freeaddrinfo_ptr == NULL || getnameinfo_ptr == NULL)

+ {

+ FreeLibrary(hLibrary);

+ hLibrary = NULL;

+  getaddrinfo_ptr = NULL;

+  freeaddrinfo_ptr = NULL;

+  getnameinfo_ptr = NULL;

+ }

+ }

+ 

+ alreadyLookedForIpv6routines = TRUE;

+ return (getaddrinfo_ptr != NULL); 

+ }

+ #endif 

+ 

+ 

 /*

 * get address info for ipv4 sockets.

 *

***

*** 47,52 

--- 137,151 

  *psin;

  struct addrinfo hints;

 

+ #ifdef WIN32

+  /* 

+  * If Windows has native IPv6 support, use the
native Windows routine.

+  * Otherwise, fall through and use our own
code.

+  */

+  if (haveNativeWindowsIPv6routines())

+  return
(*getaddrinfo_ptr)(node,service,hintp,res);

+ #endif

+ 

  if (hintp == NULL)

  {

  memset(hints, 0, sizeof(hints));

***

*** 160,165 

--- 259,275 

 {

  if (res)

  {

+ #ifdef WIN32

+  /* 

+  * If Windows has native IPv6 support,
use the native Windows routine.

+  * Otherwise, fall through and use our
own code.

+  */

+  if (haveNativeWindowsIPv6routines())

+  {

+  (*freeaddrinfo_ptr)(node,service,hintp,res);

+  return;

+  }

+ #endif

  if (res-ai_addr)

  free(res-ai_addr);

  free(res);

***

*** 216,221 

--- 326,341 

 

Re: [HACKERS] [PATCHES] Proposed patch to getaddrinfo.c to support

2005-08-24 Thread Andrew Dunstan



Bruce Momjian wrote:


Context diff, please, diff -c.

 





It needed dos2unix and pgindent as well. Here's a cleaned patch.

Thanks to Chuck for doing this work.

cheers

andrew
*** src/port/getaddrinfo.c	2005-07-28 00:03:14.0 -0400
--- /home/andrew/getaddrinfo.c	2005-08-24 16:04:29.0 -0400
***
*** 8,13 
--- 8,17 
   * platform, we'll need to split this file and provide a separate configure
   * test for getnameinfo().
   *
+  * Windows may or may not have these routines, so we handle Windows special
+  * by dynamically checking for their existance.  If they already exist, we
+  * use the Windows native routines, but if not, we use our own.
+  *
   *
   * Copyright (c) 2003-2005, PostgreSQL Global Development Group
   *
***
*** 29,34 
--- 33,132 
  
  #include getaddrinfo.h
  
+ 
+ #ifdef WIN32
+ 
+ #define WIN32_LEAN_AND_MEAN
+ /* Bring in windows.h for LoadLibrary, FreeLibrary, and GetProcAddress routines */
+ #include windows.h
+ 
+ /*
+  * The native routines may or may not exist on the Windows platform we are on,
+  * so we dynamically look up the routines, and call them via function pointers.
+  * Here we need to declare what the function pointers look like
+  */
+ typedef
+ int
+ 			(__stdcall * getaddrinfo_ptr_t) (const char *nodename, const char *servname,
+ 	  const struct addrinfo * hints, struct addrinfo ** res);
+ 
+ typedef
+ void
+ 			(__stdcall * freeaddrinfo_ptr_t) (struct addrinfo * ai);
+ 
+ typedef
+ int
+ 			(__stdcall * getnameinfo_ptr_t) (const struct sockaddr * sa, int salen,
+ char *host, int hostlen, char *serv, int servlen, int flags);
+ 
+ /* static pointers to the native Windows IPv6 routines, so we only do the lookup once. */
+ static getaddrinfo_ptr_t getaddrinfo_ptr = NULL;
+ static freeaddrinfo_ptr_t freeaddrinfo_ptr = NULL;
+ static getnameinfo_ptr_t getnameinfo_ptr = NULL;
+ 
+ static
+ bool
+ haveNativeWindowsIPv6routines(void)
+ {
+ 	void	   *hLibrary = NULL;
+ 	static bool alreadyLookedForIpv6routines = FALSE;
+ 
+ 	if (alreadyLookedForIpv6routines)
+ 		return (getaddrinfo_ptr != NULL);
+ 
+ 	/*
+ 	 * For Windows XP and Windows 2003 (and longhorn/vista), the IPv6
+ 	 * routines are present the WinSock 2 library (ws2_32.dll).  Try that first
+ 	 */
+ 
+ 	hLibrary = LoadLibraryA(ws2_32);
+ 
+ 	if (hLibrary == NULL || GetProcAddress(hLibrary, getaddrinfo) == NULL)
+ 	{
+ 		/*
+ 		 * Well, ws2_32 doesn't exist, or more likely doesn't have
+ 		 * getaddrinfo.
+ 		 */
+ 		if (hLibrary != NULL)
+ 			FreeLibrary(hLibrary);
+ 
+ 		/*
+ 		 * In Windows 2000, there was only the IPv6 Technology Preview look in
+ 		 * the IPv6 WinSock library (wship6.dll).
+ 		 */
+ 
+ 		hLibrary = LoadLibraryA(wship6);
+ 	}
+ 
+ 	/* If hLibrary is null, we couldn't find a dll that supports the functions */
+ 	if (hLibrary != NULL)
+ 	{
+ 		/* We found a dll, so now get the addresses of the routines */
+ 
+ 		getaddrinfo_ptr = GetProcAddress(hLibrary, getaddrinfo);
+ 		freeaddrinfo_ptr = GetProcAddress(hLibrary, freeaddrinfo);
+ 		getnameinfo_ptr = GetProcAddress(hLibrary, getnameinfo);
+ 
+ 		/*
+ 		 * If any one of the routines is missing, let's play it safe and
+ 		 * ignore them all
+ 		 */
+ 		if (getaddrinfo_ptr == NULL || freeaddrinfo_ptr == NULL || getnameinfo_ptr == NULL)
+ 		{
+ 			FreeLibrary(hLibrary);
+ 			hLibrary = NULL;
+ 			getaddrinfo_ptr = NULL;
+ 			freeaddrinfo_ptr = NULL;
+ 			getnameinfo_ptr = NULL;
+ 		}
+ 	}
+ 
+ 	alreadyLookedForIpv6routines = TRUE;
+ 	return (getaddrinfo_ptr != NULL);
+ }
+ #endif
+ 
+ 
  /*
   * get address info for ipv4 sockets.
   *
***
*** 47,52 
--- 145,159 
  			   *psin;
  	struct addrinfo hints;
  
+ #ifdef WIN32
+ 	/*
+ 	 * If Windows has native IPv6 support, use the native Windows routine.
+ 	 * Otherwise, fall through and use our own code.
+ 	 */
+ 	if (haveNativeWindowsIPv6routines())
+ 		return (*getaddrinfo_ptr) (node, service, hintp, res);
+ #endif
+ 
  	if (hintp == NULL)
  	{
  		memset(hints, 0, sizeof(hints));
***
*** 160,165 
--- 267,283 
  {
  	if (res)
  	{
+ #ifdef WIN32
+ 		/*
+ 		 * If Windows has native IPv6 support, use the native Windows routine.
+ 		 * Otherwise, fall through and use our own code.
+ 		 */
+ 		if (haveNativeWindowsIPv6routines())
+ 		{
+ 			(*freeaddrinfo_ptr) (node, service, hintp, res);
+ 			return;
+ 		}
+ #endif
  		if (res-ai_addr)
  			free(res-ai_addr);
  		free(res);
***
*** 188,194 
  	}
  
  	return hstrerror(hcode);
- 
  #else			/* !HAVE_HSTRERROR */
  
  	switch (errcode)
--- 306,311 
***
*** 216,221 
--- 333,348 
  			char *node, int nodelen,
  			char *service, int servicelen, int flags)
  {
+ 
+ #ifdef WIN32
+ 	/*
+ 	 * If Windows has native IPv6 support, use the native Windows routine.
+ 	 * Otherwise, fall through and use our own code.
+ 	 */
+ 	if (haveNativeWindowsIPv6routines())
+ 		return (*getnameinfo_ptr) (sa, salen, node, nodelen, 

Re: [PATCHES] enable/disable trigger (Re: Fwd: [HACKERS] Open items)

2005-08-24 Thread Gavin Sherry
Attached is a patch adding regression tests for this code.

Thanks,

Gavin

On Tue, 23 Aug 2005, Bruce Momjian wrote:


 Thanks, modified patch applied by Tom, with the addition of a USER
 triggers only mode.

 ---

 Satoshi Nagayasu wrote:
  The message format for elog() report is cleaned up.
 
  --
  NAGAYASU Satoshi [EMAIL PROTECTED]

  diff -cr pgsql.orig/src/backend/commands/tablecmds.c 
  pgsql/src/backend/commands/tablecmds.c
  *** pgsql.orig/src/backend/commands/tablecmds.c 2005-06-28 
  14:08:54.0 +0900
  --- pgsql/src/backend/commands/tablecmds.c  2005-08-08 13:46:44.0 
  +0900
  ***
  *** 236,241 
  --- 236,243 
 --
   Bruce Momjian|  http://candle.pha.pa.us
   pgman@candle.pha.pa.us   |  (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: Have you searched our list archives?

http://archives.postgresql.org
Index: src/test/regress/expected/triggers.out
===
RCS file: /usr/local/cvsroot/pgsql/src/test/regress/expected/triggers.out,v
retrieving revision 1.18
diff -c -p -r1.18 triggers.out
*** src/test/regress/expected/triggers.out  13 Oct 2004 01:22:31 -  
1.18
--- src/test/regress/expected/triggers.out  25 Aug 2005 01:07:08 -
*** SELECT * FROM main_table ORDER BY a, b;
*** 322,324 
--- 322,388 
  |   
  (8 rows)
  
+ -- Test enable/disable triggers
+ create table trigtest (i serial primary key);
+ NOTICE:  CREATE TABLE will create implicit sequence trigtest_i_seq for 
serial column trigtest.i
+ NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index 
trigtest_pkey for table trigtest
+ -- test that disabling RI triggers works
+ create table trigtest2 (i int references trigtest(i) on delete cascade);
+ create function trigtest() returns trigger as $$
+ begin
+   raise notice '% % % %', TG_RELNAME, TG_OP, TG_WHEN, TG_LEVEL;
+   return new;
+ end;$$ language plpgsql;
+ create trigger trigtest_b_row_tg before insert or update or delete on trigtest
+ for each row execute procedure trigtest();
+ create trigger trigtest_a_row_tg after insert or update or delete on trigtest
+ for each row execute procedure trigtest();
+ create trigger trigtest_b_stmt_tg before insert or update or delete on 
trigtest
+ for each statement execute procedure trigtest();
+ create trigger trigtest_a_stmt_tg after insert or update or delete on trigtest
+ for each statement execute procedure trigtest();
+ insert into trigtest default values;
+ NOTICE:  trigtest INSERT BEFORE STATEMENT
+ NOTICE:  trigtest INSERT BEFORE ROW
+ NOTICE:  trigtest INSERT AFTER ROW
+ NOTICE:  trigtest INSERT AFTER STATEMENT
+ alter table trigtest disable trigger trigtest_b_row_tg;
+ insert into trigtest default values;
+ NOTICE:  trigtest INSERT BEFORE STATEMENT
+ NOTICE:  trigtest INSERT AFTER ROW
+ NOTICE:  trigtest INSERT AFTER STATEMENT
+ alter table trigtest disable trigger user;
+ insert into trigtest default values;
+ alter table trigtest enable trigger trigtest_a_stmt_tg;
+ insert into trigtest default values;
+ NOTICE:  trigtest INSERT AFTER STATEMENT
+ insert into trigtest2 values(1);
+ insert into trigtest2 values(2);
+ delete from trigtest where i=2;
+ NOTICE:  trigtest DELETE AFTER STATEMENT
+ select * from trigtest2;
+  i 
+ ---
+  1
+ (1 row)
+ 
+ alter table trigtest disable trigger all;
+ delete from trigtest where i=1;
+ select * from trigtest2;
+  i 
+ ---
+  1
+ (1 row)
+ 
+ -- ensure we still insert, even when all triggers are disabled
+ insert into trigtest default values;
+ select *  from trigtest;
+  i 
+ ---
+  3
+  4
+  5
+ (3 rows)
+ 
+ drop table trigtest2;
+ drop table trigtest;
Index: src/test/regress/sql/triggers.sql
===
RCS file: /usr/local/cvsroot/pgsql/src/test/regress/sql/triggers.sql,v
retrieving revision 1.8
diff -c -p -r1.8 triggers.sql
*** src/test/regress/sql/triggers.sql   21 Nov 2003 22:32:49 -  1.8
--- src/test/regress/sql/triggers.sql   25 Aug 2005 01:04:38 -
*** COPY main_table (a, b) FROM stdin;
*** 253,255 
--- 253,296 
  \.
  
  SELECT * FROM main_table ORDER BY a, b;
+ 
+ -- Test enable/disable triggers
+ 
+ create table trigtest (i serial primary key);
+ -- test that disabling RI triggers works
+ create table trigtest2 (i int references trigtest(i) on delete cascade);
+ 
+ create function trigtest() returns trigger as $$
+ begin
+   raise notice '% % % %', TG_RELNAME, TG_OP, TG_WHEN, TG_LEVEL;
+   return new;
+ end;$$ language plpgsql;
+ 
+ create trigger trigtest_b_row_tg before insert or update or delete on trigtest
+ for each row execute 

Re: [PATCHES] [HACKERS] Followup on the UnixWare Optimizer bug.

2005-08-24 Thread Bruce Momjian
Larry Rosenman wrote:
 The following is from my SCO Internal contact about the bug.  It's
 definitely their bug.  Towards the end of the
 Exact diagnosis, is a suggested work-around for now, as well as a (possible)
 memory leak.
...
 Also note that there appears to be a memory leak in the interval_
 routines.  For example interval_div() allocates a result Interval.
 It eventually passes this result through to interval_justify_hours() which
 allocates another Interval result and that result is what gets passed
 back to caller on interval_div().  The 1st Interval allocated appears to be
 left around...

Good catch on the memory leak.  I have applied the following fix. 
Thanks to SCO for the report.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (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/func.sgml
===
RCS file: /cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.282
diff -c -c -r1.282 func.sgml
*** doc/src/sgml/func.sgml  24 Aug 2005 20:49:35 -  1.282
--- doc/src/sgml/func.sgml  25 Aug 2005 01:26:36 -
***
*** 5189,5194 
--- 5189,5200 
  /table
  
 para
+ If you are using both functionjustify_hours/ and 
functionjustify_days/,
+ it is best to use functionjustify_hours/ first so any additional days 
will
+ justified by functionjustify_days/.
+/para
+ 
+para
  In addition to these functions, the SQL literalOVERLAPS/ operator is
  supported:
  synopsis
Index: src/backend/utils/adt/timestamp.c
===
RCS file: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v
retrieving revision 1.148
diff -c -c -r1.148 timestamp.c
*** src/backend/utils/adt/timestamp.c   12 Aug 2005 18:23:54 -  1.148
--- src/backend/utils/adt/timestamp.c   25 Aug 2005 01:26:39 -
***
*** 1892,1898 
  {
Timestamp   dt1 = PG_GETARG_TIMESTAMP(0);
Timestamp   dt2 = PG_GETARG_TIMESTAMP(1);
!   Interval   *result;
  
result = (Interval *) palloc(sizeof(Interval));
  
--- 1892,1898 
  {
Timestamp   dt1 = PG_GETARG_TIMESTAMP(0);
Timestamp   dt2 = PG_GETARG_TIMESTAMP(1);
!   Interval   *result, *result2;
  
result = (Interval *) palloc(sizeof(Interval));
  
***
*** 1914,1922 
result-month = 0;
result-day = 0;
  
!   result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,

IntervalPGetDatum(result)));
!   PG_RETURN_INTERVAL_P(result);
  }
  
  /*interval_justify_hours()
--- 1914,1923 
result-month = 0;
result-day = 0;
  
!   result2 = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,

IntervalPGetDatum(result)));
!   pfree(result);
!   PG_RETURN_INTERVAL_P(result2);
  }
  
  /*interval_justify_hours()
***
*** 2263,2269 
Interval   *span = PG_GETARG_INTERVAL_P(0);
float8  factor = PG_GETARG_FLOAT8(1);
double  month_remainder, day_remainder;
!   Interval   *result;
  
result = (Interval *) palloc(sizeof(Interval));
  
--- 2264,2270 
Interval   *span = PG_GETARG_INTERVAL_P(0);
float8  factor = PG_GETARG_FLOAT8(1);
double  month_remainder, day_remainder;
!   Interval   *result, *result2;
  
result = (Interval *) palloc(sizeof(Interval));
  
***
*** 2289,2297 
day_remainder * SECS_PER_DAY);
  #endif
  
!   result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,

IntervalPGetDatum(result)));
!   PG_RETURN_INTERVAL_P(result);
  }
  
  Datum
--- 2290,2299 
day_remainder * SECS_PER_DAY);
  #endif
  
!   result2 = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,

IntervalPGetDatum(result)));
!   pfree(result);
!   PG_RETURN_INTERVAL_P(result2);
  }
  
  Datum
***
*** 2310,2316 
Interval   *span = PG_GETARG_INTERVAL_P(0);
float8  factor = PG_GETARG_FLOAT8(1);
double  month_remainder, day_remainder;
!   Interval   *result;
  
result = (Interval *) palloc(sizeof(Interval));
  
--- 2312,2318 
Interval   *span = PG_GETARG_INTERVAL_P(0);
  

Re: [HACKERS] [PATCHES] Proposed patch to getaddrinfo.c to support

2005-08-24 Thread Bruce Momjian

Does this fix IPv6 on Win32?

---

Tom Lane wrote:
 Andrew Dunstan [EMAIL PROTECTED] writes:
  Context diff, please, diff -c.
 
  It needed dos2unix and pgindent as well. Here's a cleaned patch.
  Thanks to Chuck for doing this work.
 
 Applied, thanks.
 
   regards, tom lane
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (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: 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] [PATCHES] Proposed patch to getaddrinfo.c to support

2005-08-24 Thread Tom Lane
Andrew Dunstan [EMAIL PROTECTED] writes:
 Context diff, please, diff -c.

 It needed dos2unix and pgindent as well. Here's a cleaned patch.
 Thanks to Chuck for doing this work.

Applied, thanks.

regards, tom lane

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

   http://www.postgresql.org/docs/faq


Re: [HACKERS] [PATCHES] Proposed patch to getaddrinfo.c to support

2005-08-24 Thread Andrew Dunstan
Bruce Momjian said:

 OK, we need text for the release notes.  What would it be?

How about this?:

. Support for connections over IPv6 on Windows platforms capable of it.
(Chuck McDevitt, Petr Jelinek, Magnus Hagander, Andrew Dunstan).


cheers

andrew





---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [HACKERS] [PATCHES] Proposed patch to getaddrinfo.c to support

2005-08-24 Thread Bruce Momjian

OK, we need text for the release notes.  What would it be?

---

Andrew Dunstan wrote:
 
 
 I believe so, yes, although I think that we should remove the
 HAVE_GETADDRINFO compile time test that Tom built into initdb.c the other
 day, so that it can fall through to this code.
 
 cheers
 
 andrew
 
 Bruce Momjian said:
 
  Does this fix IPv6 on Win32?
 
  ---
 
  Tom Lane wrote:
  Andrew Dunstan [EMAIL PROTECTED] writes:
   Context diff, please, diff -c.
 
   It needed dos2unix and pgindent as well. Here's a cleaned patch.
   Thanks to Chuck for doing this work.
 
  Applied, thanks.
 
 
 
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (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: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [HACKERS] [PATCHES] Proposed patch to getaddrinfo.c to support

2005-08-24 Thread Andrew Dunstan


I believe so, yes, although I think that we should remove the
HAVE_GETADDRINFO compile time test that Tom built into initdb.c the other
day, so that it can fall through to this code.

cheers

andrew

Bruce Momjian said:

 Does this fix IPv6 on Win32?

 ---

 Tom Lane wrote:
 Andrew Dunstan [EMAIL PROTECTED] writes:
  Context diff, please, diff -c.

  It needed dos2unix and pgindent as well. Here's a cleaned patch.
  Thanks to Chuck for doing this work.

 Applied, thanks.





---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


Re: [HACKERS] [PATCHES] Proposed patch to getaddrinfo.c to support

2005-08-24 Thread Bruce Momjian

Thanks, added.

---

Andrew Dunstan wrote:
 Bruce Momjian said:
 
  OK, we need text for the release notes.  What would it be?
 
 How about this?:
 
 . Support for connections over IPv6 on Windows platforms capable of it.
 (Chuck McDevitt, Petr Jelinek, Magnus Hagander, Andrew Dunstan).
 
 
 cheers
 
 andrew
 
 
 
 
 
 ---(end of broadcast)---
 TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (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 6: explain analyze is your friend


Re: [HACKERS] [PATCHES] Proposed patch to getaddrinfo.c to support

2005-08-24 Thread Tom Lane
Andrew Dunstan [EMAIL PROTECTED] writes:
 I believe so, yes, although I think that we should remove the
 HAVE_GETADDRINFO compile time test that Tom built into initdb.c the other
 day, so that it can fall through to this code.

Will do.  BTW, when we are using getaddrinfo.c, is the gai_strerror
routine therein sufficient for Windows?

regards, tom lane

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


Re: [PATCHES] [HACKERS] Followup on the UnixWare Optimizer bug.

2005-08-24 Thread Tom Lane
Bruce Momjian pgman@candle.pha.pa.us writes:
 Good catch on the memory leak.  I have applied the following fix. 

These explicit pfrees are a waste of time, and probably actually
counterproductive as far as speed goes, because these functions
will always be invoked in relatively short-lived memory contexts.

I wouldn't object except that they seem to make the code noticeably
more obscure.

regards, tom lane

---(end of broadcast)---
TIP 1: 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