This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients lemburg, mark.dickinson, rhettinger, vstinner
Date 2021-10-15.09:43:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634290986.94.0.655495121595.issue45476@roundup.psfhosted.org>
In-reply-to
Content
For PyObject, I converted Py_REFCNT(), Py_TYPE() and Py_SIZE() to static inline functions to enforce the usage of Py_SET_REFCNT(), Py_SET_TYPE() and Py_SET_SIZE(). Only a minority of C extensions are affected by these changes. Also, there is more pressure from recent optimization projects to abstract accesses to PyObject members.

I agree that it doesn't seem that "AS" functions are abused to *set* the inner string:

* PyByteArray_AS_STRING()
* PyBytes_AS_STRING()
* PyFloat_AS_DOUBLE()

> If "protecting against wrong use" is the only reason to go down the slippery path of starting to rely on compiler optimizations for performance critical operations, the argument is not good enough.

Again, I'm not aware of any performance issue caused by short static inline functions like Py_TYPE() or the proposed PyFloat_AS_DOUBLE(). If there is a problem, it should be addressed, since Python uses more and more static inline functions.

static inline functions is a common feature of C language. I'm not sure where your doubts of bad performance come from.

Using static inline functions has other advantages. It helps debugging and profiling, since the function name can be retrieved by debuggers and profilers when analysing the machine code. It also avoids macro pitfalls (like abusing a macro to use it as an l-value ;-)).
History
Date User Action Args
2021-10-15 09:43:07vstinnersetrecipients: + vstinner, lemburg, rhettinger, mark.dickinson
2021-10-15 09:43:06vstinnersetmessageid: <1634290986.94.0.655495121595.issue45476@roundup.psfhosted.org>
2021-10-15 09:43:06vstinnerlinkissue45476 messages
2021-10-15 09:43:06vstinnercreate