Skip to content

Commit ede5772

Browse files
committed
use cstring(Ptr) to make a string from a C string, instead of string()
1 parent 2015f90 commit ede5772

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

j/env.j

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function getenv(var::String)
1010
if val == C_NULL
1111
error("getenv: Undefined variable: ", var)
1212
end
13-
string(val)
13+
cstring(val)
1414
end
1515

1616
function setenv(var::String, val::String)

j/libc.j

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function gethostname()
1616
hn = Array(Uint8, 128)
1717
ccall(dlsym(libc,:gethostname), Int32, (Ptr{Uint8}, Ulong),
1818
hn, ulong(length(hn)))
19-
string(convert(Ptr{Uint8},hn))
19+
cstring(convert(Ptr{Uint8},hn))
2020
end
2121

2222
## file and directory ##
@@ -28,7 +28,7 @@ function getcwd()
2828
if p == C_NULL
2929
error("path too long")
3030
end
31-
string(p)
31+
cstring(p)
3232
end
3333

3434
function setcwd(p::String)

j/regex.j

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ load("pcre_h.j")
22

33
libpcre = dlopen("libpcre")
44

5-
PCRE_VERSION = string(ccall(dlsym(libpcre, :pcre_version), Ptr{Uint8}, ()))
5+
PCRE_VERSION = cstring(ccall(dlsym(libpcre, :pcre_version), Ptr{Uint8}, ()))
66

77
## masks for supported sets of options ##
88

j/string.j

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,15 @@ lcfirst(s::String) = TransformedString((c,i)->i==1 ? lc(c) : c, s)
308308

309309
## conversion of general objects to strings ##
310310

311-
function string(p::Ptr{Uint8})
312-
p == C_NULL ? error("cannot convert NULL to string") :
313-
ccall(:jl_cstr_to_string, Any, (Ptr{Uint8},), p)::String
314-
end
315-
316311
string(x) = print_to_string(show, x)
317312

318313
cstring(args...) = print_to_string(print, args...)
319314

315+
function cstring(p::Ptr{Uint8})
316+
p == C_NULL ? error("cannot convert NULL to string") :
317+
ccall(:jl_cstr_to_string, Any, (Ptr{Uint8},), p)::String
318+
end
319+
320320
## printing literal quoted string data ##
321321

322322
# TODO: this is really the inverse of print_unbackslashed

0 commit comments

Comments
 (0)