If not already present, do you think it's useful to add a macro that does something like
# ifdef Py_DEBUG
fprintf(stderr, "%s\n", message);
# endif
?
On Wed, 21 Oct 2020 14:19:37 +0200 Marco Sulla Marco.Sulla.Python@gmail.com wrote:
If not already present, do you think it's useful to add a macro that does something like
# ifdef Py_DEBUG
fprintf(stderr, "%s\n", message);
# endif
In general, you want to do this on a per-component basis, so each C source file tends to redefine its own macros if it needs to.
Regards
Antoine.
21.10.20 15:30, Antoine Pitrou пише:
On Wed, 21 Oct 2020 14:19:37 +0200 Marco Sulla Marco.Sulla.Python@gmail.com wrote:
If not already present, do you think it's useful to add a macro that does something like
# ifdef Py_DEBUG
fprintf(stderr, "%s\n", message);
# endif
In general, you want to do this on a per-component basis, so each C source file tends to redefine its own macros if it needs to.
I concur with Antoine.
Hi,
There is the __debug__ builtin variable which is equal to True by default, but is equal to False when Python is run with the -O command line option.
The compiler removes dead code when -O is used. Example:
$ cat x.py def func(): if __debug__: print("debug")
import dis dis.dis(func)
# "debug" constant is checked at runtime
$ python3 x.py 2 0 LOAD_GLOBAL 0 (print) 2 LOAD_CONST 1 ('debug') 4 CALL_FUNCTION 1 6 POP_TOP 8 LOAD_CONST 0 (None) 10 RETURN_VALUE
# code removed by the compiler
$ python3 -O x.py 2 0 LOAD_CONST 0 (None) 2 RETURN_VALUE
Victor
Le mer. 21 oct. 2020 à 14:21, Marco Sulla
Marco.Sulla.Python@gmail.com a écrit : >
If not already present, do you think it's useful to add a macro that does something like
# ifdef Py_DEBUG
fprintf(stderr, "%s\n", message);
# endif
?
Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/6W6YO6JS... Code of Conduct: http://python.org/psf/codeofconduct/
-- Night gathers, and now my watch begins. It shall not end until my death.
Thank you Victor, I know. I meant a macro in CPython. Maybe not so sane to have a unique global logger in C, as Antoine pointed out.