Skip to content

Commit eb6edd9

Browse files
committed
Merge branch 'master' into sh_merge_master
2 parents 4c4b33f + d75b353 commit eb6edd9

File tree

8 files changed

+106
-32
lines changed

8 files changed

+106
-32
lines changed

.github/workflows/ci.yml

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ jobs:
3131
- '3.6'
3232
- '3.9'
3333
- '3.10'
34-
- 'pypy-3.7-v7.3.7'
35-
- 'pypy-3.8-v7.3.7'
34+
- 'pypy-3.7'
35+
- 'pypy-3.8'
3636

3737
# Items in here will either be added to the build matrix (if not
3838
# present), or add new keys to an existing matrix element if all the
@@ -756,6 +756,60 @@ jobs:
756756
- name: Python tests
757757
run: cmake --build build -t pytest
758758

759+
win32-debug:
760+
strategy:
761+
fail-fast: false
762+
matrix:
763+
python:
764+
- 3.8
765+
- 3.9
766+
767+
include:
768+
- python: 3.9
769+
args: -DCMAKE_CXX_STANDARD=20
770+
- python: 3.8
771+
args: -DCMAKE_CXX_STANDARD=17
772+
773+
name: "🐍 ${{ matrix.python }} • MSVC 2019 (Debug) • x86 ${{ matrix.args }}"
774+
runs-on: windows-2019
775+
776+
steps:
777+
- uses: actions/checkout@v2
778+
779+
- name: Setup Python ${{ matrix.python }}
780+
uses: actions/setup-python@v2
781+
with:
782+
python-version: ${{ matrix.python }}
783+
architecture: x86
784+
785+
- name: Update CMake
786+
uses: jwlawson/[email protected]
787+
788+
- name: Prepare MSVC
789+
uses: ilammy/[email protected]
790+
with:
791+
arch: x86
792+
793+
- name: Prepare env
794+
run: |
795+
python -m pip install -r tests/requirements.txt
796+
797+
# First build - C++11 mode and inplace
798+
- name: Configure ${{ matrix.args }}
799+
run: >
800+
cmake -S . -B build
801+
-G "Visual Studio 16 2019" -A Win32
802+
-DCMAKE_BUILD_TYPE=Debug
803+
-DPYBIND11_WERROR=ON
804+
-DDOWNLOAD_CATCH=ON
805+
-DDOWNLOAD_EIGEN=ON
806+
${{ matrix.args }}
807+
- name: Build C++11
808+
run: cmake --build build --config Debug -j 2
809+
810+
- name: Python tests
811+
run: cmake --build build --config Debug -t pytest
812+
759813
win32-msvc2017:
760814
name: "🐍 ${{ matrix.python }} • MSVC 2017 • x64"
761815
runs-on: windows-2016

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ repos:
6060

6161
# Changes tabs to spaces
6262
- repo: https://github.com/Lucas-C/pre-commit-hooks
63-
rev: "v1.1.12"
63+
rev: "v1.1.13"
6464
hooks:
6565
- id: remove-tabs
6666
exclude: (^docs/.*|\.patch)?$
@@ -73,7 +73,7 @@ repos:
7373

7474
# Autoremoves unused imports
7575
- repo: https://github.com/hadialqattan/pycln
76-
rev: "v1.2.0"
76+
rev: "v1.2.4"
7777
hooks:
7878
- id: pycln
7979

include/pybind11/detail/class.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ inline PyTypeObject *make_static_property_type() {
101101
inline PyTypeObject *make_static_property_type() {
102102
auto d = dict();
103103
PyObject *result = PyRun_String(R"(\
104-
class pybind11_static_property(property):
105-
def __get__(self, obj, cls):
106-
return property.__get__(self, cls, cls)
107-
108-
def __set__(self, obj, value):
109-
cls = obj if isinstance(obj, type) else type(obj)
110-
property.__set__(self, cls, value)
111-
)",
104+
class pybind11_static_property(property):
105+
def __get__(self, obj, cls):
106+
return property.__get__(self, cls, cls)
107+
108+
def __set__(self, obj, value):
109+
cls = obj if isinstance(obj, type) else type(obj)
110+
property.__set__(self, cls, value)
111+
)",
112112
Py_file_input,
113113
d.ptr(),
114114
d.ptr());

include/pybind11/detail/type_caster_base.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,10 @@ PYBIND11_NOINLINE std::string error_string() {
502502
}
503503

504504
PyFrameObject *frame = trace->tb_frame;
505+
Py_XINCREF(frame);
505506
errorString += "\n\nAt:\n";
506507
while (frame) {
507-
# if PY_VERSION_HEX >= 0x03090000
508+
# if PY_VERSION_HEX >= 0x030900B1
508509
PyCodeObject *f_code = PyFrame_GetCode(frame);
509510
# else
510511
PyCodeObject *f_code = frame->f_code;
@@ -514,8 +515,15 @@ PYBIND11_NOINLINE std::string error_string() {
514515
errorString += " " + handle(f_code->co_filename).cast<std::string>() + "("
515516
+ std::to_string(lineno)
516517
+ "): " + handle(f_code->co_name).cast<std::string>() + "\n";
517-
frame = frame->f_back;
518518
Py_DECREF(f_code);
519+
# if PY_VERSION_HEX >= 0x030900B1
520+
auto *b_frame = PyFrame_GetBack(frame);
521+
# else
522+
auto *b_frame = frame->f_back;
523+
Py_XINCREF(b_frame);
524+
# endif
525+
Py_DECREF(frame);
526+
frame = b_frame;
519527
}
520528
}
521529
#endif

include/pybind11/eval.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ template <eval_mode mode = eval_expr, size_t N>
8282
object eval(const char (&s)[N], object global = globals(), object local = object()) {
8383
/* Support raw string literals by removing common leading whitespace */
8484
auto expr = (s[0] == '\n') ? str(module_::import("textwrap").attr("dedent")(s)) : str(s);
85-
return eval<mode>(expr, global, local);
85+
return eval<mode>(expr, std::move(global), std::move(local));
8686
}
8787

8888
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
9191

9292
template <size_t N>
9393
void exec(const char (&s)[N], object global = globals(), object local = object()) {
94-
eval<eval_statements>(s, global, local);
94+
eval<eval_statements>(s, std::move(global), std::move(local));
9595
}
9696

9797
#if defined(PYPY_VERSION)

include/pybind11/pybind11.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class cpp_function : public function {
335335
const std::type_info *const *types,
336336
size_t args) {
337337
// Do NOT receive `unique_rec` by value. If this function fails to move out the unique_ptr,
338-
// we do not want this to destuct the pointer. `initialize` (the caller) still relies on
338+
// we do not want this to destruct the pointer. `initialize` (the caller) still relies on
339339
// the pointee being alive after this call. Only move out if a `capsule` is going to keep
340340
// it alive.
341341
auto *rec = unique_rec.get();
@@ -2739,19 +2739,19 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
27392739

27402740
/* Don't call dispatch code if invoked from overridden function.
27412741
Unfortunately this doesn't work on PyPy. */
2742-
#if !defined(PYPY_VERSION) && PY_VERSION_HEX < 0x030B0000
2743-
// TODO: Remove PyPy workaround for Python 3.11.
2744-
// Current API fails on 3.11 since co_varnames can be null.
2742+
#if !defined(PYPY_VERSION)
27452743
# if PY_VERSION_HEX >= 0x03090000
27462744
PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get());
27472745
if (frame != nullptr) {
27482746
PyCodeObject *f_code = PyFrame_GetCode(frame);
27492747
// f_code is guaranteed to not be NULL
27502748
if ((std::string) str(f_code->co_name) == name && f_code->co_argcount > 0) {
27512749
PyObject *locals = PyEval_GetLocals();
2752-
if (locals != nullptr && f_code->co_varnames != nullptr) {
2753-
PyObject *self_caller
2754-
= dict_getitem(locals, PyTuple_GET_ITEM(f_code->co_varnames, 0));
2750+
if (locals != nullptr) {
2751+
PyObject *co_varnames = PyObject_GetAttrString((PyObject *) f_code, "co_varnames");
2752+
PyObject *self_arg = PyTuple_GET_ITEM(co_varnames, 0);
2753+
Py_DECREF(co_varnames);
2754+
PyObject *self_caller = dict_getitem(locals, self_arg);
27552755
if (self_caller == self.ptr()) {
27562756
Py_DECREF(f_code);
27572757
Py_DECREF(frame);
@@ -2797,9 +2797,9 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
27972797
d.ptr());
27982798
if (result == nullptr)
27992799
throw error_already_set();
2800+
Py_DECREF(result);
28002801
if (d["self"].is_none())
28012802
return function();
2802-
Py_DECREF(result);
28032803
#endif
28042804

28052805
return override;

noxfile.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import nox
44

5+
nox.needs_version = ">=2022.1.7"
56
nox.options.sessions = ["lint", "tests", "tests_packaging"]
67

78
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:
2930
session.install("-r", "tests/requirements.txt")
3031
session.run(
3132
"cmake",
32-
"-S",
33-
".",
34-
"-B",
35-
tmpdir,
33+
"-S.",
34+
f"-B{tmpdir}",
3635
"-DPYBIND11_WERROR=ON",
3736
"-DDOWNLOAD_CATCH=ON",
3837
"-DDOWNLOAD_EIGEN=ON",
39-
*session.posargs
38+
*session.posargs,
4039
)
4140
session.run("cmake", "--build", tmpdir)
4241
session.run("cmake", "--build", tmpdir, "--config=Release", "--target", "check")

tools/FindPythonLibsNew.cmake

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,24 @@ endif()
112112
# VERSION. VERSION will typically be like "2.7" on unix, and "27" on windows.
113113
execute_process(
114114
COMMAND
115-
"${PYTHON_EXECUTABLE}" "-c" "from distutils import sysconfig as s;import sys;import struct;
115+
"${PYTHON_EXECUTABLE}" "-c" "
116+
import sys;import struct;
117+
import sysconfig as s
118+
USE_SYSCONFIG = sys.version_info >= (3, 10)
119+
if not USE_SYSCONFIG:
120+
from distutils import sysconfig as ds
116121
print('.'.join(str(v) for v in sys.version_info));
117122
print(sys.prefix);
118-
print(s.get_python_inc(plat_specific=True));
119-
print(s.get_python_lib(plat_specific=True));
123+
if USE_SYSCONFIG:
124+
scheme = s.get_default_scheme()
125+
if scheme == 'posix_local':
126+
# Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/
127+
scheme = 'posix_prefix'
128+
print(s.get_path('platinclude', scheme))
129+
print(s.get_path('platlib'))
130+
else:
131+
print(ds.get_python_inc(plat_specific=True));
132+
print(ds.get_python_lib(plat_specific=True));
120133
print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'));
121134
print(hasattr(sys, 'gettotalrefcount')+0);
122135
print(struct.calcsize('@P'));

0 commit comments

Comments
 (0)