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

Commit

Permalink
drop julia 0.4 + fix errors and deprecations in 0.6 (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloLucibello authored and timholy committed Mar 7, 2017
1 parent 5f9f3b2 commit 6298bd4
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 223 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ os:
- linux
- osx
julia:
- 0.4
- 0.5
- nightly
notifications:
Expand Down
4 changes: 2 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
julia 0.4
julia 0.5
Cairo 0.2.2
Graphics 0.1
BinDeps
@windows WinRPM
@osx Homebrew
Compat 0.9.5
Compat 0.18
BaseTestNext
6 changes: 1 addition & 5 deletions deps/ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ if isfile(_depspath)
include(_depspath)
end

if VERSION >= v"0.5.0-dev+4257"
const KERNEL = Base.Sys.KERNEL
else
const KERNEL = Base.OS_NAME
end
const KERNEL = Base.Sys.KERNEL

if gtk_version == 3
if KERNEL == :Windows
Expand Down
6 changes: 1 addition & 5 deletions deps/ext_glib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ if isfile(_depspath)
include(_depspath)
end

if VERSION >= v"0.5.0-dev+4257"
const KERNEL = Base.Sys.KERNEL
else
const KERNEL = Base.OS_NAME
end
const KERNEL = Base.Sys.KERNEL

if KERNEL == :Windows
@assign_if_unassigned libgobject = "libgobject-2.0-0"
Expand Down
2 changes: 1 addition & 1 deletion gen/gtk_auto_gen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let gtk_version = Gtk.gtk_version
println(cache)
Base.println(cache,"end")
end
const ser_version = VERSION >= v"0.4-" ? Base.Serializer.ser_version : Base.ser_version
const ser_version = Base.Serializer.ser_version
open(joinpath(splitdir(@__FILE__)[1], "$(cachepath)_julia_ser$(ser_version)"), "w") do cache
serialize(cache, gbox)
serialize(cache, gconsts)
Expand Down
26 changes: 4 additions & 22 deletions src/GLib/GLib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ module GLib

using Compat

if VERSION < v"0.5.0-dev+3876"
include("../compat_string.jl")
end

if false
function include(x)
println("including $x")
Expand Down Expand Up @@ -46,11 +42,7 @@ module CompatGLib
TupleType(types...) = Tuple{types...}
const unsafe_convert = Base.unsafe_convert
import Base.Libdl: dlopen, dlsym_e
if VERSION >= v"0.5.0-dev+4257"
using Base.Sys.WORD_SIZE
else
using Base.WORD_SIZE
end
using Base.Sys.WORD_SIZE
if VERSION >= v"0.6.0-dev" && !isdefined(Base, :xor)
export xor
const xor = $
Expand All @@ -62,21 +54,11 @@ importall .CompatGLib
using .CompatGLib.WORD_SIZE

# local function, handles Symbol and makes UTF8-strings easier
typealias AbstractStringLike Union{AbstractString, Symbol}
const AbstractStringLike = Union{AbstractString, Symbol}
bytestring(s) = String(s)
bytestring(s::Symbol) = s
if VERSION >= v"0.5.0-dev+4612"
bytestring(s::Ptr{UInt8}, own::Bool) = unsafe_wrap(String, s, ccall(:strlen, Csize_t, (Ptr{UInt8},), s), own)
else
bytestring(s::Ptr{UInt8}, own::Bool) = String(pointer_to_array(s, Int(ccall(:strlen, Csize_t, (Ptr{UInt8},), s)), own))
end
if VERSION >= v"0.5.0-dev+4612"
bytestring(s::Ptr{UInt8}) = unsafe_string(s)
elseif VERSION >= v"0.5.0-dev+4200"
bytestring(s::Ptr{UInt8}) = String(s)
else
bytestring(s::Ptr{UInt8}) = Base.bytestring(s)
end
bytestring(s::Ptr{UInt8}) = unsafe_string(s)
# bytestring(s::Ptr{UInt8}, own::Bool=false) = unsafe_string(s)

g_malloc(s::Integer) = ccall((:g_malloc, libglib), Ptr{Void}, (Csize_t,), s)
g_free(p::Ptr) = ccall((:g_free, libglib), Void, (Ptr{Void},), p)
Expand Down
9 changes: 5 additions & 4 deletions src/GLib/MutableTypes.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
module MutableTypes
using Compat
export mutable, Mutable, deref

abstract Mutable{T}
@compat abstract type Mutable{T} end
type MutableX{T} <: Mutable{T}
x::T
MutableX() = new()
MutableX(x) = new(x)
(::Type{MutableX{T}}){T}() = new{T}()
(::Type{MutableX{T}}){T}(x) = new{T}(x)
end
immutable MutableA{T, N} <: Mutable{T}
x::Array{T, N}
i::Int
end
typealias MutableV{T} MutableA{T, 1}
@compat const MutableV{T} = MutableA{T, 1}

mutable{T}(x::T) = MutableX{T}(x)
mutable(x::Mutable) = x
Expand Down
11 changes: 6 additions & 5 deletions src/GLib/glist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### an _LList is expected to have a data::Ptr{T} and next::Ptr{_LList{T}} element
### they are expected to be allocated and freed by GLib (e.g. with malloc/free)
abstract _LList{T}
@compat abstract type _LList{T} end

immutable _GSList{T} <: _LList{T}
data::Ptr{T}
Expand All @@ -21,19 +21,20 @@ eltype{L <: _LList}(::Type{L}) = eltype(supertype(L))
type GList{L <: _LList, T} <: AbstractVector{T}
handle::Ptr{L}
transfer_full::Bool
function GList(handle, transfer_full::Bool) # if transfer_full == true, then also free the elements when finalizing the list
function (::Type{GList{L,T}}){L<:_LList,T}(handle, transfer_full::Bool)
# if transfer_full == true, then also free the elements when finalizing the list
# this function assumes the caller will take care of holding a pointer to the returned object
# until it wants to be garbage collected
@assert T == eltype(L)
l = new(handle, transfer_full)
l = new{L,T}(handle, transfer_full)
finalizer(l, empty!)
return l
end
end
GList{T}(list::Type{T}) = GList(convert(Ptr{_GList{T}}, C_NULL), true)
GList{L <: _LList}(list::Ptr{L}, transfer_full::Bool = false) = GList{L, eltype(L)}(list, transfer_full)

typealias LList{L <: _LList} Union{Ptr{L}, GList{L}}
@compat const LList{L <: _LList} = Union{Ptr{L}, GList{L}}
eltype{L <: _LList}(::LList{L}) = eltype(L)

_listdatatype{T}(::Type{_LList{T}}) = T
Expand All @@ -51,7 +52,7 @@ start{L}(list::LList{L}) = unsafe_convert(Ptr{L}, list)
next{T}(::LList, s::Ptr{T}) = (deref(s), unsafe_load(s).next) # return (value, state)
done(::LList, s::Ptr) = (s == C_NULL)

typealias LListPair{L} Tuple{LList, Ptr{L}}
@compat const LListPair{L} = Tuple{LList, Ptr{L}}
function glist_iter{L <: _LList}(list::Ptr{L}, transfer_full::Bool = false)
# this function pairs every list element with the list head, to forestall garbage collection
return (GList(list, transfer_full), list)
Expand Down
95 changes: 30 additions & 65 deletions src/GLib/gtype.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
abstract GObject
abstract GInterface <: GObject
abstract GBoxed
@compat abstract type GObject end
@compat abstract type GInterface <: GObject end
@compat abstract type GBoxed end
type GBoxedUnkown <: GBoxed
handle::Ptr{GBoxed}
end

typealias GEnum Int32
typealias GType Csize_t
const GEnum = Int32
const GType = Csize_t

immutable GParamSpec
g_type_instance::Ptr{Void}
name::Ptr{UInt8}
Expand Down Expand Up @@ -63,7 +64,7 @@ G_OBJECT_CLASS_TYPE(w) = G_TYPE_FROM_CLASS(G_OBJECT_GET_CLASS(w))
g_isa(gtyp::GType, is_a_type::GType) = ccall((:g_type_is_a, libgobject), Cint, (GType, GType), gtyp, is_a_type) != 0
g_isa(gtyp, is_a_type) = g_isa(g_type(gtyp), g_type(is_a_type))
g_type_parent(child::GType) = ccall((:g_type_parent, libgobject), GType, (GType,), child)
g_type_name(g_type::GType) = Symbol(bytestring(ccall((:g_type_name, libgobject), Ptr{UInt8}, (GType,), g_type), false))
g_type_name(g_type::GType) = Symbol(bytestring(ccall((:g_type_name, libgobject), Ptr{UInt8}, (GType,), g_type)))

g_type_test_flags(g_type::GType, flag) = ccall((:g_type_test_flags, libgobject), Bool, (GType, GEnum), g_type, flag)
const G_TYPE_FLAG_CLASSED = 1 << 0
Expand Down Expand Up @@ -168,7 +169,7 @@ function get_itype_decl(iname::Symbol, gtyp::GType)
const $(esc(iname)) = gtype_abstracts[$(QuoteNode(iname))]
else
$piface_decl
abstract $(esc(iname)) <: $(esc(piname))
@compat abstract type $(esc(iname)) <: $(esc(piname)) end
gtype_abstracts[$(QuoteNode(iname))] = $(esc(iname))
end
nothing
Expand Down Expand Up @@ -337,59 +338,31 @@ end

### Garbage collection [prevention]
const gc_preserve = ObjectIdDict() # reference counted closures
if VERSION >= v"0.4-"
function gc_ref(x::ANY)
global gc_preserve
local ref::Ref{Any}, cnt::Int
if x in keys(gc_preserve)
ref, cnt = gc_preserve[x]::Tuple{Ref{Any}, Int}
else
ref = Ref{Any}(x)
cnt = 0
end
gc_preserve[x] = (ref, cnt + 1)
return unsafe_load(convert(Ptr{Ptr{Void}}, unsafe_convert(Ptr{Any}, ref)))
end
function gc_unref(x::ANY)
global gc_preserve
function gc_ref(x::ANY)
global gc_preserve
local ref::Ref{Any}, cnt::Int
if x in keys(gc_preserve)
ref, cnt = gc_preserve[x]::Tuple{Ref{Any}, Int}
@assert cnt > 0
if cnt == 1
delete!(gc_preserve, x)
else
gc_preserve[x] = (ref, cnt - 1)
end
nothing
end
if VERSION >= v"0.5-"
gc_ref_closure{T}(x::T) = (gc_ref(x), cfunction(_gc_unref, Void, (Any, Ptr{Void})))
_gc_unref(x::ANY, ::Ptr{Void}) = gc_unref(x)
else
gc_ref_closure{T}(x::T) = (gc_ref(x), cfunction(_gc_unref, Void, (Ref{T}, Ptr{Void})))
_gc_unref(x::Any, ::Ptr{Void}) = gc_unref(x)
ref = Ref{Any}(x)
cnt = 0
end
else
function gc_ref(x::ANY)
global gc_preserve
isbits(x) && error("can't gc-preserve an isbits object")
gc_preserve[x] = (get(gc_preserve, x, 0)::Int) + 1
return pointer_from_objref(x)
end
function gc_unref(x::ANY)
global gc_preserve
@assert !isbits(x)
cnt = gc_preserve[x]::Int
@assert cnt > 0
if cnt == 1
delete!(gc_preserve, x)
else
gc_preserve[x] = cnt - 1
end
nothing
gc_preserve[x] = (ref, cnt + 1)
return unsafe_load(convert(Ptr{Ptr{Void}}, unsafe_convert(Ptr{Any}, ref)))
end
function gc_unref(x::ANY)
global gc_preserve
ref, cnt = gc_preserve[x]::Tuple{Ref{Any}, Int}
@assert cnt > 0
if cnt == 1
delete!(gc_preserve, x)
else
gc_preserve[x] = (ref, cnt - 1)
end
gc_ref_closure{T}(x::T) = (gc_ref(x), cfunction(_gc_unref, Void, (T, Ptr{Void})))
_gc_unref(x::Any, ::Ptr{Void}) = gc_unref(x)
nothing
end
gc_ref_closure{T}(x::T) = (gc_ref(x), cfunction(_gc_unref, Void, (Any, Ptr{Void})))
_gc_unref(x::ANY, ::Ptr{Void}) = gc_unref(x)

# generally, you shouldn't be calling gc_ref(::Ptr{GObject})
gc_ref(x::Ptr{GObject}) = ccall((:g_object_ref, libgobject), Void, (Ptr{GObject},), x)
Expand Down Expand Up @@ -445,11 +418,7 @@ function gobject_ref{T <: GObject}(x::T)
strong = get(gc_preserve_glib, x, nothing)
if strong === nothing
# we haven't seen this before, setup the metadata
if VERSION >= v"0.4-"
deref = cfunction(gc_unref, Void, (Ref{T},))
else
deref = cfunction(gc_unref, Void, (T,))
end
deref = cfunction(gc_unref, Void, (Ref{T},))
ccall((:g_object_set_qdata_full, libgobject), Void,
(Ptr{GObject}, UInt32, Any, Ptr{Void}), x, jlref_quark::UInt32, x,
deref) # add a circular reference to the Julia object in the GObject
Expand Down Expand Up @@ -495,11 +464,7 @@ function gc_unref(x::GObject)
if ref != C_NULL && x !== unsafe_pointer_to_objref(ref)
# We got called because we are no longer the default object for this handle, but we are still alive
warn("Duplicate Julia object creation detected for GObject")
if VERSION >= v"0.4-"
deref = cfunction(gc_unref_weak, Void, (Ref{typeof(x)},))
else
deref = cfunction(gc_unref_weak, Void, (typeof(x),))
end
deref = cfunction(gc_unref_weak, Void, (Ref{typeof(x)},))
ccall((:g_object_weak_ref, libgobject), Void, (Ptr{GObject}, Ptr{Void}, Any), x, deref, x)
else
ccall((:g_object_steal_qdata, libgobject), Any, (Ptr{GObject}, UInt32), x, jlref_quark::UInt32)
Expand Down
2 changes: 1 addition & 1 deletion src/GLib/gvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ immutable GValue
field3::UInt64
GValue() = new(0, 0, 0)
end
typealias GV Union{Mutable{GValue}, Ptr{GValue}}
@compat const GV = Union{Mutable{GValue}, Ptr{GValue}}
Base.zero(::Type{GValue}) = GValue()
function gvalue{T}(::Type{T})
v = mutable(GValue())
Expand Down
40 changes: 8 additions & 32 deletions src/GLib/signals.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
# id = VERSION >= v"0.4-"get, :event, Void, (ArgsT...)) do ptr, evt_args..., closure
# stuff
# end
if VERSION < v"0.5.0-dev"
function signal_connect{CT, RT}(cb::Function, w::GObject, sig::AbstractStringLike,
::Type{RT}, param_types::Tuple, after::Bool = false, user_data::CT = w)
if isgeneric(cb)
return signal_connect_generic(cb, w, sig, RT, param_types, after, user_data)
end
# oops, Julia doesn't support this natively yet -- fake it instead
return _signal_connect(cb, w, sig, after, true, param_types, user_data)
end
else
function signal_connect{CT, RT}(cb::Function, w::GObject, sig::AbstractStringLike,
::Type{RT}, param_types::Tuple, after::Bool = false, user_data::CT = w)
signal_connect_generic(cb, w, sig, RT, param_types, after, user_data)
end
function signal_connect{CT, RT}(cb::Function, w::GObject, sig::AbstractStringLike,
::Type{RT}, param_types::Tuple, after::Bool = false, user_data::CT = w)
signal_connect_generic(cb, w, sig, RT, param_types, after, user_data)
end

function signal_connect_generic{CT, RT}(cb::Function, w::GObject, sig::AbstractStringLike,
Expand Down Expand Up @@ -65,7 +54,7 @@ function GClosureMarshal(closuref::Ptr{Void}, return_value::Ptr{GValue}, n_param
closure_env = convert(Ptr{Any}, closuref + sizeof_gclosure)
cb = unsafe_load(closure_env, 1)
gtk_calling_convention = (0 != unsafe_load(convert(Ptr{Int}, closure_env), 2))
params = Array(Any, n_param_values)
params = Vector{Any}(n_param_values)
local retval = nothing
g_siginterruptible(cb) do
if gtk_calling_convention
Expand Down Expand Up @@ -115,11 +104,7 @@ function GClosureMarshal(closuref::Ptr{Void}, return_value::Ptr{GValue}, n_param
end

function blame(cb)
if VERSION > v"0.5.0-dev" || isgeneric(cb)
warn("Executing ", cb, ":")
else
warn("Executing ", Base.uncompressed_ast(cb.code).args[3].args[1]) # just show file/line
end
warn("Executing ", cb, ":")
end

# Signals API for the cb pointer
Expand Down Expand Up @@ -287,16 +272,9 @@ function new_gsource(source_funcs::_GSourceFuncs)
end

expiration = UInt64(0)
if VERSION < v"0.3-"
_isempty_workqueue() = isempty(Base.Workqueue) || (length(Base.Workqueue) == 1 && Base.Workqueue[1] === Base.Scheduler)
function uv_loop_alive(evt)
ccall(:uv_stop, Void, (Ptr{Void},), evt)
ccall(:uv_run, Cint, (Ptr{Void}, Cint), evt, 2) != 0
end
else
_isempty_workqueue() = isempty(Base.Workqueue)
uv_loop_alive(evt) = ccall(:uv_loop_alive, Cint, (Ptr{Void},), evt) != 0
end
_isempty_workqueue() = isempty(Base.Workqueue)
uv_loop_alive(evt) = ccall(:uv_loop_alive, Cint, (Ptr{Void},), evt) != 0

function uv_prepare(src::Ptr{Void}, timeout::Ptr{Cint})
global expiration, uv_pollfd
local tmout_ms::Cint
Expand All @@ -307,8 +285,6 @@ function uv_prepare(src::Ptr{Void}, timeout::Ptr{Cint})
tmout_ms = -1
elseif uv_pollfd.revents != 0
tmout_ms = 0
elseif is_windows() ? (VERSION < v"0.3-") : false # uv_backend_timeout broken on windows before Julia v0.3-rc2
tmout_ms = 10
else
ccall(:uv_update_time, Void, (Ptr{Void},), evt)
tmout_ms = ccall(:uv_backend_timeout, Cint, (Ptr{Void},), evt)
Expand Down
Loading

0 comments on commit 6298bd4

Please sign in to comment.