GNU bug report logs - #69749
(bindat-type sint 32 t) -> unbound variable bitlen

Previous Next

Package: emacs;

Reported by: Eric Marsden <eric.marsden <at> risk-engineering.org>

Date: Tue, 12 Mar 2024 15:20:02 UTC

Severity: normal

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 69749 in the body.
You can then email your comments to 69749 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#69749; Package emacs. (Tue, 12 Mar 2024 15:20:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Eric Marsden <eric.marsden <at> risk-engineering.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 12 Mar 2024 15:20:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Eric Marsden <eric.marsden <at> risk-engineering.org>
To: bug-gnu-emacs <at> gnu.org
Subject: (bindat-type sint 32 t) -> unbound variable bitlen
Date: Tue, 12 Mar 2024 16:18:58 +0100
-- 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







Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69749; Package emacs. (Wed, 13 Mar 2024 11:54:02 GMT) Full text and rfc822 format available.

Message #8 received at 69749 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Eric Marsden <eric.marsden <at> risk-engineering.org>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 69749 <at> debbugs.gnu.org
Subject: Re: bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen
Date: Wed, 13 Mar 2024 13:53:12 +0200
> Date: Tue, 12 Mar 2024 16:18:58 +0100
> From: Eric Marsden <eric.marsden <at> risk-engineering.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.

Thanks, I added Stefan to this discussion.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69749; Package emacs. (Wed, 13 Mar 2024 12:56:02 GMT) Full text and rfc822 format available.

Message #11 received at 69749 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 69749 <at> debbugs.gnu.org, Eric Marsden <eric.marsden <at> risk-engineering.org>
Subject: Re: bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen
Date: Wed, 13 Mar 2024 08:54:53 -0400
>> -- file bd.el
>> (require 'bindat)
>> (bindat-pack (bindat-type sint 32 t) 42)
>> -- 

When you open this file in Emacs≥28, the modeline will have an orange
"/d" which is meant to warn you that something's amiss.
Click on it, and your problem will be solved :-)

>> 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.

Your code ends up (via the `sint` of `bindat-type`) relying on the
`lexical-binding` dialect of ELisp, which is enabled by default in
`ielm` but not in your file.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69749; Package emacs. (Fri, 15 Mar 2024 16:53:01 GMT) Full text and rfc822 format available.

Message #14 received at 69749 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eric Marsden <eric.marsden <at> risk-engineering.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 69749 <at> debbugs.gnu.org
Subject: Re: bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen
Date: Fri, 15 Mar 2024 12:51:36 -0400
>> Your code ends up (via the `sint` of `bindat-type`) relying on the
>> `lexical-binding` dialect of ELisp, which is enabled by default in
>> `ielm` but not in your file.
> Indeed, thanks for the fix.
> Perhaps it would be useful for the bindat-type macro to emit a warning when
> it is running in the dynamic-binding dialect (at least for the types that
> require lexical binding)?

Agreed.  I just pushed a corresponding patch to `master`.
It impacts only `sint` (among the predefined types).

> This would have no runtime cost when byte-compiled or native-compiled,
> I assume.

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. 🙁


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69749; Package emacs. (Sat, 16 Mar 2024 11:18:01 GMT) Full text and rfc822 format available.

Message #17 received at 69749 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 69749 <at> debbugs.gnu.org, eric.marsden <at> risk-engineering.org
Subject: Re: bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen
Date: Sat, 16 Mar 2024 13:16:17 +0200
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: Eli Zaretskii <eliz <at> gnu.org>,  69749 <at> debbugs.gnu.org
> Date: Fri, 15 Mar 2024 12:51:36 -0400
> 
> >> Your code ends up (via the `sint` of `bindat-type`) relying on the
> >> `lexical-binding` dialect of ELisp, which is enabled by default in
> >> `ielm` but not in your file.
> > Indeed, thanks for the fix.
> > Perhaps it would be useful for the bindat-type macro to emit a warning when
> > it is running in the dynamic-binding dialect (at least for the types that
> > require lexical binding)?
> 
> Agreed.  I just pushed a corresponding patch to `master`.
> It impacts only `sint` (among the predefined types).
> 
> > This would have no runtime cost when byte-compiled or native-compiled,
> > I assume.
> 
> 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?




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sun, 17 Mar 2024 19:14:02 GMT) Full text and rfc822 format available.

Notification sent to Eric Marsden <eric.marsden <at> risk-engineering.org>:
bug acknowledged by developer. (Sun, 17 Mar 2024 19:14:02 GMT) Full text and rfc822 format available.

Message #22 received at 69749-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Eric Marsden <eric.marsden <at> risk-engineering.org>
Cc: 69749-done <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca
Subject: Re: bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen
Date: Sun, 17 Mar 2024 21:13:10 +0200
> Date: Sun, 17 Mar 2024 19:28:17 +0100
> Cc: 69749-done <at> debbugs.gnu.org
> From: Eric Marsden <eric.marsden <at> risk-engineering.org>
> 
> 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.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 15 Apr 2024 11:26:12 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 144 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.