title: Is there any benefit to using Py_DECREF instead of Py_XDECREF for Python C Extensions?
body: <p>I'm working through the Python C Extension documentation for defining new types and just finished the <a href="https://docs.python.org/2/extending/newtypes.html#providing-finer-control-over-data-attributes" rel="noreferrer">Providing finer control over data attributes</a> section.</p>
  
  <p>In this section, they change the example code to ensure that the <code>first</code> and <code>last</code> attributes of the <code>Noddy</code> struct can never be <code>NULL</code>, for example by initializing the attributes to empty strings in <code>new</code> and adding getters and setters that raise <code>TypeError</code> if the user tries to delete or otherwise set these attributes to Null.</p>
  
  <p>Additionally (and the point of my question), the author changes all of the <code>Py_XDECREF</code> to <code>Py_DECREF</code> for these attributes, stating that:</p>
  
  <blockquote>
    <p>With these changes, we can assure that the first and last members are never NULL so we can remove checks for NULL values in almost all cases. This means that most of the Py_XDECREF() calls can be converted to Py_DECREF() calls. The only place we can’t change these calls is in the deallocator, where there is the possibility that the initialization of these members failed in the constructor.</p>
  </blockquote>
  
  <p>It seems to me that it would just be safer to use <code>Py_XDECREF</code>, given that <code>Py_DECREF</code> results in a <code>segmentation fault</code> if its passed a <code>NULL</code> value.</p>
  
  <p>What is the benefit to using <code>Py_DECREF</code> over <code>Py_XDECREF</code>?</p>