unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen
@ 2024-03-12 15:18 Eric Marsden
  2024-03-13 11:53 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Marsden @ 2024-03-12 15:18 UTC (permalink / raw)
  To: 69749

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








^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen
  2024-03-12 15:18 bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen Eric Marsden
@ 2024-03-13 11:53 ` Eli Zaretskii
  2024-03-13 12:54   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2024-03-13 11:53 UTC (permalink / raw)
  To: Eric Marsden, Stefan Monnier; +Cc: 69749

> Date: Tue, 12 Mar 2024 16:18:58 +0100
> From: Eric Marsden <eric.marsden@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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen
  2024-03-13 11:53 ` Eli Zaretskii
@ 2024-03-13 12:54   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
       [not found]     ` <4a7ccaf7-02dc-4cca-b6e7-520ffb45dcac@risk-engineering.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-03-13 12:54 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 69749, Eric Marsden

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






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen
       [not found]     ` <4a7ccaf7-02dc-4cca-b6e7-520ffb45dcac@risk-engineering.org>
@ 2024-03-15 16:51       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-03-16 11:16         ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-03-15 16:51 UTC (permalink / raw)
  To: Eric Marsden; +Cc: Eli Zaretskii, 69749

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






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen
  2024-03-15 16:51       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-03-16 11:16         ` Eli Zaretskii
       [not found]           ` <000d8acf-bad4-432a-a775-0c03225674fe@risk-engineering.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2024-03-16 11:16 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 69749, eric.marsden

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: Eli Zaretskii <eliz@gnu.org>,  69749@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?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen
       [not found]           ` <000d8acf-bad4-432a-a775-0c03225674fe@risk-engineering.org>
@ 2024-03-17 19:13             ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2024-03-17 19:13 UTC (permalink / raw)
  To: Eric Marsden; +Cc: 69749-done, monnier

> Date: Sun, 17 Mar 2024 19:28:17 +0100
> Cc: 69749-done@debbugs.gnu.org
> From: Eric Marsden <eric.marsden@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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-17 19:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-12 15:18 bug#69749: (bindat-type sint 32 t) -> unbound variable bitlen Eric Marsden
2024-03-13 11:53 ` Eli Zaretskii
2024-03-13 12:54   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
     [not found]     ` <4a7ccaf7-02dc-4cca-b6e7-520ffb45dcac@risk-engineering.org>
2024-03-15 16:51       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-16 11:16         ` Eli Zaretskii
     [not found]           ` <000d8acf-bad4-432a-a775-0c03225674fe@risk-engineering.org>
2024-03-17 19:13             ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).