Subject: bug#25851: 25.2; GTK warning when starting Emacs when desktop file has more than one frame

From: [email-masked] (N. Jackson)
Date: Fri, 24 Feb 2017 15:28:19 -0500

At 11:09 -0500 on Friday 2017-02-24, N. Jackson wrote:
>
>   (gdb) list gtkutil.c:780
>   775     static void
>   776     xg_set_geometry (struct frame *f)
>   777     {
>   778       if (f->size_hint_flags & (USPosition | PPosition))
>   779         {
>   780           int left = f->left_pos;
>   781           int xneg = f->size_hint_flags & XNegative;
>   782           int top = f->top_pos;
>   783           int yneg = f->size_hint_flags & YNegative;
>   784           char geom_str[sizeof "=x--" + 4 * INT_STRLEN_BOUND (int)];
>   (gdb) list +20
>   800                                   | G_LOG_FLAG_RECURSION, my_log_handler, NULL);
>   801
>   802           if (!gtk_window_parse_geometry (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
>   803                                           geom_str))
>   804             fprintf (stderr, "Failed to parse: '%s'\n", geom_str);
>   805
>   806           g_log_remove_handler ("Gtk", id);
>   807         }
>   808     }
>   809

FWIW, the following expands on the information in my previous
message.

I have breakpoints set a) at the entry to `xg_set_geometry' so
that I can see when it is called even when the body is not
executed, b) at the call to `gtk_window_parse_geometry' (line
802), and c) at line 806 just after the call to
`gtk_window_parse_geometry' so I can see if the GTK warning
message is emitted.

  (gdb) break xg_set_geometry 
  Breakpoint 3 at 0x5656b4: file gtkutil.c, line 778.
  (gdb) break gtkutil.c:802   
  Breakpoint 4 at 0x565799: file gtkutil.c, line 802.
  (gdb) break gtkutil.c:806
  Breakpoint 5 at 0x5657ee: file gtkutil.c, line 806.

1. With a desktop file that specifies three frames, the first time
we enter `xg_set_geometry' after starting Emacs (presumably when
the first/main Emacs frame is created), `f->size_hint_flags' is 0,
the body of the function is not executed,
`gtk_window_parse_geometry' is not called, and no warning message
is printed by GTK:

  (gdb) run
  Starting program: /data/projects/vc/emacs/emacs-25.2.rc2/src/emacs 
  [Thread debugging using libthread_db enabled]
  Using host libthread_db library "/lib64/libthread_db.so.1".
  [New Thread 0x7fffe166d700 (LWP 15522)]
  [New Thread 0x7fffe07fa700 (LWP 15523)]
  [New Thread 0x7fffde714700 (LWP 15524)]

  Thread 1 "emacs" hit Breakpoint 3, xg_set_geometry (f=0x13b4c30) at gtkutil.c:778
  778       if (f->size_hint_flags & (USPosition | PPosition))
  (gdb) bt
  [ *See bt-first-no-warning.txt attached* ]
  (gdb) print f->size_hint_flags 
  $9 = 0
  (gdb) print USPosition
  No symbol "USPosition" in current context.
  (gdb) print PPosition
  No symbol "PPosition" in current context.
  (gdb) s
  808     }
  (gdb) c
  Continuing.
  Detaching after vfork from child process 15530.
  Detaching after vfork from child process 15531.
  Detaching after vfork from child process 15532.
  Detaching after vfork from child process 15533.
  Detaching after vfork from child process 15534.
  Detaching after vfork from child process 15536.
  Detaching after vfork from child process 15537.
  Detaching after vfork from child process 15538.
  Detaching after vfork from child process 15539.
  Detaching after vfork from child process 15540.
  Detaching after vfork from child process 15541.
  Detaching after vfork from child process 15542.
  Detaching after vfork from child process 15543.
  Detaching after vfork from child process 15544.
  Detaching after vfork from child process 15545.
  Detaching after vfork from child process 15546.
  Detaching after vfork from child process 15547.
  Detaching after vfork from child process 15548.
  Detaching after vfork from child process 15549.
  Detaching after vfork from child process 15550.
  Detaching after vfork from child process 15551.

2. Each of the next two times we enter `xg_set_geometry'
(presumably as the second and third frame specified in the desktop
file are created), `f->size_hint_flags' is 4, the body of the
function is executed, `gtk_window_parse_geometry' is called, and
the warning message is printed by GTK:

  Thread 1 "emacs" hit Breakpoint 3, xg_set_geometry (f=0x31d79a0) at gtkutil.c:778
  778       if (f->size_hint_flags & (USPosition | PPosition))
  (gdb) bt
  [ *See bt-second-warns.txt attached* ]
  (gdb) print f->size_hint_flags 
  $10 = 4
  (gdb) print USPosition
  No symbol "USPosition" in current context.
  (gdb) print PPosition
  No symbol "PPosition" in current context.
  (gdb) s
  780           int left = f->left_pos;
  (gdb) c
  Continuing.

  Thread 1 "emacs" hit Breakpoint 4, xg_set_geometry (f=0x31d79a0) at gtkutil.c:802
  802           if (!gtk_window_parse_geometry (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
  (gdb) c
  Continuing.

  (emacs:15521): Gtk-WARNING **: gtk_window_parse_geometry() called on a window with no visible children; the window should be set up before gtk_window_parse_geometry() is called.

  Thread 1 "emacs" hit Breakpoint 5, xg_set_geometry (f=0x31d79a0) at gtkutil.c:806
  806           g_log_remove_handler ("Gtk", id);
  (gdb) c
  Continuing.

  Thread 1 "emacs" hit Breakpoint 3, xg_set_geometry (f=0x390cdc8) at gtkutil.c:778
  778       if (f->size_hint_flags & (USPosition | PPosition))
  (gdb) bt
  [ *See bt-third-warns.txt attached* ]
  (gdb) print f->size_hint_flags 
  $11 = 4
  (gdb) print USPosition
  No symbol "USPosition" in current context.
  (gdb) print PPosition
  No symbol "PPosition" in current context.
  (gdb) s
  780           int left = f->left_pos;
  (gdb) c
  Continuing.

  Thread 1 "emacs" hit Breakpoint 4, xg_set_geometry (f=0x390cdc8) at gtkutil.c:802
  802           if (!gtk_window_parse_geometry (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
  (gdb) c
  Continuing.

  (emacs:15521): Gtk-WARNING **: gtk_window_parse_geometry() called on a window with no visible children; the window should be set up before gtk_window_parse_geometry() is called.

  Thread 1 "emacs" hit Breakpoint 5, xg_set_geometry (f=0x390cdc8) at gtkutil.c:806
  806           g_log_remove_handler ("Gtk", id);
  (gdb) c
  Continuing.

3. Now, creating a frame interactively with `C-x 5 2', we enter
`xg_set_geometry', `f->size_hint_flags' is 0, the body of the
function is not executed, `gtk_window_parse_geometry' is not
called, and no warning message is printed by GTK:

  Thread 1 "emacs" hit Breakpoint 3, xg_set_geometry (f=0x472a1a0) at gtkutil.c:778
  778       if (f->size_hint_flags & (USPosition | PPosition))
  (gdb) bt
  [ *See bt-interactive-no-warning.txt attached* ]
  (gdb) print f->size_hint_flags 
  $12 = 0
  (gdb) print USPosition
  No symbol "USPosition" in current context.
  (gdb) print PPosition
  No symbol "PPosition" in current context.
  (gdb) s
  808     }
  (gdb) c
  Continuing.

4. Finally, starting a new instance with no desktop file, we enter
`xg_set_geometry' just once, `f->size_hint_flags' is 0, the body
of the function is not executed, `gtk_window_parse_geometry' is
not called, and no warning message is printed by GTK:

  (gdb) run --no-desktop
  Starting program: /data/projects/vc/emacs/emacs-25.2.rc2/src/emacs --no-desktop
  [Thread debugging using libthread_db enabled]
  Using host libthread_db library "/lib64/libthread_db.so.1".
  [New Thread 0x7fffe166d700 (LWP 16966)]
  [New Thread 0x7fffe07fa700 (LWP 16967)]
  [New Thread 0x7fffde714700 (LWP 16968)]

  Thread 1 "emacs" hit Breakpoint 3, xg_set_geometry (f=0x13b4c30) at gtkutil.c:778
  778       if (f->size_hint_flags & (USPosition | PPosition))
  (gdb) bt
  [ *See bt-no-desktop-no-warning.txt attached* ]
  (gdb) print f->size_hint_flags 
  $14 = 0
  (gdb) print USPosition
  No symbol "USPosition" in current context.
  (gdb) print PPosition
  No symbol "PPosition" in current context.
  (gdb) s
  808     }
  (gdb) c
  Continuing.
  Detaching after vfork from child process 16971.
  Detaching after vfork from child process 16973.
  Detaching after vfork from child process 16974.
  Detaching after vfork from child process 16975.
  Detaching after vfork from child process 16976.
  Detaching after vfork from child process 16978.
  Detaching after vfork from child process 16979.
  Detaching after vfork from child process 16980.
  Detaching after vfork from child process 16981.
  Detaching after vfork from child process 16982.
  Detaching after vfork from child process 16983.
  Detaching after vfork from child process 16984.

(Note: I don't understand why the variables USPosition' and
`PPosition' (or are they preprocessor macros?) are reported to be
undefined. I don't understand how the bit mask in the conditional
could execute if this were true.)