[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-20 Thread Erlend Egeberg Aasland
Erlend Egeberg Aasland added the comment: Based on the feedback, I'm closing this. The PyUnicode_* macros, or the callers, can be fixed in a separate issue. -- resolution: -> wont fix stage: patch review -> resolved status: open -> closed ___ Pyth

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-19 Thread Erlend Egeberg Aasland
Erlend Egeberg Aasland added the comment: FYI, thread started on https://discuss.python.org/t/what-to-do-with-unsafe-macros/7771?u=erlendaasland -- ___ Python tracker ___ ___

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-17 Thread Erlend Egeberg Aasland
Erlend Egeberg Aasland added the comment: Pablo: > I agree we should be careful here. There are several things to consider: Yes, and thanks for your thorough reply and insights. I do not suggest converting macros blindly, and I have no intention of doing so. Apart from the three PyUnicode_*(

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-16 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: I agree we should be careful here. There are several things to consider: * Macros transformed into function may or may not get inlined so there is a risk of affecting performance if we just transform them in bulk. * Because the macro is defined as 'st

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-16 Thread Raymond Hettinger
Raymond Hettinger added the comment: Be careful about performance. We know for sure that macros will inline. In contrast, inline functions might or might not inline (there are rules for when it can be done). When applied across source files, inlining often only occurs with an LTO build — a

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-16 Thread Erlend Egeberg Aasland
Erlend Egeberg Aasland added the comment: PyUnicode_WRITE, PyUnicode_READ, and PyUnicode_READ_CHAR all reuse their arguments, and there's a lot of occurrences (58 AFAICS) where they are called with the increment operator applied to the index argument. For example: Objects/unicodeobject.c:

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-16 Thread Erlend Egeberg Aasland
Change by Erlend Egeberg Aasland : Added file: https://bugs.python.org/file49877/macros-that-reuse-args.txt ___ Python tracker ___ ___ Pytho

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-16 Thread Erlend Egeberg Aasland
Change by Erlend Egeberg Aasland : Removed file: https://bugs.python.org/file49876/macros-that-reuse-args.txt ___ Python tracker ___ ___ Pyt

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-16 Thread Erlend Egeberg Aasland
Erlend Egeberg Aasland added the comment: Under Include/, including subdirectories, there are 88 macros that reuse arguments. -- Added file: https://bugs.python.org/file49876/macros-that-reuse-args.txt ___ Python tracker

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-15 Thread Erlend Egeberg Aasland
Change by Erlend Egeberg Aasland : -- keywords: +patch pull_requests: +23637 stage: -> patch review pull_request: https://github.com/python/cpython/pull/24875 ___ Python tracker _

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-15 Thread Erlend Egeberg Aasland
Erlend Egeberg Aasland added the comment: Should we try to split all macros like that, if possible? -- ___ Python tracker ___ ___ P

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-15 Thread STINNER Victor
STINNER Victor added the comment: I would add that we should pay attention to: * not introducing a backward incompatible C API change by mistake * not introducing new compiler warnings. A common source of warning is that macros have no type for their arguments or return value, whereas static

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-15 Thread STINNER Victor
STINNER Victor added the comment: For me, one of the my worst issue is when a macro evalutes an argument twice. Example: --- #include #define DOUBLE(value) ((value) + (value)) int main() { int x = 1; // expanded to: ((++x) + (++x)) int y = DOUBLE(++x); printf("x=%i y=%i\n",

[issue43502] [C-API] Convert obvious unsafe macros to static inline functions

2021-03-15 Thread Erlend Egeberg Aasland
New submission from Erlend Egeberg Aasland : Convert macros to static inline functions if...: - the macro contains a clear pitfall (for example "duplication of side effects") - the fix is trivial - the macro is not used as an l-value (for example Py_TYPE()) See also: - https://gcc.gnu.org/onli