Skip to content

Commit

Permalink
remove all platform-specific code from Core.Inference and further shr…
Browse files Browse the repository at this point in the history
…ink its size
  • Loading branch information
vtjnash authored and ihnorton committed May 20, 2015
1 parent 469f699 commit 7d8d76d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 33 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ CORE_SRCS := base/boot.jl base/coreimg.jl \
base/array.jl \
base/bool.jl \
base/build_h.jl \
base/c.jl \
base/dict.jl \
base/error.jl \
base/essentials.jl \
Expand All @@ -164,13 +163,11 @@ CORE_SRCS := base/boot.jl base/coreimg.jl \
base/number.jl \
base/operators.jl \
base/options.jl \
base/osutils.jl \
base/pointer.jl \
base/promotion.jl \
base/range.jl \
base/reduce.jl \
base/reflection.jl \
base/refpointer.jl \
base/subarray.jl \
base/subarray2.jl \
base/tuple.jl
Expand Down
8 changes: 8 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ map{T<:Real}(::Type{T}, r::StepRange) = T(r.start):T(r.step):T(last(r))
map{T<:Real}(::Type{T}, r::UnitRange) = T(r.start):T(last(r))
map{T<:FloatingPoint}(::Type{T}, r::FloatRange) = FloatRange(T(r.start), T(r.step), r.len, T(r.divisor))

## unsafe/pointer conversions ##

# note: the following type definitions don't mean any AbstractArray is convertible to
# a data Ref. they just map the array element type to the pointer type for
# convenience in cases that work.
pointer{T}(x::AbstractArray{T}) = unsafe_convert(Ptr{T}, x)
pointer{T}(x::AbstractArray{T}, i::Integer) = unsafe_convert(Ptr{T},x) + (i-1)*elsize(x)

## Unary operators ##

conj{T<:Real}(x::AbstractArray{T}) = x
Expand Down
4 changes: 4 additions & 0 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ end
convert{T<:Union(Int8,UInt8)}(::Type{Cstring}, p::Ptr{T}) = box(Cstring, unbox(Ptr{T}, p))
convert(::Type{Cwstring}, p::Ptr{Cwchar_t}) = box(Cwstring, unbox(Ptr{Cwchar_t}, p))

# convert strings to ByteString etc. to pass as pointers
cconvert(::Type{Cstring}, s::AbstractString) = bytestring(s)
cconvert(::Type{Cwstring}, s::AbstractString) = wstring(s)

containsnul(p::Ptr, len) = C_NULL != ccall(:memchr, Ptr{Cchar}, (Ptr{Cchar}, Cint, Csize_t), p, 0, len)
function unsafe_convert(::Type{Cstring}, s::ByteString)
p = unsafe_convert(Ptr{Cchar}, s)
Expand Down
8 changes: 2 additions & 6 deletions base/coreimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ print(a::ANY...) = for x=a; print(x); end
include("essentials.jl")
include("reflection.jl")
include("build_h.jl")
include("c.jl")
include("options.jl")

# core operations & types
typealias Cint Int32
typealias Csize_t UInt
include("promotion.jl")
include("tuple.jl")
include("range.jl")
Expand All @@ -37,7 +38,6 @@ include("number.jl")
include("int.jl")
include("operators.jl")
include("pointer.jl")
include("refpointer.jl")

# core array operations
include("abstractarray.jl")
Expand Down Expand Up @@ -78,9 +78,5 @@ precompile(occurs_undef, (Symbol, Expr))
precompile(sym_replace, (UInt8, Array{Any,1}, Array{Any,1}, Array{Any,1}, Array{Any,1}))
precompile(symequal, (Symbol, Symbol))

# For OS specific stuff in I/O
# to force compile of inference
include("osutils.jl")

end # baremodule Inference
))
24 changes: 12 additions & 12 deletions base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
# NOTE: This type needs to be kept in sync with jl_options in src/julia.h
immutable JLOptions
quiet::Int8
julia_home::Ptr{Cchar}
julia_bin::Ptr{Cchar}
build_path::Ptr{Cchar}
eval::Ptr{Cchar}
print::Ptr{Cchar}
postboot::Ptr{Cchar}
load::Ptr{Cchar}
image_file::Ptr{Cchar}
cpu_target::Ptr{Cchar}
nprocs::Clong
machinefile::Ptr{Cchar}
julia_home::Ptr{UInt8}
julia_bin::Ptr{UInt8}
build_path::Ptr{UInt8}
eval::Ptr{UInt8}
print::Ptr{UInt8}
postboot::Ptr{UInt8}
load::Ptr{UInt8}
image_file::Ptr{UInt8}
cpu_target::Ptr{UInt8}
nprocs::Int32
machinefile::Ptr{UInt8}
isinteractive::Int8
color::Int8
historyfile::Int8
Expand All @@ -28,7 +28,7 @@ immutable JLOptions
can_inline::Int8
fast_math::Int8
worker::Int8
bindto::Ptr{Cchar}
bindto::Ptr{UInt8}
end

JLOptions() = unsafe_load(cglobal(:jl_options, JLOptions))
2 changes: 0 additions & 2 deletions base/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ unsafe_convert(::Type{Ptr{Int8}}, s::ByteString) = convert(Ptr{Int8}, unsafe_con
# convert strings to ByteString etc. to pass as pointers
cconvert(::Type{Ptr{UInt8}}, s::AbstractString) = bytestring(s)
cconvert(::Type{Ptr{Int8}}, s::AbstractString) = bytestring(s)
cconvert(::Type{Cstring}, s::AbstractString) = bytestring(s)
cconvert(::Type{Cwstring}, s::AbstractString) = wstring(s)

unsafe_convert{T}(::Type{Ptr{T}}, a::Array{T}) = ccall(:jl_array_ptr, Ptr{T}, (Any,), a)
unsafe_convert(::Type{Ptr{Void}}, a::Array) = ccall(:jl_array_ptr, Ptr{Void}, (Any,), a)
Expand Down
7 changes: 0 additions & 7 deletions base/refpointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ end
unsafe_convert{T}(::Type{Ptr{Void}}, b::RefValue{T}) = convert(Ptr{Void}, unsafe_convert(Ptr{T}, b))

### Methods for a Ref object that is backed by an array at index i

# note: the following type definitions don't mean any AbstractArray is convertible to
# a data Ref. they just map the array element type to the pointer type for
# convenience in cases that work.
pointer{T}(x::AbstractArray{T}) = unsafe_convert(Ptr{T}, x)
pointer{T}(x::AbstractArray{T}, i::Integer) = unsafe_convert(Ptr{T},x) + (i-1)*elsize(x)

immutable RefArray{T, A<:AbstractArray, R} <: Ref{T}
x::A
i::Int
Expand Down
2 changes: 1 addition & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ typedef struct {
const char *load;
const char *image_file;
const char *cpu_target;
long nprocs;
int32_t nprocs;
const char *machinefile;
int8_t isinteractive;
int8_t color;
Expand Down
5 changes: 3 additions & 2 deletions ui/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ void parse_opts(int *argcp, char ***argvp)
jl_options.nprocs = jl_cpu_cores();
}
else {
jl_options.nprocs = strtol(optarg, &endptr, 10);
if (errno != 0 || optarg == endptr || *endptr != 0 || jl_options.nprocs < 1)
long nprocs = strtol(optarg, &endptr, 10);
if (errno != 0 || optarg == endptr || *endptr != 0 || nprocs < 1 || nprocs >= INT_MAX)
jl_errorf("julia: -p,--procs=<n> must be an integer >= 1\n");
jl_options.nprocs = (int)nprocs;
}
break;
case opt_machinefile:
Expand Down

0 comments on commit 7d8d76d

Please sign in to comment.