Skip to content

Commit

Permalink
Fix incompatibility of callback notify func with precompilation
Browse files Browse the repository at this point in the history
  • Loading branch information
jdlangs committed Mar 19, 2018
1 parent 41dff2e commit 60be2a0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/RobotOS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function __init__()
copy!(_py_sys, pyimport("sys"))
_py_sys["argv"] = ARGS

#Fill in empty PyObjects
if ! (dirname(@__FILE__) in _py_sys["path"])
unshift!(_py_sys["path"], dirname(@__FILE__))
end
Expand All @@ -29,6 +30,9 @@ function __init__()
rethrow(ex)
end
end

#Compile the callback notify function, see callbacks.jl
CB_NOTIFY_PTR[] = cfunction(_callback_notify, Cint, Tuple{Ptr{Void}})
end

include("debug.jl")
Expand Down
4 changes: 3 additions & 1 deletion src/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ function _callback_notify(handle::Ptr{Void})
ccall(:uv_async_send, Cint, (Ptr{Void},), handle)
end

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

function _callback_async_loop(rosobj, cond)
@debug("Spinning up callback loop...")
Expand Down
2 changes: 1 addition & 1 deletion src/pubsub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mutable struct Subscriber{MsgType<:AbstractMsg}
rospycls = _get_rospy_class(MT)

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

rosobj = new{MT}(cb, cb_args, subobj, mqueue)
Expand Down
2 changes: 1 addition & 1 deletion src/services.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mutable struct Service{SrvType <: AbstractService}
rospycls = _get_rospy_class(ST)

cond = Base.AsyncCondition()
pysrv = _py_ros_callbacks["ServiceCallback"](CB_NOTIFY_PTR, cond.handle)
pysrv = _py_ros_callbacks["ServiceCallback"](CB_NOTIFY_PTR[], cond.handle)

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

0 comments on commit 60be2a0

Please sign in to comment.