-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
types as C-structs #2818
types as C-structs #2818
Conversation
I like it. We'll need some clear documentation on what becomes a pointer and what is just a field, but that's perfectly doable. |
I agree that this would be a nice feature. In PyCall, for example, I needed precisely this feature of inserting a pointer to one structure in another structure, and I needed to use some hacks since |
@JeffBezanson: can you please review? I think that's the hold up here. |
@JeffBezanson Yes, I'm waiting for your input before I finish this. I'm on IRC too if you prefer to discuss there. |
Yes, I certainly approve the concept. Please continue fixing and ping me again when ready. |
How's this going? |
It's being held up by a thesis. |
Boo! :-P |
Any progress on this? |
Depends on what you want. #3466 does some of it. |
I'm waiting for after 0.2 gets tagged to merge both |
@loladiro, I was specifically wondering about the capability to treat a |
Bump. |
Is this waiting on #5227? |
Yes |
As already said by many before, this capability would be really amazing to have. |
6c7c7e3
to
1a4c02f
Compare
almost done getting this recreated against my jn/ccall3 branch, so it should all be ready-to-merge at the same time: |
cc697f1
to
8e0bd2d
Compare
it's amazing how much our usage of travis has changed since this PR was first submitted: https://travis-ci.org/JuliaLang/julia/builds/6230711 this is likely now ready to merge, pending any findings from CI or code review |
Seems to have segfaulted building system image on 32bit linux? |
8e0bd2d
to
3676ed5
Compare
yes, although, strangely, on windows it did the reverse (the i686 build succeeded and x86-64 failed). the llvm verifier locally pointed out my invalid pointer -> int64 cast though. |
this makes references to types allocated in Julia recursively forward compatible with C structs
3676ed5
to
c5e83a6
Compare
moved to #10579 |
* Formatting changes/fixes * Small wording updates * Removed references to #2818
* Formatting changes/fixes * Small wording updates * Removed references to #2818
* Formatting changes/fixes * Small wording updates * Removed references to #2818
* Formatting changes/fixes * Small wording updates * Removed references to #2818
- Remove references to #2818 - Explain when to use `Ptr{T}` and when to use `Ref{T}` correctly. `Ptr` is generally used for return types and fields of types mirroring C structs. `Ref` is generally used for input types, allowing memory managed by either C or Julia to be referenced by `ccall`. - Provide some examples of C wrappers simplified from GSL.jl - Other minor formatting change Ref: JuliaMath/GSL.jl#43
- Remove references to #2818 - Explain when to use `Ptr{T}` and when to use `Ref{T}` correctly. `Ptr` is generally used for return types and fields of types mirroring C structs. `Ref` is generally used for input types, allowing memory managed by either C or Julia to be referenced by `ccall`. - Provide some examples of C wrappers simplified from GSL.jl - Other minor formatting change Ref: JuliaMath/GSL.jl#43
- Remove references to #2818 - Explain when to use `Ptr{T}` and when to use `Ref{T}` correctly. `Ptr` is generally used for return types and fields of types mirroring C structs. `Ref` is generally used for input types, allowing memory managed by either C or Julia to be referenced by `ccall`. - Provide some examples of C wrappers simplified from GSL.jl - Fix description of `cconvert` in the Auto-conversion section - Better cross-referencing to the standard library - Other minor formatting changes Ref: JuliaMath/GSL.jl#43
- Remove references to #2818 - Explain when to use `Ptr{T}` and when to use `Ref{T}` correctly. `Ptr` is generally used for return types and fields of types mirroring C structs. `Ref` is generally used for input types, allowing memory managed by either C or Julia to be referenced by `ccall`. - Provide some examples of C wrappers simplified from GSL.jl, with comments delineating the various parts of the `ccall`. - Fix description of `cconvert` in the Auto-conversion section - Better cross-referencing to the standard library - Other minor formatting changes Ref: JuliaMath/GSL.jl#43
Remove mention of issue #2818 from 0.4 manual
This is a first pass at giving pointers to julia types easy compatibility with C. This is done by "hiding" the type and GC information before the data, and shifting all references in the julia source by 1 to match. What this would mean for the user is that
can be passed to a C function expecting:
If the user is receiving data from C (e.g. anything not created by Julia's GC), then they must instead declare it as
Ptr{A}
and access with unsafe_ref (I'm wondering if it might be more appropriate to introduce another type for this purpose, but thats a separate issue I'll go into later).If @JeffBezanson approves of this, I'll go back through and clean this up some to make it ready to merge. TODO items include: