pybind11/6cb584e9de6e8d54f5576c299a308f89bfdcb519.patch
2019-10-08 18:50:20 +02:00

82 lines
3.0 KiB
Diff

From 6cb584e9de6e8d54f5576c299a308f89bfdcb519 Mon Sep 17 00:00:00 2001
From: Sergei Izmailov <sergei.a.izmailov@gmail.com>
Date: Tue, 8 Oct 2019 19:25:09 +0300
Subject: [PATCH] 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
---
.travis.yml | 27 +++++++++++++++++++++++++++
include/pybind11/detail/class.h | 6 ++++++
2 files changed, 33 insertions(+)
diff --git a/.travis.yml b/.travis.yml
index 381148e04..28f35f995 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -106,6 +106,33 @@ matrix:
- lld-7
- libc++-7-dev
- 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
name: Python 2.7, c++14, AppleClang 7.3, CMake test
osx_image: xcode7.3
diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h
index ffdfefe74..230ae81ae 100644
--- a/include/pybind11/detail/class.h
+++ b/include/pybind11/detail/class.h
@@ -350,6 +350,7 @@ extern "C" inline void pybind11_object_dealloc(PyObject *self) {
auto type = Py_TYPE(self);
type->tp_free(self);
+#if PY_VERSION_HEX < 0x03080000
// `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
// 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;
if (type->tp_dealloc == pybind11_object_type->tp_dealloc)
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