Closed mkitti closed 2 years ago
Looks like it compiles!
julia> function foo()
ptr = Ptr{Int}(malloc(25*sizeof(Int)))
a = Base.unsafe_wrap(MallocArray, ptr, (5,5))
a .= 5
printf(a)
end
foo (generic function with 1 method)
julia> compile_executable(foo, (), "./")
ld: warning: object file (./foo.o) was built for newer OSX version (12.0) than being linked (10.13)
"/Users/cbkeller/foo"
shell> ./foo
5 5 5 5 5
5 5 5 5 5
5 5 5 5 5
5 5 5 5 5
5 5 5 5 5
This seems like a totally reasonable thing to add, thanks for the PR!
This pull request implements
Base.unsafe_wrap
forMallocArray
. This provides a hook to make it easier to compose with other packages sinceBase.unsafe_wrap
is a generic method to construct anAbstractArray
from a pointer.