netgen-mesher 6.2.2504.post11.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 (153) hide show
  1. netgen/__init__.pyi +3 -3
  2. netgen/cmake/NetgenConfig.cmake +10 -9
  3. netgen/config/__init__.pyi +8 -8
  4. netgen/config/config.py +7 -7
  5. netgen/config/config.pyi +8 -8
  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/paje_trace.hpp +9 -8
  17. netgen/include/core/profiler.hpp +5 -5
  18. netgen/include/core/register_archive.hpp +8 -0
  19. netgen/include/core/simd.hpp +69 -1
  20. netgen/include/core/simd_arm64.hpp +205 -1
  21. netgen/include/core/simd_avx.hpp +72 -4
  22. netgen/include/core/simd_avx512.hpp +9 -0
  23. netgen/include/core/simd_generic.hpp +274 -8
  24. netgen/include/core/simd_math.hpp +178 -0
  25. netgen/include/core/simd_sse.hpp +11 -1
  26. netgen/include/core/statushandler.hpp +37 -0
  27. netgen/include/core/table.hpp +3 -2
  28. netgen/include/core/taskmanager.hpp +34 -1
  29. netgen/include/core/utils.hpp +3 -8
  30. netgen/include/include/netgen_version.hpp +4 -4
  31. netgen/include/meshing/basegeom.hpp +1 -4
  32. netgen/include/meshing/global.hpp +0 -17
  33. netgen/include/meshing/hpref_tet.hpp +41 -0
  34. netgen/include/meshing/hprefinement.hpp +2 -0
  35. netgen/include/meshing/meshtype.hpp +2 -1
  36. netgen/include/meshing/msghandler.hpp +9 -6
  37. netgen/include/meshing/topology.hpp +2 -2
  38. netgen/include/nginterface.h +3 -2
  39. netgen/include/occ/occ_utils.hpp +26 -0
  40. netgen/include/occ/occgeom.hpp +8 -0
  41. netgen/include/pybind11/attr.h +40 -8
  42. netgen/include/pybind11/buffer_info.h +14 -14
  43. netgen/include/pybind11/cast.h +553 -29
  44. netgen/include/pybind11/chrono.h +4 -1
  45. netgen/include/pybind11/conduit/README.txt +15 -0
  46. netgen/include/pybind11/conduit/pybind11_conduit_v1.h +116 -0
  47. netgen/include/pybind11/conduit/pybind11_platform_abi_id.h +87 -0
  48. netgen/include/pybind11/conduit/wrap_include_python_h.h +72 -0
  49. netgen/include/pybind11/critical_section.h +56 -0
  50. netgen/include/pybind11/detail/class.h +172 -97
  51. netgen/include/pybind11/detail/common.h +270 -189
  52. netgen/include/pybind11/detail/cpp_conduit.h +75 -0
  53. netgen/include/pybind11/detail/descr.h +55 -0
  54. netgen/include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h +39 -0
  55. netgen/include/pybind11/detail/exception_translation.h +71 -0
  56. netgen/include/pybind11/detail/function_record_pyobject.h +191 -0
  57. netgen/include/pybind11/detail/init.h +113 -9
  58. netgen/include/pybind11/detail/internals.h +479 -344
  59. netgen/include/pybind11/detail/native_enum_data.h +209 -0
  60. netgen/include/pybind11/detail/pybind11_namespace_macros.h +82 -0
  61. netgen/include/pybind11/detail/struct_smart_holder.h +378 -0
  62. netgen/include/pybind11/detail/type_caster_base.h +506 -133
  63. netgen/include/pybind11/detail/using_smart_holder.h +22 -0
  64. netgen/include/pybind11/detail/value_and_holder.h +90 -0
  65. netgen/include/pybind11/eigen/matrix.h +19 -10
  66. netgen/include/pybind11/eigen/tensor.h +15 -11
  67. netgen/include/pybind11/embed.h +50 -46
  68. netgen/include/pybind11/eval.h +11 -6
  69. netgen/include/pybind11/functional.h +58 -49
  70. netgen/include/pybind11/gil.h +34 -82
  71. netgen/include/pybind11/gil_safe_call_once.h +12 -1
  72. netgen/include/pybind11/gil_simple.h +37 -0
  73. netgen/include/pybind11/native_enum.h +67 -0
  74. netgen/include/pybind11/numpy.h +272 -93
  75. netgen/include/pybind11/pybind11.h +947 -265
  76. netgen/include/pybind11/pytypes.h +127 -21
  77. netgen/include/pybind11/stl/filesystem.h +23 -25
  78. netgen/include/pybind11/stl.h +277 -59
  79. netgen/include/pybind11/stl_bind.h +42 -7
  80. netgen/include/pybind11/subinterpreter.h +299 -0
  81. netgen/include/pybind11/trampoline_self_life_support.h +65 -0
  82. netgen/include/pybind11/typing.h +177 -4
  83. netgen/include/pybind11/warnings.h +75 -0
  84. netgen/include/visualization/mvdraw.hpp +48 -12
  85. netgen/include/visualization/vssolution.hpp +3 -1
  86. netgen/lib/libnggui.lib +0 -0
  87. netgen/lib/ngcore.lib +0 -0
  88. netgen/lib/nglib.lib +0 -0
  89. netgen/libnggui.dll +0 -0
  90. netgen/libngguipy.pyd +0 -0
  91. netgen/libngpy/_NgOCC.pyi +224 -139
  92. netgen/libngpy/_csg.pyi +26 -26
  93. netgen/libngpy/_geom2d.pyi +34 -25
  94. netgen/libngpy/_meshing.pyi +262 -111
  95. netgen/libngpy/_stl.pyi +3 -4
  96. netgen/libngpy.pyd +0 -0
  97. netgen/ngcore.dll +0 -0
  98. netgen/nglib.dll +0 -0
  99. netgen/read_gmsh.py +41 -0
  100. netgen/togl.dll +0 -0
  101. netgen/version.py +1 -1
  102. netgen/webgui.py +38 -2
  103. {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/METADATA +2 -1
  104. {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/RECORD +153 -132
  105. pyngcore/pyngcore.cp313-win_amd64.pyd +0 -0
  106. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/boundarycondition.geo +0 -0
  107. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/boxcyl.geo +0 -0
  108. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/circle_on_cube.geo +0 -0
  109. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cone.geo +0 -0
  110. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cube.geo +0 -0
  111. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubeandring.geo +0 -0
  112. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubeandspheres.geo +0 -0
  113. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubemcyl.geo +0 -0
  114. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubemsphere.geo +0 -0
  115. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cylinder.geo +0 -0
  116. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cylsphere.geo +0 -0
  117. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/doc/ng4.pdf +0 -0
  118. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ellipsoid.geo +0 -0
  119. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ellipticcyl.geo +0 -0
  120. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/extrusion.geo +0 -0
  121. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/fichera.geo +0 -0
  122. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/frame.step +0 -0
  123. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/hinge.stl +0 -0
  124. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/lshape3d.geo +0 -0
  125. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/manyholes.geo +0 -0
  126. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/manyholes2.geo +0 -0
  127. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/matrix.geo +0 -0
  128. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ortho.geo +0 -0
  129. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/part1.stl +0 -0
  130. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/period.geo +0 -0
  131. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/py_tutorials/exportNeutral.py +0 -0
  132. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/py_tutorials/mesh.py +0 -0
  133. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/py_tutorials/shaft.geo +0 -0
  134. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/revolution.geo +0 -0
  135. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/screw.step +0 -0
  136. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sculpture.geo +0 -0
  137. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/shaft.geo +0 -0
  138. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/shell.geo +0 -0
  139. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sphere.geo +0 -0
  140. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sphereincube.geo +0 -0
  141. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/square.in2d +0 -0
  142. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/squarecircle.in2d +0 -0
  143. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/squarehole.in2d +0 -0
  144. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/torus.geo +0 -0
  145. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/trafo.geo +0 -0
  146. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twobricks.geo +0 -0
  147. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twocubes.geo +0 -0
  148. {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twocyl.geo +0 -0
  149. {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/AUTHORS +0 -0
  150. {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/LICENSE +0 -0
  151. {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/WHEEL +0 -0
  152. {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/entry_points.txt +0 -0
  153. {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/top_level.txt +0 -0
@@ -9,8 +9,10 @@
9
9
 
10
10
  #pragma once
11
11
 
12
- #include "../attr.h"
13
- #include "../options.h"
12
+ #include <pybind11/attr.h>
13
+ #include <pybind11/options.h>
14
+
15
+ #include "exception_translation.h"
14
16
 
15
17
  PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
16
18
  PYBIND11_NAMESPACE_BEGIN(detail)
@@ -96,7 +98,7 @@ inline PyTypeObject *make_static_property_type() {
96
98
  pybind11_fail("make_static_property_type(): failure in PyType_Ready()!");
97
99
  }
98
100
 
99
- setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
101
+ setattr((PyObject *) type, "__module__", str(PYBIND11_DUMMY_MODULE_NAME));
100
102
  PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
101
103
 
102
104
  return type;
@@ -205,39 +207,40 @@ extern "C" inline PyObject *pybind11_meta_call(PyObject *type, PyObject *args, P
205
207
 
206
208
  /// Cleanup the type-info for a pybind11-registered type.
207
209
  extern "C" inline void pybind11_meta_dealloc(PyObject *obj) {
208
- auto *type = (PyTypeObject *) obj;
209
- auto &internals = get_internals();
210
-
211
- // A pybind11-registered type will:
212
- // 1) be found in internals.registered_types_py
213
- // 2) have exactly one associated `detail::type_info`
214
- auto found_type = internals.registered_types_py.find(type);
215
- if (found_type != internals.registered_types_py.end() && found_type->second.size() == 1
216
- && found_type->second[0]->type == type) {
217
-
218
- auto *tinfo = found_type->second[0];
219
- auto tindex = std::type_index(*tinfo->cpptype);
220
- internals.direct_conversions.erase(tindex);
221
-
222
- if (tinfo->module_local) {
223
- get_local_internals().registered_types_cpp.erase(tindex);
224
- } else {
225
- internals.registered_types_cpp.erase(tindex);
226
- }
227
- internals.registered_types_py.erase(tinfo->type);
228
-
229
- // Actually just `std::erase_if`, but that's only available in C++20
230
- auto &cache = internals.inactive_override_cache;
231
- for (auto it = cache.begin(), last = cache.end(); it != last;) {
232
- if (it->first == (PyObject *) tinfo->type) {
233
- it = cache.erase(it);
210
+ with_internals([obj](internals &internals) {
211
+ auto *type = (PyTypeObject *) obj;
212
+
213
+ // A pybind11-registered type will:
214
+ // 1) be found in internals.registered_types_py
215
+ // 2) have exactly one associated `detail::type_info`
216
+ auto found_type = internals.registered_types_py.find(type);
217
+ if (found_type != internals.registered_types_py.end() && found_type->second.size() == 1
218
+ && found_type->second[0]->type == type) {
219
+
220
+ auto *tinfo = found_type->second[0];
221
+ auto tindex = std::type_index(*tinfo->cpptype);
222
+ internals.direct_conversions.erase(tindex);
223
+
224
+ if (tinfo->module_local) {
225
+ get_local_internals().registered_types_cpp.erase(tindex);
234
226
  } else {
235
- ++it;
227
+ internals.registered_types_cpp.erase(tindex);
228
+ }
229
+ internals.registered_types_py.erase(tinfo->type);
230
+
231
+ // Actually just `std::erase_if`, but that's only available in C++20
232
+ auto &cache = internals.inactive_override_cache;
233
+ for (auto it = cache.begin(), last = cache.end(); it != last;) {
234
+ if (it->first == (PyObject *) tinfo->type) {
235
+ it = cache.erase(it);
236
+ } else {
237
+ ++it;
238
+ }
236
239
  }
237
- }
238
240
 
239
- delete tinfo;
240
- }
241
+ delete tinfo;
242
+ }
243
+ });
241
244
 
242
245
  PyType_Type.tp_dealloc(obj);
243
246
  }
@@ -279,7 +282,7 @@ inline PyTypeObject *make_default_metaclass() {
279
282
  pybind11_fail("make_default_metaclass(): failure in PyType_Ready()!");
280
283
  }
281
284
 
282
- setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
285
+ setattr((PyObject *) type, "__module__", str(PYBIND11_DUMMY_MODULE_NAME));
283
286
  PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
284
287
 
285
288
  return type;
@@ -309,20 +312,45 @@ inline void traverse_offset_bases(void *valueptr,
309
312
  }
310
313
  }
311
314
 
315
+ #ifdef Py_GIL_DISABLED
316
+ inline void enable_try_inc_ref(PyObject *obj) {
317
+ // TODO: Replace with PyUnstable_Object_EnableTryIncRef when available.
318
+ // See https://github.com/python/cpython/issues/128844
319
+ if (_Py_IsImmortal(obj)) {
320
+ return;
321
+ }
322
+ for (;;) {
323
+ Py_ssize_t shared = _Py_atomic_load_ssize_relaxed(&obj->ob_ref_shared);
324
+ if ((shared & _Py_REF_SHARED_FLAG_MASK) != 0) {
325
+ // Nothing to do if it's in WEAKREFS, QUEUED, or MERGED states.
326
+ return;
327
+ }
328
+ if (_Py_atomic_compare_exchange_ssize(
329
+ &obj->ob_ref_shared, &shared, shared | _Py_REF_MAYBE_WEAKREF)) {
330
+ return;
331
+ }
332
+ }
333
+ }
334
+ #endif
335
+
312
336
  inline bool register_instance_impl(void *ptr, instance *self) {
313
- get_internals().registered_instances.emplace(ptr, self);
337
+ #ifdef Py_GIL_DISABLED
338
+ enable_try_inc_ref(reinterpret_cast<PyObject *>(self));
339
+ #endif
340
+ with_instance_map(ptr, [&](instance_map &instances) { instances.emplace(ptr, self); });
314
341
  return true; // unused, but gives the same signature as the deregister func
315
342
  }
316
343
  inline bool deregister_instance_impl(void *ptr, instance *self) {
317
- auto &registered_instances = get_internals().registered_instances;
318
- auto range = registered_instances.equal_range(ptr);
319
- for (auto it = range.first; it != range.second; ++it) {
320
- if (self == it->second) {
321
- registered_instances.erase(it);
322
- return true;
344
+ return with_instance_map(ptr, [&](instance_map &instances) {
345
+ auto range = instances.equal_range(ptr);
346
+ for (auto it = range.first; it != range.second; ++it) {
347
+ if (self == it->second) {
348
+ instances.erase(it);
349
+ return true;
350
+ }
323
351
  }
324
- }
325
- return false;
352
+ return false;
353
+ });
326
354
  }
327
355
 
328
356
  inline void register_instance(instance *self, void *valptr, const type_info *tinfo) {
@@ -377,23 +405,32 @@ extern "C" inline int pybind11_object_init(PyObject *self, PyObject *, PyObject
377
405
  }
378
406
 
379
407
  inline void add_patient(PyObject *nurse, PyObject *patient) {
380
- auto &internals = get_internals();
381
408
  auto *instance = reinterpret_cast<detail::instance *>(nurse);
382
409
  instance->has_patients = true;
383
410
  Py_INCREF(patient);
384
- internals.patients[nurse].push_back(patient);
411
+
412
+ with_internals([&](internals &internals) { internals.patients[nurse].push_back(patient); });
385
413
  }
386
414
 
387
415
  inline void clear_patients(PyObject *self) {
388
416
  auto *instance = reinterpret_cast<detail::instance *>(self);
389
- auto &internals = get_internals();
390
- auto pos = internals.patients.find(self);
391
- assert(pos != internals.patients.end());
392
- // Clearing the patients can cause more Python code to run, which
393
- // can invalidate the iterator. Extract the vector of patients
394
- // from the unordered_map first.
395
- auto patients = std::move(pos->second);
396
- internals.patients.erase(pos);
417
+ std::vector<PyObject *> patients;
418
+
419
+ with_internals([&](internals &internals) {
420
+ auto pos = internals.patients.find(self);
421
+
422
+ if (pos == internals.patients.end()) {
423
+ pybind11_fail(
424
+ "FATAL: Internal consistency check failed: Invalid clear_patients() call.");
425
+ }
426
+
427
+ // Clearing the patients can cause more Python code to run, which
428
+ // can invalidate the iterator. Extract the vector of patients
429
+ // from the unordered_map first.
430
+ patients = std::move(pos->second);
431
+ internals.patients.erase(pos);
432
+ });
433
+
397
434
  instance->has_patients = false;
398
435
  for (PyObject *&patient : patients) {
399
436
  Py_CLEAR(patient);
@@ -420,6 +457,8 @@ inline void clear_instance(PyObject *self) {
420
457
  if (instance->owned || v_h.holder_constructed()) {
421
458
  v_h.type->dealloc(v_h);
422
459
  }
460
+ } else if (v_h.holder_constructed()) {
461
+ v_h.type->dealloc(v_h); // Disowned instance.
423
462
  }
424
463
  }
425
464
  // Deallocate the value/holder layout internals:
@@ -455,23 +494,18 @@ extern "C" inline void pybind11_object_dealloc(PyObject *self) {
455
494
 
456
495
  type->tp_free(self);
457
496
 
458
- #if PY_VERSION_HEX < 0x03080000
459
- // `type->tp_dealloc != pybind11_object_dealloc` means that we're being called
460
- // as part of a derived type's dealloc, in which case we're not allowed to decref
461
- // the type here. For cross-module compatibility, we shouldn't compare directly
462
- // with `pybind11_object_dealloc`, but with the common one stashed in internals.
463
- auto pybind11_object_type = (PyTypeObject *) get_internals().instance_base;
464
- if (type->tp_dealloc == pybind11_object_type->tp_dealloc)
465
- Py_DECREF(type);
466
- #else
467
497
  // This was not needed before Python 3.8 (Python issue 35810)
468
498
  // https://github.com/pybind/pybind11/issues/1946
469
499
  Py_DECREF(type);
470
- #endif
471
500
  }
472
501
 
502
+ PYBIND11_WARNING_PUSH
503
+ PYBIND11_WARNING_DISABLE_GCC("-Wredundant-decls")
504
+
473
505
  std::string error_string();
474
506
 
507
+ PYBIND11_WARNING_POP
508
+
475
509
  /** Create the type which can be used as a common base for all classes. This is
476
510
  needed in order to satisfy Python's requirements for multiple inheritance.
477
511
  Return value: New reference. */
@@ -510,7 +544,7 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
510
544
  pybind11_fail("PyType_Ready failed in make_object_base_type(): " + error_string());
511
545
  }
512
546
 
513
- setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
547
+ setattr((PyObject *) type, "__module__", str(PYBIND11_DUMMY_MODULE_NAME));
514
548
  PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
515
549
 
516
550
  assert(!PyType_HasFeature(type, Py_TPFLAGS_HAVE_GC));
@@ -547,7 +581,7 @@ extern "C" inline int pybind11_clear(PyObject *self) {
547
581
  inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) {
548
582
  auto *type = &heap_type->ht_type;
549
583
  type->tp_flags |= Py_TPFLAGS_HAVE_GC;
550
- #if PY_VERSION_HEX < 0x030B0000
584
+ #ifdef PYBIND11_BACKWARD_COMPATIBILITY_TP_DICTOFFSET
551
585
  type->tp_dictoffset = type->tp_basicsize; // place dict at the end
552
586
  type->tp_basicsize += (ssize_t) sizeof(PyObject *); // and allocate enough space for it
553
587
  #else
@@ -556,17 +590,9 @@ inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) {
556
590
  type->tp_traverse = pybind11_traverse;
557
591
  type->tp_clear = pybind11_clear;
558
592
 
559
- static PyGetSetDef getset[] = {{
560
- #if PY_VERSION_HEX < 0x03070000
561
- const_cast<char *>("__dict__"),
562
- #else
563
- "__dict__",
564
- #endif
565
- PyObject_GenericGetDict,
566
- PyObject_GenericSetDict,
567
- nullptr,
568
- nullptr},
569
- {nullptr, nullptr, nullptr, nullptr, nullptr}};
593
+ static PyGetSetDef getset[]
594
+ = {{"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict, nullptr, nullptr},
595
+ {nullptr, nullptr, nullptr, nullptr, nullptr}};
570
596
  type->tp_getset = getset;
571
597
  }
572
598
 
@@ -588,31 +614,85 @@ extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int fla
588
614
  return -1;
589
615
  }
590
616
  std::memset(view, 0, sizeof(Py_buffer));
591
- buffer_info *info = tinfo->get_buffer(obj, tinfo->get_buffer_data);
617
+ std::unique_ptr<buffer_info> info = nullptr;
618
+ try {
619
+ info.reset(tinfo->get_buffer(obj, tinfo->get_buffer_data));
620
+ } catch (...) {
621
+ try_translate_exceptions();
622
+ raise_from(PyExc_BufferError, "Error getting buffer");
623
+ return -1;
624
+ }
625
+ if (info == nullptr) {
626
+ pybind11_fail("FATAL UNEXPECTED SITUATION: tinfo->get_buffer() returned nullptr.");
627
+ }
628
+
592
629
  if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE && info->readonly) {
593
- delete info;
594
630
  // view->obj = nullptr; // Was just memset to 0, so not necessary
595
631
  set_error(PyExc_BufferError, "Writable buffer requested for readonly storage");
596
632
  return -1;
597
633
  }
598
- view->obj = obj;
599
- view->ndim = 1;
600
- view->internal = info;
601
- view->buf = info->ptr;
634
+
635
+ // Fill in all the information, and then downgrade as requested by the caller, or raise an
636
+ // error if that's not possible.
602
637
  view->itemsize = info->itemsize;
603
638
  view->len = view->itemsize;
604
639
  for (auto s : info->shape) {
605
640
  view->len *= s;
606
641
  }
642
+ view->ndim = static_cast<int>(info->ndim);
643
+ view->shape = info->shape.data();
644
+ view->strides = info->strides.data();
607
645
  view->readonly = static_cast<int>(info->readonly);
608
646
  if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) {
609
647
  view->format = const_cast<char *>(info->format.c_str());
610
648
  }
611
- if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES) {
612
- view->ndim = (int) info->ndim;
613
- view->strides = info->strides.data();
614
- view->shape = info->shape.data();
649
+
650
+ // Note, all contiguity flags imply PyBUF_STRIDES and lower.
651
+ if ((flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS) {
652
+ if (PyBuffer_IsContiguous(view, 'C') == 0) {
653
+ std::memset(view, 0, sizeof(Py_buffer));
654
+ set_error(PyExc_BufferError,
655
+ "C-contiguous buffer requested for discontiguous storage");
656
+ return -1;
657
+ }
658
+ } else if ((flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS) {
659
+ if (PyBuffer_IsContiguous(view, 'F') == 0) {
660
+ std::memset(view, 0, sizeof(Py_buffer));
661
+ set_error(PyExc_BufferError,
662
+ "Fortran-contiguous buffer requested for discontiguous storage");
663
+ return -1;
664
+ }
665
+ } else if ((flags & PyBUF_ANY_CONTIGUOUS) == PyBUF_ANY_CONTIGUOUS) {
666
+ if (PyBuffer_IsContiguous(view, 'A') == 0) {
667
+ std::memset(view, 0, sizeof(Py_buffer));
668
+ set_error(PyExc_BufferError, "Contiguous buffer requested for discontiguous storage");
669
+ return -1;
670
+ }
671
+
672
+ } else if ((flags & PyBUF_STRIDES) != PyBUF_STRIDES) {
673
+ // If no strides are requested, the buffer must be C-contiguous.
674
+ // https://docs.python.org/3/c-api/buffer.html#contiguity-requests
675
+ if (PyBuffer_IsContiguous(view, 'C') == 0) {
676
+ std::memset(view, 0, sizeof(Py_buffer));
677
+ set_error(PyExc_BufferError,
678
+ "C-contiguous buffer requested for discontiguous storage");
679
+ return -1;
680
+ }
681
+
682
+ view->strides = nullptr;
683
+
684
+ // Since this is a contiguous buffer, it can also pretend to be 1D.
685
+ if ((flags & PyBUF_ND) != PyBUF_ND) {
686
+ view->shape = nullptr;
687
+ view->ndim = 0;
688
+ }
615
689
  }
690
+
691
+ // Set these after all checks so they don't leak out into the caller, and can be automatically
692
+ // cleaned up on error.
693
+ view->buf = info->ptr;
694
+ view->internal = info.release();
695
+ view->obj = obj;
616
696
  Py_INCREF(view->obj);
617
697
  return 0;
618
698
  }
@@ -641,15 +721,7 @@ inline PyObject *make_new_python_type(const type_record &rec) {
641
721
  PyUnicode_FromFormat("%U.%U", rec.scope.attr("__qualname__").ptr(), name.ptr()));
642
722
  }
643
723
 
644
- object module_;
645
- if (rec.scope) {
646
- if (hasattr(rec.scope, "__module__")) {
647
- module_ = rec.scope.attr("__module__");
648
- } else if (hasattr(rec.scope, "__name__")) {
649
- module_ = rec.scope.attr("__name__");
650
- }
651
- }
652
-
724
+ object module_ = get_module_name_if_available(rec.scope);
653
725
  const auto *full_name = c_str(
654
726
  #if !defined(PYPY_VERSION)
655
727
  module_ ? str(module_).cast<std::string>() + "." + rec.name :
@@ -658,10 +730,13 @@ inline PyObject *make_new_python_type(const type_record &rec) {
658
730
 
659
731
  char *tp_doc = nullptr;
660
732
  if (rec.doc && options::show_user_defined_docstrings()) {
661
- /* Allocate memory for docstring (using PyObject_MALLOC, since
662
- Python will free this later on) */
733
+ /* Allocate memory for docstring (Python will free this later on) */
663
734
  size_t size = std::strlen(rec.doc) + 1;
735
+ #if PY_VERSION_HEX >= 0x030D0000
736
+ tp_doc = (char *) PyMem_MALLOC(size);
737
+ #else
664
738
  tp_doc = (char *) PyObject_MALLOC(size);
739
+ #endif
665
740
  std::memcpy((void *) tp_doc, rec.doc, size);
666
741
  }
667
742