Ivan Shmakov | 27 Apr 19:46

byte-vector-≥os-string: Should ensure terminating NUL

	Currently `byte-vector-≥os-string' assumes that the byte vector
	passed contains terminating NUL.  Hence I suggest the following
	patch.

;; Before:
(x->os-string (byte-vector 33))
; => #{OS-string ("US-ASCII" "ANSI_X3.4-1968") ""}

;; After:
(x->os-string (byte-vector 33))
; => #{OS-string ("US-ASCII" "ANSI_X3.4-1968") "!"}

scheme/rts/os-string.scm (byte-vector-≥os-string): Call
`byte-vector-copy-z' instead of `byte-vector-copy'.
(byte-vector-copy-z): Renamed function from...
(byte-vector-copy): ... this name; ensure that the byte vector to be
returned is NUL-terminated.

diff -r 293c27a240bc scheme/rts/os-string.scm
--- a/scheme/rts/os-string.scm	Wed Apr 16 18:45:32 2008 +0700
+++ b/scheme/rts/os-string.scm	Mon Apr 28 00:30:12 2008 +0700
@@ -57,7 +57,7 @@
 		    c #f)))

 (define (byte-vector-≥os-string b)
-  (let ((c (byte-vector-copy b)))
+  (let ((c (byte-vector-copy-z b)))
     (make-immutable! b)
     (make-os-string (current-os-string-text-codec)
 		    #f c)))
(Continue reading)

Ivan Shmakov | 29 Apr 05:29

Re: byte-vector-≥os-string: Should ensure terminating NUL

>>>>> Ivan Shmakov <ivan <at> theory.asu.ru> writes:

 > Currently `byte-vector-≥os-string' assumes that the byte vector
 > passed contains terminating NUL.  Hence I suggest the following
 > patch.

 > ;; Before: (x->os-string (byte-vector 33))
 > ; => #{OS-string ("US-ASCII" "ANSI_X3.4-1968") ""}

 > ;; After: (x->os-string (byte-vector 33))
 > ; => #{OS-string ("US-ASCII" "ANSI_X3.4-1968") "!"}

[...]

	... However, there're some unresolved issues.

	First of all, utilities.tex reads:

--cut: utilities.tex--
\begin{protos}
[...]
\proto{byte-vector-≥os-string}{ byte-vector}{os-string}
[...]
\end{protos}
\noindent
These procedures create an OS string from a string, a byte-vector
(whose last value should be 0), [...]

\begin{protos}
\proto{os-string-≥byte-vector}{ os-string}{byte-vector}
(Continue reading)

Michael Sperber | 1 May 09:07

Re: byte-vector-≥os-string: Should ensure terminating NUL


Ivan Shmakov <ivan <at> theory.asu.ru> writes:

> (os-string-≥byte-vector (byte-vector-≥os-string X))
>
> 	is no longer an identity function for any byte vector X (while
> 	it probably should be.)

I think that's OK---`os-string-≥byte-vector' really needs to return
something acceptable for the OS, and that needs to be NUL-terminated.
You might want to patch the documentation as well.

> 	Also, wouldn't it make more sense to terminate UTF-16 strings
> 	with 0, 0 and UCS-32 ones with 0, 0, 0, 0?

The byte vectors that are in OS strings are always in a conservative
extension of ASCII.  (Even on Windows, where the native UTF-16 is
converted to a bastard variant of UTF-8 that preserves unpaired
surrogates.)

--

-- 
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla


Gmane