8000 Reference count error from subscript operation · Issue #5063 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Reference count error from subscript operation #5063

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

Closed
abalkin opened this issue Sep 10, 2014 · 4 comments · Fixed by #5066
Closed

Reference count error from subscript operation #5063

abalkin opened this issue Sep 10, 2014 · 4 comments · Fixed by #5066

Comments

@abalkin
Copy link
Contributor
abalkin commented Sep 10, 2014

Running the following code with numpy 1.8.1

import numpy

class C(object):
    def __index__(self):
        return 0
    def __len__(self):
        return 1
    def __getitem__(self, item):
        raise IndexError

x = numpy.array([1])
i = C()
print(repr(x[i]))

I get

*** Reference count error detected:
an attempt was made to deallocate 5 (i) ***
Traceback (most recent call last):
  File "x.py", line 13, in <module>
    print(x[i])
  File "x.py", line 9, in __getitem__
    raise NotImplementedError
NotImplementedError

With 1.9.0, I don't get a reference error, but the result is still wrong:

array([1])

(I expect 1.)

@seberg
Copy link
Member
seberg commented Sep 11, 2014

Shit, while I don't trust your type with that length + index not an error, a bug did seem to have sneaked past the tests... (Which I find weird, because I should have tests for this, but maybe just the 0-d case, and array_assert_equal has a weakness there)

@seberg
Copy link
Member
seberg commented Sep 11, 2014

Ohh ok, the sequence stuff doesn't matter anyway. x[i,] works right, so I expect the reason is hidden in the C-Api sequence getting code.

@seberg
Copy link
Member
seberg commented Sep 11, 2014

Or maybe it does :), heh... so I guess it is due to missing error handling, maybe in the non-tuple code making it an empty tuple. May look at it more today, otherwise tomorrow probably.

@seberg
Copy link
Member
seberg commented Sep 11, 2014

OK, it is because tuple(C()) == (), which may or may not be funny. Anyway, the fact that it does tuple(C()) and not (C(), ) on failing to get C()[0] is wrong.

seberg added a commit to seberg/numpy that referenced this issue Sep 13, 2014
A sequence which raises an error on item getting, should be just
handled as a single index and not a tuple nd-index.

Also fix some error handling.

closes numpygh-5063
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0