This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: lock/unlock filechannel Win32 implementation
- From: Marco Trudel <mtrudel at gmx dot ch>
- To: Martin <gpointorama at gmail dot com>
- Cc: java-patches at gcc dot gnu dot org
- Date: Tue, 07 Nov 2006 09:26:10 +0100
- Subject: Re: lock/unlock filechannel Win32 implementation
- References: <454E1D62.8030103@gmail.com>
Martin wrote:
I hope this works, but i can't test!
I needed to change
throw new IllegalArgumentException(...) to
throw new ::java::lang::IllegalArgumentException(...)
I don't know why other exception types do not need the package name
(name space)...
Also I included <java.lang.IllegalArgumentException>.
A patch of the final version is attached. Please supply patches, not
code snippets. You can create them with "svn diff".
i have followed, the instruction at
http://rmathew.com/articles/gcj/bldgcj.html i get this error at step 11
of paragraph "Building a Cross Compiler", i am using archlinux
0.7.2(bundled with gcc 4.0.3) inside Microsoft Virtual PC, with the last
svn from gcc and last cvs from binutils the error is:
/gnubuild/xgcc_build/gcc/gcj
-B/gnubuild/xgcc_build/i686-pc-mingw32/libjava/ -B
gnubuild/xgcc_build/gcc/ -Wno-deprecated --encoding=UTF-8
--bootclasspath '' --
lasspath
..:/gnu/gcc/libjava:/gnubuild/xgcc_build/i686-pc-mingw32/libjava:/gnu/
cc/libjava/classpath:/gnu/gcc/libjava/classpath/external/w3c_dom:/gnu/gcc/libja
a/classpath/external/sax:/gnu/gcc/libjava/classpath/external/relaxngDatatype:.:
-C -d . -MD -MF lists/javax-swing-plaf.deps -MT
lists/javax-swing-plaf.stamp -
P @lists/javax-swing-plaf.list
gcj: Internal error: Killed (program jc1)
I built a Windows GCJ last week from the most recent source. It seems
that there are some major regressions because it was killed by "Internal
error: Killed" most of the time I used it. But I was able to compile it
without problems, so this might be another problem.
I now currently work with revision 117'867. There you have to add
--disable-tls to Ranjits manual. GCC was changed in the core and they
broke libjava. I was ignored when reporting it...
anyway this is the code that should be replaced in
/libjava/gnu/java/nio/channels/natFileChannelWin32.cc:
In order to get the patch into GCJ, you will have to make copyright
assignment and then someone has to commit it for you.
Unfortunately the only one that seems to care about such things (Tom
Tromey) is away for a month. So you will have to wait for him to come
back (I'm already sitting on 8 fixes that do not find it's way into GCJ
because no one commits them). Or is there someone else that might give a
little help here? Please!
Anyway, I included your patch in my newest built that I will release
quite soon (locking didn't work before, so it only can get better or
stay useless).
Marco
Index: gnu/java/nio/channels/natFileChannelWin32.cc
===================================================================
--- gnu/java/nio/channels/natFileChannelWin32.cc (revision 117867)
+++ gnu/java/nio/channels/natFileChannelWin32.cc (working copy)
@@ -30,6 +30,7 @@
#include <java/io/InterruptedIOException.h>
#include <java/io/EOFException.h>
#include <java/lang/ArrayIndexOutOfBoundsException.h>
+#include <java/lang/IllegalArgumentException.h>
#include <java/lang/NullPointerException.h>
#include <java/lang/System.h>
#include <java/lang/String.h>
@@ -342,19 +343,87 @@
return size() - position();
}
-jboolean
-FileChannelImpl::lock
-(jlong /*pos*/, jlong /*len*/, jboolean /*shared*/, jboolean /*wait*/)
+jboolean FileChannelImpl::lock (jlong pos, jlong len, jboolean shared, jboolean wait)
{
- throw new IOException (JvNewStringLatin1
- ("FileChannel.lock() not implemented"));
+ DWORD flags = 0;
+ OVERLAPPED ovlpd;
+
+ if(pos<0 || len<0)
+ throw new ::java::lang::IllegalArgumentException
+ (JvNewStringLatin1("pos or len are negative!"));
+
+ ZeroMemory(&ovlpd,sizeof(OVERLAPPED));
+
+ if(!shared)
+ flags |= LOCKFILE_EXCLUSIVE_LOCK;
+ if(!wait)
+ flags |= LOCKFILE_FAIL_IMMEDIATELY;
+
+ ovlpd.Offset = (DWORD)pos;
+ ovlpd.OffsetHigh = pos>>32;
+
+ DWORD lenlow = (DWORD)len;
+ DWORD lenhigh = len>>32;
+
+ BOOL ret = LockFileEx((HANDLE)fd,flags,0,lenlow,lenhigh,&ovlpd);
+
+ if(ret==ERROR_IO_PENDING && !shared && wait)
+ {
+ ret = GetOverlappedResult((HANDLE)fd,&ovlpd,NULL,wait);
+ }
+
+ if(!ret)
+ {
+ DWORD errnum = GetLastError();
+ LPTSTR perrmsg = NULL;
+
+ if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM,0,errnum,0,(LPTSTR)&perrmsg,0,NULL))
+ {
+ jstring jerrstr= JvNewStringLatin1(perrmsg);
+ LocalFree(perrmsg);
+ throw new IOException(jerrstr);
+ }
+ else
+ throw new IOException(JvNewStringLatin1("LockFileEx() failed!"));
+ }
+
+ return true;
}
-void
-FileChannelImpl::unlock (jlong /*pos*/, jlong /*len*/)
+void FileChannelImpl::unlock (jlong pos, jlong len)
{
- throw new IOException (JvNewStringLatin1
- ("FileChannel.unlock() not implemented"));
+ OVERLAPPED ovlpd;
+
+ if(pos<0 || len<0)
+ throw new ::java::lang::IllegalArgumentException
+ (JvNewStringLatin1("pos or len are negative!"));
+
+ ZeroMemory(&ovlpd,sizeof(OVERLAPPED));
+
+ ovlpd.Offset = (DWORD)pos;
+ ovlpd.OffsetHigh = pos>>32;
+
+ DWORD lenlow = (DWORD)len;
+ DWORD lenhigh = len>>32;
+
+ BOOL ret = UnlockFileEx((HANDLE)fd,0,lenlow,lenhigh,&ovlpd);
+
+ if(!ret)
+ {
+ DWORD errnum = GetLastError();
+ LPTSTR perrmsg = NULL;
+
+ if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM,0,errnum,0,(LPTSTR)&perrmsg,0,NULL))
+ {
+ jstring jerrstr= JvNewStringLatin1(perrmsg);
+ LocalFree(perrmsg);
+ throw new IOException(jerrstr);
+ }
+ else
+ throw new IOException(JvNewStringLatin1("UnlockFileEx() failed!"));
+ }
}
java::nio::MappedByteBuffer *