Adapt to python3.8 C API change (#1950)

* Adapt to python3.8 C API change

Do `Py_DECREF(type)` on all python objects on deallocation

fix #1946

* Add bare python3.8 build to CI matrix

While numpy/scipy wheels are available, run python3.8 test without them
This commit is contained in:
Sergei Izmailov 2019-10-08 19:25:09 +03:00 committed by Wenzel Jakob
parent 96be2c154f
commit 6cb584e9de
2 changed files with 33 additions and 0 deletions

View File

@ -106,6 +106,33 @@ matrix:
- lld-7 - lld-7
- libc++-7-dev - libc++-7-dev
- libc++abi-7-dev # Why is this necessary??? - libc++abi-7-dev # Why is this necessary???
- os: linux
dist: xenial
env: PYTHON=3.8 CPP=17 GCC=7
name: Python 3.8, c++17, gcc 7 (w/o numpy/scipy) # TODO: update build name when the numpy/scipy wheels become available
addons:
apt:
sources:
- deadsnakes
- ubuntu-toolchain-r-test
packages:
- g++-7
- python3.8-dev
- python3.8-venv
# Currently there is no numpy/scipy wheels available for python3.8
# TODO: remove next before_install, install and script clause when the wheels become available
before_install:
- pyenv global $(pyenv whence 2to3) # activate all python versions
- PY_CMD=python3
- $PY_CMD -m pip install --user --upgrade pip wheel setuptools
install:
- $PY_CMD -m pip install --user --upgrade pytest
script:
- |
# Barebones build
cmake -DCMAKE_BUILD_TYPE=Debug -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DPYTHON_EXECUTABLE=$(which $PY_CMD) .
make pytest -j 2
make cpptest -j 2
- os: osx - os: osx
name: Python 2.7, c++14, AppleClang 7.3, CMake test name: Python 2.7, c++14, AppleClang 7.3, CMake test
osx_image: xcode7.3 osx_image: xcode7.3

View File

@ -350,6 +350,7 @@ extern "C" inline void pybind11_object_dealloc(PyObject *self) {
auto type = Py_TYPE(self); auto type = Py_TYPE(self);
type->tp_free(self); type->tp_free(self);
#if PY_VERSION_HEX < 0x03080000
// `type->tp_dealloc != pybind11_object_dealloc` means that we're being called // `type->tp_dealloc != pybind11_object_dealloc` means that we're being called
// as part of a derived type's dealloc, in which case we're not allowed to decref // as part of a derived type's dealloc, in which case we're not allowed to decref
// the type here. For cross-module compatibility, we shouldn't compare directly // the type here. For cross-module compatibility, we shouldn't compare directly
@ -357,6 +358,11 @@ extern "C" inline void pybind11_object_dealloc(PyObject *self) {
auto pybind11_object_type = (PyTypeObject *) get_internals().instance_base; auto pybind11_object_type = (PyTypeObject *) get_internals().instance_base;
if (type->tp_dealloc == pybind11_object_type->tp_dealloc) if (type->tp_dealloc == pybind11_object_type->tp_dealloc)
Py_DECREF(type); Py_DECREF(type);
#else
// This was not needed before Python 3.8 (Python issue 35810)
// https://github.com/pybind/pybind11/issues/1946
Py_DECREF(type);
#endif
} }
/** Create the type which can be used as a common base for all classes. This is /** Create the type which can be used as a common base for all classes. This is