This is the mail archive of the
java-patches@sourceware.cygnus.com
mailing list for the Java project.
Re: on DU4.0d/alpha, gethostbyname_r is only declared with -D_REENTRANT
- To: java-discuss@sourceware.cygnus.com, java-patches@sourceware.cygnus.com
- Subject: Re: on DU4.0d/alpha, gethostbyname_r is only declared with -D_REENTRANT
- From: Alexandre Oliva <oliva@dcc.unicamp.br>
- Date: 20 Jul 1999 19:48:28 -0300
- References: <orso6l6lbq.fsf@cupuacu.lsd.dcc.unicamp.br>
On Jul 19, 1999, Alexandre Oliva <oliva@dcc.unicamp.br> wrote:
> So java/net/natInetAddress.cc fails to compile with g++ 2.95 (unless
> -fpermissive is given, of course).
And it is very good that it fails to compile! After arranging that
_REENTRANT is declared, I found out the signature is completely
different. Here's a patch that adds support for DU4's
gethostby{name,addr}_r:
Index: libjava/ChangeLog
from Alexandre Oliva <oliva@dcc.unicamp.br>
* configure.in: Check for struct hostent_data and need for
-D_REENTRANT for gethostbyname_r declaration.
* java/net/natInetAddress.cc: Define _REENTRANT if needed.
(lookup): Use hostent_data for fixed_buffer.
* configure, include/config.h.in: Rebuilt.
Index: libjava/configure.in
===================================================================
RCS file: /cvs/java/libgcj/libjava/configure.in,v
retrieving revision 1.11.2.1
diff -u -r1.11.2.1 configure.in
--- libjava/configure.in 1999/06/24 20:14:59 1.11.2.1
+++ libjava/configure.in 1999/07/20 22:44:12
@@ -309,8 +309,49 @@
# We look for the one that returns `int'.
# Hopefully this check is robust enough.
AC_EGREP_HEADER(int.*gethostbyname_r, netdb.h, [
- AC_DEFINE(GETHOSTBYNAME_R_RETURNS_INT)])])
+ AC_DEFINE(GETHOSTBYNAME_R_RETURNS_INT)])
+ case " $GCINCS " in
+ *" -D_REENTRANT "*) ;;
+ *)
+ dnl On DU4.0, gethostbyname_r is only declared with -D_REENTRANT
+ AC_CACHE_CHECK([whether gethostbyname_r declaration requires -D_REENTRANT],
+ [libjava_cv_gethostbyname_r_needs_reentrant],
+ [ AC_LANG_SAVE
+ AC_LANG_CPLUSPLUS
+ AC_TRY_COMPILE([#include <netdb.h>],
+ [gethostbyname_r("", 0, 0);],
+ [libjava_cv_gethostbyname_r_needs_reentrant=no], [dnl
+ CPPFLAGS_SAVE="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS -D_REENTRANT"
+ AC_TRY_COMPILE([#include <netdb.h>], [gethostbyname_r("", 0, 0);],
+ [libjava_cv_gethostbyname_r_needs_reentrant=yes],
+ [libjava_cv_gethostbyname_r_needs_reentrant=fail])
+ CPPFLAGS="$CPPFLAGS_SAVE"
+ ])
+ AC_LANG_RESTORE
+ ])
+ if test "x$libjava_cv_gethostbyname_r_needs_reentrant" = xyes; then
+ AC_DEFINE(GETHOSTBYNAME_R_NEEDS_REENTRANT, 1, [Define if gethostbyname_r is only declared if _REENTRANT is defined])
+ fi
+ ;;
+ esac
+
+ AC_CACHE_CHECK([for struct hostent_data],
+ [libjava_cv_struct_hostent_data], [dnl
+ AC_TRY_COMPILE([
+#if GETHOSTBYNAME_R_NEEDS_REENTRANT && !defined(_REENTRANT)
+# define _REENTRANT 1
+#endif
+#include <netdb.h>], [struct hostent_data data;],
+ [libjava_cv_struct_hostent_data=yes],
+ [libjava_cv_struct_hostent_data=no])])
+ if test "x$libjava_cv_struct_hostent_data" = xyes; then
+ AC_DEFINE(HAVE_STRUCT_HOSTENT_DATA, 1,
+ [Define if struct hostent_data is defined in netdb.h])
+ fi
+ ])
+
AC_CHECK_FUNCS(gethostbyaddr_r, [
AC_DEFINE(HAVE_GETHOSTBYADDR_R)
# There are two different kinds of gethostbyaddr_r.
Index: libjava/java/net/natInetAddress.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/net/natInetAddress.cc,v
retrieving revision 1.6
diff -u -r1.6 natInetAddress.cc
--- libjava/java/net/natInetAddress.cc 1999/06/18 01:17:28 1.6
+++ libjava/java/net/natInetAddress.cc 1999/07/20 22:44:12
@@ -10,6 +10,10 @@
#include <config.h>
+#if GETHOSTBYNAME_R_NEEDS_REENTRANT && !defined(_REENTRANT)
+# define _REENTRANT 1
+#endif
+
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -97,6 +101,9 @@
struct hostent *hptr = NULL;
#if defined (HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYADDR_R)
struct hostent hent_r;
+#if HAVE_STRUCT_HOSTENT_DATA
+ struct hostent_data fixed_buffer, *buffer_r = &fixed_buffer;
+#else
#if defined (__GLIBC__)
// FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
// ERANGE to errno if the buffer size is too small, rather than what is
@@ -109,6 +116,7 @@
char *buffer_r = fixed_buffer;
int size_r = sizeof (fixed_buffer);
#endif
+#endif
if (host != NULL)
{
@@ -122,10 +130,13 @@
JvGetStringUTFRegion (host, 0, host->length(), hostname);
buf[len] = '\0';
#ifdef HAVE_GETHOSTBYNAME_R
- int herr = 0;
while (true)
{
int ok;
+#if HAVE_STRUCT_HOSTENT_DATA
+ ok = ! gethostbyname_r (hostname, &hent_r, buffer_r);
+#else
+ int herr = 0;
#ifdef GETHOSTBYNAME_R_RETURNS_INT
ok = ! gethostbyname_r (hostname, &hent_r, buffer_r, size_r,
&hptr, &herr);
@@ -139,6 +150,7 @@
buffer_r = (char *) _Jv_AllocBytesChecked (size_r);
}
else
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
break;
}
#else
@@ -171,10 +183,13 @@
JvFail ("unrecognized size");
#ifdef HAVE_GETHOSTBYADDR_R
- int herr = 0;
while (true)
{
int ok;
+#if HAVE_STRUCT_HOSTENT_DATA
+ ok = ! gethostbyaddr_r (val, len, type, &hent_r, buffer_r);
+#else
+ int herr = 0;
#ifdef GETHOSTBYADDR_R_RETURNS_INT
ok = ! gethostbyaddr_r (val, len, type, &hent_r,
buffer_r, size_r, &hptr, &herr);
@@ -189,6 +204,7 @@
buffer_r = (char *) _Jv_AllocBytesChecked (size_r);
}
else
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
break;
}
#else /* HAVE_GETHOSTBYADDR_R */
--
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{dcc.unicamp.br,guarana.{org,com}} aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them