-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Returning borrowed reference Python objects causes reference count error. #21
Comments
Good catch. James submitted (and I pushed) that example knowing that it was causing segmentation faults, but we didn't have time to debug it at the SciPy sprint. (Conjecture, but feels spot on:) This code (along with other code posted on the discussion list) returns the output parameter. Since the generated code doesn't increment the reference count, the output array gets free()'d when the return value is ignored and popped off the interpreter's value stack. Subsequent uses of that array are writing to unmapped memory, causing segmentation faults, or double free()'s. See if removing the "return output" line fixes it, and I'll try the same. As far as the prognosis for fixing this goes, I can most likely write a quick fix that detects escaping array objects, and increments the reference count before returning to Python (taking care to remove the reference count increment added to fix issue 2). This complicates LLVM-to-LLVM code calls, however, since nesting calls will return an incorrect reference count (for example, a JIT'ed function returning the array returned by another JIT'ed function would have 1 more reference count than needed, causing a memory leak). |
See the commit for my modified version of the fbcorr example. This works for me, but note that the return type has changed, in addition to removing the return statement (when Numba currently tries to cast None to a 4-d array of doubles, it hits a LLVM assertion and dies). |
I will test this for my code tomorrow. |
Works for me now! I don't know how you want to inform users of this quirk. Outside of Numba, these pointer problems are either hyper-explicit (Cython) or completely transparent (Python/Numpy). I wouldn't mind Numba throwing an error if I tried to return an array. I also can't allocate arrays of arbitrary sizes (np.zeros() et al don't work right now, I think), so it seems reasonable to beep at the user if a return statement will cause problems. |
This is what I was writing it all for: http://nbviewer.ipython.org/3407544 It now works quite well! So astoundingly fast for how readable the code is. |
And one last syntactic question: |
The [['d']] type notation was an early ad hoc design, and will be deprecated. If you don't like typing "numba.double" all the time, the shorthand "numba.d" is also available. |
This has been fixed for the ast backend for a while now. SInce the bytecode backend is deprecated, I'm closing this. |
Making a small modification to the fbcorr code like this, to call the fbcorr() method from within a for loop causes a crash:
Produces the following crash:
The text was updated successfully, but these errors were encountered: