Commit 778f29a7 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

refnanny: Added missing casts.

parent 77a40c90
...@@ -729,8 +729,8 @@ class CCodeWriter(object): ...@@ -729,8 +729,8 @@ class CCodeWriter(object):
def entry_as_pyobject(self, entry): def entry_as_pyobject(self, entry):
type = entry.type type = entry.type
if (not entry.is_self_arg and not entry.type.is_complete()) \ if (not entry.is_self_arg and not entry.type.is_complete()
or (entry.type.is_extension_type and entry.type.base_type): or entry.type.is_extension_type):
return "(PyObject *)" + entry.cname return "(PyObject *)" + entry.cname
else: else:
return entry.cname return entry.cname
...@@ -752,7 +752,19 @@ class CCodeWriter(object): ...@@ -752,7 +752,19 @@ class CCodeWriter(object):
def put_decref(self, cname, type): def put_decref(self, cname, type):
self.putln("__Pyx_DECREF(%s);" % self.as_pyobject(cname, type)) self.putln("__Pyx_DECREF(%s);" % self.as_pyobject(cname, type))
def put_var_gotref(self, entry):
if entry.type.is_pyobject:
self.putln("__Pyx_GOTREF(%s);" % self.entry_as_pyobject(entry))
def put_var_giveref(self, entry):
if entry.type.is_pyobject:
self.putln("__Pyx_GIVEREF(%s);" % self.entry_as_pyobject(entry))
def put_var_xgiveref(self, entry):
if entry.type.is_pyobject:
self.putln("__Pyx_XGIVEREF(%s);" % self.entry_as_pyobject(entry))
def put_var_incref(self, entry): def put_var_incref(self, entry):
if entry.type.is_pyobject: if entry.type.is_pyobject:
self.putln("__Pyx_INCREF(%s);" % self.entry_as_pyobject(entry)) self.putln("__Pyx_INCREF(%s);" % self.entry_as_pyobject(entry))
......
...@@ -1017,7 +1017,7 @@ class LongNode(AtomicNewTempExprNode): ...@@ -1017,7 +1017,7 @@ class LongNode(AtomicNewTempExprNode):
self.result(), self.result(),
self.value, self.value,
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
class ImagNode(AtomicNewTempExprNode): class ImagNode(AtomicNewTempExprNode):
...@@ -1044,7 +1044,7 @@ class ImagNode(AtomicNewTempExprNode): ...@@ -1044,7 +1044,7 @@ class ImagNode(AtomicNewTempExprNode):
self.result(), self.result(),
self.value, self.value,
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
...@@ -1266,7 +1266,7 @@ class NameNode(AtomicExprNode): ...@@ -1266,7 +1266,7 @@ class NameNode(AtomicExprNode):
namespace, namespace,
self.interned_cname, self.interned_cname,
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
elif entry.is_local and False: elif entry.is_local and False:
# control flow not good enough yet # control flow not good enough yet
...@@ -1413,7 +1413,7 @@ class BackquoteNode(ExprNode): ...@@ -1413,7 +1413,7 @@ class BackquoteNode(ExprNode):
self.result(), self.result(),
self.arg.py_result(), self.arg.py_result(),
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
...@@ -1451,7 +1451,7 @@ class ImportNode(ExprNode): ...@@ -1451,7 +1451,7 @@ class ImportNode(ExprNode):
self.module_name.py_result(), self.module_name.py_result(),
name_list_code, name_list_code,
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
class IteratorNode(NewTempExprNode): class IteratorNode(NewTempExprNode):
...@@ -1510,7 +1510,7 @@ class IteratorNode(NewTempExprNode): ...@@ -1510,7 +1510,7 @@ class IteratorNode(NewTempExprNode):
self.result(), self.result(),
self.sequence.py_result(), self.sequence.py_result(),
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
code.putln("}") code.putln("}")
...@@ -1569,7 +1569,7 @@ class NextNode(AtomicNewTempExprNode): ...@@ -1569,7 +1569,7 @@ class NextNode(AtomicNewTempExprNode):
code.putln(code.error_goto_if_PyErr(self.pos)) code.putln(code.error_goto_if_PyErr(self.pos))
code.putln("break;") code.putln("break;")
code.putln("}") code.putln("}")
code.put_gotref(self.result()) code.put_gotref(self.py_result())
code.putln("}") code.putln("}")
...@@ -1831,7 +1831,7 @@ class IndexNode(ExprNode): ...@@ -1831,7 +1831,7 @@ class IndexNode(ExprNode):
self.index_unsigned_parameter(), self.index_unsigned_parameter(),
self.result(), self.result(),
code.error_goto(self.pos))) code.error_goto(self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
def generate_setitem_code(self, value_code, code): def generate_setitem_code(self, value_code, code):
if self.index.type.is_int: if self.index.type.is_int:
...@@ -2007,7 +2007,7 @@ class SliceIndexNode(ExprNode): ...@@ -2007,7 +2007,7 @@ class SliceIndexNode(ExprNode):
self.start_code(), self.start_code(),
self.stop_code(), self.stop_code(),
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
def generate_assignment_code(self, rhs, code): def generate_assignment_code(self, rhs, code):
self.generate_subexpr_evaluation_code(code) self.generate_subexpr_evaluation_code(code)
...@@ -2172,7 +2172,7 @@ class SliceNode(ExprNode): ...@@ -2172,7 +2172,7 @@ class SliceNode(ExprNode):
self.stop.py_result(), self.stop.py_result(),
self.step.py_result(), self.step.py_result(),
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
class CallNode(NewTempExprNode): class CallNode(NewTempExprNode):
...@@ -2393,7 +2393,7 @@ class SimpleCallNode(CallNode): ...@@ -2393,7 +2393,7 @@ class SimpleCallNode(CallNode):
self.function.py_result(), self.function.py_result(),
arg_code, arg_code,
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
elif func_type.is_cfunction: elif func_type.is_cfunction:
if self.has_optional_args: if self.has_optional_args:
actual_nargs = len(self.args) actual_nargs = len(self.args)
...@@ -2449,7 +2449,7 @@ class SimpleCallNode(CallNode): ...@@ -2449,7 +2449,7 @@ class SimpleCallNode(CallNode):
goto_error = "" goto_error = ""
code.putln("%s%s; %s" % (lhs, rhs, goto_error)) code.putln("%s%s; %s" % (lhs, rhs, goto_error))
if self.type.is_pyobject and self.result(): if self.type.is_pyobject and self.result():
code.put_gotref(self.result()) code.put_gotref(self.py_result())
class GeneralCallNode(CallNode): class GeneralCallNode(CallNode):
...@@ -2526,7 +2526,7 @@ class GeneralCallNode(CallNode): ...@@ -2526,7 +2526,7 @@ class GeneralCallNode(CallNode):
self.result(), self.result(),
call_code, call_code,
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
class AsTupleNode(ExprNode): class AsTupleNode(ExprNode):
...@@ -2562,7 +2562,7 @@ class AsTupleNode(ExprNode): ...@@ -2562,7 +2562,7 @@ class AsTupleNode(ExprNode):
self.result(), self.result(),
self.arg.py_result(), self.arg.py_result(),
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
class AttributeNode(ExprNode): class AttributeNode(ExprNode):
...@@ -2832,7 +2832,7 @@ class AttributeNode(ExprNode): ...@@ -2832,7 +2832,7 @@ class AttributeNode(ExprNode):
self.obj.py_result(), self.obj.py_result(),
self.interned_attr_cname, self.interned_attr_cname,
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
else: else:
# result_code contains what is needed, but we may need to insert # result_code contains what is needed, but we may need to insert
# a check and raise an exception # a check and raise an exception
...@@ -3002,7 +3002,7 @@ class SequenceNode(NewTempExprNode): ...@@ -3002,7 +3002,7 @@ class SequenceNode(NewTempExprNode):
self.iterator.result(), self.iterator.result(),
rhs.py_result(), rhs.py_result(),
code.error_goto_if_null(self.iterator.result(), self.pos))) code.error_goto_if_null(self.iterator.result(), self.pos)))
code.put_gotref(self.iterator.result()) code.put_gotref(self.iterator.py_result())
rhs.generate_disposal_code(code) rhs.generate_disposal_code(code)
for i in range(len(self.args)): for i in range(len(self.args)):
item = self.unpacked_items[i] item = self.unpacked_items[i]
...@@ -3013,7 +3013,7 @@ class SequenceNode(NewTempExprNode): ...@@ -3013,7 +3013,7 @@ class SequenceNode(NewTempExprNode):
item.result(), item.result(),
typecast(item.ctype(), py_object_type, unpack_code), typecast(item.ctype(), py_object_type, unpack_code),
code.error_goto_if_null(item.result(), self.pos))) code.error_goto_if_null(item.result(), self.pos)))
code.put_gotref(item.result()) code.put_gotref(item.py_result())
value_node = self.coerced_unpacked_items[i] value_node = self.coerced_unpacked_items[i]
value_node.generate_evaluation_code(code) value_node.generate_evaluation_code(code)
code.put_error_if_neg(self.pos, code.put_error_if_neg(self.pos,
...@@ -3080,7 +3080,7 @@ class TupleNode(SequenceNode): ...@@ -3080,7 +3080,7 @@ class TupleNode(SequenceNode):
self.result(), self.result(),
len(self.args), len(self.args),
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
for i in range(len(self.args)): for i in range(len(self.args)):
arg = self.args[i] arg = self.args[i]
if not arg.result_in_temp(): if not arg.result_in_temp():
...@@ -3176,7 +3176,7 @@ class ListNode(SequenceNode): ...@@ -3176,7 +3176,7 @@ class ListNode(SequenceNode):
(self.result(), (self.result(),
len(self.args), len(self.args),
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
for i in range(len(self.args)): for i in range(len(self.args)):
arg = self.args[i] arg = self.args[i]
#if not arg.is_temp: #if not arg.is_temp:
...@@ -3425,7 +3425,7 @@ class DictNode(ExprNode): ...@@ -3425,7 +3425,7 @@ class DictNode(ExprNode):
"%s = PyDict_New(); %s" % ( "%s = PyDict_New(); %s" % (
self.result(), self.result(),
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
for item in self.key_value_pairs: for item in self.key_value_pairs:
item.generate_evaluation_code(code) item.generate_evaluation_code(code)
if self.type.is_pyobject: if self.type.is_pyobject:
...@@ -3521,7 +3521,7 @@ class ClassNode(ExprNode): ...@@ -3521,7 +3521,7 @@ class ClassNode(ExprNode):
self.cname, self.cname,
self.module_name, self.module_name,
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
class UnboundMethodNode(ExprNode): class UnboundMethodNode(ExprNode):
...@@ -3549,7 +3549,7 @@ class UnboundMethodNode(ExprNode): ...@@ -3549,7 +3549,7 @@ class UnboundMethodNode(ExprNode):
self.function.py_result(), self.function.py_result(),
self.class_cname, self.class_cname,
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
class PyCFunctionNode(AtomicNewTempExprNode): class PyCFunctionNode(AtomicNewTempExprNode):
# Helper class used in the implementation of Python # Helper class used in the implementation of Python
...@@ -3571,7 +3571,7 @@ class PyCFunctionNode(AtomicNewTempExprNode): ...@@ -3571,7 +3571,7 @@ class PyCFunctionNode(AtomicNewTempExprNode):
self.result(), self.result(),
self.pymethdef_cname, self.pymethdef_cname,
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
#------------------------------------------------------------------- #-------------------------------------------------------------------
# #
...@@ -3650,7 +3650,7 @@ class UnopNode(ExprNode): ...@@ -3650,7 +3650,7 @@ class UnopNode(ExprNode):
function, function,
self.operand.py_result(), self.operand.py_result(),
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
def type_error(self): def type_error(self):
if not self.operand.type.is_error: if not self.operand.type.is_error:
...@@ -4057,7 +4057,7 @@ class BinopNode(NewTempExprNode): ...@@ -4057,7 +4057,7 @@ class BinopNode(NewTempExprNode):
self.operand2.py_result(), self.operand2.py_result(),
extra_args, extra_args,
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
else: else:
if self.is_temp: if self.is_temp:
self.generate_c_operation_code(code) self.generate_c_operation_code(code)
...@@ -4957,7 +4957,7 @@ class CoerceToPyTypeNode(CoercionNode): ...@@ -4957,7 +4957,7 @@ class CoerceToPyTypeNode(CoercionNode):
function, function,
self.arg.result(), self.arg.result(),
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.py_result())
class CoerceFromPyTypeNode(CoercionNode): class CoerceFromPyTypeNode(CoercionNode):
...@@ -4990,7 +4990,7 @@ class CoerceFromPyTypeNode(CoercionNode): ...@@ -4990,7 +4990,7 @@ class CoerceFromPyTypeNode(CoercionNode):
rhs, rhs,
code.error_goto_if(self.type.error_condition(self.result()), self.pos))) code.error_goto_if(self.type.error_condition(self.result()), self.pos)))
if self.type.is_pyobject: if self.type.is_pyobject:
code.put_gotref(self.result()) code.put_gotref(self.py_result())
class CoerceToBooleanNode(CoercionNode): class CoerceToBooleanNode(CoercionNode):
......
...@@ -1143,7 +1143,7 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -1143,7 +1143,7 @@ class FuncDefNode(StatNode, BlockNode):
if err_val is None and default_retval: if err_val is None and default_retval:
err_val = default_retval err_val = default_retval
if self.return_type.is_pyobject: if self.return_type.is_pyobject:
code.put_xgiveref(Naming.retval_cname) code.put_xgiveref(self.return_type.as_pyobject(Naming.retval_cname))
if err_val is None: if err_val is None:
code.putln('__Pyx_FinishRefcountContext();') code.putln('__Pyx_FinishRefcountContext();')
else: else:
...@@ -2287,7 +2287,7 @@ class DefNode(FuncDefNode): ...@@ -2287,7 +2287,7 @@ class DefNode(FuncDefNode):
func, func,
arg.hdr_cname, arg.hdr_cname,
code.error_goto_if_null(arg.entry.cname, arg.pos))) code.error_goto_if_null(arg.entry.cname, arg.pos)))
code.put_gotref(arg.entry.cname) code.put_var_gotref(arg.entry)
else: else:
error(arg.pos, error(arg.pos,
"Cannot convert argument of type '%s' to Python object" "Cannot convert argument of type '%s' to Python object"
...@@ -2367,7 +2367,7 @@ class OverrideCheckNode(StatNode): ...@@ -2367,7 +2367,7 @@ class OverrideCheckNode(StatNode):
else: else:
code.putln("else if (unlikely(Py_TYPE(%s)->tp_dictoffset != 0)) {" % self_arg) code.putln("else if (unlikely(Py_TYPE(%s)->tp_dictoffset != 0)) {" % self_arg)
err = code.error_goto_if_null(self.func_node.result(), self.pos) err = code.error_goto_if_null(self.func_node.result(), self.pos)
code.put_gotref(self.func_node.result()) code.put_gotref(self.func_node.py_result())
# need to get attribute manually--scope would return cdef method # need to get attribute manually--scope would return cdef method
code.putln("%s = PyObject_GetAttr(%s, %s); %s" % (self.func_node.result(), self_arg, self.py_func.interned_attr_cname, err)) code.putln("%s = PyObject_GetAttr(%s, %s); %s" % (self.func_node.result(), self_arg, self.py_func.interned_attr_cname, err))
# It appears that this type is not anywhere exposed in the Python/C API # It appears that this type is not anywhere exposed in the Python/C API
...@@ -3068,7 +3068,7 @@ class InPlaceAssignmentNode(AssignmentNode): ...@@ -3068,7 +3068,7 @@ class InPlaceAssignmentNode(AssignmentNode):
self.rhs.py_result(), self.rhs.py_result(),
extra, extra,
code.error_goto_if_null(self.result_value.py_result(), self.pos))) code.error_goto_if_null(self.result_value.py_result(), self.pos)))
code.put_gotref(self.result_value.result()) code.put_gotref(self.result_value.py_result())
self.result_value.generate_evaluation_code(code) # May be a type check... self.result_value.generate_evaluation_code(code) # May be a type check...
self.rhs.generate_disposal_code(code) self.rhs.generate_disposal_code(code)
self.rhs.free_temps(code) self.rhs.free_temps(code)
...@@ -4580,7 +4580,7 @@ class FromImportStatNode(StatNode): ...@@ -4580,7 +4580,7 @@ class FromImportStatNode(StatNode):
self.module.py_result(), self.module.py_result(),
cname, cname,
code.error_goto_if_null(self.item.result(), self.pos))) code.error_goto_if_null(self.item.result(), self.pos)))
code.put_gotref(self.item.result()) code.put_gotref(self.item.py_result())
target.generate_assignment_code(self.item, code) target.generate_assignment_code(self.item, code)
self.module.generate_disposal_code(code) self.module.generate_disposal_code(code)
self.module.free_temps(code) self.module.free_temps(code)
......
...@@ -20,7 +20,6 @@ class BaseType(object): ...@@ -20,7 +20,6 @@ class BaseType(object):
else: else:
return base_code return base_code
class PyrexType(BaseType): class PyrexType(BaseType):
# #
# Base class for all Pyrex types. # Base class for all Pyrex types.
...@@ -257,6 +256,11 @@ class PyObjectType(PyrexType): ...@@ -257,6 +256,11 @@ class PyObjectType(PyrexType):
else: else:
return "%s *%s" % (public_decl("PyObject", dll_linkage), entity_code) return "%s *%s" % (public_decl("PyObject", dll_linkage), entity_code)
def as_pyobject(self, cname):
if (not self.is_complete()) or self.is_extension_type:
return "(PyObject *)" + cname
else:
return cname
class BuiltinObjectType(PyObjectType): class BuiltinObjectType(PyObjectType):
......
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