Skip to content

Commit df32f3c

Browse files
authored
Merge pull request #43 from jdlangs/cbnotify_precompile
Fix incompatibility of callback notify func with precompilation
2 parents 41dff2e + 60be2a0 commit df32f3c

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

src/RobotOS.jl

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function __init__()
1414
copy!(_py_sys, pyimport("sys"))
1515
_py_sys["argv"] = ARGS
1616

17+
#Fill in empty PyObjects
1718
if ! (dirname(@__FILE__) in _py_sys["path"])
1819
unshift!(_py_sys["path"], dirname(@__FILE__))
1920
end
@@ -29,6 +30,9 @@ function __init__()
2930
rethrow(ex)
3031
end
3132
end
33+
34+
#Compile the callback notify function, see callbacks.jl
35+
CB_NOTIFY_PTR[] = cfunction(_callback_notify, Cint, Tuple{Ptr{Void}})
3236
end
3337

3438
include("debug.jl")

src/callbacks.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ function _callback_notify(handle::Ptr{Void})
44
ccall(:uv_async_send, Cint, (Ptr{Void},), handle)
55
end
66

7-
const CB_NOTIFY_PTR = cfunction(_callback_notify, Cint, Tuple{Ptr{Void}})
7+
#The pointer to the compiled notify function. This can't be precompiled so it gets initialized in
8+
#the module __init__ function.
9+
const CB_NOTIFY_PTR = Ref{Ptr{Void}}()
810

911
function _callback_async_loop(rosobj, cond)
1012
@debug("Spinning up callback loop...")

src/pubsub.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ mutable struct Subscriber{MsgType<:AbstractMsg}
5252
rospycls = _get_rospy_class(MT)
5353

5454
cond = Base.AsyncCondition()
55-
mqueue = _py_ros_callbacks["MessageQueue"](CB_NOTIFY_PTR, cond.handle)
55+
mqueue = _py_ros_callbacks["MessageQueue"](CB_NOTIFY_PTR[], cond.handle)
5656
subobj = __rospy__[:Subscriber](ascii(topic), rospycls, mqueue["storemsg"]; kwargs...)
5757

5858
rosobj = new{MT}(cb, cb_args, subobj, mqueue)

src/services.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mutable struct Service{SrvType <: AbstractService}
5151
rospycls = _get_rospy_class(ST)
5252

5353
cond = Base.AsyncCondition()
54-
pysrv = _py_ros_callbacks["ServiceCallback"](CB_NOTIFY_PTR, cond.handle)
54+
pysrv = _py_ros_callbacks["ServiceCallback"](CB_NOTIFY_PTR[], cond.handle)
5555

5656
srvobj = try
5757
__rospy__[:Service](ascii(name), rospycls, pysrv["srv_cb"]; kwargs...)

0 commit comments

Comments
 (0)