Skip to content

Commit efb462d

Browse files
committed
Additional 0.7 fixes
1 parent 7fac68e commit efb462d

File tree

4 files changed

+44
-45
lines changed

4 files changed

+44
-45
lines changed

src/RobotOS.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ const _py_sys = PyCall.PyNULL()
1010
const _py_ros_callbacks = PyCall.PyNULL()
1111
const __rospy__ = PyCall.PyNULL()
1212

13+
include("debug.jl")
14+
include("time.jl")
15+
include("gentypes.jl")
16+
include("rospy.jl")
17+
include("pubsub.jl")
18+
include("services.jl")
19+
include("callbacks.jl")
20+
1321
function __init__()
1422
#Put julia's ARGS into python's so remappings will work
1523
copy!(_py_sys, pyimport("sys"))
@@ -33,15 +41,7 @@ function __init__()
3341
end
3442

3543
#Compile the callback notify function, see callbacks.jl
36-
CB_NOTIFY_PTR[] = cfunction(_callback_notify, Cint, Tuple{Ptr{Cvoid}})
44+
CB_NOTIFY_PTR[] = @cfunction(_callback_notify, Cint, (Ptr{Cvoid},))
3745
end
3846

39-
include("debug.jl")
40-
include("time.jl")
41-
include("gentypes.jl")
42-
include("rospy.jl")
43-
include("pubsub.jl")
44-
include("services.jl")
45-
include("callbacks.jl")
46-
4747
end

src/gentypes.jl

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ abstract type AbstractMsg end
6464
abstract type AbstractSrv end
6565
abstract type AbstractService end
6666

67+
_is_tuple_expr(input) = input isa Expr && input.head == :tuple
68+
_is_colon_expr(input) = input isa Expr && input.head == :call && input.args[1] == :(:)
69+
_is_dot_expr(input) = input isa Expr && input.head == :(.)
70+
6771
"""
6872
@rosimport
6973
@@ -81,13 +85,11 @@ macro rosimport(input)
8185
#Rearranges the expression into a RobotOS._rosimport call. Input comes in as a single package
8286
#qualified expression, or as a tuple expression where the first element is the same as the
8387
#single expression case. Most of the code is just error checking that the input takes that form.
84-
@assert input.head in [:tuple, :(.), :(:)] "Improper @rosimport input"
85-
if input.head == :tuple
86-
@assert isa(input.args[1], Expr) "Improper @rosimport input"
87-
@assert input.args[1].head == :(:) "First argument needs ':' following"
88-
types = String[]
88+
@assert _is_tuple_expr(input) || _is_colon_expr(input) || _is_dot_expr(input) "Improper @rosimport input"
89+
if _is_tuple_expr(input)
90+
@assert _is_colon_expr(input.args[1]) "Improper @rosimport input, first argument needs ':' following"
8991
pkg, ismsg, typ = _pkgtype_import(input.args[1])
90-
push!(types, typ)
92+
types = String[typ]
9193
for t in input.args[2:end]
9294
@assert isa(t, Symbol) "Type name ($(string(t))) not a symbol"
9395
push!(types, string(t))
@@ -98,32 +100,29 @@ macro rosimport(input)
98100
return :(_rosimport($pkg, $ismsg, $typ))
99101
end
100102
end
101-
102-
_get_quote_value(input::QuoteNode) = input.value
103-
_get_quote_value(input::Expr) = (@assert input.head == :quote; input.args[1])
104-
105103
#Return the pkg and types strings for a single expression of form:
106104
# pkg.[msg|srv].type or pkg.[msg|srv]:type
107105
function _pkgtype_import(input::Expr)
108-
@assert input.head in (:(.), :(:)) "Improper @rosimport input"
109-
@assert isa(input.args[1], Expr) "Improper @rosimport input"
110-
@assert input.args[1].head == :(.) "Improper @rosimport input"
111-
p = input.args[1].args[1]
106+
@assert _is_colon_expr(input) || _is_dot_expr(input) "Improper @rosimport input"
107+
p_ms, t = _is_colon_expr(input) ? (input.args[2], input.args[3]) : (input.args[1], input.args[2])
108+
@assert _is_dot_expr(p_ms) "Improper @rosimport input"
109+
p = p_ms.args[1]
112110
@assert isa(p, Symbol) "Package name ($(string(p))) not a symbol"
113-
m_or_s = _get_quote_value(input.args[1].args[2])
111+
@assert isa(p_ms.args[2], QuoteNode) "Improper @rosimport input"
112+
m_or_s = p_ms.args[2].value
114113
@assert m_or_s in (:msg,:srv) "Improper @rosimport input"
115114
ps = string(p)
116115
msb = m_or_s == :msg
117116
ts = ""
118-
if isa(input.args[2], Symbol)
119-
ts = string(input.args[2])
120-
elseif isa(input.args[2], Expr)
121-
@assert length(input.args[2].args) == 1 "Type name not a symbol"
122-
tsym = input.args[2].args[1]
117+
if isa(t, Symbol)
118+
ts = string(t)
119+
elseif isa(t, Expr)
120+
@assert length(t.args) == 1 "Type name ($(t)) not a symbol"
121+
tsym = t.args[1]
123122
@assert isa(tsym, Symbol) "Type name ($(string(tsym))) not a symbol"
124123
ts = string(tsym)
125-
elseif isa(input.args[2], QuoteNode)
126-
tsym = input.args[2].value
124+
elseif isa(t, QuoteNode)
125+
tsym = t.value
127126
@assert isa(tsym, Symbol) "Type name ($(string(tsym))) not a symbol"
128127
ts = string(tsym)
129128
end
@@ -179,8 +178,8 @@ function addtype!(mod::ROSMsgModule, typ::String)
179178
if !(typ in mod.members)
180179
@debug("Message type import: ", _fullname(mod), ".", typ)
181180
if _nameconflicts(typ)
182-
warn("Message type '$typ' conflicts with Julia builtin, ",
183-
"will be imported as '$(_jl_safe_name(typ,"Msg"))'")
181+
@warn("Message type '$typ' conflicts with Julia builtin, ",
182+
"will be imported as '$(_jl_safe_name(typ,"Msg"))'")
184183
end
185184
pymod, pyobj = _pyvars(_fullname(mod), typ)
186185

@@ -350,19 +349,19 @@ end
350349

351350
#The imports specific to each module, including dependant packages
352351
function _importexprs(mod::ROSMsgModule, rosrootmod::Module)
353-
imports = Expr[Expr(:import, :RobotOS, :AbstractMsg)]
352+
imports = Expr[:(import RobotOS.AbstractMsg)]
354353
othermods = filter(d -> d != _name(mod), mod.deps)
355-
append!(imports, [Expr(:using,fullname(rosrootmod)...,Symbol(m),:msg) for m in othermods])
354+
append!(imports, [Expr(:using, Expr(:., fullname(rosrootmod)..., Symbol(m), :msg)) for m in othermods])
356355
imports
357356
end
358357
function _importexprs(mod::ROSSrvModule, rosrootmod::Module)
359358
imports = Expr[
360-
Expr(:import, :RobotOS, :AbstractSrv),
361-
Expr(:import, :RobotOS, :AbstractService),
362-
Expr(:import, :RobotOS, :_srv_reqtype),
363-
Expr(:import, :RobotOS, :_srv_resptype),
359+
:(import RobotOS.AbstractSrv),
360+
:(import RobotOS.AbstractService),
361+
:(import RobotOS._srv_reqtype),
362+
:(import RobotOS._srv_resptype)
364363
]
365-
append!(imports, [Expr(:using,fullname(rosrootmod)...,Symbol(m),:msg) for m in mod.deps])
364+
append!(imports, [Expr(:using, Expr(:., fullname(rosrootmod)..., Symbol(m), :msg)) for m in mod.deps])
366365
imports
367366
end
368367

@@ -513,8 +512,8 @@ function _addtypemember!(exprs, namestr, typestr)
513512
jlconargs = exprs[4].args[2].args
514513

515514
if typestr == "char" || typestr == "byte"
516-
warn("Use of type '$typestr' is deprecated in message definitions, ",
517-
"use '$(lowercase(string(_ros_builtin_types[typestr])))' instead.")
515+
@warn("Use of type '$typestr' is deprecated in message definitions, ",
516+
"use '$(lowercase(string(_ros_builtin_types[typestr])))' instead.")
518517
end
519518

520519
typestr, arraylen = _check_array_type(typestr)

test/pubsub.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using .geometry_msgs.msg
77
const Nmsgs = 10
88
const rate = 20. #Hz
99
const msgs = PoseStamped[]
10-
const refs = Array{Vector3}(Nmsgs)
10+
const refs = Array{Vector3}(undef, Nmsgs)
1111
const t0 = to_nsec(get_rostime())
1212

1313
for i=1:Nmsgs

test/typegeneration.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ rostypegen()
3232
module TestModule
3333
using RobotOS
3434
@rosimport std_msgs.msg: Float32
35-
rostypegen(current_module())
35+
rostypegen(@__MODULE__)
3636
end
3737
@test !isdefined(std_msgs.msg, :Float32Msg)
3838
@test isdefined(TestModule, :std_msgs)
@@ -84,7 +84,7 @@ path2 = convert(nav_msgs.msg.Path, pypath)
8484

8585
#Issue #6 - Empty message
8686
emptymsg = std_msgs.msg.Empty()
87-
@test length(fieldnames(emptymsg)) == 0
87+
@test length(fieldnames(typeof(emptymsg))) == 0
8888

8989
#Issue #7/8 - Renaming conflicting message types
9090
@test isdefined(std_msgs.msg, :Float64Msg)

0 commit comments

Comments
 (0)