Issue 505427: socket module fails to build on HPUX10 (original) (raw)

Issue505427

Created on 2002-01-18 16:12 by edg, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (16)
msg8845 - (view) Author: Eddy De Greef (edg) Date: 2002-01-18 16:12
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
msg8846 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-01-18 21:09
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?
msg8847 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-01-18 21:09
Logged In: YES user_id=21627 s/HPUX/HPUX11/
msg8848 - (view) Author: Eddy De Greef (edg) Date: 2002-01-22 09:41
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.
msg8849 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-11-02 20:07
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?
msg8850 - (view) Author: Eddy De Greef (edg) Date: 2002-11-04 10:45
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.
msg8851 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-11-13 03:33
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>
msg8852 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-11-13 08:34
Logged In: YES user_id=21627 Since Eddy indicated that that patch helps on HP-UX 10 as well, and since it definitely won't break other systems, I think this is a good idea, please apply it. For 2.3, the definition of _XOPEN_SOURCE_EXTENDED should be sufficient. So I think you can safely close this after you've applied the patch; if Eddy finds further problems on HPUX10, he should then submit a new report. Thanks for looking into this.
msg8853 - (view) Author: Eddy De Greef (edg) Date: 2002-11-13 09:01
Logged In: YES user_id=73597 As I wrote before, this patch is not thread-safe on HPUX11 (see the man page section below), so I don't think it should be applied.
msg8854 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-11-13 16:41
Logged In: YES user_id=33168 On HPUX 11, socketmodule.c builds fine with or without the patch. All the tests run successfully with or without this patch. Since python provides its own lock (see USE_GETHOSTBYNAME_LOCK) around access to h_errno (actually gethost_common() which accesses h_errno), it seems to me the usage will still be thread safe. The reason to not use _XOPEN_SOURCE_EXTENDED is the potential breakage. Especially since this is working on HPUX11. I don't see any way to distinguish between HPUX10 and HPUX11.
msg8855 - (view) Author: Eddy De Greef (edg) Date: 2002-11-13 18:25
Logged In: YES user_id=73597 What if other parts of the code access h_errno indirectly (eg, via libc)? That could still pose thread-safety problems. But I guess this is so unlikely, that it's probably safe. I've applied the patch to 2.2.2 and it compiles and works (without the _XOPEN_SOURCE_EXTENDED flag). Thanks.
msg8856 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-11-13 18:26
Logged In: YES user_id=21627 I propose a slightly modified patch, but first a few observations: On HPUX10, there is no way to get a thread-safe h_errno, and a h_errno declaration can be obtained by either defining _XOPEN_SOURCE_EXTENDED, or declaring it yourself. On HPUX11, h_errno is always declared (whether or not _XOPEN_SOURCE_EXTENDED is defined). If _REENTRANT is also defined, h_errno is thread-safe and is a macro. If these observations are correct, I think the following patch should satisfy all needs: #if defined(__hpux) && !defined(h_errno) extern int h_errno; #endif What do you think? I'm actually surprised that Neal's patch compiles for HPUX11. Shouldn't this expand to extern int (*__h_errno()); and thus conflict with the earlier declaration of __h_errno as a function?
msg8857 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-11-13 18:35
Logged In: YES user_id=33168 Martin, I agree with both your observations. I don't know why it wasn't a problem on HPUX11. I agree with checking that h_errno is not defined. I will look through the compiler/preprocessor output a bit more and try to make sure everything seems ok before checking in. Eddy, thanks for all your input.
msg8858 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-11-13 18:58
Logged In: YES user_id=33168 h_errno doesn't get expanded from the macro because it is declared before including netdb.h which defines the macro.
msg8859 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-11-13 19:12
Logged In: YES user_id=21627 In that case, the patch is, strictly speaking, correct: the external definition won't be used if a #define comes along later. It seems to be cleaner to declare it after including netdb, and only if it wasn't defined. Unless testing such an approach reveals further insights, I trust you that you will implement something that works well on all considered systems - just go ahead an implement what you like most.
msg8860 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-11-14 02:22
Logged In: YES user_id=33168 Checked in as Modules/socketmodule.c 1.200.6.10
History
Date User Action Args
2022-04-10 16:04:54 admin set github: 35944
2002-01-18 16:12:22 edg create