netgen-mesher 6.2.2505.post48.dev0__cp313-cp313-win_amd64.whl → 6.2.2506.post48.dev0__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. netgen/__init__.pyi +3 -3
  2. netgen/cmake/NetgenConfig.cmake +9 -8
  3. netgen/config/__init__.pyi +7 -7
  4. netgen/config/config.py +6 -6
  5. netgen/config/config.pyi +7 -7
  6. netgen/include/core/archive.hpp +18 -3
  7. netgen/include/core/array.hpp +20 -4
  8. netgen/include/core/autodiff.hpp +9 -11
  9. netgen/include/core/autodiffdiff.hpp +0 -2
  10. netgen/include/core/bitarray.hpp +1 -1
  11. netgen/include/core/flags.hpp +1 -1
  12. netgen/include/core/hashtable.hpp +1 -1
  13. netgen/include/core/memtracer.hpp +7 -7
  14. netgen/include/core/ngcore.hpp +5 -0
  15. netgen/include/core/ngcore_api.hpp +11 -0
  16. netgen/include/core/register_archive.hpp +8 -0
  17. netgen/include/core/simd_arm64.hpp +100 -5
  18. netgen/include/core/simd_generic.hpp +187 -6
  19. netgen/include/core/simd_math.hpp +3 -2
  20. netgen/include/core/statushandler.hpp +37 -0
  21. netgen/include/core/table.hpp +2 -2
  22. netgen/include/core/taskmanager.hpp +34 -1
  23. netgen/include/include/netgen_version.hpp +3 -3
  24. netgen/include/meshing/basegeom.hpp +1 -4
  25. netgen/include/meshing/global.hpp +0 -17
  26. netgen/include/meshing/hpref_tet.hpp +41 -0
  27. netgen/include/meshing/hprefinement.hpp +2 -0
  28. netgen/include/meshing/meshtype.hpp +1 -0
  29. netgen/include/meshing/msghandler.hpp +9 -6
  30. netgen/include/meshing/topology.hpp +2 -2
  31. netgen/include/nginterface.h +3 -2
  32. netgen/include/occ/occ_utils.hpp +26 -0
  33. netgen/include/occ/occgeom.hpp +8 -0
  34. netgen/include/pybind11/attr.h +40 -8
  35. netgen/include/pybind11/buffer_info.h +14 -14
  36. netgen/include/pybind11/cast.h +553 -29
  37. netgen/include/pybind11/chrono.h +4 -1
  38. netgen/include/pybind11/conduit/README.txt +15 -0
  39. netgen/include/pybind11/conduit/pybind11_conduit_v1.h +116 -0
  40. netgen/include/pybind11/conduit/pybind11_platform_abi_id.h +87 -0
  41. netgen/include/pybind11/conduit/wrap_include_python_h.h +72 -0
  42. netgen/include/pybind11/critical_section.h +56 -0
  43. netgen/include/pybind11/detail/class.h +172 -97
  44. netgen/include/pybind11/detail/common.h +270 -189
  45. netgen/include/pybind11/detail/cpp_conduit.h +75 -0
  46. netgen/include/pybind11/detail/descr.h +55 -0
  47. netgen/include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h +39 -0
  48. netgen/include/pybind11/detail/exception_translation.h +71 -0
  49. netgen/include/pybind11/detail/function_record_pyobject.h +191 -0
  50. netgen/include/pybind11/detail/init.h +113 -9
  51. netgen/include/pybind11/detail/internals.h +479 -344
  52. netgen/include/pybind11/detail/native_enum_data.h +209 -0
  53. netgen/include/pybind11/detail/pybind11_namespace_macros.h +82 -0
  54. netgen/include/pybind11/detail/struct_smart_holder.h +378 -0
  55. netgen/include/pybind11/detail/type_caster_base.h +506 -133
  56. netgen/include/pybind11/detail/using_smart_holder.h +22 -0
  57. netgen/include/pybind11/detail/value_and_holder.h +90 -0
  58. netgen/include/pybind11/eigen/matrix.h +19 -10
  59. netgen/include/pybind11/eigen/tensor.h +15 -11
  60. netgen/include/pybind11/embed.h +50 -46
  61. netgen/include/pybind11/eval.h +11 -6
  62. netgen/include/pybind11/functional.h +58 -49
  63. netgen/include/pybind11/gil.h +34 -82
  64. netgen/include/pybind11/gil_safe_call_once.h +12 -1
  65. netgen/include/pybind11/gil_simple.h +37 -0
  66. netgen/include/pybind11/native_enum.h +67 -0
  67. netgen/include/pybind11/numpy.h +272 -93
  68. netgen/include/pybind11/pybind11.h +947 -265
  69. netgen/include/pybind11/pytypes.h +127 -21
  70. netgen/include/pybind11/stl/filesystem.h +23 -25
  71. netgen/include/pybind11/stl.h +277 -59
  72. netgen/include/pybind11/stl_bind.h +42 -7
  73. netgen/include/pybind11/subinterpreter.h +299 -0
  74. netgen/include/pybind11/trampoline_self_life_support.h +65 -0
  75. netgen/include/pybind11/typing.h +177 -4
  76. netgen/include/pybind11/warnings.h +75 -0
  77. netgen/lib/libnggui.lib +0 -0
  78. netgen/lib/ngcore.lib +0 -0
  79. netgen/lib/nglib.lib +0 -0
  80. netgen/libnggui.dll +0 -0
  81. netgen/libngguipy.pyd +0 -0
  82. netgen/libngpy/_NgOCC.pyi +220 -141
  83. netgen/libngpy/_csg.pyi +26 -26
  84. netgen/libngpy/_geom2d.pyi +34 -25
  85. netgen/libngpy/_meshing.pyi +262 -111
  86. netgen/libngpy/_stl.pyi +3 -4
  87. netgen/libngpy.pyd +0 -0
  88. netgen/ngcore.dll +0 -0
  89. netgen/nglib.dll +0 -0
  90. netgen/read_gmsh.py +41 -0
  91. netgen/togl.dll +0 -0
  92. netgen/version.py +1 -1
  93. netgen/webgui.py +38 -2
  94. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/METADATA +2 -1
  95. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/RECORD +144 -124
  96. pyngcore/pyngcore.cp313-win_amd64.pyd +0 -0
  97. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/boundarycondition.geo +0 -0
  98. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/boxcyl.geo +0 -0
  99. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/circle_on_cube.geo +0 -0
  100. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cone.geo +0 -0
  101. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cube.geo +0 -0
  102. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubeandring.geo +0 -0
  103. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubeandspheres.geo +0 -0
  104. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubemcyl.geo +0 -0
  105. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubemsphere.geo +0 -0
  106. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cylinder.geo +0 -0
  107. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cylsphere.geo +0 -0
  108. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/doc/ng4.pdf +0 -0
  109. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ellipsoid.geo +0 -0
  110. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ellipticcyl.geo +0 -0
  111. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/extrusion.geo +0 -0
  112. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/fichera.geo +0 -0
  113. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/frame.step +0 -0
  114. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/hinge.stl +0 -0
  115. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/lshape3d.geo +0 -0
  116. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/manyholes.geo +0 -0
  117. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/manyholes2.geo +0 -0
  118. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/matrix.geo +0 -0
  119. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ortho.geo +0 -0
  120. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/part1.stl +0 -0
  121. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/period.geo +0 -0
  122. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/py_tutorials/exportNeutral.py +0 -0
  123. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/py_tutorials/mesh.py +0 -0
  124. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/py_tutorials/shaft.geo +0 -0
  125. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/revolution.geo +0 -0
  126. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/screw.step +0 -0
  127. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sculpture.geo +0 -0
  128. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/shaft.geo +0 -0
  129. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/shell.geo +0 -0
  130. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sphere.geo +0 -0
  131. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sphereincube.geo +0 -0
  132. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/square.in2d +0 -0
  133. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/squarecircle.in2d +0 -0
  134. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/squarehole.in2d +0 -0
  135. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/torus.geo +0 -0
  136. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/trafo.geo +0 -0
  137. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twobricks.geo +0 -0
  138. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twocubes.geo +0 -0
  139. {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twocyl.geo +0 -0
  140. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/AUTHORS +0 -0
  141. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/LICENSE +0 -0
  142. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/WHEEL +0 -0
  143. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/entry_points.txt +0 -0
  144. {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,22 @@
1
+ // Copyright (c) 2024 The Pybind Development Team.
2
+ // All rights reserved. Use of this source code is governed by a
3
+ // BSD-style license that can be found in the LICENSE file.
4
+
5
+ #pragma once
6
+
7
+ #include "common.h"
8
+ #include "struct_smart_holder.h"
9
+
10
+ #include <type_traits>
11
+
12
+ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
13
+
14
+ using pybind11::memory::smart_holder;
15
+
16
+ PYBIND11_NAMESPACE_BEGIN(detail)
17
+
18
+ template <typename H>
19
+ using is_smart_holder = std::is_same<H, smart_holder>;
20
+
21
+ PYBIND11_NAMESPACE_END(detail)
22
+ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
@@ -0,0 +1,90 @@
1
+ // Copyright (c) 2016-2024 The Pybind Development Team.
2
+ // All rights reserved. Use of this source code is governed by a
3
+ // BSD-style license that can be found in the LICENSE file.
4
+
5
+ #pragma once
6
+
7
+ #include "common.h"
8
+
9
+ #include <cstddef>
10
+ #include <cstdint>
11
+ #include <typeinfo>
12
+
13
+ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
14
+ PYBIND11_NAMESPACE_BEGIN(detail)
15
+
16
+ struct value_and_holder {
17
+ instance *inst = nullptr;
18
+ size_t index = 0u;
19
+ const detail::type_info *type = nullptr;
20
+ void **vh = nullptr;
21
+
22
+ // Main constructor for a found value/holder:
23
+ value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
24
+ : inst{i}, index{index}, type{type},
25
+ vh{inst->simple_layout ? inst->simple_value_holder
26
+ : &inst->nonsimple.values_and_holders[vpos]} {}
27
+
28
+ // Default constructor (used to signal a value-and-holder not found by get_value_and_holder())
29
+ value_and_holder() = default;
30
+
31
+ // Used for past-the-end iterator
32
+ explicit value_and_holder(size_t index) : index{index} {}
33
+
34
+ template <typename V = void>
35
+ V *&value_ptr() const {
36
+ return reinterpret_cast<V *&>(vh[0]);
37
+ }
38
+ // True if this `value_and_holder` has a non-null value pointer
39
+ explicit operator bool() const { return value_ptr() != nullptr; }
40
+
41
+ template <typename H>
42
+ H &holder() const {
43
+ return reinterpret_cast<H &>(vh[1]);
44
+ }
45
+ bool holder_constructed() const {
46
+ return inst->simple_layout
47
+ ? inst->simple_holder_constructed
48
+ : (inst->nonsimple.status[index] & instance::status_holder_constructed) != 0u;
49
+ }
50
+ // NOLINTNEXTLINE(readability-make-member-function-const)
51
+ void set_holder_constructed(bool v = true) {
52
+ if (inst->simple_layout) {
53
+ inst->simple_holder_constructed = v;
54
+ } else if (v) {
55
+ inst->nonsimple.status[index] |= instance::status_holder_constructed;
56
+ } else {
57
+ inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_holder_constructed;
58
+ }
59
+ }
60
+ bool instance_registered() const {
61
+ return inst->simple_layout
62
+ ? inst->simple_instance_registered
63
+ : ((inst->nonsimple.status[index] & instance::status_instance_registered) != 0);
64
+ }
65
+ // NOLINTNEXTLINE(readability-make-member-function-const)
66
+ void set_instance_registered(bool v = true) {
67
+ if (inst->simple_layout) {
68
+ inst->simple_instance_registered = v;
69
+ } else if (v) {
70
+ inst->nonsimple.status[index] |= instance::status_instance_registered;
71
+ } else {
72
+ inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_instance_registered;
73
+ }
74
+ }
75
+ };
76
+
77
+ // This is a semi-public API to check if the corresponding instance has been constructed with a
78
+ // holder. That is, if the instance has been constructed with a holder, the `__init__` method is
79
+ // called and the C++ object is valid. Otherwise, the C++ object might only be allocated, but not
80
+ // initialized. This will lead to **SEGMENTATION FAULTS** if the C++ object is used in any way.
81
+ // Example usage: https://pybind11.readthedocs.io/en/stable/advanced/classes.html#custom-type-setup
82
+ // for `tp_traverse` and `tp_clear` implementations.
83
+ // WARNING: The caller is responsible for ensuring that the `reinterpret_cast` is valid.
84
+ inline bool is_holder_constructed(PyObject *obj) {
85
+ auto *const instance = reinterpret_cast<pybind11::detail::instance *>(obj);
86
+ return instance->get_value_and_holder().holder_constructed();
87
+ }
88
+
89
+ PYBIND11_NAMESPACE_END(detail)
90
+ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
@@ -9,7 +9,8 @@
9
9
 
10
10
  #pragma once
11
11
 
12
- #include "../numpy.h"
12
+ #include <pybind11/numpy.h>
13
+
13
14
  #include "common.h"
14
15
 
15
16
  /* HINT: To suppress warnings originating from the Eigen headers, use -isystem.
@@ -224,19 +225,22 @@ struct EigenProps {
224
225
  = !show_c_contiguous && show_order && requires_col_major;
225
226
 
226
227
  static constexpr auto descriptor
227
- = const_name("numpy.ndarray[") + npy_format_descriptor<Scalar>::name + const_name("[")
228
+ = const_name("typing.Annotated[")
229
+ + io_name("numpy.typing.ArrayLike, ", "numpy.typing.NDArray[")
230
+ + npy_format_descriptor<Scalar>::name + io_name("", "]") + const_name(", \"[")
228
231
  + const_name<fixed_rows>(const_name<(size_t) rows>(), const_name("m")) + const_name(", ")
229
- + const_name<fixed_cols>(const_name<(size_t) cols>(), const_name("n")) + const_name("]")
230
- +
232
+ + const_name<fixed_cols>(const_name<(size_t) cols>(), const_name("n"))
233
+ + const_name("]\"")
231
234
  // For a reference type (e.g. Ref<MatrixXd>) we have other constraints that might need to
232
235
  // be satisfied: writeable=True (for a mutable reference), and, depending on the map's
233
236
  // stride options, possibly f_contiguous or c_contiguous. We include them in the
234
237
  // descriptor output to provide some hint as to why a TypeError is occurring (otherwise
235
- // it can be confusing to see that a function accepts a 'numpy.ndarray[float64[3,2]]' and
236
- // an error message that you *gave* a numpy.ndarray of the right type and dimensions.
237
- const_name<show_writeable>(", flags.writeable", "")
238
- + const_name<show_c_contiguous>(", flags.c_contiguous", "")
239
- + const_name<show_f_contiguous>(", flags.f_contiguous", "") + const_name("]");
238
+ // it can be confusing to see that a function accepts a
239
+ // 'typing.Annotated[numpy.typing.NDArray[numpy.float64], "[3,2]"]' and an error message
240
+ // that you *gave* a numpy.ndarray of the right type and dimensions.
241
+ + const_name<show_writeable>(", \"flags.writeable\"", "")
242
+ + const_name<show_c_contiguous>(", \"flags.c_contiguous\"", "")
243
+ + const_name<show_f_contiguous>(", \"flags.f_contiguous\"", "") + const_name("]");
240
244
  };
241
245
 
242
246
  // Casts an Eigen type to numpy array. If given a base, the numpy array references the src data,
@@ -315,8 +319,11 @@ struct type_caster<Type, enable_if_t<is_eigen_dense_plain<Type>::value>> {
315
319
  return false;
316
320
  }
317
321
 
322
+ PYBIND11_WARNING_PUSH
323
+ PYBIND11_WARNING_DISABLE_GCC("-Wmaybe-uninitialized") // See PR #5516
318
324
  // Allocate the new type, then build a numpy reference into it
319
325
  value = Type(fits.rows, fits.cols);
326
+ PYBIND11_WARNING_POP
320
327
  auto ref = reinterpret_steal<array>(eigen_ref_array<props>(value));
321
328
  if (dims == 1) {
322
329
  ref = ref.squeeze();
@@ -437,7 +444,9 @@ public:
437
444
  }
438
445
  }
439
446
 
440
- static constexpr auto name = props::descriptor;
447
+ // return_descr forces the use of NDArray instead of ArrayLike in args
448
+ // since Ref<...> args can only accept arrays.
449
+ static constexpr auto name = return_descr(props::descriptor);
441
450
 
442
451
  // Explicitly delete these: support python -> C++ conversion on these (i.e. these can be return
443
452
  // types but not bound arguments). We still provide them (with an explicitly delete) so that
@@ -7,7 +7,8 @@
7
7
 
8
8
  #pragma once
9
9
 
10
- #include "../numpy.h"
10
+ #include <pybind11/numpy.h>
11
+
11
12
  #include "common.h"
12
13
 
13
14
  #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
@@ -123,13 +124,16 @@ struct eigen_tensor_helper<
123
124
  template <typename Type, bool ShowDetails, bool NeedsWriteable = false>
124
125
  struct get_tensor_descriptor {
125
126
  static constexpr auto details
126
- = const_name<NeedsWriteable>(", flags.writeable", "")
127
- + const_name<static_cast<int>(Type::Layout) == static_cast<int>(Eigen::RowMajor)>(
128
- ", flags.c_contiguous", ", flags.f_contiguous");
127
+ = const_name<NeedsWriteable>(", \"flags.writeable\"", "") + const_name
128
+ < static_cast<int>(Type::Layout)
129
+ == static_cast<int>(Eigen::RowMajor)
130
+ > (", \"flags.c_contiguous\"", ", \"flags.f_contiguous\"");
129
131
  static constexpr auto value
130
- = const_name("numpy.ndarray[") + npy_format_descriptor<typename Type::Scalar>::name
131
- + const_name("[") + eigen_tensor_helper<remove_cv_t<Type>>::dimensions_descriptor
132
- + const_name("]") + const_name<ShowDetails>(details, const_name("")) + const_name("]");
132
+ = const_name("typing.Annotated[")
133
+ + io_name("numpy.typing.ArrayLike, ", "numpy.typing.NDArray[")
134
+ + npy_format_descriptor<typename Type::Scalar>::name + io_name("", "]")
135
+ + const_name(", \"[") + eigen_tensor_helper<remove_cv_t<Type>>::dimensions_descriptor
136
+ + const_name("]\"") + const_name<ShowDetails>(details, const_name("")) + const_name("]");
133
137
  };
134
138
 
135
139
  // When EIGEN_AVOID_STL_ARRAY is defined, Eigen::DSizes<T, 0> does not have the begin() member
@@ -469,9 +473,6 @@ struct type_caster<Eigen::TensorMap<Type, Options>,
469
473
  parent_object = reinterpret_borrow<object>(parent);
470
474
  break;
471
475
 
472
- case return_value_policy::take_ownership:
473
- delete src;
474
- // fallthrough
475
476
  default:
476
477
  // move, take_ownership don't make any sense for a ref/map:
477
478
  pybind11_fail("Invalid return_value_policy for Eigen Map type, must be either "
@@ -504,7 +505,10 @@ protected:
504
505
  std::unique_ptr<MapType> value;
505
506
 
506
507
  public:
507
- static constexpr auto name = get_tensor_descriptor<Type, true, needs_writeable>::value;
508
+ // return_descr forces the use of NDArray instead of ArrayLike since refs can only reference
509
+ // arrays
510
+ static constexpr auto name
511
+ = return_descr(get_tensor_descriptor<Type, true, needs_writeable>::value);
508
512
  explicit operator MapType *() { return value.get(); }
509
513
  explicit operator MapType &() { return *value; }
510
514
  explicit operator MapType &&() && { return std::move(*value); }
@@ -37,24 +37,32 @@
37
37
  return "Hello, World!";
38
38
  });
39
39
  }
40
+
41
+ The third and subsequent macro arguments are optional, and can be used to
42
+ mark the module as supporting various Python features.
43
+
44
+ - ``mod_gil_not_used()``
45
+ - ``multiple_interpreters::per_interpreter_gil()``
46
+ - ``multiple_interpreters::shared_gil()``
47
+ - ``multiple_interpreters::not_supported()``
48
+
49
+ .. code-block:: cpp
50
+
51
+ PYBIND11_EMBEDDED_MODULE(example, m, py::mod_gil_not_used()) {
52
+ m.def("foo", []() {
53
+ return "Hello, Free-threaded World!";
54
+ });
55
+ }
56
+
40
57
  \endrst */
41
- #define PYBIND11_EMBEDDED_MODULE(name, variable) \
42
- static ::pybind11::module_::module_def PYBIND11_CONCAT(pybind11_module_def_, name); \
43
- static void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ &); \
44
- static PyObject PYBIND11_CONCAT(*pybind11_init_wrapper_, name)() { \
45
- auto m = ::pybind11::module_::create_extension_module( \
46
- PYBIND11_TOSTRING(name), nullptr, &PYBIND11_CONCAT(pybind11_module_def_, name)); \
47
- try { \
48
- PYBIND11_CONCAT(pybind11_init_, name)(m); \
49
- return m.ptr(); \
50
- } \
51
- PYBIND11_CATCH_INIT_EXCEPTIONS \
52
- } \
53
- PYBIND11_EMBEDDED_MODULE_IMPL(name) \
58
+ PYBIND11_WARNING_PUSH
59
+ PYBIND11_WARNING_DISABLE_CLANG("-Wgnu-zero-variadic-macro-arguments")
60
+ #define PYBIND11_EMBEDDED_MODULE(name, variable, ...) \
61
+ PYBIND11_MODULE_PYINIT(name, {}, ##__VA_ARGS__) \
54
62
  ::pybind11::detail::embedded_module PYBIND11_CONCAT(pybind11_module_, name)( \
55
- PYBIND11_TOSTRING(name), PYBIND11_CONCAT(pybind11_init_impl_, name)); \
56
- void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ \
57
- & variable) // NOLINT(bugprone-macro-parentheses)
63
+ PYBIND11_TOSTRING(name), PYBIND11_CONCAT(PyInit_, name)); \
64
+ PYBIND11_MODULE_EXEC(name, variable)
65
+ PYBIND11_WARNING_POP
58
66
 
59
67
  PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
60
68
  PYBIND11_NAMESPACE_BEGIN(detail)
@@ -103,19 +111,6 @@ inline void initialize_interpreter_pre_pyconfig(bool init_signal_handlers,
103
111
  bool add_program_dir_to_path) {
104
112
  detail::precheck_interpreter();
105
113
  Py_InitializeEx(init_signal_handlers ? 1 : 0);
106
- # if defined(WITH_THREAD) && PY_VERSION_HEX < 0x03070000
107
- PyEval_InitThreads();
108
- # endif
109
-
110
- // Before it was special-cased in python 3.8, passing an empty or null argv
111
- // caused a segfault, so we have to reimplement the special case ourselves.
112
- bool special_case = (argv == nullptr || argc <= 0);
113
-
114
- const char *const empty_argv[]{"\0"};
115
- const char *const *safe_argv = special_case ? empty_argv : argv;
116
- if (special_case) {
117
- argc = 1;
118
- }
119
114
 
120
115
  auto argv_size = static_cast<size_t>(argc);
121
116
  // SetArgv* on python 3 takes wchar_t, so we have to convert.
@@ -123,7 +118,7 @@ inline void initialize_interpreter_pre_pyconfig(bool init_signal_handlers,
123
118
  std::vector<std::unique_ptr<wchar_t[], detail::wide_char_arg_deleter>> widened_argv_entries;
124
119
  widened_argv_entries.reserve(argv_size);
125
120
  for (size_t ii = 0; ii < argv_size; ++ii) {
126
- widened_argv_entries.emplace_back(detail::widen_chars(safe_argv[ii]));
121
+ widened_argv_entries.emplace_back(detail::widen_chars(argv[ii]));
127
122
  if (!widened_argv_entries.back()) {
128
123
  // A null here indicates a character-encoding failure or the python
129
124
  // interpreter out of memory. Give up.
@@ -205,6 +200,9 @@ inline void initialize_interpreter(bool init_signal_handlers = true,
205
200
  config.install_signal_handlers = init_signal_handlers ? 1 : 0;
206
201
  initialize_interpreter(&config, argc, argv, add_program_dir_to_path);
207
202
  #endif
203
+
204
+ // There is exactly one interpreter alive currently.
205
+ detail::get_num_interpreters_seen() = 1;
208
206
  }
209
207
 
210
208
  /** \rst
@@ -243,26 +241,32 @@ inline void initialize_interpreter(bool init_signal_handlers = true,
243
241
 
244
242
  \endrst */
245
243
  inline void finalize_interpreter() {
246
- // Get the internals pointer (without creating it if it doesn't exist). It's possible for the
247
- // internals to be created during Py_Finalize() (e.g. if a py::capsule calls `get_internals()`
248
- // during destruction), so we get the pointer-pointer here and check it after Py_Finalize().
249
- detail::internals **internals_ptr_ptr = detail::get_internals_pp();
250
- // It could also be stashed in state_dict, so look there too:
251
- if (object internals_obj
252
- = get_internals_obj_from_state_dict(detail::get_python_state_dict())) {
253
- internals_ptr_ptr = detail::get_internals_pp_from_capsule(internals_obj);
244
+ // get rid of any thread-local interpreter cache that currently exists
245
+ if (detail::get_num_interpreters_seen() > 1) {
246
+ detail::get_internals_pp_manager().unref();
247
+ detail::get_local_internals_pp_manager().unref();
248
+
249
+ // We know there can be no other interpreter alive now, so we can lower the count
250
+ detail::get_num_interpreters_seen() = 1;
254
251
  }
255
- // Local internals contains data managed by the current interpreter, so we must clear them to
256
- // avoid undefined behaviors when initializing another interpreter
257
- detail::get_local_internals().registered_types_cpp.clear();
258
- detail::get_local_internals().registered_exception_translators.clear();
252
+
253
+ // Re-fetch the internals pointer-to-pointer (but not the internals itself, which might not
254
+ // exist). It's possible for the internals to be created during Py_Finalize() (e.g. if a
255
+ // py::capsule calls `get_internals()` during destruction), so we get the pointer-pointer here
256
+ // and check it after Py_Finalize().
257
+ detail::get_internals_pp_manager().get_pp();
258
+ detail::get_local_internals_pp_manager().get_pp();
259
259
 
260
260
  Py_Finalize();
261
261
 
262
- if (internals_ptr_ptr) {
263
- delete *internals_ptr_ptr;
264
- *internals_ptr_ptr = nullptr;
265
- }
262
+ detail::get_internals_pp_manager().destroy();
263
+
264
+ // Local internals contains data managed by the current interpreter, so we must clear them to
265
+ // avoid undefined behaviors when initializing another interpreter
266
+ detail::get_local_internals_pp_manager().destroy();
267
+
268
+ // We know there is no interpreter alive now, so we can reset the count
269
+ detail::get_num_interpreters_seen() = 0;
266
270
  }
267
271
 
268
272
  /** \rst
@@ -19,7 +19,7 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
19
19
  PYBIND11_NAMESPACE_BEGIN(detail)
20
20
 
21
21
  inline void ensure_builtins_in_globals(object &global) {
22
- #if defined(PYPY_VERSION) || PY_VERSION_HEX < 0x03080000
22
+ #if defined(PYPY_VERSION)
23
23
  // Running exec and eval adds `builtins` module under `__builtins__` key to
24
24
  // globals if not yet present. Python 3.8 made PyRun_String behave
25
25
  // similarly. Let's also do that for older versions, for consistency. This
@@ -94,18 +94,18 @@ void exec(const char (&s)[N], object global = globals(), object local = object()
94
94
  eval<eval_statements>(s, std::move(global), std::move(local));
95
95
  }
96
96
 
97
- #if defined(PYPY_VERSION)
97
+ #if defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)
98
98
  template <eval_mode mode = eval_statements>
99
99
  object eval_file(str, object, object) {
100
- pybind11_fail("eval_file not supported in PyPy3. Use eval");
100
+ pybind11_fail("eval_file not supported in this interpreter. Use eval");
101
101
  }
102
102
  template <eval_mode mode = eval_statements>
103
103
  object eval_file(str, object) {
104
- pybind11_fail("eval_file not supported in PyPy3. Use eval");
104
+ pybind11_fail("eval_file not supported in this interpreter. Use eval");
105
105
  }
106
106
  template <eval_mode mode = eval_statements>
107
107
  object eval_file(str) {
108
- pybind11_fail("eval_file not supported in PyPy3. Use eval");
108
+ pybind11_fail("eval_file not supported in this interpreter. Use eval");
109
109
  }
110
110
  #else
111
111
  template <eval_mode mode = eval_statements>
@@ -133,7 +133,12 @@ object eval_file(str fname, object global = globals(), object local = object())
133
133
 
134
134
  int closeFile = 1;
135
135
  std::string fname_str = (std::string) fname;
136
- FILE *f = _Py_fopen_obj(fname.ptr(), "r");
136
+ FILE *f =
137
+ # if PY_VERSION_HEX >= 0x030E0000
138
+ Py_fopen(fname.ptr(), "r");
139
+ # else
140
+ _Py_fopen_obj(fname.ptr(), "r");
141
+ # endif
137
142
  if (!f) {
138
143
  PyErr_Clear();
139
144
  pybind11_fail("File \"" + fname_str + "\" could not be opened!");
@@ -15,6 +15,47 @@
15
15
 
16
16
  PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
17
17
  PYBIND11_NAMESPACE_BEGIN(detail)
18
+ PYBIND11_NAMESPACE_BEGIN(type_caster_std_function_specializations)
19
+
20
+ // ensure GIL is held during functor destruction
21
+ struct func_handle {
22
+ function f;
23
+ #if !(defined(_MSC_VER) && _MSC_VER == 1916 && defined(PYBIND11_CPP17))
24
+ // This triggers a syntax error under very special conditions (very weird indeed).
25
+ explicit
26
+ #endif
27
+ func_handle(function &&f_) noexcept
28
+ : f(std::move(f_)) {
29
+ }
30
+ func_handle(const func_handle &f_) { operator=(f_); }
31
+ func_handle &operator=(const func_handle &f_) {
32
+ gil_scoped_acquire acq;
33
+ f = f_.f;
34
+ return *this;
35
+ }
36
+ ~func_handle() {
37
+ gil_scoped_acquire acq;
38
+ function kill_f(std::move(f));
39
+ }
40
+ };
41
+
42
+ // to emulate 'move initialization capture' in C++11
43
+ struct func_wrapper_base {
44
+ func_handle hfunc;
45
+ explicit func_wrapper_base(func_handle &&hf) noexcept : hfunc(hf) {}
46
+ };
47
+
48
+ template <typename Return, typename... Args>
49
+ struct func_wrapper : func_wrapper_base {
50
+ using func_wrapper_base::func_wrapper_base;
51
+ Return operator()(Args... args) const { // NOLINT(performance-unnecessary-value-param)
52
+ gil_scoped_acquire acq;
53
+ // casts the returned object as a rvalue to the return type
54
+ return hfunc.f(std::forward<Args>(args)...).template cast<Return>();
55
+ }
56
+ };
57
+
58
+ PYBIND11_NAMESPACE_END(type_caster_std_function_specializations)
18
59
 
19
60
  template <typename Return, typename... Args>
20
61
  struct type_caster<std::function<Return(Args...)>> {
@@ -50,23 +91,22 @@ public:
50
91
  auto *cfunc_self = PyCFunction_GET_SELF(cfunc.ptr());
51
92
  if (cfunc_self == nullptr) {
52
93
  PyErr_Clear();
53
- } else if (isinstance<capsule>(cfunc_self)) {
54
- auto c = reinterpret_borrow<capsule>(cfunc_self);
55
-
56
- function_record *rec = nullptr;
57
- // Check that we can safely reinterpret the capsule into a function_record
58
- if (detail::is_function_record_capsule(c)) {
59
- rec = c.get_pointer<function_record>();
60
- }
61
-
94
+ } else {
95
+ function_record *rec = function_record_ptr_from_PyObject(cfunc_self);
62
96
  while (rec != nullptr) {
63
97
  if (rec->is_stateless
64
98
  && same_type(typeid(function_type),
65
99
  *reinterpret_cast<const std::type_info *>(rec->data[1]))) {
66
100
  struct capture {
67
101
  function_type f;
102
+
103
+ static capture *from_data(void **data) {
104
+ return PYBIND11_STD_LAUNDER(reinterpret_cast<capture *>(data));
105
+ }
68
106
  };
69
- value = ((capture *) &rec->data)->f;
107
+ PYBIND11_ENSURE_PRECONDITION_FOR_FUNCTIONAL_H_PERFORMANCE_OPTIMIZATIONS(
108
+ std::is_standard_layout<capture>::value);
109
+ value = capture::from_data(rec->data)->f;
70
110
  return true;
71
111
  }
72
112
  rec = rec->next;
@@ -77,40 +117,8 @@ public:
77
117
  // See PR #1413 for full details
78
118
  }
79
119
 
80
- // ensure GIL is held during functor destruction
81
- struct func_handle {
82
- function f;
83
- #if !(defined(_MSC_VER) && _MSC_VER == 1916 && defined(PYBIND11_CPP17))
84
- // This triggers a syntax error under very special conditions (very weird indeed).
85
- explicit
86
- #endif
87
- func_handle(function &&f_) noexcept
88
- : f(std::move(f_)) {
89
- }
90
- func_handle(const func_handle &f_) { operator=(f_); }
91
- func_handle &operator=(const func_handle &f_) {
92
- gil_scoped_acquire acq;
93
- f = f_.f;
94
- return *this;
95
- }
96
- ~func_handle() {
97
- gil_scoped_acquire acq;
98
- function kill_f(std::move(f));
99
- }
100
- };
101
-
102
- // to emulate 'move initialization capture' in C++11
103
- struct func_wrapper {
104
- func_handle hfunc;
105
- explicit func_wrapper(func_handle &&hf) noexcept : hfunc(std::move(hf)) {}
106
- Return operator()(Args... args) const {
107
- gil_scoped_acquire acq;
108
- // casts the returned object as a rvalue to the return type
109
- return hfunc.f(std::forward<Args>(args)...).template cast<Return>();
110
- }
111
- };
112
-
113
- value = func_wrapper(func_handle(std::move(func)));
120
+ value = type_caster_std_function_specializations::func_wrapper<Return, Args...>(
121
+ type_caster_std_function_specializations::func_handle(std::move(func)));
114
122
  return true;
115
123
  }
116
124
 
@@ -127,11 +135,12 @@ public:
127
135
  return cpp_function(std::forward<Func>(f_), policy).release();
128
136
  }
129
137
 
130
- PYBIND11_TYPE_CASTER(type,
131
- const_name("Callable[[")
132
- + ::pybind11::detail::concat(make_caster<Args>::name...)
133
- + const_name("], ") + make_caster<retval_type>::name
134
- + const_name("]"));
138
+ PYBIND11_TYPE_CASTER(
139
+ type,
140
+ const_name("collections.abc.Callable[[")
141
+ + ::pybind11::detail::concat(::pybind11::detail::arg_descr(make_caster<Args>::name)...)
142
+ + const_name("], ") + ::pybind11::detail::return_descr(make_caster<retval_type>::name)
143
+ + const_name("]"));
135
144
  };
136
145
 
137
146
  PYBIND11_NAMESPACE_END(detail)