[Python-bugs-list] [ python-Bugs-505427 ] socket module fails to build on HPUX10

noreply@sourceforge.net noreply@sourceforge.net
Tue, 12 Nov 2002 19:33:28 -0800


Bugs item #505427, was opened at 2002-01-18 11:12
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=505427&group_id=5470

Category: Build
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Eddy De Greef (edg)
>Assigned to: Martin v. Löwis (loewis)
Summary: socket module fails to build on HPUX10

Initial Comment:
On HPUX10, the variable h_errno is undeclared.
Modules/socketmodule.c, line 1975:

		PyH_Err(h_errno);

unless _XOPEN_SOURCE_EXTENDED is defined before
netdb.h is included.

Another option is to add an external declaration:

#ifdef __hpux
extern int h_errno;
#endif


----------------------------------------------------------------------

>Comment By: Neal Norwitz (nnorwitz)
Date: 2002-11-12 22:33

Message:
Logged In: YES 
user_id=33168

Martin, do you think it is acceptable to add the patch below
to the 2.2.2 branch?  Do you have any ideas for a better
patch?  I don't have access to HPUX 10, I only have access
to HPUX 11.

If this patch is acceptable, assign back to me.  I will test
it on HPUX 11 to make sure it doesn't break.

Eddy, if Martin accepts this, could you also test that patch
to verify that 2.2.2 works?

+++ Modules/socketmodule.c      13 Nov 2002 03:29:55 -0000
@@ -130,6 +130,9 @@
 #include <os2.h>
 #endif
 
+#if defined(__hpux)
+extern int h_errno;
+#endif
 
 #include <sys/types.h>


----------------------------------------------------------------------

Comment By: Eddy De Greef (edg)
Date: 2002-11-04 05:45

Message:
Logged In: YES 
user_id=73597

I've downloaded the latest 2.3 snapshot (11-4) and it is
indeed fixed, thanks.
Yes, I still had the problem with 2.2.2.


----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2002-11-02 15:07

Message:
Logged In: YES 
user_id=33168

Eddy, _XOPEN_SOURCE_EXTENDED is now defined in pyconfig.h
for 2.3.  Can you verify this fixes your problem?  Are you
still having a problem with 2.2.2?

----------------------------------------------------------------------

Comment By: Eddy De Greef (edg)
Date: 2002-01-22 04:41

Message:
Logged In: YES 
user_id=73597

On HPUX-10, the man page states the following:

  SYNOPSIS
       #include <sys/socket.h>
       #include <netinet/in.h>
       #include <netdb.h>

       extern int h_errno;

       struct hostent *gethostent(void);

       int gethostent_r(struct hostent *result,
                        struct hostent_data *buffer);

       struct hostent *gethostbyname(const char *name);

       int gethostbyname_r(const char *name,
                           struct hostent *result,
                           struct hostent_data *buffer);

       struct hostent *gethostbyaddr(const char *addr,
                                     int len,
                                     int type);

       _XOPEN_SOURCE_EXTENDED only
       struct hostent *gethostbyaddr(const void *addr,
                                     size_t len,
                                     int type);

       int gethostbyaddr_r(const char *addr,
                           int len,
                           int type,
                           struct hostent *result,
                           struct hostent_data *buffer);

       int sethostent(int stayopen);

       int sethostent_r(int stayopen, 
                        struct hostent_data *buffer);

       int endhostent(void);

       int endhostent_r(struct hostent_data *buffer);

       _XOPEN_SOURCE_EXTENDED only
       void sethostent(int stayopen);
       void endhostent(void);

  ...

  ERRORS
       If the name server is being used and
       gethostbyname() or gethostbyaddr() returns a NULL
       pointer, the external integer h_errno contains one
       of the following values:

            HOST_NOT_FOUND
              No such host is known.

            TRY_AGAIN              
              This is usually a temporary error. The local
              server did not receive a response from an
              authoritative server. A retry at some later
              time may succeed.

            NO_RECOVERY
               This is a non-recoverable error.

            NO_ADDRESS
               The requested name is valid but does not
               have an IP address; this is not a temporary
               error. This means another type of request
               to the name server will result in an
               answer.

       If the name server is not being used, the value of
       h_errno may not be meaningful.

/usr/include/netdb.h includes the following fragment:
      
   #ifdef _XOPEN_SOURCE_EXTENDED
   extern int h_errno;
   #endif

So, although this is not mentioned in the man page, 
_XOPEN_SOURCE_EXTENDED must be defined to include 
the declaration.


On HPUX11, the man pages says more or less the same,
but adds the following:

WARNINGS
     Programs that use the interfaces described in
     this manpage cannot be linked statically because
     the implementations of these functions employ
     dynamic loading and linking of shared objects at
     run time.

     h_errno is referenced as an extern int for single
     thread applications and is defined as function
     call macro for multithreaded applications in file
     /usr/include/netdb.h. Applications that reference
     h_errno need to include /usr/include/netdb.h.


/usr/include/netdb.h contains the following:

/*
 * Error return codes from gethostbyname() and
gethostbyaddr()
 */
#ifndef h_ERRNO_KT_DEFINED
#define h_ERRNO_KT_DEFINED
#ifdef _REENTRANT
#ifdef _PROTOTYPES            /* 64 bit: add _PROTOTYPES */
extern int *__h_errno(void);  /* 64 bit: add _PROTOTYPES */
#else /* _PROTOTYPES */       /* 64 bit: add _PROTOTYPES */
extern int *__h_errno();
#endif /* _PROTOTYPES */      /* 64 bit: add _PROTOTYPES */
#define h_errno        (*__h_errno())
#else /* _REENTRANT */
extern int h_errno;
#endif /* REENTRANT */
#endif /* ! h_ERRNO_KT_DEFINED */
#endif /* _NETDB_INCLUDED */


So, the only safe way to get things working on HPUX-10 and
HPUX-11 is to define _XOPEN_SOURCE_EXTENDED before netdb.h
is included. The hardcoded declaration I mentioned before
isn't safe.



----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-01-18 16:09

Message:
Logged In: YES 
user_id=21627

s/HPUX/HPUX11/

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-01-18 16:09

Message:
Logged In: YES 
user_id=21627

Does the second version of your patch also work on HPUX? Can
you point to official documentation on that matter?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=505427&group_id=5470