FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Specialize Py_DECREF() for Py_REF_DEBUG by vstinner · Pull Request #16781 · python/cpython · GitHub

/ cpython Public

Specialize Py_DECREF() for Py_REF_DEBUG - #16781

Closed
vstinner wants to merge 1 commit into
python:masterfrom
vstinner:decref
Closed

Specialize Py_DECREF() for Py_REF_DEBUG#16781
vstinner wants to merge 1 commit into
python:masterfrom
vstinner:decref

Conversation

Copy link
Copy Markdown
Member

Simplify Py_DECREF() code for release mode: don't pass FILE and
LINE to the static inline function.

Simplify Py_DECREF() code for release mode: don't pass __FILE__ and
__LINE__ to the static inline function.

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member

Why so complicated? Why not use just macros?

vstinner commented Oct 14, 2019
edited
Loading

Copy link
Copy Markdown
Member Author

Why so complicated? Why not use just macros?

Oh, see https://bugs.python.org/issue35059#msg328367 for the rationale.

Comment thread Include/object.h
_Py_NegativeRefcount(filename, lineno, op);
}
#endif
_Py_RefTotal--;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

So this _Py_DEC_REFTOTAL would be converted in your plan?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

_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.

ghost commented Oct 18, 2019

Copy link
Copy Markdown

I'm not sure that all compilers are smart enough to remove the arguments

I tested almost all versions of gcc/clang/msvc/icc:
https://godbolt.org/z/w-N-Kt

All versions have the same behavior:
If with -O1 option, compilers are smart enough to remove the arguments.
If without any option, the extra machine code was emited.

Copy link
Copy Markdown
Member Author

Why not use just macros?

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.)

Comment thread Include/object.h
#endif
_Py_RefTotal--;
if (--op->ob_refcnt == 0) {
_Py_Dealloc(op);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This code dupe irks me. Can't you make the REF_DEBUG version call the regular version instead?

vstinner commented Jan 6, 2020

Copy link
Copy Markdown
Member Author

This code dupe irks me. Can't you make the REF_DEBUG version call the regular version instead?

_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).

Copy link
Copy Markdown
Member Author

I merged PR #17870 instead, commit f3a0a6b.

vstinner closed this Jan 25, 2020
vstinner deleted the decref branch January 25, 2020 11:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

6 participants


Back | FazBrowse Home | New Git URL