[kaffe] CVS kaffe (robilad): Merged in support for nio file channel
locking from GNU Classpath
Kaffe CVS
cvs-commits at kaffe.org
Sun Jul 17 08:09:56 PDT 2005
PatchSet 6740
Date: 2005/07/17 15:03:21
Author: robilad
Branch: HEAD
Tag: (none)
Log:
Merged in support for nio file channel locking from GNU Classpath
2005-07-17 Dalibor Topic <robilad at kaffe.org>
* libraries/clib/nio/FileChannelImpl.c:
(getFD) Renamed to get_native_fd. No longer static since it is used in
gnu_java_nio_channels_FileChannelImpl.c as well.
(Java_gnu_java_nio_channels_FileChannelImpl_available,
Java_gnu_java_nio_channels_FileChannelImpl_implPosition,
Java_gnu_java_nio_channels_FileChannelImpl_seek,
Java_gnu_java_nio_channels_FileChannelImpl_implTruncate,
Java_gnu_java_nio_channels_FileChannelImpl_size,
Java_gnu_java_nio_channels_FileChannelImpl_write__I,
Java_gnu_java_nio_channels_FileChannelImpl_implCloseChannel) Use get_native_fd
instead of getFD.
(Java_gnu_java_nio_channels_FileChannelImpl_lock,
Java_gnu_java_nio_channels_FileChannelImpl_unlock) Removed.
* libraries/clib/nio/gnu_java_nio_channels_FileChannelImpl.c:
New file. Taken from GNU Classpath. Removed unused functions.
* libraries/clib/nio/Makefile.am (libnio_la_SOURCES): Added
gnu_java_nio_channels_FileChannelImpl.c.
Resynced with GNU Classpath.
2005-07-10 Casey Marshall <csm at gnu.org>
* native/jni/java-nio/gnu_java_nio_channels_FileChannel.c:
Include <fcntl.h> if HAVE_FCNTL_H.
(Java_gnu_java_nio_channels_FileChannelImpl_lock,
Java_gnu_java_nio_channels_FileChannelImpl_unlock): implemented
if HAVE_FCNTL.
Members:
ChangeLog:1.4264->1.4265
libraries/clib/nio/FileChannelImpl.c:1.11->1.12
libraries/clib/nio/Makefile.am:1.14->1.15
libraries/clib/nio/Makefile.in:1.73->1.74
libraries/clib/nio/gnu_java_nio_channels_FileChannelImpl.c:INITIAL->1.1
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4264 kaffe/ChangeLog:1.4265
--- kaffe/ChangeLog:1.4264 Sun Jul 17 12:18:16 2005
+++ kaffe/ChangeLog Sun Jul 17 15:03:21 2005
@@ -1,3 +1,35 @@
+2005-07-17 Dalibor Topic <robilad at kaffe.org>
+
+ * libraries/clib/nio/FileChannelImpl.c:
+ (getFD) Renamed to get_native_fd. No longer static since it is used in
+ gnu_java_nio_channels_FileChannelImpl.c as well.
+ (Java_gnu_java_nio_channels_FileChannelImpl_available,
+ Java_gnu_java_nio_channels_FileChannelImpl_implPosition,
+ Java_gnu_java_nio_channels_FileChannelImpl_seek,
+ Java_gnu_java_nio_channels_FileChannelImpl_implTruncate,
+ Java_gnu_java_nio_channels_FileChannelImpl_size,
+ Java_gnu_java_nio_channels_FileChannelImpl_write__I,
+ Java_gnu_java_nio_channels_FileChannelImpl_implCloseChannel) Use get_native_fd
+ instead of getFD.
+ (Java_gnu_java_nio_channels_FileChannelImpl_lock,
+ Java_gnu_java_nio_channels_FileChannelImpl_unlock) Removed.
+
+ * libraries/clib/nio/gnu_java_nio_channels_FileChannelImpl.c:
+ New file. Taken from GNU Classpath. Removed unused functions.
+
+ * libraries/clib/nio/Makefile.am (libnio_la_SOURCES): Added
+ gnu_java_nio_channels_FileChannelImpl.c.
+
+ Resynced with GNU Classpath.
+
+ 2005-07-10 Casey Marshall <csm at gnu.org>
+
+ * native/jni/java-nio/gnu_java_nio_channels_FileChannel.c:
+ Include <fcntl.h> if HAVE_FCNTL_H.
+ (Java_gnu_java_nio_channels_FileChannelImpl_lock,
+ Java_gnu_java_nio_channels_FileChannelImpl_unlock): implemented
+ if HAVE_FCNTL.
+
2005-07-17 Riccardo Mottola <multix at gmail.com>
* config/i386/gnu/md.h
Index: kaffe/libraries/clib/nio/FileChannelImpl.c
diff -u kaffe/libraries/clib/nio/FileChannelImpl.c:1.11 kaffe/libraries/clib/nio/FileChannelImpl.c:1.12
--- kaffe/libraries/clib/nio/FileChannelImpl.c:1.11 Fri May 6 15:36:12 2005
+++ kaffe/libraries/clib/nio/FileChannelImpl.c Sun Jul 17 15:03:24 2005
@@ -119,8 +119,7 @@
return fd;
}
-static
-jint getFD(JNIEnv *env, jobject filechannel)
+jint get_native_fd(JNIEnv *env, jobject filechannel)
{
jclass filechannel_class = (*env)->GetObjectClass(env, filechannel);
jfieldID fid = (*env)->GetFieldID(env, filechannel_class, "fd", "I");
@@ -132,7 +131,7 @@
Java_gnu_java_nio_channels_FileChannelImpl_available(JNIEnv *env, jobject filechannel)
{
int r, nr, rc;
- int nativeFd = getFD(env, filechannel);
+ int nativeFd = get_native_fd(env, filechannel);
off_t cur = 0;
r = KLSEEK(nativeFd, cur, SEEK_CUR, &cur);
@@ -183,7 +182,7 @@
jlong JNICALL
Java_gnu_java_nio_channels_FileChannelImpl_implPosition(JNIEnv *env, jobject filechannel)
{
- int nativeFd = getFD(env, filechannel);
+ int nativeFd = get_native_fd(env, filechannel);
off_t cur;
int rc;
@@ -200,7 +199,7 @@
Java_gnu_java_nio_channels_FileChannelImpl_seek(JNIEnv *env, jobject filechannel,
jlong offset)
{
- int nativeFd = (int)getFD(env, filechannel);
+ int nativeFd = (int)get_native_fd(env, filechannel);
int sysWhence = SEEK_SET;
int rc;
off_t sysOffset = (off_t)offset;
@@ -232,7 +231,7 @@
Java_gnu_java_nio_channels_FileChannelImpl_implTruncate(JNIEnv *env, jobject filechannel,
jlong newSize)
{
- int nativeFd = (int) getFD(env, filechannel);
+ int nativeFd = (int) get_native_fd(env, filechannel);
off_t fileSize;
off_t new_length = (off_t)newSize;
off_t cur, oldPosition;
@@ -319,7 +318,7 @@
/* Kaffe's mmapping mode corresponds exactly to java.nio.channels.FileChannel.MapMode numbers. */
void *memory;
int rc;
- int nativeFd = (int)getFD(env, filechannel);
+ int nativeFd = (int)get_native_fd(env, filechannel);
off_t nativePos = (off_t)pos;
size_t nativeSize = (size_t)size;
jclass bytebuffer_class = (*env)->FindClass(env, "java.nio.MappedByteBufferImpl");
@@ -359,7 +358,7 @@
jlong JNICALL
Java_gnu_java_nio_channels_FileChannelImpl_size(JNIEnv *env, jobject filechannel)
{
- int fd = (int)getFD(env, filechannel);
+ int fd = (int)get_native_fd(env, filechannel);
int rc;
off_t fileSize;
@@ -377,7 +376,7 @@
jbyteArray bytes, jint offset, jint len)
{
int rc;
- int nativeFd = (int)getFD(env, filechannel);
+ int nativeFd = (int)get_native_fd(env, filechannel);
ssize_t nativeLen = (ssize_t)len;
ssize_t nativeRead = 0;
off_t off = (off_t)offset;
@@ -414,7 +413,7 @@
{
int rc;
uint8 one_byte;
- int nativeFd = (int)getFD(env, filechannel);
+ int nativeFd = (int)get_native_fd(env, filechannel);
ssize_t ret;
do
@@ -440,7 +439,7 @@
jbyteArray bytes, jint offset, jint len)
{
int rc;
- int nativeFd = (int)getFD(env, filechannel);
+ int nativeFd = (int)get_native_fd(env, filechannel);
ssize_t nativeLen = (ssize_t)len;
ssize_t nativeWritten = 0;
off_t off = (off_t)offset;
@@ -467,7 +466,7 @@
Java_gnu_java_nio_channels_FileChannelImpl_write__I(JNIEnv *env, jobject filechannel, jint byte)
{
int rc;
- int nativeFd = (int)getFD(env, filechannel);
+ int nativeFd = (int)get_native_fd(env, filechannel);
uint8 real_byte = byte;
ssize_t ret;
@@ -484,27 +483,11 @@
void JNICALL
Java_gnu_java_nio_channels_FileChannelImpl_implCloseChannel(JNIEnv *env, jobject filechannel)
{
- int fd = (int)getFD(env, filechannel);
+ int fd = (int)get_native_fd(env, filechannel);
int rc = KCLOSE(fd);
if (rc != 0)
throwIOException(env, rc);
-}
-
-jboolean JNICALL
-Java_gnu_java_nio_channels_FileChannelImpl_lock(JNIEnv *env UNUSED, jobject filechannel UNUSED, jlong position UNUSED,
- jlong size UNUSED, jboolean shared UNUSED,
- jboolean wait_lock UNUSED)
-{
- (*env)->ThrowNew(env, (*env)->FindClass(env, "java.io.IOException"), "java.nio.FileChannelImpl.lock(): not implemented");
- return false;
-}
-
-void JNICALL
-Java_gnu_java_nio_channels_FileChannelImpl_unlock(JNIEnv *env UNUSED, jobject filechannel UNUSED, jlong position UNUSED,
- jlong size UNUSED)
-{
- (*env)->ThrowNew(env, (*env)->FindClass(env, "java.io.IOException"), "java.nio.FileChannelImpl.unlock(): not implemented");
}
/*
Index: kaffe/libraries/clib/nio/Makefile.am
diff -u kaffe/libraries/clib/nio/Makefile.am:1.14 kaffe/libraries/clib/nio/Makefile.am:1.15
--- kaffe/libraries/clib/nio/Makefile.am:1.14 Sun Apr 24 09:57:38 2005
+++ kaffe/libraries/clib/nio/Makefile.am Sun Jul 17 15:03:24 2005
@@ -27,6 +27,7 @@
gnu_java_nio_charset_iconv_IconvDecoder.c \
gnu_java_nio_charset_iconv_IconvEncoder.c \
gnu_java_nio_VMSelector.c \
+ gnu_java_nio_channels_FileChannelImpl.c \
FileChannelImpl.c
libnio_la_DEPENDENCIES = \
Index: kaffe/libraries/clib/nio/Makefile.in
diff -u kaffe/libraries/clib/nio/Makefile.in:1.73 kaffe/libraries/clib/nio/Makefile.in:1.74
--- kaffe/libraries/clib/nio/Makefile.in:1.73 Sat May 14 21:46:54 2005
+++ kaffe/libraries/clib/nio/Makefile.in Sun Jul 17 15:03:24 2005
@@ -90,6 +90,7 @@
libnio_la-gnu_java_nio_charset_iconv_IconvDecoder.lo \
libnio_la-gnu_java_nio_charset_iconv_IconvEncoder.lo \
libnio_la-gnu_java_nio_VMSelector.lo \
+ libnio_la-gnu_java_nio_channels_FileChannelImpl.lo \
libnio_la-FileChannelImpl.lo
libnio_la_OBJECTS = $(am_libnio_la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/config
@@ -404,6 +405,7 @@
gnu_java_nio_charset_iconv_IconvDecoder.c \
gnu_java_nio_charset_iconv_IconvEncoder.c \
gnu_java_nio_VMSelector.c \
+ gnu_java_nio_channels_FileChannelImpl.c \
FileChannelImpl.c
libnio_la_DEPENDENCIES = \
@@ -486,6 +488,7 @@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnio_la-FileChannelImpl.Plo at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnio_la-gnu_java_nio_VMSelector.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnio_la-gnu_java_nio_channels_FileChannelImpl.Plo at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnio_la-gnu_java_nio_charset_iconv_IconvDecoder.Plo at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnio_la-gnu_java_nio_charset_iconv_IconvEncoder.Plo at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnio_la-java_nio_VMDirectByteBuffer.Plo at am__quote@
@@ -538,6 +541,13 @@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='gnu_java_nio_VMSelector.c' object='libnio_la-gnu_java_nio_VMSelector.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnio_la_CFLAGS) $(CFLAGS) -c -o libnio_la-gnu_java_nio_VMSelector.lo `test -f 'gnu_java_nio_VMSelector.c' || echo '$(srcdir)/'`gnu_java_nio_VMSelector.c
+
+libnio_la-gnu_java_nio_channels_FileChannelImpl.lo: gnu_java_nio_channels_FileChannelImpl.c
+ at am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnio_la_CFLAGS) $(CFLAGS) -MT libnio_la-gnu_java_nio_channels_FileChannelImpl.lo -MD -MP -MF "$(DEPDIR)/libnio_la-gnu_java_nio_channels_FileChannelImpl.Tpo" -c -o libnio_la-gnu_java_nio_channels_FileChannelImpl.lo `test -f 'gnu_java_nio_channels_FileChannelImpl.c' || echo '$(srcdir)/'`gnu_java_nio_channels_FileChannelImpl.c; \
+ at am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libnio_la-gnu_java_nio_channels_FileChannelImpl.Tpo" "$(DEPDIR)/libnio_la-gnu_java_nio_channels_FileChannelImpl.Plo"; else rm -f "$(DEPDIR)/libnio_la-gnu_java_nio_channels_FileChannelImpl.Tpo"; exit 1; fi
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@ source='gnu_java_nio_channels_FileChannelImpl.c' object='libnio_la-gnu_java_nio_channels_FileChannelImpl.lo' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnio_la_CFLAGS) $(CFLAGS) -c -o libnio_la-gnu_java_nio_channels_FileChannelImpl.lo `test -f 'gnu_java_nio_channels_FileChannelImpl.c' || echo '$(srcdir)/'`gnu_java_nio_channels_FileChannelImpl.c
libnio_la-FileChannelImpl.lo: FileChannelImpl.c
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnio_la_CFLAGS) $(CFLAGS) -MT libnio_la-FileChannelImpl.lo -MD -MP -MF "$(DEPDIR)/libnio_la-FileChannelImpl.Tpo" -c -o libnio_la-FileChannelImpl.lo `test -f 'FileChannelImpl.c' || echo '$(srcdir)/'`FileChannelImpl.c; \
===================================================================
Checking out kaffe/libraries/clib/nio/gnu_java_nio_channels_FileChannelImpl.c
RCS: /home/cvs/kaffe/kaffe/libraries/clib/nio/gnu_java_nio_channels_FileChannelImpl.c,v
VERS: 1.1
***************
--- /dev/null Sun Aug 4 19:57:58 2002
+++ kaffe/libraries/clib/nio/gnu_java_nio_channels_FileChannelImpl.c Sun Jul 17 15:09:56 2005
@@ -0,0 +1,127 @@
+/* gnu_java_nio_channels_FileChannelImpl.c -
+ Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+/* do not move; needed here because of some macro definitions */
+#include <config.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <jni.h>
+#include <jcl.h>
+
+#include "gnu_java_nio_channels_FileChannelImpl.h"
+
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif /* HAVE_FCNTL_H */
+
+#define IO_EXCEPTION "java/io/IOException"
+
+extern jint get_native_fd(JNIEnv *env, jobject filechannel);
+
+JNIEXPORT jboolean JNICALL
+Java_gnu_java_nio_channels_FileChannelImpl_lock (JNIEnv *env, jobject obj,
+ jlong position, jlong size,
+ jboolean shared, jboolean wait)
+{
+#ifdef HAVE_FCNTL
+ int fd = get_native_fd (env, obj);
+ int cmd = wait ? F_SETLKW : F_SETLK;
+ struct flock flock;
+ int ret;
+
+ flock.l_type = shared ? F_RDLCK : F_WRLCK;
+ flock.l_whence = SEEK_SET;
+ flock.l_start = (off_t) position;
+ flock.l_len = (off_t) size;
+
+ ret = fcntl (fd, cmd, &flock);
+ if (ret)
+ {
+ /* Linux man pages for fcntl state that errno might be either
+ EACCES or EAGAIN if we try F_SETLK, and another process has
+ an overlapping lock. */
+ if (errno != EACCES && errno != EAGAIN)
+ {
+ JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));
+ }
+ return JNI_FALSE;
+ }
+ return JNI_TRUE;
+#else
+ (void) obj;
+ (void) position;
+ (void) size;
+ (void) shared;
+ (void) wait;
+ JCL_ThrowException (env, "java/lang/UnsupportedOperationException",
+ "file locks not implemented on this platform");
+ return JNI_FALSE;
+#endif /* HAVE_FCNTL */
+}
+
+JNIEXPORT void JNICALL
+Java_gnu_java_nio_channels_FileChannelImpl_unlock (JNIEnv *env,
+ jobject obj,
+ jlong position,
+ jlong length)
+{
+#ifdef HAVE_FCNTL
+ int fd = get_native_fd (env, obj);
+ struct flock flock;
+ int ret;
+
+ flock.l_type = F_UNLCK;
+ flock.l_whence = SEEK_SET;
+ flock.l_start = (off_t) position;
+ flock.l_len = (off_t) length;
+
+ ret = fcntl (fd, F_SETLK, &flock);
+ if (ret)
+ {
+ JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));
+ }
+#else
+ (void) obj;
+ (void) position;
+ (void) length;
+ JCL_ThrowException (env, "java/lang/UnsupportedOperationException",
+ "file locks not implemented on this platform");
+#endif /* HAVE_FCNTL */
+}
More information about the kaffe
mailing list