wrappy
wrappy copied to clipboard
Add optional support for Python 3
This PR adds Python 3 support. By default, the system version of PythonLibs is used, but I can set it to use v2.7 by default instead.
Mostly it was just a case of replacing Py* functions with their Python 3 counterparts, but there were a couple of semantic changes I had to make to make things work with Python 3:
- Strings are encoded as Unicode in Python 3, so use
wchar_tinternally. Rather than returningwchar_tfromstr()I opted to convert it to UTF8 and return astd::stringfor the Python 3 version (needed because you have to copy the memory). Likewisestd::map<char *, ...>has been changed to usestd::stringin a few places. I could have just replaced uses ofchar *withstd::stringfor Python 2 but that would have broken the API for existing users -- you could do this for consistency in some future version though. This change also means thatPython.hhas to be included inwrappy.hso that it knows what the return type forstr()should be. - CObjects have been replaced with Capsules in Python 3, so I use those instead. I think what I've done should be equivalent.
Ok, so I only just noticed #4! It seems that that PR doesn't change the functions to their Python 3 counterparts though.