Fix code style problems identified by lint

main
Adam Retter 11 years ago
parent 25641bfc9c
commit 5e25274110
  1. 17
      java/rocksjni/comparator.cc
  2. 53
      java/rocksjni/comparatorjnicallback.cc
  3. 16
      java/rocksjni/comparatorjnicallback.h
  4. 9
      java/rocksjni/options.cc
  5. 24
      java/rocksjni/portal.h
  6. 26
      java/rocksjni/slice.cc

@ -37,7 +37,6 @@ void Java_org_rocksdb_ComparatorOptions_newComparatorOptions(
rocksdb::BackupableDBOptionsJni::setHandle(env, jobj, bopt); rocksdb::BackupableDBOptionsJni::setHandle(env, jobj, bopt);
} }
// </editor-fold> // </editor-fold>
// <editor-fold desc="org.rocksdb.AbstractComparator> // <editor-fold desc="org.rocksdb.AbstractComparator>
@ -51,7 +50,6 @@ void Java_org_rocksdb_AbstractComparator_disposeInternal(
JNIEnv* env, jobject jobj, jlong handle) { JNIEnv* env, jobject jobj, jlong handle) {
delete reinterpret_cast<rocksdb::BaseComparatorJniCallback*>(handle); delete reinterpret_cast<rocksdb::BaseComparatorJniCallback*>(handle);
} }
// </editor-fold> // </editor-fold>
// <editor-fold desc="org.rocksdb.Comparator> // <editor-fold desc="org.rocksdb.Comparator>
@ -63,11 +61,12 @@ void Java_org_rocksdb_AbstractComparator_disposeInternal(
*/ */
void Java_org_rocksdb_Comparator_createNewComparator0( void Java_org_rocksdb_Comparator_createNewComparator0(
JNIEnv* env, jobject jobj, jlong copt_handle) { JNIEnv* env, jobject jobj, jlong copt_handle) {
const rocksdb::ComparatorJniCallbackOptions* copt = reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(copt_handle); const rocksdb::ComparatorJniCallbackOptions* copt =
const rocksdb::ComparatorJniCallback* c = new rocksdb::ComparatorJniCallback(env, jobj, copt); reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(copt_handle);
const rocksdb::ComparatorJniCallback* c =
new rocksdb::ComparatorJniCallback(env, jobj, copt);
rocksdb::AbstractComparatorJni::setHandle(env, jobj, c); rocksdb::AbstractComparatorJni::setHandle(env, jobj, c);
} }
// </editor-fold> // </editor-fold>
// <editor-fold desc="org.rocksdb.DirectComparator> // <editor-fold desc="org.rocksdb.DirectComparator>
@ -79,10 +78,10 @@ void Java_org_rocksdb_Comparator_createNewComparator0(
*/ */
void Java_org_rocksdb_DirectComparator_createNewDirectComparator0( void Java_org_rocksdb_DirectComparator_createNewDirectComparator0(
JNIEnv* env, jobject jobj, jlong copt_handle) { JNIEnv* env, jobject jobj, jlong copt_handle) {
const rocksdb::ComparatorJniCallbackOptions* copt = reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(copt_handle); const rocksdb::ComparatorJniCallbackOptions* copt =
const rocksdb::DirectComparatorJniCallback* c = new rocksdb::DirectComparatorJniCallback(env, jobj, copt); reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(copt_handle);
const rocksdb::DirectComparatorJniCallback* c =
new rocksdb::DirectComparatorJniCallback(env, jobj, copt);
rocksdb::AbstractComparatorJni::setHandle(env, jobj, c); rocksdb::AbstractComparatorJni::setHandle(env, jobj, c);
} }
// </editor-fold> // </editor-fold>

@ -7,11 +7,12 @@
// rocksdb::Comparator. // rocksdb::Comparator.
#include "rocksjni/comparatorjnicallback.h" #include "rocksjni/comparatorjnicallback.h"
#include "portal.h" #include "rocksjni/portal.h"
namespace rocksdb { namespace rocksdb {
BaseComparatorJniCallback::BaseComparatorJniCallback( BaseComparatorJniCallback::BaseComparatorJniCallback(
JNIEnv* env, jobject jComparator, const ComparatorJniCallbackOptions* copt) { JNIEnv* env, jobject jComparator,
const ComparatorJniCallbackOptions* copt) {
// mutex is used for synchronisation when we are re-using // mutex is used for synchronisation when we are re-using
// the global java slice objects // the global java slice objects
@ -33,8 +34,10 @@ BaseComparatorJniCallback::BaseComparatorJniCallback(
m_name = JniUtil::copyString(env, jsName); // also releases jsName m_name = JniUtil::copyString(env, jsName); // also releases jsName
m_jCompareMethodId = AbstractComparatorJni::getCompareMethodId(env); m_jCompareMethodId = AbstractComparatorJni::getCompareMethodId(env);
m_jFindShortestSeparatorMethodId = AbstractComparatorJni::getFindShortestSeparatorMethodId(env); m_jFindShortestSeparatorMethodId =
m_jFindShortSuccessorMethodId = AbstractComparatorJni::getFindShortSuccessorMethodId(env); AbstractComparatorJni::getFindShortestSeparatorMethodId(env);
m_jFindShortSuccessorMethodId =
AbstractComparatorJni::getFindShortSuccessorMethodId(env);
} }
/** /**
@ -42,24 +45,25 @@ BaseComparatorJniCallback::BaseComparatorJniCallback(
*/ */
JNIEnv* BaseComparatorJniCallback::getJniEnv() const { JNIEnv* BaseComparatorJniCallback::getJniEnv() const {
JNIEnv *env; JNIEnv *env;
jint rs = m_jvm->AttachCurrentThread((void **)&env, NULL); jint rs = m_jvm->AttachCurrentThread(reinterpret_cast<void **>(&env), NULL);
assert(rs == JNI_OK); assert(rs == JNI_OK);
return env; return env;
}; }
const char* BaseComparatorJniCallback::Name() const { const char* BaseComparatorJniCallback::Name() const {
return m_name.c_str(); return m_name.c_str();
} }
int BaseComparatorJniCallback::Compare(const Slice& a, const Slice& b) const { int BaseComparatorJniCallback::Compare(const Slice& a, const Slice& b) const {
JNIEnv* m_env = getJniEnv(); JNIEnv* m_env = getJniEnv();
mutex_->Lock(); mutex_->Lock();
AbstractSliceJni::setHandle(m_env, m_jSliceA, &a); AbstractSliceJni::setHandle(m_env, m_jSliceA, &a);
AbstractSliceJni::setHandle(m_env, m_jSliceB, &b); AbstractSliceJni::setHandle(m_env, m_jSliceB, &b);
jint result = m_env->CallIntMethod(m_jComparator, m_jCompareMethodId, m_jSliceA, m_jSliceB); jint result =
m_env->CallIntMethod(m_jComparator, m_jCompareMethodId, m_jSliceA,
m_jSliceB);
mutex_->Unlock(); mutex_->Unlock();
@ -68,8 +72,8 @@ int BaseComparatorJniCallback::Compare(const Slice& a, const Slice& b) const {
return result; return result;
} }
void BaseComparatorJniCallback::FindShortestSeparator(std::string* start, const Slice& limit) const { void BaseComparatorJniCallback::FindShortestSeparator(
std::string* start, const Slice& limit) const {
if (start == nullptr) { if (start == nullptr) {
return; return;
} }
@ -82,7 +86,9 @@ void BaseComparatorJniCallback::FindShortestSeparator(std::string* start, const
mutex_->Lock(); mutex_->Lock();
AbstractSliceJni::setHandle(m_env, m_jSliceLimit, &limit); AbstractSliceJni::setHandle(m_env, m_jSliceLimit, &limit);
jstring jsResultStart = (jstring)m_env->CallObjectMethod(m_jComparator, m_jFindShortestSeparatorMethodId, jsStart, m_jSliceLimit); jstring jsResultStart =
(jstring)m_env->CallObjectMethod(m_jComparator,
m_jFindShortestSeparatorMethodId, jsStart, m_jSliceLimit);
mutex_->Unlock(); mutex_->Unlock();
@ -90,14 +96,14 @@ void BaseComparatorJniCallback::FindShortestSeparator(std::string* start, const
if (jsResultStart != nullptr) { if (jsResultStart != nullptr) {
// update start with result // update start with result
*start = JniUtil::copyString(m_env, jsResultStart); //also releases jsResultStart *start =
JniUtil::copyString(m_env, jsResultStart); // also releases jsResultStart
} }
m_jvm->DetachCurrentThread(); m_jvm->DetachCurrentThread();
} }
void BaseComparatorJniCallback::FindShortSuccessor(std::string* key) const { void BaseComparatorJniCallback::FindShortSuccessor(std::string* key) const {
if (key == nullptr) { if (key == nullptr) {
return; return;
} }
@ -107,13 +113,16 @@ void BaseComparatorJniCallback::FindShortSuccessor(std::string* key) const {
const char* keyUtf = key->c_str(); const char* keyUtf = key->c_str();
jstring jsKey = m_env->NewStringUTF(keyUtf); jstring jsKey = m_env->NewStringUTF(keyUtf);
jstring jsResultKey = (jstring)m_env->CallObjectMethod(m_jComparator, m_jFindShortSuccessorMethodId, jsKey); jstring jsResultKey =
(jstring)m_env->CallObjectMethod(m_jComparator,
m_jFindShortSuccessorMethodId, jsKey);
m_env->DeleteLocalRef(jsKey); m_env->DeleteLocalRef(jsKey);
if (jsResultKey != nullptr) { if (jsResultKey != nullptr) {
// update key with result // update key with result
*key = JniUtil::copyString(m_env, jsResultKey); //also releases jsResultKey *key =
JniUtil::copyString(m_env, jsResultKey); // also releases jsResultKey
} }
m_jvm->DetachCurrentThread(); m_jvm->DetachCurrentThread();
@ -129,21 +138,23 @@ BaseComparatorJniCallback::~BaseComparatorJniCallback() {
// Note: do not need to explicitly detach, as this function is effectively // Note: do not need to explicitly detach, as this function is effectively
// called from the Java class's disposeInternal method, and so already // called from the Java class's disposeInternal method, and so already
// has an attached thread, getJniEnv above is just a no-op Attach to get the env // has an attached thread, getJniEnv above is just a no-op Attach to get
//jvm->DetachCurrentThread(); // the env jvm->DetachCurrentThread();
} }
ComparatorJniCallback::ComparatorJniCallback( ComparatorJniCallback::ComparatorJniCallback(
JNIEnv* env, jobject jComparator, const ComparatorJniCallbackOptions* copt) : BaseComparatorJniCallback(env, jComparator, copt) { JNIEnv* env, jobject jComparator,
const ComparatorJniCallbackOptions* copt) :
BaseComparatorJniCallback(env, jComparator, copt) {
m_jSliceA = env->NewGlobalRef(SliceJni::construct0(env)); m_jSliceA = env->NewGlobalRef(SliceJni::construct0(env));
m_jSliceB = env->NewGlobalRef(SliceJni::construct0(env)); m_jSliceB = env->NewGlobalRef(SliceJni::construct0(env));
m_jSliceLimit = env->NewGlobalRef(SliceJni::construct0(env)); m_jSliceLimit = env->NewGlobalRef(SliceJni::construct0(env));
} }
DirectComparatorJniCallback::DirectComparatorJniCallback( DirectComparatorJniCallback::DirectComparatorJniCallback(
JNIEnv* env, jobject jComparator, const ComparatorJniCallbackOptions* copt) : BaseComparatorJniCallback(env, jComparator, copt) { JNIEnv* env, jobject jComparator,
const ComparatorJniCallbackOptions* copt) :
BaseComparatorJniCallback(env, jComparator, copt) {
m_jSliceA = env->NewGlobalRef(DirectSliceJni::construct0(env)); m_jSliceA = env->NewGlobalRef(DirectSliceJni::construct0(env));
m_jSliceB = env->NewGlobalRef(DirectSliceJni::construct0(env)); m_jSliceB = env->NewGlobalRef(DirectSliceJni::construct0(env));
m_jSliceLimit = env->NewGlobalRef(DirectSliceJni::construct0(env)); m_jSliceLimit = env->NewGlobalRef(DirectSliceJni::construct0(env));

@ -10,6 +10,7 @@
#define JAVA_ROCKSJNI_COMPARATORJNICALLBACK_H_ #define JAVA_ROCKSJNI_COMPARATORJNICALLBACK_H_
#include <jni.h> #include <jni.h>
#include <string>
#include "rocksdb/comparator.h" #include "rocksdb/comparator.h"
#include "rocksdb/slice.h" #include "rocksdb/slice.h"
#include "port/port.h" #include "port/port.h"
@ -44,11 +45,14 @@ struct ComparatorJniCallbackOptions {
*/ */
class BaseComparatorJniCallback : public Comparator { class BaseComparatorJniCallback : public Comparator {
public: public:
BaseComparatorJniCallback(JNIEnv* env, jobject jComparator, const ComparatorJniCallbackOptions* copt); BaseComparatorJniCallback(
JNIEnv* env, jobject jComparator,
const ComparatorJniCallbackOptions* copt);
virtual ~BaseComparatorJniCallback(); virtual ~BaseComparatorJniCallback();
virtual const char* Name() const; virtual const char* Name() const;
virtual int Compare(const Slice& a, const Slice& b) const; virtual int Compare(const Slice& a, const Slice& b) const;
virtual void FindShortestSeparator(std::string* start, const Slice& limit) const; virtual void FindShortestSeparator(
std::string* start, const Slice& limit) const;
virtual void FindShortSuccessor(std::string* key) const; virtual void FindShortSuccessor(std::string* key) const;
private: private:
@ -69,12 +73,16 @@ class BaseComparatorJniCallback : public Comparator {
class ComparatorJniCallback : public BaseComparatorJniCallback { class ComparatorJniCallback : public BaseComparatorJniCallback {
public: public:
ComparatorJniCallback(JNIEnv* env, jobject jComparator, const ComparatorJniCallbackOptions* copt); ComparatorJniCallback(
JNIEnv* env, jobject jComparator,
const ComparatorJniCallbackOptions* copt);
}; };
class DirectComparatorJniCallback : public BaseComparatorJniCallback { class DirectComparatorJniCallback : public BaseComparatorJniCallback {
public: public:
DirectComparatorJniCallback(JNIEnv* env, jobject jComparator, const ComparatorJniCallbackOptions* copt); DirectComparatorJniCallback(
JNIEnv* env, jobject jComparator,
const ComparatorJniCallbackOptions* copt);
}; };
} // namespace rocksdb } // namespace rocksdb

@ -16,6 +16,7 @@
#include "include/org_rocksdb_ReadOptions.h" #include "include/org_rocksdb_ReadOptions.h"
#include "include/org_rocksdb_ComparatorOptions.h" #include "include/org_rocksdb_ComparatorOptions.h"
#include "rocksjni/comparatorjnicallback.h"
#include "rocksjni/portal.h" #include "rocksjni/portal.h"
#include "rocksdb/db.h" #include "rocksdb/db.h"
#include "rocksdb/options.h" #include "rocksdb/options.h"
@ -25,7 +26,6 @@
#include "rocksdb/slice_transform.h" #include "rocksdb/slice_transform.h"
#include "rocksdb/rate_limiter.h" #include "rocksdb/rate_limiter.h"
#include "rocksdb/comparator.h" #include "rocksdb/comparator.h"
#include "comparatorjnicallback.h"
/* /*
* Class: org_rocksdb_Options * Class: org_rocksdb_Options
@ -1794,7 +1794,8 @@ void Java_org_rocksdb_ComparatorOptions_newComparatorOptions(
*/ */
jboolean Java_org_rocksdb_ComparatorOptions_useAdaptiveMutex( jboolean Java_org_rocksdb_ComparatorOptions_useAdaptiveMutex(
JNIEnv * env, jobject jobj, jlong jhandle) { JNIEnv * env, jobject jobj, jlong jhandle) {
return reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(jhandle)->use_adaptive_mutex; return reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(jhandle)
->use_adaptive_mutex;
} }
/* /*
@ -1804,8 +1805,8 @@ jboolean Java_org_rocksdb_ComparatorOptions_useAdaptiveMutex(
*/ */
void Java_org_rocksdb_ComparatorOptions_setUseAdaptiveMutex( void Java_org_rocksdb_ComparatorOptions_setUseAdaptiveMutex(
JNIEnv * env, jobject jobj, jlong jhandle, jboolean juse_adaptive_mutex) { JNIEnv * env, jobject jobj, jlong jhandle, jboolean juse_adaptive_mutex) {
reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(jhandle)->use_adaptive_mutex = reinterpret_cast<rocksdb::ComparatorJniCallbackOptions*>(jhandle)
static_cast<bool>(juse_adaptive_mutex); ->use_adaptive_mutex = static_cast<bool>(juse_adaptive_mutex);
} }
/* /*

@ -12,6 +12,8 @@
#include <jni.h> #include <jni.h>
#include <limits> #include <limits>
#include <string>
#include "rocksdb/db.h" #include "rocksdb/db.h"
#include "rocksdb/filter_policy.h" #include "rocksdb/filter_policy.h"
#include "rocksdb/status.h" #include "rocksdb/status.h"
@ -383,7 +385,8 @@ class ComparatorOptionsJni {
// Pass the ComparatorJniCallbackOptions pointer to the java side. // Pass the ComparatorJniCallbackOptions pointer to the java side.
static void setHandle( static void setHandle(
JNIEnv* env, jobject jobj, const rocksdb::ComparatorJniCallbackOptions* op) { JNIEnv* env, jobject jobj,
const rocksdb::ComparatorJniCallbackOptions* op) {
env->SetLongField( env->SetLongField(
jobj, getHandleFieldID(env), jobj, getHandleFieldID(env),
reinterpret_cast<jlong>(op)); reinterpret_cast<jlong>(op));
@ -418,30 +421,34 @@ class AbstractComparatorJni {
// Get the java method `compare` of org.rocksdb.Comparator. // Get the java method `compare` of org.rocksdb.Comparator.
static jmethodID getCompareMethodId(JNIEnv* env) { static jmethodID getCompareMethodId(JNIEnv* env) {
static jmethodID mid = env->GetMethodID( static jmethodID mid = env->GetMethodID(getJClass(env),
getJClass(env), "compare", "(Lorg/rocksdb/AbstractSlice;Lorg/rocksdb/AbstractSlice;)I"); "compare",
"(Lorg/rocksdb/AbstractSlice;Lorg/rocksdb/AbstractSlice;)I");
assert(mid != nullptr); assert(mid != nullptr);
return mid; return mid;
} }
// Get the java method `findShortestSeparator` of org.rocksdb.Comparator. // Get the java method `findShortestSeparator` of org.rocksdb.Comparator.
static jmethodID getFindShortestSeparatorMethodId(JNIEnv* env) { static jmethodID getFindShortestSeparatorMethodId(JNIEnv* env) {
static jmethodID mid = env->GetMethodID( static jmethodID mid = env->GetMethodID(getJClass(env),
getJClass(env), "findShortestSeparator", "(Ljava/lang/String;Lorg/rocksdb/AbstractSlice;)Ljava/lang/String;"); "findShortestSeparator",
"(Ljava/lang/String;Lorg/rocksdb/AbstractSlice;)Ljava/lang/String;");
assert(mid != nullptr); assert(mid != nullptr);
return mid; return mid;
} }
// Get the java method `findShortSuccessor` of org.rocksdb.Comparator. // Get the java method `findShortSuccessor` of org.rocksdb.Comparator.
static jmethodID getFindShortSuccessorMethodId(JNIEnv* env) { static jmethodID getFindShortSuccessorMethodId(JNIEnv* env) {
static jmethodID mid = env->GetMethodID( static jmethodID mid = env->GetMethodID(getJClass(env),
getJClass(env), "findShortSuccessor", "(Ljava/lang/String;)Ljava/lang/String;"); "findShortSuccessor",
"(Ljava/lang/String;)Ljava/lang/String;");
assert(mid != nullptr); assert(mid != nullptr);
return mid; return mid;
} }
// Get the pointer to ComparatorJniCallback. // Get the pointer to ComparatorJniCallback.
static rocksdb::BaseComparatorJniCallback* getHandle(JNIEnv* env, jobject jobj) { static rocksdb::BaseComparatorJniCallback* getHandle(
JNIEnv* env, jobject jobj) {
return reinterpret_cast<rocksdb::BaseComparatorJniCallback*>( return reinterpret_cast<rocksdb::BaseComparatorJniCallback*>(
env->GetLongField(jobj, getHandleFieldID(env))); env->GetLongField(jobj, getHandleFieldID(env)));
} }
@ -586,7 +593,6 @@ class ListJni {
class JniUtil { class JniUtil {
public: public:
/** /**
* Copies a jstring to a std::string * Copies a jstring to a std::string
* and releases the original jstring * and releases the original jstring

@ -73,7 +73,8 @@ jstring Java_org_rocksdb_AbstractSlice_toString0(
jint Java_org_rocksdb_AbstractSlice_compare0( jint Java_org_rocksdb_AbstractSlice_compare0(
JNIEnv* env, jobject jobj, jlong handle, jlong otherHandle) { JNIEnv* env, jobject jobj, jlong handle, jlong otherHandle) {
const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle); const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
const rocksdb::Slice* otherSlice = reinterpret_cast<rocksdb::Slice*>(otherHandle); const rocksdb::Slice* otherSlice =
reinterpret_cast<rocksdb::Slice*>(otherHandle);
return slice->compare(*otherSlice); return slice->compare(*otherSlice);
} }
@ -85,7 +86,8 @@ jint Java_org_rocksdb_AbstractSlice_compare0(
jboolean Java_org_rocksdb_AbstractSlice_startsWith0( jboolean Java_org_rocksdb_AbstractSlice_startsWith0(
JNIEnv* env, jobject jobj, jlong handle, jlong otherHandle) { JNIEnv* env, jobject jobj, jlong handle, jlong otherHandle) {
const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle); const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
const rocksdb::Slice* otherSlice = reinterpret_cast<rocksdb::Slice*>(otherHandle); const rocksdb::Slice* otherSlice =
reinterpret_cast<rocksdb::Slice*>(otherHandle);
return slice->starts_with(*otherSlice); return slice->starts_with(*otherSlice);
} }
@ -113,13 +115,11 @@ void Java_org_rocksdb_Slice_createNewSlice0(
const jsize dataSize = env->GetArrayLength(data); const jsize dataSize = env->GetArrayLength(data);
const int len = dataSize - offset; const int len = dataSize - offset;
//jbyte ptrData[len];
jbyte* ptrData = new jbyte[len]; jbyte* ptrData = new jbyte[len];
env->GetByteArrayRegion(data, offset, len, ptrData); env->GetByteArrayRegion(data, offset, len, ptrData);
const rocksdb::Slice* slice = new rocksdb::Slice((const char*)ptrData, len); const rocksdb::Slice* slice = new rocksdb::Slice((const char*)ptrData, len);
rocksdb::AbstractSliceJni::setHandle(env, jobj, slice); rocksdb::AbstractSliceJni::setHandle(env, jobj, slice);
} }
/* /*
@ -135,9 +135,10 @@ void Java_org_rocksdb_Slice_createNewSlice1(
jboolean isCopy; jboolean isCopy;
jbyte* ptrData = env->GetByteArrayElements(data, &isCopy); jbyte* ptrData = env->GetByteArrayElements(data, &isCopy);
const char* buf = new char[len]; const char* buf = new char[len];
memcpy((void*)buf, ptrData, len); memcpy(const_cast<char*>(buf), ptrData, len);
const rocksdb::Slice* slice = new rocksdb::Slice(buf, env->GetArrayLength(data)); const rocksdb::Slice* slice =
new rocksdb::Slice(buf, env->GetArrayLength(data));
rocksdb::AbstractSliceJni::setHandle(env, jobj, slice); rocksdb::AbstractSliceJni::setHandle(env, jobj, slice);
env->ReleaseByteArrayElements(data, ptrData, JNI_ABORT); env->ReleaseByteArrayElements(data, ptrData, JNI_ABORT);
@ -155,7 +156,8 @@ jbyteArray Java_org_rocksdb_Slice_data0(
const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle); const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
const int len = slice->size(); const int len = slice->size();
const jbyteArray data = env->NewByteArray(len); const jbyteArray data = env->NewByteArray(len);
env->SetByteArrayRegion(data, 0, len, (jbyte*)slice->data()); env->SetByteArrayRegion(data, 0, len,
reinterpret_cast<jbyte*>(const_cast<char*>(slice->data())));
return data; return data;
} }
@ -181,7 +183,8 @@ void Java_org_rocksdb_Slice_disposeInternalBuf(
*/ */
void Java_org_rocksdb_DirectSlice_createNewDirectSlice0( void Java_org_rocksdb_DirectSlice_createNewDirectSlice0(
JNIEnv* env, jobject jobj, jobject data, jint length) { JNIEnv* env, jobject jobj, jobject data, jint length) {
const char* ptrData = (char*)env->GetDirectBufferAddress(data); const char* ptrData =
reinterpret_cast<char*>(env->GetDirectBufferAddress(data));
const rocksdb::Slice* slice = new rocksdb::Slice(ptrData, length); const rocksdb::Slice* slice = new rocksdb::Slice(ptrData, length);
rocksdb::AbstractSliceJni::setHandle(env, jobj, slice); rocksdb::AbstractSliceJni::setHandle(env, jobj, slice);
} }
@ -193,7 +196,8 @@ void Java_org_rocksdb_DirectSlice_createNewDirectSlice0(
*/ */
void Java_org_rocksdb_DirectSlice_createNewDirectSlice1( void Java_org_rocksdb_DirectSlice_createNewDirectSlice1(
JNIEnv* env, jobject jobj, jobject data) { JNIEnv* env, jobject jobj, jobject data) {
const char* ptrData = (char*)env->GetDirectBufferAddress(data); const char* ptrData =
reinterpret_cast<char*>(env->GetDirectBufferAddress(data));
const rocksdb::Slice* slice = new rocksdb::Slice(ptrData); const rocksdb::Slice* slice = new rocksdb::Slice(ptrData);
rocksdb::AbstractSliceJni::setHandle(env, jobj, slice); rocksdb::AbstractSliceJni::setHandle(env, jobj, slice);
} }
@ -206,7 +210,8 @@ void Java_org_rocksdb_DirectSlice_createNewDirectSlice1(
jobject Java_org_rocksdb_DirectSlice_data0( jobject Java_org_rocksdb_DirectSlice_data0(
JNIEnv* env, jobject jobj, jlong handle) { JNIEnv* env, jobject jobj, jlong handle) {
const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle); const rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
return env->NewDirectByteBuffer((void*)slice->data(), slice->size()); return env->NewDirectByteBuffer(const_cast<char*>(slice->data()),
slice->size());
} }
/* /*
@ -228,6 +233,7 @@ jbyte Java_org_rocksdb_DirectSlice_get0(
void Java_org_rocksdb_DirectSlice_clear0( void Java_org_rocksdb_DirectSlice_clear0(
JNIEnv* env, jobject jobj, jlong handle) { JNIEnv* env, jobject jobj, jlong handle) {
rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle); rocksdb::Slice* slice = reinterpret_cast<rocksdb::Slice*>(handle);
delete [] slice->data_;
slice->clear(); slice->clear();
} }

Loading…
Cancel
Save