Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make boost compatible with python limited API #221

Open
Raincloud7 opened this issue Jul 26, 2018 · 6 comments
Open

Make boost compatible with python limited API #221

Raincloud7 opened this issue Jul 26, 2018 · 6 comments

Comments

@Raincloud7
Copy link

Currently boost python cannot be compiled with limited python API. To support many python versions it would be helpful to have this option.

https://docs.python.org/3/c-api/stable.html
http://code.activestate.com/lists/python-cplusplus-sig/17408/
https://www.python.org/dev/peps/pep-0384/

@cas--
Copy link

cas-- commented Jun 27, 2019

To help with searching, specifically ability to define Py_LIMITED_API

cas-- added a commit to cas--/boost.python that referenced this issue Jun 27, 2019
To allow building multi-version Python 3 extensions.

The replaced methods are error-checking variants.

Ref: boostorg#221
@cas--
Copy link

cas-- commented Jun 27, 2019

I have made a start on this and replace the methods in #270 which builds and passes tests.

However defining Py_LIMITED_API results in the build errors below:

--- include/boost/python/detail/wrap_python.hpp
+++ include/boost/python/detail/wrap_python.hpp
@@ -175,6 +175,7 @@ typedef int pid_t;
 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2 && PY_MICRO_VERSION < 2
 # include <boost/python/detail/python22_fixed.h>
 #else
+#define Py_LIMITED_API
 # include <Python.h>
 #endif

Snippet of build error:

gxx.compile src.list.o
In file included from include/boost/python/object/make_ptr_instance.hpp:8:0,
                 from include/boost/python/to_python_indirect.hpp:11,
                 from include/boost/python/converter/arg_to_python.hpp:10,
                 from include/boost/python/call.hpp:15,
                 from include/boost/python/object_core.hpp:14,
                 from include/boost/python/object.hpp:9,
                 from include/boost/python/list.hpp:10,
                 from ./src/list.cpp:5:
include/boost/python/object/make_instance.hpp: In static member function ‘static PyObject* boost::python::objects::make_instance_impl<T, Holder, Derived>::execute(Arg&)’:
include/boost/python/object/make_instance.hpp:35:36: error: invalid use of incomplete type ‘PyTypeObject {aka struct _typeobject}’
         PyObject* raw_result = type->tp_alloc(

I'm a little out of my depth here so some expertise would be welcome

@earonesty
Copy link

earonesty commented May 20, 2020

That error is because tp_alloc is not available in the limited api. Follow https://www.python.org/dev/peps/pep-0384/ to fix. Basically, you have to walk through all the failures, change boost to using the limited api for as many as you can (a good practice anyway), and disable the feature if you can't. It's a big chore.

@AllSeeingEyeTolledEweSew

This is really important.

Compilation times with boost are already huge, since boost is meant for large-scale C++ projects.

Lack of support for abi3 / Py_LIMITED_API means that users have to build and ship 5x as many artifacts, to cover all currently-supported python versions (3.6 through 3.10 as of writing).

cas-- added a commit to cas--/boost.python that referenced this issue Sep 4, 2021
To allow building multi-version Python 3 extensions.

The replaced methods are error-checking variants.

Ref: boostorg#221
@cas--
Copy link

cas-- commented Sep 4, 2021

I thought I would do some research on this to determine what effort is required to get to a stable abi. The only downsides I have read is that it might come at a small performance cost.

cPython Reference:

Push to maintain the stable abi:

Other projects with in-progress work:

Building the pip wheel with py_limited_api:

For the current code there is usage of fields that will need alternatives to just using the Py_ prefix:

  • tp_name e.g. Py_TYPE(callable)->tp_name see: https://bugs.python.org/issue42035
  • tp_dict ?
  • tp_flags -> PyType_GetFlags
  • tp_basicsize PyType_Spec?
  • tp_as_number PyNumberMethods are only used in Python 2 blocks

@cas--
Copy link

cas-- commented Sep 4, 2021

@AllSeeingEyeTolledEweSew I am not sure whether discussing on the boost mailing lists might get more traction?

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

No branches or pull requests

4 participants