Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Change curr_module to __module__ (or @__MODULE__ when appropria…
Browse files Browse the repository at this point in the history
…te) (#386)
  • Loading branch information
fcard authored and tknopp committed Sep 14, 2018
1 parent e820acc commit 4190f44
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 48 deletions.
11 changes: 4 additions & 7 deletions src/GLib/GLib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ import Base: convert, copy, show, size, length, getindex, setindex!, get,
using Libdl

export GInterface, GType, GObject, GBoxed, @Gtype, @Gabstract, @Giface
export GEnum, GError, GValue, gvalue, make_gvalue, g_type
export GEnum, GError, GValue, gvalue, make_gvalue, @make_gvalue, g_type
export GList, glist_iter, _GSList, _GList, gobject_ref, gobject_move_ref
export signal_connect, signal_emit, signal_handler_disconnect
export signal_handler_block, signal_handler_unblock
export set_gtk_property!, get_gtk_property
export GConnectFlags
export @sigatom, curr_module, cfunction_
export @sigatom, cfunction_

export curr_module

curr_module() = @__MODULE__

cfunction_(f, r, a::Tuple) = cfunction_(f, r, Tuple{a...})
@noinline function cfunction_(f, r, a)
Expand Down Expand Up @@ -63,8 +60,8 @@ macro g_type_delegate(eq)
@assert isa(eq, Expr) && eq.head == :(=) && length(eq.args) == 2
new = eq.args[1]
real = eq.args[2]
newleaf = esc(Symbol(string(new, curr_module().suffix)))
realleaf = esc(Symbol(string(real, curr_module().suffix)))
newleaf = esc(Symbol(string(new, __module__.suffix)))
realleaf = esc(Symbol(string(real, __module__.suffix)))
new = esc(new)
macroreal = QuoteNode(Symbol(string('@', real)))
quote
Expand Down
2 changes: 1 addition & 1 deletion src/GLib/gerror.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ struct GError
code::Cint
message::Ptr{UInt8}
end
make_gvalue(GError, Ptr{GError}, :boxed, (:g_error, :libgobject))
@make_gvalue(GError, Ptr{GError}, :boxed, (:g_error, :libgobject))
convert(::Type{GError}, err::Ptr{GError}) = GError(err)

GError(err::Ptr{GError}) = unsafe_load(err)
Expand Down
42 changes: 21 additions & 21 deletions src/GLib/gtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ gtype_wrappers[:GObject] = GObjectLeaf

let libs = Dict{AbstractString, Any}()
global get_fn_ptr
function get_fn_ptr(fnname, lib)
function get_fn_ptr(fnname, lib, cm)
if !isa(lib, AbstractString)
lib = Core.eval(curr_module(), lib)
lib = Core.eval(cm, lib)
end
libptr = get(libs, lib, C_NULL)::Ptr{Nothing}
if libptr == C_NULL
Expand All @@ -105,22 +105,22 @@ function get_fn_ptr(fnname, lib)
fnptr = dlsym_e(libptr, fnname)
end
end
function g_type(name::Symbol, lib, symname::Symbol)
function g_type(name::Symbol, lib, symname::Symbol, cm)
if name in keys(gtype_wrappers)
return g_type(gtype_wrappers[name])
return g_type(gtype_wrappers[name], cm)
end
fnptr = get_fn_ptr(string(symname, "_get_type"), lib)
fnptr = get_fn_ptr(string(symname, "_get_type"), lib, cm)
if fnptr != C_NULL
ccall(fnptr, GType, ())
else
convert(GType, 0)
end
end
g_type(name::Symbol, lib, symname::Expr) = Core.eval(curr_module(), symname)
g_type(name::Expr, lib::Expr, symname::Expr) = info( (name,lib,symname) )
g_type(name::Symbol, lib, symname::Expr, cm) = Core.eval(cm, symname)
g_type(name::Expr, lib::Expr, symname::Expr, cm) = info( (name,lib,symname) )

function get_interface_decl(iname::Symbol, gtyp::GType, gtyp_decl)
if isdefined(curr_module(), iname)
function get_interface_decl(iname::Symbol, gtyp::GType, gtyp_decl, cm)
if isdefined(cm, iname)
return nothing
end
parent = g_type_parent(gtyp)
Expand Down Expand Up @@ -148,8 +148,8 @@ function get_interface_decl(iname::Symbol, gtyp::GType, gtyp_decl)
end
end

function get_itype_decl(iname::Symbol, gtyp::GType)
if isdefined(curr_module(), iname)
function get_itype_decl(iname::Symbol, gtyp::GType, cm)
if isdefined(cm, iname)
return nothing
end
if iname === :GObject
Expand All @@ -165,7 +165,7 @@ function get_itype_decl(iname::Symbol, gtyp::GType)
parent = g_type_parent(gtyp)
@assert parent != 0
piname = g_type_name(parent)
piface_decl = get_itype_decl(piname, parent)
piface_decl = get_itype_decl(piname, parent, cm)
quote
if $(QuoteNode(iname)) in keys(gtype_abstracts)
$(esc(iname)) = gtype_abstracts[$(QuoteNode(iname))]
Expand All @@ -192,14 +192,14 @@ function get_gtype_decl(name::Symbol, lib, symname::Symbol)
end
end #let

function get_type_decl(name, iname, gtyp, gtype_decl)
function get_type_decl(name, iname, gtyp, gtype_decl, cm)
ename = esc(name)
einame = esc(iname)
quote
if $(QuoteNode(iname)) in keys(gtype_wrappers)
$einame = gtype_abstracts[$(QuoteNode(iname))]
else
$(get_itype_decl(iname, gtyp))
$(get_itype_decl(iname, gtyp, cm))
end
mutable struct $ename <: $einame
handle::Ptr{GObject}
Expand Down Expand Up @@ -231,11 +231,11 @@ function get_type_decl(name, iname, gtyp, gtype_decl)
end

macro Gtype_decl(name, gtyp, gtype_decl)
get_type_decl(name, Symbol(string(name, curr_module().suffix)), gtyp, gtype_decl)
get_type_decl(name, Symbol(string(name, __module__.suffix)), gtyp, gtype_decl, __module__)
end

macro Gtype(iname, lib, symname)
gtyp = g_type(iname, lib, symname)
gtyp = g_type(iname, lib, symname, __module__)
if gtyp == 0
return Expr(:call, :error, string("Could not find ", symname, " in ", lib,
". This is likely a issue with a missing Gtk.jl version check."))
Expand All @@ -245,8 +245,8 @@ macro Gtype(iname, lib, symname)
error("GType is currently only implemented for G_TYPE_FLAG_CLASSED")
end
gtype_decl = get_gtype_decl(iname, lib, symname)
name = Symbol(string(iname, curr_module().suffix))
get_type_decl(name, iname, gtyp, gtype_decl)
name = Symbol(string(iname, __module__.suffix))
get_type_decl(name, iname, gtyp, gtype_decl, __module__)
end

macro Gabstract(iname, lib, symname)
Expand All @@ -256,18 +256,18 @@ macro Gabstract(iname, lib, symname)
end
@assert iname === g_type_name(gtyp)
Expr(:block,
get_itype_decl(iname, gtyp),
get_itype_decl(iname, gtyp, __module__),
get_gtype_decl(iname, lib, symname))
end

macro Giface(iname, lib, symname)
gtyp = g_type(iname, lib, symname)
gtyp = g_type(iname, lib, symname, __module__)
if gtyp == 0
return Expr(:call, :error, string("Could not find ", symname, " in ", lib, ". This is likely a issue with a missing Gtk.jl version check."))
end
@assert iname === g_type_name(gtyp)
gtype_decl = get_gtype_decl(iname, lib, symname)
get_interface_decl(iname::Symbol, gtyp::GType, gtype_decl)
get_interface_decl(iname::Symbol, gtyp::GType, gtype_decl, __module__)
end


Expand Down
26 changes: 15 additions & 11 deletions src/GLib/gvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ getindex(v::GV, i::Int, ::Type{Nothing}) = nothing

let handled = Set()
global make_gvalue, getindex
function make_gvalue(pass_x, as_ctype, to_gtype, with_id, allow_reverse::Bool = true, fundamental::Bool = false)
function make_gvalue(pass_x, as_ctype, to_gtype, with_id, cm::Module, allow_reverse::Bool = true, fundamental::Bool = false)
with_id === :error && return
if isa(with_id, Tuple)
with_id = with_id::Tuple{Symbol, Any}
with_id = :(ccall($(Expr(:tuple, Meta.quot(Symbol(string(with_id[1], "_get_type"))), with_id[2])), GType, ()))
end
if pass_x !== Union{} && !(pass_x in handled)
Core.eval(curr_module(), quote
Core.eval(cm, quote
function Base.setindex!(v::GLib.GV, ::Type{T}) where T <: $pass_x
ccall((:g_value_init, GLib.libgobject), Nothing, (Ptr{GLib.GValue}, Csize_t), v, $with_id)
v
Expand All @@ -81,7 +81,7 @@ function make_gvalue(pass_x, as_ctype, to_gtype, with_id, allow_reverse::Bool =
end
if pass_x !== Union{} && !(pass_x in handled)
push!(handled, pass_x)
Core.eval(curr_module(), quote
Core.eval(cm, quote
function Base.getindex(v::GLib.GV, ::Type{T}) where T <: $pass_x
x = ccall(($(string("g_value_get_", to_gtype)), GLib.libgobject), $as_ctype, (Ptr{GLib.GValue},), v)
$( if to_gtype == :string
Expand All @@ -94,7 +94,7 @@ function make_gvalue(pass_x, as_ctype, to_gtype, with_id, allow_reverse::Bool =
end)
end
if fundamental || allow_reverse
fn = Core.eval(curr_module(), quote
fn = Core.eval(cm, quote
function(v::GLib.GV)
x = ccall(($(string("g_value_get_", to_gtype)), GLib.libgobject), $as_ctype, (Ptr{GLib.GValue},), v)
$(if to_gtype == :string; :(x = GLib.bytestring(x)) end)
Expand All @@ -105,24 +105,28 @@ function make_gvalue(pass_x, as_ctype, to_gtype, with_id, allow_reverse::Bool =
end)
end
end)
allow_reverse && pushfirst!(gvalue_types, [pass_x, Core.eval(curr_module(), :(() -> $with_id)), fn])
allow_reverse && pushfirst!(gvalue_types, [pass_x, Core.eval(cm, :(() -> $with_id)), fn])
return fn
end
return nothing
end
end #let

function make_gvalue_from_fundamental_type(i)
macro make_gvalue(pass_x, as_ctype, to_gtype, with_id, opt...)
esc(:(make_gvalue($pass_x, $as_ctype, $to_gtype, $with_id, $__module__, $(opt...))))
end

function make_gvalue_from_fundamental_type(i,cm)
(name, ctype, juliatype, g_value_fn) = fundamental_types[i]
return make_gvalue(juliatype, ctype, g_value_fn, fundamental_ids[i], false, true)
return make_gvalue(juliatype, ctype, g_value_fn, fundamental_ids[i], cm, false, true)
end

const gvalue_types = Any[]
const fundamental_fns = tuple(Function[ make_gvalue_from_fundamental_type(i) for
const fundamental_fns = tuple(Function[ make_gvalue_from_fundamental_type(i, @__MODULE__) for
i in 1:length(fundamental_types)]...)
make_gvalue(Symbol, Ptr{UInt8}, :static_string, :(g_type(AbstractString)), false)
make_gvalue(Type, GType, :gtype, (:g_gtype, :libgobject))
make_gvalue(Ptr{GBoxed}, Ptr{GBoxed}, :gboxed, :(g_type(GBoxed)), false)
@make_gvalue(Symbol, Ptr{UInt8}, :static_string, :(g_type(AbstractString)), false)
@make_gvalue(Type, GType, :gtype, (:g_gtype, :libgobject))
@make_gvalue(Ptr{GBoxed}, Ptr{GBoxed}, :gboxed, :(g_type(GBoxed)), false)

function getindex(gv::GV, ::Type{Any})
gtyp = unsafe_load(gv).g_type
Expand Down
3 changes: 0 additions & 3 deletions src/Gtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import .GLib:
signal_handler_block, signal_handler_unblock,
signal_emit, unsafe_convert

import .GLib: curr_module
curr_module() = @__MODULE__

import Base: convert, show, run, size, resize!, length, getindex, setindex!,
insert!, push!, append!, pushfirst!, pop!, splice!, delete!, deleteat!,
parent, isempty, empty!, first, last, in, popfirst!,
Expand Down
4 changes: 2 additions & 2 deletions src/gdk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct GdkRectangle <: GBoxed
height::Int32
GdkRectangle(x, y, w, h) = new(x, y, w, h)
end
make_gvalue(GdkRectangle, Ptr{GdkRectangle}, :boxed, (:gdk_rectangle, :libgdk))
@make_gvalue(GdkRectangle, Ptr{GdkRectangle}, :boxed, (:gdk_rectangle, :libgdk))
convert(::Type{GdkRectangle}, rect::Ptr{GdkRectangle}) = unsafe_load(rect)

struct GdkPoint
Expand Down Expand Up @@ -68,7 +68,7 @@ baremodule GdkKeySyms
end

abstract type GdkEvent <: GBoxed end
make_gvalue(GdkEvent, Ptr{GdkEvent}, :boxed, (:gdk_event, :libgdk))
@make_gvalue(GdkEvent, Ptr{GdkEvent}, :boxed, (:gdk_event, :libgdk))
function convert(::Type{GdkEvent}, evt::Ptr{GdkEvent})
e = unsafe_load(convert(Ptr{GdkEventAny}, evt))
if e.event_type == GdkEventType.KEY_PRESS ||
Expand Down
5 changes: 2 additions & 3 deletions src/gtktypes.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function _gtksubtype_constructors(name::Symbol)
cm = @__MODULE__ #curr_module()
function _gtksubtype_constructors(name::Symbol, cm::Module)
ename = Symbol(string(name, getfield(cm, :suffix)))
typ = getfield(cm, ename)
if GLib.g_isa(typ, GtkOrientable)
Expand All @@ -16,7 +15,7 @@ end
macro gtktype_custom_symname_and_lib(name, symname, lib)
esc(quote
@Gtype $name $lib $symname
_gtksubtype_constructors($(QuoteNode(name)))
_gtksubtype_constructors($(QuoteNode(name)), $__module__)
end)
end

Expand Down

0 comments on commit 4190f44

Please sign in to comment.