From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#46534: Lexical change in bindat breaks weechat.el Date: Mon, 15 Feb 2021 10:50:30 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33741"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 46534@debbugs.gnu.org, "Kim F. Storm" To: Tony Olagbaiye Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 15 16:51:16 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lBg9c-0008eR-D6 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 15 Feb 2021 16:51:16 +0100 Original-Received: from localhost ([::1]:50752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBg9b-0005Co-ES for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 15 Feb 2021 10:51:15 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBg9O-0005BO-SW for bug-gnu-emacs@gnu.org; Mon, 15 Feb 2021 10:51:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lBg9N-0006yu-QZ for bug-gnu-emacs@gnu.org; Mon, 15 Feb 2021 10:51:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lBg9N-0003xO-Pd for bug-gnu-emacs@gnu.org; Mon, 15 Feb 2021 10:51:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 15 Feb 2021 15:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46534 X-GNU-PR-Package: emacs Original-Received: via spool by 46534-submit@debbugs.gnu.org id=B46534.161340424315186 (code B ref 46534); Mon, 15 Feb 2021 15:51:01 +0000 Original-Received: (at 46534) by debbugs.gnu.org; 15 Feb 2021 15:50:43 +0000 Original-Received: from localhost ([127.0.0.1]:38551 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lBg94-0003ws-Vq for submit@debbugs.gnu.org; Mon, 15 Feb 2021 10:50:43 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:58585) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lBg91-0003wa-R0 for 46534@debbugs.gnu.org; Mon, 15 Feb 2021 10:50:41 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 7342B10022E; Mon, 15 Feb 2021 10:50:33 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id E5706100091; Mon, 15 Feb 2021 10:50:31 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1613404231; bh=WFhtbkB9KaBabvpr9YVVzkG04CNWsxyiGLVUtWVgJPA=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=RUPMS1OWKWbpq2rfP4Y3Zjm/fTIxWyd3dCM/ETLzeJtIP2gX3K4mZv7sBBwn8sfV7 Oianda7WxeDScDQIFcBDsndr+LqdiWd8cOSFFgyb7rnRquS6Rv4Liu0mVs+bSjQ9lY uGE9ONbXVE5KKhI6AC51wD8YXijvWh9Np3ldY3MxeJTnZlZdpaKs1MmG0mPjxpbNH+ Wgp4cGKaeHoHdL/cjWCWeet12NpVQXI+WC0lQBV2OtD9aTR6U0Wje53SUSCQtLw+Py urjnnF2Wxq1o4DgsfuXQUTOOmkEueiQaSTi3x0KlyNoWUIdxStLoKJgW+hjwasVzTm mPPsnfV8f3QUg== Original-Received: from alfajor (unknown [216.154.41.47]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id B4D8C1203B6; Mon, 15 Feb 2021 10:50:31 -0500 (EST) In-Reply-To: (Tony Olagbaiye's message of "Mon, 15 Feb 2021 14:29:06 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:200068 Archived-At: [ Hi Kim, long time no see. I'd appreciate your opinion on this issue with bindat.el. ] > (defconst minrepro--str-spec > '((len u32) > (val str (eval (let ((len (minrepro--bindat-unsigned-to-signed > (bindat-get-field struct 'len) > 4))) > ;; Hack for signed/unsigned problems > (if (<= len 0) 0 len)))))) Hmm... the doc of bindat.el does not include `struct` among the vars you can use in `eval`. OTOH, a variable which you can use is `last` and it indeed contains exactly the info you need from `struct`, so you can rewrite the above to: (defconst minrepro--str-spec '((len u32) (val str (eval (let ((len (minrepro--bindat-unsigned-to-signed last 4))) ;; Hack for signed/unsigned problems (if (<= len 0) 0 len)))))) > (defconst minrepro--message-spec > '((length u32) > (compression u8) > (id struct minrepro--str-spec) > (data vec (eval (let ((l (- (bindat-get-field struct 'length) > 4 ;length > 1 ;compression > (+ 4 (length (bindat-get-field struct 'id 'val)))))) > l))))) This one OTOH can't just use `last` since that only gives us the `id` field but not the `length` field :-( I can't see any way to do what you want given the documentation found in the `Commentary:` of `bindat.el`, so I guess we do need to extend the documented functionality. I installed the patch below, for now. It fixes the problem in your test case and hopefully in other cases as well. Please confirm. Stefan diff --git a/lisp/emacs-lisp/bindat.el b/lisp/emacs-lisp/bindat.el index 0d9ba57d66..bf01347ae0 100644 --- a/lisp/emacs-lisp/bindat.el +++ b/lisp/emacs-lisp/bindat.el @@ -26,7 +26,7 @@ ;; Packing and unpacking of (binary) data structures. ;; ;; The data formats used in binary files and network protocols are -;; often structed data which can be described by a C-style structure +;; often structured data which can be described by a C-style structure ;; such as the one shown below. Using the bindat package, decoding ;; and encoding binary data formats like these is made simple using a ;; structure specification which closely resembles the C style @@ -135,7 +135,8 @@ ;; | ( [FIELD] repeat COUNT ITEM... ) ;; -- In (eval EXPR), the value of the last field is available in -;; the dynamically bound variable `last'. +;; the dynamically bound variable `last' and all the previous +;; ones in the variable `struct'. ;; TYPE ::= ( eval EXPR ) -- interpret result as TYPE ;; | u8 | byte -- length 1 @@ -191,7 +192,7 @@ ;;; Code: ;; Helper functions for structure unpacking. -;; Relies on dynamic binding of BINDAT-RAW and BINDAT-IDX +;; Relies on dynamic binding of `bindat-raw' and `bindat-idx'. (defvar bindat-raw) (defvar bindat-idx) @@ -276,8 +277,8 @@ bindat--unpack-item (t nil))) (defun bindat--unpack-group (spec) - (with-suppressed-warnings ((lexical last)) - (defvar last)) + (with-suppressed-warnings ((lexical struct last)) + (defvar struct) (defvar last)) (let (struct last) (while spec (let* ((item (car spec)) @@ -378,9 +379,9 @@ bindat--fixed-length-alist (ip . 4))) (defun bindat--length-group (struct spec) - (with-suppressed-warnings ((lexical last)) - (defvar last)) - (let (last) + (with-suppressed-warnings ((lexical struct last)) + (defvar struct) (defvar last)) + (let ((struct struct) last) (while spec (let* ((item (car spec)) (field (car item)) @@ -544,9 +545,9 @@ bindat--pack-item (setq bindat-idx (+ bindat-idx len))))) (defun bindat--pack-group (struct spec) - (with-suppressed-warnings ((lexical last)) - (defvar last)) - (let (last) + (with-suppressed-warnings ((lexical struct last)) + (defvar struct) (defvar last)) + (let ((struct struct) last) (while spec (let* ((item (car spec)) (field (car item))