This is an automated email from the ASF dual-hosted git repository.

marong pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new 7a12970d68 [VL] Fix VLA error when compiling with apple clang (#9730)
7a12970d68 is described below

commit 7a12970d680805470226c49624dd0813d3b1a9d6
Author: Rong Ma <[email protected]>
AuthorDate: Fri May 23 17:07:09 2025 +0800

    [VL] Fix VLA error when compiling with apple clang (#9730)
---
 cpp/core/jni/JniCommon.h                           | 40 ++++++++++++++++------
 .../serializer/VeloxRowToColumnarConverter.cc      |  4 +--
 2 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/cpp/core/jni/JniCommon.h b/cpp/core/jni/JniCommon.h
index 7315327b61..67b3d2a911 100644
--- a/cpp/core/jni/JniCommon.h
+++ b/cpp/core/jni/JniCommon.h
@@ -33,27 +33,47 @@
 static jint jniVersion = JNI_VERSION_1_8;
 
 static inline std::string jStringToCString(JNIEnv* env, jstring string) {
-  int32_t jlen, clen;
-  clen = env->GetStringUTFLength(string);
-  jlen = env->GetStringLength(string);
-  char buffer[clen + 1];
-  env->GetStringUTFRegion(string, 0, jlen, buffer);
-  return std::string(buffer, clen);
+  if (!string) {
+    return {};
+  }
+
+  const char* chars = env->GetStringUTFChars(string, nullptr);
+  if (chars == nullptr) {
+    // OOM During GetStringUTFChars.
+    throw gluten::GlutenException("Error occurred during GetStringUTFChars. 
Probably OOM.");
+  }
+
+  std::string result(chars);
+  env->ReleaseStringUTFChars(string, chars);
+  return result;
 }
 
 static inline void checkException(JNIEnv* env) {
   if (env->ExceptionCheck()) {
     jthrowable t = env->ExceptionOccurred();
     env->ExceptionClear();
+
     jclass describerClass = 
env->FindClass("org/apache/gluten/exception/JniExceptionDescriber");
     jmethodID describeMethod =
         env->GetStaticMethodID(describerClass, "describe", 
"(Ljava/lang/Throwable;)Ljava/lang/String;");
-    std::string description =
-        jStringToCString(env, 
(jstring)env->CallStaticObjectMethod(describerClass, describeMethod, t));
+
+    std::stringstream message;
+    message << "Error during calling Java code from native code: ";
+
+    const auto description = 
static_cast<jstring>(env->CallStaticObjectMethod(describerClass, 
describeMethod, t));
+
     if (env->ExceptionCheck()) {
-      LOG(WARNING) << "Fatal: Uncaught Java exception during calling the Java 
exception describer method! ";
+      message << "Uncaught Java exception during calling the Java exception 
describer method!";
+      env->ExceptionClear();
+    } else {
+      try {
+        message << jStringToCString(env, description);
+      } catch (const std::exception& e) {
+        message << e.what();
+      }
     }
-    throw gluten::GlutenException("Error during calling Java code from native 
code: " + description);
+
+    throw gluten::GlutenException(message.str());
   }
 }
 
diff --git a/cpp/velox/operators/serializer/VeloxRowToColumnarConverter.cc 
b/cpp/velox/operators/serializer/VeloxRowToColumnarConverter.cc
index 7529b9d1fd..fa89a664d7 100644
--- a/cpp/velox/operators/serializer/VeloxRowToColumnarConverter.cc
+++ b/cpp/velox/operators/serializer/VeloxRowToColumnarConverter.cc
@@ -106,8 +106,8 @@ VectorPtr createFlatVector<TypeKind::HUGEINT>(
       int64_t offsetAndSize = *reinterpret_cast<int64_t*>(memoryAddress + 
offsets[pos] + fieldOffset);
       int32_t length = static_cast<int32_t>(offsetAndSize);
       int32_t wordoffset = static_cast<int32_t>(offsetAndSize >> 32);
-      uint8_t bytesValue[length];
-      memcpy(bytesValue, memoryAddress + offsets[pos] + wordoffset, length);
+      std::vector<uint8_t> bytesValue(length);
+      memcpy(bytesValue.data(), memoryAddress + offsets[pos] + wordoffset, 
length);
       uint8_t bytesValue2[16]{};
       GLUTEN_CHECK(length <= 16, "array out of bounds exception");
       for (int k = length - 1; k >= 0; k--) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to