Skip to content

Commit

Permalink
Revert ":wrench: Use @CCall macro"
Browse files Browse the repository at this point in the history
This reverts commit 8bd54c3.
  • Loading branch information
ronisbr committed Nov 27, 2024
1 parent 72dc114 commit 10a829c
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 5 deletions.
40 changes: 38 additions & 2 deletions src/submodules/NCurses/form/form_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@
#
############################################################################################

############################################################################################
# Private Macros #
############################################################################################

"""
@_ccallf expr
Make a `ccall` to a `libform` function. The usage should be:
@_ccallf function(arg1::Type1, arg2::Type2, ...) -> TypeReturn
It uses the global constant structure `ncurses` to call the function. Hence, it must be
initialized.
"""
macro _ccallf(expr)
!(expr.head == :(::) && expr.args[1].head == :call) &&
error("Invalid use of @_ccall")

return_type = expr.args[2]
function_name = QuoteNode(expr.args[1].args[1])
args = expr.args[1].args[2:end]

arglist = []
typeargs = :(())
handler = :(dlsym($(esc(ncurses)).libform, $(esc(function_name))))
out = :(ccall( $(handler), $(esc(return_type)), $(esc(typeargs))))

for arg in args
!(arg.head == :(::)) && error("All arguments must have a type.")
push!(out.args, :($(esc(arg.args[1]))))
push!(typeargs.args, arg.args[2])
end

return out
end

############################################################################################
# `libform` Functions #
############################################################################################
Expand All @@ -18,7 +54,7 @@ function new_field(
offscreen::Int,
nbuffers::Int
)
@ccall new_field(
@_ccallf new_field(
height::Cint,
width::Cint,
toprow::Cint,
Expand Down Expand Up @@ -201,7 +237,7 @@ for (f, r, v, j, c) in
For more information, see `libform` documentation.
"""
$f($(argsj...)) = @ccall $f($(argsc...))::$r
$f($(argsj...)) = @_ccallf $f($(argsc...))::$r
_precompile_func($f, $argst)
end
end
Expand Down
38 changes: 37 additions & 1 deletion src/submodules/NCurses/menu/menu_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@
#
############################################################################################

############################################################################################
# Private Macros #
############################################################################################

"""
@_ccallm expr
Make a `ccall` to a `libmenu` function. The usage should be:
@_ccallm function(arg1::Type1, arg2::Type2, ...) -> TypeReturn
It uses the global constant structure `ncurses` to call the function. Hence, it must be
initialized.
"""
macro _ccallm(expr)
!(expr.head == :(::) && expr.args[1].head == :call) &&
error("Invalid use of @_ccall")

return_type = expr.args[2]
function_name = QuoteNode(expr.args[1].args[1])
args = expr.args[1].args[2:end]

arglist = []
typeargs = :(())
handler = :(dlsym($(esc(ncurses)).libmenu, $(esc(function_name)) ))
out = :(ccall($(handler), $(esc(return_type)), $(esc(typeargs))))

for arg in args
!(arg.head == :(::)) && error("All arguments must have a type.")
push!(out.args, :($(esc(arg.args[1]))))
push!(typeargs.args, arg.args[2])
end

return out
end

############################################################################################
# `libform` Functions #
############################################################################################
Expand Down Expand Up @@ -169,7 +205,7 @@ for (f, r, v, j, c) in
For more information, see `libmenu` documentation.
"""
$f($(argsj...)) = @ccall $f($(argsc...))::$r
$f($(argsj...)) = @_ccallm $f($(argsc...))::$r
_precompile_func($f, $argst)
end
end
38 changes: 37 additions & 1 deletion src/submodules/NCurses/ncurses_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@
#
############################################################################################

############################################################################################
# Private Macros #
############################################################################################

"""
@_ccalln expr
Make a `ccall` to a `libncurses` function. The usage should be:
@_ccalln function(arg1::Type1, arg2::Type2, ...) -> TypeReturn
It uses the global constant structure `ncurses` to call the function. Hence, it must be
initialized.
"""
macro _ccalln(expr)
!(expr.head == :(::) && expr.args[1].head == :call) &&
error("Invalid use of @_ccall")

return_type = expr.args[2]
function_name = QuoteNode(expr.args[1].args[1])
args = expr.args[1].args[2:end]

arglist = []
typeargs = :(())
handler = :(dlsym($(esc(ncurses)).libncurses, $(esc(function_name))))
out = :(ccall( $(handler), $(esc(return_type)), $(esc(typeargs))))

for arg in args
!(arg.head == :(::)) && error("All arguments must have a type.")
push!(out.args, :($(esc(arg.args[1]))))
push!(typeargs.args, arg.args[2])
end

return out
end

############################################################################################
# NCurses Functions #
############################################################################################
Expand Down Expand Up @@ -634,7 +670,7 @@ for (f, r, v, j, c) in
For more information, see `libncurses` documentation.
"""
$f($(argsj...)) = @ccall $f($(argsc...))::$r
$f($(argsj...)) = @_ccalln $f($(argsc...))::$r
_precompile_func($f, $argst)
end
end
Expand Down
38 changes: 37 additions & 1 deletion src/submodules/NCurses/panel/panel_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@
#
############################################################################################

############################################################################################
# Private Macros #
############################################################################################

"""
@_ccallm expr
Make a `ccall` to a `libpanel` function. The usage should be:
@_ccallm function(arg1::Type1, arg2::Type2, ...) -> TypeReturn
It uses the global constant structure `ncurses` to call the function. Hence, it must be
initialized.
"""
macro _ccallp(expr)
!( expr.head == :(::) && expr.args[1].head == :call ) &&
error("Invalid use of @_ccall")

return_type = expr.args[2]
function_name = QuoteNode(expr.args[1].args[1])
args = expr.args[1].args[2:end]

arglist = []
typeargs = :(())
handler = :(dlsym($(esc(ncurses)).libpanel, $(esc(function_name))))
out = :(ccall($(handler), $(esc(return_type)), $(esc(typeargs))))

for arg in args
!(arg.head == :(::)) && error("All arguments must have a type.")
push!(out.args, :($(esc(arg.args[1]))))
push!(typeargs.args, arg.args[2])
end

return out
end

############################################################################################
# `libpanel` functions #
############################################################################################
Expand Down Expand Up @@ -113,7 +149,7 @@ for (f, r, v, j, c) in
For more information, see `libmenu` documentation.
"""
$f($(argsj...)) = @ccall $f($(argsc...))::$r
$f($(argsj...)) = @_ccallp $f($(argsc...))::$r
_precompile_func($f, $argst)
end
end

0 comments on commit 10a829c

Please sign in to comment.