fixes 1220: rocksjni build fails on Windows due to variable-size array declaration (#1223)

* fixes 1220: rocksjni build fails on Windows due to variable-size array declaration

using new keyword to create variable-size arrays in order to satisfy most of the compilers

* fixes 1220: rocksjni build fails on Windows due to variable-size array declaration

using unique_ptr keyword to create variable-size arrays in order to satisfy most of the compilers
main
Alexander Jipa 8 years ago committed by Yueh-Hsuan Chiang
parent a9d512a76b
commit 12767b3130
  1. 4
      java/rocksjni/options.cc
  2. 4
      java/rocksjni/rocksjni.cc
  3. 5
      java/rocksjni/ttl.cc

@ -1104,7 +1104,7 @@ std::vector<rocksdb::CompressionType> rocksdb_compression_vector_helper(
*/
jbyteArray rocksdb_compression_list_helper(JNIEnv* env,
std::vector<rocksdb::CompressionType> compressionLevels) {
jbyte jbuf[compressionLevels.size()];
std::unique_ptr<jbyte[]> jbuf = std::make_unique<jbyte[]>(compressionLevels.size());
for (std::vector<rocksdb::CompressionType>::size_type i = 0;
i != compressionLevels.size(); i++) {
jbuf[i] = compressionLevels[i];
@ -1113,7 +1113,7 @@ jbyteArray rocksdb_compression_list_helper(JNIEnv* env,
jbyteArray jcompressionLevels = env->NewByteArray(
static_cast<jsize>(compressionLevels.size()));
env->SetByteArrayRegion(jcompressionLevels, 0,
static_cast<jsize>(compressionLevels.size()), jbuf);
static_cast<jsize>(compressionLevels.size()), jbuf.get());
return jcompressionLevels;
}

@ -115,14 +115,14 @@ jlongArray rocksdb_open_helper(JNIEnv* env, jlong jopt_handle,
// check if open operation was successful
if (s.ok()) {
jsize resultsLen = 1 + len_cols; //db handle + column family handles
jlong results[resultsLen];
std::unique_ptr<jlong[]> results = std::make_unique<jlong[]>(resultsLen);
results[0] = reinterpret_cast<jlong>(db);
for(int i = 1; i <= len_cols; i++) {
results[i] = reinterpret_cast<jlong>(handles[i - 1]);
}
jlongArray jresults = env->NewLongArray(resultsLen);
env->SetLongArrayRegion(jresults, 0, resultsLen, results);
env->SetLongArrayRegion(jresults, 0, resultsLen, results.get());
return jresults;
} else {
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);

@ -12,6 +12,7 @@
#include <stdlib.h>
#include <string>
#include <vector>
#include <memory>
#include "include/org_rocksdb_TtlDB.h"
#include "rocksdb/utilities/db_ttl.h"
@ -95,14 +96,14 @@ jlongArray
// check if open operation was successful
if (s.ok()) {
jsize resultsLen = 1 + len_cols; //db handle + column family handles
jlong results[resultsLen];
std::unique_ptr<jlong[]> results = std::make_unique<jlong[]>(resultsLen);
results[0] = reinterpret_cast<jlong>(db);
for(int i = 1; i <= len_cols; i++) {
results[i] = reinterpret_cast<jlong>(handles[i - 1]);
}
jlongArray jresults = env->NewLongArray(resultsLen);
env->SetLongArrayRegion(jresults, 0, resultsLen, results);
env->SetLongArrayRegion(jresults, 0, resultsLen, results.get());
return jresults;
} else {
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);

Loading…
Cancel
Save