This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[PATCH] Re: PATCH for java.nio FileChannel and MappedByteBuffer
Tom Tromey wrote:
"Andreas" == andreas tobler <toa@pop.agri.ch> writes:
+#if defined(__JV_POSIX_H__) && defined(HAVE_MMAP)
I don't like the header guard #define being used as a test macro.
Andreas> extern int munmap(void *, size_t);
Andreas> extern int msync(void *, size_t, int);
Andreas> extern int munmap(caddr_t, size_t);
Andreas> extern int msync(caddr_t, size_t, int);
Usually our fix in situations like this is to introduce a new
template function to work around the platform differences. See,
e.g., getpwuid_adaptor in java/lang/natRuntime.cc.
Ok, with help of Tom I hacked this one.
Currently testing on Solaris 2.9 and 2.6.
Compiled on darwin6.8, Linuxppc run will follow shortly.
Ok for mainline?
Thanks
Andreas
2004-03-11 Andreas Tobler <a.tobler@schweiz.ch>
* gnu/java/nio/channels/natFileChannelPosix.cc: Implement
munmap_adaptor and msync_adaptor for older POSIX_C_SOURCES
specs.
(MappedByteBufferImpl::unmapImpl): Use munmap_adaptor.
(MappedByteBufferImpl::forceImpl): Use msync_adptor.
Index: gnu/java/nio/channels/natFileChannelPosix.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/channels/natFileChannelPosix.cc,v
retrieving revision 1.1
diff -u -r1.1 natFileChannelPosix.cc
--- gnu/java/nio/channels/natFileChannelPosix.cc 29 Feb 2004 19:09:28 -0000 1.1
+++ gnu/java/nio/channels/natFileChannelPosix.cc 11 Mar 2004 05:10:46 -0000
@@ -56,6 +56,46 @@
#ifdef HAVE_MMAP
#include <sys/mman.h>
+
+// Use overload resolution to find out the argument types.
+// E.g. Solaris 2.6 uses different argument types for munmap and msync.
+// This is in case _POSIX_C_SOURCES is smaller than 3.
+
+// This is for _POSIX_C_SOURCES > 2.
+template <typename T_implPtr, typename T_implLen>
+static inline int
+munmap_adaptor(int (*munmap)(T_implPtr caddr, T_implLen sizet),
+ void* caddr, size_t sizet)
+{
+ return munmap ((T_implPtr) caddr, (T_implLen) sizet);
+}
+
+// This is for _POSIX_C_SOURCES < 2.
+template <typename T_implPtr, typename T_implLen>
+static inline int
+munmap_adaptor(int (*munmap)(T_implPtr caddr, T_implLen sizet),
+ caddr_t caddr, size_t sizet)
+{
+ return munmap ((T_implPtr) caddr, (T_implLen) sizet);
+}
+
+// This is for _POSIX_C_SOURCES > 2.
+template <typename T_implPtr, typename T_implLen, typename T_msync>
+static inline int
+msync_adaptor(int (*msync)(T_implPtr caddr, T_implLen sizet, T_msync msynct),
+ void* caddr, size_t sizet, int msynct)
+{
+ return msync ((T_implPtr) caddr, (T_implLen) sizet, (T_msync) msynct);
+}
+
+// This is for _POSIX_C_SOURCES < 2.
+template <typename T_implPtr, typename T_implLen, typename T_msync>
+static inline int
+msync_adaptor(int (*msync)(T_implPtr caddr, T_implLen sizet, T_msync msynct),
+ caddr_t caddr, size_t sizet, int msynct)
+{
+ return msync ((T_implPtr) caddr, (T_implLen) sizet, (T_msync) msynct);
+}
#endif
using gnu::gcj::RawData;
@@ -498,7 +538,7 @@
MappedByteBufferImpl::unmapImpl ()
{
#if defined(HAVE_MMAP)
- munmap((void*) implPtr, implLen);
+ munmap_adaptor(munmap, implPtr, implLen);
#endif
}
@@ -517,6 +557,6 @@
MappedByteBufferImpl::forceImpl ()
{
#if defined(HAVE_MMAP)
- ::msync((void*) implPtr, implLen, MS_SYNC);
+ ::msync_adaptor(msync, implPtr, implLen, MS_SYNC);
#endif
}