all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Third <alan@idiocy.org>
To: Jimmy Yuen Ho Wong <wyuenho@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: NS port crashes when interacting with the profiler on the menu bar
Date: Wed, 13 Jun 2018 20:57:49 +0100	[thread overview]
Message-ID: <20180613195749.GA31667@breton.holly.idiocy.org> (raw)
In-Reply-To: <124c265f-9c41-6041-8a7f-ba2e3fcabd07@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1677 bytes --]

On Tue, Jun 12, 2018 at 09:02:35PM +0100, Jimmy Yuen Ho Wong wrote:
> >> Case 2 repro:
> >>
> >> Put this into your init file:
> >>
> >> (set-fontset-font "fontset-default" 'unicode "Apple Color Emoji" nil
> >> 'append)
> >>
> >> Crashes on start up.
> > Again I can’t reproduce it. Do you have anything else in your init.el
> > that might try to display an emoji or similar? In fact, you’ve got the
> > colour emoji patch applied, right? I wonder if that changes
> > something...
> Yes I have MacPort's multifonts_color patch applied.

It doesn’t make any difference here. It’s odd. Can you reproduce the
crash using -Q?

Do you have symbola installed?

> >> Case 3 repro:
> >>
> >> 1. Goto System Preferences > Keyword and turn on Show keyboard and emoji
> >> viewers in menu bar.
> >> 2. Go to emacs NS port, turn on Show Emoji & Symbols to get the emoji
> >> viewer out, insert some Emoji
> >> 3. Internal Error dialog pops up, Emacs caught the crash this time.
> > This isn’t a crash, right? I’m pretty sure this is fixed in master,
> > specifically commit 703ac3ea1c1ce381f385469a0e88bc29d3fe83c2. I think
> > this should be easily back ported to Emacs 26 if it’s causing crashes.
> This is a crash, but not a fatal crash, it's the Emacs NS port or Cocoa
> caught it and popped up an Internal Error dialog. For the dialog I can
> choose to let it crash the entire process or continue and ignore it.

Two patches attached which I believe fix this in emacs-26. I think
they’re safe. The second patch is part of commit
1daac66a6eedbcbfa32ab920b5c579872d989517 on master, but it adds a new
feature, so probably shouldn’t be applied in full.

-- 
Alan Third

[-- Attachment #2: 0001-Allow-inserting-non-BMP-characters.patch --]
[-- Type: text/plain, Size: 4100 bytes --]

From 023fc1a8b3902caf7221805db8ac262fbcbe3ba0 Mon Sep 17 00:00:00 2001
From: Philipp Stephani <phst@google.com>
Date: Mon, 25 Dec 2017 22:00:00 +0100
Subject: [PATCH] Allow inserting non-BMP characters

* src/coding.h (UTF_16_HIGH_SURROGATE_P, UTF_16_LOW_SURROGATE_P): Move
from coding.c and document.
(surrogates_to_codepoint): New function.

* src/nsterm.m (insertText:): Properly handle surrogate pairs.

(cherry picked from commit 703ac3ea1c1ce381f385469a0e88bc29d3fe83c2)
---
 src/coding.c |  7 -------
 src/coding.h | 24 ++++++++++++++++++++++++
 src/nsterm.m | 25 +++++++++++++++++++------
 3 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/src/coding.c b/src/coding.c
index e756ba169d..121614fad1 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -1515,13 +1515,6 @@ encode_coding_utf_8 (struct coding_system *coding)
 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
    Return true if a text is encoded in one of UTF-16 based coding systems.  */
 
-#define UTF_16_HIGH_SURROGATE_P(val) \
-  (((val) & 0xFC00) == 0xD800)
-
-#define UTF_16_LOW_SURROGATE_P(val) \
-  (((val) & 0xFC00) == 0xDC00)
-
-
 static bool
 detect_coding_utf_16 (struct coding_system *coding,
 		      struct coding_detection_info *detect_info)
diff --git a/src/coding.h b/src/coding.h
index 2a87fc32e9..502c472314 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -662,6 +662,30 @@ struct coding_system
 /* Note that this encodes utf-8, not utf-8-emacs, so it's not a no-op.  */
 #define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, true)
 
+/* Return true if VAL is a high surrogate.  VAL must be a 16-bit code
+   unit.  */
+
+#define UTF_16_HIGH_SURROGATE_P(val) \
+  (((val) & 0xFC00) == 0xD800)
+
+/* Return true if VAL is a low surrogate.  VAL must be a 16-bit code
+   unit.  */
+
+#define UTF_16_LOW_SURROGATE_P(val) \
+  (((val) & 0xFC00) == 0xDC00)
+
+/* Return the Unicode code point for the given UTF-16 surrogates.  */
+
+INLINE int
+surrogates_to_codepoint (int low, int high)
+{
+  eassert (0 <= low && low <= 0xFFFF);
+  eassert (0 <= high && high <= 0xFFFF);
+  eassert (UTF_16_LOW_SURROGATE_P (low));
+  eassert (UTF_16_HIGH_SURROGATE_P (high));
+  return 0x10000 + (low - 0xDC00) + ((high - 0xD800) * 0x400);
+}
+
 /* Extern declarations.  */
 extern Lisp_Object code_conversion_save (bool, bool);
 extern bool encode_coding_utf_8 (struct coding_system *);
diff --git a/src/nsterm.m b/src/nsterm.m
index e4a9b014f4..d51782e538 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -6317,14 +6317,13 @@ flag set (this is probably a bug in the OS).
          by doCommandBySelector: deleteBackward: */
 - (void)insertText: (id)aString
 {
-  int code;
-  int len = [(NSString *)aString length];
-  int i;
+  NSString *s = aString;
+  NSUInteger len = [s length];
 
   NSTRACE ("[EmacsView insertText:]");
 
   if (NS_KEYLOG)
-    NSLog (@"insertText '%@'\tlen = %d", aString, len);
+    NSLog (@"insertText '%@'\tlen = %lu", aString, (unsigned long) len);
   processingCompose = NO;
 
   if (!emacs_event)
@@ -6334,10 +6333,24 @@ - (void)insertText: (id)aString
   if (workingText != nil)
     [self deleteWorkingText];
 
+  /* It might be preferable to use getCharacters:range: below,
+     cf. https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CocoaPerformance/Articles/StringDrawing.html#//apple_ref/doc/uid/TP40001445-112378.
+     However, we probably can't use SAFE_NALLOCA here because it might
+     exit nonlocally.  */
+
   /* now insert the string as keystrokes */
-  for (i =0; i<len; i++)
+  for (NSUInteger i = 0; i < len; i++)
     {
-      code = [aString characterAtIndex: i];
+      NSUInteger code = [s characterAtIndex:i];
+      if (UTF_16_HIGH_SURROGATE_P (code) && i < len - 1)
+        {
+          unichar low = [s characterAtIndex:i + 1];
+          if (UTF_16_LOW_SURROGATE_P (low))
+            {
+              code = surrogates_to_codepoint (low, code);
+              ++i;
+            }
+        }
       /* TODO: still need this? */
       if (code == 0x2DC)
         code = '~'; /* 0x7E */
-- 
2.17.1


[-- Attachment #3: 0001-Handle-NSAttributedString-inputs-bug-29837.patch --]
[-- Type: text/plain, Size: 1064 bytes --]

From f3e78727d77c50594fc9f4b03b8640825af49016 Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Sun, 24 Dec 2017 15:40:03 +0000
Subject: [PATCH] Handle NSAttributedString inputs (bug#29837)

; Do not merge to master.

* src/nsterm.m (EmacsView::insertText): Handle NSAttributedString.
---
 src/nsterm.m | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index d51782e538..c8b4a87990 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -6317,11 +6317,18 @@ flag set (this is probably a bug in the OS).
          by doCommandBySelector: deleteBackward: */
 - (void)insertText: (id)aString
 {
-  NSString *s = aString;
-  NSUInteger len = [s length];
+  NSString *s;
+  NSUInteger len;
 
   NSTRACE ("[EmacsView insertText:]");
 
+  if ([aString isKindOfClass:[NSAttributedString class]])
+    s = [aString string];
+  else
+    s = aString;
+
+  len = [s length];
+
   if (NS_KEYLOG)
     NSLog (@"insertText '%@'\tlen = %lu", aString, (unsigned long) len);
   processingCompose = NO;
-- 
2.17.1


  reply	other threads:[~2018-06-13 19:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAKDRQS7Dz=CPF+2vbim2T1x-CePJZvETCUcS31kgKVLSOY9pcQ@mail.gmail.com>
2018-06-12 19:39 ` NS port crashes when interacting with the profiler on the menu bar Alan Third
2018-06-12 20:02   ` Jimmy Yuen Ho Wong
2018-06-13 19:57     ` Alan Third [this message]
2018-06-15  0:51       ` Jimmy Yuen Ho Wong
2018-06-16 11:45         ` Alan Third
2018-06-17 15:54           ` Jimmy Yuen Ho Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180613195749.GA31667@breton.holly.idiocy.org \
    --to=alan@idiocy.org \
    --cc=emacs-devel@gnu.org \
    --cc=wyuenho@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.