Skip to content

Commit 69f0a50

Browse files
committed
Move name assert and improve nargs behaviour in registerfunc.
1 parent ad41fce commit 69f0a50

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/UDF.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# scalar functions
22
function registerfunc(db::SQLiteDB, nargs::Integer, func::Function, isdeterm::Bool=true; name="")
3-
@assert sizeof(name) <= 255 "size of function name must be <= 255"
4-
@assert (-1 <= nargs <= 127) "nargs must follow the inequality -1 <= nargs <= 127"
3+
@assert nargs <= 127 "only varargs functions can have more than 127 arguments"
4+
# assume any negative number means a varargs function
5+
nargs < -1 && (nargs = -1)
56

67
name = isempty(name) ? string(func) : name::String
8+
@assert sizeof(name) <= 255 "size of function name must be <= 255"
9+
710
cfunc = cfunction(func, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}}))
811

912
# TODO: allow the other encodings
@@ -17,7 +20,9 @@ end
1720

1821
# aggregate functions
1922
function registerfunc(db::SQLiteDB, nargs::Integer, step::Function, final::Function, isdeterm::Bool=true; name="")
20-
@assert (-1 <= nargs <= 127) "nargs must follow the inequality -1 <= nargs <= 127"
23+
@assert nargs <= 127 "only varargs functions can have more than 127 arguments"
24+
# assume any negative number means a varargs function
25+
nargs < -1 && (nargs = -1)
2126

2227
name = isempty(name) ? string(step) : name::String
2328
cstep = cfunction(step, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}}))
@@ -94,7 +99,6 @@ macro scalarfunc(args...)
9499
end
95100
end
96101

97-
98102
# annotate types because the MethodError makes more sense that way
99103
@scalarfunc regexp(r::String, s::String) = ismatch(Regex(r), s)
100104
# macro for preserving the special characters in a string

0 commit comments

Comments
 (0)