[Python-Dev] Maybe we should have a C++ extension for testing...

Barry Scott barry at barrys-emacs.org
Sat Sep 23 14:06:34 CEST 2006

On Sep 13, 2006, at 18:46, skip at pobox.com wrote:

> Building Python with C and then linking in extensions written in or  
> wrapped
> with C++ can present problems, at least in some situations.  I  
> don't know if
> it's kosher to build that way, but folks do.  We're bumping into such
> problems at work using Solaris 10 and Python 2.4 (building  
> matplotlib, which
> is largely written in C++), and it appears others have similar  
> problems:
>     http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6395191
>     http://mail.python.org/pipermail/patches/2005-June/017820.html
>     http://mail.python.org/pipermail/python-bugs-list/2005-November/ 
> 030900.html
> I attached a comment to the third item yesterday (even though it was
> closed).
> One of our C++ gurus (that's definitely not me!) patched the Python  
> source
> to include <wchar.h> at the top of Python.h.  That seems to have  
> solved our
> problems, but seems to be a symptomatic fix.  I got to thinking,  
> should we
> a) encourage people to compile Python with a C++ compiler if most/ 
> all of
> their extensions are written in C++ anyway (does that even work if  
> one or
> more extensions are written in C?), or b) should the standard  
> distribution
> maybe include a toy extension written in C++ whose sole purpose is  
> to test
> for cross-language problems?

Mixing of C and C++ code is fully supported by the compilers and  
There is no need to compile the python core as C++ code, indeed if you
did only C++ extension could use it!

In the distent past  there had been problems with some
unix distributions linking python in such a way that C++ code would not
initialise. The major distributions seem to have sort these problems  
But clearly Solaris has a problem.

It would be worth finding out out why it was necessary to include  
to fix the problems. If you do add a C++ test extension it will need  
to do what
ever it was that <wchar.h> fixes.

 From what I can remember attempts to use std::cout would fail and I  
static object initialisation would fail. The test code would need to  
do all these
things and verify they are working.

Barry (PyCXX cxx.sourceforge.net)

More information about the Python-Dev mailing list