Skip to content

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Mar 6, 2020

In debug mode, _PyObject_CAST() now checks if the argument is valid
Python object. The new _PyObject_Cast() function is a tradeoff
between correctness and performance: it implements way less checks
than _PyObject_CheckConsistency(). It only checks 3 things:

  • check the pointer itself with _PyMem_IsPtrFreed()
  • check that ob_refcnt >= 0
  • check ob_type with _PyMem_IsPtrFreed()

Tolerate ob_refcnt==0 to allow to use _PyObject_CAST() in deallocator
functions like unicode_dealloc().

https://bugs.python.org/issue39873

In debug mode, _PyObject_CAST() now checks if the argument is valid
Python object. The new _PyObject_Cast() function is a tradeoff
between correctness and performance: it implements way less checks
than _PyObject_CheckConsistency(). It only checks 3 things:

* check the pointer itself with _PyMem_IsPtrFreed()
* check that ob_refcnt >= 0
* check ob_type with _PyMem_IsPtrFreed()

Tolerate ob_refcnt==0 to allow to use _PyObject_CAST() in deallocator
functions like unicode_dealloc().
@vstinner
Copy link
Member Author

vstinner commented Mar 6, 2020

PR rebased on master, since I merged two other changes related to https://bugs.python.org/issue39873

@brettcannon brettcannon removed their request for review March 13, 2020 20:39
@vstinner
Copy link
Member Author

This change was mostly an experimentation. But I'm not sure that it does solve any issue. The change is more intrusive than what I expected. I prefer to abandon it.

@vstinner vstinner closed this Mar 25, 2020
@vstinner vstinner deleted the pyobject_cast branch March 25, 2020 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants