Commit 59cfc984 authored by da-woods's avatar da-woods Committed by Stefan Behnel

Fixed default buffer arguments with binding [Fixes `bufaccess`] (GH-3164)

* Fixed default buffer arguments with binding

They were assigned to global scope, but buffers aren't allowed in
global scope. To fix, dropped the buffer type from the default value

* Updated reference counting tests in bufaccess

So they now have the new values for binding=True
parent 8d8795c6
...@@ -9250,7 +9250,10 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin): ...@@ -9250,7 +9250,10 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin):
scope = Symtab.StructOrUnionScope(cname) scope = Symtab.StructOrUnionScope(cname)
self.defaults = [] self.defaults = []
for arg in nonliteral_objects: for arg in nonliteral_objects:
entry = scope.declare_var(arg.name, arg.type, None, type_ = arg.type
if type_.is_buffer:
type_ = type_.base
entry = scope.declare_var(arg.name, type_, None,
Naming.arg_prefix + arg.name, Naming.arg_prefix + arg.name,
allow_pyobject=True) allow_pyobject=True)
self.defaults.append((arg, entry)) self.defaults.append((arg, entry))
......
...@@ -974,7 +974,7 @@ def printbuf_object(object[object] buf, shape): ...@@ -974,7 +974,7 @@ def printbuf_object(object[object] buf, shape):
>>> a, b, c = "globally_unique_string_23234123", {4:23}, [34,3] >>> a, b, c = "globally_unique_string_23234123", {4:23}, [34,3]
>>> get_refcount(a), get_refcount(b), get_refcount(c) >>> get_refcount(a), get_refcount(b), get_refcount(c)
(2, 2, 2) (3, 3, 3)
>>> A = ObjectMockBuffer(None, [a, b, c]) >>> A = ObjectMockBuffer(None, [a, b, c])
>>> printbuf_object(A, (3,)) >>> printbuf_object(A, (3,))
'globally_unique_string_23234123' 2 'globally_unique_string_23234123' 2
...@@ -991,15 +991,16 @@ def assign_to_object(object[object] buf, int idx, obj): ...@@ -991,15 +991,16 @@ def assign_to_object(object[object] buf, int idx, obj):
See comments on printbuf_object above. See comments on printbuf_object above.
>>> a, b = [1, 2, 3], [4, 5, 6] >>> a, b = [1, 2, 3], [4, 5, 6]
>>> get_refcount(a), get_refcount(b) >>> rca1, rcb1 = get_refcount(a), get_refcount(b)
(2, 2) >>> rca1 == rcb1
True
>>> addref(a) >>> addref(a)
>>> A = ObjectMockBuffer(None, [1, a]) # 1, ...,otherwise it thinks nested lists... >>> A = ObjectMockBuffer(None, [1, a]) # 1, ...,otherwise it thinks nested lists...
>>> get_refcount(a), get_refcount(b) >>> get_refcount(a) == rca1+1, get_refcount(b) == rcb1
(3, 2) (True, True)
>>> assign_to_object(A, 1, b) >>> assign_to_object(A, 1, b)
>>> get_refcount(a), get_refcount(b) >>> get_refcount(a) == rca1, get_refcount(b) == rcb1+1
(2, 3) (True, True)
>>> decref(b) >>> decref(b)
""" """
buf[idx] = obj buf[idx] = obj
...@@ -1010,15 +1011,14 @@ def assign_temporary_to_object(object[object] buf): ...@@ -1010,15 +1011,14 @@ def assign_temporary_to_object(object[object] buf):
See comments on printbuf_object above. See comments on printbuf_object above.
>>> a, b = [1, 2, 3], {4:23} >>> a, b = [1, 2, 3], {4:23}
>>> get_refcount(a) >>> rc1 = get_refcount(a)
2
>>> addref(a) >>> addref(a)
>>> A = ObjectMockBuffer(None, [b, a]) >>> A = ObjectMockBuffer(None, [b, a])
>>> get_refcount(a) >>> get_refcount(a) == rc1+1
3 True
>>> assign_temporary_to_object(A) >>> assign_temporary_to_object(A)
>>> get_refcount(a) >>> get_refcount(a) == rc1
2 True
>>> printbuf_object(A, (2,)) >>> printbuf_object(A, (2,))
{4: 23} 2 {4: 23} 2
......
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