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