compilation problem on AIX

Started by Peter Gucwaover 27 years ago8 messages
#1Peter Gucwa
pg@softcomputer.com

Does somebody have solution for this problem that was discussed here a month ago?

the stream functions on AIX need a size_t for addrlen's in fe-connect.c and pqcomm.c.
This has come up before. AIX wants size_t for certain structures like

getsockname(). I believe the third parameter on AIX is size_t, while it
used to be int on my machine, but is not socklen_t. Is this correct?
The 'int' code works fine for me, but I can see why AIX is having a
problem, and perhaps it is time for configure to check on the various
types.

getsockname(int s, struct sockaddr *name, socklen_t *namelen);

Ok, so this gets tricky. In 4.2.1 it is size_t and in 4.3.1 it is as above with socklen_t :-(

Peter Gucwa

#2Marc G. Fournier
scrappy@hub.org
In reply to: Peter Gucwa (#1)
Re: [HACKERS] compilation problem on AIX

On Mon, 12 Oct 1998, Peter Gucwa wrote:

Does somebody have solution for this problem that was discussed here a month ago?

the stream functions on AIX need a size_t for addrlen's in fe-connect.c and pqcomm.c.
This has come up before. AIX wants size_t for certain structures like

getsockname(). I believe the third parameter on AIX is size_t, while it
used to be int on my machine, but is not socklen_t. Is this correct?
The 'int' code works fine for me, but I can see why AIX is having a
problem, and perhaps it is time for configure to check on the various
types.

getsockname(int s, struct sockaddr *name, socklen_t *namelen);

Ok, so this gets tricky. In 4.2.1 it is size_t and in 4.3.1 it is as
above with socklen_t :-(

If someone can make me a *short* code stub that fails to compile depending
on which is used, I can add this to configure...

Marc G. Fournier scrappy@hub.org
Systems Administrator @ hub.org
scrappy@{postgresql|isc}.org ICQ#7615664

#3Andreas Zeugswetter
andreas.zeugswetter@telecom.at
In reply to: Marc G. Fournier (#2)
AW: compilation problem on AIX

Does somebody have solution for this problem that was discussed here a month ago?

the stream functions on AIX need a size_t for addrlen's in fe-connect.c and pqcomm.c.
This has come up before. AIX wants size_t for certain structures like

getsockname(). I believe the third parameter on AIX is size_t, while it
used to be int on my machine, but is not socklen_t. Is this correct?
The 'int' code works fine for me, but I can see why AIX is having a
problem, and perhaps it is time for configure to check on the various
types.

getsockname(int s, struct sockaddr *name, socklen_t *namelen);

Ok, so this gets tricky. In 4.2.1 it is size_t and in 4.3.1 it is as above with socklen_t :-(

I would simply do:

#ifndef size_t
typedef int size_t
#endif

#ifndef socklen_t
typedef size_t socklen_t
#endif

and use socklen_t which is now standard for socket functions

Andreas

PS.: I am back from "vacation" and am now happy father of our 16 day old daughter Hannah :-)

#4Thomas G. Lockhart
lockhart@alumni.caltech.edu
In reply to: Andreas Zeugswetter (#3)
Re: [HACKERS] AW: compilation problem on AIX

PS.: I am back from "vacation" and am now happy father of our 16 day
old daughter Hannah :-)

Congratulations! We'll smoke a virtual cigar to celebrate.

- Tom

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas G. Lockhart (#4)
Re: [HACKERS] AW: compilation problem on AIX

Andreas Zeugswetter <andreas.zeugswetter@telecom.at> writes:

I would simply do:

#ifndef size_t
typedef int size_t
#endif

#ifndef socklen_t
typedef size_t socklen_t
#endif

That has no hope of working, since typedefs generally are not macros.

Marc had the right idea: a configure test is the only real way to
discover how getsockname() is declared. A small problem is that
configure can only detect outright compilation failures, not warnings.
That's probably good enough, but people with nonstandard definitions
of getsockname may have to live with looking at warnings.

and use socklen_t which is now standard for socket functions

It is? The machines I have access to think the parameter is plain,
unvarnished "int".

regards, tom lane

#6Taral
taral@mail.utexas.edu
In reply to: Tom Lane (#5)
RE: [HACKERS] AW: compilation problem on AIX

Marc had the right idea: a configure test is the only real way to
discover how getsockname() is declared. A small problem is that
configure can only detect outright compilation failures, not warnings.
That's probably good enough, but people with nonstandard definitions
of getsockname may have to live with looking at warnings.

Just redeclare the function with the parameters you expect. Most compilers
will fail if you redeclare with parameters of different types or different
number of parameters, but silently ignore functionally identical prototype
lines.

Taral

#7Peter Gucwa
pg@softcomputer.com
In reply to: Taral (#6)
RE: [HACKERS] compilation problem on AIX

Here are patches needed to complie under AIX 4.2.
I changed configure.in, pqcomm.c, config.h.in, and fe-connect.c.
Also I had to install flex because lex did not want to translate pgc.l.

*** configure.in	Tue Oct 13 14:05:50 1998
--- configure.in.orig	Tue Oct 13 14:02:18 1998
***************
*** 444,458 ****
  AC_HEADER_TIME
  AC_STRUCT_TM
- AC_MSG_CHECKING(for type of last arg to accept)
- AC_TRY_COMPILE([#include <stdlib.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- ],
- [int a = accept(1, (struct sockaddr *) 0, (size_t *) 0);],
- [AC_DEFINE(SOCKET_SIZE_TYPE, size_t) AC_MSG_RESULT(size_t)],
- [AC_DEFINE(SOCKET_SIZE_TYPE, int) AC_MSG_RESULT(int)])
- 
  dnl Check for any "odd" conditions
  AC_MSG_CHECKING(for int timezone)
  AC_TRY_LINK([#include <time.h>],
--- 444,449 ----
*** pqcomm.c	Tue Oct 13 15:11:56 1998
--- pqcomm.c.orig	Tue Oct 13 14:48:44 1998
***************
*** 660,667 ****
  int
  StreamConnection(int server_fd, Port *port)
  {
! 	int			len;
! 	SOCKET_SIZE_TYPE	addrlen;
  	int			family = port->raddr.sa.sa_family;
  	/* accept connection (and fill in the client (remote) address) */
--- 660,667 ----
  int
  StreamConnection(int server_fd, Port *port)
  {
! 	int			len,
! 				addrlen;
  	int			family = port->raddr.sa.sa_family;

/* accept connection (and fill in the client (remote) address) */
***************
*** 732,739 ****
int
StreamOpen(char *hostName, short portName, Port *port)
{
! SOCKET_SIZE_TYPE len;
! int err;
struct hostent *hp;
extern int errno;

--- 732,739 ----
  int
  StreamOpen(char *hostName, short portName, Port *port)
  {
! 	int			len,
! 				err;
  	struct hostent *hp;
  	extern int	errno;
*** config.h.in	Tue Oct 13 14:32:40 1998
--- config.h.in.orig	Tue Oct 13 14:33:28 1998
***************
*** 210,218 ****
  /* Set to 1 if you want to Enable ASSERT CHECKING */
  #undef USE_ASSERT_CHECKING
- /* Define as the base type of the last arg to accept */
- #undef SOCKET_SIZE_TYPE
- 
  /*
   * Code below this point should not require changes
   */
--- 210,215 ----
*** fe-connect.c	Tue Oct 13 15:20:14 1998
--- fe-connect.c.orig	Tue Oct 13 15:19:10 1998
***************
*** 472,478 ****
  	StartupPacket sp;
  	AuthRequest areq;
! 	SOCKET_SIZE_TYPE	laddrlen = sizeof(SockAddr);
  	int			portno,
  				family,
  				len;
--- 472,478 ----

StartupPacket sp;
AuthRequest areq;
! int laddrlen = sizeof(SockAddr);
int portno,
family,
len;

-----Original Message-----
From: Marc G. Fournier [SMTP:scrappy@hub.org]
Sent: Monday, October 12, 1998 8:38 PM
To: Peter Gucwa
Cc: 'hackers@postgresql.org'; 'andreas.zeugswetter@telecom.at'
Subject: Re: [HACKERS] compilation problem on AIX

On Mon, 12 Oct 1998, Peter Gucwa wrote:

Does somebody have solution for this problem that was discussed here a month ago?

the stream functions on AIX need a size_t for addrlen's in fe-connect.c and pqcomm.c.
This has come up before. AIX wants size_t for certain structures like

getsockname(). I believe the third parameter on AIX is size_t, while it
used to be int on my machine, but is not socklen_t. Is this correct?
The 'int' code works fine for me, but I can see why AIX is having a
problem, and perhaps it is time for configure to check on the various
types.

getsockname(int s, struct sockaddr *name, socklen_t *namelen);

Ok, so this gets tricky. In 4.2.1 it is size_t and in 4.3.1 it is as
above with socklen_t :-(

If someone can make me a *short* code stub that fails to compile depending
on which is used, I can add this to configure...

Marc G. Fournier scrappy@hub.org
Systems Administrator @ hub.org
scrappy@{postgresql|isc}.org ICQ#7615664

#8Taral
taral@mail.utexas.edu
In reply to: Peter Gucwa (#7)
RE: [HACKERS] compilation problem on AIX

getsockname(int s, struct sockaddr *name, socklen_t *namelen);

Ok, so this gets tricky. In 4.2.1 it is size_t and in 4.3.1 it is as
above with socklen_t :-(

If someone can make me a *short* code stub that fails to compile depending
on which is used, I can add this to configure...

--- cut here ---
#include <sys/socket.h>

int getsockname(int, struct sockaddr *, socklen_t *);

int x() {return 0;}
--- cut here ---

If your compiler insists on size_t instead of socklen_t, this will fail with
an error.

My test (since linux doesn't care):

test.c:
extern int x(int);

extern int x(long);

% gcc -c test.c
~
test.c:3: conflicting types for `x'
test.c:1: previous declaration of `x'
% echo $?
~
1

Enjoy.

Taral