Subject: Re: bug#36019: 27.0.50; Segfault in color_distance in emacs --batch

From: Vitalie Spinu <[email-masked]>
Date: Sat, 01 Jun 2019 08:22:23 +0200

Hi Alex,

You are right on spot. 

Before the crash:
   
   Initial: 1, hook: (nil)

Your fix does help and the following is printed:

  Initial: 1, hook: 0x561a49f72240Initial: 1, hook: 0x561a49f72240Initial: 1,
  hook: 0x561a49f72240Initial: 1, hook: 0x561a49f72240Initial: 1, hook:
  0x561a49f72240Initial: 1, hook: 0x561a49f72240Initial: 1, hook:
  0x561a49f72240Initial: 1, hook: 0x561a49f72240Initial: 1, hook:
  0x561a49f72240Initial: 1, hook: 0x561a49f72240

Thanks for the quick resolution. 

  Vitalie

>> On Fri, May 31 2019 14:30, Alex Gramiak wrote:

> Vitalie Spinu <[email-masked]> writes:

>> I have bisected it to:
>>
>> yes: 5d8b0fadee * | Add terminal hook query_frame_background_color
>> err: 41e20ee4bc * | Add terminal hook defined_color_hook
>> err: a411517faf * | Rename generic x_* identifiers
>> err: da9541dd10 * | Add prefixes to some window system-dependent procedures
>>  no: ff4e31fa32 * |  Rename generic x_* procedures in xdisp.c
>>
>> The commits marked with err: don't build. So should be one of the top 4 commits.
>>
>>
>>   Vitalie
>>
>>>> On Fri, May 31 2019 10:30, Vitalie Spinu wrote:
>>
>>> Hi,
>>
>>> One of my packages started segfaulting in tests after emacs 27 update. I cannot
>>> reproduce it in an X session, nor make a simple reproducible example. Hopefully
>>> the backtraces will be enough.
>>
>>> The issue appeared in the last 4-5 months. I can bisect if needed.

> I can't reproduce this, but looking at the likely culprit (41e20ee4bc)
> it's likely due to the frame being the initial frame. Just to make sure,
> could you test with this simple primitive check for this?

> diff --git a/src/xfaces.c b/src/xfaces.c
> index d211ec8c46..10cfa50526 100644
> --- a/src/xfaces.c
> +++ b/src/xfaces.c
> @@ -4207,6 +4207,11 @@ two lists of the form (RED GREEN BLUE) aforementioned. */)
>    struct frame *f = decode_live_frame (frame);
>    Emacs_Color cdef1, cdef2;

> +  fprintf (stderr,
> +           "Initial: %d, hook: %p",
> +           FRAME_INITIAL_P (f),
> +           FRAME_TERMINAL (f)->defined_color_hook);
> +
>    if (!(CONSP (color1) && parse_rgb_list (color1, &cdef1))
>        && !(STRINGP (color1)
>             && FRAME_TERMINAL (f)->defined_color_hook (f,

> I expect that it will print "Initial: 1, hook: 0x0" before segfaulting.

> If this is the case, then perhaps the initial frame should also have
> this hook defined, though this would be the first such hook defined for
> the initial frame type.

> If this is correct, then the following diff should fix this:

> diff --git a/src/terminal.c b/src/terminal.c
> index 0ee0121e35..ed2cfead7a 100644
> --- a/src/terminal.c
> +++ b/src/terminal.c
> @@ -624,6 +624,7 @@ init_initial_terminal (void)
>    initial_terminal->kboard = initial_kboard;
>    initial_terminal->delete_terminal_hook = &delete_initial_terminal;
>    initial_terminal->delete_frame_hook = &initial_free_frame_resources;
> +  initial_terminal->defined_color_hook = &tty_defined_color; /* xfaces.c */
>    /* Other hooks are NULL by default.  */

>    return initial_terminal;