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

Interpreter doesn't wrap extern fun vars in Crystal procs #12495

Open
asterite opened this issue Sep 18, 2022 · 3 comments
Open

Interpreter doesn't wrap extern fun vars in Crystal procs #12495

asterite opened this issue Sep 18, 2022 · 3 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:interpreter

Comments

@asterite
Copy link
Member

This code crashes the interpreter:

x = LibPCRE.free
x.call(Pointer(Void).new(0))

The problem is that LibCPRE.free's type is Proc(Void*). Right now Crystal returns that type from LibPCRE.free, which is 16 bytes, but that's wrong. The actual size is 8 bytes and it needs to be wrapped in a FFI closure and then padded with zero to form the Proc.

@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:interpreter labels Sep 18, 2022
@straight-shoota
Copy link
Member

For reference: This was discovered in #12456 (comment)

straight-shoota added a commit to straight-shoota/crystal that referenced this issue Sep 18, 2022
This is a workaround for an interpreter bug (crystal-lang#12495) and basically
restores the status before crystal-lang#12456.
@asterite
Copy link
Member Author

Also a note that I briefly thought how to implement this but I have no idea. I get confused. And I won't have time to do this. So if someone wants to do it, please go ahead :-)

I also noticed that things like ->foo doesn't work either in the interpreter.

@HertzDevil
Copy link
Contributor

This is also related to the Proc.new(Void*, Void*) constructor in case the C function returns a type-erased pointer, since that can directly implement the use case here. Crystal::System::Socket.load_extension_function on Windows does this and it is currently blocking any form of networking in interpreted code on Windows.

We should decide whether that constructor accepts bytecode pointers or C function pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:interpreter
Projects
None yet
Development

No branches or pull requests

3 participants