Skip to content

Commit

Permalink
Deprecate Coff_t and FileOffset. Close JuliaLang#14555.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Jan 7, 2016
1 parent 9e773f9 commit 8f080e6
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 106 deletions.
9 changes: 0 additions & 9 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ typealias Culonglong UInt64
typealias Cfloat Float32
typealias Cdouble Float64

const sizeof_off_t = ccall(:jl_sizeof_off_t, Cint, ())
if OS_NAME !== :Windows
const sizeof_mode_t = ccall(:jl_sizeof_mode_t, Cint, ())
if sizeof_mode_t == 2
Expand All @@ -49,14 +48,6 @@ if OS_NAME !== :Windows
end
end

if sizeof_off_t === 4
typealias FileOffset Int32
else
typealias FileOffset Int64
end

typealias Coff_t FileOffset

# C NUL-terminated string pointers; these can be used in ccall
# instead of Ptr{Cchar} and Ptr{Cwchar_t}, respectively, to enforce
# a check for embedded NUL chars in the string (to avoid silent truncation).
Expand Down
12 changes: 8 additions & 4 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,10 @@ export mmap
throw(ArgumentError("requested size must be ≤ $(typemax(Int)-pagesize), got $len"))
end
# Set the offset to a page boundary
offset_page::FileOffset = floor(Integer,offset/pagesize)*pagesize
offset_page::Int64 = floor(Integer,offset/pagesize)*pagesize
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)
p = ccall(:jl_mmap, Ptr{Void}, (Ptr{Void}, Csize_t, Cint, Cint, Cint, Int64), C_NULL, len_page, prot, flags, fd, offset_page)
systemerror("memory mapping failed", reinterpret(Int,p) == -1)
# Also return a pointer that compensates for any adjustment in the offset
return p, Int(offset-offset_page)
Expand Down Expand Up @@ -659,7 +659,7 @@ type SharedMemSpec
create :: Bool
end
export mmap_array
@noinline function mmap_array{T,N}(::Type{T}, dims::NTuple{N,Integer}, s::Union{IO,SharedMemSpec}, offset::FileOffset)
@noinline function mmap_array{T,N}(::Type{T}, dims::NTuple{N,Integer}, s::Union{IO,SharedMemSpec}, offset::Int64)
depwarn("`mmap_array` is deprecated, use `Mmap.mmap(io, Array{T,N}, dims, offset)` instead to return an mmapped-array", :mmap_array)
if isa(s,SharedMemSpec)
a = Mmap.Anonymous(s.name, s.readonly, s.create)
Expand All @@ -670,7 +670,7 @@ export mmap_array
end
end

@deprecate mmap_bitarray{N}(::Type{Bool}, dims::NTuple{N,Integer}, s::IOStream, offset::FileOffset=position(s)) mmap(s, BitArray, dims, offset)
@deprecate mmap_bitarray{N}(::Type{Bool}, dims::NTuple{N,Integer}, s::IOStream, offset::Int64=position(s)) mmap(s, BitArray, dims, offset)
@deprecate mmap_bitarray{N}(dims::NTuple{N,Integer}, s::IOStream, offset=position(s)) mmap(s, BitArray, dims, offset)

# T[a:b] and T[a:s:b]
Expand Down Expand Up @@ -948,3 +948,7 @@ function with_output_limit(thk, lim=true) # thk is usually show()
_limit_output = last
end
end

#14555
@deprecate_binding Coff_t Int64
@deprecate_binding FileOffset Int64
2 changes: 0 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export
Enumerate,
Factorization,
FileMonitor,
FileOffset,
Filter,
FloatRange,
Future,
Expand Down Expand Up @@ -137,7 +136,6 @@ export
Cintmax_t,
Clong,
Clonglong,
Coff_t,
Cptrdiff_t,
Cshort,
Csize_t,
Expand Down
2 changes: 1 addition & 1 deletion base/filesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const SEEK_END = Int32(2)

function position(f::File)
check_open(f)
ret = ccall(:jl_lseek, Coff_t, (Int32, Coff_t, Int32), f.handle, 0, SEEK_CUR)
ret = ccall(:jl_lseek, Int64, (Int32, Int64, Int32), f.handle, 0, SEEK_CUR)
systemerror("lseek", ret == -1)
return ret
end
Expand Down
12 changes: 6 additions & 6 deletions base/iostream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function truncate(s::IOStream, n::Integer)
end

function seek(s::IOStream, n::Integer)
ret = ccall(:ios_seek, FileOffset, (Ptr{Void}, FileOffset), s.ios, n)
ret = ccall(:ios_seek, Int64, (Ptr{Void}, Int64), s.ios, n)
systemerror("seek", ret == -1)
ret < -1 && error("seek failed")
return s
Expand All @@ -55,19 +55,19 @@ end
seekstart(s::IO) = seek(s,0)

function seekend(s::IOStream)
systemerror("seekend", ccall(:ios_seek_end, FileOffset, (Ptr{Void},), s.ios) != 0)
systemerror("seekend", ccall(:ios_seek_end, Int64, (Ptr{Void},), s.ios) != 0)
return s
end

function skip(s::IOStream, delta::Integer)
ret = ccall(:ios_skip, FileOffset, (Ptr{Void}, FileOffset), s.ios, delta)
ret = ccall(:ios_skip, Int64, (Ptr{Void}, Int64), s.ios, delta)
systemerror("skip", ret == -1)
ret < -1 && error("skip failed")
return s
end

function position(s::IOStream)
pos = ccall(:ios_pos, FileOffset, (Ptr{Void},), s.ios)
pos = ccall(:ios_pos, Int64, (Ptr{Void},), s.ios)
systemerror("position", pos == -1)
return pos
end
Expand All @@ -92,7 +92,7 @@ function open(fname::AbstractString, rd::Bool, wr::Bool, cr::Bool, tr::Bool, ff:
(Ptr{UInt8}, Cstring, Cint, Cint, Cint, Cint),
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)
systemerror("seeking to end of file $fname", ccall(:ios_seek_end, Int64, (Ptr{Void},), s.ios) != 0)
end
return s
end
Expand Down Expand Up @@ -245,7 +245,7 @@ function readbytes(s::IOStream)
sz = 0
try # filesize is just a hint, so ignore if it fails
sz = filesize(s)
pos = ccall(:ios_pos, FileOffset, (Ptr{Void},), s.ios)
pos = ccall(:ios_pos, Int64, (Ptr{Void},), s.ios)
if pos > 0
sz -= pos
end
Expand Down
8 changes: 4 additions & 4 deletions base/mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function grow!(io::IO, offset::Integer, len::Integer)
pos = position(io)
filelen = filesize(io)
if filelen < offset + len
failure = ccall(:jl_ftruncate, Cint, (Cint, Coff_t), fd(io), offset+len)
failure = ccall(:jl_ftruncate, Cint, (Cint, Int64), fd(io), offset+len)
Base.systemerror(:ftruncate, failure != 0)
end
seek(io, pos)
Expand Down Expand Up @@ -108,7 +108,7 @@ function mmap{T,N}(io::IO,
offset >= 0 || throw(ArgumentError("requested offset must be ≥ 0, got $offset"))

# shift `offset` to start of page boundary
offset_page::FileOffset = div(offset, PAGESIZE) * PAGESIZE
offset_page::Int64 = div(offset, PAGESIZE) * PAGESIZE
# add (offset - offset_page) to `len` to get total length of memory-mapped region
mmaplen = (offset - offset_page) + len

Expand All @@ -118,7 +118,7 @@ function mmap{T,N}(io::IO,
prot, flags, iswrite = settings(file_desc, shared)
iswrite && grow && grow!(io, offset, len)
# mmap the file
ptr = ccall(:jl_mmap, Ptr{Void}, (Ptr{Void}, Csize_t, Cint, Cint, Cint, FileOffset), C_NULL, mmaplen, prot, flags, file_desc, offset_page)
ptr = ccall(:jl_mmap, Ptr{Void}, (Ptr{Void}, Csize_t, Cint, Cint, Cint, Int64), C_NULL, mmaplen, prot, flags, file_desc, offset_page)
systemerror("memory mapping failed", reinterpret(Int,ptr) == -1)
end # @unix_only

Expand Down Expand Up @@ -165,7 +165,7 @@ mmap{T<:Array}(::Type{T}, i::Integer...; shared::Bool=true) = mmap(Anonymous(),
function mmap{T<:BitArray,N}(io::IOStream,
::Type{T},
dims::NTuple{N,Integer},
offset::FileOffset=position(io); grow::Bool=true, shared::Bool=true)
offset::Int64=position(io); grow::Bool=true, shared::Bool=true)
n = prod(dims)
nc = Base.num_bit_chunks(n)
chunks = mmap(io, Vector{UInt64}, (nc,), offset; grow=grow, shared=shared)
Expand Down
6 changes: 3 additions & 3 deletions base/sharedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,11 @@ function _shm_mmap_array(T, dims, shm_seg_name, mode)
# On OSX, ftruncate must to used to set size of segment, just lseek does not work.
# and only at creation time
if (mode & JL_O_CREAT) == JL_O_CREAT
rc = ccall(:jl_ftruncate, Cint, (Cint, Coff_t), fd_mem, prod(dims)*sizeof(T))
rc = ccall(:jl_ftruncate, Cint, (Cint, Int64), fd_mem, prod(dims)*sizeof(T))
systemerror("ftruncate() failed for shm segment " * shm_seg_name, rc != 0)
end

Mmap.mmap(s, Array{T,length(dims)}, dims, zero(FileOffset); grow=false)
Mmap.mmap(s, Array{T,length(dims)}, dims, zero(Int64); grow=false)
end

shm_unlink(shm_seg_name) = ccall(:shm_unlink, Cint, (Cstring,), shm_seg_name)
Expand All @@ -549,7 +549,7 @@ function _shm_mmap_array(T, dims, shm_seg_name, mode)
readonly = !((mode & JL_O_RDWR) == JL_O_RDWR)
create = (mode & JL_O_CREAT) == JL_O_CREAT
s = Mmap.Anonymous(shm_seg_name, readonly, create)
Mmap.mmap(s, Array{T,length(dims)}, dims, zero(FileOffset))
Mmap.mmap(s, Array{T,length(dims)}, dims, zero(Int64))
end

# no-op in windows
Expand Down
2 changes: 0 additions & 2 deletions contrib/BBEditTextWrangler-julia.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,6 @@
<string>Clonglong</string>
<string>ClusterManager</string>
<string>Cmd</string>
<string>Coff_t</string>
<string>Collections</string>
<string>Colon</string>
<string>Complex</string>
Expand Down Expand Up @@ -1183,7 +1182,6 @@
<string>FFTW</string>
<string>Factorization</string>
<string>FileMonitor</string>
<string>FileOffset</string>
<string>Filter</string>
<string>FloatRange</string>
<string>Graphics</string>
Expand Down
2 changes: 1 addition & 1 deletion contrib/Julia_Notepad++.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">true false C_NULL Inf NaN Inf32 NaN32 nothing</Keywords>
<Keywords name="Keywords2">ASCIIString AbstractArray AbstractMatrix AbstractSparseMatrix AbstractString AbstractVector Any ArgumentError Array Associative AsyncStream BigFloat BigInt BitArray BitMatrix BitVector Bool BunchKaufman ByteString Cchar Cdouble Cfloat Char CharString CholeskyDense CholeskyPivotedDense Cint Cintmax_t Clong Clonglong Colon Complex Complex128 Complex64 ComplexPair Cptrdiff_t Cshort Csize_t Cuchar Cuint Cuintmax_t Culong Culonglong Cushort DArray Dict Dims DisconnectException EOFError EachLine EnvHash ErrorException Exception Expr Factorization FileOffset Filter Float Float32 Float64 Function GSVDDense IO IOBuffer IOStream ImaginaryUnit InsertionSort Int Int128 Int16 Int32 Int64 Int8 IntSet Integer KeyError LDLTTridiagonal LUDense LUTridiagonal LoadError LocalProcess Matrix MergeSort MethodError NTuple Number ObjectIdDict ObjectIdDict OrdinalRange ParseError PipeBuffer ProcessGroup Ptr QRDense QRPivotedDense QuickSort Range Range1 RangeIndex Ranges Rational Real Regex RegexMatch RegexMatchIterator RemoteRef RepString RevString Reverse RopeString SVDDense Set Signed SparseMatrixCSC SpawnNullStream Stat StridedArray StridedMatrix StridedVecOrMat StridedVector SubArray SubDArray SubOrDArray SubString SymTridiagonal Symbol SystemError Task TCPSocket TimSort Tridiagonal Tuple Type TypeError UInt UInt128 UInt16 UInt32 UInt64 UInt8 UTF8String UVError Union Unsigned VecOrMat Vector VersionNumber Void WeakKeyDict WeakRef Zip</Keywords>
<Keywords name="Keywords2">ASCIIString AbstractArray AbstractMatrix AbstractSparseMatrix AbstractString AbstractVector Any ArgumentError Array Associative AsyncStream BigFloat BigInt BitArray BitMatrix BitVector Bool BunchKaufman ByteString Cchar Cdouble Cfloat Char CharString CholeskyDense CholeskyPivotedDense Cint Cintmax_t Clong Clonglong Colon Complex Complex128 Complex64 ComplexPair Cptrdiff_t Cshort Csize_t Cuchar Cuint Cuintmax_t Culong Culonglong Cushort DArray Dict Dims DisconnectException EOFError EachLine EnvHash ErrorException Exception Expr Factorization Filter Float Float32 Float64 Function GSVDDense IO IOBuffer IOStream ImaginaryUnit InsertionSort Int Int128 Int16 Int32 Int64 Int8 IntSet Integer KeyError LDLTTridiagonal LUDense LUTridiagonal LoadError LocalProcess Matrix MergeSort MethodError NTuple Number ObjectIdDict ObjectIdDict OrdinalRange ParseError PipeBuffer ProcessGroup Ptr QRDense QRPivotedDense QuickSort Range Range1 RangeIndex Ranges Rational Real Regex RegexMatch RegexMatchIterator RemoteRef RepString RevString Reverse RopeString SVDDense Set Signed SparseMatrixCSC SpawnNullStream Stat StridedArray StridedMatrix StridedVecOrMat StridedVector SubArray SubDArray SubOrDArray SubString SymTridiagonal Symbol SystemError Task TCPSocket TimSort Tridiagonal Tuple Type TypeError UInt UInt128 UInt16 UInt32 UInt64 UInt8 UTF8String UVError Union Unsigned VecOrMat Vector VersionNumber Void WeakKeyDict WeakRef Zip</Keywords>
<Keywords name="Keywords3">abstract begin baremodule bitstype break catch ccall const continue do else elseif end export finally for function global if immutable import importall let local macro module quote return try type typealias using while</Keywords>
<Keywords name="Keywords4">close enumerate error info open print println read write warn</Keywords>
<Keywords name="Keywords5">print println</Keywords>
Expand Down
2 changes: 0 additions & 2 deletions contrib/julia.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
<item> Exception </item>
<item> Expr </item>
<item> FileMonitor </item>
<item> FileOffset </item>
<item> Filter </item>
<item> AbstractFloat </item>
<item> Float16 </item>
Expand Down Expand Up @@ -252,7 +251,6 @@
<item> Culonglong </item>
<item> Cintmax_t </item>
<item> Cuintmax_t </item>
<item> Coff_t </item>
<item> Cfloat </item>
<item> Cdouble </item>
<item> Cwchar_t </item>
Expand Down
4 changes: 0 additions & 4 deletions doc/stdlib/c.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@

Equivalent to the native ``ptrdiff_t`` c-type (Int)

.. data:: Coff_t

Equivalent to the native ``off_t`` c-type. Note that julia defines ``_FILE_OFFSET_BITS=64`` so this may not be the same as the default value on 32bits Linux.

.. data:: Cwchar_t

Equivalent to the native ``wchar_t`` c-type (Int32)
Expand Down
2 changes: 1 addition & 1 deletion src/flisp/cvalues.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ void to_sized_ptr(fl_context_t *fl_ctx, value_t v, char *fname, char **pdata, si
ios_t *x = value2c(ios_t*,v);
if (cv_class(pcv) == fl_ctx->iostreamtype && (x->bm == bm_mem)) {
*pdata = x->buf;
*psz = x->size;
*psz = (size_t)x->size;
return;
}
else if (cv_isPOD(pcv)) {
Expand Down
6 changes: 3 additions & 3 deletions src/flisp/iostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ value_t fl_ioseek(fl_context_t *fl_ctx, value_t *args, u_int32_t nargs)
argcount(fl_ctx, "io.seek", nargs, 2);
ios_t *s = toiostream(fl_ctx, args[0], "io.seek");
size_t pos = tosize(fl_ctx, args[1], "io.seek");
off_t res = ios_seek(s, (off_t)pos);
int64_t res = ios_seek(s, pos);
if (res < 0)
return fl_ctx->F;
return fl_ctx->T;
Expand All @@ -225,7 +225,7 @@ value_t fl_iopos(fl_context_t *fl_ctx, value_t *args, u_int32_t nargs)
{
argcount(fl_ctx, "io.pos", nargs, 1);
ios_t *s = toiostream(fl_ctx, args[0], "io.pos");
off_t res = ios_pos(s);
int64_t res = ios_pos(s);
if (res == -1)
return fl_ctx->F;
return size_wrap(fl_ctx, (size_t)res);
Expand Down Expand Up @@ -375,7 +375,7 @@ value_t stream_to_string(fl_context_t *fl_ctx, value_t *ps)
size_t n;
ios_t *st = value2c(ios_t*,*ps);
if (st->buf == &st->local[0]) {
n = st->size;
n = (size_t)st->size;
str = cvalue_string(fl_ctx, n);
st = value2c(ios_t*,*ps); // reload after allocating str
memcpy(cvalue_data(str), st->buf, n);
Expand Down
6 changes: 3 additions & 3 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,16 +750,16 @@ static void julia_save(void)
ios_t f;
if (ios_file(&f, jl_options.outputji, 1, 1, 1, 1) == NULL)
jl_errorf("cannot open system image file \"%s\" for writing", jl_options.outputji);
ios_write(&f, (const char*)s->buf, s->size);
ios_write(&f, (const char*)s->buf, (size_t)s->size);
ios_close(&f);
}
}

if (jl_options.outputbc)
jl_dump_bitcode((char*)jl_options.outputbc, (const char*)s->buf, s->size);
jl_dump_bitcode((char*)jl_options.outputbc, (const char*)s->buf, (size_t)s->size);

if (jl_options.outputo)
jl_dump_objfile((char*)jl_options.outputo, 0, (const char*)s->buf, s->size);
jl_dump_objfile((char*)jl_options.outputo, 0, (const char*)s->buf, (size_t)s->size);
}
JL_GC_POP();
}
Expand Down
Loading

0 comments on commit 8f080e6

Please sign in to comment.