More safe types to infer.
authorRobert Bradshaw <robertwb@math.washington.edu>
Wed, 10 Feb 2010 23:31:55 +0000 (15:31 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Wed, 10 Feb 2010 23:31:55 +0000 (15:31 -0800)
Cython/Compiler/ExprNodes.py
Cython/Compiler/TypeInference.py

index 1c04e93e7c8b9c49e867abec58e66b3065791a6e..b7023ab8b1141d8c14890c08d65193208b9e86c2 100755 (executable)
@@ -2492,6 +2492,8 @@ class SimpleCallNode(CallNode):
     def infer_type(self, env):
         function = self.function
         func_type = function.infer_type(env)
+        if isinstance(self.function, NewExprNode):
+            return PyrexTypes.CPtrType(self.function.class_type)
         if func_type.is_ptr:
             func_type = func_type.base_type
         if func_type.is_cfunction:
index d7089d5773785864e093c37adb8f0cb4e254fe10..72d389c82141d160b0b2d08bc1532b8f611f996b 100644 (file)
@@ -235,6 +235,20 @@ def safe_spanning_type(types):
         # find_spanning_type() only returns 'bint' for clean boolean
         # operations without other int types, so this is safe, too
         return result_type
+    elif result_type.is_ptr and not (result_type.is_int and result_type.rank == 0):
+        # Any pointer except (signed|unsigned|) char* can't implicitly 
+        # become a PyObject.
+        return result_type
+    elif result_type.is_cpp_class:
+        # These can't implicitly become Python objects either.
+        return result_type
+    elif result_type.is_struct:
+        # Though we have struct -> object for some structs, this is uncommonly
+        # used, won't arise in pure Python, and there shouldn't be side
+        # effects, so I'm declaring this safe.
+        return result_type
+    # TODO: double complex should be OK as well, but we need 
+    # to make sure everything is supported.
     return py_object_type