Using C++ and ctypes together: a vast conspiracy? ;)

Diez B. Roggisch deets at nospam.web.de
Tue Jun 2 17:11:58 EDT 2009


Joseph Garvin schrieb:
> So I was curious whether it's possible to use the ctypes module with
> C++ and if so how difficult it is. I figure in principal it's possible
> if ctypes knows about each compiler's name mangling scheme. So I
> searched for "ctypes c++" on Google.
> 
> The third link will be "Using ctypes to Wrap C++ Libraries". If you
> follow the link, it's broken. If you view the cache of the link, it's
> someone pointing to another blog, retrograde-orbit.blogspot.com,
> saying they discovered a way to do it easily. If you follow that link,
> you get taken a page does not exist error.
> 
> Clearly there's some way to use ctypes with C++ and there's a vast
> conspiracy preventing it from reaching the masses ;) What's even
> stranger is that this link, despite being broken, has seemingly been
> near the top of google's results for these terms for a couple weeks
> (that's when I last tried), as if there were some underground group of
> rebels trying to hint the truth to us... ;)
> 
> More seriously -- how difficult is it to use ctypes instead of saying,
> boost::python, and why isn't this in a FAQ somewhere? ;)

Because it's much more needed than name-mangling. Name mangling is 
(amongst other things) one thing to prevent 
C++-inter-compiler-interoperability which results from differing C++ ABIs.

I'm not an expert on this, but AFAIK no common ABI exists, especially 
not amongst VC++ & G++. Which means that to work for C++, ctypes would 
need to know about the internals of both compilers, potentially in 
several versions, and possibly without prior notice to changes.

Instead of dealing with this truly daunting task, tools such as SIP and 
SWIG or boost::python deal with this by utilizing the one tool that 
really knows about the ABI in use - the compiler itself.

So while I'd loved to be proven wrong, I fear your curiosity won't be 
satisfied - or at least not in the positive sense you certainly envisioned.

Diez








More information about the Python-list mailing list