Skip to content

Commit

Permalink
Close most issues for the windows port
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed May 27, 2012
1 parent ac27903 commit 23cb6ad
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 25 deletions.
9 changes: 6 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "deps/libuv"]
path = deps/libuv
url = https://github.com/JuliaLang/libuv.git
[submodule "deps/libuv"]
path = deps/libuv
url = https://github.com/JuliaLang/libuv.git
[submodule "deps/openlibm"]
path = deps/openlibm
url = https://github.com/JuliaLang/openlibm.git
1 change: 1 addition & 0 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function _jl_answer_color()
c == "magenta" ? "\033[1m\033[35m" :
c == "cyan" ? "\033[1m\033[36m" :
c == "white" ? "\033[1m\033[37m" :
c == "normal" ? _jl_color_normal :
"\033[1m\033[34m"
end

Expand Down
51 changes: 33 additions & 18 deletions base/env.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
## core libc calls ##

hasenv(s::String) = ccall(:getenv, Ptr{Uint8}, (Ptr{Uint8},), s) != C_NULL
@unix_only _getenv(var::String) = ccall(:getenv, Ptr{Uint8}, (Ptr{Uint8},), var)
@unix_only hasenv(s::String) = _getenv(s) != C_NULL

function getenv(var::String)
val = ccall(:getenv, Ptr{Uint8}, (Ptr{Uint8},), var)
@windows_only begin
_getenvlen(var::String) = ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),var,C_NULL,0)
hasenv(s::String) = false#_getenvlen(s)!=0
function _jl_win_getenv(s::String,len::Uint32)
val=zeros(Uint8,len)
ret=ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),s,val,len)
if(ret==0||ret!=len-1) #Trailing 0 is only included on first call to GetEnvA
error("getenv: unknown system error: ", s, len, ret)
end
val
end
end

macro accessEnv(var,errorcase)
@unix_only quote
val=_getenv($var)
if val == C_NULL
error("getenv: undefined variable: ", var)
$errorcase
end
cstring(val)
end
@windows_only quote
len=_getenvlen($var)
if len == 0
$errorcase
end
cstring(convert(Ptr{Uint8},_jl_win_getenv($var,len)))
end
end

getenv(var::String) = @accessEnv var error("getenv: undefined variable: ", var)

function setenv(var::String, val::String, overwrite::Bool)
@unix_only begin
ret = ccall(:setenv, Int32, (Ptr{Uint8},Ptr{Uint8},Int32), var, val, overwrite)
system_error(:setenv, ret != 0)
end
@windows_only begin
if(overwrite||!hasenv(var))
ret = ccall(:SetEnvironmentVariableA,stdcall,Int32,(Ptr{Uint8},Ptr{Uint8}),var,val)
system_error(:setenv, ret == 0)
end
end
end

setenv(var::String, val::String) = setenv(var, val, true)

Expand All @@ -40,21 +67,9 @@ type EnvHash <: Associative{ByteString,ByteString}; end

const ENV = EnvHash()

function ref(::EnvHash, k::String)
val = ccall(:getenv, Ptr{Uint8}, (Ptr{Uint8},), k)
if val == C_NULL
throw(KeyError(k))
end
cstring(val)
end
ref(::EnvHash, k::String) = @accessEnv k throw(KeyError(k))

function get(::EnvHash, k::String, deflt)
val = ccall(:getenv, Ptr{Uint8}, (Ptr{Uint8},), k)
if val == C_NULL
return deflt
end
cstring(val)
end
get(::EnvHash, k::String, deflt) = @accessEnv k (return deflt)

has(::EnvHash, k::String) = hasenv(k)
del(::EnvHash, k::String) = unsetenv(k)
Expand Down
4 changes: 2 additions & 2 deletions base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ function _jl_librandom_init()
end
srand(seed)
end
_jl_randn_zig_init()
end
@windows_only begin
a=zeros(Uint32,2)
#ccall(dlsym(_jl_advapi32,:SystemFunction036),stdcall,Uint8,(Ptr{Void},Uint64),convert(Ptr{Void},a),8)
ccall(dlsym(_jl_advapi32,:SystemFunction036),stdcall,Uint8,(Ptr{Void},Uint32),convert(Ptr{Void},a),8)
srand(a)
end
_jl_randn_zig_init()
end

# macros to generate random arrays
Expand Down
3 changes: 3 additions & 0 deletions base/start_image.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ _jl_lib = ccall(:jl_load_dynamic_library,Ptr{Void},(Ptr{None},),C_NULL)
@unix_only _jl_repl = _jl_lib
@windows_only _jl_repl = ccall(:jl_wrap_raw_dl_handle,Ptr{Void},(Ptr{Void},),ccall(:GetModuleHandleA,stdcall,Ptr{Void},(Ptr{Void},),C_NULL))

# Set up envrionment variables
@windows_only setenv("JL_ANSWER_COLOR","normal",false)

# Essential libraries
_jl_libpcre = dlopen("libpcre")
_jl_libgrisu = dlopen("libgrisu")
Expand Down
25 changes: 24 additions & 1 deletion deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GLPK_VER = 4.43
JULIAHOME = $(abspath ..)
include $(JULIAHOME)/Make.inc

LIBS = uv fdlibm dsfmt rmath double-conversion amos suitesparse-wrapper gmp-wrapper
LIBS = uv fdlibm dsfmt rmath double-conversion amos suitesparse-wrapper gmp-wrapper openlibm

## WGET / CURL
ifeq ($(OS), Linux)
Expand Down Expand Up @@ -223,6 +223,28 @@ distclean-readline:

endif

# openlibm

ifeq ($(OS), WINNT) #needs more advanced detection once 64bit build is possible
OPENLIBM_FLAGS = ARCH=i386
endif

OPENLIBM_OBJ_TARGET = $(USRLIB)/libopenlibm.$(SHLIB_EXT)
OPENLIBM_OBJ_SOURCE = openlibm/libopenlibm.$(SHLIB_EXT)

openlibm/Makefile:
(cd .. && git submodule update --init)
$(OPENLIBM_OBJ_SOURCE): openlibm/Makefile
$(MAKE) -C openlibm $(OPENLIBM_FLAGS)
$(OPENLIBM_OBJ_TARGET): $(OPENLIBM_OBJ_SOURCE) | $(USRLIB)
cp $< $@
install-openlibm: $(OPENLIBM_OBJ_TARGET)

clean-openlibm:
$(MAKE) -C openlibm clean
rm $(OPENLIBM_OBJ_TARGET)
distclean-openlibm: clean-openlibm

## LIBUV

ifeq ($(OS), WINNT)
Expand Down Expand Up @@ -313,6 +335,7 @@ clean-double-conversion:
distclean-double-conversion:
rm -rf double-conversion-$(GRISU_VER).tar.gz double-conversion-$(GRISU_VER)


## fdlibm ##

FDLIBM_OBJ_TARGET = $(USRLIB)/libfdm.$(SHLIB_EXT)
Expand Down
1 change: 1 addition & 0 deletions deps/openlibm
Submodule openlibm added at fed038
4 changes: 4 additions & 0 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
cc = CallingConv::X86_FastCall;
nargs--;
}
else if (lhd == jl_symbol("thiscall")) {
cc = CallingConv::X86_ThisCall;
nargs--;
}
}

if ((!isVa && jl_tuple_len(tt) != (nargs-2)/2) ||
Expand Down
2 changes: 1 addition & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@
(take-token s)
(let ((al (parse-arglist s #\))))
(if (and (length> al 1)
(memq (cadr al) '(cdecl stdcall fastcall)))
(memq (cadr al) '(cdecl stdcall fastcall thiscall)))
;; place (callingconv) at end of arglist
`(ccall ,(car al) ,@(cddr al) (,(cadr al)))
`(ccall ,.al))))
Expand Down
2 changes: 2 additions & 0 deletions test/perf/perf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ end

## printfd ##

@unix_only begin
function printfd(n)
f = open("/dev/null","w")
for i = 1:n
Expand All @@ -143,3 +144,4 @@ end

printfd(1)
@timeit printfd(100000) "printfd"
end

0 comments on commit 23cb6ad

Please sign in to comment.