Subject: bug#69749: closed (Re: bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 17 Mar 2024 19:14:02 +0000

Your bug report

#69749: (bindat-type sint 32 t) -> unbound variable bitlen

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
69749: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69749
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen
From: Eli Zaretskii <[email-masked]>
To: Eric Marsden <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Sun, 17 Mar 2024 21:13:10 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> Date: Sun, 17 Mar 2024 19:28:17 +0100
> Cc: [email-masked]
> From: Eric Marsden <[email-masked]>
> 
> Le 3/16/2024 à 12:16 PM, Eli Zaretskii a écrit :
> >> The patch I installed indeed doesn't impact the performance of the code.
> >> The underlying detail which requires `lexical-binding` to be active does
> >> cause the code for `sint` to be significantly less efficient than that
> >> for `uint`, tho, so if performance is important, you may prefer to use
> >> `uint` and do the conversion to a signed integer manually elsewhere. 🙁
> > Thanks, should we now close this bug?
> 
> In my opinion yes, and thanks.
> 
> (Not sure whether my cc to -done will work.)

It will.

Subject: (bindat-type sint 32 t) -> unbound variable bitlen
From: Eric Marsden <[email-masked]>
To: [email-masked]
Date: Tue, 12 Mar 2024 16:18:58 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

-- file bd.el
(require 'bindat)
(bindat-pack (bindat-type sint 32 t) 42)
-- 
emacs -Q --batch -l bd.el -->

Error: void-variable (bitlen)
   mapbacktrace(#f(compiled-function (evald func args flags) #<bytecode 
-0x160fbb9816517825>))
   debug-early-backtrace()
   debug-early(error (void-variable bitlen))
   (/ bitlen 8)
   (+ bindat-idx (/ bitlen 8))
   (setq bindat-idx (+ bindat-idx (/ bitlen 8)))
   (let ((v field2)) (setq bindat-idx (+ bindat-idx (/ bitlen 8))))
   (let ((field2 (if (< v 0) (+ v wrap) v))) (let ((v field2)) (setq 
bindat-idx (+ bindat-idx (/ bitlen 8)))))
   (let ((v v)) (let ((field2 (if (< v 0) (+ v wrap) v))) (let ((v 
field2)) (setq bindat-idx (+ bindat-idx (/ bitlen 8))))))
   (lambda (v) (let ((v v)) (let ((field2 (if (< v 0) (+ v wrap) v))) 
(let ((v field2)) (setq bindat-idx (+ bindat-idx (/ bitlen 8)))))))(42)
   bindat--length-group(42 #s(bindat--type :le (lambda (v) (let ((v v)) 
(let ((field2 (if (< v 0) (+ v wrap) v))) (let ((v field2)) (setq 
bindat-idx (+ bindat-idx (/ bitlen 8))))))) :ue (lambda nil (let ((n (if 
t (bindat--unpack-uintr bitlen) (bindat--unpack-uint bitlen)))) (if (>= 
n max) (- n wrap) n))) :pe (lambda (v) (let ((v v)) (let ((field2 (if (< 
v 0) (+ v wrap) v))) (let ((v field2)) (if t (bindat--pack-uintr bitlen 
v) (bindat--pack-uint bitlen v))))))))
   bindat-length(#s(bindat--type :le (lambda (v) (let ((v v)) (let 
((field2 (if (< v 0) (+ v wrap) v))) (let ((v field2)) (setq bindat-idx 
(+ bindat-idx (/ bitlen 8))))))) :ue (lambda nil (let ((n (if t 
(bindat--unpack-uintr bitlen) (bindat--unpack-uint bitlen)))) (if (>= n 
max) (- n wrap) n))) :pe (lambda (v) (let ((v v)) (let ((field2 (if (< v 
0) (+ v wrap) v))) (let ((v field2)) (if t (bindat--pack-uintr bitlen v) 
(bindat--pack-uint bitlen v))))))) 42)
   bindat-pack(#s(bindat--type :le (lambda (v) (let ((v v)) (let 
((field2 (if (< v 0) (+ v wrap) v))) (let ((v field2)) (setq bindat-idx 
(+ bindat-idx (/ bitlen 8))))))) :ue (lambda nil (let ((n (if t 
(bindat--unpack-uintr bitlen) (bindat--unpack-uint bitlen)))) (if (>= n 
max) (- n wrap) n))) :pe (lambda (v) (let ((v v)) (let ((field2 (if (< v 
0) (+ v wrap) v))) (let ((v field2)) (if t (bindat--pack-uintr bitlen v) 
(bindat--pack-uint bitlen v))))))) 42)
   load-with-code-conversion("/tmp/bd.el" "/tmp/bd.el" nil t)
   command-line-1(("-l" "/tmp/bd.el"))
   command-line()
   normal-top-level()
Symbol’s value as variable is void: bitlen

This bug is difficult to understand. Run from an IELM buffer, this code 
works as expected. The macroexpansion of the bindat-type declaration 
includes a binding for bitlen.

GNU Emacs 29.2 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.41, 
cairo version 1.18.0) of 2024-03-09, modified by Debian