ndk icon indicating copy to clipboard operation
ndk copied to clipboard

[FR] improve bad diagnostic for `__REMOVED_IN` on `ALooper_pollAll`

Open DanAlbert opened this issue 1 year ago • 8 comments
trafficstars

Description

error: 'ALooper_pollAll' is unavailable: obsoleted in Android 1
     45 |     if (ALooper_pollAll(IsVulkanReady() ? 1 : 0, nullptr,
        |         ^
  usr/include/android/looper.h:216:5: note: 'ALooper_pollAll' has been explicitly marked unavailable here
    216 | int ALooper_pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData) __REMOVED_IN(1);
        |     ^

It's been marked obsolete because the implementation is racy and can't be called safely, but ALooper_pollOnce can be called in a loop for the same effect, and is available for all supported OS versions.

The diagnostic is next to useless though, and should be expanded to include that explanation.

I've explained the OS bug in another thread to not bog down this bug (which is about an unclear diagnostic, not a missing API): https://github.com/android/ndk/discussions/2020.

DanAlbert avatar Apr 16 '24 18:04 DanAlbert

is plain old __attribute__((__deprecated__(("use foo instead")))) a better choice then, since it includes a user-provided diagnostic?

enh-google avatar Apr 16 '24 23:04 enh-google

__attribute__((availability)) supports that too. We don't expose that in __REMOVED_IN() though, and that's the fix we need.

DanAlbert avatar Apr 17 '24 21:04 DanAlbert

oh, yeah, that seems like a bug in __REMOVED_IN() --- i vote we require an explanation...

enh-google avatar Apr 17 '24 21:04 enh-google

Don't know why I didn't think of that, or why we didn't do that in the first place :) +1

DanAlbert avatar Apr 17 '24 22:04 DanAlbert

Status? SDL will not compile for android because of this bug

FaisalAhmedAlghamdi avatar May 01 '24 06:05 FaisalAhmedAlghamdi

Status? SDL will not compile for android because of this bug

this bug won't fix any builds --- this bug will just give you a compiler diagnostic explaining that you need to switch from ALooper_pollAll() to ALooper_pollOnce().

enh-google avatar May 01 '24 14:05 enh-google

but, yes, it looks like even SDL 3.0 relies on ALooper_pollAll(): https://github.com/libsdl-org/SDL/blob/12b6c17575a4b24539b7d17625232fff899c90cf/src/sensor/android/SDL_androidsensor.c#L73

enh-google avatar May 01 '24 14:05 enh-google

It also uses ALooper_wake, so this is not a false positive. That's a bug in SDL.

EDIT: It may not be. The bug happens if you use pollAll in combination with both events signaled by callbacks and those signaled by wait. There's definitely a wait in that code. Whether there's a callback or not is not depends on how the sensor API is implemented in the OS, I think.

Okay, looking even more closely, it's not just in combination with callbacks, and wake and any other event, so yes, that probably does have the bug. See the discussion post I added to the OP for more info.

DanAlbert avatar May 01 '24 19:05 DanAlbert