From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.devel Subject: [PATCH] bindat and multibyte string RAW-DATA Date: Wed, 24 May 2006 01:26:38 +0200 Message-ID: Reply-To: ttn@gnu.org NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1148426713 17286 80.91.229.2 (23 May 2006 23:25:13 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 23 May 2006 23:25:13 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 24 01:25:10 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FigFK-0003B1-BB for ged-emacs-devel@m.gmane.org; Wed, 24 May 2006 01:25:02 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FigFJ-0000aZ-RQ for ged-emacs-devel@m.gmane.org; Tue, 23 May 2006 19:25:01 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FigFA-0000ZK-DE for emacs-devel@gnu.org; Tue, 23 May 2006 19:24:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FigF9-0000Y2-Lc for emacs-devel@gnu.org; Tue, 23 May 2006 19:24:52 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FigF9-0000Xt-Hf for emacs-devel@gnu.org; Tue, 23 May 2006 19:24:51 -0400 Original-Received: from [151.38.235.133] (helo=surf.glug.org) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FigJS-0003S5-Ou for emacs-devel@gnu.org; Tue, 23 May 2006 19:29:19 -0400 Original-Received: from ttn by surf.glug.org with local (Exim 3.35 #1 (Debian)) id 1FigGs-0001Yw-00 for ; Wed, 24 May 2006 01:26:38 +0200 Original-To: emacs-devel@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:55162 Archived-At: 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