[Python-3000] Python/C++ question

"Martin v. Löwis" martin at v.loewis.de
Sat Dec 16 13:22:33 CET 2006

Giovanni Bajo schrieb:
>>> To me, the killer feature would be that in C++ you can implement a smart 
>>> pointer which takes care of incref/decref automatically for 99% of the code. 
>>> This would be a terrific tool for the extension/core writers.
>> Of course, this would also break in presence of binary-incompatible
>> compilers, in particular when it relates to exception handling.
> Details?

For the smart pointer itself, the object layout may differ between
compilers, and the mangled names for the constructor and destructor
will differ.

For exception handling, the layout of stack frames, and the way
unwinding information is represented will differ.

> Is that a problem, given that you can't compile Python core and 
> extensions with different MSVC versions?

Yes. First, we currently *can* compile extensions with gcc on Windows;
that may stop working. Furthermore, we currently have compatibility
across compilers on Solaris, HP-UX, AIX, etc; we will lose that when
we use C++ (except perhaps for Linux, where compilers tend to be ABI
compatible with g++ these days).

> struct ScopedIncRef
> {
> public:
>      ScopedIncRef(PyObject *o) { Py_INCREF(o); }
>      ~ScopedIncRef() { Py_DECREF(o); }
> };

That won't work: the variable "o" is not available in the destructor.


More information about the Python-3000 mailing list