Skip to content

Commit f5abc46

Browse files
committed
Neaten scalarfunc and improve error feedback.
Pull naming logic out of macro and add type annotations to the returned function to prevent overwriting previously defined methods. Let errors propagate, giving a more comprehensive traceback.
1 parent 0874081 commit f5abc46

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/UDF.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,24 @@ sqlreturn(context, val::Bool) = sqlreturn(context, int(val))
9090
sqludferror(context, msg::String) = sqlite3_result_error(context, msg)
9191
sqludferror(context, msg::UTF16String) = sqlite3_result_error16(context, msg)
9292

93-
macro scalarfunc(args...)
94-
if length(args) == 2
95-
func = args[2]
96-
name = args[1]
93+
function funcname(expr)
94+
if length(expr) == 2
95+
func = expr[2]
96+
name = expr[1]
9797
else
98-
func = args[1]
98+
func = expr[1]
9999
name = func.args[1].args[1]
100100
end
101+
name, func
102+
end
103+
104+
macro scalarfunc(args...)
105+
name, func = funcname(args)
101106
return quote
102-
function $(esc(name))(context, nargs, values)
107+
function $(esc(name))(context::Ptr{Void}, nargs::Cint, values::Ptr{Ptr{Void}})
103108
args = [sqlvalue(values, i) for i in 1:nargs]
104-
# TODO: would it be better to let the exceptions propagate?
105-
try
106-
ret = $(func)(args...)
107-
sqlreturn(context, ret)
108-
catch err
109-
sqludferror(context, string(err))
110-
end
109+
ret = $(func)(args...)
110+
sqlreturn(context, ret)
111111
nothing
112112
end
113113
end

0 commit comments

Comments
 (0)