Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename `cstring` to `bytestring` and restrict it to be used on strings

`bytestring` has two definitions:
 1. Turn a pointer to a string to a proper ByteString
 2. Turn a T<:String into ByteString to be used e.g. in ccall

All other uses are now disallowed
  • Loading branch information...
commit 213f1a15cc07c49a3a06721f00e60f13a7ad61f5 1 parent 53f1ba9
@Keno Keno authored
View
2  base/ascii.jl
@@ -77,4 +77,4 @@ ascii(x) = convert(ASCIIString, x)
convert(::Type{ASCIIString}, s::ASCIIString) = s
convert(::Type{ASCIIString}, s::UTF8String) = ascii(s.data)
convert(::Type{ASCIIString}, a::Array{Uint8,1}) = check_ascii(ASCIIString(a))
-convert(::Type{ASCIIString}, s::String) = ascii(cstring(s))
+convert(::Type{ASCIIString}, s::String) = ascii(bytestring(s))
View
2  base/base.jl
@@ -100,7 +100,7 @@ gc_disable() = ccall(:jl_gc_disable, Void, ())
current_task() = ccall(:jl_get_current_task, Task, ())
istaskdone(t::Task) = t.done
-cstring(str::ByteString) = str
+bytestring(str::ByteString) = str
# return an integer such that object_id(x)==object_id(y) if is(x,y)
object_id(x::ANY) = ccall(:jl_object_id, Uint, (Any,), x)
View
2  base/client.jl
@@ -108,7 +108,7 @@ function run_repl()
end
function parse_input_line(s::String)
- # s = cstring(s)
+ # s = bytestring(s)
# (expr, pos) = parse(s, 1, true)
# (ex, pos) = ccall(:jl_parse_string, Any,
# (Ptr{Uint8},Int32,Int32),
View
6 base/env.jl
@@ -7,7 +7,7 @@ function getenv(var::String)
if val == C_NULL
error("getenv: undefined variable: ", var)
end
- cstring(val)
+ bytestring(val)
end
function setenv(var::String, val::String, overwrite::Bool)
@@ -45,7 +45,7 @@ function ref(::EnvHash, k::String)
if val == C_NULL
throw(KeyError(k))
end
- cstring(val)
+ bytestring(val)
end
function get(::EnvHash, k::String, deflt)
@@ -53,7 +53,7 @@ function get(::EnvHash, k::String, deflt)
if val == C_NULL
return deflt
end
- cstring(val)
+ bytestring(val)
end
has(::EnvHash, k::String) = hasenv(k)
View
4 base/error.jl
@@ -2,7 +2,7 @@
error(e::Exception) = throw(e)
error{E<:Exception}(::Type{E}) = throw(E())
-error(s...) = throw(ErrorException(cstring(s...)))
+error(s...) = throw(ErrorException(bytestring(s...)))
macro unexpected()
:(error("unexpected branch reached"))
@@ -13,7 +13,7 @@ end
errno() = ccall(:jl_errno, Int32, ())
strerror(e::Integer) = ccall(:jl_strerror, Any, (Int32,), e)::ByteString
strerror() = strerror(errno())
-system_error(p, b::Bool) = b ? throw(SystemError(cstring(p))) : nothing
+system_error(p, b::Bool) = b ? throw(SystemError(bytestring(p))) : nothing
## assertion functions and macros ##
View
4 base/file.jl
@@ -155,7 +155,7 @@ function real_path(fname::String)
fname = tilde_expand(fname)
sp = ccall(:realpath, Ptr{Uint8}, (Ptr{Uint8}, Ptr{Uint8}), fname, C_NULL)
system_error(:real_path, sp == C_NULL)
- s = cstring(sp)
+ s = bytestring(sp)
ccall(:free, Void, (Ptr{Uint8},), sp)
return s
end
@@ -166,7 +166,7 @@ function cwd()
b = Array(Uint8,1024)
p = ccall(:getcwd, Ptr{Uint8}, (Ptr{Uint8}, Uint), b, length(b))
system_error("getcwd", p == C_NULL)
- cstring(p)
+ bytestring(p)
end
cd(dir::String) = system_error("chdir", ccall(:chdir,Int32,(Ptr{Uint8},),dir) == -1)
View
8 base/libc.jl
@@ -13,7 +13,7 @@ function strftime(fmt::ByteString, t)
if n == 0
return ""
end
- cstring(convert(Ptr{Uint8},timestr))
+ bytestring(convert(Ptr{Uint8},timestr))
end
strptime(timestr::ByteString) = strptime("%c", timestr)
@@ -37,18 +37,18 @@ system(cmd::String) = int(ccall(:system, Int32, (Ptr{Uint8},), cmd))
function gethostname()
hn = Array(Uint8, 128)
ccall(:gethostname, Int32, (Ptr{Uint8}, Uint), hn, length(hn))
- cstring(convert(Ptr{Uint8},hn))
+ bytestring(convert(Ptr{Uint8},hn))
end
function getipaddr()
ip = Array(Uint8, 128)
ccall(:getlocalip, Void, (Ptr{Uint8}, Uint), ip, length(ip))
- cstring(convert(Ptr{Uint8},ip))
+ bytestring(convert(Ptr{Uint8},ip))
end
## get a temporary file name ##
-tmpnam() = cstring(ccall(:tmpnam, Ptr{Uint8}, (Ptr{Uint8},), C_NULL))
+tmpnam() = bytestring(ccall(:tmpnam, Ptr{Uint8}, (Ptr{Uint8},), C_NULL))
## Memory related ##
View
2  base/multi.jl
@@ -1078,7 +1078,7 @@ function start_sge_workers(n)
sleep(0.5)
end
end
- hostname = cstring(readline(fl)[1:end-1])
+ hostname = bytestring(readline(fl)[1:end-1])
#print("hostname=$hostname, port=$port\n")
workers[i] = Worker(hostname, port)
close(fl)
View
2  base/pcre.jl
@@ -8,7 +8,7 @@ global info, compile, study, exec
include("pcre_h.jl")
-const VERSION = cstring(ccall(dlsym(Base.libpcre, :pcre_version), Ptr{Uint8}, ()))
+const VERSION = bytestring(ccall(dlsym(Base.libpcre, :pcre_version), Ptr{Uint8}, ()))
# supported options for different use cases
View
8 base/printf.jl
@@ -139,9 +139,9 @@ function _special_handler(flags::ASCIIString, width::Int)
pos = contains(flags,'+') ? "+" :
contains(flags,' ') ? " " : ""
abn = quote
- isnan($x) ? $(cstring(pad("NaN", width))) :
- $x < 0 ? $(cstring(pad("-Inf", width))) :
- $(cstring(pad("$(pos)Inf", width)))
+ isnan($x) ? $(bytestring(pad("NaN", width))) :
+ $x < 0 ? $(bytestring(pad("-Inf", width))) :
+ $(bytestring(pad("$(pos)Inf", width)))
end
ex = :(isfinite($x) ? $blk : write(out, $abn))
x, ex, blk
@@ -490,7 +490,7 @@ function _gen_p(flags::ASCIIString, width::Int, precision::Int, c::Char)
end
push(blk.args, :(write(out, '0')))
push(blk.args, :(write(out, 'x')))
- push(blk.args, :(write(out, cstring(hex(unsigned($x), $ptrwidth)))))
+ push(blk.args, :(write(out, bytestring(hex(unsigned($x), $ptrwidth)))))
if width > 0 && contains(flags,'-')
push(blk.args, _pad(width, width, ' '))
end
View
8 base/process.jl
@@ -115,7 +115,7 @@ end
function exec(args::String...)
arr = Array(ByteString, length(args))
for i = 1:length(args)
- arr[i] = cstring(args[i])
+ arr[i] = bytestring(args[i])
end
exec(arr)
end
@@ -517,11 +517,11 @@ function arg_gen(head)
if applicable(start,head)
vals = ByteString[]
for x in head
- push(vals,cstring(x))
+ push(vals,bytestring(x))
end
return vals
else
- return ByteString[cstring(head)]
+ return ByteString[bytestring(head)]
end
end
@@ -530,7 +530,7 @@ function arg_gen(head, tail...)
tail = arg_gen(tail...)
vals = ByteString[]
for h in head, t in tail
- push(vals,cstring(strcat(h,t)))
+ push(vals,bytestring(strcat(h,t)))
end
vals
end
View
6 base/regex.jl
@@ -9,7 +9,7 @@ type Regex
extra::Ptr{Void}
function Regex(pat::String, opts::Integer, study::Bool)
- pat = cstring(pat); opts = int32(opts)
+ pat = bytestring(pat); opts = int32(opts)
if (opts & ~PCRE.OPTIONS_MASK) != 0
error("invalid regex option(s)")
end
@@ -85,7 +85,7 @@ function show(io, m::RegexMatch)
end
matches(r::Regex, s::String, o::Integer) =
- PCRE.exec(r.regex, r.extra, cstring(s), 0, o, false)
+ PCRE.exec(r.regex, r.extra, bytestring(s), 0, o, false)
matches(r::Regex, s::String) = matches(r, s, r.options & PCRE.EXECUTE_MASK)
contains(s::String, r::Regex, opts::Integer) = matches(r,s,opts)
@@ -99,7 +99,7 @@ function match(re::Regex, str::ByteString, idx::Integer, opts::Integer)
off = map(i->m[2i+1]+1, [1:n])
RegexMatch(mat, cap, m[1]+1, off)
end
-match(r::Regex, s::String, i::Integer, o::Integer) = match(r, cstring(s), i, o)
+match(r::Regex, s::String, i::Integer, o::Integer) = match(r, bytestring(s), i, o)
match(r::Regex, s::String, i::Integer) = match(r, s, i, r.options & PCRE.EXECUTE_MASK)
match(r::Regex, s::String) = match(r, s, start(s))
View
4 base/signal_fftw.jl
@@ -36,7 +36,7 @@ const _jl_FFTW_RODFT11 = int32(10)
function fftwd_import_wisdom_from_filename(filename::String)
stat = ccall(dlsym(_jl_libfftw,:fftw_import_wisdom_from_filename),
- Int32, (Ptr{Uint8},), cstring(filename))
+ Int32, (Ptr{Uint8},), bytestring(filename))
if stat == 0
error("failed to import wisdom from $filename")
end
@@ -44,7 +44,7 @@ end
function fftwf_import_wisdom_from_filename(filename::String)
stat = ccall(dlsym(_jl_libfftwf,:fftwf_import_wisdom_from_filename),
- Int32, (Ptr{Uint8},), cstring(filename))
+ Int32, (Ptr{Uint8},), bytestring(filename))
if stat == 0
error("failed to import wisdom from $filename")
end
View
26 base/string.jl
@@ -28,21 +28,22 @@ string() = ""
string(s::String) = s
string(xs...) = print_to_string(xs...)
-cstring() = ""
-cstring(xs...) = print_to_string(xs...)
+bytestring() = ""
+bytestring(s::Array{Uint8,1}) = utf8(s)
+bytestring(s::String) = print_to_string(s)
-function cstring(p::Ptr{Uint8})
+function bytestring(p::Ptr{Uint8})
p == C_NULL ? error("cannot convert NULL to string") :
ccall(:jl_cstr_to_string, ByteString, (Ptr{Uint8},), p)
end
-function cstring(p::Ptr{Uint8},len::Int)
+function bytestring(p::Ptr{Uint8},len::Int)
p == C_NULL ? error("cannot convert NULL to string") :
ccall(:jl_pchar_to_string, ByteString, (Ptr{Uint8},Int), p, len)
end
-convert(::Type{Ptr{Uint8}}, s::String) = convert(Ptr{Uint8}, cstring(s))
-convert(::Type{ByteString}, s::String) = cstring(s)
+convert(::Type{Ptr{Uint8}}, s::String) = convert(Ptr{Uint8}, bytestring(s))
+convert(::Type{ByteString}, s::String) = bytestring(s)
## generic supplied functions ##
@@ -57,7 +58,7 @@ ref{T<:Integer}(s::String, r::Range1{T}) = s[int(first(r)):int(last(r))]
ref(s::String, v::AbstractVector) =
sprint(length(v), io->(for i in v write(io,s[i]) end))
-symbol(s::String) = symbol(cstring(s))
+symbol(s::String) = symbol(bytestring(s))
print(io::IO, s::String) = for c in s write(io, c) end
show(io::IO, s::String) = print_quoted(io, s)
@@ -244,7 +245,7 @@ end
isequal(a::String, b::String) = cmp(a,b) == 0
isless(a::String, b::String) = cmp(a,b) < 0
-hash(s::String) = hash(cstring(s))
+hash(s::String) = hash(bytestring(s))
# begins with and ends with predicates
@@ -853,7 +854,7 @@ function lpad(s::String, n::Integer, p::String)
end
q = div(m,l)
r = m - q*l
- cstring(p^q*p[1:chr2ind(p,r)]*s)
+ bytestring(p^q*p[1:chr2ind(p,r)]*s)
end
function rpad(s::String, n::Integer, p::String)
@@ -865,7 +866,7 @@ function rpad(s::String, n::Integer, p::String)
end
q = div(m,l)
r = m - q*l
- cstring(s*p^q*p[1:chr2ind(p,r)])
+ bytestring(s*p^q*p[1:chr2ind(p,r)])
end
lpad(s, n::Integer, p) = lpad(string(s), n, string(p))
@@ -921,9 +922,9 @@ function replace(str::ByteString, pattern, repl::Function, limit::Integer)
n += 1
end
rstr = RopeString(rstr,SubString(str,i))
- cstring(rstr)
+ bytestring(rstr)
end
-replace(s::String, pat, f::Function, n::Integer) = replace(cstring(s), pat, f, n)
+replace(s::String, pat, f::Function, n::Integer) = replace(bytestring(s), pat, f, n)
replace(s::String, pat, r, n::Integer) = replace(s, pat, x->r, n)
replace(s::String, pat, r) = replace(s, pat, r, 0)
@@ -1111,7 +1112,6 @@ uint128 (s::String) = parse_int(Uint128,s)
## stringifying integers more efficiently ##
string(x::Union(Int8,Int16,Int32,Int64,Int128)) = dec(x)
-cstring(x::Union(Int8,Int16,Int32,Int64,Int128)) = dec(x)
## string to float functions ##
View
2  base/sysimg.jl
@@ -61,7 +61,7 @@ export
complex64,cond,conj,conj!,connect,consume,contains,contains_is,conv,conv2,
convert,copy,copy_to,copysign,cor,cor_pearson,cor_spearman,cos,
cosc,cosd,cosh,cot,cotd,coth,count,count_ones,count_zeros,countlines,countp,
- cov,cov_pearson,cov_spearman,cross,csc,cscd,csch,cstring,csvread,csvwrite,
+ cov,cov_pearson,cov_spearman,cross,csc,cscd,csch,bytestring,csvread,csvwrite,
ctranspose,cumprod,cumsum,current_task,cwd,darray,dcell,dec,decile,deconv,
defaultdist,degrees2radians,del,del_all,del_each,del_fd_handler,
den,deserialize,det,dfill,diag,diagm,diagmm,diagmm!,dict,diff,
View
2  base/utf8.jl
@@ -101,4 +101,4 @@ utf8(x) = convert(UTF8String, x)
convert(::Type{UTF8String}, s::UTF8String) = s
convert(::Type{UTF8String}, s::ASCIIString) = UTF8String(s.data)
convert(::Type{UTF8String}, a::Array{Uint8,1}) = check_utf8(UTF8String(a))
-convert(::Type{UTF8String}, s::String) = utf8(cstring(s))
+convert(::Type{UTF8String}, s::String) = utf8(bytestring(s))
View
6 base/util.jl
@@ -165,7 +165,7 @@ methods(t::CompositeKind) = t.env
# require
# Store list of files and their load time
global _jl_package_list = Dict{ByteString,Float64}()
-require(fname::String) = require(cstring(fname))
+require(fname::String) = require(bytestring(fname))
require(f::String, fs::String...) = (require(f); for x in fs require(x); end)
function require(name::ByteString)
path = find_in_path(name)
@@ -186,7 +186,7 @@ include_string(txt::ByteString) = ccall(:jl_load_file_string, Void, (Ptr{Uint8},
function is_file_readable(path)
local f
try
- f = open(cstring(path))
+ f = open(bytestring(path))
catch
return false
end
@@ -217,7 +217,7 @@ local in_remote_load = false
local load_dict = {}
global load, remote_load
-load(fname::String) = load(cstring(fname))
+load(fname::String) = load(bytestring(fname))
load(f::String, fs::String...) = (load(f); for x in fs load(x); end)
function load(fname::ByteString)
if in_load
View
4 extras/bigfloat.jl
@@ -7,7 +7,7 @@ type BigFloat <: Float
function BigFloat(x::String)
z = _jl_BigFloat_init()
- ccall(dlsym(_jl_libgmp_wrapper, :_jl_mpf_set_string), Void, (Ptr{Void}, Ptr{Uint8}), z, cstring(x))
+ ccall(dlsym(_jl_libgmp_wrapper, :_jl_mpf_set_string), Void, (Ptr{Void}, Ptr{Uint8}), z, bytestring(x))
b = new(z)
finalizer(b, _jl_BigFloat_clear)
b
@@ -132,7 +132,7 @@ end
function string(x::BigFloat)
s=ccall(dlsym(_jl_libgmp_wrapper, :_jl_mpf_printf), Ptr{Uint8}, (Ptr{Void},), x.mpf)
- ret = cstring(s) #This copies s.
+ ret = bytestring(s) #This copies s.
c_free(s)
ret
end
View
4 extras/bigint.jl
@@ -5,7 +5,7 @@ type BigInt <: Integer
function BigInt(x::String)
z = _jl_bigint_init()
- ccall(dlsym(_jl_libgmp_wrapper, :_jl_mpz_set_string), Void, (Ptr{Void}, Ptr{Uint8}),z,cstring(x))
+ ccall(dlsym(_jl_libgmp_wrapper, :_jl_mpz_set_string), Void, (Ptr{Void}, Ptr{Uint8}),z,bytestring(x))
b = new(z)
finalizer(b, _jl_bigint_clear)
b
@@ -118,7 +118,7 @@ end
function string(x::BigInt)
s=ccall(dlsym(_jl_libgmp_wrapper, :_jl_mpz_printf), Ptr{Uint8}, (Ptr{Void},),x.mpz)
- ret = cstring(s) #This copies s.
+ ret = bytestring(s) #This copies s.
ccall(dlsym(_jl_libgmp_wrapper,:_jl_gmp_free), Void, (Ptr{Void},), s)
ret
end
View
10 extras/cairo.jl
@@ -52,7 +52,7 @@ end
function CairoPDFSurface(filename::String, w_pts::Real, h_pts::Real)
ptr = ccall(dlsym(_jl_libcairo,:cairo_pdf_surface_create), Ptr{Void},
- (Ptr{Uint8},Float64,Float64), cstring(filename), w_pts, h_pts)
+ (Ptr{Uint8},Float64,Float64), bytestring(filename), w_pts, h_pts)
surface = CairoSurface(ptr, :pdf)
surface.width = w_pts
surface.height = h_pts
@@ -61,7 +61,7 @@ end
function CairoEPSSurface(filename::String, w_pts::Real, h_pts::Real)
ptr = ccall(dlsym(_jl_libcairo,:cairo_ps_surface_create), Ptr{Void},
- (Ptr{Uint8},Float64,Float64), cstring(filename), w_pts, h_pts)
+ (Ptr{Uint8},Float64,Float64), bytestring(filename), w_pts, h_pts)
ccall(dlsym(_jl_libcairo,:cairo_ps_surface_set_eps), Void,
(Ptr{Void},Int32), ptr, 1)
surface = CairoSurface(ptr, :eps)
@@ -72,7 +72,7 @@ end
function write_to_png(surface::CairoSurface, filename::String)
ccall(dlsym(_jl_libcairo,:cairo_surface_write_to_png), Void,
- (Ptr{Uint8},Ptr{Uint8}), surface.ptr, cstring(filename))
+ (Ptr{Uint8},Ptr{Uint8}), surface.ptr, bytestring(filename))
end
# -----------------------------------------------------------------------------
@@ -216,7 +216,7 @@ end
function set_font_from_string(ctx::CairoContext, str::String)
fontdesc = ccall(dlsym(_jl_libpangocairo,:pango_font_description_from_string),
- Ptr{Void}, (Ptr{Uint8},), cstring(str))
+ Ptr{Void}, (Ptr{Uint8},), bytestring(str))
ccall(dlsym(_jl_libpangocairo,:pango_layout_set_font_description), Void,
(Ptr{Void},Ptr{Void}), ctx.layout, fontdesc)
ccall(dlsym(_jl_libpangocairo,:pango_font_description_free), Void,
@@ -225,7 +225,7 @@ end
function set_markup(ctx::CairoContext, markup::String)
ccall(dlsym(_jl_libpangocairo,:pango_layout_set_markup), Void,
- (Ptr{Void},Ptr{Uint8},Int32), ctx.layout, cstring(markup), -1)
+ (Ptr{Void},Ptr{Uint8},Int32), ctx.layout, bytestring(markup), -1)
end
function get_layout_size(ctx::CairoContext)
View
2  extras/dicom.jl
@@ -271,7 +271,7 @@ function element(st, evr, dcm)
sz = read(st,lentype)
data =
- vr=="ST" || vr=="LT" || vr=="UT" ? cstring(read(st, Uint8, sz)) :
+ vr=="ST" || vr=="LT" || vr=="UT" ? bytestring(read(st, Uint8, sz)) :
sz==0 || vr=="XX" ? {} :
View
28 extras/fitsio.jl
@@ -9,7 +9,7 @@ end
function fits_get_errstatus(status::Int32)
msg = Array(Uint8, 31)
ccall(dlsym(_jl_libcfitsio,:ffgerr), Void, (Int32,Ptr{Uint8}), status, msg)
- cstring(convert(Ptr{Uint8},msg))
+ bytestring(convert(Ptr{Uint8},msg))
end
function fits_assert_ok(status::Int32)
@@ -45,7 +45,7 @@ function fits_create_file(filename::String)
status = Int32[0]
ccall(dlsym(_jl_libcfitsio,:ffinit),
Int32, (Ptr{Ptr{Void}},Ptr{Uint8},Ptr{Int32}),
- ptr, cstring(filename), status)
+ ptr, bytestring(filename), status)
fits_assert_ok(status[1])
FITSFile(ptr[1], status[1])
end
@@ -58,7 +58,7 @@ function fits_open_file(filename::String)
status = Int32[0]
ccall(dlsym(_jl_libcfitsio,:ffopen),
Int32, (Ptr{Ptr{Void}},Ptr{Uint8},Int32,Ptr{Int32}),
- ptr, cstring(filename), mode, status)
+ ptr, bytestring(filename), mode, status)
fits_assert_ok(status[1])
FITSFile(ptr[1], status[1])
end
@@ -87,9 +87,9 @@ function fits_read_keyword(f::FITSFile, keyname::String)
comment = Array(Uint8, 71)
ccall(dlsym(_jl_libcfitsio,:ffgkey), Int32,
(Ptr{Void},Ptr{Uint8},Ptr{Uint8},Ptr{Uint8},Ptr{Int32}),
- f.ptr, cstring(keyname), value, comment, &f.status)
+ f.ptr, bytestring(keyname), value, comment, &f.status)
fits_assert_ok(f)
- cstring(convert(Ptr{Uint8},value)), cstring(convert(Ptr{Uint8},comment))
+ bytestring(convert(Ptr{Uint8},value)), bytestring(convert(Ptr{Uint8},comment))
end
function fits_read_record(f::FITSFile, keynum::Int)
@@ -98,7 +98,7 @@ function fits_read_record(f::FITSFile, keynum::Int)
(Ptr{Void},Int32,Ptr{Uint8},Ptr{Int32}),
f.ptr, keynum, card, &f.status)
fits_assert_ok(f)
- cstring(convert(Ptr{Uint8},card))
+ bytestring(convert(Ptr{Uint8},card))
end
function fits_read_keyn(f::FITSFile, keynum::Int)
@@ -109,25 +109,25 @@ function fits_read_keyn(f::FITSFile, keynum::Int)
(Ptr{Void},Int32,Ptr{Uint8},Ptr{Uint8},Ptr{Uint8},Ptr{Int32}),
f.ptr, keynum, keyname, value, comment, &f.status)
fits_assert_ok(f)
- cstring(convert(Ptr{Uint8},keyname)),
- cstring(convert(Ptr{Uint8},value)),
- cstring(convert(Ptr{Uint8},comment))
+ bytestring(convert(Ptr{Uint8},keyname)),
+ bytestring(convert(Ptr{Uint8},value)),
+ bytestring(convert(Ptr{Uint8},comment))
end
function fits_write_key(f::FITSFile, keyname::String, value::Union(Number,String), comment::String)
- cvalue = isa(value,String) ? cstring(value) :
+ cvalue = isa(value,String) ? bytestring(value) :
isa(value,Bool) ? [int32(value)] : [value]
ccall(dlsym(_jl_libcfitsio,:ffpky), Int32,
(Ptr{Void},Int32,Ptr{Uint8},Ptr{Uint8},Ptr{Uint8},Ptr{Int32}),
- f.ptr, _cfitsio_datatype(typeof(value)), cstring(keyname),
- cvalue, cstring(comment), &f.status)
+ f.ptr, _cfitsio_datatype(typeof(value)), bytestring(keyname),
+ cvalue, bytestring(comment), &f.status)
fits_assert_ok(f)
end
function fits_write_record(f::FITSFile, card::String)
ccall(dlsym(_jl_libcfitsio,:ffprec), Int32,
(Ptr{Void},Ptr{Uint8},Ptr{Int32}),
- f.ptr, cstring(card), &f.status)
+ f.ptr, bytestring(card), &f.status)
fits_assert_ok(f)
end
@@ -141,7 +141,7 @@ end
function fits_delete_key(f::FITSFile, keyname::String)
ccall(dlsym(_jl_libcfitsio,:ffdkey), Int32,
(Ptr{Void},Ptr{Uint8},Ptr{Int32}),
- f.ptr, cstring(keyname), &f.status)
+ f.ptr, bytestring(keyname), &f.status)
fits_assert_ok(f)
end
View
70 extras/glpk.jl
@@ -896,7 +896,7 @@ function glp_set_prob_name(glp_prob::GLPProb, name::Union(String,Nothing))
name = ""
end
_jl_glpk__check_string_length(name, 0, 255)
- @glpk_ccall set_prob_name Void (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(name)
+ @glpk_ccall set_prob_name Void (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(name)
end
function glp_set_obj_name(glp_prob::GLPProb, name::Union(String,Nothing))
@@ -905,7 +905,7 @@ function glp_set_obj_name(glp_prob::GLPProb, name::Union(String,Nothing))
name = ""
end
_jl_glpk__check_string_length(name, 0, 255)
- @glpk_ccall set_obj_name Void (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(name)
+ @glpk_ccall set_obj_name Void (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(name)
end
function glp_set_row_name(glp_prob::GLPProb, row::Integer, name::Union(String,Nothing))
@@ -915,7 +915,7 @@ function glp_set_row_name(glp_prob::GLPProb, row::Integer, name::Union(String,No
name = ""
end
_jl_glpk__check_string_length(name, 0, 255)
- @glpk_ccall set_row_name Void (Ptr{Void}, Int32, Ptr{Uint8}) glp_prob.p row cstring(name)
+ @glpk_ccall set_row_name Void (Ptr{Void}, Int32, Ptr{Uint8}) glp_prob.p row bytestring(name)
end
function glp_set_col_name(glp_prob::GLPProb, col::Integer, name::Union(String,Nothing))
@@ -925,7 +925,7 @@ function glp_set_col_name(glp_prob::GLPProb, col::Integer, name::Union(String,No
name = ""
end
_jl_glpk__check_string_length(name, 0, 255)
- @glpk_ccall set_col_name Void (Ptr{Void}, Int32, Ptr{Uint8}) glp_prob.p col cstring(name)
+ @glpk_ccall set_col_name Void (Ptr{Void}, Int32, Ptr{Uint8}) glp_prob.p col bytestring(name)
end
function glp_set_obj_dir(glp_prob::GLPProb, dir::Integer)
@@ -1136,7 +1136,7 @@ function glp_get_prob_name(glp_prob::GLPProb)
if name_cstr == C_NULL
return ""
else
- return cstring(name_cstr)
+ return bytestring(name_cstr)
end
end
@@ -1146,7 +1146,7 @@ function glp_get_obj_name(glp_prob::GLPProb)
if name_cstr == C_NULL
return ""
else
- return cstring(name_cstr)
+ return bytestring(name_cstr)
end
end
@@ -1172,7 +1172,7 @@ function glp_get_row_name(glp_prob::GLPProb, row::Integer)
if name_cstr == C_NULL
return ""
else
- return cstring(name_cstr)
+ return bytestring(name_cstr)
end
end
@@ -1183,7 +1183,7 @@ function glp_get_col_name(glp_prob::GLPProb, col::Integer)
if name_cstr == C_NULL
return ""
else
- return cstring(name_cstr)
+ return bytestring(name_cstr)
end
end
@@ -1325,12 +1325,12 @@ end
function glp_find_row(glp_prob::GLPProb, name::String)
_jl_glpk__check_glp_prob(glp_prob)
- @glpk_ccall find_row Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(name)
+ @glpk_ccall find_row Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(name)
end
function glp_find_col(glp_prob::GLPProb, name::String)
_jl_glpk__check_glp_prob(glp_prob)
- @glpk_ccall find_col Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(name)
+ @glpk_ccall find_col Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(name)
end
function glp_delete_index(glp_prob::GLPProb)
@@ -1622,7 +1622,7 @@ function glp_read_mps(glp_prob::GLPProb, format::Integer, param, filename::Strin
end
_jl_glpk__check_file_is_readable(filename)
- ret = @glpk_ccall read_mps Int32 (Ptr{Void}, Int32, Ptr{Void}, Ptr{Uint8}) glp_prob.p format param cstring(filename)
+ ret = @glpk_ccall read_mps Int32 (Ptr{Void}, Int32, Ptr{Void}, Ptr{Uint8}) glp_prob.p format param bytestring(filename)
if ret != 0
throw(GLPError("Error reading MPS file"))
end
@@ -1641,7 +1641,7 @@ function glp_write_mps(glp_prob::GLPProb, format::Integer, param, filename::Stri
_jl_glpk__check_mps_param(param)
end
_jl_glpk__check_file_is_writable(filename)
- ret = @glpk_ccall write_mps Int32 (Ptr{Void}, Int32, Ptr{Void}, Ptr{Uint8}) glp_prob.p format param cstring(filename)
+ ret = @glpk_ccall write_mps Int32 (Ptr{Void}, Int32, Ptr{Void}, Ptr{Uint8}) glp_prob.p format param bytestring(filename)
if ret != 0
throw(GLPError("Error writing MPS file"))
end
@@ -1655,7 +1655,7 @@ function glp_read_lp(glp_prob::GLPProb, param, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_lp_param(param)
_jl_glpk__check_file_is_readable(filename)
- ret = @glpk_ccall read_lp Int32 (Ptr{Void}, Ptr{Void}, Ptr{Uint8}) glp_prob.p param cstring(filename)
+ ret = @glpk_ccall read_lp Int32 (Ptr{Void}, Ptr{Void}, Ptr{Uint8}) glp_prob.p param bytestring(filename)
if ret != 0
throw(GLPError("Error reading LP file"))
end
@@ -1669,7 +1669,7 @@ function glp_write_lp(glp_prob::GLPProb, param, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_lp_param(param)
_jl_glpk__check_file_is_writable(filename)
- ret = @glpk_ccall write_lp Int32 (Ptr{Void}, Ptr{Void}, Ptr{Uint8}) glp_prob.p param cstring(filename)
+ ret = @glpk_ccall write_lp Int32 (Ptr{Void}, Ptr{Void}, Ptr{Uint8}) glp_prob.p param bytestring(filename)
if ret != 0
throw(GLPError("Error writing LP file"))
end
@@ -1683,7 +1683,7 @@ function glp_read_prob(glp_prob::GLPProb, flags::Integer, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_read_prob_flags(flags)
_jl_glpk__check_file_is_readable(filename)
- @glpk_ccall read_prob Int32 (Ptr{Void}, Int32, Ptr{Uint8}) glp_prob.p flags cstring(filename)
+ @glpk_ccall read_prob Int32 (Ptr{Void}, Int32, Ptr{Uint8}) glp_prob.p flags bytestring(filename)
end
glp_read_prob(glp_prob::GLPProb, filename::String) =
@@ -1693,7 +1693,7 @@ function glp_write_prob(glp_prob::GLPProb, flags::Integer, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_write_prob_flags(flags)
_jl_glpk__check_file_is_writable(filename)
- @glpk_ccall write_prob Int32 (Ptr{Void}, Int32, Ptr{Uint8}) glp_prob.p flags cstring(filename)
+ @glpk_ccall write_prob Int32 (Ptr{Void}, Int32, Ptr{Uint8}) glp_prob.p flags bytestring(filename)
end
glp_write_prob(glp_prob::GLPProb, filename::String) =
@@ -1702,7 +1702,7 @@ glp_write_prob(glp_prob::GLPProb, filename::String) =
function glp_mpl_read_model(glp_tran::GLPMathProgWorkspace, filename::String, skip::Integer)
_jl_glpk__check_mpl_workspace(glp_tran)
_jl_glpk__check_file_is_readable(filename)
- ret = @glpk_ccall mpl_read_model Int32 (Ptr{Void}, Ptr{Uint8}, Int32) glp_tran.p cstring(filename) skip
+ ret = @glpk_ccall mpl_read_model Int32 (Ptr{Void}, Ptr{Uint8}, Int32) glp_tran.p bytestring(filename) skip
if ret != 0
throw(GLPError("Error reading MathProg file"))
end
@@ -1712,7 +1712,7 @@ end
function glp_mpl_read_data(glp_tran::GLPMathProgWorkspace, filename::String)
_jl_glpk__check_mpl_workspace(glp_tran)
_jl_glpk__check_file_is_readable(filename)
- ret = @glpk_ccall mpl_read_data Int32 (Ptr{Void}, Ptr{Uint8}) glp_tran.p cstring(filename)
+ ret = @glpk_ccall mpl_read_data Int32 (Ptr{Void}, Ptr{Uint8}) glp_tran.p bytestring(filename)
if ret != 0
throw(GLPError("Error reading MathProg data file"))
end
@@ -1725,7 +1725,7 @@ function glp_mpl_generate(glp_tran::GLPMathProgWorkspace, filename::Union(String
cfilename = C_NULL
else
_jl_glpk__check_file_is_writable(filename)
- cfilename = cstring(filename)
+ cfilename = bytestring(filename)
end
ret = @glpk_ccall mpl_generate Int32 (Ptr{Void}, Ptr{Uint8}) glp_tran.p cfilename
if ret != 0
@@ -1758,7 +1758,7 @@ end
function glp_print_sol(glp_prob::GLPProb, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_file_is_writable(filename)
- ret = @glpk_ccall print_sol Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(filename)
+ ret = @glpk_ccall print_sol Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(filename)
if ret != 0
throw(GLPError("Error printing solution"))
end
@@ -1768,7 +1768,7 @@ end
function glp_read_sol(glp_prob::GLPProb, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_file_is_readable(filename)
- ret = @glpk_ccall read_sol Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(filename)
+ ret = @glpk_ccall read_sol Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(filename)
if ret != 0
throw(GLPError("Error reading solution"))
end
@@ -1778,7 +1778,7 @@ end
function glp_write_sol(glp_prob::GLPProb, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_file_is_writable(filename)
- ret = @glpk_ccall write_sol Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(filename)
+ ret = @glpk_ccall write_sol Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(filename)
if ret != 0
throw(GLPError("Error writing solution"))
end
@@ -1788,7 +1788,7 @@ end
function glp_print_ipt(glp_prob::GLPProb, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_file_is_writable(filename)
- ret = @glpk_ccall print_ipt Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(filename)
+ ret = @glpk_ccall print_ipt Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(filename)
if ret != 0
throw(GLPError("Error printing interior point solution"))
end
@@ -1798,7 +1798,7 @@ end
function glp_read_ipt(glp_prob::GLPProb, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_file_is_readable(filename)
- ret = @glpk_ccall read_ipt Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(filename)
+ ret = @glpk_ccall read_ipt Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(filename)
if ret != 0
throw(GLPError("Error reading interior point solution"))
end
@@ -1808,7 +1808,7 @@ end
function glp_write_ipt(glp_prob::GLPProb, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_file_is_writable(filename)
- ret = @glpk_ccall write_ipt Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(filename)
+ ret = @glpk_ccall write_ipt Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(filename)
if ret != 0
throw(GLPError("Error writing interior point solution"))
end
@@ -1818,7 +1818,7 @@ end
function glp_print_mip(glp_prob::GLPProb, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_file_is_writable(filename)
- ret = @glpk_ccall print_mip Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(filename)
+ ret = @glpk_ccall print_mip Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(filename)
if ret != 0
throw(GLPError("Error printing mixed integer programming solution"))
end
@@ -1828,7 +1828,7 @@ end
function glp_read_mip(glp_prob::GLPProb, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_file_is_readable(filename)
- ret = @glpk_ccall read_mip Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(filename)
+ ret = @glpk_ccall read_mip Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(filename)
if ret != 0
throw(GLPError("Error reading mixed integer programming solution"))
end
@@ -1838,7 +1838,7 @@ end
function glp_write_mip(glp_prob::GLPProb, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_file_is_writable(filename)
- ret = @glpk_ccall write_mip Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(filename)
+ ret = @glpk_ccall write_mip Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(filename)
if ret != 0
throw(GLPError("Error writing mixed integer programming solution"))
end
@@ -1863,7 +1863,7 @@ function glp_print_ranges{Ti<:Integer}(glp_prob::GLPProb, len::Integer, list::Ve
list32p = C_NULL
end
- @glpk_ccall print_ranges Int32 (Ptr{Void}, Int32, Ptr{Int32}, Int32, Ptr{Uint8}) glp_prob.p len list32p flags cstring(filename)
+ @glpk_ccall print_ranges Int32 (Ptr{Void}, Int32, Ptr{Int32}, Int32, Ptr{Uint8}) glp_prob.p len list32p flags bytestring(filename)
end
glp_print_ranges{Ti<:Integer}(glp_prob::GLPProb, list::Vector{Ti}, flags::Integer, filename::String) =
@@ -2264,7 +2264,7 @@ function glp_term_out(flag::Integer)
end
function glp_open_tee(filename::String)
- ret = @glpk_ccall open_tee Int32 (Ptr{Uint8},) cstring(filename)
+ ret = @glpk_ccall open_tee Int32 (Ptr{Uint8},) bytestring(filename)
_jl_glpk__check_open_tee_succeeded(ret)
return ret
end
@@ -2331,7 +2331,7 @@ end
function glp_sdf_open_file(filename::String)
_jl_glpk__check_file_is_readable(filename)
- data_p = @glpk_ccall sdf_open_file Ptr{Void} (Ptr{Uint8},) cstring(filename)
+ data_p = @glpk_ccall sdf_open_file Ptr{Void} (Ptr{Uint8},) bytestring(filename)
_jl_glpk__check_sdf_file_opened(data_p)
return GLPData(data_p)
end
@@ -2349,13 +2349,13 @@ end
function glp_sdf_read_item(glp_data::GLPData)
_jl_glpk__check_data(glp_data)
item_cstr = @glpk_ccall sdf_read_item Ptr{Uint8} (Ptr{Void},) pointer(glp_data)
- return cstring(item_cstr)
+ return bytestring(item_cstr)
end
function glp_sdf_read_text(glp_data::GLPData)
_jl_glpk__check_data(glp_data)
text_cstr = @glpk_ccall sdf_read_text Ptr{Uint8} (Ptr{Void},) pointer(glp_data)
- return cstring(text_cstr)
+ return bytestring(text_cstr)
end
function glp_sdf_line(glp_data::GLPData)
@@ -2371,7 +2371,7 @@ end
function glp_read_cnfsat(glp_prob::GLPProb, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_file_is_readable(filename)
- ret = @glpk_ccall read_cnfsat Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(filename)
+ ret = @glpk_ccall read_cnfsat Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(filename)
if ret != 0
throw(GLPError("Error reading CNF file"))
end
@@ -2386,7 +2386,7 @@ end
function glp_write_cnfsat(glp_prob::GLPProb, filename::String)
_jl_glpk__check_glp_prob(glp_prob)
_jl_glpk__check_file_is_writable(filename)
- ret = @glpk_ccall write_cnfsat Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p cstring(filename)
+ ret = @glpk_ccall write_cnfsat Int32 (Ptr{Void}, Ptr{Uint8}) glp_prob.p bytestring(filename)
if ret != 0
throw(GLPError("Error writing CNF file"))
end
View
4 extras/libhdfs.jl
@@ -134,12 +134,12 @@ hdfs_get_working_directory(fs::HdfsFS, buffer, bufferSize)=ccall(_hdfsGetWorking
function hdfs_get_working_directory(fs::HdfsFS,bufferSize)
buffer = Array(Uint8, bufferSize)
path = ccall(_hdfsGetWorkingDirectory, Ptr{Uint8}, (Ptr{Void}, Ptr{Uint8}, Int32), fs.ptr, buffer, bufferSize)
- return cstring(path)
+ return bytestring(path)
end
function hdfs_get_working_directory(fs::HdfsFS)
buffer = Array(Uint8, 128)
path = ccall(_hdfsGetWorkingDirectory, Ptr{Uint8}, (Ptr{Void}, Ptr{Uint8}, Int32), fs.ptr, buffer, 128)
- return cstring(path)
+ return bytestring(path)
end
hdfs_set_working_directory(fs::HdfsFS, path)=ccall(_hdfsSetWorkingDirectory, Int32, (Ptr{Void}, Ptr{Uint8}), fs.ptr, path)
Please sign in to comment.
Something went wrong with that request. Please try again.