* [PATCH] bindat and multibyte string RAW-DATA
@ 2006-05-23 23:26 Thien-Thi Nguyen
2006-05-24 9:09 ` Kim F. Storm
0 siblings, 1 reply; 2+ messages in thread
From: Thien-Thi Nguyen @ 2006-05-23 23:26 UTC (permalink / raw)
i am having difficulty imagining how a multibyte string RAW-DATA to
`bindat-pack' and `bindat-unpack' could be anything less than latent
confusion and bugs cultivation. so i propose the change below. WDYT?
here is an example of the problem (silent weirdness):
;; unibyte ok
(bindat-unpack '((one u8) (two u8)) (string 40 41))
=> ((two . 41) (one . 40))
;; multibyte -- big "bytes"!
(bindat-unpack '((one u8) (two u8)) (string 53450 53451))
=> ((two . 53451) (one . 53450))
there was variability over "size of byte" a while back, but these
days the above behavior would probably be considered buggy.
apparently, there are other problems as well:
;; vector -- more big bytes
(bindat-unpack '((one u8) (two u8)) (vector 53450 53451))
=> ((two . 53451) (one . 53450))
however, the patch does not address this last problem. a check:
(when (vectorp raw-data)
(let ((i 0) (len (length raw-data)) value)
(while (< i len)
(setq value (aref raw-data i))
(unless (and (<= 0 value) (<= value 255))
(error "Array element out of range")))))
inserted into `bindat-unpack' would work, but it seems heavy...
thi
__________________________________________________________
*** bindat.el 23 May 2006 11:21:59 -0000 1.10
--- bindat.el 23 May 2006 23:11:32 -0000
***************
*** 345,352 ****
(defun bindat-unpack (spec raw-data &optional pos)
"Return structured data according to SPEC for binary data in RAW-DATA.
! RAW-DATA is a string or vector. Optional third arg POS specifies the
! starting offset in RAW-DATA."
(unless pos (setq pos 0))
(bindat--unpack-group spec))
--- 345,354 ----
(defun bindat-unpack (spec raw-data &optional pos)
"Return structured data according to SPEC for binary data in RAW-DATA.
! RAW-DATA is a unibyte string or vector. Optional third arg POS specifies
! the starting offset in RAW-DATA."
! (when (multibyte-string-p raw-data)
! (error "String is multibyte"))
(unless pos (setq pos 0))
(bindat--unpack-group spec))
***************
*** 581,590 ****
(defun bindat-pack (spec struct &optional raw-data pos)
"Return binary data packed according to SPEC for structured data STRUCT.
! Optional third arg RAW-DATA is a pre-allocated string or vector to pack into.
! Optional fourth arg POS is the starting offset into RAW-DATA.
! Note: The result is a multibyte string; use `string-make-unibyte' on it
! to make it unibyte if necessary."
(let ((no-return raw-data))
(unless pos (setq pos 0))
(unless raw-data
--- 583,592 ----
(defun bindat-pack (spec struct &optional raw-data pos)
"Return binary data packed according to SPEC for structured data STRUCT.
! Optional third arg RAW-DATA is a pre-allocated unibyte string or vector to
! pack into. Optional fourth arg POS is the starting offset into RAW-DATA."
! (when (multibyte-string-p raw-data)
! (error "Pre-allocated string is multibyte"))
(let ((no-return raw-data))
(unless pos (setq pos 0))
(unless raw-data
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] bindat and multibyte string RAW-DATA
2006-05-23 23:26 [PATCH] bindat and multibyte string RAW-DATA Thien-Thi Nguyen
@ 2006-05-24 9:09 ` Kim F. Storm
0 siblings, 0 replies; 2+ messages in thread
From: Kim F. Storm @ 2006-05-24 9:09 UTC (permalink / raw)
Cc: emacs-devel
Thien-Thi Nguyen <ttn@gnu.org> writes:
> i am having difficulty imagining how a multibyte string RAW-DATA to
> `bindat-pack' and `bindat-unpack' could be anything less than latent
> confusion and bugs cultivation. so i propose the change below. WDYT?
Your changes looks ok. Please install them.
--
Kim F. Storm <storm@cua.dk> http://www.cua.dk
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-05-24 9:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-23 23:26 [PATCH] bindat and multibyte string RAW-DATA Thien-Thi Nguyen
2006-05-24 9:09 ` Kim F. Storm
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).