-
Notifications
You must be signed in to change notification settings - Fork 0
/
example5.jl
74 lines (58 loc) · 2.19 KB
/
example5.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Libdl
lib = Libdl.dlopen(joinpath(@__DIR__, "../o/liblibrary_default_cc_example5c.dylib"))
println("-----------------------------------------------------")
x = Int32(5)
@show x
@show ccall(:incrementIntegerValueReturnValue, Cint, (Cint, ), 5)
@show x
println("-----------------------------------------------------")
x = Int32(5)
@show x
@show ccall(:incrementIntegerPointerReturnValue, Cint, (Ptr{Cint}, ), Ref(Int32(x)))
@show x
println("-----------------------------------------------------")
x = Int32(5)
ref_x = Ref(x)
@show ref_x[]
@show ccall(:incrementIntegerPointerInInput, Cvoid, (Ptr{Cint}, ), ref_x)
@show ref_x[]
println("-----------------------------------------------------")
arr = Int32[0, 1, 2, 3, 4]
@show arr
@show ccall(:incrementIntegersInIntStarArray, Cvoid, (Ptr{Vector{Cint}}, Cint), pointer(arr), length(arr))
@show arr
println("-----------------------------------------------------")
arr = Int32[0, 1, 2, 3, 4]
@show arr
@show ccall(:incrementIntegersInIntStarStarArray, Cvoid, (Vector{Cint}, Cint), arr, length(arr))
@show arr
println("-----------------------------------------------------")
arr = Int32[0, 1, 2, 3, 4]
ref_arr = Ref(arr)
@show arr
@show ccall(:incrementIntegersInIntStarStarArray, Cvoid, (Ptr{Vector{Cint}}, Cint), ref_arr, length(arr))
@show arr
println("-----------------------------------------------------")
mutable struct Structure
integer::Cint
end
s = Structure(1)
@show s
@show ccall(:incrementIntegerInStruct, Structure, (Structure, ), s)
@show s
println("-----------------------------------------------------")
s = Structure(1)
@show s
@show ccall(:incrementIntegerInStructPointer, Cvoid, (Ref{Structure}, ), s)
@show s
println("-----------------------------------------------------")
s = Structure(1)
@show s
@show ccall(:incrementIntegerInStructPointer, Cvoid, (Ptr{Nothing}, ), pointer_from_objref(s))
@show s
println("-----------------------------------------------------")
@show s = ccall(:initializeStructureStack, Structure, ())
println("-----------------------------------------------------")
@show s = unsafe_load(ccall(:initializeStructureHeap, Ptr{Structure}, ()))
println("-----------------------------------------------------")
Libdl.dlclose(lib)