[Python-3000] Python/C++ question
"Martin v. Löwis"
martin at v.loewis.de
Sun Dec 10 10:13:16 CET 2006
> A while back someone proposed switching to C++ as the implementation
> language for CPython, and the response was that this would make ABI
> compatibility too difficult, since the different C++ compilers don't
> have a common way to represent things like vtables and such.
This is a lesser issue than it used to be. Today, on Linux, many
compilers support a standard ABI (specified originally for IA-64);
this ABI is now also part of the Linux Standards Base. The issue
also became lesser as the number of "life" C++ implementations got
reduced over time. The issue is still real on Windows, where you
either use the MS ABI or the GCC ABI.
> However, I was thinking - if you remove all of the ABI-breaking features
> of C++, such as virtual functions, name mangling, RTTI, exceptions, and
> so on, its still a pretty nice language compared to C - you still have
> things like namespaces, constructors/destructors (especially nice for
> stack-local objects), overloadable type conversion, automatic
> upcasting/downcasting, references, plus you don't have to keep repeating
> the word 'struct' everywhere.
Most of these are ABI relevant:
- namespaces rely on the name mangling the compiler uses; different
compilers use different name mangling
- constructors also rely on name mangling, plus there are differences
on how virtual bases are dealt with, and on where the memory
allocation occurs (for heap objects)
- overloadable type conversions rely on name mangling
- automatic upcasting and downcasting relies on the object layout;
for dynamic_cast, you need virtual methods
References themselves likely have a uniform implementation, but
reference parameters of course affect the name mangling. Also,
binding to references may involve temporary objects, in which case
constructors are involved.
Not having to repeat struct has no ABI impact.
More information about the Python-3000