Skip to content

Commit 23cb6ad

Browse files
committed
Close most issues for the windows port
Closes JuliaLang#7 Closes JuliaLang#10 Closes JuliaLang#13
1 parent ac27903 commit 23cb6ad

10 files changed

+77
-25
lines changed

.gitmodules

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
[submodule "deps/libuv"]
2-
path = deps/libuv
3-
url = https://github.com/JuliaLang/libuv.git
1+
[submodule "deps/libuv"]
2+
path = deps/libuv
3+
url = https://github.com/JuliaLang/libuv.git
4+
[submodule "deps/openlibm"]
5+
path = deps/openlibm
6+
url = https://github.com/JuliaLang/openlibm.git

base/client.jl

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function _jl_answer_color()
1515
c == "magenta" ? "\033[1m\033[35m" :
1616
c == "cyan" ? "\033[1m\033[36m" :
1717
c == "white" ? "\033[1m\033[37m" :
18+
c == "normal" ? _jl_color_normal :
1819
"\033[1m\033[34m"
1920
end
2021

base/env.jl

+33-18
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,52 @@
11
## core libc calls ##
22

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

5-
function getenv(var::String)
6-
val = ccall(:getenv, Ptr{Uint8}, (Ptr{Uint8},), var)
6+
@windows_only begin
7+
_getenvlen(var::String) = ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),var,C_NULL,0)
8+
hasenv(s::String) = false#_getenvlen(s)!=0
9+
function _jl_win_getenv(s::String,len::Uint32)
10+
val=zeros(Uint8,len)
11+
ret=ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),s,val,len)
12+
if(ret==0||ret!=len-1) #Trailing 0 is only included on first call to GetEnvA
13+
error("getenv: unknown system error: ", s, len, ret)
14+
end
15+
val
16+
end
17+
end
18+
19+
macro accessEnv(var,errorcase)
20+
@unix_only quote
21+
val=_getenv($var)
722
if val == C_NULL
8-
error("getenv: undefined variable: ", var)
23+
$errorcase
924
end
1025
cstring(val)
1126
end
27+
@windows_only quote
28+
len=_getenvlen($var)
29+
if len == 0
30+
$errorcase
31+
end
32+
cstring(convert(Ptr{Uint8},_jl_win_getenv($var,len)))
33+
end
34+
end
35+
36+
getenv(var::String) = @accessEnv var error("getenv: undefined variable: ", var)
1237

1338
function setenv(var::String, val::String, overwrite::Bool)
1439
@unix_only begin
1540
ret = ccall(:setenv, Int32, (Ptr{Uint8},Ptr{Uint8},Int32), var, val, overwrite)
1641
system_error(:setenv, ret != 0)
1742
end
1843
@windows_only begin
44+
if(overwrite||!hasenv(var))
1945
ret = ccall(:SetEnvironmentVariableA,stdcall,Int32,(Ptr{Uint8},Ptr{Uint8}),var,val)
2046
system_error(:setenv, ret == 0)
2147
end
2248
end
49+
end
2350

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

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

4168
const ENV = EnvHash()
4269

43-
function ref(::EnvHash, k::String)
44-
val = ccall(:getenv, Ptr{Uint8}, (Ptr{Uint8},), k)
45-
if val == C_NULL
46-
throw(KeyError(k))
47-
end
48-
cstring(val)
49-
end
70+
ref(::EnvHash, k::String) = @accessEnv k throw(KeyError(k))
5071

51-
function get(::EnvHash, k::String, deflt)
52-
val = ccall(:getenv, Ptr{Uint8}, (Ptr{Uint8},), k)
53-
if val == C_NULL
54-
return deflt
55-
end
56-
cstring(val)
57-
end
72+
get(::EnvHash, k::String, deflt) = @accessEnv k (return deflt)
5873

5974
has(::EnvHash, k::String) = hasenv(k)
6075
del(::EnvHash, k::String) = unsetenv(k)

base/random.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ function _jl_librandom_init()
1818
end
1919
srand(seed)
2020
end
21-
_jl_randn_zig_init()
2221
end
2322
@windows_only begin
2423
a=zeros(Uint32,2)
25-
#ccall(dlsym(_jl_advapi32,:SystemFunction036),stdcall,Uint8,(Ptr{Void},Uint64),convert(Ptr{Void},a),8)
24+
ccall(dlsym(_jl_advapi32,:SystemFunction036),stdcall,Uint8,(Ptr{Void},Uint32),convert(Ptr{Void},a),8)
2625
srand(a)
2726
end
27+
_jl_randn_zig_init()
2828
end
2929

3030
# macros to generate random arrays

base/start_image.jl

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ _jl_lib = ccall(:jl_load_dynamic_library,Ptr{Void},(Ptr{None},),C_NULL)
1010
@unix_only _jl_repl = _jl_lib
1111
@windows_only _jl_repl = ccall(:jl_wrap_raw_dl_handle,Ptr{Void},(Ptr{Void},),ccall(:GetModuleHandleA,stdcall,Ptr{Void},(Ptr{Void},),C_NULL))
1212

13+
# Set up envrionment variables
14+
@windows_only setenv("JL_ANSWER_COLOR","normal",false)
15+
1316
# Essential libraries
1417
_jl_libpcre = dlopen("libpcre")
1518
_jl_libgrisu = dlopen("libgrisu")

deps/Makefile

+24-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ GLPK_VER = 4.43
2121
JULIAHOME = $(abspath ..)
2222
include $(JULIAHOME)/Make.inc
2323

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

2626
## WGET / CURL
2727
ifeq ($(OS), Linux)
@@ -223,6 +223,28 @@ distclean-readline:
223223

224224
endif
225225

226+
# openlibm
227+
228+
ifeq ($(OS), WINNT) #needs more advanced detection once 64bit build is possible
229+
OPENLIBM_FLAGS = ARCH=i386
230+
endif
231+
232+
OPENLIBM_OBJ_TARGET = $(USRLIB)/libopenlibm.$(SHLIB_EXT)
233+
OPENLIBM_OBJ_SOURCE = openlibm/libopenlibm.$(SHLIB_EXT)
234+
235+
openlibm/Makefile:
236+
(cd .. && git submodule update --init)
237+
$(OPENLIBM_OBJ_SOURCE): openlibm/Makefile
238+
$(MAKE) -C openlibm $(OPENLIBM_FLAGS)
239+
$(OPENLIBM_OBJ_TARGET): $(OPENLIBM_OBJ_SOURCE) | $(USRLIB)
240+
cp $< $@
241+
install-openlibm: $(OPENLIBM_OBJ_TARGET)
242+
243+
clean-openlibm:
244+
$(MAKE) -C openlibm clean
245+
rm $(OPENLIBM_OBJ_TARGET)
246+
distclean-openlibm: clean-openlibm
247+
226248
## LIBUV
227249

228250
ifeq ($(OS), WINNT)
@@ -313,6 +335,7 @@ clean-double-conversion:
313335
distclean-double-conversion:
314336
rm -rf double-conversion-$(GRISU_VER).tar.gz double-conversion-$(GRISU_VER)
315337

338+
316339
## fdlibm ##
317340

318341
FDLIBM_OBJ_TARGET = $(USRLIB)/libfdm.$(SHLIB_EXT)

deps/openlibm

Submodule openlibm added at fed038b

src/ccall.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
250250
cc = CallingConv::X86_FastCall;
251251
nargs--;
252252
}
253+
else if (lhd == jl_symbol("thiscall")) {
254+
cc = CallingConv::X86_ThisCall;
255+
nargs--;
256+
}
253257
}
254258

255259
if ((!isVa && jl_tuple_len(tt) != (nargs-2)/2) ||

src/julia-parser.scm

+1-1
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@
794794
(take-token s)
795795
(let ((al (parse-arglist s #\))))
796796
(if (and (length> al 1)
797-
(memq (cadr al) '(cdecl stdcall fastcall)))
797+
(memq (cadr al) '(cdecl stdcall fastcall thiscall)))
798798
;; place (callingconv) at end of arglist
799799
`(ccall ,(car al) ,@(cddr al) (,(cadr al)))
800800
`(ccall ,.al))))

test/perf/perf.jl

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ end
131131

132132
## printfd ##
133133

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

144145
printfd(1)
145146
@timeit printfd(100000) "printfd"
147+
end

0 commit comments

Comments
 (0)