Skip to content

Add @gcsafe ccall #835

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

Closed
wants to merge 7 commits into from
Closed

Add @gcsafe ccall #835

wants to merge 7 commits into from

Conversation

kpamnany
Copy link
Member

@kpamnany kpamnany force-pushed the kp-add-gcsafe_ccall branch 6 times, most recently from e6f268f to d055c52 Compare March 18, 2025 17:33
@kpamnany
Copy link
Member Author

@martinholters: looks like an upstream change has broken a test you added? Can you take a look please?

@martinholters
Copy link
Member

Huh? AFAICT, the problem originates in

Compat.jl/test/runtests.jl

Lines 158 to 174 in 8819abe

function _retrieve_exception_stack(;with_backtraces::Bool)
exception_stack = try
try
# Generate the first exception:
__not_a_binding__
catch
# Catch the first exception, and generate a second exception
# during what would be handling of the first exception:
1 ÷ 0
end
catch
# Retrieve an ExceptionStack with both exceptions,
# and bind `exception_stack` (at the top of this block) thereto:
current_exceptions(;backtrace=with_backtraces)
end
return exception_stack
end
which was added in #746 by @c42f and then modified by @Sacha0 in #758. But I can take a look non-the-less, of course. Presumable the error caused by accessing __not_a_binding__ has changed by the binding partitioning work? Maybe explicitly throwing an exception would be less brittle?

@kpamnany
Copy link
Member Author

So sorry for the mistaken tag @martinholters! I didn't look too closely... maybe @Sacha0 can take a look at it?

@martinholters
Copy link
Member

No worries. And it's just the "Suggestion: check for spelling errors or missing imports." that has been added to the exception printing at some point that causes the test failure. Fix at #836.

@martinholters martinholters added the needs-news Needs an entry in the README label Mar 19, 2025
@martinholters
Copy link
Member

Any chance to make this work on v1.6 and v1.7?

@kpamnany
Copy link
Member Author

Any chance to make this work on v1.6 and v1.7?

@vchuravy would know... when he gets back and reviews this.

@kpamnany kpamnany force-pushed the kp-add-gcsafe_ccall branch from d055c52 to 7a9e37d Compare March 24, 2025 16:39
src/Compat.jl Outdated
# when callbacks occur, the code should ensure the GC is not running by wrapping the code
# in the `@gcunsafe` macro

if VERSION >= v"1.8"
Copy link
Member

Choose a reason for hiding this comment

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

I don't see why this code should be lower bounded to 1.8?

Copy link
Member Author

@kpamnany kpamnany Mar 24, 2025

Choose a reason for hiding this comment

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

On Julia 1.6:

gcsafe_ccall: Error During Test at /Users/kpamnany/Work/Compat.jl/test/runtests.jl:1086
  Test threw exception
  Expression: gc_safe_ccall() isa UInt64
  could not load symbol "jl_rand":
  dlsym(RTLD_DEFAULT, jl_rand): symbol not found
<snip>

Copy link
Member Author

Choose a reason for hiding this comment

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

Calling any Julia C function marked JL_NOTSAFEPOINT will serve, yeah?

Copy link
Member Author

Choose a reason for hiding this comment

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

Switched to calling jl_errno.

@KristofferC
Copy link
Member

I got asked to review here so I give my personal opinion. I don't think Compat with a bunch of internals that tries to backport features from later Julia versions is a good idea in general. I don't think adding a Compat dependency (which transitively gives you dependencies on very large stdlibs) is very nice, especially when it is done on small packages that themselves have many other packages depending on them. I personally rather see some copy-pasting if something like this is really needed.

@kpamnany
Copy link
Member Author

@KristofferC's points make sense to me. I can copy-paste this macro instead; that was also an alternative @vchuravy had suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-news Needs an entry in the README
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants