Skip to content

Commit 54ab444

Browse files
committed
Merge pull request #55 from JuliaLang/sjk/libc-libdl
Compat for Libc and Libdl
2 parents 3582cf1 + 8759ca5 commit 54ab444

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ Currently, the `@compat` macro supports the following syntaxes:
7272

7373
* `@inline` and `@noinline` have been added. On 0.3, these are "no-ops," meaning they don't actually do anything.
7474

75-
## Other syntax changes
75+
## Other changes
7676

7777
* `Dict(ks, vs)` is now `Dict(zip(ks, vs))` [#8521](https://github.com/JuliaLang/julia/pull/8521)
7878

79+
* Libc and dynamic library-related functions have been moved to the Libc and Libdl modules [#10328](https://github.com/JuliaLang/julia/pull/10328)
80+
7981
## Nullable type
8082
* [`Nullable` types](http://julia.readthedocs.org/en/latest/manual/types/?highlight=nullable#nullable-types-representing-missing-values) and their associated operations.
8183

src/Compat.jl

+24
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,28 @@ if VERSION < v"0.4.0-dev+656"
263263
include("nullable.jl")
264264
end
265265

266+
if VERSION < v"0.4.0-dev+3844"
267+
@eval module Libc
268+
const FILE = Base.CFILE
269+
const calloc = Base.c_calloc
270+
const free = Base.c_free
271+
const malloc = Base.c_malloc
272+
const realloc = Base.c_realloc
273+
using Base: munmap, systemsleep
274+
export FILE, MS_ASYNC, MS_INVALIDATE, MS_SYNC, TmStruct, calloc, errno,
275+
flush_cstdio, free, gethostname, getpid, malloc, mmap, msync,
276+
munmap, realloc, strerror, strftime, strptime, systemsleep,
277+
time
278+
end
279+
@eval module Libdl
280+
using Base.Sys: dlext, dllist, dlpath
281+
export DL_LOAD_PATH, RTLD_DEEPBIND, RTLD_FIRST, RTLD_GLOBAL, RTLD_LAZY,
282+
RTLD_LOCAL, RTLD_NODELETE, RTLD_NOLOAD, RTLD_NOW, dlclose, dlext,
283+
dllist, dlopen, dlopen_e, dlpath, dlsym, dlsym_e, find_library
284+
end
285+
export Libc, Libdl
286+
else
287+
import Base: Libc, Libdl
288+
end
289+
266290
end # module

test/runtests.jl

+8
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,11 @@ end
159159
@test parse(Int16, "1101", 2) == convert(Int16, 13)
160160
@test parse(Float64, "222") == 222.0
161161
@test parse(Float32, "1.1") == convert(Float32, 1.1)
162+
163+
# Make sure exports from Libc and Libdl are defined
164+
for x in [:strftime,:systemsleep,:getpid,:FILE,:malloc,:MS_SYNC,:munmap,:flush_cstdio,:realloc,:strptime,:Libc,:errno,:msync,:TmStruct,:calloc,:MS_INVALIDATE,:MS_ASYNC,:time,:strerror,:gethostname,:free,:mmap]
165+
Libc.(x)
166+
end
167+
for x in [:RTLD_LOCAL,:RTLD_GLOBAL,:find_library,:dlsym,:RTLD_LAZY,:RTLD_NODELETE,:DL_LOAD_PATH,:RTLD_NOW,:Libdl,:dlext,:dlsym_e,:RTLD_FIRST,:dlopen,:dllist,:dlpath,:RTLD_NOLOAD,:dlclose,:dlopen_e,:RTLD_DEEPBIND]
168+
Libdl.(x)
169+
end

0 commit comments

Comments
 (0)