This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Re: PATCH for java.nio FileChannel and MappedByteBuffer


Tom Tromey wrote:

I think one of these is redundant and couple be eliminated...

Andreas> + munmap_adaptor(munmap, implPtr, implLen);

I think that this will select one of the two templates above for
instantiation, depending on the types of implPtr and implLen, which
are OS-independent.  So then the other template function can just be
removed.

Could you remove the unused one?  (And likewise for munmap?)
Otherwise this is fine, it can go in with that change.


Huh, magic, magic.

Thanks again Tom for the explanation. The appended patch completed compilation on ppclinux, darwin6.8 solaris2.6 and 2.9.

After testing on solaris I will commit, ok?

Regards,

Andreas
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	12 Mar 2004 19:49:28 -0000
@@ -56,6 +56,26 @@
 
 #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.
+
+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);
+}
+
+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);
+}
 #endif
 
 using gnu::gcj::RawData;
@@ -498,7 +518,7 @@
 MappedByteBufferImpl::unmapImpl ()
 {
 #if defined(HAVE_MMAP)
-  munmap((void*) implPtr, implLen);
+  munmap_adaptor(munmap, implPtr, implLen);
 #endif
 }
 
@@ -517,6 +537,6 @@
 MappedByteBufferImpl::forceImpl ()
 {
 #if defined(HAVE_MMAP)
-  ::msync((void*) implPtr, implLen, MS_SYNC);
+  ::msync_adaptor(msync, implPtr, implLen, MS_SYNC);
 #endif
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]