summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/ScopedByteArray.h57
-rw-r--r--include/ScopedPrimitiveArray.h65
-rw-r--r--luni/src/main/java/java/util/zip/Adler32.java4
-rw-r--r--luni/src/main/native/BidiWrapper.cpp6
-rw-r--r--luni/src/main/native/NativeConverter.cpp131
-rw-r--r--luni/src/main/native/java_io_File.cpp50
-rw-r--r--luni/src/main/native/java_util_zip_Adler32.cpp17
-rw-r--r--luni/src/main/native/java_util_zip_CRC32.cpp16
-rw-r--r--luni/src/main/native/java_util_zip_Deflater.cpp8
-rw-r--r--luni/src/main/native/java_util_zip_Inflater.cpp9
-rw-r--r--luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp25
-rw-r--r--luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp20
-rw-r--r--luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp119
-rw-r--r--luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp30
-rw-r--r--openssl/src/main/native/BNInterface.cpp180
15 files changed, 333 insertions, 404 deletions
diff --git a/include/ScopedByteArray.h b/include/ScopedByteArray.h
deleted file mode 100644
index 6955b70..0000000
--- a/include/ScopedByteArray.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
-
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef SCOPED_BYTE_ARRAY_H_included
-#define SCOPED_BYTE_ARRAY_H_included
-
-#include "JNIHelp.h"
-
-// A smart pointer that provides read-only access to a Java byte[].
-class ScopedByteArray {
-public:
- ScopedByteArray(JNIEnv* env, jbyteArray byteArray)
- : mEnv(env), mByteArray(byteArray), mBytes(NULL)
- {
- mBytes = env->GetByteArrayElements(mByteArray, NULL);
- }
-
- ~ScopedByteArray() {
- if (mBytes) {
- mEnv->ReleaseByteArrayElements(mByteArray, mBytes, JNI_ABORT);
- }
- }
-
- const jbyte* bytes() const {
- return mBytes;
- }
-
- // Element access.
- const char& operator[](size_t n) const {
- const char* array = reinterpret_cast<const char*>(mBytes);
- return array[n];
- }
-
-private:
- JNIEnv* mEnv;
- jbyteArray mByteArray;
- jbyte* mBytes;
-
- // Disallow copy and assignment.
- ScopedByteArray(const ScopedByteArray&);
- void operator=(const ScopedByteArray&);
-};
-
-#endif // SCOPED_BYTE_ARRAY_H_included
diff --git a/include/ScopedPrimitiveArray.h b/include/ScopedPrimitiveArray.h
new file mode 100644
index 0000000..b3b16e1
--- /dev/null
+++ b/include/ScopedPrimitiveArray.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SCOPED_PRIMITIVE_ARRAY_H_included
+#define SCOPED_PRIMITIVE_ARRAY_H_included
+
+#include "JNIHelp.h"
+
+// ScopedBooleanArray, ScopedByteArray, ScopedCharArray, ScopedDoubleArray, ScopedFloatArray,
+// ScopedIntArray, ScopedLongArray, and ScopedShortArray provide convenient read-only access to
+// Java arrays from JNI code.
+#define INSTANTIATE_SCOPED_PRIMITIVE_ARRAY(PRIMITIVE_TYPE, NAME) \
+ class Scoped ## NAME ## Array { \
+ public: \
+ Scoped ## NAME ## Array(JNIEnv* env, PRIMITIVE_TYPE ## Array javaArray) \
+ : mEnv(env), mJavaArray(javaArray), mRawArray(NULL) { \
+ mRawArray = mEnv->Get ## NAME ## ArrayElements(mJavaArray, NULL); \
+ } \
+ ~Scoped ## NAME ## Array() { \
+ if (mRawArray) { \
+ mEnv->Release ## NAME ## ArrayElements(mJavaArray, mRawArray, JNI_ABORT); \
+ } \
+ } \
+ const PRIMITIVE_TYPE* get() const { \
+ return mRawArray; \
+ } \
+ const PRIMITIVE_TYPE& operator[](size_t n) const { \
+ return mRawArray[n]; \
+ } \
+ size_t size() const { \
+ return mEnv->GetArrayLength(mJavaArray); \
+ } \
+ private: \
+ JNIEnv* mEnv; \
+ PRIMITIVE_TYPE ## Array mJavaArray; \
+ PRIMITIVE_TYPE* mRawArray; \
+ Scoped ## NAME ## Array(const Scoped ## NAME ## Array&); \
+ void operator=(const Scoped ## NAME ## Array&); \
+ }
+
+INSTANTIATE_SCOPED_PRIMITIVE_ARRAY(jboolean, Boolean);
+INSTANTIATE_SCOPED_PRIMITIVE_ARRAY(jbyte, Byte);
+INSTANTIATE_SCOPED_PRIMITIVE_ARRAY(jchar, Char);
+INSTANTIATE_SCOPED_PRIMITIVE_ARRAY(jdouble, Double);
+INSTANTIATE_SCOPED_PRIMITIVE_ARRAY(jfloat, Float);
+INSTANTIATE_SCOPED_PRIMITIVE_ARRAY(jint, Int);
+INSTANTIATE_SCOPED_PRIMITIVE_ARRAY(jlong, Long);
+INSTANTIATE_SCOPED_PRIMITIVE_ARRAY(jshort, Short);
+
+#undef INSTANTIATE_SCOPED_PRIMITIVE_ARRAY
+
+#endif // SCOPED_PRIMITIVE_ARRAY_H_included
diff --git a/luni/src/main/java/java/util/zip/Adler32.java b/luni/src/main/java/java/util/zip/Adler32.java
index ebdc996..7682ef9 100644
--- a/luni/src/main/java/java/util/zip/Adler32.java
+++ b/luni/src/main/java/java/util/zip/Adler32.java
@@ -19,10 +19,8 @@ package java.util.zip;
/**
* The Adler-32 class is used to compute the {@code Adler32} checksum from a set
- * of data. Compared to the CRC-32 algorithm it trades reliabilty for speed.
+ * of data. Compared to {@link CRC32} it trades reliability for speed.
* Refer to RFC 1950 for the specification.
- *
- * @see CRC32
*/
public class Adler32 implements java.util.zip.Checksum {
diff --git a/luni/src/main/native/BidiWrapper.cpp b/luni/src/main/native/BidiWrapper.cpp
index 3ec51cb..0f55430 100644
--- a/luni/src/main/native/BidiWrapper.cpp
+++ b/luni/src/main/native/BidiWrapper.cpp
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/luni/src/main/native/NativeConverter.cpp b/luni/src/main/native/NativeConverter.cpp
index 5ef5329..95b7752 100644
--- a/luni/src/main/native/NativeConverter.cpp
+++ b/luni/src/main/native/NativeConverter.cpp
@@ -76,11 +76,11 @@ static void closeConverter(JNIEnv*, jclass, jlong handle) {
}
/**
- * Converts a buffer of Unicode code units to target encoding
- * @param env environment handle for JNI
+ * Converts a buffer of Unicode code units to target encoding
+ * @param env environment handle for JNI
* @param jClass handle for the class
* @param handle address of ICU converter
- * @param source buffer of Unicode chars to convert
+ * @param source buffer of Unicode chars to convert
* @param sourceEnd limit of the source buffer
* @param target buffer to recieve the converted bytes
* @param targetEnd the limit of the target buffer
@@ -88,60 +88,57 @@ static void closeConverter(JNIEnv*, jclass, jlong handle) {
* @param flush boolean that specifies end of source input
*/
static jint convertCharToByte(JNIEnv* env, jclass, jlong handle, jcharArray source, jint sourceEnd, jbyteArray target, jint targetEnd, jintArray data, jboolean flush) {
-
- UErrorCode errorCode =U_ZERO_ERROR;
UConverter* cnv = (UConverter*)handle;
- if(cnv) {
- jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
- if(myData) {
- jint* sourceOffset = &myData[0];
- jint* targetOffset = &myData[1];
- const jchar* uSource =(jchar*) env->GetPrimitiveArrayCritical(source, NULL);
- if(uSource) {
- jbyte* uTarget=(jbyte*) env->GetPrimitiveArrayCritical(target,NULL);
- if(uTarget) {
- const jchar* mySource = uSource+ *sourceOffset;
- const UChar* mySourceLimit= uSource+sourceEnd;
- char* cTarget = reinterpret_cast<char*>(uTarget+ *targetOffset);
- const char* cTargetLimit = reinterpret_cast<const char*>(uTarget+targetEnd);
-
- ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&mySource,
- mySourceLimit,NULL,(UBool) flush, &errorCode);
-
- *sourceOffset = (jint) (mySource - uSource)-*sourceOffset;
- *targetOffset = (jint) ((jbyte*)cTarget - uTarget)- *targetOffset;
- if(U_FAILURE(errorCode)) {
- env->ReleasePrimitiveArrayCritical(target,uTarget,0);
- env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0);
- env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
- return errorCode;
- }
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ if (!cnv) {
+ return U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ UErrorCode errorCode = U_ZERO_ERROR;
+ jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
+ if(myData) {
+ jint* sourceOffset = &myData[0];
+ jint* targetOffset = &myData[1];
+ const jchar* uSource =(jchar*) env->GetPrimitiveArrayCritical(source, NULL);
+ if(uSource) {
+ jbyte* uTarget=(jbyte*) env->GetPrimitiveArrayCritical(target,NULL);
+ if(uTarget) {
+ const jchar* mySource = uSource+ *sourceOffset;
+ const UChar* mySourceLimit= uSource+sourceEnd;
+ char* cTarget = reinterpret_cast<char*>(uTarget+ *targetOffset);
+ const char* cTargetLimit = reinterpret_cast<const char*>(uTarget+targetEnd);
+
+ ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&mySource, mySourceLimit,NULL,(UBool) flush, &errorCode);
+
+ *sourceOffset = (jint) (mySource - uSource)-*sourceOffset;
+ *targetOffset = (jint) ((jbyte*)cTarget - uTarget)- *targetOffset;
+ if(U_FAILURE(errorCode)) {
+ env->ReleasePrimitiveArrayCritical(target,uTarget,0);
+ env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0);
+ env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
+ return errorCode;
}
- env->ReleasePrimitiveArrayCritical(target,uTarget,0);
}else{
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
- env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0);
+ env->ReleasePrimitiveArrayCritical(target,uTarget,0);
}else{
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
- env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
- return errorCode;
+ env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0);
+ }else{
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
return errorCode;
}
static jint encode(JNIEnv* env, jclass, jlong handle, jcharArray source, jint sourceEnd, jbyteArray target, jint targetEnd, jintArray data, jboolean flush) {
-
+
UErrorCode ec = UErrorCode(convertCharToByte(env, NULL,handle,source,sourceEnd, target,targetEnd,data,flush));
UConverter* cnv = (UConverter*)handle;
jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
if(cnv && myData) {
-
+
UErrorCode errorCode = U_ZERO_ERROR;
myData[3] = ucnv_fromUCountPending(cnv, &errorCode);
@@ -161,10 +158,10 @@ static jint encode(JNIEnv* env, jclass, jlong handle, jcharArray source, jint so
/**
* Converts a buffer of encoded bytes to Unicode code units
- * @param env environment handle for JNI
+ * @param env environment handle for JNI
* @param jClass handle for the class
* @param handle address of ICU converter
- * @param source buffer of Unicode chars to convert
+ * @param source buffer of Unicode chars to convert
* @param sourceEnd limit of the source buffer
* @param target buffer to recieve the converted bytes
* @param targetEnd the limit of the target buffer
@@ -189,10 +186,10 @@ static jint convertByteToChar(JNIEnv* env, jclass, jlong handle, jbyteArray sour
const char* mySourceLimit = reinterpret_cast<const char*>(uSource+sourceEnd);
UChar* cTarget=uTarget+ *targetOffset;
const UChar* cTargetLimit=uTarget+targetEnd;
-
+
ucnv_toUnicode( cnv , &cTarget, cTargetLimit,(const char**)&mySource,
mySourceLimit,NULL,(UBool) flush, &errorCode);
-
+
*sourceOffset = mySource - uSource - *sourceOffset ;
*targetOffset = cTarget - uTarget - *targetOffset;
if(U_FAILURE(errorCode)) {
@@ -234,10 +231,10 @@ static jint decode(JNIEnv* env, jclass, jlong handle, jbyteArray source, jint so
char invalidChars[32] = {'\0'};
int8_t len = 32;
ucnv_getInvalidChars(cnv,invalidChars,&len,&errorCode);
-
+
if(U_SUCCESS(errorCode)) {
myData[2] = len;
- }
+ }
}
}
env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
@@ -320,7 +317,7 @@ static jint flushByteToChar(JNIEnv* env, jclass,jlong handle, jcharArray target,
}
static jint flushCharToByte (JNIEnv* env, jclass, jlong handle, jbyteArray target, jint targetEnd, jintArray data) {
-
+
UErrorCode errorCode =U_ZERO_ERROR;
UConverter* cnv = (UConverter*)handle;
jchar source = '\0';
@@ -337,12 +334,12 @@ static jint flushCharToByte (JNIEnv* env, jclass, jlong handle, jbyteArray targe
ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&mySource,
mySourceLimit,NULL,TRUE, &errorCode);
-
+
*targetOffset = (jint) ((jbyte*)cTarget - uTarget)- *targetOffset;
if(U_FAILURE(errorCode)) {
env->ReleasePrimitiveArrayCritical(target,uTarget,0);
-
+
env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
return errorCode;
}
@@ -400,7 +397,7 @@ struct SubCharStruct {
};
-static UErrorCode
+static UErrorCode
setToUCallbackSubs(UConverter* cnv,UChar* subChars, int32_t length,UBool stopOnIllegal ) {
SubCharStruct* substitutionCharS = (SubCharStruct*) malloc(sizeof(SubCharStruct));
UErrorCode errorCode = U_ZERO_ERROR;
@@ -470,7 +467,7 @@ static void JNI_TO_U_CALLBACK_SUBSTITUTE( const void *context, UConverterToUnico
ucnv_cbToUWriteUChars(toArgs,temp->subChars ,temp->length , 0, err);
}else{
if(reason != UCNV_UNASSIGNED) {
- /* the caller must have set
+ /* the caller must have set
* the error code accordingly
*/
return;
@@ -486,7 +483,7 @@ static void JNI_TO_U_CALLBACK_SUBSTITUTE( const void *context, UConverterToUnico
}
static jboolean canEncode(JNIEnv*, jclass, jlong handle, jint codeUnit) {
-
+
UErrorCode errorCode =U_ZERO_ERROR;
UConverter* cnv = (UConverter*)handle;
if(cnv) {
@@ -499,8 +496,8 @@ static jboolean canEncode(JNIEnv*, jclass, jlong handle, jint codeUnit) {
int i=0;
UTF_APPEND_CHAR(&source[0],i,2,codeUnit);
- ucnv_fromUnicode(cnv,&myTarget,targetLimit,
- (const UChar**)&mySource,
+ ucnv_fromUnicode(cnv,&myTarget,targetLimit,
+ (const UChar**)&mySource,
sourceLimit,NULL, TRUE,&errorCode);
if(U_SUCCESS(errorCode)) {
@@ -643,10 +640,10 @@ static void CHARSET_ENCODER_CALLBACK(const void *context,
int32_t length,
UChar32 codePoint,
UConverterCallbackReason reason,
- UErrorCode * status) {
+ UErrorCode * status) {
if(context) {
EncoderCallbackContext* ctx = (EncoderCallbackContext*)context;
-
+
if(ctx) {
UConverterFromUCallback realCB = NULL;
switch(reason) {
@@ -677,7 +674,7 @@ static void CHARSET_ENCODER_CALLBACK(const void *context,
realCB(context, fromArgs, codeUnits, length, codePoint, reason, status);
}
}
- }
+ }
}
static void JNI_FROM_U_CALLBACK_SUBSTITUTE_ENCODER(const void *context,
@@ -713,7 +710,7 @@ static jint setCallbackEncode(JNIEnv* env, jclass, jlong handle, jint onMalforme
UErrorCode errorCode =U_ZERO_ERROR;
if(conv) {
-
+
UConverterFromUCallback fromUOldAction = NULL;
void* fromUOldContext = NULL;
EncoderCallbackContext* fromUNewContext=NULL;
@@ -759,7 +756,7 @@ static jint setCallbackEncode(JNIEnv* env, jclass, jlong handle, jint onMalforme
}
return U_ILLEGAL_ARGUMENT_ERROR;
}
-
+
struct DecoderCallbackContext {
int length;
UChar subUChars[256];
@@ -794,15 +791,15 @@ static UConverterToUCallback getToUCallback(int32_t mode) {
}
static void CHARSET_DECODER_CALLBACK(const void *context,
- UConverterToUnicodeArgs *args,
- const char* codeUnits,
+ UConverterToUnicodeArgs *args,
+ const char* codeUnits,
int32_t length,
UConverterCallbackReason reason,
UErrorCode *status ) {
-
+
if(context) {
DecoderCallbackContext* ctx = (DecoderCallbackContext*)context;
-
+
if(ctx) {
UConverterToUCallback realCB = NULL;
switch(reason) {
@@ -833,21 +830,21 @@ static void CHARSET_DECODER_CALLBACK(const void *context,
realCB(context, args, codeUnits, length, reason, status);
}
}
- }
+ }
}
static jint setCallbackDecode(JNIEnv* env, jclass, jlong handle, jint onMalformedInput, jint onUnmappableInput, jcharArray subChars, jint length) {
-
+
UConverter* conv = (UConverter*)handle;
UErrorCode errorCode =U_ZERO_ERROR;
if(conv) {
-
+
UConverterToUCallback toUOldAction ;
void* toUOldContext;
DecoderCallbackContext* toUNewContext = NULL;
UConverterToUCallback toUNewAction = NULL;
jchar* sub = (jchar*) env->GetPrimitiveArrayCritical(subChars, NULL);
-
+
ucnv_getToUCallBack(conv, &toUOldAction, const_cast<const void**>(&toUOldContext));
/* toUOldContext can only be DecodeCallbackContext since
@@ -920,7 +917,7 @@ static jboolean contains(JNIEnv*, jclass, jlong handle1, jlong handle2) {
const UConverter * cnv1 = (const UConverter *) handle1;
const UConverter * cnv2 = (const UConverter *) handle2;
UBool bRet = 0;
-
+
if(cnv1 != NULL && cnv2 != NULL) {
/* open charset 1 */
USet* set1 = uset_open(1, 2);
diff --git a/luni/src/main/native/java_io_File.cpp b/luni/src/main/native/java_io_File.cpp
index 1d5ec51..864a105 100644
--- a/luni/src/main/native/java_io_File.cpp
+++ b/luni/src/main/native/java_io_File.cpp
@@ -17,8 +17,8 @@
#include "JNIHelp.h"
#include "LocalArray.h"
-#include "ScopedByteArray.h"
#include "ScopedFd.h"
+#include "ScopedPrimitiveArray.h"
#include <dirent.h>
#include <errno.h>
@@ -37,25 +37,29 @@
// poor choices of where to divide the work between Java and native
// code.
+static const char* toPath(const ScopedByteArray& path) {
+ return reinterpret_cast<const char*>(&path[0]);
+}
+
static jbyteArray java_io_File_getCanonImpl(JNIEnv* env, jobject, jbyteArray pathBytes) {
ScopedByteArray path(env, pathBytes);
// The only thing this native code currently does is truncate the byte[] at
// the first NUL.
// TODO: this is completely pointless. we should do this in Java, or do all of getCanonicalPath in native code. (realpath(2)?)
- size_t length = strlen(&path[0]);
+ size_t length = strlen(toPath(path));
jbyteArray result = env->NewByteArray(length);
- env->SetByteArrayRegion(result, 0, length, path.bytes());
+ env->SetByteArrayRegion(result, 0, length, path.get());
return result;
}
static jboolean java_io_File_deleteImpl(JNIEnv* env, jobject, jbyteArray pathBytes) {
ScopedByteArray path(env, pathBytes);
- return (remove(&path[0]) == 0);
+ return (remove(toPath(path)) == 0);
}
static bool doStat(JNIEnv* env, jbyteArray pathBytes, struct stat& sb) {
ScopedByteArray path(env, pathBytes);
- return (stat(&path[0], &sb) == 0);
+ return (stat(toPath(path), &sb) == 0);
}
static jlong java_io_File_lengthImpl(JNIEnv* env, jobject, jbyteArray pathBytes) {
@@ -65,7 +69,7 @@ static jlong java_io_File_lengthImpl(JNIEnv* env, jobject, jbyteArray pathBytes)
// TODO: shouldn't we throw an IOException for ELOOP or EACCES?
return 0;
}
-
+
/*
* This android-changed code explicitly treats non-regular files (e.g.,
* sockets and block-special devices) as having size zero. Some synthetic
@@ -73,7 +77,7 @@ static jlong java_io_File_lengthImpl(JNIEnv* env, jobject, jbyteArray pathBytes)
* in these cases they generally report a block count of zero.
* So, use a zero block count to trump any other concept of
* size.
- *
+ *
* TODO: why do we do this?
*/
if (!S_ISREG(sb.st_mode) || sb.st_blocks == 0) {
@@ -102,22 +106,22 @@ static jboolean java_io_File_isFileImpl(JNIEnv* env, jobject, jbyteArray pathByt
static jboolean java_io_File_existsImpl(JNIEnv* env, jobject, jbyteArray pathBytes) {
ScopedByteArray path(env, pathBytes);
- return (access(&path[0], F_OK) == 0);
+ return (access(toPath(path), F_OK) == 0);
}
static jboolean java_io_File_canExecuteImpl(JNIEnv* env, jobject, jbyteArray pathBytes) {
ScopedByteArray path(env, pathBytes);
- return (access(&path[0], X_OK) == 0);
+ return (access(toPath(path), X_OK) == 0);
}
static jboolean java_io_File_canReadImpl(JNIEnv* env, jobject, jbyteArray pathBytes) {
ScopedByteArray path(env, pathBytes);
- return (access(&path[0], R_OK) == 0);
+ return (access(toPath(path), R_OK) == 0);
}
static jboolean java_io_File_canWriteImpl(JNIEnv* env, jobject, jbyteArray pathBytes) {
ScopedByteArray path(env, pathBytes);
- return (access(&path[0], W_OK) == 0);
+ return (access(toPath(path), W_OK) == 0);
}
static jbyteArray java_io_File_getLinkImpl(JNIEnv* env, jobject, jbyteArray pathBytes) {
@@ -128,7 +132,7 @@ static jbyteArray java_io_File_getLinkImpl(JNIEnv* env, jobject, jbyteArray path
size_t bufSize = 512;
while (true) {
LocalArray<512> buf(bufSize);
- ssize_t len = readlink(&path[0], &buf[0], buf.size() - 1);
+ ssize_t len = readlink(toPath(path), &buf[0], buf.size() - 1);
if (len == -1) {
// An error occurred.
return pathBytes;
@@ -149,28 +153,28 @@ static jbyteArray java_io_File_getLinkImpl(JNIEnv* env, jobject, jbyteArray path
static jboolean java_io_File_setLastModifiedImpl(JNIEnv* env, jobject, jbyteArray pathBytes, jlong ms) {
ScopedByteArray path(env, pathBytes);
-
+
// We want to preserve the access time.
struct stat sb;
- if (stat(&path[0], &sb) == -1) {
+ if (stat(toPath(path), &sb) == -1) {
return JNI_FALSE;
}
-
+
// TODO: we could get microsecond resolution with utimes(3), "legacy" though it is.
utimbuf times;
times.actime = sb.st_atime;
times.modtime = static_cast<time_t>(ms / 1000);
- return (utime(&path[0], &times) == 0);
+ return (utime(toPath(path), &times) == 0);
}
static jboolean doChmod(JNIEnv* env, jbyteArray pathBytes, mode_t mask, bool set) {
ScopedByteArray path(env, pathBytes);
struct stat sb;
- if (stat(&path[0], &sb) == -1) {
+ if (stat(toPath(path), &sb) == -1) {
return JNI_FALSE;
}
mode_t newMode = set ? (sb.st_mode | mask) : (sb.st_mode & ~mask);
- return (chmod(&path[0], newMode) == 0);
+ return (chmod(toPath(path), newMode) == 0);
}
static jboolean java_io_File_setExecutableImpl(JNIEnv* env, jobject, jbyteArray pathBytes,
@@ -190,7 +194,7 @@ static jboolean java_io_File_setWritableImpl(JNIEnv* env, jobject, jbyteArray pa
static bool doStatFs(JNIEnv* env, jbyteArray pathBytes, struct statfs& sb) {
ScopedByteArray path(env, pathBytes);
- int rc = statfs(&path[0], &sb);
+ int rc = statfs(toPath(path), &sb);
return (rc != -1);
}
@@ -323,7 +327,7 @@ private:
// to 'entries'.
static bool readDirectory(JNIEnv* env, jbyteArray pathBytes, DirEntries& entries) {
ScopedByteArray path(env, pathBytes);
- ScopedReaddir dir(&path[0]);
+ ScopedReaddir dir(toPath(path));
if (dir.isBad()) {
return false;
}
@@ -368,13 +372,13 @@ static jobjectArray java_io_File_listImpl(JNIEnv* env, jobject, jbyteArray pathB
static jboolean java_io_File_mkdirImpl(JNIEnv* env, jobject, jbyteArray pathBytes) {
ScopedByteArray path(env, pathBytes);
// On Android, we don't want default permissions to allow global access.
- return (mkdir(&path[0], S_IRWXU) == 0);
+ return (mkdir(toPath(path), S_IRWXU) == 0);
}
static jboolean java_io_File_createNewFileImpl(JNIEnv* env, jobject, jbyteArray pathBytes) {
ScopedByteArray path(env, pathBytes);
// On Android, we don't want default permissions to allow global access.
- ScopedFd fd(open(&path[0], O_CREAT | O_EXCL, 0600));
+ ScopedFd fd(open(toPath(path), O_CREAT | O_EXCL, 0600));
if (fd.get() != -1) {
// We created a new file. Success!
return JNI_TRUE;
@@ -390,7 +394,7 @@ static jboolean java_io_File_createNewFileImpl(JNIEnv* env, jobject, jbyteArray
static jboolean java_io_File_renameToImpl(JNIEnv* env, jobject, jbyteArray oldPathBytes, jbyteArray newPathBytes) {
ScopedByteArray oldPath(env, oldPathBytes);
ScopedByteArray newPath(env, newPathBytes);
- return (rename(&oldPath[0], &newPath[0]) == 0);
+ return (rename(toPath(oldPath), toPath(newPath)) == 0);
}
static JNINativeMethod gMethods[] = {
diff --git a/luni/src/main/native/java_util_zip_Adler32.cpp b/luni/src/main/native/java_util_zip_Adler32.cpp
index 3dc1802..3112600 100644
--- a/luni/src/main/native/java_util_zip_Adler32.cpp
+++ b/luni/src/main/native/java_util_zip_Adler32.cpp
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,18 +16,17 @@
*/
#include "JNIHelp.h"
+#include "ScopedPrimitiveArray.h"
#include "jni.h"
#include "zlib.h"
-static jlong Adler32_updateImpl(JNIEnv* env, jobject, jbyteArray buf, int off, int len, jlong crc) {
- jbyte* b = (jbyte*) env->GetPrimitiveArrayCritical(buf, NULL);
- if (b == NULL) {
+static jlong Adler32_updateImpl(JNIEnv* env, jobject, jbyteArray byteArray, int off, int len, jlong crc) {
+ ScopedByteArray bytes(env, byteArray);
+ if (bytes.get() == NULL) {
jniThrowNullPointerException(env, NULL);
return 0;
}
- jlong result = (jlong) adler32((uLong) crc, (Bytef *) (b + off), (uInt) len);
- env->ReleasePrimitiveArrayCritical(buf, b, JNI_ABORT);
- return result;
+ return adler32((uLong) crc, (Bytef *) (bytes.get() + off), (uInt) len);
}
static jlong Adler32_updateByteImpl(JNIEnv*, jobject, jint val, jlong crc) {
diff --git a/luni/src/main/native/java_util_zip_CRC32.cpp b/luni/src/main/native/java_util_zip_CRC32.cpp
index 7b1bd29..3ee3273 100644
--- a/luni/src/main/native/java_util_zip_CRC32.cpp
+++ b/luni/src/main/native/java_util_zip_CRC32.cpp
@@ -1,13 +1,13 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,17 +16,17 @@
*/
#include "JNIHelp.h"
+#include "ScopedPrimitiveArray.h"
#include "jni.h"
#include "zlib.h"
-static jlong CRC32_updateImpl(JNIEnv* env, jobject, jbyteArray buf, int off, int len, jlong crc) {
- jbyte* b = (jbyte*) env->GetPrimitiveArrayCritical(buf, NULL);
- if (b == NULL) {
+static jlong CRC32_updateImpl(JNIEnv* env, jobject, jbyteArray byteArray, int off, int len, jlong crc) {
+ ScopedByteArray bytes(env, byteArray);
+ if (bytes.get() == NULL) {
jniThrowNullPointerException(env, NULL);
return 0;
}
- jlong result = crc32((uLong) crc, (Bytef *) (b + off), (uInt) len);
- env->ReleasePrimitiveArrayCritical(buf, b, JNI_ABORT);
+ jlong result = crc32((uLong) crc, (Bytef *) (bytes.get() + off), (uInt) len);
return result;
}
diff --git a/luni/src/main/native/java_util_zip_Deflater.cpp b/luni/src/main/native/java_util_zip_Deflater.cpp
index c449087..35d3f6b 100644
--- a/luni/src/main/native/java_util_zip_Deflater.cpp
+++ b/luni/src/main/native/java_util_zip_Deflater.cpp
@@ -15,6 +15,7 @@
* limitations under the License.
*/
+#include "ScopedPrimitiveArray.h"
#include "zip.h"
static struct {
@@ -76,13 +77,12 @@ static jint Deflater_deflateImpl(JNIEnv* env, jobject recv, jbyteArray buf, int
stream->stream.avail_out = len;
jint sin = stream->stream.total_in;
jint sout = stream->stream.total_out;
- jbyte* out = (jbyte*) env->GetPrimitiveArrayCritical(buf, NULL);
- if (out == NULL) {
+ ScopedByteArray out(env, buf);
+ if (out.get() == NULL) {
return -1;
}
- stream->stream.next_out = (Bytef *) out + off;
+ stream->stream.next_out = (Bytef *) out.get() + off;
int err = deflate(&stream->stream, flushParm);
- env->ReleasePrimitiveArrayCritical(buf, out, 0);
if (err != Z_OK) {
if (err == Z_MEM_ERROR) {
jniThrowOutOfMemoryError(env, NULL);
diff --git a/luni/src/main/native/java_util_zip_Inflater.cpp b/luni/src/main/native/java_util_zip_Inflater.cpp
index e07de72..fcedc28 100644
--- a/luni/src/main/native/java_util_zip_Inflater.cpp
+++ b/luni/src/main/native/java_util_zip_Inflater.cpp
@@ -15,6 +15,7 @@
* limitations under the License.
*/
+#include "ScopedPrimitiveArray.h"
#include "zip.h"
static struct {
@@ -75,15 +76,13 @@ static jint Inflater_inflateImpl(JNIEnv* env, jobject recv, jbyteArray buf, int
stream->stream.avail_out = len;
jint sin = stream->stream.total_in;
jint sout = stream->stream.total_out;
- jbyte* out = (jbyte*) env->GetPrimitiveArrayCritical(buf, 0);
- if (out == NULL) {
+ ScopedByteArray out(env, buf);
+ if (out.get() == NULL) {
jniThrowOutOfMemoryError(env, NULL);
return -1;
}
- stream->stream.next_out = (Bytef *) out + off;
+ stream->stream.next_out = (Bytef *) out.get() + off;
int err = inflate(&stream->stream, Z_SYNC_FLUSH);
- env->ReleasePrimitiveArrayCritical(buf, out, 0);
-
if (err != Z_OK) {
if (err == Z_STREAM_ERROR) {
return 0;
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 5813fb8..1ab8743 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
@@ -30,7 +30,7 @@
#include "JNIHelp.h"
#include "LocalArray.h"
-#include "ScopedByteArray.h"
+#include "ScopedPrimitiveArray.h"
#include "UniquePtr.h"
#include <assert.h>
@@ -198,16 +198,13 @@ static iovec* initIoVec(JNIEnv* env,
jniThrowException(env, "java/lang/OutOfMemoryError", "native heap");
return NULL;
}
- jint *buffers = env->GetIntArrayElements(jBuffers, NULL);
- jint *offsets = env->GetIntArrayElements(jOffsets, NULL);
- jint *lengths = env->GetIntArrayElements(jLengths, NULL);
+ ScopedIntArray buffers(env, jBuffers);
+ ScopedIntArray offsets(env, jOffsets);
+ ScopedIntArray lengths(env, jLengths);
for (int i = 0; i < size; ++i) {
vectors[i].iov_base = reinterpret_cast<void*>(buffers[i] + offsets[i]);
vectors[i].iov_len = lengths[i];
}
- env->ReleaseIntArrayElements(jBuffers, buffers, JNI_ABORT);
- env->ReleaseIntArrayElements(jOffsets, offsets, JNI_ABORT);
- env->ReleaseIntArrayElements(jLengths, lengths, JNI_ABORT);
return vectors;
}
@@ -297,7 +294,6 @@ static jlong harmony_io_readImpl(JNIEnv* env, jobject, jint fd,
jbyte* bytes = env->GetByteArrayElements(byteArray, NULL);
jlong rc = TEMP_FAILURE_RETRY(read(fd, bytes + offset, nbytes));
env->ReleaseByteArrayElements(byteArray, bytes, 0);
-
if (rc == 0) {
return -1;
}
@@ -315,10 +311,8 @@ static jlong harmony_io_readImpl(JNIEnv* env, jobject, jint fd,
static jlong harmony_io_writeImpl(JNIEnv* env, jobject, jint fd,
jbyteArray byteArray, jint offset, jint nbytes) {
- jbyte* bytes = env->GetByteArrayElements(byteArray, NULL);
- jlong result = TEMP_FAILURE_RETRY(write(fd, bytes + offset, nbytes));
- env->ReleaseByteArrayElements(byteArray, bytes, JNI_ABORT);
-
+ ScopedByteArray bytes(env, byteArray);
+ jlong result = TEMP_FAILURE_RETRY(write(fd, bytes.get() + offset, nbytes));
if (result == -1) {
if (errno == EAGAIN) {
jniThrowException(env, "java/io/InterruptedIOException",
@@ -425,16 +419,15 @@ static jint harmony_io_openImpl(JNIEnv* env, jobject, jbyteArray pathByteArray,
flags = EsTranslateOpenFlags(flags);
ScopedByteArray path(env, pathByteArray);
- jint rc = TEMP_FAILURE_RETRY(open(&path[0], flags, mode));
+ jint rc = TEMP_FAILURE_RETRY(open(reinterpret_cast<const char*>(&path[0]), flags, mode));
if (rc == -1) {
// Get the human-readable form of errno.
char buffer[80];
const char* reason = jniStrError(errno, &buffer[0], sizeof(buffer));
// Construct a message that includes the path and the reason.
- // (pathByteCount already includes space for our trailing NUL.)
- size_t pathByteCount = env->GetArrayLength(pathByteArray);
- LocalArray<128> message(pathByteCount + 2 + strlen(reason) + 1);
+ // (path.size() already includes space for our trailing NUL.)
+ LocalArray<128> message(path.size() + 2 + strlen(reason) + 1);
snprintf(&message[0], message.size(), "%s (%s)", &path[0], reason);
// We always throw FileNotFoundException, regardless of the specific
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 84d2ea0..753635c 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
@@ -25,6 +25,7 @@
#include "JNIHelp.h"
#include "LocalArray.h"
+#include "ScopedPrimitiveArray.h"
#include "jni.h"
#include <arpa/inet.h>
@@ -1671,12 +1672,10 @@ static jint osNetworkSystem_sendDatagramDirect(JNIEnv* env, jobject,
static jint osNetworkSystem_sendDatagram(JNIEnv* env, jobject,
jobject fd, jbyteArray data, jint offset, jint length, jint port,
jboolean bindToDevice, jint trafficClass, jobject inetAddress) {
- jbyte *bytes = env->GetByteArrayElements(data, NULL);
- int actualLength = osNetworkSystem_sendDatagramDirect(env, NULL, fd,
- (jint)bytes, offset, length, port, bindToDevice, trafficClass,
- inetAddress);
- env->ReleaseByteArrayElements(data, bytes, JNI_ABORT);
- return actualLength;
+ ScopedByteArray bytes(env, data);
+ return osNetworkSystem_sendDatagramDirect(env, NULL, fd,
+ reinterpret_cast<uintptr_t>(bytes.get()), offset, length, port,
+ bindToDevice, trafficClass, inetAddress);
}
static jint osNetworkSystem_sendConnectedDatagramDirect(JNIEnv* env,
@@ -1704,12 +1703,9 @@ static jint osNetworkSystem_sendConnectedDatagramDirect(JNIEnv* env,
static jint osNetworkSystem_sendConnectedDatagram(JNIEnv* env, jobject,
jobject fd, jbyteArray data, jint offset, jint length,
jboolean bindToDevice) {
- jbyte *bytes = env->GetByteArrayElements(data, NULL);
- int actualLength = osNetworkSystem_sendConnectedDatagramDirect(env,
- NULL, fd, (jint)bytes, offset, length, bindToDevice);
- env->ReleaseByteArrayElements(data, bytes, JNI_ABORT);
-
- return actualLength;
+ ScopedByteArray bytes(env, data);
+ return osNetworkSystem_sendConnectedDatagramDirect(env, NULL, fd,
+ reinterpret_cast<uintptr_t>(bytes.get()), offset, length, bindToDevice);
}
static void osNetworkSystem_createServerStreamSocket(JNIEnv* env, jobject,
diff --git a/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp b/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp
index 78c29f9..4f0dc6e 100644
--- a/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp
+++ b/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp
@@ -18,6 +18,7 @@
#include "JNIHelp.h"
#include "LocalArray.h"
+#include "ScopedPrimitiveArray.h"
#include "jni.h"
#include "utils/Log.h"
@@ -40,7 +41,7 @@ struct InternedString {
const char* bytes;
/** Hash code of the interned string. */
- int hash;
+ int hash;
};
/**
@@ -936,10 +937,10 @@ static void unparsedEntityDecl(void* data, const char* name, const char* base, c
ParsingContext* parsingContext = reinterpret_cast<ParsingContext*>(data);
jobject javaParser = parsingContext->object;
JNIEnv* env = parsingContext->env;
-
+
// Bail out if a previously called handler threw an exception.
if (env->ExceptionCheck()) return;
-
+
jstring javaName = env->NewStringUTF(name);
if (env->ExceptionCheck()) return;
jstring javaPublicId = env->NewStringUTF(publicId);
@@ -948,9 +949,9 @@ static void unparsedEntityDecl(void* data, const char* name, const char* base, c
if (env->ExceptionCheck()) return;
jstring javaNotationName = env->NewStringUTF(notationName);
if (env->ExceptionCheck()) return;
-
+
env->CallVoidMethod(javaParser, unparsedEntityDeclMethod, javaName, javaPublicId, javaSystemId, javaNotationName);
-
+
env->DeleteLocalRef(javaName);
env->DeleteLocalRef(javaPublicId);
env->DeleteLocalRef(javaSystemId);
@@ -961,19 +962,19 @@ static void notationDecl(void* data, const char* name, const char* base, const c
ParsingContext* parsingContext = reinterpret_cast<ParsingContext*>(data);
jobject javaParser = parsingContext->object;
JNIEnv* env = parsingContext->env;
-
+
// Bail out if a previously called handler threw an exception.
if (env->ExceptionCheck()) return;
-
+
jstring javaName = env->NewStringUTF(name);
if (env->ExceptionCheck()) return;
jstring javaPublicId = env->NewStringUTF(publicId);
if (env->ExceptionCheck()) return;
jstring javaSystemId = env->NewStringUTF(systemId);
if (env->ExceptionCheck()) return;
-
+
env->CallVoidMethod(javaParser, notationDeclMethod, javaName, javaPublicId, javaSystemId);
-
+
env->DeleteLocalRef(javaName);
env->DeleteLocalRef(javaPublicId);
env->DeleteLocalRef(javaSystemId);
@@ -1066,91 +1067,47 @@ static jint initialize(JNIEnv* env, jobject object, jstring javaEncoding,
}
/**
- * Passes some XML to the parser.
- *
- * @param object the Java ExpatParser instance
- * @param pointer to the C expat parser
- * @param xml Java string containing an XML snippet
- * @param isFinal whether or not this is the last snippet; enables more error
- * checking, i.e. is the document complete?
- */
-static void appendString(JNIEnv* env, jobject object, jint pointer, jstring xml,
- jboolean isFinal) {
- XML_Parser parser = (XML_Parser) pointer;
- ParsingContext* context = (ParsingContext*) XML_GetUserData(parser);
- context->env = env;
- context->object = object;
-
- int length = env->GetStringLength(xml) << 1; // in bytes
- const jchar* characters = env->GetStringChars(xml, NULL);
-
- if (!XML_Parse(parser, (char*) characters, length, isFinal)
- && !env->ExceptionCheck()) {
- jniThrowExpatException(env, XML_GetErrorCode(parser));
- }
-
- env->ReleaseStringChars(xml, characters);
-
- context->object = NULL;
- context->env = NULL;
-}
-
-/**
- * Passes some XML to the parser.
- *
- * @param object the Java ExpatParser instance
- * @param pointer to the C expat parser
- * @param xml Java char[] containing XML
- * @param offset into the xml buffer
- * @param length of text in the xml buffer
+ * Expat decides for itself what character encoding it's looking at. The interface is in terms of
+ * bytes, which may point to UTF-8, UTF-16, ISO-8859-1, or US-ASCII. appendBytes, appendCharacters,
+ * and appendString thus all call through to this method, strange though that appears.
*/
-static void appendCharacters(JNIEnv* env, jobject object, jint pointer,
- jcharArray xml, jint offset, jint length) {
+static void append(JNIEnv* env, jobject object, jint pointer,
+ const char* bytes, size_t byteOffset, size_t byteCount, jboolean isFinal) {
XML_Parser parser = (XML_Parser) pointer;
ParsingContext* context = (ParsingContext*) XML_GetUserData(parser);
context->env = env;
context->object = object;
-
- jchar* characters = env->GetCharArrayElements(xml, NULL);
-
- if (!XML_Parse(parser, ((char*) characters) + (offset << 1),
- length << 1, XML_FALSE) && !env->ExceptionCheck()) {
+ if (!XML_Parse(parser, bytes + byteOffset, byteCount, isFinal) &&
+ !env->ExceptionCheck()) {
jniThrowExpatException(env, XML_GetErrorCode(parser));
}
-
- env->ReleaseCharArrayElements(xml, characters, JNI_ABORT);
-
context->object = NULL;
context->env = NULL;
}
-/**
- * Passes some XML to the parser.
- *
- * @param object the Java ExpatParser instance
- * @param pointer to the C expat parser
- * @param xml Java byte[] containing XML
- * @param offset into the xml buffer
- * @param length of text in the xml buffer
- */
static void appendBytes(JNIEnv* env, jobject object, jint pointer,
- jbyteArray xml, jint offset, jint length) {
- XML_Parser parser = (XML_Parser) pointer;
- ParsingContext* context = (ParsingContext*) XML_GetUserData(parser);
- context->env = env;
- context->object = object;
-
- jbyte* bytes = env->GetByteArrayElements(xml, NULL);
-
- if (!XML_Parse(parser, ((char*) bytes) + offset, length, XML_FALSE)
- && !env->ExceptionCheck()) {
- jniThrowExpatException(env, XML_GetErrorCode(parser));
- }
+ jbyteArray xml, jint byteOffset, jint byteCount) {
+ ScopedByteArray byteArray(env, xml);
+ const char* bytes = reinterpret_cast<const char*>(byteArray.get());
+ append(env, object, pointer, bytes, byteOffset, byteCount, XML_FALSE);
+}
- env->ReleaseByteArrayElements(xml, bytes, JNI_ABORT);
+static void appendCharacters(JNIEnv* env, jobject object, jint pointer,
+ jcharArray xml, jint charOffset, jint charCount) {
+ ScopedCharArray charArray(env, xml);
+ const char* bytes = reinterpret_cast<const char*>(charArray.get());
+ size_t byteOffset = 2 * charOffset;
+ size_t byteCount = 2 * charCount;
+ append(env, object, pointer, bytes, byteOffset, byteCount, XML_FALSE);
+}
- context->object = NULL;
- context->env = NULL;
+static void appendString(JNIEnv* env, jobject object, jint pointer,
+ jstring xml, jboolean isFinal) {
+ const jchar* chars = env->GetStringChars(xml, NULL);
+ const char* bytes = reinterpret_cast<const char*>(chars);
+ size_t byteCount = 2 * env->GetStringLength(xml);
+ append(env, object, pointer, bytes, 0, byteCount, isFinal);
+ env->ReleaseStringChars(xml, chars);
}
/**
@@ -1433,7 +1390,7 @@ static void staticInitialize(JNIEnv* env, jobject classObject, jstring empty) {
startElementMethod = env->GetMethodID(clazz, "startElement",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;II)V");
if (startElementMethod == NULL) return;
-
+
endElementMethod = env->GetMethodID(clazz, "endElement",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
if (endElementMethod == NULL) return;
diff --git a/luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp b/luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp
index a0492ce..8866db6 100644
--- a/luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp
+++ b/luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp
@@ -36,8 +36,8 @@
#include <openssl/rsa.h>
#include <openssl/ssl.h>
-#include "ScopedByteArray.h"
#include "ScopedLocalRef.h"
+#include "ScopedPrimitiveArray.h"
#include "ScopedUtfChars.h"
#include "UniquePtr.h"
@@ -256,9 +256,7 @@ static BIGNUM* arrayToBignum(JNIEnv* env, jbyteArray source) {
// LOGD("Entering arrayToBignum()");
ScopedByteArray sourceBytes(env, source);
- int sourceLength = env->GetArrayLength(source);
- BIGNUM* bignum = BN_bin2bn((unsigned char*) sourceBytes.bytes(), sourceLength, NULL);
- return bignum;
+ return BN_bin2bn((unsigned char*) sourceBytes.get(), sourceBytes.size(), NULL);
}
/**
@@ -551,7 +549,7 @@ static void NativeCrypto_EVP_DigestUpdate(JNIEnv* env, jclass, EVP_MD_CTX* ctx,
}
ScopedByteArray bufferBytes(env, buffer);
- EVP_DigestUpdate(ctx, (unsigned char*) (bufferBytes.bytes() + offset), length);
+ EVP_DigestUpdate(ctx, (unsigned char*) (bufferBytes.get() + offset), length);
throwExceptionIfNecessary(env, "NativeCrypto_EVP_DigestUpdate");
}
@@ -593,7 +591,7 @@ static void NativeCrypto_EVP_VerifyUpdate(JNIEnv* env, jclass, EVP_MD_CTX* ctx,
}
ScopedByteArray bufferBytes(env, buffer);
- EVP_VerifyUpdate(ctx, (unsigned char*) (bufferBytes.bytes() + offset), length);
+ EVP_VerifyUpdate(ctx, (unsigned char*) (bufferBytes.get() + offset), length);
throwExceptionIfNecessary(env, "NativeCrypto_EVP_VerifyUpdate");
}
@@ -610,7 +608,7 @@ static int NativeCrypto_EVP_VerifyFinal(JNIEnv* env, jclass, EVP_MD_CTX* ctx, jb
}
ScopedByteArray bufferBytes(env, buffer);
- int result = EVP_VerifyFinal(ctx, (unsigned char*) (bufferBytes.bytes() + offset), length, pkey);
+ int result = EVP_VerifyFinal(ctx, (unsigned char*) (bufferBytes.get() + offset), length, pkey);
throwExceptionIfNecessary(env, "NativeCrypto_EVP_VerifyFinal");
@@ -709,23 +707,16 @@ static int NativeCrypto_verifysignature(JNIEnv* env, jclass,
int result = -1;
ScopedByteArray msgBytes(env, msg);
- jint msgLength = env->GetArrayLength(msg);
-
ScopedByteArray sigBytes(env, sig);
- jint sigLength = env->GetArrayLength(sig);
-
ScopedByteArray modBytes(env, mod);
- jint modLength = env->GetArrayLength(mod);
-
ScopedByteArray expBytes(env, exp);
- jint expLength = env->GetArrayLength(exp);
ScopedUtfChars algorithmChars(env, algorithm);
JNI_TRACE("NativeCrypto_verifysignature algorithmChars=%s", algorithmChars.c_str());
- RSA* rsa = rsaCreateKey((unsigned char*) modBytes.bytes(), modLength, (unsigned char*) expBytes.bytes(), expLength);
+ RSA* rsa = rsaCreateKey((unsigned char*) modBytes.get(), modBytes.size(), (unsigned char*) expBytes.get(), expBytes.size());
if (rsa != NULL) {
- result = rsaVerify((unsigned char*) msgBytes.bytes(), msgLength, (unsigned char*) sigBytes.bytes(), sigLength,
+ result = rsaVerify((unsigned char*) msgBytes.get(), msgBytes.size(), (unsigned char*) sigBytes.get(), sigBytes.size(),
(char*) algorithmChars.c_str(), rsa);
RSA_free(rsa);
}
@@ -2285,12 +2276,11 @@ static void NativeCrypto_SSL_write(JNIEnv* env, jclass,
ScopedByteArray bytes(env, dest);
int returnCode = 0;
int errorCode = 0;
- int ret = sslWrite(env, ssl, (const char *) (bytes.bytes() + offset), len, &returnCode, &errorCode);
+ int ret = sslWrite(env, ssl, (const char *) (bytes.get() + offset), len, &returnCode, &errorCode);
if (ret == THROW_EXCEPTION) {
// See sslWrite() regarding improper failure to handle normal cases.
- throwSSLExceptionWithSslErrors(env, ssl, errorCode,
- "Write error");
+ throwSSLExceptionWithSslErrors(env, ssl, errorCode, "Write error");
} else if(ret == THROW_SOCKETTIMEOUTEXCEPTION) {
throwSocketTimeoutException(env, "Write timed out");
}
@@ -2548,7 +2538,7 @@ static jint NativeCrypto_d2i_SSL_SESSION(JNIEnv* env, jclass, jbyteArray bytes,
}
ScopedByteArray tmp(env, bytes);
- const unsigned char* ucp = reinterpret_cast<const unsigned char*>(tmp.bytes());
+ const unsigned char* ucp = reinterpret_cast<const unsigned char*>(tmp.get());
SSL_SESSION* ssl_session = d2i_SSL_SESSION(NULL, &ucp, size);
JNI_TRACE("NativeCrypto_d2i_SSL_SESSION => %p", ssl_session);
diff --git a/openssl/src/main/native/BNInterface.cpp b/openssl/src/main/native/BNInterface.cpp
index 61fa529..44dd38a 100644
--- a/openssl/src/main/native/BNInterface.cpp
+++ b/openssl/src/main/native/BNInterface.cpp
@@ -18,24 +18,21 @@
* Native glue for Java class org.openssl.NativeBN
*/
-#include <jni.h>
-#include <JNIHelp.h>
-#include <openssl/err.h>
-#include <openssl/crypto.h>
+#include "JNIHelp.h"
+#include "ScopedPrimitiveArray.h"
+#include "jni.h"
+#include <assert.h>
#include <openssl/bn.h>
+#include <openssl/crypto.h>
+#include <openssl/err.h>
#include <stdio.h>
-#ifndef FALSE
-#define FALSE 0
-#define TRUE 1
-#endif
-
static int isValidHandle (JNIEnv* env, void* handle, const char *message) {
if (handle == NULL) {
jniThrowNullPointerException(env, message);
- return FALSE;
+ return JNI_FALSE;
}
- return TRUE;
+ return JNI_TRUE;
}
static int oneValidHandle (JNIEnv* env, void* a)
@@ -45,19 +42,19 @@ static int oneValidHandle (JNIEnv* env, void* a)
static int twoValidHandles (JNIEnv* env, void* a, void *b)
{
- if (!oneValidHandle(env, a)) return FALSE;
+ if (!oneValidHandle(env, a)) return JNI_FALSE;
return isValidHandle(env, b, "Mandatory handle (second) passed as null");
}
static int threeValidHandles (JNIEnv* env, void* a, void *b, void* c)
{
- if (!twoValidHandles(env, a, b)) return FALSE;
+ if (!twoValidHandles(env, a, b)) return JNI_FALSE;
return isValidHandle(env, c, "Mandatory handle (third) passed as null");
}
static int fourValidHandles (JNIEnv* env, void* a, void *b, void* c, void* d)
{
- if (!threeValidHandles(env, a, b, c)) return FALSE;
+ if (!threeValidHandles(env, a, b, c)) return JNI_FALSE;
return isValidHandle(env, d, "Mandatory handle (fourth) passed as null");
}
@@ -114,7 +111,7 @@ static int NativeBN_BN_cmp(JNIEnv* env, jclass, BIGNUM* a, BIGNUM* b) {
* public static native int BN_copy(int, int)
*/
static jboolean NativeBN_BN_copy(JNIEnv* env, jclass, BIGNUM* to, BIGNUM* from) {
- if (!twoValidHandles(env, to, from)) return FALSE;
+ if (!twoValidHandles(env, to, from)) return JNI_FALSE;
return (BN_copy(to, from) != NULL);
}
@@ -123,7 +120,7 @@ static jboolean NativeBN_BN_copy(JNIEnv* env, jclass, BIGNUM* to, BIGNUM* from)
* public static native int putULongInt(int, long, int)
*/
static jboolean NativeBN_putULongInt(JNIEnv* env, jclass, BIGNUM* a, unsigned long long dw, jboolean neg) {
- if (!oneValidHandle(env, a)) return FALSE;
+ if (!oneValidHandle(env, a)) return JNI_FALSE;
unsigned int hi = dw >> 32; // This shifts without sign extension.
int lo = (int)dw; // This truncates implicitely.
@@ -135,17 +132,17 @@ static jboolean NativeBN_putULongInt(JNIEnv* env, jclass, BIGNUM* a, unsigned lo
a->top = 2;
a->neg = neg;
bn_correct_top(a);
- return TRUE;
+ return JNI_TRUE;
}
- else return FALSE;
+ else return JNI_FALSE;
}
/**
* public static native int putLongInt(int, long)
*/
static jboolean NativeBN_putLongInt(JNIEnv* env, jclass cls, BIGNUM* a, long long dw) {
- if (dw >= 0) return NativeBN_putULongInt(env, cls, a, dw, FALSE);
- else return NativeBN_putULongInt(env, cls, a, -dw, TRUE);
+ if (dw >= 0) return NativeBN_putULongInt(env, cls, a, dw, JNI_FALSE);
+ else return NativeBN_putULongInt(env, cls, a, -dw, JNI_TRUE);
}
/**
@@ -180,56 +177,49 @@ static int NativeBN_BN_hex2bn(JNIEnv* env, jclass, BIGNUM* a, jstring str) {
* public static native boolean BN_bin2bn(byte[], int, int, int)
*/
static jboolean NativeBN_BN_bin2bn(JNIEnv* env, jclass, jbyteArray arr, int len, jboolean neg, BIGNUM* ret) {
- if (!oneValidHandle(env, ret)) return FALSE;
- jboolean success;
- unsigned char * tmpBytes;
- tmpBytes = (unsigned char *)env->GetPrimitiveArrayCritical(arr, 0);
- if (tmpBytes != NULL) {
- success = (BN_bin2bn(tmpBytes, len, ret) != NULL);
- if (neg) {
- BN_set_negative(ret, 1);
- }
- env->ReleasePrimitiveArrayCritical(arr, tmpBytes, JNI_ABORT);
- return success;
+ if (!oneValidHandle(env, ret)) return JNI_FALSE;
+ ScopedByteArray bytes(env, arr);
+ if (bytes.get() == NULL) {
+ return -1;
}
- else return -1; // Error outside BN. mc FIXME: what to do in this case? Does JNI throw exception itself?
+ jboolean success = (BN_bin2bn(reinterpret_cast<const unsigned char*>(bytes.get()), len, ret) != NULL);
+ if (success && neg) {
+ BN_set_negative(ret, 1);
+ }
+ return success;
}
/**
* public static native boolean litEndInts2bn(int[], int, int, int)
- * Note:
+ * Note:
* This procedure directly writes the internal representation of BIGNUMs.
* We do so as there is no direct interface based on Little Endian Integer Arrays.
* Also note that the same representation is used in the Cordoba Java Implementation of BigIntegers,
* whereof certain functionality is still being used.
*/
static jboolean NativeBN_litEndInts2bn(JNIEnv* env, jclass, jintArray arr, int len, jboolean neg, BIGNUM* ret) {
- if (!oneValidHandle(env, ret)) return FALSE;
+ if (!oneValidHandle(env, ret)) return JNI_FALSE;
bn_check_top(ret);
- if (len > 0) {
- BN_ULONG* tmpInts; // BN_ULONG is 4 Bytes on this system for sure, i.e. same as jint!
- tmpInts = (BN_ULONG*)env->GetPrimitiveArrayCritical(arr, 0);
+ if (len > 0) {
+ ScopedIntArray scopedArray(env, arr);
+ assert(sizeof(BN_ULONG) == sizeof(jint));
+ const BN_ULONG* tmpInts = reinterpret_cast<const BN_ULONG*>(scopedArray.get());
if ((tmpInts != NULL) && (bn_wexpand(ret, len) != NULL)) {
int i = len; do { i--; ret->d[i] = tmpInts[i]; } while (i > 0);
- env->ReleasePrimitiveArrayCritical(arr, tmpInts, JNI_ABORT);
ret->top = len;
ret->neg = neg;
// need to call this due to clear byte at top if avoiding
// having the top bit set (-ve number)
// Basically get rid of top zero ints:
bn_correct_top(ret);
- return TRUE;
+ return JNI_TRUE;
+ } else {
+ return JNI_FALSE;
}
- else {
- if (tmpInts != NULL)
- env->ReleasePrimitiveArrayCritical(arr, tmpInts, JNI_ABORT);
- return FALSE;
- }
- }
- else { // (len = 0) means value = 0 and sign will be 0, too.
- ret->top = 0;
- return TRUE;
- }
+ } else { // (len = 0) means value = 0 and sign will be 0, too.
+ ret->top = 0;
+ return JNI_TRUE;
+ }
}
@@ -239,13 +229,13 @@ static jboolean NativeBN_litEndInts2bn(JNIEnv* env, jclass, jintArray arr, int l
| (bytes[k + 1] & 0xFF) << 16 \
| (bytes[k + 0] & 0xFF) << 24 )
-static jboolean negBigEndianBytes2bn(JNIEnv*, jclass, unsigned char* bytes, int bytesLen, BIGNUM* ret) {
+static jboolean negBigEndianBytes2bn(JNIEnv*, jclass, const unsigned char* bytes, int bytesLen, BIGNUM* ret) {
// We rely on: (BN_BITS2 == 32), i.e. BN_ULONG is unsigned int and has 4 bytes:
//
bn_check_top(ret);
// FIXME: ASSERT (bytesLen > 0);
- int intLen = (bytesLen + 3) / 4;
- int firstNonzeroDigit = -2;
+ int intLen = (bytesLen + 3) / 4;
+ int firstNonzeroDigit = -2;
if (bn_wexpand(ret, intLen) != NULL) {
BN_ULONG* d = ret->d;
BN_ULONG di;
@@ -287,38 +277,36 @@ static jboolean negBigEndianBytes2bn(JNIEnv*, jclass, unsigned char* bytes, int
d[i] = -di;
}
}
- return TRUE;
+ return JNI_TRUE;
}
- else return FALSE;
+ else return JNI_FALSE;
}
/**
* public static native boolean twosComp2bn(byte[], int, int)
*/
static jboolean NativeBN_twosComp2bn(JNIEnv* env, jclass cls, jbyteArray arr, int bytesLen, BIGNUM* ret) {
- if (!oneValidHandle(env, ret)) return FALSE;
+ if (!oneValidHandle(env, ret)) return JNI_FALSE;
+ ScopedByteArray bytes(env, arr);
+ if (bytes.get() == NULL) {
+ return -1;
+ }
jboolean success;
- unsigned char* tmpBytes;
- tmpBytes = (unsigned char*)env->GetPrimitiveArrayCritical(arr, 0);
- if (tmpBytes != NULL) {
- if ((tmpBytes[0] & 0X80) == 0) { // Positive value!
- //
- // We can use the existing BN implementation for unsigned big endian bytes:
- //
- success = (BN_bin2bn(tmpBytes, bytesLen, ret) != NULL);
- BN_set_negative(ret, FALSE);
- }
- else { // Negative value!
- //
- // We need to apply two's complement:
- //
- success = negBigEndianBytes2bn(env, cls, tmpBytes, bytesLen, ret);
- BN_set_negative(ret, TRUE);
- }
- env->ReleasePrimitiveArrayCritical(arr, tmpBytes, JNI_ABORT);
- return success;
+ const unsigned char* s = reinterpret_cast<const unsigned char*>(bytes.get());
+ if ((bytes[0] & 0X80) == 0) { // Positive value!
+ //
+ // We can use the existing BN implementation for unsigned big endian bytes:
+ //
+ success = (BN_bin2bn(s, bytesLen, ret) != NULL);
+ BN_set_negative(ret, JNI_FALSE);
+ } else { // Negative value!
+ //
+ // We need to apply two's complement:
+ //
+ success = negBigEndianBytes2bn(env, cls, s, bytesLen, ret);
+ BN_set_negative(ret, JNI_TRUE);
}
- else return -1; // Error outside BN. mc FIXME: what to do in this case? Does JNI throw exception itself?
+ return success;
}
@@ -462,7 +450,7 @@ static void NativeBN_BN_set_negative(JNIEnv* env, jclass, BIGNUM* b, int n) {
static int NativeBN_bitLength(JNIEnv* env, jclass, BIGNUM* a) {
// We rely on: (BN_BITS2 == 32), i.e. BN_ULONG is unsigned int and has 4 bytes:
//
- if (!oneValidHandle(env, a)) return FALSE;
+ if (!oneValidHandle(env, a)) return JNI_FALSE;
bn_check_top(a);
int intLen = a->top;
if (intLen == 0) return 0;
@@ -483,7 +471,7 @@ static int NativeBN_bitLength(JNIEnv* env, jclass, BIGNUM* a) {
* public static native boolean BN_is_bit_set(int, int)
*/
static jboolean NativeBN_BN_is_bit_set(JNIEnv* env, jclass, BIGNUM* a, int n) {
- if (!oneValidHandle(env, a)) return FALSE;
+ if (!oneValidHandle(env, a)) return JNI_FALSE;
return (jboolean)BN_is_bit_set(a, n);
}
@@ -492,7 +480,7 @@ static jboolean NativeBN_BN_is_bit_set(JNIEnv* env, jclass, BIGNUM* a, int n) {
*/
static jboolean NativeBN_modifyBit(JNIEnv* env, jclass, BIGNUM* a, int n, int op) {
// LOGD("NativeBN_BN_modifyBit");
- if (!oneValidHandle(env, a)) return FALSE;
+ if (!oneValidHandle(env, a)) return JNI_FALSE;
switch (op) {
case 1: return BN_set_bit(a, n);
case 0: return BN_clear_bit(a, n);
@@ -500,14 +488,14 @@ static jboolean NativeBN_modifyBit(JNIEnv* env, jclass, BIGNUM* a, int n, int op
if (BN_is_bit_set(a, n)) return BN_clear_bit(a, n);
else return BN_set_bit(a, n);
}
- return FALSE;
+ return JNI_FALSE;
}
/**
* public static native int BN_shift(int, int, int)
*/
static jboolean NativeBN_BN_shift(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, int n) {
- if (!twoValidHandles(env, r, a)) return FALSE;
+ if (!twoValidHandles(env, r, a)) return JNI_FALSE;
return (n >= 0) ? BN_lshift(r, a, n) : BN_rshift(r, a, -n);
}
@@ -515,7 +503,7 @@ static jboolean NativeBN_BN_shift(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, int
* public static native boolean BN_add_word(int, int)
*/
static jboolean NativeBN_BN_add_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w) {
- if (!oneValidHandle(env, a)) return FALSE;
+ if (!oneValidHandle(env, a)) return JNI_FALSE;
return BN_add_word(a, w);
}
@@ -523,7 +511,7 @@ static jboolean NativeBN_BN_add_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w)
* public static native boolean BN_sub_word(int, int)
*/
static jboolean NativeBN_BN_sub_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w) {
- if (!oneValidHandle(env, a)) return FALSE;
+ if (!oneValidHandle(env, a)) return JNI_FALSE;
return BN_sub_word(a, w);
}
@@ -531,7 +519,7 @@ static jboolean NativeBN_BN_sub_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w)
* public static native boolean BN_mul_word(int, int)
*/
static jboolean NativeBN_BN_mul_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w) {
- if (!oneValidHandle(env, a)) return FALSE;
+ if (!oneValidHandle(env, a)) return JNI_FALSE;
return BN_mul_word(a, w);
}
@@ -539,7 +527,7 @@ static jboolean NativeBN_BN_mul_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w)
* public static native boolean BN_div_word(int, int)
*/
static BN_ULONG NativeBN_BN_div_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w) {
- if (!oneValidHandle(env, a)) return FALSE;
+ if (!oneValidHandle(env, a)) return JNI_FALSE;
return BN_div_word(a, w);
}
@@ -547,7 +535,7 @@ static BN_ULONG NativeBN_BN_div_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w)
* public static native boolean BN_mod_word(int, int)
*/
static BN_ULONG NativeBN_BN_mod_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w) {
- if (!oneValidHandle(env, a)) return FALSE;
+ if (!oneValidHandle(env, a)) return JNI_FALSE;
return BN_mod_word(a, w);
}
@@ -557,7 +545,7 @@ static BN_ULONG NativeBN_BN_mod_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w)
* public static native int BN_add(int, int, int)
*/
static jboolean NativeBN_BN_add(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* b) {
- if (!threeValidHandles(env, r, a, b)) return FALSE;
+ if (!threeValidHandles(env, r, a, b)) return JNI_FALSE;
return BN_add(r, a, b);
}
@@ -565,7 +553,7 @@ static jboolean NativeBN_BN_add(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNU
* public static native int BN_sub(int, int, int)
*/
static jboolean NativeBN_BN_sub(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* b) {
- if (!threeValidHandles(env, r, a, b)) return FALSE;
+ if (!threeValidHandles(env, r, a, b)) return JNI_FALSE;
return BN_sub(r, a, b);
}
@@ -574,7 +562,7 @@ static jboolean NativeBN_BN_sub(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNU
* public static native int BN_gcd(int, int, int, int)
*/
static jboolean NativeBN_BN_gcd(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* b, BN_CTX* ctx) {
- if (!threeValidHandles(env, r, a, b)) return FALSE;
+ if (!threeValidHandles(env, r, a, b)) return JNI_FALSE;
return BN_gcd(r, a, b, ctx);
}
@@ -582,7 +570,7 @@ static jboolean NativeBN_BN_gcd(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNU
* public static native int BN_mul(int, int, int, int)
*/
static jboolean NativeBN_BN_mul(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* b, BN_CTX* ctx) {
- if (!threeValidHandles(env, r, a, b)) return FALSE;
+ if (!threeValidHandles(env, r, a, b)) return JNI_FALSE;
return BN_mul(r, a, b, ctx);
}
@@ -590,7 +578,7 @@ static jboolean NativeBN_BN_mul(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNU
* public static native int BN_exp(int, int, int, int)
*/
static jboolean NativeBN_BN_exp(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* p, BN_CTX* ctx) {
- if (!threeValidHandles(env, r, a, p)) return FALSE;
+ if (!threeValidHandles(env, r, a, p)) return JNI_FALSE;
return BN_exp(r, a, p, ctx);
}
@@ -598,7 +586,7 @@ static jboolean NativeBN_BN_exp(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNU
* public static native boolean BN_div(int, int, int, int, int)
*/
static jboolean NativeBN_BN_div(JNIEnv* env, jclass, BIGNUM* dv, BIGNUM* rem, BIGNUM* m, BIGNUM* d, BN_CTX* ctx) {
- if (!fourValidHandles(env, (rem ? rem : dv), (dv ? dv : rem), m, d)) return FALSE;
+ if (!fourValidHandles(env, (rem ? rem : dv), (dv ? dv : rem), m, d)) return JNI_FALSE;
return BN_div(dv, rem, m, d, ctx);
}
@@ -606,7 +594,7 @@ static jboolean NativeBN_BN_div(JNIEnv* env, jclass, BIGNUM* dv, BIGNUM* rem, BI
* public static native int BN_nnmod(int, int, int, int)
*/
static jboolean NativeBN_BN_nnmod(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* m, BN_CTX* ctx) {
- if (!threeValidHandles(env, r, a, m)) return FALSE;
+ if (!threeValidHandles(env, r, a, m)) return JNI_FALSE;
return BN_nnmod(r, a, m, ctx);
}
@@ -614,7 +602,7 @@ static jboolean NativeBN_BN_nnmod(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIG
* public static native int BN_mod_exp(int, int, int, int, int)
*/
static jboolean NativeBN_BN_mod_exp(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* p, BIGNUM* m, BN_CTX* ctx) {
- if (!fourValidHandles(env, r, a, p, m)) return FALSE;
+ if (!fourValidHandles(env, r, a, p, m)) return JNI_FALSE;
return BN_mod_exp(r, a, p, m, ctx);
}
@@ -623,7 +611,7 @@ static jboolean NativeBN_BN_mod_exp(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, B
* public static native int BN_mod_inverse(int, int, int, int)
*/
static jboolean NativeBN_BN_mod_inverse(JNIEnv* env, jclass, BIGNUM* ret, BIGNUM* a, BIGNUM* n, BN_CTX* ctx) {
- if (!threeValidHandles(env, ret, a, n)) return FALSE;
+ if (!threeValidHandles(env, ret, a, n)) return JNI_FALSE;
return (BN_mod_inverse(ret, a, n, ctx) != NULL);
}
@@ -633,7 +621,7 @@ static jboolean NativeBN_BN_mod_inverse(JNIEnv* env, jclass, BIGNUM* ret, BIGNUM
*/
static jboolean NativeBN_BN_generate_prime_ex(JNIEnv* env, jclass, BIGNUM* ret, int bits, jboolean safe,
BIGNUM* add, BIGNUM* rem, jint cb) {
- if (!oneValidHandle(env, ret)) return FALSE;
+ if (!oneValidHandle(env, ret)) return JNI_FALSE;
return BN_generate_prime_ex(ret, bits, safe, add, rem, (BN_GENCB*) cb);
}
@@ -641,7 +629,7 @@ static jboolean NativeBN_BN_generate_prime_ex(JNIEnv* env, jclass, BIGNUM* ret,
* public static native int BN_mod_inverse(int, int, int, int)
*/
static jboolean NativeBN_BN_is_prime_ex(JNIEnv* env, jclass, BIGNUM* p, int nchecks, BN_CTX* ctx, jint cb) {
- if (!oneValidHandle(env, p)) return FALSE;
+ if (!oneValidHandle(env, p)) return JNI_FALSE;
return BN_is_prime_ex(p, nchecks, ctx, (BN_GENCB*) cb);
}