Patchwork =?UTF-8?Q?ObjC++:=20fix=20for=20=5F=5FPRETTY=5FFUNCTION=5F=5F=20on=20Dar?= =?UTF-8?Q?win?=

login
register
mail settings
Submitter Nicola Pero
Date Nov. 28, 2010, 5:45 p.m.
Message ID <1290966316.900327126@192.168.2.229>
Download mbox | patch
Permalink /patch/73345/
State New
Headers show

Comments

Nicola Pero - Nov. 28, 2010, 5:45 p.m.
This patch fixes the testcase demangle-2.mm on Mac OS X (problem reported by Iain, fix by me).

Ok to commit ?

Thanks
Mike Stump - Nov. 28, 2010, 11:12 p.m.
On Nov 28, 2010, at 9:45 AM, "Nicola Pero" <nicola.pero@meta-innovation.com> wrote:
> This patch fixes the testcase demangle-2.mm on Mac OS X (problem reported by Iain, fix by me).
> 
> Ok to commit ?

Ok.
>

Patch

Index: objc-act.c
===================================================================
--- objc-act.c	(revision 167220)
+++ objc-act.c	(working copy)
@@ -12399,6 +12399,22 @@ 
 {
   char *demangled, *cp;
 
+  /* First of all, if the name is too short it can't be an Objective-C
+     mangled method name.  */
+  if (mangled[0] == '\0' || mangled[1] == '\0' || mangled[2] == '\0')
+    return NULL;
+     
+  /* If the name looks like an already demangled one, return it
+     unchanged.  This should only happen on Darwin, where method names
+     are mangled differently into a pretty-print form (such as
+     '+[NSObject class]', see darwin.h).  In that case, demangling is
+     a no-op, but we need to return the demangled name if it was an
+     ObjC one, and return NULL if not.  We should be safe as no C/C++
+     function can start with "-[" or "+[".  */
+  if ((mangled[0] == '-' || mangled[0] == '+')
+      && (mangled[1] == '['))
+    return mangled;
+  
   if (mangled[0] == '_' &&
       (mangled[1] == 'i' || mangled[1] == 'c') &&
       mangled[2] == '_')
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 167220)
+++ ChangeLog	(working copy)
@@ -1,3 +1,9 @@ 
+2010-11-28  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+	* objc-act.c (objc_demangle): Return immediately if the string is
+	too short.  Detect names that do not need demangling, and return
+	them unchanged.
+
 2010-11-27  Nicola Pero  <nicola.pero@meta-innovation.com>
 
 	Implemented optional properties.