Hi,
Here is a patch for NATIVE-LAYER branch that fixes a few problems which
have been highlighted by mauve tests.
Guilhem.
2006-06-16 Guilhem Lavaux <[EMAIL PROTECTED]>
* native/jni/java-net/java_net_VMInetAddress.c
(Java_java_net_VMInetAddress_getHostByName): Fix detection of
error.
* native/jni/java-net/javanet.c
(_javanet_accept): Fixed bogus call to TARGET.
(_javanet_create_inetaddress): Fixed address generation. Fixed
bogus memory free.
(_javanet_bind): set "Reuse address" flag.
* native/jni/native-lib/cpio.c
(cpio_getModificationTime): Fixed type.
(cpio_removeFile): Use rmdir too.
* native/jni/native-lib/cpnet.c
(cpnet_getHostByName): Fixed error detection.
* native/jni/native-lib/cpnet.h
(cpnet_newIPV4address, cpnet_newIPV6address): Put zero in the
memory.
(cpnet_IPV4AddressToBytes): Fixed types.
Index: native/jni/java-net/java_net_VMInetAddress.c
===================================================================
RCS file:
/cvsroot/classpath/classpath/native/jni/java-net/java_net_VMInetAddress.c,v
retrieving revision 1.7.2.2
diff -u -r1.7.2.2 java_net_VMInetAddress.c
--- native/jni/java-net/java_net_VMInetAddress.c 18 Feb 2006 18:15:55
-0000 1.7.2.2
+++ native/jni/java-net/java_net_VMInetAddress.c 16 Jun 2006 18:03:17
-0000
@@ -221,7 +221,7 @@
}
result = cpnet_getHostByName (env, hostname, &addresses, &addresses_count);
- if (result != CPNATIVE_OK)
+ if (result != CPNATIVE_OK || addresses_count == 0)
{
JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, (char *) hostname);
return (jobjectArray) NULL;
Index: native/jni/java-net/javanet.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-net/javanet.c,v
retrieving revision 1.32.2.9
diff -u -r1.32.2.9 javanet.c
--- native/jni/java-net/javanet.c 8 Jun 2006 20:20:11 -0000 1.32.2.9
+++ native/jni/java-net/javanet.c 16 Jun 2006 18:03:17 -0000
@@ -237,7 +237,7 @@
{
#ifndef WITHOUT_NETWORK
jbyte octets[4];
- char buf[16];
+ char buf[64];
jclass ia_cls;
jmethodID mid;
jstring ip_str;
@@ -245,7 +245,7 @@
/* Build a string IP address */
cpnet_IPV4AddressToBytes(netaddr, octets);
- sprintf (buf, "%d.%d.%d.%d", octets[0], octets[1], octets[2], octets[3]);
+ sprintf (buf, "%d.%d.%d.%d", (int) (unsigned char)octets[0], (int)(unsigned
char)octets[1], (int)(unsigned char)octets[2], (int)(unsigned char)octets[3]);
DBG ("_javanet_create_inetaddress(): Created ip addr string\n");
/* Get an InetAddress object for this IP */
@@ -574,8 +574,6 @@
}
}
while (result != CPNATIVE_OK);
-
- cpnet_freeAddress(env, netaddr);
DBG ("_javanet_connect(): Connected successfully\n");
@@ -583,6 +581,7 @@
result = cpnet_getLocalAddr (env, fd, &local_addr);
if (result != CPNATIVE_OK)
{
+ cpnet_freeAddress(env, netaddr);
JCL_ThrowException (env, IO_EXCEPTION,
cpnative_getErrorString (result));
/* We don't care whether this succeeds. close() will cleanup later. */
@@ -594,6 +593,7 @@
if ((*env)->ExceptionOccurred (env))
{
/* We don't care whether this succeeds. close() will cleanup later. */
+ cpnet_freeAddress(env, netaddr);
cpnet_freeAddress(env, local_addr);
cpnet_close (env, fd);
return;
@@ -611,6 +611,7 @@
if ((*env)->ExceptionOccurred (env))
{
/* We don't care whether this succeeds. close() will cleanup later. */
+ cpnet_freeAddress(env, netaddr);
cpnet_close (env, fd);
return;
}
@@ -619,6 +620,7 @@
result = cpnet_getRemoteAddr (env, fd, &remote_addr);
if (result != CPNATIVE_OK)
{
+ cpnet_freeAddress(env, netaddr);
JCL_ThrowException (env, IO_EXCEPTION,
cpnative_getErrorString (result));
/* We don't care whether this succeeds. close() will cleanup later. */
@@ -636,6 +638,7 @@
{
_javanet_set_remhost (env, this, remote_addr);
}
+ cpnet_freeAddress(env, netaddr);
if ((*env)->ExceptionOccurred (env))
{
@@ -692,6 +695,8 @@
return;
}
+ cpnet_setReuseAddress (env, fd, 1);
+
/* Get the address to connect to */
tmpaddr = _javanet_get_ip_netaddr (env, addr);
if ((*env)->ExceptionOccurred (env))
@@ -807,7 +812,7 @@
while (result != CPNATIVE_OK);
/* Reset the inherited timeout. */
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_TIMEOUT (newfd, 0, result);
+ cpnet_setSocketTimeout (env, newfd, 0);
/* Populate instance variables */
_javanet_set_int_field (env, impl, "gnu/java/net/PlainSocketImpl",
Index: native/jni/native-lib/cpio.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/native-lib/Attic/cpio.c,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 cpio.c
--- native/jni/native-lib/cpio.c 10 Jun 2006 20:26:36 -0000 1.1.2.4
+++ native/jni/native-lib/cpio.c 16 Jun 2006 18:03:17 -0000
@@ -374,7 +374,7 @@
if (stat(filename, &statbuf) < 0)
return errno;
- *mtime = statbuf.st_mtime * 1000;
+ *mtime = (jlong)statbuf.st_mtime * (jlong)1000;
return 0;
}
@@ -398,7 +398,7 @@
int cpio_removeFile (const char *filename)
{
- if (unlink(filename) < 0)
+ if (unlink(filename) < 0 && rmdir(filename) < 0)
return errno;
return 0;
Index: native/jni/native-lib/cpnet.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/native-lib/Attic/cpnet.c,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 cpnet.c
--- native/jni/native-lib/cpnet.c 10 Jun 2006 20:26:36 -0000 1.1.2.5
+++ native/jni/native-lib/cpnet.c 16 Jun 2006 18:03:17 -0000
@@ -601,7 +601,7 @@
{
buf = (char *)JCL_malloc(env, buflen);
ret = gethostbyname_r (hostname, &hret, buf, buflen, &result, &herr);
- if (ret != 0)
+ if (ret != 0 || result == NULL)
{
if (herr == ERANGE)
{
@@ -611,7 +611,7 @@
}
JCL_free(env, buf);
- return herr;
+ return -herr;
}
break;
Index: native/jni/native-lib/cpnet.h
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/native-lib/Attic/cpnet.h,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 cpnet.h
--- native/jni/native-lib/cpnet.h 10 Jun 2006 20:26:36 -0000 1.1.2.6
+++ native/jni/native-lib/cpnet.h 16 Jun 2006 18:03:17 -0000
@@ -101,8 +101,8 @@
struct sockaddr_in *netaddr = (struct sockaddr_in *)&(addr->data[0]);
addr->len = sizeof(struct sockaddr_in);
+ memset(netaddr, 0, addr->len);
netaddr->sin_family = AF_INET;
-
return addr;
}
@@ -119,6 +119,7 @@
struct sockaddr_in6 *netaddr = (struct sockaddr_in6 *)&(addr->data[0]);
addr->len = sizeof(struct sockaddr_in6);
+ memset(netaddr, 0, addr->len);
netaddr->sin6_family = AF_INET6;
return addr;
@@ -176,12 +177,12 @@
static inline void cpnet_IPV4AddressToBytes(cpnet_address *netaddr, jbyte
*octets)
{
struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(netaddr->data[0]);
- jint sysaddr = ntohl(ipaddr->sin_addr.s_addr);
+ unsigned long sysaddr = ntohl(ipaddr->sin_addr.s_addr);
- octets[0] = (sysaddr >> 24) & 0xff;
- octets[1] = (sysaddr >> 16) & 0xff;
- octets[2] = (sysaddr >> 8) & 0xff;
- octets[3] = sysaddr & 0xff;
+ octets[0] = ((sysaddr >> 24) & 0xff);
+ octets[1] = ((sysaddr >> 16) & 0xff);
+ octets[2] = ((sysaddr >> 8) & 0xff);
+ octets[3] = (sysaddr & 0xff);
}
static inline void cpnet_bytesToIPV4Address(cpnet_address *netaddr, jbyte
*octets)