@@ -38,7 +38,7 @@ const fundamental_types = (
38
38
# (:GVariant, Ptr{GVariant}, GVariant, :variant),
39
39
)
40
40
# NOTE: in general do not cache ids, except for the fundamental values
41
- g_type_from_name (name:: Symbol ) = ccall ((:g_type_from_name ,libgobject),Int ,(Ptr{Uint8},),name)
41
+ g_type_from_name (name:: Symbol ) = ccall ((:g_type_from_name ,libgobject),GType ,(Ptr{Uint8},),name)
42
42
# these constants are used elsewhere
43
43
const gvoid_id = g_type_from_name (:void )
44
44
const gboxed_id = g_type_from_name (:GBoxed )
@@ -62,6 +62,7 @@ type GObjectAny <: GObjectI
62
62
handle:: Ptr{GObject}
63
63
GObjectAny (handle:: Ptr{GObject} ) = (handle != C_NULL ? gc_ref (new (handle)) : error (" Cannot construct $gname with a NULL pointer" ))
64
64
end
65
+ g_type (obj:: GObjectI ) = g_type (typeof (obj))
65
66
g_type (:: Type{GObjectI} ) = gobject_id
66
67
g_type (:: Type{GObject} ) = gobject_id
67
68
g_type (:: Type{GObjectAny} ) = gobject_id
@@ -77,34 +78,43 @@ function g_type(name::Symbol, lib, symname::Symbol)
77
78
return g_type (gtype_wrappers[name])
78
79
end
79
80
if ! isa (lib,String)
80
- lib = eval (current_module (),lib)
81
+ lib = eval (current_module (), lib)
81
82
end
82
83
libptr = dlopen (lib)
83
84
fnptr = dlsym (libptr, string (symname," _get_type" ))
84
85
typ = ccall (fnptr, GType, ())
85
86
dlclose (libptr)
86
87
typ
87
88
end
89
+ g_type (name:: Symbol , lib, symname:: Expr ) = eval (current_module (), symname)
88
90
89
91
function get_iface_decl (name:: Symbol , iname:: Symbol , gtyp:: GType )
90
- if name in keys (gtype_ifaces )
92
+ if isdefined ( current_module (), iname )
91
93
return nothing
92
94
end
95
+ if name === :GObject
96
+ return :( const $ (esc (iname)) = gtype_ifaces[:GObject ] )
97
+ end
93
98
parent = g_type_parent (gtyp)
94
99
@assert parent != 0
95
100
pname = g_type_name (parent)
96
101
piname = symbol (string (pname,' I' ))
97
102
piface_decl = get_iface_decl (pname, piname, parent)
98
103
quote
99
- $ piface_decl
100
- abstract $ (esc (iname)) <: $ (esc (piname))
101
- gtype_ifaces[$ (Meta. quot (name))] = $ (esc (iname))
104
+ if $ (Meta. quot (iname)) in keys (gtype_ifaces)
105
+ const $ (esc (iname)) = gtype_ifaces[$ (Meta. quot (name))]
106
+ else
107
+ $ piface_decl
108
+ abstract $ (esc (iname)) <: $ (esc (piname))
109
+ gtype_ifaces[$ (Meta. quot (name))] = $ (esc (iname))
110
+ end
102
111
end
103
112
end
104
113
114
+ get_gtype_decl (name:: Symbol , lib, symname:: Expr ) = esc (symname)
105
115
function get_gtype_decl (name:: Symbol , lib, symname:: Symbol )
106
116
quote
107
- GLib. g_type (:: Type{$(esc(name))} ) = ccall (($ (symbol (string (symname," _get_type" ))), $ (esc (lib))), GType, ())
117
+ GLib. g_type (:: Type{$(esc(name))} ) = ccall (($ (Meta . quot ( symbol (string (symname," _get_type" ) ))), $ (esc (lib))), GType, ())
108
118
end
109
119
end
110
120
@@ -116,12 +126,17 @@ macro Gtype(name,lib,symname)
116
126
end
117
127
iname = symbol (string (name,' I' ))
118
128
quote
119
- $ (get_iface_decl (name, iname, gtyp))
120
- type $ (esc (name)) <: $ (esc (iname))
121
- handle:: Ptr{GObjectI}
122
- $ (esc (name))(handle:: Ptr{GObjectI} ) = (handle != C_NULL ? gc_ref (new (handle)) : error ($ (" Cannot construct $name with a NULL pointer" )))
129
+ if $ (Meta. quot (name)) in keys (gtype_wrappers)
130
+ const $ (esc (iname)) = gtype_ifaces[$ (Meta. quot (name))]
131
+ const $ (esc (name)) = gtype_wrappers[$ (Meta. quot (name))]
132
+ else
133
+ $ (get_iface_decl (name, iname, gtyp))
134
+ type $ (esc (name)) <: $ (esc (iname))
135
+ handle:: Ptr{GObjectI}
136
+ $ (esc (name))(handle:: Ptr{GObjectI} ) = (handle != C_NULL ? gc_ref (new (handle)) : error ($ (" Cannot construct $name with a NULL pointer" )))
137
+ end
138
+ gtype_wrappers[$ (Meta. quot (name))] = $ (esc (name))
123
139
end
124
- gtype_wrappers[$ (Meta. quot (name))] = $ (esc (name))
125
140
$ (get_gtype_decl (name, lib, symname))
126
141
end
127
142
end
@@ -143,8 +158,8 @@ macro quark_str(q)
143
158
end
144
159
const jlref_quark = quark " julia_ref"
145
160
146
- # All GtkWidgets are expected to have a 'handle' field
147
- # of type Ptr{GObjectI} corresponding to the Gtk object
161
+ # All GObjects are expected to have a 'handle' field
162
+ # of type Ptr{GObjectI} corresponding to the GLib object
148
163
convert (:: Type{Ptr{GObjectI}} ,w:: GObjectI ) = w. handle
149
164
convert {T<:GObjectI} (:: Type{T} ,w:: Ptr{T} ) = convert (T,convert (Ptr{GObjectI},w))
150
165
eltype {T<:GObjectI} (:: GSList{T} ) = T
@@ -237,16 +252,16 @@ end
237
252
238
253
function gc_unref_weak (x:: GObjectI )
239
254
# this strongly destroys and invalidates the object
240
- # it is intended to be called by Gtk , not in user code function
241
- # note: this may be called multiple times by Gtk
255
+ # it is intended to be called by GLib , not in user code function
256
+ # note: this may be called multiple times by GLib
242
257
x. handle = C_NULL
243
258
global gc_preserve_gtk
244
259
delete! (gc_preserve_gtk, x)
245
260
nothing
246
261
end
247
262
function gc_unref (x:: GObjectI )
248
263
# this strongly destroys and invalidates the object
249
- # it is intended to be called by Gtk , not in user code function
264
+ # it is intended to be called by GLib , not in user code function
250
265
ref = ccall ((:g_object_get_qdata ,libgobject),Ptr{Void},(Ptr{GObjectI},Uint32),x,jlref_quark)
251
266
if ref != C_NULL && x != = unsafe_pointer_to_objref (ref)
252
267
# We got called because we are no longer the default object for this handle, but we are still alive
0 commit comments