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.
- netgen/__init__.pyi +3 -3
- netgen/cmake/NetgenConfig.cmake +9 -8
- netgen/config/__init__.pyi +7 -7
- netgen/config/config.py +6 -6
- netgen/config/config.pyi +7 -7
- netgen/include/core/archive.hpp +18 -3
- netgen/include/core/array.hpp +20 -4
- netgen/include/core/autodiff.hpp +9 -11
- netgen/include/core/autodiffdiff.hpp +0 -2
- netgen/include/core/bitarray.hpp +1 -1
- netgen/include/core/flags.hpp +1 -1
- netgen/include/core/hashtable.hpp +1 -1
- netgen/include/core/memtracer.hpp +7 -7
- netgen/include/core/ngcore.hpp +5 -0
- netgen/include/core/ngcore_api.hpp +11 -0
- netgen/include/core/register_archive.hpp +8 -0
- netgen/include/core/simd_arm64.hpp +100 -5
- netgen/include/core/simd_generic.hpp +187 -6
- netgen/include/core/simd_math.hpp +3 -2
- netgen/include/core/statushandler.hpp +37 -0
- netgen/include/core/table.hpp +2 -2
- netgen/include/core/taskmanager.hpp +34 -1
- netgen/include/include/netgen_version.hpp +3 -3
- netgen/include/meshing/basegeom.hpp +1 -4
- netgen/include/meshing/global.hpp +0 -17
- netgen/include/meshing/hpref_tet.hpp +41 -0
- netgen/include/meshing/hprefinement.hpp +2 -0
- netgen/include/meshing/meshtype.hpp +1 -0
- netgen/include/meshing/msghandler.hpp +9 -6
- netgen/include/meshing/topology.hpp +2 -2
- netgen/include/nginterface.h +3 -2
- netgen/include/occ/occ_utils.hpp +26 -0
- netgen/include/occ/occgeom.hpp +8 -0
- netgen/include/pybind11/attr.h +40 -8
- netgen/include/pybind11/buffer_info.h +14 -14
- netgen/include/pybind11/cast.h +553 -29
- netgen/include/pybind11/chrono.h +4 -1
- netgen/include/pybind11/conduit/README.txt +15 -0
- netgen/include/pybind11/conduit/pybind11_conduit_v1.h +116 -0
- netgen/include/pybind11/conduit/pybind11_platform_abi_id.h +87 -0
- netgen/include/pybind11/conduit/wrap_include_python_h.h +72 -0
- netgen/include/pybind11/critical_section.h +56 -0
- netgen/include/pybind11/detail/class.h +172 -97
- netgen/include/pybind11/detail/common.h +270 -189
- netgen/include/pybind11/detail/cpp_conduit.h +75 -0
- netgen/include/pybind11/detail/descr.h +55 -0
- netgen/include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h +39 -0
- netgen/include/pybind11/detail/exception_translation.h +71 -0
- netgen/include/pybind11/detail/function_record_pyobject.h +191 -0
- netgen/include/pybind11/detail/init.h +113 -9
- netgen/include/pybind11/detail/internals.h +479 -344
- netgen/include/pybind11/detail/native_enum_data.h +209 -0
- netgen/include/pybind11/detail/pybind11_namespace_macros.h +82 -0
- netgen/include/pybind11/detail/struct_smart_holder.h +378 -0
- netgen/include/pybind11/detail/type_caster_base.h +506 -133
- netgen/include/pybind11/detail/using_smart_holder.h +22 -0
- netgen/include/pybind11/detail/value_and_holder.h +90 -0
- netgen/include/pybind11/eigen/matrix.h +19 -10
- netgen/include/pybind11/eigen/tensor.h +15 -11
- netgen/include/pybind11/embed.h +50 -46
- netgen/include/pybind11/eval.h +11 -6
- netgen/include/pybind11/functional.h +58 -49
- netgen/include/pybind11/gil.h +34 -82
- netgen/include/pybind11/gil_safe_call_once.h +12 -1
- netgen/include/pybind11/gil_simple.h +37 -0
- netgen/include/pybind11/native_enum.h +67 -0
- netgen/include/pybind11/numpy.h +272 -93
- netgen/include/pybind11/pybind11.h +947 -265
- netgen/include/pybind11/pytypes.h +127 -21
- netgen/include/pybind11/stl/filesystem.h +23 -25
- netgen/include/pybind11/stl.h +277 -59
- netgen/include/pybind11/stl_bind.h +42 -7
- netgen/include/pybind11/subinterpreter.h +299 -0
- netgen/include/pybind11/trampoline_self_life_support.h +65 -0
- netgen/include/pybind11/typing.h +177 -4
- netgen/include/pybind11/warnings.h +75 -0
- netgen/lib/libnggui.lib +0 -0
- netgen/lib/ngcore.lib +0 -0
- netgen/lib/nglib.lib +0 -0
- netgen/libnggui.dll +0 -0
- netgen/libngguipy.pyd +0 -0
- netgen/libngpy/_NgOCC.pyi +220 -141
- netgen/libngpy/_csg.pyi +26 -26
- netgen/libngpy/_geom2d.pyi +34 -25
- netgen/libngpy/_meshing.pyi +262 -111
- netgen/libngpy/_stl.pyi +3 -4
- netgen/libngpy.pyd +0 -0
- netgen/ngcore.dll +0 -0
- netgen/nglib.dll +0 -0
- netgen/read_gmsh.py +41 -0
- netgen/togl.dll +0 -0
- netgen/version.py +1 -1
- netgen/webgui.py +38 -2
- {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/METADATA +2 -1
- {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/RECORD +144 -124
- pyngcore/pyngcore.cp313-win_amd64.pyd +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/boundarycondition.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/boxcyl.geo +0 -0
- {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
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cone.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cube.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubeandring.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubeandspheres.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubemcyl.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubemsphere.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cylinder.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cylsphere.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/doc/ng4.pdf +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ellipsoid.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ellipticcyl.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/extrusion.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/fichera.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/frame.step +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/hinge.stl +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/lshape3d.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/manyholes.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/manyholes2.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/matrix.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ortho.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/part1.stl +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/period.geo +0 -0
- {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
- {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
- {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
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/revolution.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/screw.step +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sculpture.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/shaft.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/shell.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sphere.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sphereincube.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/square.in2d +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/squarecircle.in2d +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/squarehole.in2d +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/torus.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/trafo.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twobricks.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twocubes.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twocyl.geo +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/AUTHORS +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/LICENSE +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/WHEEL +0 -0
- {netgen_mesher-6.2.2505.post48.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/entry_points.txt +0 -0
- {netgen_mesher-6.2.2505.post48.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
|
|
13
|
-
#include
|
|
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(
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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(
|
|
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
|
-
#
|
|
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
|
-
|
|
561
|
-
|
|
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
|
|
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
|
-
|
|
599
|
-
|
|
600
|
-
|
|
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
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
view
|
|
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 (
|
|
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
|
|