Remove printing if Decref is called with NULL. Rename Decref/Incref to XDecref/XIncref#275
Conversation
filmor
left a comment
There was a problem hiding this comment.
The Runtime.Decref and Incref check for the pointer being 0 in all cases. Did you see any actual problems with this part of the code?
|
@filmor actually Also there are 2 places where Runtime.Decref(self.repr) is called in the same file. |
|
The check was the problem, actually: it calls
then (for some reason I don't fully understand) |
|
I found the reason for the IOException: it is due to this:
from https://msdn.microsoft.com/en-us/library/system.console.aspx?f=255&MSPPError=-2147217396 Even without those problems the spurious "Decref("NULL")" error messages are pretty annoying. Any objections to this change? |
|
I agree with this change but why not change in both places? pythonnet/src/runtime/constructorbinding.cs Line 239 in 44973c6 pythonnet/src/runtime/constructorbinding.cs Line 150 in 44973c6 On Thu, Oct 20, 2016 at 8:53 AM, ArvidJB notifications@github.com wrote:
|
|
Well, isn't the right thing to do then fixing/removing the debug log and documenting that EDIT: Just to clarify, even if the code does not go into the home-made decref (https://github.com/pythonnet/pythonnet/blob/master/src/runtime/runtime.cs#L567), it calls |
|
Is it really safe to call On Thu, Oct 20, 2016 at 9:16 AM, Benedikt Reinartz <notifications@github.com
|
|
@denfromufa i made the other change as well. I missed it since it looks like we were not hitting that problem in ConstructorBinding.tp_dealloc in our codebase. |
|
@denfromufa I don't know why those checks are in, but just look at the function, both implementations (with I vote we remove the message instead and document the behaviour. |
|
I agree that DebugUtil.Print() is a useful method and it should probably be So I agree with this pull request now, but generally we have a lot of other On Thu, Oct 20, 2016 at 10:57 AM, ArvidJB notifications@github.com wrote:
|
|
@denfromufa sounds good to me. |
|
@filmor do you mean that this line below is the check for the pointer being zero? pythonnet/src/runtime/runtime.cs Line 579 in 44973c6 Where is equivalent check for Py_DEBUG version? I did not find this! @ArvidJB somehow my previous message that I sent using gmail was pushed/updated only 9 hours ago on github. But in my gmail I sent it 5 days ago, before @filmor 's last message. This is just to clarify the sequence of messages we had 5 days ago. @tonyroberts @vmuriart do you guys have any better suggestions for this pull request? In my opinion, we need to address 2 questions:
|
|
Just saw filmor's earlier comment that the exported Py_DecRef function is actually Py_XDECREF. What I would do is rename Decref to Py_XDECREF and keep the null check and remove the logging - then it's clear to everyone that it can be called safely with a null pointer. |
|
@tonyroberts thanks for pointing to @filmor 's edit above. Indeed, I did not notice it either. Especially, since I was looking at my email. So new messages about edits are generally better + optional in-place edits. @ArvidJB now I completely agree with the latest comments from @filmor and @tonyroberts. Let me know if anything is not clear? Are you planning to continue with this pull request? |
|
@denfromufa That makes sense, I will try to make that change. Should I open a new pull request for that or is it okay to continue on this one? |
|
We can continue on this pull request and from your branch. Once ready, we On Wed, Oct 26, 2016 at 11:12 AM, ArvidJB notifications@github.com wrote:
|
…heck for NULL Remove NULL check debug print in Decref Remove added NULL checks for self.repr in constructorbinding.cs
|
I renamed Incref/Decref to XIncref/XDecref instead of Py_XINCREF/Py_XDECREF since that felt like a more C# appropriate name. I removed the additional NULL check I had added and also removed the code that prints on NULL in Decref. |
|
looks like @tonyroberts approved your commit @ArvidJB @filmor do you agree with these changes? |
|
I agree, but please rename and squash the PR before merging. |
|
@filmor now we can squash or rebase and merge pull requests with one button click (select a drop-down on merge pull request). More info in this article: |
self.repr is set in tp_repr() when called (which also increases the reference count). But if it's not populated we should not decrease the reference count