mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-31 23:30:30 +00:00
Merge branch 'master' into sh_merge_master
This commit is contained in:
commit
eb6edd9fac
58
.github/workflows/ci.yml
vendored
58
.github/workflows/ci.yml
vendored
@ -31,8 +31,8 @@ jobs:
|
|||||||
- '3.6'
|
- '3.6'
|
||||||
- '3.9'
|
- '3.9'
|
||||||
- '3.10'
|
- '3.10'
|
||||||
- 'pypy-3.7-v7.3.7'
|
- 'pypy-3.7'
|
||||||
- 'pypy-3.8-v7.3.7'
|
- 'pypy-3.8'
|
||||||
|
|
||||||
# Items in here will either be added to the build matrix (if not
|
# Items in here will either be added to the build matrix (if not
|
||||||
# present), or add new keys to an existing matrix element if all the
|
# present), or add new keys to an existing matrix element if all the
|
||||||
@ -756,6 +756,60 @@ jobs:
|
|||||||
- name: Python tests
|
- name: Python tests
|
||||||
run: cmake --build build -t pytest
|
run: cmake --build build -t pytest
|
||||||
|
|
||||||
|
win32-debug:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
python:
|
||||||
|
- 3.8
|
||||||
|
- 3.9
|
||||||
|
|
||||||
|
include:
|
||||||
|
- python: 3.9
|
||||||
|
args: -DCMAKE_CXX_STANDARD=20
|
||||||
|
- python: 3.8
|
||||||
|
args: -DCMAKE_CXX_STANDARD=17
|
||||||
|
|
||||||
|
name: "🐍 ${{ matrix.python }} • MSVC 2019 (Debug) • x86 ${{ matrix.args }}"
|
||||||
|
runs-on: windows-2019
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Python ${{ matrix.python }}
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python }}
|
||||||
|
architecture: x86
|
||||||
|
|
||||||
|
- name: Update CMake
|
||||||
|
uses: jwlawson/actions-setup-cmake@v1.12
|
||||||
|
|
||||||
|
- name: Prepare MSVC
|
||||||
|
uses: ilammy/msvc-dev-cmd@v1.10.0
|
||||||
|
with:
|
||||||
|
arch: x86
|
||||||
|
|
||||||
|
- name: Prepare env
|
||||||
|
run: |
|
||||||
|
python -m pip install -r tests/requirements.txt
|
||||||
|
|
||||||
|
# First build - C++11 mode and inplace
|
||||||
|
- name: Configure ${{ matrix.args }}
|
||||||
|
run: >
|
||||||
|
cmake -S . -B build
|
||||||
|
-G "Visual Studio 16 2019" -A Win32
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug
|
||||||
|
-DPYBIND11_WERROR=ON
|
||||||
|
-DDOWNLOAD_CATCH=ON
|
||||||
|
-DDOWNLOAD_EIGEN=ON
|
||||||
|
${{ matrix.args }}
|
||||||
|
- name: Build C++11
|
||||||
|
run: cmake --build build --config Debug -j 2
|
||||||
|
|
||||||
|
- name: Python tests
|
||||||
|
run: cmake --build build --config Debug -t pytest
|
||||||
|
|
||||||
win32-msvc2017:
|
win32-msvc2017:
|
||||||
name: "🐍 ${{ matrix.python }} • MSVC 2017 • x64"
|
name: "🐍 ${{ matrix.python }} • MSVC 2017 • x64"
|
||||||
runs-on: windows-2016
|
runs-on: windows-2016
|
||||||
|
@ -60,7 +60,7 @@ repos:
|
|||||||
|
|
||||||
# Changes tabs to spaces
|
# Changes tabs to spaces
|
||||||
- repo: https://github.com/Lucas-C/pre-commit-hooks
|
- repo: https://github.com/Lucas-C/pre-commit-hooks
|
||||||
rev: "v1.1.12"
|
rev: "v1.1.13"
|
||||||
hooks:
|
hooks:
|
||||||
- id: remove-tabs
|
- id: remove-tabs
|
||||||
exclude: (^docs/.*|\.patch)?$
|
exclude: (^docs/.*|\.patch)?$
|
||||||
@ -73,7 +73,7 @@ repos:
|
|||||||
|
|
||||||
# Autoremoves unused imports
|
# Autoremoves unused imports
|
||||||
- repo: https://github.com/hadialqattan/pycln
|
- repo: https://github.com/hadialqattan/pycln
|
||||||
rev: "v1.2.0"
|
rev: "v1.2.4"
|
||||||
hooks:
|
hooks:
|
||||||
- id: pycln
|
- id: pycln
|
||||||
|
|
||||||
|
@ -101,14 +101,14 @@ inline PyTypeObject *make_static_property_type() {
|
|||||||
inline PyTypeObject *make_static_property_type() {
|
inline PyTypeObject *make_static_property_type() {
|
||||||
auto d = dict();
|
auto d = dict();
|
||||||
PyObject *result = PyRun_String(R"(\
|
PyObject *result = PyRun_String(R"(\
|
||||||
class pybind11_static_property(property):
|
class pybind11_static_property(property):
|
||||||
def __get__(self, obj, cls):
|
def __get__(self, obj, cls):
|
||||||
return property.__get__(self, cls, cls)
|
return property.__get__(self, cls, cls)
|
||||||
|
|
||||||
def __set__(self, obj, value):
|
def __set__(self, obj, value):
|
||||||
cls = obj if isinstance(obj, type) else type(obj)
|
cls = obj if isinstance(obj, type) else type(obj)
|
||||||
property.__set__(self, cls, value)
|
property.__set__(self, cls, value)
|
||||||
)",
|
)",
|
||||||
Py_file_input,
|
Py_file_input,
|
||||||
d.ptr(),
|
d.ptr(),
|
||||||
d.ptr());
|
d.ptr());
|
||||||
|
@ -502,9 +502,10 @@ PYBIND11_NOINLINE std::string error_string() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyFrameObject *frame = trace->tb_frame;
|
PyFrameObject *frame = trace->tb_frame;
|
||||||
|
Py_XINCREF(frame);
|
||||||
errorString += "\n\nAt:\n";
|
errorString += "\n\nAt:\n";
|
||||||
while (frame) {
|
while (frame) {
|
||||||
# if PY_VERSION_HEX >= 0x03090000
|
# if PY_VERSION_HEX >= 0x030900B1
|
||||||
PyCodeObject *f_code = PyFrame_GetCode(frame);
|
PyCodeObject *f_code = PyFrame_GetCode(frame);
|
||||||
# else
|
# else
|
||||||
PyCodeObject *f_code = frame->f_code;
|
PyCodeObject *f_code = frame->f_code;
|
||||||
@ -514,8 +515,15 @@ PYBIND11_NOINLINE std::string error_string() {
|
|||||||
errorString += " " + handle(f_code->co_filename).cast<std::string>() + "("
|
errorString += " " + handle(f_code->co_filename).cast<std::string>() + "("
|
||||||
+ std::to_string(lineno)
|
+ std::to_string(lineno)
|
||||||
+ "): " + handle(f_code->co_name).cast<std::string>() + "\n";
|
+ "): " + handle(f_code->co_name).cast<std::string>() + "\n";
|
||||||
frame = frame->f_back;
|
|
||||||
Py_DECREF(f_code);
|
Py_DECREF(f_code);
|
||||||
|
# if PY_VERSION_HEX >= 0x030900B1
|
||||||
|
auto *b_frame = PyFrame_GetBack(frame);
|
||||||
|
# else
|
||||||
|
auto *b_frame = frame->f_back;
|
||||||
|
Py_XINCREF(b_frame);
|
||||||
|
# endif
|
||||||
|
Py_DECREF(frame);
|
||||||
|
frame = b_frame;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -82,7 +82,7 @@ template <eval_mode mode = eval_expr, size_t N>
|
|||||||
object eval(const char (&s)[N], object global = globals(), object local = object()) {
|
object eval(const char (&s)[N], object global = globals(), object local = object()) {
|
||||||
/* Support raw string literals by removing common leading whitespace */
|
/* Support raw string literals by removing common leading whitespace */
|
||||||
auto expr = (s[0] == '\n') ? str(module_::import("textwrap").attr("dedent")(s)) : str(s);
|
auto expr = (s[0] == '\n') ? str(module_::import("textwrap").attr("dedent")(s)) : str(s);
|
||||||
return eval<mode>(expr, global, local);
|
return eval<mode>(expr, std::move(global), std::move(local));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void exec(const str &expr, object global = globals(), object local = object()) {
|
inline void exec(const str &expr, object global = globals(), object local = object()) {
|
||||||
@ -91,7 +91,7 @@ inline void exec(const str &expr, object global = globals(), object local = obje
|
|||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
void exec(const char (&s)[N], object global = globals(), object local = object()) {
|
void exec(const char (&s)[N], object global = globals(), object local = object()) {
|
||||||
eval<eval_statements>(s, global, local);
|
eval<eval_statements>(s, std::move(global), std::move(local));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PYPY_VERSION)
|
#if defined(PYPY_VERSION)
|
||||||
|
@ -335,7 +335,7 @@ protected:
|
|||||||
const std::type_info *const *types,
|
const std::type_info *const *types,
|
||||||
size_t args) {
|
size_t args) {
|
||||||
// Do NOT receive `unique_rec` by value. If this function fails to move out the unique_ptr,
|
// Do NOT receive `unique_rec` by value. If this function fails to move out the unique_ptr,
|
||||||
// we do not want this to destuct the pointer. `initialize` (the caller) still relies on
|
// we do not want this to destruct the pointer. `initialize` (the caller) still relies on
|
||||||
// the pointee being alive after this call. Only move out if a `capsule` is going to keep
|
// the pointee being alive after this call. Only move out if a `capsule` is going to keep
|
||||||
// it alive.
|
// it alive.
|
||||||
auto *rec = unique_rec.get();
|
auto *rec = unique_rec.get();
|
||||||
@ -2739,9 +2739,7 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
|
|||||||
|
|
||||||
/* Don't call dispatch code if invoked from overridden function.
|
/* Don't call dispatch code if invoked from overridden function.
|
||||||
Unfortunately this doesn't work on PyPy. */
|
Unfortunately this doesn't work on PyPy. */
|
||||||
#if !defined(PYPY_VERSION) && PY_VERSION_HEX < 0x030B0000
|
#if !defined(PYPY_VERSION)
|
||||||
// TODO: Remove PyPy workaround for Python 3.11.
|
|
||||||
// Current API fails on 3.11 since co_varnames can be null.
|
|
||||||
# if PY_VERSION_HEX >= 0x03090000
|
# if PY_VERSION_HEX >= 0x03090000
|
||||||
PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get());
|
PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get());
|
||||||
if (frame != nullptr) {
|
if (frame != nullptr) {
|
||||||
@ -2749,9 +2747,11 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
|
|||||||
// f_code is guaranteed to not be NULL
|
// f_code is guaranteed to not be NULL
|
||||||
if ((std::string) str(f_code->co_name) == name && f_code->co_argcount > 0) {
|
if ((std::string) str(f_code->co_name) == name && f_code->co_argcount > 0) {
|
||||||
PyObject *locals = PyEval_GetLocals();
|
PyObject *locals = PyEval_GetLocals();
|
||||||
if (locals != nullptr && f_code->co_varnames != nullptr) {
|
if (locals != nullptr) {
|
||||||
PyObject *self_caller
|
PyObject *co_varnames = PyObject_GetAttrString((PyObject *) f_code, "co_varnames");
|
||||||
= dict_getitem(locals, PyTuple_GET_ITEM(f_code->co_varnames, 0));
|
PyObject *self_arg = PyTuple_GET_ITEM(co_varnames, 0);
|
||||||
|
Py_DECREF(co_varnames);
|
||||||
|
PyObject *self_caller = dict_getitem(locals, self_arg);
|
||||||
if (self_caller == self.ptr()) {
|
if (self_caller == self.ptr()) {
|
||||||
Py_DECREF(f_code);
|
Py_DECREF(f_code);
|
||||||
Py_DECREF(frame);
|
Py_DECREF(frame);
|
||||||
@ -2797,9 +2797,9 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
|
|||||||
d.ptr());
|
d.ptr());
|
||||||
if (result == nullptr)
|
if (result == nullptr)
|
||||||
throw error_already_set();
|
throw error_already_set();
|
||||||
|
Py_DECREF(result);
|
||||||
if (d["self"].is_none())
|
if (d["self"].is_none())
|
||||||
return function();
|
return function();
|
||||||
Py_DECREF(result);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return override;
|
return override;
|
||||||
|
@ -2,6 +2,7 @@ import os
|
|||||||
|
|
||||||
import nox
|
import nox
|
||||||
|
|
||||||
|
nox.needs_version = ">=2022.1.7"
|
||||||
nox.options.sessions = ["lint", "tests", "tests_packaging"]
|
nox.options.sessions = ["lint", "tests", "tests_packaging"]
|
||||||
|
|
||||||
PYTHON_VERISONS = ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.7", "pypy3.8"]
|
PYTHON_VERISONS = ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.7", "pypy3.8"]
|
||||||
@ -29,14 +30,12 @@ def tests(session: nox.Session) -> None:
|
|||||||
session.install("-r", "tests/requirements.txt")
|
session.install("-r", "tests/requirements.txt")
|
||||||
session.run(
|
session.run(
|
||||||
"cmake",
|
"cmake",
|
||||||
"-S",
|
"-S.",
|
||||||
".",
|
f"-B{tmpdir}",
|
||||||
"-B",
|
|
||||||
tmpdir,
|
|
||||||
"-DPYBIND11_WERROR=ON",
|
"-DPYBIND11_WERROR=ON",
|
||||||
"-DDOWNLOAD_CATCH=ON",
|
"-DDOWNLOAD_CATCH=ON",
|
||||||
"-DDOWNLOAD_EIGEN=ON",
|
"-DDOWNLOAD_EIGEN=ON",
|
||||||
*session.posargs
|
*session.posargs,
|
||||||
)
|
)
|
||||||
session.run("cmake", "--build", tmpdir)
|
session.run("cmake", "--build", tmpdir)
|
||||||
session.run("cmake", "--build", tmpdir, "--config=Release", "--target", "check")
|
session.run("cmake", "--build", tmpdir, "--config=Release", "--target", "check")
|
||||||
|
@ -112,11 +112,24 @@ endif()
|
|||||||
# VERSION. VERSION will typically be like "2.7" on unix, and "27" on windows.
|
# VERSION. VERSION will typically be like "2.7" on unix, and "27" on windows.
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND
|
COMMAND
|
||||||
"${PYTHON_EXECUTABLE}" "-c" "from distutils import sysconfig as s;import sys;import struct;
|
"${PYTHON_EXECUTABLE}" "-c" "
|
||||||
|
import sys;import struct;
|
||||||
|
import sysconfig as s
|
||||||
|
USE_SYSCONFIG = sys.version_info >= (3, 10)
|
||||||
|
if not USE_SYSCONFIG:
|
||||||
|
from distutils import sysconfig as ds
|
||||||
print('.'.join(str(v) for v in sys.version_info));
|
print('.'.join(str(v) for v in sys.version_info));
|
||||||
print(sys.prefix);
|
print(sys.prefix);
|
||||||
print(s.get_python_inc(plat_specific=True));
|
if USE_SYSCONFIG:
|
||||||
print(s.get_python_lib(plat_specific=True));
|
scheme = s.get_default_scheme()
|
||||||
|
if scheme == 'posix_local':
|
||||||
|
# Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/
|
||||||
|
scheme = 'posix_prefix'
|
||||||
|
print(s.get_path('platinclude', scheme))
|
||||||
|
print(s.get_path('platlib'))
|
||||||
|
else:
|
||||||
|
print(ds.get_python_inc(plat_specific=True));
|
||||||
|
print(ds.get_python_lib(plat_specific=True));
|
||||||
print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'));
|
print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'));
|
||||||
print(hasattr(sys, 'gettotalrefcount')+0);
|
print(hasattr(sys, 'gettotalrefcount')+0);
|
||||||
print(struct.calcsize('@P'));
|
print(struct.calcsize('@P'));
|
||||||
|
Loading…
Reference in New Issue
Block a user