Commit 12d628d7 authored by Mark Florisson's avatar Mark Florisson

Bludgeon warning & fix argument unpacking closure leak

parent 3c13f13d
...@@ -2618,12 +2618,12 @@ class DefNode(FuncDefNode): ...@@ -2618,12 +2618,12 @@ class DefNode(FuncDefNode):
if arg.type.is_pyobject and arg.entry.in_closure: if arg.type.is_pyobject and arg.entry.in_closure:
code.put_var_giveref(arg.entry) code.put_var_giveref(arg.entry)
def generate_arg_assignment(self, arg, item, code): def generate_arg_assignment(self, arg, item, code, incref_closure=True):
if arg.type.is_pyobject: if arg.type.is_pyobject:
if arg.is_generic: if arg.is_generic:
item = PyrexTypes.typecast(arg.type, PyrexTypes.py_object_type, item) item = PyrexTypes.typecast(arg.type, PyrexTypes.py_object_type, item)
entry = arg.entry entry = arg.entry
if entry.in_closure: if incref_closure and entry.in_closure:
code.put_incref(item, PyrexTypes.py_object_type) code.put_incref(item, PyrexTypes.py_object_type)
code.putln("%s = %s;" % (entry.cname, item)) code.putln("%s = %s;" % (entry.cname, item))
else: else:
...@@ -3035,7 +3035,7 @@ class DefNode(FuncDefNode): ...@@ -3035,7 +3035,7 @@ class DefNode(FuncDefNode):
for i, arg in enumerate(all_args): for i, arg in enumerate(all_args):
if arg.default and not arg.type.is_pyobject: if arg.default and not arg.type.is_pyobject:
code.putln("if (values[%d]) {" % i) code.putln("if (values[%d]) {" % i)
self.generate_arg_assignment(arg, "values[%d]" % i, code) self.generate_arg_assignment(arg, "values[%d]" % i, code, incref_closure=False)
if arg.default and not arg.type.is_pyobject: if arg.default and not arg.type.is_pyobject:
code.putln('} else {') code.putln('} else {')
code.putln( code.putln(
......
...@@ -561,18 +561,29 @@ cdef memoryview memview_slice(memoryview memview, object indices): ...@@ -561,18 +561,29 @@ cdef memoryview memview_slice(memoryview memview, object indices):
dst.memview = p_src.memview dst.memview = p_src.memview
dst.data = p_src.data dst.data = p_src.data
# Put everything in temps to avoid this bloody warning:
# "Argument evaluation order in C function call is undefined and
# may not be as expected"
cdef {{memviewslice_name}} *p_dst = &dst
cdef int *p_suboffset_dim = &suboffset_dim
cdef Py_ssize_t start, stop, step
cdef bint have_start, have_stop, have_step
for dim, index in enumerate(indices): for dim, index in enumerate(indices):
if PyIndex_Check(index): if PyIndex_Check(index):
slice_memviewslice(p_src, &dst, True, dim, new_ndim, &suboffset_dim, slice_memviewslice(p_src, p_dst, True, dim, new_ndim, p_suboffset_dim,
index, 0, 0, 0, 0, 0, False) index, 0, 0, 0, 0, 0, False)
else: else:
slice_memviewslice(p_src, &dst, True, dim, new_ndim, &suboffset_dim, start = index.start or 0
index.start or 0, stop = index.stop or 0
index.stop or 0, step = index.step or 0
index.step or 0,
index.start is not None, have_start = index.start is not None
index.stop is not None, have_stop = index.stop is not None
index.step is not None, have_step = index.step is not None
slice_memviewslice(p_src, p_dst, True, dim, new_ndim, p_suboffset_dim,
start, stop, step, have_start, have_stop, have_step,
True) True)
new_ndim += 1 new_ndim += 1
......
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