changeset 58752:4ad0594e1ac4

* macterm.h (cfstring_create_with_utf8_cstring): Added prototype. * image.c (image_load_quartz2d): Use cfstring_create_with_utf8_cstring * macmenu.c (add_menu_item): Use cfstring_create_with_utf8_cstring * macfns.c (x_set_name, x_set_title): Use cfstring_create_with_utf8_cstring (Fx_file_dialog): Use cfstring_create_with_utf8_cstring and use constant CFRefs instead of creating them each time for labels. * mac.c (cfstring_create_with_utf8_cstring): Added to prevent crashes with invalid characters.
author Steven Tamm <steventamm@mac.com>
date Fri, 03 Dec 2004 17:00:11 +0000
parents 0cb8dbb527b9
children b854b191862d
files src/ChangeLog src/image.c src/mac.c src/macfns.c src/macmenu.c src/macterm.h
diffstat 6 files changed, 45 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Dec 03 11:30:11 2004 +0000
+++ b/src/ChangeLog	Fri Dec 03 17:00:11 2004 +0000
@@ -1,3 +1,17 @@
+2004-12-03  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
+
+	* macterm.h (cfstring_create_with_utf8_cstring): Added prototype.
+	* image.c (image_load_quartz2d): Use
+	cfstring_create_with_utf8_cstring
+	* macmenu.c (add_menu_item): Use
+	cfstring_create_with_utf8_cstring
+	* macfns.c (x_set_name, x_set_title): Use
+	cfstring_create_with_utf8_cstring
+	(Fx_file_dialog): Use cfstring_create_with_utf8_cstring and use
+	constant CFRefs instead of creating them each time for labels.
+	* mac.c (cfstring_create_with_utf8_cstring): Added to prevent
+	crashes with invalid characters.
+
 2004-12-02  Richard M. Stallman  <rms@gnu.org>
 
 	* config.in (RE_TRANSLATE_P): If make_number is not a macro,
--- a/src/image.c	Fri Dec 03 11:30:11 2004 +0000
+++ b/src/image.c	Fri Dec 03 17:00:11 2004 +0000
@@ -2416,8 +2416,7 @@
 	  UNGCPRO;
 	  return 0;
 	}
-      path = CFStringCreateWithCString (NULL, SDATA (file),
-					kCFStringEncodingUTF8);
+      path = cfstring_create_with_utf8_cstring (SDATA (file));
       url = CFURLCreateWithFileSystemPath (NULL, path,
 					   kCFURLPOSIXPathStyle, 0);
       CFRelease (path);
--- a/src/mac.c	Fri Dec 03 11:30:11 2004 +0000
+++ b/src/mac.c	Fri Dec 03 17:00:11 2004 +0000
@@ -262,6 +262,22 @@
   return 1;
 }
 
+#if TARGET_API_MAC_CARBON
+CFStringRef
+cfstring_create_with_utf8_cstring (c_str)
+     const char *c_str;
+{
+  CFStringRef str;
+
+  str = CFStringCreateWithCString (NULL, c_str, kCFStringEncodingUTF8);
+  if (str == NULL)
+    /* Failed to interpret as UTF 8.  Fall back on Mac Roman.  */
+    str = CFStringCreateWithCString (NULL, c_str, kCFStringEncodingMacRoman);
+
+  return str;
+}
+#endif
+
 #ifndef MAC_OSX
 
 /* The following functions with "sys_" prefix are stubs to Unix
--- a/src/macfns.c	Fri Dec 03 11:30:11 2004 +0000
+++ b/src/macfns.c	Fri Dec 03 17:00:11 2004 +0000
@@ -1932,8 +1932,7 @@
       {
 #if TARGET_API_MAC_CARBON
 	CFStringRef windowTitle =
-	  CFStringCreateWithCString (NULL, SDATA (name),
-				     kCFStringEncodingUTF8);
+	  cfstring_create_with_utf8_cstring (SDATA (name));
 
 	SetWindowTitleWithCFString (FRAME_MAC_WINDOW (f), windowTitle);
 	CFRelease (windowTitle);
@@ -2015,8 +2014,7 @@
       {
 #if TARGET_API_MAC_CARBON
 	CFStringRef windowTitle =
-	  CFStringCreateWithCString (NULL, SDATA (name),
-				     kCFStringEncodingUTF8);
+	  cfstring_create_with_utf8_cstring (SDATA (name));
 
 	SetWindowTitleWithCFString (FRAME_MAC_WINDOW (f), windowTitle);
 	CFRelease (windowTitle);
@@ -4246,8 +4244,7 @@
     NavDialogRef dialogRef;
     NavTypeListHandle fileTypes = NULL;
     NavUserAction userAction;
-    CFStringRef message=NULL, client=NULL, saveName = NULL, ok = NULL;
-    CFStringRef title = NULL;
+    CFStringRef message=NULL, saveName = NULL;
     
     BLOCK_INPUT;
     /* No need for a callback function because we are modal */
@@ -4259,15 +4256,11 @@
     options.optionFlags |= kNavSelectAllReadableItem;
     if (!NILP(prompt))
       {
-	message = CFStringCreateWithCStringNoCopy(NULL, SDATA(prompt),
-						  kCFStringEncodingUTF8, 
-						  kCFAllocatorNull);
+	message = cfstring_create_with_utf8_cstring (SDATA (prompt));
 	options.message = message;
       }
     /* Don't set the application, let it use default.
-    client = CFStringCreateWithCStringNoCopy(NULL, "Emacs", 
-					     kCFStringEncodingMacRoman, NULL);
-    options.clientName = client;
+    options.clientName = CFSTR ("Emacs");
     */
 
     if (!NILP (only_dir_p))
@@ -4276,17 +4269,14 @@
     else if (NILP (mustmatch)) 
       { 
 	/* This is a save dialog */
-	ok = CFStringCreateWithCString (NULL, "Ok", kCFStringEncodingUTF8);
-	title = CFStringCreateWithCString (NULL, "Enter name",
-	                                   kCFStringEncodingUTF8);
 	options.optionFlags |= kNavDontConfirmReplacement;
-	options.actionButtonLabel = ok;
-	options.windowTitle = title;
+	options.actionButtonLabel = CFSTR ("Ok");
+	options.windowTitle = CFSTR ("Enter name");
 
 	if (!NILP(default_filename))
 	  {
-	    saveName = CFStringCreateWithCString(NULL, SDATA(default_filename),
-						 kCFStringEncodingUTF8);
+	    saveName =
+	      cfstring_create_with_utf8_cstring (SDATA (default_filename));
 	    options.saveFileName = saveName;
 	    options.optionFlags |= kNavSelectDefaultLocation;
 	  }
@@ -4320,10 +4310,7 @@
     }
 
     if (saveName) CFRelease(saveName);
-    if (client) CFRelease(client);
     if (message) CFRelease(message);
-    if (ok) CFRelease(ok);
-    if (title) CFRelease(title);
 
     if (status == noErr) {
       userAction = NavDialogGetUserAction(dialogRef);
--- a/src/macmenu.c	Fri Dec 03 11:30:11 2004 +0000
+++ b/src/macmenu.c	Fri Dec 03 17:00:11 2004 +0000
@@ -2264,17 +2264,8 @@
       item_name[255] = 0;
 #if TARGET_API_MAC_CARBON
       {
-	CFStringRef string =
-	  CFStringCreateWithCString (NULL, item_name, kCFStringEncodingUTF8);
+	CFStringRef string = cfstring_create_with_utf8_cstring (item_name);
 
- 	if (string == NULL)
- 	  {
- 	    /* Failed to interpret as UTF8.  Fall back to Mac Roman.
- 	       Maybe wv->name is corrupted?  */
- 	    string = CFStringCreateWithCString (NULL, item_name,
- 						kCFStringEncodingMacRoman);
- 	  }
-	
 	SetMenuItemTextWithCFString (menu, pos, string);
 	CFRelease (string);
       }
--- a/src/macterm.h	Fri Dec 03 11:30:11 2004 +0000
+++ b/src/macterm.h	Fri Dec 03 17:00:11 2004 +0000
@@ -600,5 +600,9 @@
 #define FONT_TYPE_FOR_UNIBYTE(font, ch) 0
 #define FONT_TYPE_FOR_MULTIBYTE(font, ch) 0
 
+#if TARGET_API_MAC_CARBON
+extern CFStringRef cfstring_create_with_utf8_cstring P_ ((const char *));
+#endif
+
 /* arch-tag: 6b4ca125-5bef-476d-8ee8-31ed808b7e79
    (do not change this comment) */