Skip to content

Commit e80e57c

Browse files
committed
nanobind: upgraded to version 2.12.0.
1 parent 0c683b0 commit e80e57c

33 files changed

+311
-125
lines changed

extern/nanobind/cmake/nanobind-config.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,14 +500,16 @@ function(nanobind_sanitizer_preload_env env_var)
500500
get_target_property(options ${tgt} ${prop})
501501
if(options)
502502
foreach(opt ${options})
503-
if(opt MATCHES "-fsanitize=([^ ]+)")
503+
if(opt MATCHES "-fsanitize=([^ >]+)")
504504
list(APPEND san_flags "${CMAKE_MATCH_1}")
505505
endif()
506506
endforeach()
507507
endif()
508508
endforeach()
509509
endforeach()
510510

511+
list(REMOVE_DUPLICATES san_flags)
512+
511513
# Parse sanitizer flags
512514
foreach(flag ${san_flags})
513515
string(REPLACE "\"" "" flag "${flag}")
@@ -517,6 +519,8 @@ function(nanobind_sanitizer_preload_env env_var)
517519
list(APPEND detected_san "asan")
518520
elseif(san MATCHES "^(thread|tsan)$")
519521
list(APPEND detected_san "tsan")
522+
elseif(san MATCHES "^(realtime)$")
523+
list(APPEND detected_san "rtsan")
520524
elseif(san MATCHES "^(undefined|ubsan)$")
521525
list(APPEND detected_san "ubsan")
522526
endif()
@@ -525,7 +529,6 @@ function(nanobind_sanitizer_preload_env env_var)
525529
endforeach()
526530

527531
if (detected_san)
528-
list(REMOVE_DUPLICATES detected_san)
529532
set(libs "")
530533

531534
foreach(san ${detected_san})

extern/nanobind/docs/api_core.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,15 @@ Wrapper classes
12681268
// Now do something ...
12691269
});
12701270
1271+
.. cpp:class:: memoryview: public object
1272+
1273+
Wrapper class representing Python ``memoryview`` instances.
1274+
1275+
.. cpp:function:: memoryview(handle h)
1276+
1277+
Attempt to create a ``memoryview`` Python object from an object. Analogous
1278+
to the expression ``memoryview(h)`` in Python.
1279+
12711280
.. cpp:class:: ellipsis: public object
12721281

12731282
Wrapper class representing a Python ellipsis (``...``) object.
@@ -2641,8 +2650,8 @@ Class binding
26412650

26422651
Bind the enumeration of type `T` to the identifier `name` within the
26432652
scope `scope`. The variable length `extra` parameter can be used to pass
2644-
a docstring and other :ref:`enum binding annotations
2645-
<enum_binding_annotations>` (currently, only :cpp:class:`is_arithmetic` is supported).
2653+
a docstring and
2654+
:ref:`enum binding annotations <enum_binding_annotations>`.
26462655

26472656
.. cpp:function:: enum_ &value(const char * name, T value, const char * doc = nullptr)
26482657

extern/nanobind/docs/bazel.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ in your MODULE.bazel file:
2727
# Place this in your MODULE.bazel file.
2828
# The major version of nanobind-bazel is equal to the version
2929
# of the internally used nanobind.
30-
# In this case, we are building bindings with nanobind v2.11.0.
31-
bazel_dep(name = "nanobind_bazel", version = "2.11.0")
30+
# In this case, we are building bindings with nanobind v2.12.0.
31+
bazel_dep(name = "nanobind_bazel", version = "2.12.0")
3232
3333
To instead use a development version from GitHub, you can declare the
3434
dependency as a ``git_override()`` in your MODULE.bazel:

extern/nanobind/docs/changelog.rst

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@ case, both modules must use the same nanobind ABI version, or they will be
1515
isolated from each other. Releases that don't explicitly mention an ABI version
1616
below inherit that of the preceding release.
1717

18+
Version 2.12.0 (Feb 25, 2025)
19+
-----------------------------
20+
21+
- Added :cpp:class:`nb::memoryview` that wraps the Python ``memoryview`` type.
22+
(PR `#1291 <https://github.com/wjakob/nanobind/pull/1291>`__).
23+
24+
- Made stub generation compatible with the Realtime Sanitizer (RTSan)
25+
from Clang 20.
26+
(PR `#1285 <https://github.com/wjakob/nanobind/pull/1285>`__).
27+
28+
- Fixed a use-after-free when calling functions after their module has been
29+
deleted. The internals state is now reference-counted with references held by
30+
modules, functions, and types. This also fixes memory leaks reported in issue
31+
`#957 <https://github.com/wjakob/nanobind/issues/957>`__.
32+
(PR `#1287 <https://github.com/wjakob/nanobind/pull/1287>`__).
33+
34+
- Fixed two regressions from v2.11.0 related to the implicit ``std::optional``
35+
:cpp:func:`.none() <arg::none>` annotation: an off-by-one error that applied
36+
the annotation to the wrong argument for methods, and a missing ``convert``
37+
flag that silently disabled implicit type conversions.
38+
(issues `#1281 <https://github.com/wjakob/nanobind/issues/1281>`__,
39+
`#1293 <https://github.com/wjakob/nanobind/issues/1293>`__,
40+
commits `ed7ab31
41+
<https://github.com/wjakob/nanobind/commit/ed7ab31f5ffe313b2ca945573e29112ea5e475b2>`__,
42+
`1f96278
43+
<https://github.com/wjakob/nanobind/commit/1f96278c09ec1f7110105f5e2e3dbd2f08dc66a4>`__).
44+
45+
- ABI version 19.
46+
1847
Version 2.11.0 (Jan 29, 2026)
1948
-----------------------------
2049

@@ -92,7 +121,7 @@ Version 2.11.0 (Jan 29, 2026)
92121
(PR `#1255 <https://github.com/wjakob/nanobind/pull/1255>`__).
93122

94123
Version 2.10.2 (Dec 10, 2025)
95-
----------------------------
124+
-----------------------------
96125

97126
- Fixes a regression that broke compilation on 32-bit architectures.
98127
(PR `#1239 <https://github.com/wjakob/nanobind/pull/1239>`__).
@@ -564,7 +593,7 @@ Version 2.3.0
564593

565594
There is no version 2.3.0 due to a deployment mishap.
566595

567-
- Added casters for `Eigen::Map<Eigen::SparseMatrix<...>` types from the `Eigen library
596+
- Added casters for ``Eigen::Map<Eigen::SparseMatrix<...>>`` types from the `Eigen library
568597
<https://eigen.tuxfamily.org/index.php?title=Main_Page>`__. (PR `#782
569598
<https://github.com/wjakob/nanobind/pull/782>`_).
570599

extern/nanobind/docs/faq.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ build system compatible with another tool that is sufficiently
369369
feature-complete, then please file an issue and I am happy to reference it in
370370
the documentation.
371371

372+
Is there a way to pass ``JSON`` objects between Python and C++?
373+
-------------------------------------------------
374+
Yes, an unofficial, currently maintained, package supporting that can be found `here
375+
<https://github.com/Griger5/nanobind_json>`_. It is based on a similar package for
376+
``pybind11`` called ``pybind11_json``.
377+
372378
Are there tools to generate nanobind bindings automatically?
373379
------------------------------------------------------------
374380

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
furo
22
sphinx==6.1.3
33
sphinx-copybutton==0.5.1
4-
sphinxcontrib-moderncmakedomain==3.25.0
4+
sphinxcontrib-moderncmakedomain==3.29.0
55
sphinxcontrib-svg2pdfconverter==1.2.2

extern/nanobind/docs/why.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ would require a substantial redesign and years of careful work by a team of C++
247247
metaprogramming experts. At the same time, changing anything in pybind11 is
248248
extremely hard because of the large number of downstream users and their
249249
requirements on API/ABI stability. I personally don't have the time and energy
250-
to fix pybind11 and have moved my focus to this project. The `testimonials
251-
section
252-
<https://github.com/wjakob/nanobind/blob/master/README.md#testimonials>` lists
250+
to fix pybind11 and have moved my focus to this project. The `testimonials section
251+
<https://github.com/wjakob/nanobind/blob/master/README.md#testimonials>`__ lists
253252
the experience of a number of large projects that made the switch.

extern/nanobind/include/nanobind/nanobind.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@
2222
#endif
2323

2424
#define NB_VERSION_MAJOR 2
25-
#define NB_VERSION_MINOR 11
25+
#define NB_VERSION_MINOR 12
2626
#define NB_VERSION_PATCH 0
2727
#define NB_VERSION_DEV 0 // A value > 0 indicates a development release
2828

29+
// nb_python.h includes Python.h, which according to
30+
// https://docs.python.org/3/c-api/intro.html#include-files, must be included
31+
// before standard headers because it overrides feature test macros
32+
#include "nb_python.h"
33+
2934
// Core C++ headers that nanobind depends on
3035
#include <cstddef>
3136
#include <cstdint>
@@ -39,7 +44,6 @@
3944

4045
// Implementation. The nb_*.h files should only be included through nanobind.h
4146
// IWYU pragma: begin_exports
42-
#include "nb_python.h"
4347
#include "nb_defs.h"
4448
#include "nb_enums.h"
4549
#include "nb_traits.h"

extern/nanobind/include/nanobind/nb_attr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ NB_INLINE void func_extra_apply(F &f, const arg &a, size_t &index) {
328328
flag |= (uint8_t) cast_flags::convert;
329329

330330
arg_data &arg = f.args[index];
331-
arg.flag |= flag;
331+
arg.flag = flag;
332332
arg.name = a.name_;
333333
arg.signature = a.signature_;
334334
arg.value = nullptr;

extern/nanobind/include/nanobind/nb_defs.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@
169169
X(const X &) = delete; \
170170
X &operator=(const X &) = delete;
171171

172-
#define NB_MOD_STATE_SIZE (12 * sizeof(PyObject*))
173-
174172
// Helper macros to ensure macro arguments are expanded before token pasting/stringification
175173
#define NB_MODULE_IMPL(name, variable) NB_MODULE_IMPL2(name, variable)
176174
#define NB_MODULE_IMPL2(name, variable) \
@@ -196,9 +194,9 @@
196194
NB_MODULE_SLOTS_2 \
197195
}; \
198196
static struct PyModuleDef nanobind_##name##_module = { \
199-
PyModuleDef_HEAD_INIT, #name, nullptr, NB_MOD_STATE_SIZE, nullptr, \
200-
nanobind_##name##_slots, nanobind::detail::nb_module_traverse, \
201-
nanobind::detail::nb_module_clear, nanobind::detail::nb_module_free \
197+
PyModuleDef_HEAD_INIT, #name, nullptr, 0, nullptr, \
198+
nanobind_##name##_slots, nullptr, nullptr, \
199+
nanobind::detail::nb_module_free \
202200
}; \
203201
extern "C" [[maybe_unused]] NB_EXPORT PyObject *PyInit_##name(void); \
204202
extern "C" PyObject *PyInit_##name(void) { \

0 commit comments

Comments
 (0)