Subject: bug#63614: 29.0.91; PGTK Emacs crashes after clearing the clipboard

From: Leonardo Hernández <[email-masked]>
Date: Sat, 20 May 2023 18:52:31 +0000

Hello, I have been having issues with crashes running Emacs with PGTK
on Wayland.

To reproduce, open `emacs -Q`, then copy whatever you want with <M-w> or
<C-w> and then copy another thing outside Emacs, for example, `wl-copy
<<< "Copied text"`, then Emacs crashes.

Backtrace:
#0 0x00007f92636ac8ec in () at /usr/lib64/libc.so.6
#1 0x00007f926365d3e2 in raise () at /usr/lib64/libc.so.6
#2 0x0000563f0697d0a5 in terminate_due_to_signal (sig=11, 
backtrace_limit=<optimized out>) at emacs.c:464
#3 0x0000563f0697def8 in handle_fatal_signal (sig=11) at sysdep.c:1783
fatal = <optimized out>
#4 deliver_thread_signal (handler=<optimized out>, sig=11) at sysdep.c:1775
fatal = <optimized out>
#5 deliver_fatal_thread_signal (sig=11) at sysdep.c:1795
fatal = <optimized out>
#6 handle_sigsegv (sig=11, siginfo=0x563f072243f0 <sigsegv_stack+64496>, 
arg=<optimized out>) at sysdep.c:1888
fatal = <optimized out>
#7 0x00007f926365d490 in <signal handler called> () at /usr/lib64/libc.so.6
#8 0x0000563f06c49d89 in pgtk_handle_selection_clear (event=<optimized 
out>) at pgtkselect.c:742
selection = <optimized out>
changed_owner_time = 0
selection_symbol = <optimized out>
local_selection_data = <optimized out>
local_selection_time = <optimized out>
dpyinfo = 0x90c1b80
Vselection_alist = <optimized out>
#9 0x0000563f06a9a5c6 in pgtk_handle_selection_event 
(event=0x7fff20369bc0) at pgtkselect.c:782
event = 0x563f071d44a0 <kbd_buffer+1344>
copy = {kind = SELECTION_CLEAR_EVENT, dpyinfo = 0x90c1b80, requestor = 
0x0, selection = 0x45, target = 0x0, property = 0x0, time = 0}
moved_events = <optimized out>
#10 process_special_events () at keyboard.c:4449
event = 0x563f071d44a0 <kbd_buffer+1344>
copy = {kind = SELECTION_CLEAR_EVENT, dpyinfo = 0x90c1b80, requestor = 
0x0, selection = 0x45, target = 0x0, property = 0x0, time = 0}
moved_events = <optimized out>
#11 0x0000563f06a9b7cd in swallow_events (do_display=true) at 
keyboard.c:4489
old_timers_run = <optimized out>
#12 0x0000563f06bc2c0c in wait_reading_process_output 
(time_limit=<optimized out>, nsecs=<optimized out>, read_kbd=<optimized 
out>, do_display=<optimized out>, wait_for_cell=<optimized out>, 
wait_proc=<optimized out>, just_wait_proc=<optimized out>) at 
process.c:5781
leave = false
wrapped = <optimized out>
process_skipped = <optimized out>
channel_start = <optimized out>
child_fd = <optimized out>
channel = <optimized out>
nfds = <optimized out>
Available = {fds_bits = {16, 0 <repeats 15 times>}}
Writeok = {fds_bits = {0 <repeats 16 times>}}
check_write = true
check_delay = <optimized out>
no_avail = false
xerrno = 11
proc = <optimized out>
timeout = {tv_sec = 0, tv_nsec = 0}
end_time = {tv_sec = <optimized out>, tv_nsec = <optimized out>}
timer_delay = {tv_sec = <optimized out>, tv_nsec = <optimized out>}
got_output_end_time = {tv_sec = <optimized out>, tv_nsec = <optimized out>}
wait = <optimized out>
got_some_output = <optimized out>
prev_wait_proc_nbytes_read = <optimized out>
retry_for_async = <optimized out>
count = {bytes = <optimized out>}
now = {tv_sec = <optimized out>, tv_nsec = <optimized out>}
last_read_channel = 17
#13 0x0000563f06997b20 in sit_for (timeout=<optimized out>, 
reading=<optimized out>, display_option=<optimized out>) at dispnew.c:6264
sec = 30
nsec = 0
do_display = <optimized out>
curbuf_eq_winbuf = true
nbytes = <optimized out>
#14 0x0000563f06aa40d5 in read_char (commandflag=1, map=0x563f09b61013, 
prev_event=0x0, used_mouse_menu=0x7fff2036a6bb, end_time=0x0) at 
keyboard.c:2881
delay_level = <optimized out>
buffer_size = <optimized out>
c = 0x0
local_getcjmp = {{__jmpbuf = {94828702059008, -8807486309767267314, 1, 
94828736677880, 0, 94828745980467, -8807486309702255602, 
-3006776290544272370}, __mask_was_saved = 0, __saved_mask = {__val = 
{94828696057600, 140266600468637, 66, 140266600466355, 94828696063071, 
140266600468637, 40080, 140733733840032, 0, 0, 94828736677885, 0, 
94828745829971, 0, 16, 17}}}}
save_jump = {{__jmpbuf = {0, 0, 0, 0, 0, 0, 0, 0}, __mask_was_saved = 0, 
__saved_mask = {__val = {0 <repeats 16 times>}}}}
tem = <optimized out>
save = <optimized out>
previous_echo_area_message = 0x0
also_record = 0x0
reread = false
recorded = false
polling_stopped_here = false
orig_kboard = 0x563f08f43c30
#15 0x0000563f06c620d7 in read_key_sequence.constprop.0 
(keybuf=<optimized out>, prevent_redisplay=false, 
fix_current_buffer=<optimized out>, can_return_switch_frame=<optimized 
out>, dont_downcase_last=<optimized out>, prompt=<optimized out>) at 
keyboard.c:10083
interrupted_kboard = 0x563f08f43c30
key = <optimized out>
used_mouse_menu = false
echo_local_start = 0
last_real_key_start = 0
keys_local_start = 0
new_binding = <optimized out>
t = 0
echo_start = 0
keys_start = 0
current_binding = 0x563f09b61013
first_unbound = 31
mock_input = 0
used_mouse_menu_history = {false <repeats 30 times>}
fkey = {parent = 0x563f08e6f3d3, map = 0x563f08e6f3d3, start = 0, end = 0}
keytran = {parent = 0x7f925d6191eb, map = 0x7f925d6191eb, start = 0, end 
= 0}
indec = {parent = 0x563f08e6f4a3, map = 0x563f08e6f4a3, start = 0, end = 0}
shift_translated = <optimized out>
delayed_switch_frame = <optimized out>
original_uppercase = <optimized out>
original_uppercase_position = <optimized out>
dummyflag = false
fake_prefixed_keys = 0x0
first_event = 0x0
second_event = <optimized out>
#16 0x0000563f06a9776a in command_loop_1 () at keyboard.c:1384
cmd = <optimized out>
keybuf = {0x200001de, 0x1a, 0x7fff2036a8f0, 0x2, 0x295355bfea70, 
0x7f925cf00a7d, 0x0, 0x563f06c6728d <run_hook_with_args.constprop.0+45>, 
0x1, 0x1, 0x1, 0x7fff2036a950, 0x7fff2036a8c0, 0x563f0722f000 <freloc>, 
0x563f06ca0314, 0x7f92636ba48c, 0x295355ba8688, 0x981baf1862a21b00, 
0x9510, 0x563f06ca6dc0, 0x7fff2036a980, 0x60, 0x563f08fd28d4, 0x0, 
0x563f06d19020 <main_thread.lto_priv>, 0x563f06a954a5 <top_level_2+725>, 
0x563f06ca0314, 0x7f92636baf12 <malloc+434>, 0x563f06ca0314, 0x30}
i = <optimized out>
prev_modiff = 6
prev_buffer = 0x563f092a07f8
#17 0x0000563f06b4cc67 in internal_condition_case (bfun=0x563f06a974a0 
<command_loop_1>, handlers=<optimized out>, hfun=0x563f06a94f00 
<cmd_error>) at eval.c:1474
val = <optimized out>
c = 0x563f08f8c370
#18 0x0000563f06a951be in command_loop_2 (handlers=handlers@entry=0x90) 
at keyboard.c:1133
val = <optimized out>
#19 0x0000563f06b4cbbc in internal_catch (tag=<optimized out>, 
func=0x563f06a95190 <command_loop_2>, arg=0x90) at eval.c:1197
val = <optimized out>
c = 0x563f08f8c240
#20 0x0000563f06a96f89 in command_loop () at keyboard.c:1111
#21 0x0000563f06c95c30 in recursive_edit_1.isra.0 () at keyboard.c:720
val = <optimized out>
#22 0x0000563f06a9746c in Frecursive_edit () at keyboard.c:803
buffer = <optimized out>
#23 0x0000563f0698b274 in main (argc=<optimized out>, 
argv=0x7fff2036adc8) at emacs.c:2529
stack_bottom_variable = 0x0
no_loadup = false
junk = 0x0
dname_arg = 0x0
ch_to_dir = 0x0
original_pwd = 0x0
dump_mode = <optimized out>
skip_args = 0
temacs = 0x0
attempt_load_pdump = <optimized out>
only_version = false
rlim = {rlim_cur = 10022912, rlim_max = 18446744073709551615}
lc_all = <optimized out>
sockfd = -1
module_assertions = <optimized out>

In GNU Emacs 29.0.91 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.37, cairo version 1.17.8) of 2023-05-20 built on localhost
Repository revision: f571e8f1bb678c52839180e450c2415b31a70516
Repository branch: emacs-29
System Description: Gentoo Linux

Configured using:
'configure --prefix=/usr --build=x86_64-pc-linux-gnu
--host=x86_64-pc-linux-gnu --mandir=/usr/share/man
--infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc
--localstatedir=/var/lib --datarootdir=/usr/share
--disable-silent-rules --docdir=/usr/share/doc/emacs-29.0.9999-r1
--htmldir=/usr/share/doc/emacs-29.0.9999-r1/html --libdir=/usr/lib64
--program-suffix=-emacs-29-vcs --includedir=/usr/include/emacs-29-vcs
--infodir=/usr/share/info/emacs-29-vcs --localstatedir=/var
--enable-locallisppath=/etc/emacs:/usr/share/emacs/site-lisp
--without-compress-install --without-hesiod --without-pop
--with-file-notification=inotify --with-pdumper --enable-acl
--with-dbus --with-modules --without-gameuser --with-libgmp --with-gpm
--with-native-compilation=aot --with-json --without-kerberos
--without-kerberos5 --with-lcms2 --with-xml2 --with-mailutils
--without-selinux --with-sqlite3 --with-gnutls --without-libsystemd
--with-threads --with-tree-sitter --without-wide-int --with-sound=alsa
--with-zlib --with-pgtk --without-x --without-ns
--with-toolkit-scroll-bars --without-gconf --with-gsettings
--with-harfbuzz --without-libotf --without-m17n-flt --without-xwidgets
--with-gif --with-jpeg --with-png --with-rsvg --with-tiff --with-webp
--with-imagemagick --with-dumping=pdumper --with-cairo
'CFLAGS=-march=native -O3 -pipe -flto=auto -Werror=odr
-Werror=strict-aliasing -Werror=lto-type-mismatch -g3 -ggdb3 -gdwarf-4'
'LDFLAGS=-Wl,-O1 -Wl,--as-needed -Wl,-O2''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ
IMAGEMAGICK JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY
PDUMPER PGTK PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM GTK3 ZLIB

Important settings:
value of $LC_MONETARY: es_MX.UTF-8
value of $LC_NUMERIC: es_MX.UTF-8
value of $LC_TIME: es_MX.UTF-8
value of $LANG: en_US.utf8
locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
show-paren-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
buffer-read-only: t
line-number-mode: t
indent-tabs-mode: t
transient-mark-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search time-date mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
comp comp-cstr warnings icons subr-x rx cl-seq cl-macs gv cl-extra
help-mode bytecomp byte-compile cl-lib sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils rmc iso-transl tooltip cconv
eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/pgtk-win pgtk-win term/common-win pgtk-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq
simple cl-generic indonesian philippine 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 emoji-zwj charscript charprop case-table
epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button
loaddefs theme-loaddefs faces cus-face macroexp files window
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget keymap hashtable-print-readable backquote threads dbusbind
inotify dynamic-setting system-font-setting font-render-setting cairo
gtk pgtk lcms2 multi-tty make-network-process native-compile emacs)

Memory information:
((conses 16 77298 7908)
(symbols 48 7106 0)
(strings 32 19506 1667)
(string-bytes 1 590407)
(vectors 16 15625)
(vector-slots 8 327135 8165)
(floats 8 27 46)
(intervals 56 405 0)
(buffers 984 12))