Commits

Ronald Oussoren committed 569bd90

Some small changes that ensure all bridgesupport files on OSX 10.8 can be parsed

* Testing is not complete

* Remove the regression test from test_splitsig, that wasn't a
regression but a broken encoding in a bridgesupport file
(see also Lib/objc/_bridgesupport.py for a rant)

Comments (0)

Files changed (3)

pyobjc-core/Lib/objc/_bridgesupport.py

                 gettypeid = getattr(dll, funcname)
                 gettypeid.restype = ctypes.c_long
             except AttributeError:
-                objc.registerCFSignature(name, typestr, None, "NSCFType")
+                self.cftypes.append((name, typestr, None, "NSCFType"))
                 return
 
-            self.cftypes.append((name, gettypeid(), typeId))
+            self.cftypes.append((name, gettypeid(), typestr))
 
 
     def do_constant(self, node):
         if not name or not value:
             return
 
-        if '.' in value:
+        if value.lower() in ('+inf', '-inf', 'nan'):
             value = float(value)
 
+        elif '.' in value:
+            if value.endswith('f') or value.endswith('F'):
+                value = value[:-1]
+            if value.endswith('l') or value.endswith('L'):
+                value = value[:-1]
+            if value.startswith('0x') or value.startswith('0X'):
+                try:
+                    value = float.fromhex(value)
+                except:
+                    print value
+                    raise
+
+            else:
+                value = float(value)
+
         else:
             value = int(value, 10)
 
         if not name or not typestr:
             return
 
+        # Apple's bridgesupport files contain nice encoding like this:
+        # {tag="field"a"NSImage"}, that is not only are field names encoded
+        # but also class names. This is obviously completely undocumented,
+        # and not backward compatible (and it is not easily possible to detect
+        # if class names are present.
+        typestr = re.sub(r'@"[^"]*"', '@', typestr)
+
         try:
             typestr = as_bytes(self.typestr2typestr(typestr))
         except:
 
         globals.update(prs.values)
         for entry in prs.cftypes:
-            if len(entry) == 4:
-                tp = objc.registerCFSignature(*entry)
-            else:
-                tp = objc.registerCFSignature(*entry)
+            tp = objc.registerCFSignature(*entry)
 
             globals[entry[0]] = tp
 

pyobjc-core/PyObjCTest/test_bridgesupport.py

         print framework_name
         prs = bridgesupport._BridgeSupportParser(xmldata, framework_name)
 
-        for item in prs.ctypes:
+        for item in prs.cftypes:
             # XXX: validate items
             pass
 
-        for name, typestr, magic in pfs.constants:
+        for name, typestr, magic in prs.constants:
             self.assertIsInstance(name, basestring)
             self.assertIsInstance(typestr, bytes)
             self.assertIsInstance(magic, bool)
 
-            self.assertEqual(len(objc.splitSig(typestr)), 1)
+            self.assertEqual(len(objc.splitSignature(typestr)), 1)
 
         for name, orig in prs.func_aliases:
             self.assertIsInstance(name, basestring)
             self.assertIsInstance(name, basestring)
             self.assertIsInstance(typestr, bytes)
 
-            self.assertEqual(len(objc.splitSig(typestr)), 1)
+            self.assertEqual(len(objc.splitSignature(typestr)), 1)
 
         for name, typestr in prs.structs:
             self.assertIsInstance(name, basestring)
             self.assertIsInstance(typestr, bytes)
 
-            self.assertEqual(len(objc.splitSig(typestr)), 1)
+            self.assertEqual(len(objc.splitSignature(typestr)), 1)
 
         # XXX: Is there anything to do w.r.t. validating prs.values? 
         prs.values

pyobjc-core/PyObjCTest/test_splitsig.py

         self.assertEqual(objc.splitStructSignature(b'{NSPoint=dd}'), ("NSPoint", [(None, b'd'), (None, b'd')]))
         self.assertEqual(objc.splitStructSignature(b'{NSPoint="x"d"y"d}'), ("NSPoint", [("x", b'd'), ("y", b'd')]))
 
-    def testRegressions(self):
-        sig = b'{HIViewContentInfo="contentType"s"u"(?="iconRef"^{OpaqueIconRef}"iconTypeAndCreator"{HITypeAndCreator="type"I"creator"I}"imageRef"^{CGImage}"imageResource"^{__CFString}"imageFile"^{__CFURL}"nsImage"@"NSImage")}'
-        self.assertEqual(objc.splitSignature(sig), [sig])
-
-
 
 if __name__ == "__main__":
     main()