| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Simplify Py_DECREF() code for release mode: don't pass __FILE__ and __LINE__ to the static inline function.
|
In Python 3.7, Py_DECREF() was a macro. I converted it to a static inline function in PR #10079 of https://bugs.python.org/issue35059 The new static inline function always require filename and lineno arguments, even in release mode. I'm not sure that all compilers are smart enough to remove the arguments, so I prefer to help compilers to ensure that the emited machine code is as efficient as Python 3.7. |
Sorry, something went wrong.
|
Why so complicated? Why not use just macros? |
Sorry, something went wrong.
Oh, see https://bugs.python.org/issue35059#msg328367 for the rationale. |
Sorry, something went wrong.
| _Py_NegativeRefcount(filename, lineno, op); | ||
| } | ||
| #endif | ||
| _Py_RefTotal--; |
There was a problem hiding this comment.
So this _Py_DEC_REFTOTAL would be converted in your plan?
Sorry, something went wrong.
There was a problem hiding this comment.
_Py_DEC_REFTOTAL = _Py_RefTotal-- when Py_REF_DEBUG is defined. I prefer to put directly the real code, it may help debugging. It avoids the indirection of the preprocessor.
Sorry, something went wrong.
I tested almost all versions of gcc/clang/msvc/icc: All versions have the same behavior: |
Sorry, something went wrong.
Static inline functions have multiple benefits over macros. Let me give you one example. Today we get a bug report on Fedora on Python 3.8 which uses static inline functions rather than macros. Thanks to that, the line number in the gdb traceback was more accurate and so more usefull. (Sadly, the bug report is private because it's an automated crash report and it might contain sensitive information, so I cannot share it.) |
Sorry, something went wrong.
| #endif | ||
| _Py_RefTotal--; | ||
| if (--op->ob_refcnt == 0) { | ||
| _Py_Dealloc(op); |
There was a problem hiding this comment.
This code dupe irks me. Can't you make the REF_DEBUG version call the regular version instead?
Sorry, something went wrong.
_Py_DECREF() function cannot use __FILE__ and __LINE__ preprocessor magic macros. Only a macro can use them. I wrote PR #17870 to avoid duplicated code and avoid passing __FILE__ and __LINE__ in release mode (when Py_REF_DEBUG is not set). |
Sorry, something went wrong.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Simplify Py_DECREF() code for release mode: don't pass FILE and
LINE to the static inline function.