Thanks for bringing cconvert
and unsafe_convert
to my attention: using those seems like the cleanest way. Storing both the pointer and the pointed-to data could also work…but it feels kind of clunky. However, when I try to imitate the above examples, I’m getting an Illegal instruction
error.
One thing I should’ve mentioned: the C functions I’m interested in typically take the C struct itself, not a pointer to the C struct. In that case, do things look different than in the above examples?
More details about my goals: I’m trying to build a Julia interface for the Apple Accelerate routines related to sparse matrix factorization. (Related links: my work-in-progress/proof-of-concept GitHub repo and this forum post.) I want to avoid re-inventing the wheel: ideally, cconvert
should accept a SparseMatrixCSC
(the Julia struct) and create a matching SparseMatrix
struct (the C struct), for passing into the various @ccall
s. The structs mostly line up, but there’s small differences: 0- vs 1-indexing, Cints vs Clongs for row indices.
For a more minimal, less involved example: take a look at DenseMatrix
. This only has a single pointer, and no re-indexing is required. How would I write cconvert
so as to take a Julia A::Matrix{T}
and create a B::DenseMatrix{T}
such that B.data = pointer(A.ref)
, so I could have SparseMultiply
take in normal Julia matrices for arg2
and arg3
?
EDIT: okay I have a bigger problem. I’m nesting structs (SparseMatrixStructure
inside SparseMatrix
), where the inner struct is not an isbits
struct type. Thus the Illegal instruction
error: fields weren’t lining up. But I’d still be interested in knowing the answer to the above question.