Skip to content

Commit

Permalink
Merge branch 'master' into rm_py37
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Jul 28, 2024
2 parents d255d63 + 8e7307f commit 5de1214
Show file tree
Hide file tree
Showing 34 changed files with 583 additions and 108 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ jobs:
fail-fast: false
matrix:
include:
- { gcc: 9, std: 20 }
- { gcc: 10, std: 17 }
- { gcc: 10, std: 20 }
- { gcc: 11, std: 20 }
- { gcc: 12, std: 20 }
- { gcc: 13, std: 20 }
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/emscripten.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: WASM

on:
workflow_dispatch:
pull_request:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-wasm-emscripten:
name: Pyodide wheel
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- uses: pypa/[email protected]
env:
PYODIDE_BUILD_EXPORTS: whole_archive
CFLAGS: -fexceptions
LDFLAGS: -fexceptions
with:
package-dir: tests
only: cp312-pyodide_wasm32
16 changes: 10 additions & 6 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,27 @@ jobs:
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
needs: [packaging]
environment: pypi
permissions:
id-token: write
attestations: write
contents: read

steps:
- uses: actions/setup-python@v5
with:
python-version: "3.x"

# Downloads all to directories matching the artifact names
- uses: actions/download-artifact@v4

- name: Generate artifact attestation for sdist and wheel
uses: actions/attest-build-provenance@5e9cb68e95676991667494a6a4e59b8a2f13e1d0 # v1.3.3
with:
subject-path: "*/pybind11*"

- name: Publish standard package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.pypi_password }}
packages-dir: standard/

- name: Publish global package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.pypi_password_global }}
packages-dir: global/
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ repos:

# Clang format the codebase automatically
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v18.1.5"
rev: "v18.1.8"
hooks:
- id: clang-format
types_or: [c++, c, cuda]

# Ruff, the Python auto-correcting linter/formatter written in Rust
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.7
rev: v0.5.0
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

# Check static types with mypy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.10.0"
rev: "v1.10.1"
hooks:
- id: mypy
args: []
Expand Down Expand Up @@ -79,7 +79,7 @@ repos:

# Also code format the docs
- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0"
rev: "1.18.0"
hooks:
- id: blacken-docs
additional_dependencies:
Expand Down Expand Up @@ -142,14 +142,14 @@ repos:

# PyLint has native support - not always usable, but works for us
- repo: https://github.com/PyCQA/pylint
rev: "v3.2.2"
rev: "v3.2.4"
hooks:
- id: pylint
files: ^pybind11

# Check schemas on some of our YAML files
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.4
rev: 0.28.6
hooks:
- id: check-readthedocs
- id: check-github-workflows
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ set(PYBIND11_HEADERS
include/pybind11/detail/internals.h
include/pybind11/detail/type_caster_base.h
include/pybind11/detail/typeid.h
include/pybind11/detail/value_and_holder.h
include/pybind11/attr.h
include/pybind11/buffer_info.h
include/pybind11/cast.h
Expand Down
115 changes: 115 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,121 @@ IN DEVELOPMENT

Changes will be summarized here periodically.

Version 2.13.1 (June 26, 2024)
------------------------------

New Features:

* Add support for ``Typing.Callable[..., T]``.
`#5202 <https://github.com/pybind/pybind11/pull/5202>`_

Bug fixes:

* Avoid aligned allocation in free-threaded build in order to support macOS
versions before 10.14.
`#5200 <https://github.com/pybind/pybind11/pull/5200>`_

Version 2.13.0 (June 25, 2024)
------------------------------

New Features:

* Support free-threaded CPython (3.13t). Add ``py::mod_gil_not_used()`` tag to
indicate if a module supports running with the GIL disabled.
`#5148 <https://github.com/pybind/pybind11/pull/5148>`_

* Support for Python 3.6 was removed. (Official end-of-life: 2021-12-23).
`#5177 <https://github.com/pybind/pybind11/pull/5177>`_

* ``py::list`` gained a ``.clear()`` method.
`#5153 <https://github.com/pybind/pybind11/pull/5153>`_


.. feat(types)
* Support for ``Union``, ``Optional``, ``type[T]``, ``typing.TypeGuard``,
``typing.TypeIs``, ``typing.Never``, ``typing.NoReturn`` and
``typing.Literal`` was added to ``pybind11/typing.h``.
`#5166 <https://github.com/pybind/pybind11/pull/5166>`_
`#5165 <https://github.com/pybind/pybind11/pull/5165>`_
`#5194 <https://github.com/pybind/pybind11/pull/5194>`_
`#5193 <https://github.com/pybind/pybind11/pull/5193>`_
`#5192 <https://github.com/pybind/pybind11/pull/5192>`_


.. feat(cmake)
* In CMake, if ``PYBIND11_USE_CROSSCOMPILING`` is enabled, then
``CMAKE_CROSSCOMPILING`` will be respected and will keep pybind11 from
accessing the interpreter during configuration. Several CMake variables will
be required in this case, but can be deduced from the environment variable
``SETUPTOOLS_EXT_SUFFIX``. The default (currently ``OFF``) may be changed in
the future.
`#5083 <https://github.com/pybind/pybind11/pull/5083>`_


Bug fixes:

* A refcount bug (leading to heap-use-after-free) involving trampoline
functions with ``PyObject *`` return type was fixed.
`#5156 <https://github.com/pybind/pybind11/pull/5156>`_

* Return ``py::ssize_t`` from ``.ref_count()`` instead of ``int``.
`#5139 <https://github.com/pybind/pybind11/pull/5139>`_

* A subtle bug involving C++ types with unusual ``operator&`` overrides
was fixed.
`#5189 <https://github.com/pybind/pybind11/pull/5189>`_

* Support Python 3.13 with minor fix, add to CI.
`#5127 <https://github.com/pybind/pybind11/pull/5127>`_


.. fix(cmake)
* Fix mistake affecting old cmake and old boost.
`#5149 <https://github.com/pybind/pybind11/pull/5149>`_


Documentation:

* Build docs updated to feature scikit-build-core and meson-python, and updated
setuptools instructions.
`#5168 <https://github.com/pybind/pybind11/pull/5168>`_


Tests:

* Avoid immortal objects in tests.
`#5150 <https://github.com/pybind/pybind11/pull/5150>`_


CI:

* Compile against Python 3.13t in CI.

* Use ``macos-13`` (Intel) for CI jobs for now (will drop Python 3.7 soon).
`#5109 <https://github.com/pybind/pybind11/pull/5109>`_

* Releases now have artifact attestations, visible at
https://github.com/pybind/pybind11/attestations.
`#5196 <https://github.com/pybind/pybind11/pull/5196>`_

Other:

* Some cleanup in preparation for 3.13 support.
`#5137 <https://github.com/pybind/pybind11/pull/5137>`_

* Avoid a warning by ensuring an iterator end check is included in release mode.
`#5129 <https://github.com/pybind/pybind11/pull/5129>`_

* Bump max cmake to 3.29.
`#5075 <https://github.com/pybind/pybind11/pull/5075>`_

* Update docs and noxfile.
`#5071 <https://github.com/pybind/pybind11/pull/5071>`_


Version 2.12.0 (March 27, 2024)
-------------------------------

Expand Down
4 changes: 0 additions & 4 deletions docs/limitations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ clean, well written patch would likely be accepted to solve them.
One consequence is that containers of ``char *`` are currently not supported.
`#2245 <https://github.com/pybind/pybind11/issues/2245>`_

- The ``cpptest`` does not run on Windows with Python 3.8 or newer, due to DLL
loader changes. User code that is correctly installed should not be affected.
`#2560 <https://github.com/pybind/pybind11/issue/2560>`_

Python 3.9.0 warning
^^^^^^^^^^^^^^^^^^^^

Expand Down
6 changes: 3 additions & 3 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ breathe==4.35.0 \
--hash=sha256:5165541c3c67b6c7adde8b3ecfe895c6f7844783c4076b6d8d287e4f33d62386 \
--hash=sha256:52c581f42ca4310737f9e435e3851c3d1f15446205a85fbc272f1f97ed74f5be
# via -r requirements.in
certifi==2024.2.2 \
--hash=sha256:0569859f95fc761b18b45ef421b1290a0f65f147e92a1e5eb3e635f9a5e4e66f \
--hash=sha256:dc383c07b76109f368f6106eee2b593b04a011ea4d55f652c6ca24a754d1cdd1
certifi==2024.7.4 \
--hash=sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b \
--hash=sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90
# via requests
charset-normalizer==3.3.2 \
--hash=sha256:06435b539f889b1f6f4ac1758871aae42dc3a8c0e24ac9e60c2384973ad73027 \
Expand Down
11 changes: 9 additions & 2 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,13 @@ class type_caster<std::pair<T1, T2>> : public tuple_caster<std::pair, T1, T2> {}
template <typename... Ts>
class type_caster<std::tuple<Ts...>> : public tuple_caster<std::tuple, Ts...> {};

template <>
class type_caster<std::tuple<>> : public tuple_caster<std::tuple> {
public:
// PEP 484 specifies this syntax for an empty tuple
static constexpr auto name = const_name("tuple[()]");
};

/// Helper class which abstracts away certain actions. Users can provide specializations for
/// custom holders, but it's only necessary if the type has a non-standard interface.
template <typename T>
Expand Down Expand Up @@ -787,11 +794,11 @@ struct copyable_holder_caster : public type_caster_base<type> {
}
}

bool load_value(value_and_holder &&v_h) {
void load_value(value_and_holder &&v_h) {
if (v_h.holder_constructed()) {
value = v_h.value_ptr();
holder = v_h.template holder<holder_type>();
return true;
return;
}
throw cast_error("Unable to cast from non-held to held instance (T& to Holder<T>) "
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
Expand Down
20 changes: 18 additions & 2 deletions include/pybind11/detail/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
#pragma once

#define PYBIND11_VERSION_MAJOR 2
#define PYBIND11_VERSION_MINOR 13
#define PYBIND11_VERSION_MINOR 14
#define PYBIND11_VERSION_PATCH 0.dev1

// Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html
// Additional convention: 0xD = dev
#define PYBIND11_VERSION_HEX 0x020D00D1
#define PYBIND11_VERSION_HEX 0x020E00D1

// Define some generic pybind11 helper macros for warning management.
//
Expand Down Expand Up @@ -462,6 +462,22 @@ PYBIND11_WARNING_POP
return "Hello, World!";
});
}
The third macro argument is optional (available since 2.13.0), and can be used to
mark the extension module as safe to run without the GIL under a free-threaded CPython
interpreter. Passing this argument has no effect on other interpreters.
.. code-block:: cpp
PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
m.doc() = "pybind11 example module safe to run without the GIL";
// Add bindings here
m.def("foo", []() {
return "Hello, Free-threaded World!";
});
}
\endrst */
#define PYBIND11_MODULE(name, variable, ...) \
static ::pybind11::module_::module_def PYBIND11_CONCAT(pybind11_module_def_, name) \
Expand Down
6 changes: 4 additions & 2 deletions include/pybind11/detail/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ void construct(value_and_holder &v_h, Cpp<Class> *ptr, bool need_alias) {
// the holder and destruction happens when we leave the C++ scope, and the holder
// class gets to handle the destruction however it likes.
v_h.value_ptr() = ptr;
v_h.set_instance_registered(true); // To prevent init_instance from registering it
v_h.type->init_instance(v_h.inst, nullptr); // Set up the holder
v_h.set_instance_registered(true); // Trick to prevent init_instance from registering it
// DANGER ZONE BEGIN: exceptions will leave v_h in an invalid state.
v_h.type->init_instance(v_h.inst, nullptr); // Set up the holder
Holder<Class> temp_holder(std::move(v_h.holder<Holder<Class>>())); // Steal the holder
v_h.type->dealloc(v_h); // Destroys the moved-out holder remains, resets value ptr to null
v_h.set_instance_registered(false);
// DANGER ZONE END.

construct_alias_from_cpp<Class>(is_alias_constructible<Class>{}, v_h, std::move(*ptr));
} else {
Expand Down
Loading

0 comments on commit 5de1214

Please sign in to comment.