diff --git a/base/c.jl b/base/c.jl index 89717ce2d9dde..4c70659ba0f63 100644 --- a/base/c.jl +++ b/base/c.jl @@ -12,10 +12,12 @@ const RTLD_NOLOAD = 0x00000010 const RTLD_DEEPBIND = 0x00000020 const RTLD_FIRST = 0x00000040 -dlsym(hnd, s::Union(Symbol,String)) = ccall(:jl_dlsym, Ptr{Void}, (Ptr{Void}, Ptr{Uint8}), hnd, s) -dlsym_e(hnd, s::Union(Symbol,String)) = ccall(:jl_dlsym_e, Ptr{Void}, (Ptr{Void}, Ptr{Uint8}), hnd, s) -dlopen(s::String, flags::Integer) = ccall(:jl_load_dynamic_library, Ptr{Void}, (Ptr{Uint8},Uint32), s, flags) -dlopen_e(s::String, flags::Integer) = ccall(:jl_load_dynamic_library_e, Ptr{Void}, (Ptr{Uint8},Uint32), s, flags) +dlsym(hnd, s::Union(Symbol,ByteString)) = ccall(:jl_dlsym, Ptr{Void}, (Ptr{Void}, Ptr{Uint8}), hnd, s) +dlsym_e(hnd, s::Union(Symbol,ByteString)) = ccall(:jl_dlsym_e, Ptr{Void}, (Ptr{Void}, Ptr{Uint8}), hnd, s) +dlsym(hnd, s::String) = dlsym(hnd, bytestring(s)) +dlsym_e(hnd, s::String) = dlsym_e(hnd, bytestring(s)) +dlopen(s::String, flags::Integer) = ccall(:jl_load_dynamic_library, Ptr{Void}, (Ptr{Uint8},Uint32), bytestring(s), flags) +dlopen_e(s::String, flags::Integer) = ccall(:jl_load_dynamic_library_e, Ptr{Void}, (Ptr{Uint8},Uint32), bytestring(s), flags) dlopen(s::String) = dlopen(s, RTLD_LAZY | RTLD_DEEPBIND) dlopen_e(s::String) = dlopen_e(s, RTLD_LAZY | RTLD_DEEPBIND) dlclose(p::Ptr) = if p!=C_NULL; ccall(:uv_dlclose,Void,(Ptr{Void},),p); end diff --git a/base/client.jl b/base/client.jl index d33b0f8e8ce8c..0dc82e3766801 100644 --- a/base/client.jl +++ b/base/client.jl @@ -197,7 +197,7 @@ function parse_input_line(s::String) # throw(ParseError("extra input after end of expression")) # end # expr - ccall(:jl_parse_input_line, Any, (Ptr{Uint8},), s) + ccall(:jl_parse_input_line, Any, (Ptr{Uint8},), bytestring(s)) end function parse_input_line(io::IO) diff --git a/base/env.jl b/base/env.jl index 3d62e5b34f110..0b25a5f0bd238 100644 --- a/base/env.jl +++ b/base/env.jl @@ -1,15 +1,16 @@ ## core libc calls ## @unix_only begin - _getenv(var::String) = ccall(:getenv, Ptr{Uint8}, (Ptr{Uint8},), var) + _getenv(var::String) = ccall(:getenv, Ptr{Uint8}, (Ptr{Uint8},), + bytestring(var)) _hasenv(s::String) = _getenv(s) != C_NULL end @windows_only begin -_getenvlen(var::String) = ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),var,C_NULL,0) +_getenvlen(var::String) = ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),bytestring(var),C_NULL,0) _hasenv(s::String) = _getenvlen(s)!=0 function _jl_win_getenv(s::String,len::Uint32) val=zeros(Uint8,len-1) - ret=ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),s,val,len) + ret=ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),bytestring(s),val,len) if ret==0||ret!=len-1 #Trailing 0 is only included on first call to GetEnvA error("unknown system error: ", s, len, ret) end @@ -37,12 +38,13 @@ end function _setenv(var::String, val::String, overwrite::Bool) @unix_only begin - ret = ccall(:setenv, Int32, (Ptr{Uint8},Ptr{Uint8},Int32), var, val, overwrite) + ret = ccall(:setenv, Int32, (Ptr{Uint8},Ptr{Uint8},Int32), + bytestring(var), bytestring(val), overwrite) systemerror(:setenv, ret != 0) end @windows_only begin if overwrite||!_hasenv(var) - ret = ccall(:SetEnvironmentVariableA,stdcall,Int32,(Ptr{Uint8},Ptr{Uint8}),var,val) + ret = ccall(:SetEnvironmentVariableA,stdcall,Int32,(Ptr{Uint8},Ptr{Uint8}),bytestring(var),bytestring(val)) systemerror(:setenv, ret == 0) end end @@ -52,11 +54,11 @@ _setenv(var::String, val::String) = _setenv(var, val, true) function _unsetenv(var::String) @unix_only begin - ret = ccall(:unsetenv, Int32, (Ptr{Uint8},), var) + ret = ccall(:unsetenv, Int32, (Ptr{Uint8},), bytestring(var)) systemerror(:unsetenv, ret != 0) end @windows_only begin - ret = ccall(:SetEnvironmentVariableA,stdcall,Int32,(Ptr{Uint8},Ptr{Uint8}),var,C_NULL) + ret = ccall(:SetEnvironmentVariableA,stdcall,Int32,(Ptr{Uint8},Ptr{Uint8}),bytestring(var),C_NULL) systemerror(:setenv, ret == 0) end end diff --git a/base/file.jl b/base/file.jl index 786faa94d4282..08fca110e3e71 100644 --- a/base/file.jl +++ b/base/file.jl @@ -9,8 +9,8 @@ function pwd() end function cd(dir::String) - @windows_only systemerror("chdir $dir", ccall(:_chdir,Int32,(Ptr{Uint8},),dir) == -1) - @unix_only systemerror("chdir $dir", ccall(:chdir,Int32,(Ptr{Uint8},),dir) == -1) + @windows_only systemerror("chdir $dir", ccall(:_chdir,Int32,(Ptr{Uint8},),bytestring(dir)) == -1) + @unix_only systemerror("chdir $dir", ccall(:chdir,Int32,(Ptr{Uint8},),bytestring(dir)) == -1) end cd() = cd(homedir()) @@ -100,7 +100,7 @@ end GetTempFileName(uunique::Uint32) = GetTempFileName(GetTempPath(), uunique) function GetTempFileName(temppath::String,uunique::Uint32) tname = Array(Uint8,261) - uunique = ccall(:GetTempFileNameA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32,Ptr{Uint8}),temppath,"julia",uunique,tname) + uunique = ccall(:GetTempFileNameA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32,Ptr{Uint8}),bytestring(temppath),"julia",uunique,tname) lentname = findfirst(tname,0)-1 if uunique == 0 || lentname <= 0 error("GetTempFileName failed") diff --git a/base/fs.jl b/base/fs.jl index 2da47ee9e5c2b..33f228d7a3f07 100644 --- a/base/fs.jl +++ b/base/fs.jl @@ -106,8 +106,8 @@ end # For move command function rename(src::String, dst::String) - err = ccall(:jl_fs_rename, Int32, (Ptr{Uint8}, Ptr{Uint8}), bytestring(src), - bytestring(dst)) + err = ccall(:jl_fs_rename, Int32, (Ptr{Uint8}, Ptr{Uint8}), + bytestring(src), bytestring(dst)) # on error, default to cp && rm if err < 0 diff --git a/base/io.jl b/base/io.jl index 32322e55f1e22..f5180b249bde5 100644 --- a/base/io.jl +++ b/base/io.jl @@ -351,7 +351,7 @@ function open(fname::String, rd::Bool, wr::Bool, cr::Bool, tr::Bool, ff::Bool) systemerror("opening file $fname", ccall(:ios_file, Ptr{Void}, (Ptr{Uint8}, Ptr{Uint8}, Int32, Int32, Int32, Int32), - s.ios, fname, rd, wr, cr, tr) == C_NULL) + s.ios, bytestring(fname), rd, wr, cr, tr) == C_NULL) if ff systemerror("seeking to end of file $fname", ccall(:ios_seek_end, FileOffset, (Ptr{Void},), s.ios) != 0) end diff --git a/base/libc.jl b/base/libc.jl index bfa0b7446e6d5..46d1b692acac8 100644 --- a/base/libc.jl +++ b/base/libc.jl @@ -34,22 +34,22 @@ type TmStruct end strftime(t) = strftime("%c", t) -strftime(fmt::ByteString, t::Real) = strftime(fmt, TmStruct(t)) -function strftime(fmt::ByteString, tm::TmStruct) +strftime(fmt::String, t::Real) = strftime(fmt, TmStruct(t)) +function strftime(fmt::String, tm::TmStruct) timestr = Array(Uint8, 128) n = ccall(:strftime, Int, (Ptr{Uint8}, Int, Ptr{Uint8}, Ptr{Void}), - timestr, length(timestr), fmt, &tm) + timestr, length(timestr), bytestring(fmt), &tm) if n == 0 return "" end bytestring(convert(Ptr{Uint8},timestr)) end -strptime(timestr::ByteString) = strptime("%c", timestr) -function strptime(fmt::ByteString, timestr::ByteString) +strptime(timestr::String) = strptime("%c", timestr) +function strptime(fmt::String, timestr::String) tm = TmStruct() r = ccall(:strptime, Ptr{Uint8}, (Ptr{Uint8}, Ptr{Uint8}, Ptr{Void}), - timestr, fmt, &tm) + bytestring(timestr), bytestring(fmt), &tm) # the following would tell mktime() that this is a local time, and that # it should try to guess the timezone. not sure if/how this should be # exposed in the API. diff --git a/base/loading.jl b/base/loading.jl index d5bbd6c37ae1c..fd4eed8821321 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -86,10 +86,11 @@ end # remote/parallel load -include_string(txt::ByteString, fname::ByteString) = - ccall(:jl_load_file_string, Any, (Ptr{Uint8},Ptr{Uint8}), txt, fname) +include_string(txt::String, fname::String) = + ccall(:jl_load_file_string, Any, (Ptr{Uint8},Ptr{Uint8}), + bytestring(txt), bytestring(fname)) -include_string(txt::ByteString) = include_string(txt, "string") +include_string(txt::String) = include_string(txt, "string") function source_path(default::Union(String,Nothing)="") t = current_task() diff --git a/base/mpfr.jl b/base/mpfr.jl index e69f6b8f95abc..984db9004911b 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -64,7 +64,7 @@ end function BigFloat(x::String, base::Int) z = BigFloat() - err = ccall((:mpfr_set_str, :libmpfr), Int32, (Ptr{BigFloat}, Ptr{Uint8}, Int32, Int32), &z, x, base, ROUNDING_MODE[end]) + err = ccall((:mpfr_set_str, :libmpfr), Int32, (Ptr{BigFloat}, Ptr{Uint8}, Int32, Int32), &z, bytestring(x), base, ROUNDING_MODE[end]) if err != 0; error("incorrectly formatted number"); end return z end diff --git a/base/path.jl b/base/path.jl index 7ccbe93738ad2..e24fefc918592 100644 --- a/base/path.jl +++ b/base/path.jl @@ -109,21 +109,23 @@ abspath(a::String, b::String...) = abspath(joinpath(a,b...)) @windows_only function realpath(path::String) buflength = length(path)+1 buf = zeros(Uint8,buflength) + bpath = bytestring(path) p = ccall((:GetFullPathNameA, "Kernel32"), stdcall, Uint32, (Ptr{Uint8}, Uint32, Ptr{Uint8}, Ptr{Void}), - path, buflength, buf, C_NULL) + bpath, buflength, buf, C_NULL) if p > buflength buf = zeros(Uint8,p) p = ccall((:GetFullPathNameA, "Kernel32"), stdcall, Uint32, (Ptr{Uint8}, Uint32, Ptr{Uint8}, Ptr{Void}), - path, p, buf, C_NULL) + bpath, p, buf, C_NULL) end systemerror(:realpath, p == 0) return bytestring(buf)[1:end-1] end @unix_only function realpath(path::String) - p = ccall(:realpath, Ptr{Uint8}, (Ptr{Uint8}, Ptr{Uint8}), path, C_NULL) + p = ccall(:realpath, Ptr{Uint8}, (Ptr{Uint8}, Ptr{Uint8}), + bytestring(path), C_NULL) systemerror(:realpath, p == C_NULL) s = bytestring(p) c_free(p) diff --git a/base/pcre.jl b/base/pcre.jl index 8ff53d6e3f689..b429437a72411 100644 --- a/base/pcre.jl +++ b/base/pcre.jl @@ -79,7 +79,7 @@ function compile(pattern::String, options::Integer) erroff = Array(Int32,1) re_ptr = ccall((:pcre_compile, :libpcre), Ptr{Void}, (Ptr{Uint8}, Int32, Ptr{Ptr{Uint8}}, Ptr{Int32}, Ptr{Uint8}), - pattern, options, errstr, erroff, C_NULL) + bytestring(pattern), options, errstr, erroff, C_NULL) if re_ptr == C_NULL error("$(bytestring(errstr[1]))", " at position $(erroff[1]+1)", diff --git a/base/poll.jl b/base/poll.jl index 8d0095d736a42..367b66841b2f5 100644 --- a/base/poll.jl +++ b/base/poll.jl @@ -5,7 +5,7 @@ type FileMonitor notify::Condition function FileMonitor(cb, file) handle = c_malloc(_sizeof_uv_fs_event) - err = ccall(:jl_fs_event_init,Int32, (Ptr{Void}, Ptr{Void}, Ptr{Uint8}, Int32), eventloop(),handle,file,0) + err = ccall(:jl_fs_event_init,Int32, (Ptr{Void}, Ptr{Void}, Ptr{Uint8}, Int32), eventloop(),handle,bytestring(file),0) if err < 0 c_free(handle) throw(UVError("FileMonitor",err)) @@ -250,7 +250,7 @@ function start_watching(t::PollingFileWatcher, interval) associate_julia_struct(t.handle, t) uv_error("start_watching (File)", ccall(:jl_fs_poll_start, Int32, (Ptr{Void},Ptr{Uint8},Uint32), - t.handle, t.file, iround(interval*1000))) + t.handle, bytestring(t.file), iround(interval*1000))) end start_watching(f::Function, t::PollingFileWatcher, interval) = (t.cb = f;start_watching(t,interval)) diff --git a/base/string.jl b/base/string.jl index cd31504a92912..edcf0fce0c7c4 100644 --- a/base/string.jl +++ b/base/string.jl @@ -1200,7 +1200,7 @@ function parse(str::String, pos::Int; greedy::Bool=true, raise::Bool=true) # returns (expr, end_pos). expr is () in case of parse error. ex, pos = ccall(:jl_parse_string, Any, (Ptr{Uint8}, Int32, Int32), - str, pos-1, greedy ? 1:0) + bytestring(str), pos-1, greedy ? 1:0) if raise && isa(ex,Expr) && is(ex.head,:error) throw(ParseError(ex.args[1])) end @@ -1542,9 +1542,9 @@ string(x::Union(Int8,Int16,Int32,Int64,Int128)) = dec(x) ## string to float functions ## float64_isvalid(s::String, out::Array{Float64,1}) = - ccall(:jl_strtod, Int32, (Ptr{Uint8},Ptr{Float64}), s, out) == 0 + ccall(:jl_strtod, Int32, (Ptr{Uint8},Ptr{Float64}), bytestring(s),out) == 0 float32_isvalid(s::String, out::Array{Float32,1}) = - ccall(:jl_strtof, Int32, (Ptr{Uint8},Ptr{Float32}), s, out) == 0 + ccall(:jl_strtof, Int32, (Ptr{Uint8},Ptr{Float32}), bytestring(s),out) == 0 float64_isvalid(s::SubString, out::Array{Float64,1}) = ccall(:jl_substrtod, Int32, (Ptr{Uint8},Csize_t,Int,Ptr{Float64}), s.string, convert(Csize_t,s.offset), s.endof, out) == 0 diff --git a/base/util.jl b/base/util.jl index 0083e1b2ef685..6c4be11b2586a 100644 --- a/base/util.jl +++ b/base/util.jl @@ -259,13 +259,13 @@ end end @windows_only begin - function clipboard(x::ByteString) + function clipboard(x::String) ccall((:OpenClipboard, "user32"), stdcall, Bool, (Ptr{Void},), C_NULL) ccall((:EmptyClipboard, "user32"), stdcall, Bool, ()) p = ccall((:GlobalAlloc, "kernel32"), stdcall, Ptr{Void}, (Uint16,Int32), 2, length(x)+1) p = ccall((:GlobalLock, "kernel32"), stdcall, Ptr{Void}, (Ptr{Void},), p) # write data to locked, allocated space - ccall(:memcpy, Ptr{Void}, (Ptr{Void},Ptr{Uint8},Int32), p, x, length(x)+1) + ccall(:memcpy, Ptr{Void}, (Ptr{Void},Ptr{Uint8},Int32), p, bytestring(x), length(x)+1) ccall((:GlobalUnlock, "kernel32"), stdcall, Void, (Ptr{Void},), p) # set clipboard data type to 13 for Unicode text/string p = ccall((:SetClipboardData, "user32"), stdcall, Ptr{Void}, (Uint32, Ptr{Void}), 1, p) diff --git a/test/strings.jl b/test/strings.jl index f92043674866f..48b6a48e579ee 100644 --- a/test/strings.jl +++ b/test/strings.jl @@ -850,7 +850,6 @@ bin_val = hex2bytes("07bf") # issue #4586 @test rsplit(RevString("ailuj"),'l') == {"ju","ia"} -@test_throws float64(RevString("64")) for T = (Uint8,Int8,Uint16,Int16,Uint32,Int32,Uint64,Int64,Uint128,Int128,BigInt), b = 2:62, _ = 1:10