Subject: bug#33073: 27.0.50; Fatal error when comparing threads with 'equal'

From: Gemini Lasswell <[email-masked]>
Date: Tue, 16 Oct 2018 21:58:20 -0700

When Emacs is configured with assertions, it fails at one when using
'equal' to compare main-thread to another thread.  The configure flags
which I am using are:

   --enable-checking=yes,glyphs --enable-check-lisp-object-type

To reproduce:

>From emacs -Q, enter the following code into *scratch* and
then M-x eval-buffer RET:

(defun my-func () (while t (sleep-for 10)))
(setq my-t (make-thread 'my-func))
(equal main-thread my-t) 

Result:

lisp.h:1548: Emacs fatal error: assertion failed: 0 <= size

Thread 1 "emacs" hit Breakpoint 1, terminate_due_to_signal (sig=sig@entry=6, 
    backtrace_limit=backtrace_limit@entry=2147483647) at emacs.c:369
369	{
(gdb) bt
#0  terminate_due_to_signal (sig=sig@entry=6, 
    backtrace_limit=backtrace_limit@entry=2147483647) at emacs.c:369
#1  0x00000000005a7259 in die (msg=msg@entry=0x678e84 "0 <= size", 
    file=file@entry=0x678da5 "lisp.h", line=line@entry=1548) at alloc.c:7094
#2  0x0000000000536bda in ASIZE (array=...) at lisp.h:1548
#3  0x00000000005dbb18 in internal_equal (o1=XIL(0xd73485), o2=XIL(0x15dfc35), 
    equal_kind=equal_kind@entry=EQUAL_PLAIN, depth=depth@entry=0, ht=..., 
    ht@entry=XIL(0)) at fns.c:2422
#4  0x00000000005dc163 in Fequal (o1=..., o2=...) at fns.c:2314
#5  0x00000000005cd6e6 in eval_sub (form=...) at eval.c:2327
#6  0x00000000005f6d60 in readevalloop_eager_expand_eval (val=..., 
    val@entry=XIL(0x4302393), macroexpand=macroexpand@entry=XIL(0xe3130))
    at lread.c:1903
#7  0x00000000005fd0c5 in readevalloop (
    readcharfun=readcharfun@entry=XIL(0xde3805), infile0=infile0@entry=0x0, 
    sourcename=..., sourcename@entry=XIL(0), printflag=false, unibyte=..., 
    unibyte@entry=XIL(0), readfun=..., readfun@entry=XIL(0), start=XIL(0), 
    end=...) at lread.c:2089
#8  0x00000000005fe749 in Feval_buffer (buffer=..., printflag=XIL(0), 
    filename=XIL(0), unibyte=..., do_allow_print=...) at lread.c:2156
#9  0x00000000005cc5b3 in funcall_subr (subr=0xcd9480 <Seval_buffer>, 
    numargs=numargs@entry=0, args=args@entry=0x7fff2cf3c450) at eval.c:2946
#10 0x00000000005ca771 in Ffuncall (nargs=nargs@entry=1, 
    args=args@entry=0x7fff2cf3c448) at eval.c:2859
#11 0x00000000005c6653 in Ffuncall_interactively (nargs=1, args=0x7fff2cf3c448)
    at callint.c:253
#12 0x00000000005ca771 in Ffuncall (nargs=nargs@entry=2, 
    args=args@entry=0x7fff2cf3c440) at eval.c:2859
#13 0x00000000005c7dd9 in Fcall_interactively (function=..., record_flag=..., 
    keys=...) at callint.c:781
#14 0x00000000005cc5d7 in funcall_subr (subr=0xcd6100 <Scall_interactively>, 
    numargs=numargs@entry=3, args=args@entry=0x7fff2cf3c700) at eval.c:2939
#15 0x00000000005ca771 in Ffuncall (nargs=4, args=args@entry=0x7fff2cf3c6f8)
    at eval.c:2859
#16 0x0000000000611f00 in exec_byte_code (bytestr=..., vector=..., maxdepth=..., 
    args_template=..., nargs=nargs@entry=2, args=<optimized out>, 
    args@entry=0x9c69e8 <pure+820392>) at bytecode.c:632
#17 0x00000000005cde82 in funcall_lambda (fun=XIL(0x7fff2cf3c6f8), 
    nargs=nargs@entry=2, arg_vector=0x9c69e8 <pure+820392>, 
    arg_vector@entry=0x7fff2cf3c9e8) at eval.c:3060
#18 0x00000000005ca65b in Ffuncall (nargs=3, args=args@entry=0x7fff2cf3c9e0)
    at eval.c:2873
#19 0x0000000000611f00 in exec_byte_code (bytestr=..., vector=..., maxdepth=..., 
    args_template=..., nargs=nargs@entry=3, args=<optimized out>, 
    args@entry=0x9c6698 <pure+819544>) at bytecode.c:632
#20 0x00000000005cde82 in funcall_lambda (fun=XIL(0x7fff2cf3c9e0), 
    nargs=nargs@entry=3, arg_vector=0x9c6698 <pure+819544>, 
    arg_vector@entry=0x7fff2cf3cdd0) at eval.c:3060
#21 0x00000000005ca65b in Ffuncall (nargs=nargs@entry=4, 
    args=args@entry=0x7fff2cf3cdc8) at eval.c:2873
#22 0x00000000005c6653 in Ffuncall_interactively (nargs=4, args=0x7fff2cf3cdc8)
    at callint.c:253
#23 0x00000000005ca771 in Ffuncall (nargs=nargs@entry=5, args=0x7fff2cf3cdc0)
    at eval.c:2859
#24 0x00000000005caa3a in Fapply (nargs=nargs@entry=3, 
    args=args@entry=0x7fff2cf3cf70) at eval.c:2479
#25 0x00000000005c6de1 in Fcall_interactively (function=..., record_flag=..., 
    keys=...) at callint.c:340
#26 0x00000000005cc5d7 in funcall_subr (subr=0xcd6100 <Scall_interactively>, 
    numargs=numargs@entry=3, args=args@entry=0x7fff2cf3d100) at eval.c:2939
#27 0x00000000005ca771 in Ffuncall (nargs=4, args=args@entry=0x7fff2cf3d0f8)
    at eval.c:2859
#28 0x0000000000611f00 in exec_byte_code (bytestr=..., vector=..., maxdepth=..., 
    args_template=..., nargs=nargs@entry=1, args=<optimized out>, 
    args@entry=0x9c69e8 <pure+820392>) at bytecode.c:632
#29 0x00000000005cde82 in funcall_lambda (fun=XIL(0x7fff2cf3d0f8), 
    nargs=nargs@entry=1, arg_vector=0x9c69e8 <pure+820392>, 
    arg_vector@entry=0x7fff2cf3d3b8) at eval.c:3060
#30 0x00000000005ca65b in Ffuncall (nargs=nargs@entry=2, 
    args=args@entry=0x7fff2cf3d3b0) at eval.c:2873
#31 0x00000000005ca83a in call1 (fn=..., fn@entry=XIL(0x3ff0), arg1=...)
    at eval.c:2710
#32 0x000000000054f597 in command_loop_1 () at keyboard.c:1451
#33 0x00000000005c975f in internal_condition_case (
    bfun=bfun@entry=0x54f080 <command_loop_1>, handlers=..., 
    handlers@entry=XIL(0x53a0), hfun=hfun@entry=0x541d60 <cmd_error>)
    at eval.c:1373
#34 0x000000000053db88 in command_loop_2 (ignore=..., ignore@entry=XIL(0))
    at keyboard.c:1079
#35 0x00000000005c9683 in internal_catch (tag=..., 
    func=func@entry=0x53db60 <command_loop_2>, arg=..., arg@entry=XIL(0))
    at eval.c:1136
#36 0x000000000053ddeb in command_loop () at keyboard.c:1058
#37 0x0000000000541864 in recursive_edit_1 () at keyboard.c:703
#38 0x0000000000541c23 in Frecursive_edit () at keyboard.c:774
#39 0x000000000041e727 in main (argc=<optimized out>, argv=<optimized out>)
    at emacs.c:1731

Lisp Backtrace:
"equal" (0x2cf3c120)
"eval-buffer" (0x2cf3c450)
"funcall-interactively" (0x2cf3c448)
"call-interactively" (0x2cf3c700)
"command-execute" (0x2cf3c9e8)
"execute-extended-command" (0x2cf3cdd0)
"funcall-interactively" (0x2cf3cdc8)
"call-interactively" (0x2cf3d100)
"command-execute" (0x2cf3d3b8)

(gdb) p main_thread.header
$1 = {
  size = -4611686018091843576
}
(gdb) p all_threads->header
$2 = {
  size = 4611686018763149320
}
(gdb) p/x main_thread.header
$3 = {
  size = 0xc000000014000008
}
(gdb) p/x all_threads->header
$4 = {
  size = 0x4000000014035008
}

In GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
 of 2018-10-16 built on sockeye
Repository revision: e64065bbbd21b7136a7a4efb4b0f2f39a65905dd
Windowing system distributor 'The X.Org Foundation', version 11.0.11906000
System Description: NixOS 18.09.git.ad56635 (Jellyfish)

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.

Configured using:
 'configure --prefix=/home/gem/src/emacs/master/bin --with-modules
 --with-x-toolkit=gtk3 --with-xft --config-cache
 --enable-checking=yes,glyphs --enable-check-lisp-object-type'

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND DBUS GSETTINGS GLIB NOTIFY LIBSELINUX
GNUTLS LIBXML2 FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM
MODULES THREADS GMP

Important settings:
  value of $EMACSLOADPATH:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny seq byte-opt gv
bytecomp byte-compile cconv dired dired-loaddefs format-spec rfc822 mml
easymenu mml-sec password-cache epa derived epg epg-config gnus-util
rmail rmail-loaddefs time-date mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs cl-lib sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils elec-pair
mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/x-win x-win term/common-win x-dnd tool-bar
dnd fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads dbusbind
inotify dynamic-setting system-font-setting font-render-setting
move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 94825 10040)
 (symbols 48 20044 1)
 (strings 32 28460 1827)
 (string-bytes 1 811220)
 (vectors 16 14265)
 (vector-slots 8 504082 12778)
 (floats 8 47 70)
 (intervals 56 213 0)
 (buffers 992 11))