Skip to content

Commit 38ebdbb

Browse files
committed
Rename nb_available to bytesavailable
1 parent 625923f commit 38ebdbb

File tree

18 files changed

+72
-67
lines changed

18 files changed

+72
-67
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,8 @@ Deprecated or removed
690690

691691
* `read(::IO, ::Ref)` is now a method of `read!`, since it mutates its `Ref` argument ([#21592]).
692692

693+
* `nb_available` is now `bytesavailable` ([#25634]).
694+
693695
* `Bidiagonal` constructors now use a `Symbol` (`:U` or `:L`) for the upper/lower
694696
argument, instead of a `Bool` or a `Char` ([#22703]).
695697

@@ -1222,3 +1224,4 @@ Command-line option changes
12221224
[#25532]: https://github.com/JuliaLang/julia/issues/25532
12231225
[#25545]: https://github.com/JuliaLang/julia/issues/25545
12241226
[#25616]: https://github.com/JuliaLang/julia/issues/25616
1227+
[#25634]: https://github.com/JuliaLang/julia/issues/25634

base/deprecated.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,8 @@ end
15831583
@deprecate gc_enable GC.enable
15841584
@eval @deprecate $(Symbol("@gc_preserve")) GC.$(Symbol("@preserve")) false
15851585

1586+
@deprecate nb_available bytesavailable
1587+
15861588
# issue #9053
15871589
if Sys.iswindows()
15881590
function Filesystem.tempname(uunique::UInt32)

base/exports.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ export
855855
listenany,
856856
ltoh,
857857
mark,
858-
nb_available,
858+
bytesavailable,
859859
ntoh,
860860
open,
861861
pipeline,

base/filesystem.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export File,
4040

4141
import Base:
4242
UVError, _sizeof_uv_fs, check_open, close, eof, eventloop, fd, isopen,
43-
nb_available, position, read, read!, readavailable, seek, seekend, show,
43+
bytesavailable, position, read, read!, readavailable, seek, seekend, show,
4444
skip, stat, unsafe_read, unsafe_write, transcode, uv_error, uvhandle,
4545
uvtype, write
4646
using Base: coalesce
@@ -179,12 +179,12 @@ function unsafe_read(f::File, p::Ptr{UInt8}, nel::UInt)
179179
nothing
180180
end
181181

182-
nb_available(f::File) = max(0, filesize(f) - position(f)) # position can be > filesize
182+
bytesavailable(f::File) = max(0, filesize(f) - position(f)) # position can be > filesize
183183

184-
eof(f::File) = nb_available(f) == 0
184+
eof(f::File) = bytesavailable(f) == 0
185185

186186
function readbytes!(f::File, b::Array{UInt8}, nb=length(b))
187-
nr = min(nb, nb_available(f))
187+
nr = min(nb, bytesavailable(f))
188188
if length(b) < nr
189189
resize!(b, nr)
190190
end
@@ -193,9 +193,9 @@ function readbytes!(f::File, b::Array{UInt8}, nb=length(b))
193193
uv_error("read",ret)
194194
return ret
195195
end
196-
read(io::File) = read!(io, Base.StringVector(nb_available(io)))
196+
read(io::File) = read!(io, Base.StringVector(bytesavailable(io)))
197197
readavailable(io::File) = read(io)
198-
read(io::File, nb::Integer) = read!(io, Base.StringVector(min(nb, nb_available(io))))
198+
read(io::File, nb::Integer) = read!(io, Base.StringVector(min(nb, bytesavailable(io))))
199199

200200
const SEEK_SET = Int32(0)
201201
const SEEK_CUR = Int32(1)

base/io.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function wait_connected end
6565
function wait_readnb end
6666
function wait_readbyte end
6767
function wait_close end
68-
function nb_available end
68+
function bytesavailable end
6969

7070
"""
7171
readavailable(stream)
@@ -243,19 +243,19 @@ wait_readbyte(io::AbstractPipe, byte::UInt8) = wait_readbyte(pipe_reader(io), by
243243
wait_close(io::AbstractPipe) = (wait_close(pipe_writer(io)); wait_close(pipe_reader(io)))
244244

245245
"""
246-
nb_available(io)
246+
bytesavailable(io)
247247
248248
Return the number of bytes available for reading before a read from this stream or buffer will block.
249249
250250
# Examples
251251
```jldoctest
252252
julia> io = IOBuffer("JuliaLang is a GitHub organization");
253253
254-
julia> nb_available(io)
254+
julia> bytesavailable(io)
255255
34
256256
```
257257
"""
258-
nb_available(io::AbstractPipe) = nb_available(pipe_reader(io))
258+
bytesavailable(io::AbstractPipe) = bytesavailable(pipe_reader(io))
259259

260260
"""
261261
eof(stream) -> Bool

base/iobuffer.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ show(io::IO, b::GenericIOBuffer) = print(io, "IOBuffer(data=UInt8[...], ",
147147

148148
function unsafe_read(from::GenericIOBuffer, p::Ptr{UInt8}, nb::UInt)
149149
from.readable || throw(ArgumentError("read failed, IOBuffer is not readable"))
150-
avail = nb_available(from)
150+
avail = bytesavailable(from)
151151
adv = min(avail, nb)
152152
GC.@preserve from unsafe_copyto!(p, pointer(from.data, from.ptr), adv)
153153
from.ptr += adv
@@ -200,8 +200,8 @@ iswritable(io::GenericIOBuffer) = io.writable
200200

201201
# TODO: GenericIOBuffer is not iterable, so doesn't really have a length.
202202
# This should maybe be sizeof() instead.
203-
#length(io::GenericIOBuffer) = (io.seekable ? io.size : nb_available(io))
204-
nb_available(io::GenericIOBuffer) = io.size - io.ptr + 1
203+
#length(io::GenericIOBuffer) = (io.seekable ? io.size : bytesavailable(io))
204+
bytesavailable(io::GenericIOBuffer) = io.size - io.ptr + 1
205205
position(io::GenericIOBuffer) = io.ptr-1
206206

207207
function skip(io::GenericIOBuffer, n::Integer)
@@ -251,10 +251,10 @@ function compact(io::GenericIOBuffer)
251251
if ismarked(io) && io.mark < io.ptr
252252
if io.mark == 0 return end
253253
ptr = io.mark
254-
bytes_to_move = nb_available(io) + (io.ptr-io.mark)
254+
bytes_to_move = bytesavailable(io) + (io.ptr-io.mark)
255255
else
256256
ptr = io.ptr
257-
bytes_to_move = nb_available(io)
257+
bytes_to_move = bytesavailable(io)
258258
end
259259
copyto!(io.data, 1, io.data, ptr, bytes_to_move)
260260
io.size -= ptr - 1
@@ -305,7 +305,7 @@ eof(io::GenericIOBuffer) = (io.ptr-1 == io.size)
305305
nothing
306306
end
307307

308-
isopen(io::GenericIOBuffer) = io.readable || io.writable || io.seekable || nb_available(io) > 0
308+
isopen(io::GenericIOBuffer) = io.readable || io.writable || io.seekable || bytesavailable(io) > 0
309309

310310
"""
311311
take!(b::IOBuffer)
@@ -330,7 +330,7 @@ function take!(io::GenericIOBuffer)
330330
nbytes = io.size
331331
data = copyto!(StringVector(nbytes), 1, io.data, 1, nbytes)
332332
else
333-
nbytes = nb_available(io)
333+
nbytes = bytesavailable(io)
334334
data = read!(io,StringVector(nbytes))
335335
end
336336
if io.writable
@@ -351,7 +351,7 @@ function take!(io::IOBuffer)
351351
end
352352
resize!(data,io.size)
353353
else
354-
nbytes = nb_available(io)
354+
nbytes = bytesavailable(io)
355355
a = StringVector(nbytes)
356356
data = read!(io, a)
357357
end
@@ -367,7 +367,7 @@ function write(to::GenericIOBuffer, from::GenericIOBuffer)
367367
from.ptr = from.size + 1
368368
return 0
369369
end
370-
written::Int = write_sub(to, from.data, from.ptr, nb_available(from))
370+
written::Int = write_sub(to, from.data, from.ptr, bytesavailable(from))
371371
from.ptr += written
372372
return written
373373
end
@@ -415,20 +415,20 @@ end
415415

416416
readbytes!(io::GenericIOBuffer, b::Array{UInt8}, nb=length(b)) = readbytes!(io, b, Int(nb))
417417
function readbytes!(io::GenericIOBuffer, b::Array{UInt8}, nb::Int)
418-
nr = min(nb, nb_available(io))
418+
nr = min(nb, bytesavailable(io))
419419
if length(b) < nr
420420
resize!(b, nr)
421421
end
422422
read_sub(io, b, 1, nr)
423423
return nr
424424
end
425-
read(io::GenericIOBuffer) = read!(io,StringVector(nb_available(io)))
425+
read(io::GenericIOBuffer) = read!(io,StringVector(bytesavailable(io)))
426426
readavailable(io::GenericIOBuffer) = read(io)
427-
read(io::GenericIOBuffer, nb::Integer) = read!(io,StringVector(min(nb, nb_available(io))))
427+
read(io::GenericIOBuffer, nb::Integer) = read!(io,StringVector(min(nb, bytesavailable(io))))
428428

429429
function findfirst(delim::EqualTo{UInt8}, buf::IOBuffer)
430430
p = pointer(buf.data, buf.ptr)
431-
q = GC.@preserve buf ccall(:memchr,Ptr{UInt8},(Ptr{UInt8},Int32,Csize_t),p,delim.x,nb_available(buf))
431+
q = GC.@preserve buf ccall(:memchr,Ptr{UInt8},(Ptr{UInt8},Int32,Csize_t),p,delim.x,bytesavailable(buf))
432432
q == C_NULL && return nothing
433433
return Int(q-p+1)
434434
end
@@ -472,10 +472,10 @@ end
472472
function _crc32c(io::IOBuffer, nb::Integer, crc::UInt32=0x00000000)
473473
nb < 0 && throw(ArgumentError("number of bytes to checksum must be ≥ 0"))
474474
io.readable || throw(ArgumentError("read failed, IOBuffer is not readable"))
475-
n = min(nb, nb_available(io))
475+
n = min(nb, bytesavailable(io))
476476
n == 0 && return crc
477477
crc = GC.@preserve io unsafe_crc32c(pointer(io.data, io.ptr), n, crc)
478478
io.ptr += n
479479
return crc
480480
end
481-
_crc32c(io::IOBuffer, crc::UInt32=0x00000000) = _crc32c(io, nb_available(io), crc)
481+
_crc32c(io::IOBuffer, crc::UInt32=0x00000000) = _crc32c(io, bytesavailable(io), crc)

base/iostream.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ function unsafe_write(s::IOStream, p::Ptr{UInt8}, nb::UInt)
326326
end
327327

328328
# num bytes available without blocking
329-
nb_available(s::IOStream) = ccall(:jl_nb_available, Int32, (Ptr{Cvoid},), s.ios)
329+
bytesavailable(s::IOStream) = ccall(:jl_nb_available, Int32, (Ptr{Cvoid},), s.ios)
330330

331-
readavailable(s::IOStream) = read!(s, Vector{UInt8}(uninitialized, nb_available(s)))
331+
readavailable(s::IOStream) = read!(s, Vector{UInt8}(uninitialized, bytesavailable(s)))
332332

333333
function read(s::IOStream, ::Type{UInt8})
334334
b = ccall(:ios_getc, Cint, (Ptr{Cvoid},), s.ios)

base/repl/REPL.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ function setup_interface(
888888
sbuffer = LineEdit.buffer(s)
889889
curspos = position(sbuffer)
890890
seek(sbuffer, 0)
891-
shouldeval = (nb_available(sbuffer) == curspos && findfirst(equalto(UInt8('\n')), sbuffer) === nothing)
891+
shouldeval = (bytesavailable(sbuffer) == curspos && findfirst(equalto(UInt8('\n')), sbuffer) === nothing)
892892
seek(sbuffer, curspos)
893893
if curspos == 0
894894
# if pasting at the beginning, strip leading whitespace

base/socket.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ function TCPServer(; delay=true)
326326
return tcp
327327
end
328328

329-
isreadable(io::TCPSocket) = isopen(io) || nb_available(io) > 0
329+
isreadable(io::TCPSocket) = isopen(io) || bytesavailable(io) > 0
330330
iswritable(io::TCPSocket) = isopen(io) && io.status != StatusClosing
331331

332332
## VARIOUS METHODS TO BE MOVED TO BETTER LOCATION

0 commit comments

Comments
 (0)