Thread: Threading fix for AIX

Threading fix for AIX

From
Bruce Momjian
Date:
Zeugswetter Andreas DAZ SD wrote:
>
> >> However, one thing we can do is to try this in Makefile.aix:
> >>     # AIX needs threads for everything that uses libpq
> >>     LIBS += $(PTHREAD_LIBS)
> >> That is going to enable thread libs for all linking including the
> >> backend, but it might work.
>
> > That is certainly wrong.  The correct thing is to add PTHREAD_LIBS to
> > all and only those links that include libpq.  I suspect that the cc_r
>
> You mean like attached patch ? That is safe and can be applied.
> My machine has problems with two configure tests with --enable-thread-safety.
>
> 1. the snprintf long long int check that uses int64 as variable name which is
>     a typedef in sys/inttypes.h

I changed it to ac_int64.  Does that help?

> 2. whether strerror_r returns int check fails with a redefine of named function
>     from string.h

I see.  Our test is:

    int strerror_r(int, char *, size_t);

but AIX is:

    int  strerror_r(int, char *, int);

OK, I added an #ifndef _AIX to use 'int' for the 3rd arg for AIX.

> No idea how to fix those, but workaround is easy :-(
>
> -lpthread can be removed from PTHREAD_LIBS, the lib is a compat symlink to
> -lpthreads, I guess it does not hurt eighter.

Yea, that is an effect of the tests we use and accumulate flags rather
than taking the first one that works.  The test tests compiling but
creating libraries that use threads actually needs more than one flag on
some platforms so we just take all flags we can.

It would be nice if your fix also helped unixware but that needs
compilere flags for any thread library usage and we don't have
centralized libpq-specific compiler flags like we have library flags.

Please test this patch and report back.  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
Index: configure
===================================================================
RCS file: /cvsroot/pgsql/configure,v
retrieving revision 1.413
diff -c -c -r1.413 configure
*** configure    3 Dec 2004 22:24:53 -0000    1.413
--- configure    14 Dec 2004 12:37:08 -0000
***************
*** 14608,14614 ****
--- 14608,14617 ----
  int
  main ()
  {
+ ifndef _AIX
  int strerror_r(int, char *, size_t);
+ #else
+ int strerror_r(int, char *, int);
    ;
    return 0;
  }
***************
*** 14758,14777 ****
    cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
! typedef long int int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_work()
  {
!   int64 c,d;

!   if (sizeof(int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
--- 14761,14780 ----
    cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
! typedef long int ac_int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_work()
  {
!   ac_int64 c,d;

!   if (sizeof(ac_int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
***************
*** 14872,14891 ****
    cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
! typedef long long int int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_work()
  {
!   int64 c,d;

!   if (sizeof(int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
--- 14875,14894 ----
    cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
! typedef long long int ac_int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_work()
  {
!   ac_int64 c,d;

!   if (sizeof(ac_int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
Index: config/c-compiler.m4
===================================================================
RCS file: /cvsroot/pgsql/config/c-compiler.m4,v
retrieving revision 1.13
diff -c -c -r1.13 c-compiler.m4
*** config/c-compiler.m4    20 Oct 2004 02:12:07 -0000    1.13
--- config/c-compiler.m4    14 Dec 2004 12:37:09 -0000
***************
*** 26,45 ****
  define([Ac_cachevar], [translit([pgac_cv_type_$1_64], [ *], [_p])])dnl
  AC_CACHE_CHECK([whether $1 is 64 bits], [Ac_cachevar],
  [AC_TRY_RUN(
! [typedef $1 int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_work()
  {
!   int64 c,d;

!   if (sizeof(int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
--- 26,45 ----
  define([Ac_cachevar], [translit([pgac_cv_type_$1_64], [ *], [_p])])dnl
  AC_CACHE_CHECK([whether $1 is 64 bits], [Ac_cachevar],
  [AC_TRY_RUN(
! [typedef $1 ac_int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_work()
  {
!   ac_int64 c,d;

!   if (sizeof(ac_int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
Index: config/c-library.m4
===================================================================
RCS file: /cvsroot/pgsql/config/c-library.m4,v
retrieving revision 1.28
diff -c -c -r1.28 c-library.m4
*** config/c-library.m4    4 Oct 2004 18:14:18 -0000    1.28
--- config/c-library.m4    14 Dec 2004 12:37:09 -0000
***************
*** 108,114 ****
  [AC_CACHE_CHECK(whether strerror_r returns int,
  pgac_func_strerror_r_int,
  [AC_TRY_COMPILE([#include <string.h>],
! [int strerror_r(int, char *, size_t);],
  [pgac_func_strerror_r_int=yes],
  [pgac_func_strerror_r_int=no])])
  if test x"$pgac_func_strerror_r_int" = xyes ; then
--- 108,117 ----
  [AC_CACHE_CHECK(whether strerror_r returns int,
  pgac_func_strerror_r_int,
  [AC_TRY_COMPILE([#include <string.h>],
! [ifndef _AIX
! int strerror_r(int, char *, size_t);
! #else
! int strerror_r(int, char *, int);],
  [pgac_func_strerror_r_int=yes],
  [pgac_func_strerror_r_int=no])])
  if test x"$pgac_func_strerror_r_int" = xyes ; then
Index: src/Makefile.global.in
===================================================================
RCS file: /cvsroot/pgsql/src/Makefile.global.in,v
retrieving revision 1.205
diff -c -c -r1.205 Makefile.global.in
*** src/Makefile.global.in    19 Nov 2004 00:41:38 -0000    1.205
--- src/Makefile.global.in    14 Dec 2004 12:37:14 -0000
***************
*** 308,313 ****
--- 308,319 ----

  libpq = -L$(libpq_builddir) -lpq

+ # AIX libraries do not remember their required libs so we have to force
+ # thread dependent libraires in the link
+ ifeq ($(PORTNAME), aix)
+ libpq += $(PTHREAD_LIBS)
+ endif
+
  submake-libpq:
      $(MAKE) -C $(libpq_builddir) all

Index: src/makefiles/Makefile.unixware
===================================================================
RCS file: /cvsroot/pgsql/src/makefiles/Makefile.unixware,v
retrieving revision 1.20
diff -c -c -r1.20 Makefile.unixware
*** src/makefiles/Makefile.unixware    19 Nov 2004 00:41:39 -0000    1.20
--- src/makefiles/Makefile.unixware    14 Dec 2004 12:37:21 -0000
***************
*** 33,37 ****

  # Unixware needs threads for everything that uses libpq
  CFLAGS += $(PTHREAD_CFLAGS)
-
-
--- 33,35 ----

Re: Threading fix for AIX

From
"Zeugswetter Andreas DAZ SD"
Date:
>> 1. the snprintf long long int check that uses int64 as variable name which is
>>     a typedef in sys/inttypes.h
>
> I changed it to ac_int64.  Does that help?

One more is needed in c-library.m4.

>> 2. whether strerror_r returns int check fails with a redefine of named function
>>     from string.h
>
> I see.  Our test is:
>     int strerror_r(int, char *, size_t);
> but AIX is:
>     int  strerror_r(int, char *, int);
> OK, I added an #ifndef _AIX to use 'int' for the 3rd arg for AIX.

The wrong define is only on older AIX versions :-(
And the patch produces wrong code asis (missing # and #endif).
Since AIX always has the int returning function, how about no test on AIX:
#ifndef_AIX
int strerror_r(int, char *, size_t);
#endif

> Please test this patch and report back.  Thanks.

attached is a reworked patch that works on aix 4.3.2 and 5.2, please check the configure part,
cause I don't have autoconf.

Andreas

Attachment

Re: Threading fix for AIX

From
Bruce Momjian
Date:
Zeugswetter Andreas DAZ SD wrote:
>
> >> 1. the snprintf long long int check that uses int64 as variable name which is
> >>     a typedef in sys/inttypes.h
> >
> > I changed it to ac_int64.  Does that help?
>
> One more is needed in c-library.m4.

OK, done.

> >> 2. whether strerror_r returns int check fails with a redefine of named function
> >>     from string.h
> >
> > I see.  Our test is:
> >     int strerror_r(int, char *, size_t);
> > but AIX is:
> >     int  strerror_r(int, char *, int);
> > OK, I added an #ifndef _AIX to use 'int' for the 3rd arg for AIX.
>
> The wrong define is only on older AIX versions :-(
> And the patch produces wrong code asis (missing # and #endif).
> Since AIX always has the int returning function, how about no test on AIX:
> #ifndef_AIX
> int strerror_r(int, char *, size_t);
> #endif

I would rather keep testing.  Hardcoding platforms stuff usually fails
in some way.

>
> > Please test this patch and report back.  Thanks.
>
> attached is a reworked patch that works on aix 4.3.2 and 5.2, please check the configure part,
> cause I don't have autoconf.

I modified my patch to fix the problems you reported.  Please report
back.

--
  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

Re: Threading fix for AIX

From
Bruce Momjian
Date:
Bruce Momjian wrote:
> > attached is a reworked patch that works on aix 4.3.2 and 5.2, please check the configure part,
> > cause I don't have autoconf.
>
> I modified my patch to fix the problems you reported.  Please report
> back.
>

Sorry, patch now attached.

--
  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: configure
===================================================================
RCS file: /cvsroot/pgsql/configure,v
retrieving revision 1.415
diff -c -c -r1.415 configure
*** configure    14 Dec 2004 14:53:52 -0000    1.415
--- configure    14 Dec 2004 19:57:53 -0000
***************
*** 14611,14617 ****
--- 14611,14621 ----
  int
  main ()
  {
+ #ifndef _AIX
  int strerror_r(int, char *, size_t);
+ #else
+ int strerror_r(int, char *, int);
+ #endif
    ;
    return 0;
  }
***************
*** 14761,14780 ****
    cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
! typedef long int int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_work()
  {
!   int64 c,d;

!   if (sizeof(int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
--- 14765,14784 ----
    cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
! typedef long int ac_int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_work()
  {
!   ac_int64 c,d;

!   if (sizeof(ac_int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
***************
*** 14875,14894 ****
    cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
! typedef long long int int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_work()
  {
!   int64 c,d;

!   if (sizeof(int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
--- 14879,14898 ----
    cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
! typedef long long int ac_int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_work()
  {
!   ac_int64 c,d;

!   if (sizeof(ac_int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
***************
*** 15007,15024 ****
  #line $LINENO "configure"
  #include "confdefs.h"
  #include <stdio.h>
! typedef long long int int64;
  #define INT64_FORMAT "$pgac_format"

! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_snprintf_work()
  {
!   int64 c;
    char buf[100];

!   if (sizeof(int64) != 8)
      return 0;            /* doesn't look like the right size */

    c = a * b;
--- 15011,15028 ----
  #line $LINENO "configure"
  #include "confdefs.h"
  #include <stdio.h>
! typedef long long int ac_int64;
  #define INT64_FORMAT "$pgac_format"

! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_snprintf_work()
  {
!   ac_int64 c;
    char buf[100];

!   if (sizeof(ac_int64) != 8)
      return 0;            /* doesn't look like the right size */

    c = a * b;
Index: config/c-compiler.m4
===================================================================
RCS file: /cvsroot/pgsql/config/c-compiler.m4,v
retrieving revision 1.13
diff -c -c -r1.13 c-compiler.m4
*** config/c-compiler.m4    20 Oct 2004 02:12:07 -0000    1.13
--- config/c-compiler.m4    14 Dec 2004 19:57:53 -0000
***************
*** 26,45 ****
  define([Ac_cachevar], [translit([pgac_cv_type_$1_64], [ *], [_p])])dnl
  AC_CACHE_CHECK([whether $1 is 64 bits], [Ac_cachevar],
  [AC_TRY_RUN(
! [typedef $1 int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_work()
  {
!   int64 c,d;

!   if (sizeof(int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
--- 26,45 ----
  define([Ac_cachevar], [translit([pgac_cv_type_$1_64], [ *], [_p])])dnl
  AC_CACHE_CHECK([whether $1 is 64 bits], [Ac_cachevar],
  [AC_TRY_RUN(
! [typedef $1 ac_int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_work()
  {
!   ac_int64 c,d;

!   if (sizeof(ac_int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
Index: config/c-library.m4
===================================================================
RCS file: /cvsroot/pgsql/config/c-library.m4,v
retrieving revision 1.28
diff -c -c -r1.28 c-library.m4
*** config/c-library.m4    4 Oct 2004 18:14:18 -0000    1.28
--- config/c-library.m4    14 Dec 2004 19:57:54 -0000
***************
*** 108,114 ****
  [AC_CACHE_CHECK(whether strerror_r returns int,
  pgac_func_strerror_r_int,
  [AC_TRY_COMPILE([#include <string.h>],
! [int strerror_r(int, char *, size_t);],
  [pgac_func_strerror_r_int=yes],
  [pgac_func_strerror_r_int=no])])
  if test x"$pgac_func_strerror_r_int" = xyes ; then
--- 108,118 ----
  [AC_CACHE_CHECK(whether strerror_r returns int,
  pgac_func_strerror_r_int,
  [AC_TRY_COMPILE([#include <string.h>],
! [#ifndef _AIX
! int strerror_r(int, char *, size_t);
! #else
! int strerror_r(int, char *, int);
! #endif],
  [pgac_func_strerror_r_int=yes],
  [pgac_func_strerror_r_int=no])])
  if test x"$pgac_func_strerror_r_int" = xyes ; then
***************
*** 225,242 ****
  AC_CACHE_VAL(pgac_cv_snprintf_long_long_int_format,
  [for pgac_format in '%lld' '%qd' '%I64d'; do
  AC_TRY_RUN([#include <stdio.h>
! typedef long long int int64;
  #define INT64_FORMAT "$pgac_format"

! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_snprintf_work()
  {
!   int64 c;
    char buf[100];

!   if (sizeof(int64) != 8)
      return 0;            /* doesn't look like the right size */

    c = a * b;
--- 229,246 ----
  AC_CACHE_VAL(pgac_cv_snprintf_long_long_int_format,
  [for pgac_format in '%lld' '%qd' '%I64d'; do
  AC_TRY_RUN([#include <stdio.h>
! typedef long long int ac_int64;
  #define INT64_FORMAT "$pgac_format"

! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_snprintf_work()
  {
!   ac_int64 c;
    char buf[100];

!   if (sizeof(ac_int64) != 8)
      return 0;            /* doesn't look like the right size */

    c = a * b;
Index: src/Makefile.global.in
===================================================================
RCS file: /cvsroot/pgsql/src/Makefile.global.in,v
retrieving revision 1.205
diff -c -c -r1.205 Makefile.global.in
*** src/Makefile.global.in    19 Nov 2004 00:41:38 -0000    1.205
--- src/Makefile.global.in    14 Dec 2004 19:57:58 -0000
***************
*** 308,313 ****
--- 308,319 ----

  libpq = -L$(libpq_builddir) -lpq

+ # AIX libraries do not remember their required libs so we have to force
+ # thread dependent libraires in the link
+ ifeq ($(PORTNAME), aix)
+ libpq += $(PTHREAD_LIBS)
+ endif
+
  submake-libpq:
      $(MAKE) -C $(libpq_builddir) all

***************
*** 346,358 ****
  endif

  ifdef COPT
!    CFLAGS+= $(COPT)
!    LDFLAGS+= $(COPT)
  endif

  ifdef PROFILE
!    CFLAGS+= $(PROFILE)
!    LDFLAGS+= $(PROFILE)
  endif


--- 352,364 ----
  endif

  ifdef COPT
!    CFLAGS += $(COPT)
!    LDFLAGS += $(COPT)
  endif

  ifdef PROFILE
!    CFLAGS += $(PROFILE)
!    LDFLAGS += $(PROFILE)
  endif


Index: src/makefiles/Makefile.unixware
===================================================================
RCS file: /cvsroot/pgsql/src/makefiles/Makefile.unixware,v
retrieving revision 1.20
diff -c -c -r1.20 Makefile.unixware
*** src/makefiles/Makefile.unixware    19 Nov 2004 00:41:39 -0000    1.20
--- src/makefiles/Makefile.unixware    14 Dec 2004 19:58:05 -0000
***************
*** 33,37 ****

  # Unixware needs threads for everything that uses libpq
  CFLAGS += $(PTHREAD_CFLAGS)
-
-
--- 33,35 ----

Re: Threading fix for AIX

From
Bruce Momjian
Date:
Bruce Momjian wrote:
> Zeugswetter Andreas DAZ SD wrote:
> >
> > >> 1. the snprintf long long int check that uses int64 as variable name which is
> > >>     a typedef in sys/inttypes.h
> > >
> > > I changed it to ac_int64.  Does that help?
> >
> > One more is needed in c-library.m4.
>
> OK, done.
>
> > >> 2. whether strerror_r returns int check fails with a redefine of named function
> > >>     from string.h
> > >
> > > I see.  Our test is:
> > >     int strerror_r(int, char *, size_t);
> > > but AIX is:
> > >     int  strerror_r(int, char *, int);
> > > OK, I added an #ifndef _AIX to use 'int' for the 3rd arg for AIX.
> >
> > The wrong define is only on older AIX versions :-(
> > And the patch produces wrong code asis (missing # and #endif).
> > Since AIX always has the int returning function, how about no test on AIX:
> > #ifndef_AIX
> > int strerror_r(int, char *, size_t);
> > #endif

OK, improved patch.  You mentioned only older versions of AIX have an
'int' for the 3rd strerror_r argument so we will just test for the
return value on AIX and not the args:

    int strerror();

If there are other platforms that have this we could use it on all
platforms but at this point we will do just AIX.

--
  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: configure
===================================================================
RCS file: /cvsroot/pgsql/configure,v
retrieving revision 1.415
diff -c -c -r1.415 configure
*** configure    14 Dec 2004 14:53:52 -0000    1.415
--- configure    15 Dec 2004 17:53:04 -0000
***************
*** 14611,14617 ****
--- 14611,14622 ----
  int
  main ()
  {
+ #ifndef _AIX
  int strerror_r(int, char *, size_t);
+ #else
+ /* Older AIX has 'int' for the third argument so we don't test the args. */
+ int strerror_r();
+ #endif
    ;
    return 0;
  }
***************
*** 14761,14780 ****
    cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
! typedef long int int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_work()
  {
!   int64 c,d;

!   if (sizeof(int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
--- 14766,14785 ----
    cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
! typedef long int ac_int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_work()
  {
!   ac_int64 c,d;

!   if (sizeof(ac_int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
***************
*** 14875,14894 ****
    cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
! typedef long long int int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_work()
  {
!   int64 c,d;

!   if (sizeof(int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
--- 14880,14899 ----
    cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
! typedef long long int ac_int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_work()
  {
!   ac_int64 c,d;

!   if (sizeof(ac_int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
***************
*** 15007,15024 ****
  #line $LINENO "configure"
  #include "confdefs.h"
  #include <stdio.h>
! typedef long long int int64;
  #define INT64_FORMAT "$pgac_format"

! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_snprintf_work()
  {
!   int64 c;
    char buf[100];

!   if (sizeof(int64) != 8)
      return 0;            /* doesn't look like the right size */

    c = a * b;
--- 15012,15029 ----
  #line $LINENO "configure"
  #include "confdefs.h"
  #include <stdio.h>
! typedef long long int ac_int64;
  #define INT64_FORMAT "$pgac_format"

! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_snprintf_work()
  {
!   ac_int64 c;
    char buf[100];

!   if (sizeof(ac_int64) != 8)
      return 0;            /* doesn't look like the right size */

    c = a * b;
Index: config/c-compiler.m4
===================================================================
RCS file: /cvsroot/pgsql/config/c-compiler.m4,v
retrieving revision 1.13
diff -c -c -r1.13 c-compiler.m4
*** config/c-compiler.m4    20 Oct 2004 02:12:07 -0000    1.13
--- config/c-compiler.m4    15 Dec 2004 17:53:04 -0000
***************
*** 26,45 ****
  define([Ac_cachevar], [translit([pgac_cv_type_$1_64], [ *], [_p])])dnl
  AC_CACHE_CHECK([whether $1 is 64 bits], [Ac_cachevar],
  [AC_TRY_RUN(
! [typedef $1 int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_work()
  {
!   int64 c,d;

!   if (sizeof(int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
--- 26,45 ----
  define([Ac_cachevar], [translit([pgac_cv_type_$1_64], [ *], [_p])])dnl
  AC_CACHE_CHECK([whether $1 is 64 bits], [Ac_cachevar],
  [AC_TRY_RUN(
! [typedef $1 ac_int64;

  /*
   * These are globals to discourage the compiler from folding all the
   * arithmetic tests down to compile-time constants.
   */
! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_work()
  {
!   ac_int64 c,d;

!   if (sizeof(ac_int64) != 8)
      return 0;            /* definitely not the right size */

    /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
Index: config/c-library.m4
===================================================================
RCS file: /cvsroot/pgsql/config/c-library.m4,v
retrieving revision 1.28
diff -c -c -r1.28 c-library.m4
*** config/c-library.m4    4 Oct 2004 18:14:18 -0000    1.28
--- config/c-library.m4    15 Dec 2004 17:53:04 -0000
***************
*** 108,114 ****
  [AC_CACHE_CHECK(whether strerror_r returns int,
  pgac_func_strerror_r_int,
  [AC_TRY_COMPILE([#include <string.h>],
! [int strerror_r(int, char *, size_t);],
  [pgac_func_strerror_r_int=yes],
  [pgac_func_strerror_r_int=no])])
  if test x"$pgac_func_strerror_r_int" = xyes ; then
--- 108,119 ----
  [AC_CACHE_CHECK(whether strerror_r returns int,
  pgac_func_strerror_r_int,
  [AC_TRY_COMPILE([#include <string.h>],
! [#ifndef _AIX
! int strerror_r(int, char *, size_t);
! #else
! /* Older AIX has 'int' for the third argument so we don't test the args. */
! int strerror_r();
! #endif],
  [pgac_func_strerror_r_int=yes],
  [pgac_func_strerror_r_int=no])])
  if test x"$pgac_func_strerror_r_int" = xyes ; then
***************
*** 225,242 ****
  AC_CACHE_VAL(pgac_cv_snprintf_long_long_int_format,
  [for pgac_format in '%lld' '%qd' '%I64d'; do
  AC_TRY_RUN([#include <stdio.h>
! typedef long long int int64;
  #define INT64_FORMAT "$pgac_format"

! int64 a = 20000001;
! int64 b = 40000005;

  int does_int64_snprintf_work()
  {
!   int64 c;
    char buf[100];

!   if (sizeof(int64) != 8)
      return 0;            /* doesn't look like the right size */

    c = a * b;
--- 230,247 ----
  AC_CACHE_VAL(pgac_cv_snprintf_long_long_int_format,
  [for pgac_format in '%lld' '%qd' '%I64d'; do
  AC_TRY_RUN([#include <stdio.h>
! typedef long long int ac_int64;
  #define INT64_FORMAT "$pgac_format"

! ac_int64 a = 20000001;
! ac_int64 b = 40000005;

  int does_int64_snprintf_work()
  {
!   ac_int64 c;
    char buf[100];

!   if (sizeof(ac_int64) != 8)
      return 0;            /* doesn't look like the right size */

    c = a * b;
Index: src/Makefile.global.in
===================================================================
RCS file: /cvsroot/pgsql/src/Makefile.global.in,v
retrieving revision 1.205
diff -c -c -r1.205 Makefile.global.in
*** src/Makefile.global.in    19 Nov 2004 00:41:38 -0000    1.205
--- src/Makefile.global.in    15 Dec 2004 17:53:08 -0000
***************
*** 308,313 ****
--- 308,319 ----

  libpq = -L$(libpq_builddir) -lpq

+ # AIX libraries do not remember their required libs so we have to force
+ # thread dependent libraires in the link
+ ifeq ($(PORTNAME), aix)
+ libpq += $(PTHREAD_LIBS)
+ endif
+
  submake-libpq:
      $(MAKE) -C $(libpq_builddir) all

***************
*** 346,358 ****
  endif

  ifdef COPT
!    CFLAGS+= $(COPT)
!    LDFLAGS+= $(COPT)
  endif

  ifdef PROFILE
!    CFLAGS+= $(PROFILE)
!    LDFLAGS+= $(PROFILE)
  endif


--- 352,364 ----
  endif

  ifdef COPT
!    CFLAGS += $(COPT)
!    LDFLAGS += $(COPT)
  endif

  ifdef PROFILE
!    CFLAGS += $(PROFILE)
!    LDFLAGS += $(PROFILE)
  endif


Index: src/makefiles/Makefile.unixware
===================================================================
RCS file: /cvsroot/pgsql/src/makefiles/Makefile.unixware,v
retrieving revision 1.20
diff -c -c -r1.20 Makefile.unixware
*** src/makefiles/Makefile.unixware    19 Nov 2004 00:41:39 -0000    1.20
--- src/makefiles/Makefile.unixware    15 Dec 2004 17:53:12 -0000
***************
*** 33,37 ****

  # Unixware needs threads for everything that uses libpq
  CFLAGS += $(PTHREAD_CFLAGS)
-
-
--- 33,35 ----

Re: Threading fix for AIX

From
"Zeugswetter Andreas DAZ SD"
Date:
Bruce Momjian wrote:
> > Zeugswetter Andreas DAZ SD wrote:
> > >
> > > >> 1. the snprintf long long int check that uses int64 as variable name which is
> > > >>     a typedef in sys/inttypes.h
> > > >
> > > > I changed it to ac_int64.  Does that help?
> > >
> > > One more is needed in c-library.m4.
> >
> > OK, done.
> >
> > > >> 2. whether strerror_r returns int check fails with a redefine of named function
> > > >>     from string.h
> > > >
> > > > I see.  Our test is:
> > > >     int strerror_r(int, char *, size_t);
> > > > but AIX is:
> > > >     int  strerror_r(int, char *, int);
> > > > OK, I added an #ifndef _AIX to use 'int' for the 3rd arg for AIX.
> > >
> > > The wrong define is only on older AIX versions :-(
> > > And the patch produces wrong code asis (missing # and #endif).
> > > Since AIX always has the int returning function, how about no test on AIX:
> > > #ifndef_AIX
> > > int strerror_r(int, char *, size_t);
> > > #endif
>
> OK, improved patch.  You mentioned only older versions of AIX have an
> 'int' for the 3rd strerror_r argument so we will just test for the
> return value on AIX and not the args:
>
>     int strerror();
>
> If there are other platforms that have this we could use it on all
> platforms but at this point we will do just AIX.

That is the perfect patch. Thank you Bruce. All tests pass on AIX 4.3.2 and 5.2.0
with --enable-thread-safety and this last patch.

I am quite sure xlc_r is not needed to compile a thread safe libpq. Only those
writing threaded clients will want to use it for compiling and linking their
executables if they use usually not thread safe libc functions (like gethostbyname).

Andreas

Re: Threading fix for AIX

From
Bruce Momjian
Date:
Zeugswetter Andreas DAZ SD wrote:
> > If there are other platforms that have this we could use it on all
> > platforms but at this point we will do just AIX.
>
> That is the perfect patch. Thank you Bruce. All tests pass on AIX 4.3.2 and 5.2.0
> with --enable-thread-safety and this last patch.
>
> I am quite sure xlc_r is not needed to compile a thread safe libpq. Only those
> writing threaded clients will want to use it for compiling and linking their
> executables if they use usually not thread safe libc functions (like gethostbyname).

Great.  Patch applied.

--
  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