@@ -175,10 +175,10 @@ function mkdir(path::AbstractString; mode::Integer = 0o777)
175
175
(Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Cint, Ptr{Cvoid}),
176
176
C_NULL , req, path, checkmode (mode), C_NULL )
177
177
if ret < 0
178
- ccall ( : uv_fs_req_cleanup, Cvoid, (Ptr{Cvoid},), req)
178
+ uv_fs_req_cleanup ( req)
179
179
uv_error (" mkdir($(repr (path)) ; mode=0o$(string (mode,base= 8 )) )" , ret)
180
180
end
181
- ccall ( : uv_fs_req_cleanup, Cvoid, (Ptr{Cvoid},), req)
181
+ uv_fs_req_cleanup ( req)
182
182
return path
183
183
finally
184
184
Libc. free (req)
@@ -678,11 +678,11 @@ function mktempdir(parent::AbstractString=tempdir();
678
678
(Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Ptr{Cvoid}),
679
679
C_NULL , req, tpath, C_NULL )
680
680
if ret < 0
681
- ccall ( : uv_fs_req_cleanup, Cvoid, (Ptr{Cvoid},), req)
681
+ uv_fs_req_cleanup ( req)
682
682
uv_error (" mktempdir($(repr (parent)) )" , ret)
683
683
end
684
684
path = unsafe_string (ccall (:jl_uv_fs_t_path , Cstring, (Ptr{Cvoid},), req))
685
- ccall ( : uv_fs_req_cleanup, Cvoid, (Ptr{Cvoid},), req)
685
+ uv_fs_req_cleanup ( req)
686
686
cleanup && temp_cleanup_later (path)
687
687
return path
688
688
finally
@@ -822,28 +822,31 @@ julia> readdir(abspath("base"), join=true)
822
822
"""
823
823
function readdir (dir:: AbstractString ; join:: Bool = false , sort:: Bool = true )
824
824
# Allocate space for uv_fs_t struct
825
- uv_readdir_req = zeros (UInt8, ccall ( :jl_sizeof_uv_fs_t , Int32, ()) )
826
-
827
- # defined in sys.c, to call uv_fs_readdir, which sets errno on error.
828
- err = ccall (:uv_fs_scandir , Int32, (Ptr{Cvoid}, Ptr{UInt8 }, Cstring, Cint, Ptr{Cvoid}),
829
- C_NULL , uv_readdir_req , dir, 0 , C_NULL )
830
- err < 0 && uv_error (" readdir($(repr (dir)) )" , err)
831
-
832
- # iterate the listing into entries
833
- entries = String[]
834
- ent = Ref {uv_dirent_t} ()
835
- while Base. UV_EOF != ccall (:uv_fs_scandir_next , Cint, (Ptr{Cvoid}, Ptr{uv_dirent_t}), uv_readdir_req , ent)
836
- name = unsafe_string (ent[]. name)
837
- push! (entries, join ? joinpath (dir, name) : name)
838
- end
825
+ req = Libc . malloc (_sizeof_uv_fs )
826
+ try
827
+ # defined in sys.c, to call uv_fs_readdir, which sets errno on error.
828
+ err = ccall (:uv_fs_scandir , Int32, (Ptr{Cvoid}, Ptr{Cvoid }, Cstring, Cint, Ptr{Cvoid}),
829
+ C_NULL , req , dir, 0 , C_NULL )
830
+ err < 0 && uv_error (" readdir($(repr (dir)) )" , err)
831
+
832
+ # iterate the listing into entries
833
+ entries = String[]
834
+ ent = Ref {uv_dirent_t} ()
835
+ while Base. UV_EOF != ccall (:uv_fs_scandir_next , Cint, (Ptr{Cvoid}, Ptr{uv_dirent_t}), req , ent)
836
+ name = unsafe_string (ent[]. name)
837
+ push! (entries, join ? joinpath (dir, name) : name)
838
+ end
839
839
840
- # Clean up the request string
841
- ccall ( :uv_fs_req_cleanup , Cvoid, (Ptr{UInt8},), uv_readdir_req )
840
+ # Clean up the request string
841
+ uv_fs_req_cleanup (req )
842
842
843
- # sort entries unless opted out
844
- sort && sort! (entries)
843
+ # sort entries unless opted out
844
+ sort && sort! (entries)
845
845
846
- return entries
846
+ return entries
847
+ finally
848
+ Libc. free (req)
849
+ end
847
850
end
848
851
readdir (; join:: Bool = false , sort:: Bool = true ) =
849
852
readdir (join ? pwd () : " ." , join= join, sort= sort)
@@ -1019,12 +1022,12 @@ function readlink(path::AbstractString)
1019
1022
(Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Ptr{Cvoid}),
1020
1023
C_NULL , req, path, C_NULL )
1021
1024
if ret < 0
1022
- ccall ( : uv_fs_req_cleanup, Cvoid, (Ptr{Cvoid},), req)
1025
+ uv_fs_req_cleanup ( req)
1023
1026
uv_error (" readlink($(repr (path)) )" , ret)
1024
1027
@assert false
1025
1028
end
1026
1029
tgt = unsafe_string (ccall (:jl_uv_fs_t_ptr , Cstring, (Ptr{Cvoid},), req))
1027
- ccall ( : uv_fs_req_cleanup, Cvoid, (Ptr{Cvoid},), req)
1030
+ uv_fs_req_cleanup ( req)
1028
1031
return tgt
1029
1032
finally
1030
1033
Libc. free (req)
0 commit comments