Commit c1609002 authored by Robert Bradshaw's avatar Robert Bradshaw

incref_local_binop option for SAGE

This is so mutating inplace operations can be detected safely.
parent 36549f78
......@@ -22,6 +22,8 @@ Options:
-z, --pre-import <module> If specified, assume undeclared names in this
module. Emulates the behavior of putting
"from <module> import *" at the top of the file.
--incref_local_binop Force local an extra incref on local variables before
performing any binary operations.
"""
#The following experimental options are supported only on MacOSX:
# -C, --compile Compile generated .c file to .o file
......@@ -76,6 +78,8 @@ def parse_command_line(args):
Options.embed_pos_in_docstring = 1
elif option in ("-z", "--pre-import"):
Options.pre_import = pop_arg()
elif option == "--incref_local_binop":
Options.incref_local_binop = 1
else:
bad_usage()
else:
......
......@@ -2430,6 +2430,8 @@ class BinopNode(ExprNode):
self.coerce_operands_to_pyobjects(env)
self.type = py_object_type
self.is_temp = 1
if Options.incref_local_binop and self.operand1.type.is_pyobject:
self.operand1 = self.operand1.coerce_to_temp(env)
else:
self.analyse_c_operation(env)
......
......@@ -1624,6 +1624,8 @@ class InPlaceAssignmentNode(AssignmentNode):
self.dup = self.create_dup_node(env) # re-assigns lhs to a shallow copy
self.rhs.analyse_types(env)
self.lhs.analyse_target_types(env)
if Options.incref_local_binop and self.dup.type.is_pyobject:
self.dup = self.dup.coerce_to_temp(env)
def allocate_rhs_temps(self, env):
import ExprNodes
......
......@@ -9,3 +9,10 @@ embed_pos_in_docstring = 0
gcc_branch_hints = 1
pre_import = None
# This is a SAGE-specific option that will
# cause Cython to incref local variables before
# performing a binary operation on them, for
# safe detection of inplace operators.
incref_local_binop = 0
......@@ -40,6 +40,7 @@ class Entry:
# getter_cname string C func for getting property
# setter_cname string C func for setting or deleting property
# is_self_arg boolean Is the "self" arg of an exttype method
# is_arg boolean Is the arg of a method
# is_readonly boolean Can't be assigned to
# func_cname string C func implementing Python func
# pos position Source position where declared
......@@ -81,6 +82,7 @@ class Entry:
getter_cname = None
setter_cname = None
is_self_arg = 0
is_arg = 0
is_declared_generic = 0
is_readonly = 0
func_cname = None
......@@ -910,6 +912,7 @@ class LocalScope(Scope):
entry.is_variable = 1
if type.is_pyobject:
entry.init = "0"
entry.is_arg = 1
#entry.borrowed = 1 # Not using borrowed arg refs for now
self.arg_entries.append(entry)
return entry
......
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