wrappy icon indicating copy to clipboard operation
wrappy copied to clipboard

Add optional support for Python 3

Open alexdewar opened this issue 6 years ago • 1 comments

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_t internally. Rather than returning wchar_t from str() I opted to convert it to UTF8 and return a std::string for the Python 3 version (needed because you have to copy the memory). Likewise std::map<char *, ...> has been changed to use std::string in a few places. I could have just replaced uses of char * with std::string for 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 that Python.h has to be included in wrappy.h so that it knows what the return type for str() 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.

alexdewar avatar Aug 19 '19 17:08 alexdewar

Ok, so I only just noticed #4! It seems that that PR doesn't change the functions to their Python 3 counterparts though.

alexdewar avatar Aug 19 '19 18:08 alexdewar