@@ -326,87 +326,6 @@ _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
326326
327327PyAPI_FUNC (PyObject * ) _PyObject_FunctionStr (PyObject * );
328328
329- /* Safely decref `dst` and set `dst` to `src`.
330- *
331- * As in case of Py_CLEAR "the obvious" code can be deadly:
332- *
333- * Py_DECREF(dst);
334- * dst = src;
335- *
336- * The safe way is:
337- *
338- * Py_SETREF(dst, src);
339- *
340- * That arranges to set `dst` to `src` _before_ decref'ing, so that any code
341- * triggered as a side-effect of `dst` getting torn down no longer believes
342- * `dst` points to a valid object.
343- *
344- * Temporary variables are used to only evaluate macro arguments once and so
345- * avoid the duplication of side effects. _Py_TYPEOF(), C++ auto, or memcpy()
346- * is used to avoid a miscompilation caused by type punning. See Py_CLEAR()
347- * comment for implementation details about type punning.
348- *
349- * The memcpy() implementation does not emit a compiler warning if 'src' has
350- * not the same type than 'src': any pointer type is accepted for 'src'.
351- */
352- #ifdef _Py_TYPEOF
353- #define Py_SETREF (dst, src ) \
354- do { \
355- _Py_TYPEOF (&(dst)) _tmp_dst_ptr = &(dst); \
356- _Py_TYPEOF (dst) _tmp_old_dst = (*_tmp_dst_ptr); \
357- *_tmp_dst_ptr = (src); \
358- Py_DECREF (_tmp_old_dst); \
359- } while (0 )
360- #elif defined(__cplusplus) && (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
361- #define Py_SETREF (dst, src ) \
362- do { \
363- auto _tmp_dst_ptr = &(dst); \
364- auto _tmp_old_dst = (*_tmp_dst_ptr); \
365- *_tmp_dst_ptr = (src); \
366- Py_DECREF (_tmp_old_dst); \
367- } while (0 )
368- #else
369- #define Py_SETREF (dst, src ) \
370- do { \
371- PyObject **_tmp_dst_ptr = _Py_CAST (PyObject**, &(dst)); \
372- PyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
373- PyObject *_tmp_src = _PyObject_CAST (src); \
374- memcpy (_tmp_dst_ptr, &_tmp_src, sizeof (PyObject*)); \
375- Py_DECREF (_tmp_old_dst); \
376- } while (0 )
377- #endif
378-
379- /* Py_XSETREF() is a variant of Py_SETREF() that uses Py_XDECREF() instead of
380- * Py_DECREF().
381- */
382- #ifdef _Py_TYPEOF
383- #define Py_XSETREF (dst, src ) \
384- do { \
385- _Py_TYPEOF (&(dst)) _tmp_dst_ptr = &(dst); \
386- _Py_TYPEOF (dst) _tmp_old_dst = (*_tmp_dst_ptr); \
387- *_tmp_dst_ptr = (src); \
388- Py_XDECREF (_tmp_old_dst); \
389- } while (0 )
390- #elif defined(__cplusplus) && (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
391- #define Py_XSETREF (dst, src ) \
392- do { \
393- auto _tmp_dst_ptr = &(dst); \
394- auto _tmp_old_dst = (*_tmp_dst_ptr); \
395- *_tmp_dst_ptr = (src); \
396- Py_XDECREF (_tmp_old_dst); \
397- } while (0 )
398- #else
399- #define Py_XSETREF (dst, src ) \
400- do { \
401- PyObject **_tmp_dst_ptr = _Py_CAST (PyObject**, &(dst)); \
402- PyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
403- PyObject *_tmp_src = _PyObject_CAST (src); \
404- memcpy (_tmp_dst_ptr, &_tmp_src, sizeof (PyObject*)); \
405- Py_XDECREF (_tmp_old_dst); \
406- } while (0 )
407- #endif
408-
409-
410329/* Define a pair of assertion macros:
411330 _PyObject_ASSERT_FROM(), _PyObject_ASSERT_WITH_MSG() and _PyObject_ASSERT().
412331
0 commit comments