Re: ERRORDATA_STACK_SIZE panic crashes on Windows - Mailing list pgsql-hackers

From Tom Lane
Subject Re: ERRORDATA_STACK_SIZE panic crashes on Windows
Date
Msg-id 23227.1211822423@sss.pgh.pa.us
Whole thread Raw
In response to ERRORDATA_STACK_SIZE panic crashes on Windows  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: ERRORDATA_STACK_SIZE panic crashes on Windows  (Magnus Hagander <magnus@hagander.net>)
List pgsql-hackers
I wrote:
> Have any Windows-using hackers tried to look into the reports of
> $SUBJECT on 8.3?  We have two fresh reports:
> http://archives.postgresql.org/pgsql-bugs/2008-05/msg00106.php
> http://archives.postgresql.org/pgsql-bugs/2008-05/msg00109.php
> and this isn't the first time we've heard of it.

And now we have another report:
http://archives.postgresql.org/pgsql-bugs/2008-05/msg00159.php
for which the complainant was kind enough to supply the requested
details, and they seem to confirm my previous theory:

> What I'm currently thinking is that maybe gettext() isn't on the
> same page as us concerning what encoding it's supposed to produce
> its output in.

After digging around in the source code a bit, the reason why (and why
it's only seen on Windows) became blindingly obvious :-(.  On Windows
we specifically allow UTF-8 database encoding to be selected regardless
of the system locale settings.  This is (AFAIK) safe for the basic
locale-dependent stuff we do, because that all goes through special
UTF-16-using code paths.  But it leaves gettext utterly misinformed
about what it is supposed to do.

Fortunately there is a way to tell gettext what to do, and accordingly
I propose the attached patch.  I am not in a position to test it
however.  Would somebody replicate the failure and confirm this
fixes it?

            regards, tom lane

Index: mbutils.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/mb/mbutils.c,v
retrieving revision 1.70
diff -c -r1.70 mbutils.c
*** mbutils.c    12 Apr 2008 23:21:04 -0000    1.70
--- mbutils.c    26 May 2008 17:15:49 -0000
***************
*** 697,702 ****
--- 697,721 ----

      DatabaseEncoding = &pg_enc2name_tbl[encoding];
      Assert(DatabaseEncoding->encoding == encoding);
+
+     /*
+      * On Windows, we allow UTF-8 database encoding to be used with any
+      * locale setting, because UTF-8 requires special handling anyway.
+      * But this means that gettext() might be misled about what output
+      * encoding it should use, so we have to tell it explicitly.
+      *
+      * In future we might want to call bind_textdomain_codeset
+      * unconditionally, but that requires knowing how to spell the codeset
+      * name properly for all encodings on all platforms, which might be
+      * problematic.
+      *
+      * This is presently unnecessary, but harmless, on non-Windows platforms.
+      */
+ #ifdef ENABLE_NLS
+     if (encoding == PG_UTF8)
+         if (bind_textdomain_codeset("postgres", "UTF-8") == NULL)
+             elog(LOG, "bind_textdomain_codeset failed");
+ #endif
  }

  void

pgsql-hackers by date:

Previous
From: Hannu Krosing
Date:
Subject: Re: Read Uncommitted
Next
From: Tom Lane
Date:
Subject: Re: Read Uncommitted