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

Libdl.dlclose incorrectly assumes 0 is success on all platforms #25137

Closed
jdjohnston opened this issue Dec 17, 2017 · 6 comments
Closed

Libdl.dlclose incorrectly assumes 0 is success on all platforms #25137

jdjohnston opened this issue Dec 17, 2017 · 6 comments

Comments

@jdjohnston
Copy link
Contributor

jdjohnston commented Dec 17, 2017

Libdl.dlclose returns true iff the return of the lower-level ccall is zero. However, Windows uses the opposite convention for FreeLibrary (which is what dlload.c/jl_dlclose calls on WIndows): success is non-zero.

Maybe Libdl.dlclose could use something like:

sts = ccall(:jl_dlclose, ...)
if is_windows()
  sts != 0
else
  sts == 0
end

I also noted that while Libdl.dlclose is used in test/libdl.jl, it is never tested.

Maybe also jl_dlclose should, for Windows
if (!handle) return 0;

@vtjnash
Copy link
Member

vtjnash commented Dec 17, 2017

I suppose we just assume that there's very little you can do to recover from an error during cleanup. Anyways, can you submit a PR to change the return value of jl_dlclose on Windows to be consistent with dlclose?

@staticfloat
Copy link
Member

In case you're not sure where that is, Jameson is asking you to make this line do the right thing. :)

@vtjnash
Copy link
Member

vtjnash commented Dec 17, 2017

Ah right. I was assuming jdjohnston had already found that from the quality of the report, but should probably try to avoid being as cryptic.

@jdjohnston
Copy link
Contributor Author

My initial thot was that it would be good to have jl_dlclose behave like the underlying OS system calls and account for the difference in Libdl.dlclose. But there really isn't enough benefit to that to go forward with that approach. Besides a one character addition to jl_dlclose would be simpler, more elegant, more efficient, more ... :)

PR should be up later today or tomorrow at the latest. (I'm running out of 'Net time today.) Something this simple and already discussed doesn't need to marked WIP, right?

@staticfloat
Copy link
Member

Something this simple and already discussed doesn't need to marked WIP, right?

Right, feel free to just open the PR directly, and ping myself or Jameson for a merge.

jdjohnston added a commit to jdjohnston/julia that referenced this issue Dec 19, 2017
- Invert boolean value returned by Windows FreeLibrary so it matches
  that of POSIX dlclose
- Add test of jl_dlclose/Libdl.dlclose to test/libdl.jl
@jdjohnston
Copy link
Contributor Author

jdjohnston commented Dec 19, 2017

@vtjnash @staticfloat, Please consider PR #25175.

One note: besides the 1-character fix in dlload.c, I also added a test to test/libdl.jl. Since Libdl.dlclose is expected to return different values depending on whether it succeeded or not, it makes sense to have a unit test check for those values. If such a test had existed before, it would have failed on Windows and there would have been no need for my bug report. :) Having a unit test seems like protection against regression.

I realize that a unit test wasn't requested and if need be, I'll gladly retract it from the PR.

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

No branches or pull requests

3 participants