Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 4520 due to storage model mismatch #4623

Merged
merged 3 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions numba/tests/test_dictobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,22 @@ def foo(d):
# Value is correctly updated
self.assertPreciseEqual(d[1], np.arange(10, dtype=np.int64) + 100)

def test_storage_model_mismatch(self):
sklam marked this conversation as resolved.
Show resolved Hide resolved
# https://github.com/numba/numba/issues/4520
# check for storage model mismatch in refcount ops generation
dct = Dict()
ref = [
("a", True, "a"),
("b", False, "b"),
("c", False, "c"),
]
# populate
for x in ref:
dct[x] = x
# test
for i, x in enumerate(ref):
self.assertEqual(dct[x], x)


class TestDictForbiddenTypes(TestCase):
def assert_disallow(self, expect, callable):
Expand Down
16 changes: 16 additions & 0 deletions numba/tests/test_typedlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,3 +742,19 @@ def bag_equal(one, two):
np.testing.assert_allclose(one.array, two.array)

[bag_equal(a, b) for a, b in zip(expected, got)]

def test_storage_model_mismatch(self):
# https://github.com/numba/numba/issues/4520
# check for storage model mismatch in refcount ops generation
lst = List()
ref = [
("a", True, "a"),
("b", False, "b"),
("c", False, "c"),
]
# populate
for x in ref:
lst.append(x)
# test
for i, x in enumerate(ref):
self.assertEqual(lst[i], ref[i])
11 changes: 9 additions & 2 deletions numba/typedobjectutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,23 @@ def _get_incref_decref(context, module, datamodel, container_type):
refct_fnty,
name='.numba_{}_incref${}'.format(container_type, fe_type),
)

builder = ir.IRBuilder(incref_fn.append_basic_block())
context.nrt.incref(builder, fe_type, builder.load(incref_fn.args[0]))
context.nrt.incref(
builder, fe_type,
datamodel.load_from_data_pointer(builder, incref_fn.args[0]),
)
builder.ret_void()

decref_fn = module.get_or_insert_function(
refct_fnty,
name='.numba_{}_decref${}'.format(container_type, fe_type),
)
builder = ir.IRBuilder(decref_fn.append_basic_block())
context.nrt.decref(builder, fe_type, builder.load(decref_fn.args[0]))
context.nrt.decref(
builder, fe_type,
datamodel.load_from_data_pointer(builder, decref_fn.args[0]),
)
builder.ret_void()

return incref_fn, decref_fn
Expand Down