From 60be2a043f2f68548c1c0ced8c2e6d764fbf232d Mon Sep 17 00:00:00 2001 From: Josh Langsfeld Date: Mon, 19 Mar 2018 09:54:25 -0500 Subject: [PATCH] Fix incompatibility of callback notify func with precompilation --- src/RobotOS.jl | 4 ++++ src/callbacks.jl | 4 +++- src/pubsub.jl | 2 +- src/services.jl | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/RobotOS.jl b/src/RobotOS.jl index 1891c96..05c3c2b 100644 --- a/src/RobotOS.jl +++ b/src/RobotOS.jl @@ -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 @@ -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") diff --git a/src/callbacks.jl b/src/callbacks.jl index ddbb3b9..517d8ac 100644 --- a/src/callbacks.jl +++ b/src/callbacks.jl @@ -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...") diff --git a/src/pubsub.jl b/src/pubsub.jl index 35214d5..3e11e07 100644 --- a/src/pubsub.jl +++ b/src/pubsub.jl @@ -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) diff --git a/src/services.jl b/src/services.jl index 045a9ee..1aab115 100644 --- a/src/services.jl +++ b/src/services.jl @@ -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...)