unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#46534: Lexical change in bindat breaks weechat.el
@ 2021-02-15 14:29 Tony Olagbaiye
  2021-02-15 15:50 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Tony Olagbaiye @ 2021-02-15 14:29 UTC (permalink / raw)
  To: 46534; +Cc: monnier


[-- Attachment #1.1.1: Type: text/plain, Size: 1380 bytes --]

Hi,

As of commit c8c4d65d6510724acd40527a9af67e21e3cf4d5e (as bisected in my stead by wasamasa on \#emacs) it seems bindat changes have broken weechat.el, or specifically the weechat-relay module.

Attached a minimal reproducible script which fails on master but succeeds prior to the mentioned commit: weechat-bindat.bug.el.txt

Backtrace:

Debugger entered--Lisp error: (void-variable struct) (bindat-get-field struct 'len) (weechat--relay-bindat-unsigned-to-signed (bindat-get-field struct 'len) 4) (let ((len (weechat--relay-bindat-unsigned-to-signed (bindat-get-field struct 'len) 4))) (if (<= len 0) 0 len)) bindat--unpack-group(((len u32) (val str (eval (let ((len (weechat--relay-bindat-unsigned-to-signed ... 4))) (if (<= len 0) 0 len)))))) bindat--unpack-group(((length u32) (compression u8) (id struct weechat--relay-str-spec) (data vec (eval (let ((l (- ... 4 1 ...))) l))))) bindat-unpack(((length u32) (compression u8) (id struct weechat--relay-str-spec) (data vec (eval (let ((l (- ... 4 1 ...))) l)))) "\\0\\0\\0$\\0\\0\\0\\0\\4G255inf\\0\\0\\0\\7version\\0\\0\\0\\0053.0.1") weechat-unpack-message("\\0\\0\\0$\\0\\0\\0\\0\\4G255inf\\0\\0\\0\\7version\\0\\0\\0\\0053.0.1") weechat--relay-parse-new-message() weechat--relay-process-filter(\#<process weechat-relay-tls> "\\0\\0\\0$\\0\\0\\0\\0\\4G255inf\\0\\0\\0\\7version\\0\\0\\0\\0053.0.1")

Best,
bqv

[-- Attachment #1.1.2.1: Type: text/html, Size: 1364 bytes --]

[-- Attachment #1.2: weechat-bindat.bug.el.txt --]
[-- Type: text/plain, Size: 2745 bytes --]

;;; Adapted from https://github.com/the-kenny/weechat.el/blob/master/weechat-relay.el
;(load-file "/nix/store/vy6lzg2b2kmsm4yyl7x3j9pzy10y3bsv-emacs-weechat-20190520.1551/share/emacs/site-lisp/elpa/weechat-20190520.1551/weechat.el")
;(weechat-unpack-message "\0\0\0\"\0\0\0\0\2G0inf\0\0\0\7version\0\0\0\0053.0.1")

(require 'bindat)
(require 'cl-lib)

(setq debug-on-error t)

(defun minrepro--unpack-str (data)
  "Unpacks a weechat-relay-string from unibyte string DATA.
Optional second return value contains length of parsed data."
  (let ((obj (bindat-unpack minrepro--str-spec data)))
    (cl-values (decode-coding-string (bindat-get-field obj 'val) 'utf-8)
	       (bindat-length minrepro--str-spec obj))))

(defun minrepro--parse-inf (data)
  (cl-multiple-value-bind (name len) (minrepro--unpack-str data)
    (cl-multiple-value-bind (value len*) (minrepro--unpack-str (substring data len))
      (cl-values (cons name value)
		 (+ len len*)))))

(defun minrepro--bindat-unsigned-to-signed (num bytes)
  "Convert an unsigned int NUM to signed int.
NUM is in two-complement representation with BYTES bytes.
Useful because bindat does not support signed numbers."
  (if (> num (- (expt 2 (- (* 8 bytes) 1)) 1))
      (- num (expt 2 (* 8 bytes)))
    num))

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

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

(defun minrepro--unpack-message-contents (data)
  (let* ((type (substring data 0 3))
	 (fun (symbol-function (intern (concat "minrepro--parse-" type)))))
    (cl-multiple-value-bind (obj len) (funcall fun (string-make-unibyte (substring data 3)))
      (cl-values obj
		 (+ len 3)))))

(let* ((msg (bindat-unpack minrepro--message-spec "\0\0\0\"\0\0\0\0\2G0inf\0\0\0\7version\0\0\0\0053.0.1"))
       (data (concat (bindat-get-field msg 'data)))
       (msg-id (bindat-get-field msg 'id 'val))
       (offset 0)
       (acc ()))
  ;; Only no-compression is supported atm
  (unless (= 0 (bindat-get-field msg 'compression))
    (error "Compression not supported"))
  (while (< offset (length data))
	 (cl-multiple-value-bind (obj offset*) (minrepro--unpack-message-contents
						 (substring data offset))
				 (setq offset (+ offset offset*))
				 (setq acc (cons obj acc))))
  (cl-values (cons msg-id (reverse acc))
	     (bindat-get-field msg 'length)))

[-- Attachment #1.3: publickey - EmailAddress(s=me@fron.io) - 0x3026807C.asc --]
[-- Type: application/pgp-keys, Size: 616 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 233 bytes --]

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

end of thread, other threads:[~2021-02-18 16:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-15 14:29 bug#46534: Lexical change in bindat breaks weechat.el Tony Olagbaiye
2021-02-15 15:50 ` Stefan Monnier
2021-02-15 19:19   ` Tony Olagbaiye
2021-02-15 19:51     ` Stefan Monnier
2021-02-17 22:47   ` Kim Storm
2021-02-18 16:09     ` Stefan Monnier

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