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

handle UnsatisfiedLinkError in LinuxPOSIX constructor, resolves #187 #188

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

betalb
Copy link
Contributor

@betalb betalb commented Feb 6, 2024

POC PR that will resolve #187

@enebo
Copy link
Member

enebo commented Feb 6, 2024

@betalb So I have a question which you may know. The original code is written around each of these three foreign calls potentially being independently defined (lazily setting bool for each one to fall back when it is wrong). I would think typically it would be all or nothing (like your PR does) but it isn't how the rest of this code is written. The original statVersion test is an all or nothing field but the check only checks one stat.

If we could assume alll 3 calls are always defined or not defined we could get rid of all this try/catch stuff in the individual stat methods.

I think your PR looks ok to me and it definitely fixes an obvious problem on systems missing these calls.

@headius do you have any thoughts on this? I half think we should assume all or nothing based on presence of xstat64 and then remove the volatile booleans and the extra logic in each stat.

@enebo
Copy link
Member

enebo commented Feb 6, 2024

I should add this appears to be written around lazily working but it clearly only worked lazily ONLY is __xstat64 worked. So at a minimum we could eliminate that one from having volatile field and lazy logic.

Copy link
Member

@headius headius left a comment

Choose a reason for hiding this comment

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

Looks good but we might as well clean up the three booleans and move the whitespace cleanup to a separate commit.

src/main/java/jnr/posix/LinuxPOSIX.java Outdated Show resolved Hide resolved
src/main/java/jnr/posix/LinuxPOSIX.java Outdated Show resolved Hide resolved
@enebo
Copy link
Member

enebo commented Feb 6, 2024

@betalb could you change this to be a single final boolean for all 3? Since this happens in the constructor and we try once we can then remove all UnsatisfiedLinkErrors in the 3 stat methods and only check that boolean value. If you don't want to we can do it but it might be fun to delete code? 😄

@betalb
Copy link
Contributor Author

betalb commented Feb 7, 2024

I did the changes, discussed here
Also I mentioned that -1 return code handling was inconsistent between fstat and lstat/stat in versions that accept FileStat object as argument, so I've aligned them.

I can make another change and move error reporting to method versions with 2 arguments (int fd, FileStat stat). Though I see that super-classes follow the same pattern and report error in stat versions that accept only integer argument and return stat object.

@betalb betalb requested a review from headius February 7, 2024 12:01
@headius
Copy link
Member

headius commented Feb 7, 2024

@betalb There's definitely an unfortunate lack of consistency in these APIs, as we have been slowly adding and improving them over the past 10-15 years. We would definitely welcome any additional PRs that make things more consistent!

I will review the updated PR.

Copy link
Member

@headius headius left a comment

Choose a reason for hiding this comment

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

Much cleaner this way! Thank you for making the updates.

@headius headius merged commit 7ee2a30 into jnr:master Feb 7, 2024
3 checks passed
@headius headius added this to the 3.1.19 milestone Feb 7, 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.

LinuxLibC interface is incompatible with musl libc
3 participants