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

fix: android jni unused-parameter #1772

Merged
merged 2 commits into from
Nov 17, 2023

Conversation

fdintino
Copy link
Contributor

@fdintino fdintino commented Nov 16, 2023

The more stringent error and warning compiler flags in the root CMakeLists.txt are set with add_compile_options and so, as directory properties, they don't get applied to the avif_android target. If -Wall -Werror or /W4 /WX are enabled for avif_android, the compiler fails on -Werror,-Wunused-parameter. This issue is fixed by defining a macro, IGNORE_UNUSED_JNIPARAMETERS, that is called at the top of any functions that don't reference the env or thiz parameters.

Note: this file appears to not have had clang-format run on it, so I didn't do any reformatting.

@@ -35,6 +35,8 @@ add_subdirectory(../../../../.. build)

add_library("avif_android" SHARED "libavif_jni.cc")

target_compile_options(avif_android PRIVATE $<TARGET_PROPERTY:avif,COMPILE_OPTIONS>)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Vignesh: I didn't review the change to this file. The changes to libavif_jni.cc seem like a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change isn't actually necessary and I'd be fine with removing it. It makes it so that this warning causes errors on build, but that's not strictly necessary. If something like #1778 gets merged then this would be redundant.

@vigneshvg
Copy link
Collaborator

Thank you, i will take a look at this PR.

@@ -19,10 +19,10 @@
#define FUNC(RETURN_TYPE, NAME, ...) \
extern "C" { \
JNIEXPORT RETURN_TYPE Java_org_aomedia_avif_android_AvifDecoder_##NAME( \
JNIEnv* env, jobject thiz, ##__VA_ARGS__); \
__VA_ARGS__); \
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm, i don't like the idea of repeating the jni env parameters in all the functions. it pushes the actual argument list to the back and it's a mix of named and unnamed parameters.

how about this instead: keep this macro as is. add a new macro like so:

#define IGNORE_UNUSED_JNIPARAMETERS \
  (void) env; \
  (void) thiz

and add this as the first line to each of the functions? this way it is uniform how we handle it in all the functions (it doesn't really matter if we use these variables in these functinos or not since we know what we are ignoring here).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was between that approach and the one I have here, and I didn't have strong opinion either way. I'd be fine with adding an ignore parameter macro

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

@vigneshvg vigneshvg left a comment

Choose a reason for hiding this comment

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

thank you! lgtm with one minor comment.

android_jni/avifandroidjni/src/main/jni/libavif_jni.cc Outdated Show resolved Hide resolved
@vigneshvg
Copy link
Collaborator

thank you for the PR!

@vigneshvg vigneshvg merged commit 484984a into AOMediaCodec:main Nov 17, 2023
19 checks passed
@fdintino fdintino deleted the fix/libavif-jni-unused-param branch November 17, 2023 19:29
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