[New-bugs-announce] [issue4805] Make python code compilable with a C++ compiler
Alexander Belopolsky
report at bugs.python.org
Fri Jan 2 05:56:46 CET 2009
New submission from Alexander Belopolsky <belopolsky at users.sourceforge.net>:
I am posting this patch mainly to support python-dev discussion on this
topic. In the past (see r45330) it was possible to compile python core
and standard library modules using a C++ compiler.
According to Martin v. Löwis (issue4665), "It's not a requirement that
the Python source code is compilable as C++. Only the header files
should be thus compilable." However, I can see certain benefits from
such requirement:
1. It is hard to verify that header files are compilable if source code
is not. With compilable source code, CC=g++ ./configure; make will
supply an adequate test that does not require anything beyond a standard
distribution.
2. Arguably, C++ compliant code is more consistent and less error prone.
For example, "new" is a really bad choice for a variable name regardless
of being a C++ keyword, especially when used instead of prevailing "res"
for a result of a function producing a PyObject. Even clearly redundant
explicit casts of malloc return values arguably improve readability by
reminding the type of the object that is being allocated.
3. Compiling with C++ may reveal actual coding errors that otherwise go unnoticed. For example, use of undefined PyLong_BASE_TWODIGITS_TYPE in Objects/longobject.c.
4. Stricter type checking may promote use of specific types instead of
void* which in turn may help optimizing compilers.
5. Once achieved, C++ compilability is not that hard to maintain, but
restoring it with patches like this one is hard because it requires
review of changes to many unrelated files.
----------
files: c++-patch.diff
keywords: patch
messages: 78756
nosy: belopolsky
severity: normal
status: open
title: Make python code compilable with a C++ compiler
type: feature request
versions: Python 2.6
Added file: http://bugs.python.org/file12527/c++-patch.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4805>
_______________________________________
More information about the New-bugs-announce
mailing list