Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make it Julia 0.5 compatible #10

Merged
merged 1 commit into from
Nov 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ env:
- ARCH="i686"
- ARCH="x86_64"
julia:
- release
- 0.5
- 0.6
- nightly
matrix:
exclude:
Expand Down
4 changes: 2 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.4-
BinDeps
julia 0.5
BinDeps
6 changes: 3 additions & 3 deletions src/common.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
typealias Cmode_t Cushort
const Cmode_t = Cushort

"Generic structure used for passing keys and data in and out of the database."
type MDBValue
Expand Down Expand Up @@ -89,7 +89,7 @@ function version()
minor = Cint[0]
patch = Cint[0]
ver_str = ccall( (:mdb_version, liblmdb), Cstring, (Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), major, minor, patch)
return VersionNumber(major[1],minor[1],patch[1]), bytestring(ver_str)
return VersionNumber(major[1],minor[1],patch[1]), unsafe_string(ver_str)
end

"""Return a string describing a given error code
Expand All @@ -99,7 +99,7 @@ Function returns description of the error as a string. It accepts following argu
"""
function errormsg(err::Cint)
errstr = ccall( (:mdb_strerror, liblmdb), Cstring, (Cint,), err)
return bytestring(errstr)
return unsafe_string(errstr)
end

"""LMDB exception type"""
Expand Down
4 changes: 2 additions & 2 deletions src/cur.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function get{T}(cur::Cursor, key, ::Type{T}, op::CursorOps=FIRST)
# Convert to proper type
mdb_val = mdb_val_ref[]
if T <: AbstractString
return bytestring(convert(Ptr{UInt8}, mdb_val.data), mdb_val.size)
return unsafe_string(convert(Ptr{UInt8}, mdb_val.data), mdb_val.size)
else
nvals = floor(Int, mdb_val.size/sizeof(T))
value = pointer_to_array(convert(Ptr{T}, mdb_val.data), nvals)
Expand Down Expand Up @@ -118,4 +118,4 @@ function count(cur::Cursor)
(Ptr{Void}, Csize_t), cur.handle, countp)
(ret != 0) && throw(LMDBError(ret))
return Int(countp[1])
end
end
6 changes: 3 additions & 3 deletions src/dbi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ isopen(dbi::DBI) = dbi.handle != zero(Cuint)

"Open a database in the environment"
function open(txn::Transaction, dbname::String = ""; flags::Cuint=zero(Cuint))
cdbname = length(dbname) > 0 ? bytestring(dbname) : convert(Cstring, Ptr{UInt8}(C_NULL))
cdbname = length(dbname) > 0 ? dbname : convert(Cstring, Ptr{UInt8}(C_NULL))
handle = Cuint[0]
ret = ccall((:mdb_dbi_open, liblmdb), Cint,
(Ptr{Void}, Cstring, Cuint, Ptr{Cuint}),
Expand Down Expand Up @@ -107,10 +107,10 @@ function get{T}(txn::Transaction, dbi::DBI, key, ::Type{T})
# Convert to proper type
mdb_val = mdb_val_ref[]
if T <: AbstractString
return bytestring(convert(Ptr{UInt8}, mdb_val.data), mdb_val.size)
return unsafe_string(convert(Ptr{UInt8}, mdb_val.data), mdb_val.size)
else
nvals = floor(Int, mdb_val.size/sizeof(T))
value = pointer_to_array(convert(Ptr{T}, mdb_val.data), nvals)
return length(value) == 1 ? value[1] : value
end
end
end
5 changes: 2 additions & 3 deletions src/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ end
"""
function open(env::Environment, path::String; flags::Cuint=zero(Cuint), mode::Cmode_t = 0o755)
env.path = path
cpath = bytestring(path)
ret = ccall((:mdb_env_open, liblmdb), Cint,
(Ptr{Void}, Cstring, Cuint, Cmode_t),
env.handle, cpath, flags, mode)
env.handle, path, flags, mode)
(ret != 0) && throw(LMDBError(ret))
return ret::Cint
end
Expand Down Expand Up @@ -176,4 +175,4 @@ function show(io::IO, env::Environment)
print(io,"\nMax reader slots in the environment: $(ei.maxreaders)")
print(io,"\nMax reader slots used in the environment: $(ei.numreaders)")
end
end
end
8 changes: 4 additions & 4 deletions test/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ module LMDB_Common
val = "abcd"
mdb_val_ref = Ref(MDBValue(val))
mdb_val = mdb_val_ref[]
@test val == bytestring(convert(Ptr{UInt8}, mdb_val.data), mdb_val.size)
@test val == unsafe_string(convert(Ptr{UInt8}, mdb_val.data), mdb_val.size)

val = [1233]
T = eltype(val)
val_size = sizeof(val)
mdb_val = MDBValue(val[1])
@test val_size == mdb_val.size
nvals = floor(Int, mdb_val.size/sizeof(T))
value = pointer_to_array(convert(Ptr{T}, mdb_val.data), nvals)
value = unsafe_wrap(Array, convert(Ptr{T}, mdb_val.data), nvals)
@test val == value

val = [0x0003, 0xff45]
Expand All @@ -31,6 +31,6 @@ module LMDB_Common
mdb_val = MDBValue(val)
@test val_size == mdb_val.size
nvals = floor(Int, mdb_val.size/sizeof(T))
value = pointer_to_array(convert(Ptr{T}, mdb_val.data), nvals)
value = unsafe_wrap(Array, convert(Ptr{T}, mdb_val.data), nvals)
@test val == value
end
end