Skip to content

Commit

Permalink
Rename EnvHash to EnvDict
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Ferris committed Oct 21, 2017
1 parent f092e8f commit f9217a7
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 29 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ Deprecated or removed
* `num` and `den` have been deprecated in favor of `numerator` and `denominator` respectively ([#19233],[#19246]).
* `delete!(ENV::EnvHash, k::AbstractString, def)` has been deprecated in favor of
* `delete!(ENV::EnvDict, k::AbstractString, def)` has been deprecated in favor of
`pop!(ENV, k, def)`. Be aware that `pop!` returns `k` or `def`, whereas `delete!`
returns `ENV` or `def` ([#18012]).
Expand Down Expand Up @@ -1187,6 +1187,8 @@ Deprecated or removed
* Parsing string dates from a `Dates.DateFormat` object has been deprecated as part of a
larger effort toward faster, more extensible date parsing ([#20952]).
* `EnvHash` has been renamed to `EnvDict` ([#24167]).
Command-line option changes
---------------------------
Expand Down
5 changes: 4 additions & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const _oldstyle_array_vcat_ = false

@deprecate write(x) write(STDOUT::IO, x)

function delete!(::EnvHash, k::AbstractString, def)
function delete!(::EnvDict, k::AbstractString, def)
depwarn("`delete!(ENV, k, def)` should be replaced with `pop!(ENV, k, def)`. Be aware that `pop!` returns `k` or `def`, while `delete!` returns `ENV` or `def`.", :delete!)
haskey(ENV,k) ? delete!(ENV,k) : def
end
Expand Down Expand Up @@ -1913,6 +1913,9 @@ end
@deprecate float(x::AbstractString) parse(Float64, x)
@deprecate float(a::AbstractArray{<:AbstractString}) parse.(Float64, a)

# issue #24167
@deprecate EnvHash EnvDict

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
44 changes: 22 additions & 22 deletions base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,42 @@ end # os test
## ENV: hash interface ##

"""
EnvHash() -> EnvHash
EnvDict() -> EnvDict
A singleton of this type provides a hash table interface to environment variables.
"""
struct EnvHash <: Associative{String,String}; end
struct EnvDict <: Associative{String,String}; end

"""
ENV
Reference to the singleton `EnvHash`, providing a dictionary interface to system environment
Reference to the singleton `EnvDict`, providing a dictionary interface to system environment
variables.
"""
const ENV = EnvHash()
const ENV = EnvDict()

similar(::EnvHash) = Dict{String,String}()
similar(::EnvDict) = Dict{String,String}()

getindex(::EnvHash, k::AbstractString) = access_env(k->throw(KeyError(k)), k)
get(::EnvHash, k::AbstractString, def) = access_env(k->def, k)
get(f::Callable, ::EnvHash, k::AbstractString) = access_env(k->f(), k)
in(k::AbstractString, ::KeyIterator{EnvHash}) = _hasenv(k)
pop!(::EnvHash, k::AbstractString) = (v = ENV[k]; _unsetenv(k); v)
pop!(::EnvHash, k::AbstractString, def) = haskey(ENV,k) ? pop!(ENV,k) : def
delete!(::EnvHash, k::AbstractString) = (_unsetenv(k); ENV)
setindex!(::EnvHash, v, k::AbstractString) = _setenv(k,string(v))
push!(::EnvHash, k::AbstractString, v) = setindex!(ENV, v, k)
getindex(::EnvDict, k::AbstractString) = access_env(k->throw(KeyError(k)), k)
get(::EnvDict, k::AbstractString, def) = access_env(k->def, k)
get(f::Callable, ::EnvDict, k::AbstractString) = access_env(k->f(), k)
in(k::AbstractString, ::KeyIterator{EnvDict}) = _hasenv(k)
pop!(::EnvDict, k::AbstractString) = (v = ENV[k]; _unsetenv(k); v)
pop!(::EnvDict, k::AbstractString, def) = haskey(ENV,k) ? pop!(ENV,k) : def
delete!(::EnvDict, k::AbstractString) = (_unsetenv(k); ENV)
setindex!(::EnvDict, v, k::AbstractString) = _setenv(k,string(v))
push!(::EnvDict, k::AbstractString, v) = setindex!(ENV, v, k)

if Sys.iswindows()
start(hash::EnvHash) = (pos = ccall(:GetEnvironmentStringsW,stdcall,Ptr{UInt16},()); (pos,pos))
function done(hash::EnvHash, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
start(hash::EnvDict) = (pos = ccall(:GetEnvironmentStringsW,stdcall,Ptr{UInt16},()); (pos,pos))
function done(hash::EnvDict, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
if unsafe_load(block[1]) == 0
ccall(:FreeEnvironmentStringsW, stdcall, Int32, (Ptr{UInt16},), block[2])
return true
end
return false
end
function next(hash::EnvHash, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
function next(hash::EnvDict, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
pos = block[1]
blk = block[2]
len = ccall(:wcslen, UInt, (Ptr{UInt16},), pos)
Expand All @@ -108,10 +108,10 @@ if Sys.iswindows()
return (Pair{String,String}(m.captures[1], m.captures[2]), (pos+(len+1)*2, blk))
end
else # !windows
start(::EnvHash) = 0
done(::EnvHash, i) = (ccall(:jl_environ, Any, (Int32,), i) === nothing)
start(::EnvDict) = 0
done(::EnvDict, i) = (ccall(:jl_environ, Any, (Int32,), i) === nothing)

function next(::EnvHash, i)
function next(::EnvDict, i)
env = ccall(:jl_environ, Any, (Int32,), i)
if env === nothing
throw(BoundsError())
Expand All @@ -126,15 +126,15 @@ else # !windows
end # os-test

#TODO: Make these more efficent
function length(::EnvHash)
function length(::EnvDict)
i = 0
for (k,v) in ENV
i += 1
end
return i
end

function show(io::IO, ::EnvHash)
function show(io::IO, ::EnvDict)
for (k,v) = ENV
println(io, "$k=$v")
end
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">AbstractArray AbstractMatrix AbstractRange AbstractRemoteRef AbstractSparseMatrix AbstractString AbstractVector Any ArgumentError Array Associative BigFloat BigInt BitArray BitMatrix BitVector Bool BunchKaufman 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 RangeIndex Rational Real Regex RegexMatch RegexMatchIterator RepString RevString Reverse SVDDense Set Signed SparseMatrixCSC SpawnNullStream Stat StridedArray StridedMatrix StridedVecOrMat StridedVector String SubArray SubDArray SubOrDArray SubString SymTridiagonal Symbol SystemError Task TCPSocket TimSort Tridiagonal Tuple Type TypeError UInt UInt128 UInt16 UInt32 UInt64 UInt8 UVError Union UnitRange Unsigned VecOrMat Vector VersionNumber Void WeakKeyDict WeakRef Zip</Keywords>
<Keywords name="Keywords2">AbstractArray AbstractMatrix AbstractRange AbstractRemoteRef AbstractSparseMatrix AbstractString AbstractVector Any ArgumentError Array Associative BigFloat BigInt BitArray BitMatrix BitVector Bool BunchKaufman 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 EnvDict 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 RangeIndex Rational Real Regex RegexMatch RegexMatchIterator RepString RevString Reverse SVDDense Set Signed SparseMatrixCSC SpawnNullStream Stat StridedArray StridedMatrix StridedVecOrMat StridedVector String SubArray SubDArray SubOrDArray SubString SymTridiagonal Symbol SystemError Task TCPSocket TimSort Tridiagonal Tuple Type TypeError UInt UInt128 UInt16 UInt32 UInt64 UInt8 UVError Union UnitRange Unsigned VecOrMat Vector VersionNumber Void WeakKeyDict WeakRef Zip</Keywords>
<Keywords name="Keywords3">abstract begin baremodule primitive break catch ccall const continue do else elseif end export finally for function global if struct import importall let local macro module quote return try mutable 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: 1 addition & 1 deletion contrib/julia.lang
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
<keyword>Eigen</keyword>
<keyword>EmptyCallStack</keyword>
<keyword>Enumerate</keyword>
<keyword>EnvHash</keyword>
<keyword>EnvDict</keyword>
<keyword>Executable</keyword>
<keyword>Expr(Node)?</keyword>
<keyword>Factorization</keyword>
Expand Down
2 changes: 1 addition & 1 deletion contrib/julia.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<item> EachLine </item>
<item> Eigen </item>
<item> Enumerate </item>
<item> EnvHash </item>
<item> EnvDict </item>
<item> Exception </item>
<item> Expr </item>
<item> FileMonitor </item>
Expand Down
2 changes: 1 addition & 1 deletion doc/src/stdlib/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Base.@timev
Base.@timed
Base.@elapsed
Base.@allocated
Base.EnvHash
Base.EnvDict
Base.ENV
Base.Sys.isunix
Base.Sys.isapple
Expand Down
2 changes: 1 addition & 1 deletion doc/src/stdlib/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Partially implemented by:

* [`IntSet`](@ref)
* [`Set`](@ref)
* [`EnvHash`](@ref Base.EnvHash)
* [`EnvDict`](@ref Base.EnvDict)
* [`Array`](@ref)
* [`BitArray`](@ref)

Expand Down

0 comments on commit f9217a7

Please sign in to comment.