summaryrefslogtreecommitdiffstats
path: root/luni/src
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2009-09-10 16:09:29 -0700
committerElliott Hughes <enh@google.com>2009-09-10 16:09:29 -0700
commit9ee0ceadae7cc5cdedf675f515b653cd626af132 (patch)
tree6adba8b3cd73835610b5fe53180f0407f28d8b04 /luni/src
parent1826734268ac8ec3501d7e141239db12de76df15 (diff)
downloadlibcore-9ee0ceadae7cc5cdedf675f515b653cd626af132.zip
libcore-9ee0ceadae7cc5cdedf675f515b653cd626af132.tar.gz
libcore-9ee0ceadae7cc5cdedf675f515b653cd626af132.tar.bz2
Several small native code fixes.
* Don't throw OutOfMemoryError manually in Adler32/CRC32: the VM does that for us if GetPrimitiveArrayCritical needs, but fails, to allocate memory. * Don't use anything but NULL for the "iscopy" argument to Get*ArrayElements. The other users of this argument (removed earlier this week) were under the mistaken impression that it's an "in" parameter rather than an "out" parameter, and since these remaining callers aren't actually using the result, let's remove the cruft. * Move the null check in harmony_io_openImpl for "path" to come *before* the first dereference. * Make harmony_io_ttyReadImpl just delegate to harmony_io_readImpl since, apart from the zero-length read check, they were identical. * Remove the dead function throwIOExceptionStr from the OpenSSLSessionImpl native code. Tested on sapphire-eng.
Diffstat (limited to 'luni/src')
-rw-r--r--luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp72
-rw-r--r--luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp9
2 files changed, 16 insertions, 65 deletions
diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp
index 38f3d36..6a9ab9d 100644
--- a/luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp
+++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp
@@ -337,16 +337,12 @@ static jlong harmony_io_writeDirectImpl(JNIEnv * env, jobject thiz, jint fd,
static jlong harmony_io_readImpl(JNIEnv * env, jobject thiz, jint fd,
jbyteArray byteArray, jint offset, jint nbytes) {
- jboolean isCopy;
- jbyte *bytes;
- jlong result;
-
if (nbytes == 0) {
return 0;
}
- bytes = env->GetByteArrayElements(byteArray, &isCopy);
-
+ jbyte* bytes = env->GetByteArrayElements(byteArray, NULL);
+ jlong result;
for (;;) {
result = read(fd, (void *) (bytes + offset), (int) nbytes);
@@ -374,7 +370,7 @@ static jlong harmony_io_readImpl(JNIEnv * env, jobject thiz, jint fd,
jniThrowException(env, "java/io/InterruptedIOException",
"Read timed out");
} else {
- jniThrowException(env, "java/io/IOException", strerror(errno));
+ jniThrowException(env, "java/io/IOException", strerror(errno));
}
}
@@ -389,10 +385,8 @@ static jlong harmony_io_readImpl(JNIEnv * env, jobject thiz, jint fd,
static jlong harmony_io_writeImpl(JNIEnv * env, jobject thiz, jint fd,
jbyteArray byteArray, jint offset, jint nbytes) {
- jboolean isCopy;
- jbyte *bytes = env->GetByteArrayElements(byteArray, &isCopy);
+ jbyte* bytes = env->GetByteArrayElements(byteArray, NULL);
jlong result;
-
for (;;) {
result = write(fd, (const char *) bytes + offset, (int) nbytes);
@@ -416,7 +410,7 @@ static jlong harmony_io_writeImpl(JNIEnv * env, jobject thiz, jint fd,
jniThrowException(env, "java/io/InterruptedIOException",
"Write timed out");
} else {
- jniThrowException(env, "java/io/IOException", strerror(errno));
+ jniThrowException(env, "java/io/IOException", strerror(errno));
}
}
@@ -562,11 +556,13 @@ static jint harmony_io_truncateImpl(JNIEnv * env, jobject thiz, jint fd,
static jint harmony_io_openImpl(JNIEnv * env, jobject obj, jbyteArray path,
jint jflags) {
+ if (path == NULL) {
+ jniThrowException(env, "java/lang/NullPointerException", NULL);
+ return -1;
+ }
+
int flags = 0;
int mode = 0;
- jint * portFD;
- jsize length;
- char pathCopy[HyMaxPath];
// BEGIN android-changed
// don't want default permissions to allow global access.
@@ -596,19 +592,14 @@ static jint harmony_io_openImpl(JNIEnv * env, jobject obj, jbyteArray path,
flags = EsTranslateOpenFlags(flags);
- length = env->GetArrayLength (path);
+ jsize length = env->GetArrayLength (path);
length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+ char pathCopy[HyMaxPath];
env->GetByteArrayRegion (path, 0, length, (jbyte *)pathCopy);
pathCopy[length] = '\0';
convertToPlatform (pathCopy);
int cc;
-
- if(pathCopy == NULL) {
- jniThrowException(env, "java/lang/NullPointerException", NULL);
- return -1;
- }
-
do {
cc = open(pathCopy, flags, mode);
} while(cc < 0 && errno == EINTR);
@@ -731,44 +722,7 @@ static jint harmony_io_ioctlAvailable(JNIEnv *env, jobject thiz, jint fd) {
*/
static jlong harmony_io_ttyReadImpl(JNIEnv *env, jobject thiz,
jbyteArray byteArray, jint offset, jint nbytes) {
-
- jboolean isCopy;
- jbyte *bytes = env->GetByteArrayElements(byteArray, &isCopy);
- jlong result;
-
- for(;;) {
-
- result = (jlong) read(STDIN_FILENO, (char *)(bytes + offset), (int) nbytes);
-
- if ((result != -1) || (errno != EINTR)) {
- break;
- }
-
- /*
- * If we didn't break above, that means that the read() call
- * returned due to EINTR. We shield Java code from this
- * possibility by trying again. Note that this is different
- * from EAGAIN, which should result in this code throwing
- * an InterruptedIOException.
- */
- }
-
- env->ReleaseByteArrayElements(byteArray, bytes, 0);
-
- if (result == 0) {
- return -1;
- }
-
- if (result == -1) {
- if (errno == EAGAIN) {
- jniThrowException(env, "java/io/InterruptedIOException",
- "Read timed out");
- } else {
- jniThrowException(env, "java/io/IOException", strerror(errno));
- }
- }
-
- return result;
+ return harmony_io_readImpl(env, thiz, STDIN_FILENO, byteArray, offset, nbytes);
}
/*
diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
index 02e18e9..8cd9e0f 100644
--- a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
+++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
@@ -2624,8 +2624,7 @@ static jint osNetworkSystem_receiveStreamImpl(JNIEnv* env, jclass clazz,
int spaceAvailable = env->GetArrayLength(data) - offset;
int localCount = count < spaceAvailable? count : spaceAvailable;
- jboolean isCopy;
- jbyte *body = env->GetByteArrayElements(data, &isCopy);
+ jbyte* body = env->GetByteArrayElements(data, NULL);
// set timeout
struct timeval tv;
@@ -2668,8 +2667,7 @@ static jint osNetworkSystem_sendStreamImpl(JNIEnv* env, jclass clazz,
int handle = 0;
int result = 0, sent = 0;
- jboolean isCopy;
- jbyte *message = env->GetByteArrayElements(data, &isCopy);
+ jbyte *message = env->GetByteArrayElements(data, NULL);
// Cap write length to available buf size
int spaceAvailable = env->GetArrayLength(data) - offset;
@@ -2826,7 +2824,6 @@ static jint osNetworkSystem_selectImpl(JNIEnv* env, jclass clazz,
jobject gotFD;
fd_set *fdset_read,*fdset_write;
int handle;
- jboolean isCopy ;
jint *flagArray;
int val;
unsigned int time_sec = (unsigned int)timeout/1000;
@@ -2885,7 +2882,7 @@ static jint osNetworkSystem_selectImpl(JNIEnv* env, jclass clazz,
if (0 < result) {
/*output the result to a int array*/
- flagArray = env->GetIntArrayElements(outFlags, &isCopy);
+ flagArray = env->GetIntArrayElements(outFlags, NULL);
for (val=0; val<countReadC; val++) {
gotFD = env->GetObjectArrayElement(readFDArray,val);