Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replace error() by systemerror() where appropriate

No other semantics should have changed.
  • Loading branch information...
commit 1b5cb8ff5564975e974de69c4d428ba628ed2847 1 parent 4ecfba7
@lucasb-eyer lucasb-eyer authored
View
8 base/fftw.jl
@@ -80,9 +80,7 @@ typealias fftwTypeSingle Union(Type{Float32},Type{Complex64})
function export_wisdom(fname::String)
f = ccall(:fopen, Ptr{Void}, (Ptr{Uint8},Ptr{Uint8}),
bytestring(fname), bytestring("w"))
- if f == C_NULL
- error("could not open wisdom file $fname")
- end
+ systemerror("could not open wisdom file $fname for writing", f == C_NULL)
ccall((:fftw_export_wisdom_to_file,libfftw), Void, (Ptr{Void},), f)
ccall(:fputs, Int32, (Ptr{Uint8},Ptr{Void}), bytestring(" "^256), f)
ccall((:fftwf_export_wisdom_to_file,libfftwf), Void, (Ptr{Void},), f)
@@ -92,9 +90,7 @@ end
function import_wisdom(fname::String)
f = ccall(:fopen, Ptr{Void}, (Ptr{Uint8},Ptr{Uint8}),
bytestring(fname), bytestring("r"))
- if f == C_NULL
- error("could not open wisdom file $fname")
- end
+ systemerror("could not open wisdom file $fname for reading", f == C_NULL)
if ccall((:fftw_import_wisdom_from_file,libfftw),Int32,(Ptr{Void},),f)==0||
ccall((:fftwf_import_wisdom_from_file,libfftwf),Int32,(Ptr{Void},),f)==0
error("failed to import wisdom from $fname")
View
7 base/file.jl
@@ -137,13 +137,10 @@ function readdir(path::String)
# Allocate space for uv_fs_t struct
uv_readdir_req = zeros(Uint8, ccall(:jl_sizeof_uv_fs_t, Int32, ()))
- # defined in sys.c, to call uv_fs_readdir
+ # defined in sys.c, to call uv_fs_readdir, which sets errno on error.
file_count = ccall(:jl_readdir, Int32, (Ptr{Uint8}, Ptr{Uint8}),
bytestring(path), uv_readdir_req)
-
- if file_count < 0
- error("unable to read directory $path")
- end
+ systemerror("unable to read directory $path", file_count < 0)
# The list of dir entries is returned as a contiguous sequence of null-terminated
# strings, the first of which is pointed to by ptr in uv_readdir_req.
View
28 base/io.jl
@@ -278,8 +278,7 @@ modestr(s::IO) = modestr(isreadable(s), iswritable(s))
modestr(r::Bool, w::Bool) = r ? (w ? "r+" : "r") : (w ? "w" : error("Neither readable nor writable"))
function truncate(s::IOStream, n::Integer)
- ccall(:ios_trunc, Int32, (Ptr{Void}, Uint), s.ios, n) == 0 ||
- error("truncate failed")
+ systemerror("truncate", ccall(:ios_trunc, Int32, (Ptr{Void}, Uint), s.ios, n) != 0)
return s
end
@@ -292,8 +291,7 @@ end
seekstart(s::IO) = seek(s,0)
function seekend(s::IOStream)
- ccall(:ios_seek_end, FileOffset, (Ptr{Void},), s.ios)==0 ||
- error("seekend failed")
+ systemerror("seekend", ccall(:ios_seek_end, FileOffset, (Ptr{Void},), s.ios) != 0)
return s
end
@@ -317,18 +315,15 @@ end
function CFILE(s::IO)
@unix_only FILEp = ccall(:fdopen, Ptr{Void}, (Cint, Ptr{Uint8}), convert(Cint, fd(s)), modestr(s))
@windows_only FILEp = ccall(:_fdopen, Ptr{Void}, (Cint, Ptr{Uint8}), convert(Cint, fd(s)), modestr(s))
- if FILEp == 0
- error("fdopen failed")
- end
+ systemerror("fdopen", FILEp == C_NULL)
seek(CFILE(FILEp), position(s))
end
convert(::Type{CFILE}, s::IO) = CFILE(s)
function seek(h::CFILE, offset::Integer)
- ccall(:fseek, Cint, (Ptr{Void}, Clong, Cint),
- h.ptr, convert(Clong, offset), int32(0)) == 0 ||
- error("fseek failed")
+ systemerror("fseek", ccall(:fseek, Cint, (Ptr{Void}, Clong, Cint),
+ h.ptr, convert(Clong, offset), int32(0)) != 0)
h
end
@@ -347,13 +342,12 @@ fdio(fd::Integer, own::Bool=false) = fdio(string("<fd ",fd,">"), fd, own)
function open(fname::String, rd::Bool, wr::Bool, cr::Bool, tr::Bool, ff::Bool)
s = IOStream(string("<file ",fname,">"))
- if ccall(:ios_file, Ptr{Void},
- (Ptr{Uint8}, Ptr{Uint8}, Int32, Int32, Int32, Int32),
- s.ios, fname, rd, wr, cr, tr) == C_NULL
- error("could not open file ", fname)
- end
- if ff && ccall(:ios_seek_end, FileOffset, (Ptr{Void},), s.ios) != 0
- error("error seeking to end of file ", fname)
+ systemerror("opening file $fname",
+ ccall(:ios_file, Ptr{Void},
+ (Ptr{Uint8}, Ptr{Uint8}, Int32, Int32, Int32, Int32),
+ s.ios, fname, rd, wr, cr, tr) == C_NULL)
+ if ff
+ systemerror("seeking to end of file $fname", ccall(:ios_seek_end, FileOffset, (Ptr{Void},), s.ios) != 0)
end
return s
end
View
4 base/libc.jl
@@ -72,9 +72,7 @@ function gethostname()
hn = Array(Uint8, 256)
@unix_only err=ccall(:gethostname, Int32, (Ptr{Uint8}, Uint), hn, length(hn))
@windows_only err=ccall(:gethostname, stdcall, Int32, (Ptr{Uint8}, Uint32), hn, length(hn))
- if err != 0
- error("gethostname")
- end
+ systemerror("gethostname", err != 0)
bytestring(convert(Ptr{Uint8},hn))
end
View
27 base/mmap.jl
@@ -29,9 +29,7 @@ function mmap(len::Integer, prot::Integer, flags::Integer, fd::Integer, offset::
len_page::Int = (offset-offset_page) + len
# Mmap the file
p = ccall(:jl_mmap, Ptr{Void}, (Ptr{Void}, Csize_t, Cint, Cint, Cint, FileOffset), C_NULL, len_page, prot, flags, fd, offset_page)
- if int(p) == -1
- error("memory mapping failed: ", strerror())
- end
+ systemerror("memory mapping failed", int(p) == -1)
# Also return a pointer that compensates for any adjustment in the offset
return p, int(offset-offset_page)
end
@@ -47,38 +45,25 @@ function mmap_grow(len::Integer, prot::Integer, flags::Integer, fd::Integer, off
const SEEK_END::Cint = 2
# Save current file position so we can restore it later
cpos = ccall(:jl_lseek, FileOffset, (Cint, FileOffset, Cint), fd, 0, SEEK_CUR)
- if cpos < 0
- error(strerror())
- end
+ systemerror("lseek", cpos < 0)
filelen = ccall(:jl_lseek, FileOffset, (Cint, FileOffset, Cint), fd, 0, SEEK_END)
- if filelen < 0
- error(strerror())
- end
+ systemerror("lseek", filelen < 0)
if (filelen < offset + len)
- n = ccall(:jl_pwrite, Cssize_t, (Cint, Ptr{Void}, Uint, FileOffset), fd, int8([0]), 1, offset + len - 1)
- if (n < 1)
- error(strerror())
- end
+ systemerror("pwrite", ccall(:jl_pwrite, Cssize_t, (Cint, Ptr{Void}, Uint, FileOffset), fd, int8([0]), 1, offset + len - 1) < 1)
end
cpos = ccall(:jl_lseek, FileOffset, (Cint, FileOffset, Cint), fd, cpos, SEEK_SET)
return mmap(len, prot, flags, fd, offset)
end
function munmap(p::Ptr,len::Integer)
- ret = ccall(:munmap,Cint,(Ptr{Void},Int),p,len)
- if ret != 0
- error(strerror())
- end
+ systemerror("munmap", ccall(:munmap,Cint,(Ptr{Void},Int),p,len) != 0)
end
const MS_ASYNC = 1
const MS_INVALIDATE = 2
const MS_SYNC = 4
function msync(p::Ptr, len::Integer, flags::Integer)
- ret = ccall(:msync, Cint, (Ptr{Void}, Csize_t, Cint), p, len, flags)
- if ret != 0
- error(strerror())
- end
+ systemerror("msync", ccall(:msync, Cint, (Ptr{Void}, Csize_t, Cint), p, len, flags) != 0)
end
msync(p::Ptr, len::Integer) = msync(p, len, MS_SYNC)
Please sign in to comment.
Something went wrong with that request. Please try again.