[Python-Dev] Constifying C API
victor.stinner at gmail.com
Mon Dec 19 05:29:33 EST 2016
2016-12-18 9:31 GMT+01:00 Serhiy Storchaka <storchaka at gmail.com>:
> Originally C API didn't use the const qualifier. Over few last years the
> const qualifier was added to C API if that preserved backward compatibility.
> For example input "char *" parameters were changed to "const char *". This
> makes C API compatible with C++, eliminates C compiler warnings, and helps
> to found possible errors.
Since the "const" keyword does not impact the stable *ABI*, I think
that it's fine to add use it in more places.
In the worst case, if an extension chose to be compiled with -Werror
(convert warnings into errors), the maintainer will have to fix
conversion warnings in the code. But it's easy to write C code which
works with and without const (old and new Python *API*), using
explicit cast (to const char* for example).
In the common case, it will just be a warning and nobody will notice
it since more and more people use pip which compiles C extensions in
the background and doesn't show GCC output anymore.
I agree that it can help to find real bugs.
More information about the Python-Dev