Skip to content

Commit 6cb584e

Browse files
sizmailovwjakob
authored andcommitted
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
1 parent 96be2c1 commit 6cb584e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

.travis.yml

+27
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,33 @@ matrix:
106106
- lld-7
107107
- libc++-7-dev
108108
- libc++abi-7-dev # Why is this necessary???
109+
- os: linux
110+
dist: xenial
111+
env: PYTHON=3.8 CPP=17 GCC=7
112+
name: Python 3.8, c++17, gcc 7 (w/o numpy/scipy) # TODO: update build name when the numpy/scipy wheels become available
113+
addons:
114+
apt:
115+
sources:
116+
- deadsnakes
117+
- ubuntu-toolchain-r-test
118+
packages:
119+
- g++-7
120+
- python3.8-dev
121+
- python3.8-venv
122+
# Currently there is no numpy/scipy wheels available for python3.8
123+
# TODO: remove next before_install, install and script clause when the wheels become available
124+
before_install:
125+
- pyenv global $(pyenv whence 2to3) # activate all python versions
126+
- PY_CMD=python3
127+
- $PY_CMD -m pip install --user --upgrade pip wheel setuptools
128+
install:
129+
- $PY_CMD -m pip install --user --upgrade pytest
130+
script:
131+
- |
132+
# Barebones build
133+
cmake -DCMAKE_BUILD_TYPE=Debug -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DPYTHON_EXECUTABLE=$(which $PY_CMD) .
134+
make pytest -j 2
135+
make cpptest -j 2
109136
- os: osx
110137
name: Python 2.7, c++14, AppleClang 7.3, CMake test
111138
osx_image: xcode7.3

include/pybind11/detail/class.h

+6
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,19 @@ extern "C" inline void pybind11_object_dealloc(PyObject *self) {
350350
auto type = Py_TYPE(self);
351351
type->tp_free(self);
352352

353+
#if PY_VERSION_HEX < 0x03080000
353354
// `type->tp_dealloc != pybind11_object_dealloc` means that we're being called
354355
// as part of a derived type's dealloc, in which case we're not allowed to decref
355356
// the type here. For cross-module compatibility, we shouldn't compare directly
356357
// with `pybind11_object_dealloc`, but with the common one stashed in internals.
357358
auto pybind11_object_type = (PyTypeObject *) get_internals().instance_base;
358359
if (type->tp_dealloc == pybind11_object_type->tp_dealloc)
359360
Py_DECREF(type);
361+
#else
362+
// This was not needed before Python 3.8 (Python issue 35810)
363+
// https://github.com/pybind/pybind11/issues/1946
364+
Py_DECREF(type);
365+
#endif
360366
}
361367

362368
/** Create the type which can be used as a common base for all classes. This is

0 commit comments

Comments
 (0)