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: PyErr_SetObject does not steal reference (Ticket 2216) #449

Merged
merged 1 commit into from
Sep 30, 2012

Conversation

seberg
Copy link
Member

@seberg seberg commented Sep 18, 2012

It seems that PyErr_SetObj is assumed ot steal a references in most parts of numpy, but appearently it does not. I assume that in /doc/pyrex/numpyx.c it is correct, but am not quite sure about the occurances in /numpy/random/mtrand/mtrand.c. Seems to also fix Ticket 2125.

@seberg
Copy link
Member Author

seberg commented Sep 18, 2012

This would be a test, but since it only covers broadcasting error like this... also I am not sure if the refcount may not be a bit different between python versions, since it seems to be 4 and not 2 here because of function scope or such.

    def test_error_refcount(self):
        # ticket #2216
        a = np.arange(3)
        try:
            a *= a[:-1] # broadcasting error
        except ValueError, e:
            pass
        m = e.args[0]
         # not sure why its 4 in func scope
        assert_equal(sys.getrefcount(m), 4)

@teoliphant
Copy link
Member

You are correct. We should DECREF the error message because PyErr_SetObject doesn't steal the reference. Good catch!

@njsmith
Copy link
Member

njsmith commented Sep 21, 2012

Looks good to me. I don't know of any good way to test this either. And really you'd need a different test for every possible error message, since whether or not we the programmer forgot the DECREF is determined separately for every call-site. So I guess we should let this in without tests, unless someone has a better idea.

@njsmith
Copy link
Member

njsmith commented Sep 21, 2012

(The test failure is unrelated.)

@njsmith
Copy link
Member

njsmith commented Sep 30, 2012

Well, looks like no-one has a better idea, so let's do it :-)

njsmith added a commit that referenced this pull request Sep 30, 2012
FIX: PyErr_SetObject does not steal reference (Ticket 2216)
@njsmith njsmith merged commit 78d0272 into numpy:master Sep 30, 2012
This was referenced Sep 30, 2012
@seberg seberg deleted the setobjref branch January 18, 2013 13:46
charris referenced this pull request Oct 12, 2015
Backport gh-6449: DEP: Remove warning for `full` when dtype is set.
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 this pull request may close these issues.

None yet

3 participants