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]

lock/unlock filechannel Win32 implementation


I hope this works, but i can't test!

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)



anyway this is the code that should be replaced in /libjava/gnu/java/nio/channels/natFileChannelWin32.cc:




jboolean FileChannelImpl::lock (jlong pos, jlong len, jboolean shared, jboolean wait)
{
DWORD flags = 0;
OVERLAPPED ovlpd;


	if(pos<0 || len<0)
		throw new 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)
{
	OVERLAPPED ovlpd;

	if(pos<0 || len<0)
		throw new 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!"));
	}
}


thank you, Martin


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