<type?> does type check for extension types
authorRobert Bradshaw <robertwb@math.washington.edu>
Sat, 2 Feb 2008 09:18:43 +0000 (01:18 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sat, 2 Feb 2008 09:18:43 +0000 (01:18 -0800)
Cython/Compiler/ExprNodes.py
Cython/Compiler/Parsing.py

index 09f088c766a461b20e68184ebdd8941e0f5ad01d..d8d5768cfaa4661375a4ce0fc5129472ea491a9e 100644 (file)
@@ -2617,6 +2617,9 @@ class TypecastNode(ExprNode):
                 self.operand = self.operand.coerce_to(self.type, env)
             else:
                 warning(self.pos, "No conversion from %s to %s, python object pointer used." % (self.type, self.operand.type))
+        elif from_py and to_py:
+            if self.typecheck and self.type.is_extension_type:
+                self.operand = PyTypeTestNode(self.operand, self.type, env)
     
     def check_const(self):
         self.operand.check_const()
index 14af9c99025da57144404974bb7ac218a5b711d9..52729e1a2aa5a230f81c1b46a8f54391cf20c7de 100644 (file)
@@ -207,12 +207,18 @@ def p_typecast(s):
     s.next()
     base_type = p_c_base_type(s)
     declarator = p_c_declarator(s, empty = 1)
+    if s.sy == '?':
+        s.next()
+        typecheck = 1
+    else:
+        typecheck = 0
     s.expect(">")
     operand = p_factor(s)
     return ExprNodes.TypecastNode(pos, 
         base_type = base_type, 
         declarator = declarator,
-        operand = operand)
+        operand = operand,
+        typecheck = typecheck)
 
 def p_sizeof(s):
     # s.sy == ident "sizeof"