Skip to content

Use Gdbm_jll instead of BinaryProvider #54

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

Merged
merged 1 commit into from
May 8, 2023
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
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ uuid = "a7f2b756-c18b-4c7f-87da-faca9ac81b29"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Gdbm_jll = "54ca2031-c8dd-5cab-9ed4-295edde1660f"
Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Expand All @@ -13,10 +12,10 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
TikzPictures = "37f6aa50-8035-52d0-81c2-5a1d08754b2d"

[compat]
BinaryProvider = "0.5"
Gdbm_jll = "1.18.1"
Luxor = "1"
TikzPictures = "3"
julia = "0.7, 1"
julia = "1.3"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
46 changes: 0 additions & 46 deletions deps/build.jl

This file was deleted.

8 changes: 1 addition & 7 deletions src/ThinkJulia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ module ThinkJulia
using Luxor
using TikzPictures
using Plots

const depsjl_path = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
if !isfile(depsjl_path)
error("ThinkJulia not installed properly, run Pkg.build(\"ThinkJulia\"), restart Julia and try again")
end
include(depsjl_path)
using Gdbm_jll

function __init__()
# Always check your dependencies that live in `deps.jl`
check_deps()
global setcolor! = Core.eval(Base, :(x -> (y = have_color; global have_color = x; y)))
CAN_INLINE[] = Base.JLOptions().can_inline == 0 ? false : true
end
Expand Down
38 changes: 10 additions & 28 deletions src/code/chap14.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,71 +20,53 @@ const OPENFLAGS = Dict("r"=>0, "w"=>1, "c"=>2, "n"=>3)
const STOREFLAGS = Dict("r"=>1, "i"=>0)

function gdbm_open(name::String, flag::String="r")
GDBM = Libdl.dlopen_e(libgdbm)
gdbm_open = Libdl.dlsym_e(GDBM, :gdbm_open)
handle = ccall(gdbm_open, Ptr{Cvoid}, (Cstring, Int32, Int32, Int32, Ptr{Cvoid}), name, 0, OPENFLAGS[flag], 420, C_NULL)
handle = ccall((:gdbm_open, libgdbm), Ptr{Cvoid}, (Cstring, Int32, Int32, Int32, Ptr{Cvoid}), name, 0, OPENFLAGS[flag], 420, C_NULL)
handle == C_NULL && error("File could not be opened!")
handle
end

function gdbm_close(handle::Ptr{Cvoid})
GDBM = Libdl.dlopen_e(libgdbm)
gdbm_close = Libdl.dlsym_e(GDBM, :gdbm_close)
ccall(gdbm_close, Cvoid, (Ptr{Cvoid},), handle)
ccall((:gdbm_close, libgdbm), Cvoid, (Ptr{Cvoid},), handle)
end

function gdbm_store(handle::Ptr{Cvoid}, key::Datum, value::Datum, flag::String="r")
GDBM = Libdl.dlopen_e(libgdbm)
gdbm_store = Libdl.dlsym_e(GDBM, :gdbm_store)
ret = ccall(gdbm_store, Int32, (Ptr{Cvoid}, Datum, Datum, Int32), handle, key, value, STOREFLAGS[flag])
ret = ccall((:gdbm_store, libgdbm), Int32, (Ptr{Cvoid}, Datum, Datum, Int32), handle, key, value, STOREFLAGS[flag])
ret == -1 && error("Database is not writable or key/value is not a valid string.")
ret == 1 && error("Key is already in database.")
nothing
end

function gdbm_fetch(handle::Ptr{Cvoid}, key::Datum)
GDBM = Libdl.dlopen_e(libgdbm)
gdbm_fetch = Libdl.dlsym_e(GDBM, :gdbm_fetch)
datum = ccall(gdbm_fetch, Datum, (Ptr{Cvoid}, Datum), handle, key)
datum = ccall((:gdbm_fetch, libgdbm), Datum, (Ptr{Cvoid}, Datum), handle, key)
datum.dptr == C_NULL && throw(KeyError(key))
datum
end

function gdbm_exists(handle::Ptr{Cvoid}, key::Datum)
GDBM = Libdl.dlopen_e(libgdbm)
gdbm_exists = Libdl.dlsym_e(GDBM, :gdbm_exists)
ret = ccall(gdbm_exists, Int32, (Ptr{Cvoid}, Datum), handle, key)
ret = ccall((:gdbm_exists, libgdbm)), Int32, (Ptr{Cvoid}, Datum), handle, key)
ret == 0 && return false
true
end

function gdbm_count(handle::Ptr{Cvoid})
count = Ref(UInt(0))
GDBM = Libdl.dlopen_e(libgdbm)
gdbm_count = Libdl.dlsym_e(GDBM, :gdbm_count)
ret = ccall(gdbm_count, Int32, (Ptr{Cvoid}, Ref{UInt}), handle, count)
ret = ccall((:gdbm_count, libgdbm), Int32, (Ptr{Cvoid}, Ref{UInt}), handle, count)
ret == -1 && error("Error reading database.")
Int(count[])
end

function gdbm_delete(handle::Ptr{Cvoid}, key::Datum)
GDBM = Libdl.dlopen_e(libgdbm)
gdbm_delete = Libdl.dlsym_e(GDBM, :gdbm_delete)
ret = ccall(gdbm_delete, Int32, (Ptr{Cvoid}, Datum), handle, key)
ret = ccall((:gdbm_delete, libgdbm), Int32, (Ptr{Cvoid}, Datum), handle, key)
ret ≠ 0 && error("Database is not writable or key not found.")
nothing
end

function gdbm_firstkey(handle::Ptr{Cvoid})
GDBM = Libdl.dlopen_e(libgdbm)
gdbm_firstkey = Libdl.dlsym_e(GDBM, :gdbm_firstkey)
ccall(gdbm_firstkey, Datum, (Ptr{Cvoid}, ), handle)
ccall((:gdbm_firstkey, libgdbm), Datum, (Ptr{Cvoid}, ), handle)
end

function gdbm_nextkey(handle::Ptr{Cvoid}, prev::Datum)
GDBM = Libdl.dlopen_e(libgdbm)
gdbm_nextkey = Libdl.dlsym_e(GDBM, :gdbm_nextkey)
ccall(gdbm_nextkey, Datum, (Ptr{Cvoid}, Datum), handle, prev)
ccall((:gdbm_nextkey, libgdbm), Datum, (Ptr{Cvoid}, Datum), handle, prev)
end

function Base.getindex(dbm::DBM, key::Union{String,Array{UInt8,1}})
Expand Down Expand Up @@ -200,4 +182,4 @@ function Base.in(pair::Union{Pair{String,String},Pair{String,Array{UInt8,1}},Pai
value = unsafe_string(vdatum.dptr, vdatum.dsize)
Libc.free(vdatum.dptr)
value == pair.second
end
end