@@ -73,6 +73,8 @@ for sz in (1, 4, 8, 16, 32, 64, 128, 256)
73
73
end
74
74
end
75
75
76
+ # used to zero out n lower bytes of an inline string
77
+ clear_n_bytes (s, n) = Base. shl_int (Base. lshr_int (s, 8 * n), 8 * n)
76
78
_bswap (x:: T ) where {T <: InlineString } = T === InlineString1 ? x : Base. bswap_int (x)
77
79
78
80
const InlineStringTypes = Union{InlineString1,
@@ -147,6 +149,26 @@ function Base.Symbol(x::T) where {T <: InlineString}
147
149
(Ref{T}, Int), ref, sizeof (x))
148
150
end
149
151
152
+ Base. cconvert (:: Type{Ptr{UInt8}} , x:: InlineString1 ) = Base. cconvert (Ptr{UInt8}, InlineString3 (x))
153
+ Base. cconvert (:: Type{Ptr{Int8}} , x:: InlineString1 ) = Base. cconvert (Ptr{Int8}, InlineString3 (x))
154
+ Base. cconvert (:: Type{Cstring} , x:: InlineString1 ) = Base. cconvert (Cstring, InlineString3 (x))
155
+ Base. cconvert (:: Type{Ptr{UInt8}} , x:: T ) where {T <: InlineString } =
156
+ Ref {T} (_bswap (clear_n_bytes (x, 1 )))
157
+ Base. cconvert (:: Type{Ptr{Int8}} , x:: T ) where {T <: InlineString } =
158
+ Ref {T} (_bswap (clear_n_bytes (x, 1 )))
159
+ function Base. cconvert (:: Type{Cstring} , x:: T ) where {T <: InlineString }
160
+ ref = Ref {T} (_bswap (clear_n_bytes (x, 1 )))
161
+ Base. containsnul (Ptr {Int8} (pointer_from_objref (ref)), sizeof (x)) &&
162
+ throw (ArgumentError (" embedded NULs are not allowed in C strings: $x " ))
163
+ return ref
164
+ end
165
+ Base. unsafe_convert (:: Type{Ptr{UInt8}} , x:: Ref{T} ) where {T <: InlineString } =
166
+ Ptr {UInt8} (pointer_from_objref (x))
167
+ Base. unsafe_convert (:: Type{Ptr{Int8}} , x:: Ref{T} ) where {T <: InlineString } =
168
+ Ptr {Int8} (pointer_from_objref (x))
169
+ Base. unsafe_convert (:: Type{Cstring} , s:: Ref{T} ) where {T <: InlineString } =
170
+ Cstring (Base. unsafe_convert (Ptr{Cchar}, s))
171
+
150
172
Base. Vector {UInt8} (s:: InlineString ) = Vector {UInt8} (codeunits (s))
151
173
Base. Array {UInt8} (s:: InlineString ) = Vector {UInt8} (codeunits (s))
152
174
@@ -506,9 +528,6 @@ function Base.rstrip(f, s::InlineString)
506
528
return nc == 0 ? s : _chopsuffix (s, nc)
507
529
end
508
530
509
- # used to zero out n lower bytes of an inline string
510
- clear_n_bytes (s, n) = Base. shl_int (Base. lshr_int (s, 8 * n), 8 * n)
511
-
512
531
Base. chomp (s:: InlineString1 ) = chomp (String3 (s))
513
532
function Base. chomp (s:: InlineString )
514
533
i = lastindex (s)
0 commit comments