Skip to content

Commit

Permalink
fix window jni unhappy compiler (ray-project#9635)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashione authored Jul 23, 2020
1 parent 993ff5f commit 64b0f17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ inline void MetricTransform(JNIEnv *env, jstring j_name, jstring j_description,
// item when it already exists.
std::transform(tag_key_str_list.begin(), tag_key_str_list.end(),
std::back_inserter(tag_keys),
[](std::string tag_key) { return TagKeyType::Register(tag_key); });
[](std::string &tag_key) { return TagKeyType::Register(tag_key); });
}

#ifdef __cplusplus
Expand All @@ -70,7 +70,7 @@ JNIEXPORT jlong JNICALL Java_io_ray_runtime_metric_NativeMetric_registerGaugeNat
MetricTransform(env, j_name, j_description, j_unit, tag_key_list, &metric_name,
&description, &unit, tag_keys);
auto *gauge = new ray::stats::Gauge(metric_name, description, unit, tag_keys);
return reinterpret_cast<long>(gauge);
return reinterpret_cast<jlong>(gauge);
}

JNIEXPORT jlong JNICALL Java_io_ray_runtime_metric_NativeMetric_registerCountNative(
Expand All @@ -83,7 +83,7 @@ JNIEXPORT jlong JNICALL Java_io_ray_runtime_metric_NativeMetric_registerCountNat
MetricTransform(env, j_name, j_description, j_unit, tag_key_list, &metric_name,
&description, &unit, tag_keys);
auto *count = new ray::stats::Count(metric_name, description, unit, tag_keys);
return reinterpret_cast<long>(count);
return reinterpret_cast<jlong>(count);
}

JNIEXPORT jlong JNICALL Java_io_ray_runtime_metric_NativeMetric_registerSumNative(
Expand All @@ -96,7 +96,7 @@ JNIEXPORT jlong JNICALL Java_io_ray_runtime_metric_NativeMetric_registerSumNativ
MetricTransform(env, j_name, j_description, j_unit, tag_key_list, &metric_name,
&description, &unit, tag_keys);
auto *sum = new ray::stats::Sum(metric_name, description, unit, tag_keys);
return reinterpret_cast<long>(sum);
return reinterpret_cast<jlong>(sum);
}

JNIEXPORT jlong JNICALL Java_io_ray_runtime_metric_NativeMetric_registerHistogramNative(
Expand All @@ -114,7 +114,7 @@ JNIEXPORT jlong JNICALL Java_io_ray_runtime_metric_NativeMetric_registerHistogra

auto *histogram =
new ray::stats::Histogram(metric_name, description, unit, boundaries, tag_keys);
return reinterpret_cast<long>(histogram);
return reinterpret_cast<jlong>(histogram);
}

JNIEXPORT void JNICALL Java_io_ray_runtime_metric_NativeMetric_unregisterMetricNative(
Expand Down
10 changes: 6 additions & 4 deletions src/ray/core_worker/lib/java/jni_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@ inline void JavaLongArrayToNativeLongVector(JNIEnv *env, jlongArray long_array,
std::vector<long> *native_vector) {
jlong *long_array_ptr = env->GetLongArrayElements(long_array, nullptr);
jsize vec_size = env->GetArrayLength(long_array);
native_vector->insert(native_vector->begin(), long_array_ptr,
long_array_ptr + vec_size);
for (int i = 0; i < vec_size; ++i) {
native_vector->push_back(static_cast<long>(long_array_ptr[i]));
}
env->ReleaseLongArrayElements(long_array, long_array_ptr, 0);
}

Expand All @@ -299,8 +300,9 @@ inline void JavaDoubleArrayToNativeDoubleVector(JNIEnv *env, jdoubleArray double
std::vector<double> *native_vector) {
jdouble *double_array_ptr = env->GetDoubleArrayElements(double_array, nullptr);
jsize vec_size = env->GetArrayLength(double_array);
native_vector->insert(native_vector->begin(), double_array_ptr,
double_array_ptr + vec_size);
for (int i = 0; i < vec_size; ++i) {
native_vector->push_back(static_cast<double>(double_array_ptr[i]));
}
env->ReleaseDoubleArrayElements(double_array, double_array_ptr, 0);
}

Expand Down

0 comments on commit 64b0f17

Please sign in to comment.