Commit 3d5881df authored by gsamain's avatar gsamain

Correct typecast for cypclass casts: make it temporary (properly handles refcount)

parent 45fc7d21
...@@ -10536,6 +10536,8 @@ class TypecastNode(ExprNode): ...@@ -10536,6 +10536,8 @@ class TypecastNode(ExprNode):
operator = 'operator ' + self.type.declaration_code('') operator = 'operator ' + self.type.declaration_code('')
entry = self.operand.type.scope.lookup_here(operator) entry = self.operand.type.scope.lookup_here(operator)
self.overloaded = entry is not None self.overloaded = entry is not None
if self.type.is_cyp_class:
self.is_temp = True
if self.type.is_ptr and self.type.base_type.is_cfunction and self.type.base_type.nogil: if self.type.is_ptr and self.type.base_type.is_cfunction and self.type.base_type.nogil:
op_type = self.operand.type op_type = self.operand.type
if op_type.is_ptr: if op_type.is_ptr:
...@@ -10600,11 +10602,21 @@ class TypecastNode(ExprNode): ...@@ -10600,11 +10602,21 @@ class TypecastNode(ExprNode):
def generate_result_code(self, code): def generate_result_code(self, code):
if self.is_temp: if self.is_temp:
if self.type.is_pyobject:
code.putln( code.putln(
"%s = (PyObject *)%s;" % ( "%s = (PyObject *)%s;" % (
self.result(), self.result(),
self.operand.result())) self.operand.result()))
code.put_incref(self.result(), self.ctype()) code.put_incref(self.result(), self.ctype())
elif self.type.is_cyp_class:
star = "*" if self.overloaded else ""
operand_result = "%s%s" % (star, self.operand.result())
code.putln(
"%s = (%s)(%s);" % (
self.result(),
self.type.declaration_code(''),
operand_result))
code.put_cyincref(self.result())
ERR_START = "Start may not be given" ERR_START = "Start may not be given"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment