all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: Printing to STDERR when %d is "Cannot access memory ..."
@ 2018-06-13 19:34 Keith David Bershatsky
  2018-06-13 19:46 ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Keith David Bershatsky @ 2018-06-13 19:34 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Thank you, Eli, for taking a look at this thread.  The suggestion by Davis to deal with the STDERR message avoids the crash.

My STDERR printout (with the NULL font now being assigned a 0 value) is as follows:

    it->c (120021)
    char (ð)
    w->hscroll (0)
    hscl (false)
    it->hpos (5)
    it->vpos (0)
    it->current_x (55)
    new_x (55)
    font->space_width (0)
    it->lnum_pixel_width (55)
    it->lnum_width (3)
    it->first_visible_x (0)
    relative_x (55)
    it->face_id (38)
    foreground_face (magenta)
    background_face (black)
    rc (MOVE_X_REACHED)

I create the font pointer like this ....  It has worked for everything so far except this special character (U0001D4D5) on Emacs built --with-x.  I believe the face_id is correct in this example because the foreground (magenta) and background (black) are correctly returned.

  struct face *face = mc_lookup_face (it);
  struct font *font = face->font;
  Lisp_Object foreground_face = face->lface[LFACE_FOREGROUND_INDEX];
  Lisp_Object background_face = face->lface[LFACE_BACKGROUND_INDEX];

... using the following function:

struct face *
mc_lookup_face (struct it *it)
{
  if (!NILP (Vface_remapping_alist)
      && (it->face_id == DEFAULT_FACE_ID /* Qdefault */
          || it->face_id == MODE_LINE_FACE_ID /* Qmode_line */
          || it->face_id == MODE_LINE_INACTIVE_FACE_ID /* Qmode_line_inactive */
          || it->face_id == HEADER_LINE_FACE_ID /* Qheader_line */
          || it->face_id == TOOL_BAR_FACE_ID /* Qtool_bar */
          || it->face_id == FRINGE_FACE_ID /* Qfringe */
          || it->face_id == SCROLL_BAR_FACE_ID /* Qscroll_bar */
          || it->face_id == BORDER_FACE_ID /* Qborder */
          || it->face_id == CURSOR_FACE_ID /* Qcursor */
          || it->face_id == MOUSE_FACE_ID /* Qmouse */
          || it->face_id == MENU_FACE_ID /* Qmenu */
          || it->face_id == WINDOW_DIVIDER_FACE_ID /* Qwindow_divider */
          || it->face_id == WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID /* Qwindow_divider_first_pixel */
          || it->face_id == WINDOW_DIVIDER_LAST_PIXEL_FACE_ID /* Qwindow_divider_last_pixel */
          || it->face_id == VERTICAL_BORDER_FACE_ID /* Qvertical_border */
          || it->face_id == INTERNAL_BORDER_FACE_ID)) /* Qinternal_border */
    return FACE_FROM_ID (it->f, lookup_basic_face (it->f, it->face_id));
      else
        return FACE_FROM_ID (it->f, it->face_id);
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATE:  [06-13-2018 12:11:33] <13 Jun 2018 22:11:33 +0300>
FROM:  Eli Zaretskii <eliz@gnu.org>
> 
> > Date: Wed, 13 Jun 2018 11:37:09 -0700
> > From: Keith David Bershatsky <esq@lawlist.com>
> >
> > I am working on crosshairs (17684) and multiple fake cursors (22873) and created a little problem for myself in that a character not recognized by the font (U0001D4D5) [aka a pretty letter f] on a line all by itself does not have a font->space_width and causes Emacs to crash when printing said value to STDERR.
> >
> > GDB returns "Cannot access memory at address 0xa0" when printing the value of font->space_width.
> 
> This message means that 'font' is a NULL pointer, and that is your
> basic problem.  You need to find out why 'font' is NULL.



^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: Printing to STDERR when %d is "Cannot access memory ..."
@ 2018-06-13 21:37 Keith David Bershatsky
  0 siblings, 0 replies; 7+ messages in thread
From: Keith David Bershatsky @ 2018-06-13 21:37 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Thank you, Eli.  It is a good thing that I asked about this issue because a few of my calculations require a non-NULL value.  I will be using FRAME_COLUMN_WIDTH (f) as the fallback method when font is NULL, which will probably suffice for this particular project.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATE:  [06-13-2018 12:46:54] <13 Jun 2018 22:46:54 +0300>
FROM:  Eli Zaretskii <eliz@gnu.org>
> 
> * * *
> 
> I don't think face->font is guaranteed to be non-NULL.  You need to
> check that explicitly, and you need some fallback for when it is NULL,
> to serve as a substitute for font->space_width.



^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: Printing to STDERR when %d is "Cannot access memory ..."
@ 2018-06-13 19:34 Keith David Bershatsky
  0 siblings, 0 replies; 7+ messages in thread
From: Keith David Bershatsky @ 2018-06-13 19:34 UTC (permalink / raw)
  To: Davis Herring; +Cc: Eli Zaretskii, emacs-devel

Thank you, Davis, for teaching me how to deal with a NULL pointer when printing to STDERR.  Your code works well.  Greatly appreciated!

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATE:  [06-13-2018 11:50:13] <13 Jun 2018 12:50:13 -0600>
FROM:  Davis Herring <herring@lanl.gov>
> 
> > fprintf (stderr, "(%d)", (font->space_width == NULL
> >                            ? 0
> >                            : font->space_width);
> >
> > However, that didn't fix the problem.
> 
> You meant
> 
>    fprintf (stderr, "(%d)", font == NULL ? 0 :
>                             font->space_width);
> 
> It's font that could be null, not its space_width.
> 
> Davis
> 
> PS - This says nothing about why font is null -- it might be a bug, or
> it might just be a bug that this code uses it without checking.
> 
> --
> This product is sold by volume, not by mass.  If it appears too dense or
> too sparse, it is because mass-energy conversion has occurred during
> shipping.



^ permalink raw reply	[flat|nested] 7+ messages in thread
* Printing to STDERR when %d is "Cannot access memory ..."
@ 2018-06-13 18:37 Keith David Bershatsky
  2018-06-13 18:50 ` Davis Herring
  2018-06-13 19:11 ` Eli Zaretskii
  0 siblings, 2 replies; 7+ messages in thread
From: Keith David Bershatsky @ 2018-06-13 18:37 UTC (permalink / raw)
  To: Emacs Devel

I am working on crosshairs (17684) and multiple fake cursors (22873) and created a little problem for myself in that a character not recognized by the font (U0001D4D5) [aka a pretty letter f] on a line all by itself does not have a font->space_width and causes Emacs to crash when printing said value to STDERR.

GDB returns "Cannot access memory at address 0xa0" when printing the value of font->space_width.

This came about by using the following setting for a Form Feed character:

(setq buffer-display-table (make-display-table))
(aset buffer-display-table
      ?\014
      (vector (make-glyph-code ?\U0001D4D5 'font-lock-warning-face)))

I am by passing the problem by not using ?\U0001D4D5.  However, I would like to come up with programmatic solution to avoid crashing Emacs when printing values to STDERR.

I tried:

fprintf (stderr, "(%d)", (font->space_width == NULL
                          ? 0
                          : font->space_width);

However, that didn't fix the problem.

Thanks,

Keith



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

end of thread, other threads:[~2018-06-13 21:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-13 19:34 Printing to STDERR when %d is "Cannot access memory ..." Keith David Bershatsky
2018-06-13 19:46 ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2018-06-13 21:37 Keith David Bershatsky
2018-06-13 19:34 Keith David Bershatsky
2018-06-13 18:37 Keith David Bershatsky
2018-06-13 18:50 ` Davis Herring
2018-06-13 19:11 ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.