Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly cast jlong* to int64_t* for clarity and type safety #1103

Closed
wants to merge 1 commit into from

Conversation

ilopezluna
Copy link

Fixes:

src/java/src/main/native/ai_onnxruntime_genai_Tensor.cpp:21:18: error: cannot initialize a variable of type 'const int64_t *' (aka 'const long long *') with an rvalue of type 'jlong *' (aka 'long *')
  const int64_t* shape_dims = env->GetLongArrayElements(shape_dims_in, /*isCopy*/ 0);
                 ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [src/java/CMakeFiles/onnxruntime-genai-jni.dir/src/main/native/ai_onnxruntime_genai_Tensor.cpp.o] Error 1
make[1]: *** [src/java/CMakeFiles/onnxruntime-genai-jni.dir/all] Error 2
make: *** [all] Error 2
Traceback (most recent call last):
  File "/onnxruntime-genai/build.py", line 653, in <module>
    build(arguments, environment)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/onnxruntime-genai/build.py", line 585, in build
    util.run(make_command, env=env)
    ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/onnxruntime-genai/tools/python/util/run.py", line 56, in run
    completed_process = subprocess.run(
        cmd,
    ...<6 lines>...
        shell=shell,
    )
  File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/subprocess.py", line 577, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/opt/homebrew/bin/cmake', '--build', '/onnxruntime-genai/build/macOS/Release', '--config', 'Release']' returned non-zero exit status 2.

when executing: python build.py --build_java --config Release

@@ -18,7 +18,7 @@ JNIEXPORT jlong JNICALL
Java_ai_onnxruntime_genai_Tensor_createTensor(JNIEnv* env, jobject thiz, jobject tensor_data,
jlongArray shape_dims_in, jint element_type_in) {
void* data = env->GetDirectBufferAddress(tensor_data);
const int64_t* shape_dims = env->GetLongArrayElements(shape_dims_in, /*isCopy*/ 0);
const int64_t* shape_dims = reinterpret_cast<const int64_t*>(env->GetLongArrayElements(shape_dims_in, /*isCopy*/ 0));
Copy link
Member

@RyanUnderhill RyanUnderhill Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't a reinterpret_cast remove type safety? Since now GetLongArrayElements could return a mismatched type and this won't be caught.

Edit: Looking again, I see that it's a compile error. Did this never work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never works on macOS. On other platform it works.

@skyline75489
Copy link
Contributor

This is already handled in #1030.

Still, thanks for the contribution!

@ilopezluna
Copy link
Author

Already handled in #1030.

@ilopezluna ilopezluna closed this Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants