Skip to content

Conversation

@alexdewar
Copy link

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.

By default, CMake will now use the system default version of Python.
@alexdewar
Copy link
Author

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

@alexdewar alexdewar closed this Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant