netgen-mesher 6.2.2506.post35.dev0__cp314-cp314-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/NgOCC.py +7 -0
- netgen/__init__.py +114 -0
- netgen/__init__.pyi +22 -0
- netgen/__main__.py +53 -0
- netgen/cmake/NetgenConfig.cmake +79 -0
- netgen/cmake/netgen-targets-release.cmake +69 -0
- netgen/cmake/netgen-targets.cmake +146 -0
- netgen/config/__init__.py +1 -0
- netgen/config/__init__.pyi +52 -0
- netgen/config/__main__.py +4 -0
- netgen/config/config.py +68 -0
- netgen/config/config.pyi +54 -0
- netgen/csg.py +25 -0
- netgen/geom2d.py +178 -0
- netgen/gui.py +82 -0
- netgen/include/core/archive.hpp +1256 -0
- netgen/include/core/array.hpp +1760 -0
- netgen/include/core/autodiff.hpp +1131 -0
- netgen/include/core/autodiffdiff.hpp +733 -0
- netgen/include/core/bitarray.hpp +240 -0
- netgen/include/core/concurrentqueue.h +3619 -0
- netgen/include/core/exception.hpp +145 -0
- netgen/include/core/flags.hpp +199 -0
- netgen/include/core/hashtable.hpp +1281 -0
- netgen/include/core/localheap.hpp +318 -0
- netgen/include/core/logging.hpp +117 -0
- netgen/include/core/memtracer.hpp +221 -0
- netgen/include/core/mpi4py_pycapi.h +245 -0
- netgen/include/core/mpi_wrapper.hpp +643 -0
- netgen/include/core/ng_mpi.hpp +94 -0
- netgen/include/core/ng_mpi_generated_declarations.hpp +155 -0
- netgen/include/core/ng_mpi_native.hpp +25 -0
- netgen/include/core/ngcore.hpp +32 -0
- netgen/include/core/ngcore_api.hpp +152 -0
- netgen/include/core/ngstream.hpp +115 -0
- netgen/include/core/paje_trace.hpp +279 -0
- netgen/include/core/profiler.hpp +382 -0
- netgen/include/core/python_ngcore.hpp +457 -0
- netgen/include/core/ranges.hpp +109 -0
- netgen/include/core/register_archive.hpp +100 -0
- netgen/include/core/signal.hpp +82 -0
- netgen/include/core/simd.hpp +160 -0
- netgen/include/core/simd_arm64.hpp +407 -0
- netgen/include/core/simd_avx.hpp +394 -0
- netgen/include/core/simd_avx512.hpp +285 -0
- netgen/include/core/simd_generic.hpp +1053 -0
- netgen/include/core/simd_math.hpp +178 -0
- netgen/include/core/simd_sse.hpp +289 -0
- netgen/include/core/statushandler.hpp +37 -0
- netgen/include/core/symboltable.hpp +153 -0
- netgen/include/core/table.hpp +810 -0
- netgen/include/core/taskmanager.hpp +1161 -0
- netgen/include/core/type_traits.hpp +65 -0
- netgen/include/core/utils.hpp +385 -0
- netgen/include/core/version.hpp +102 -0
- netgen/include/core/xbool.hpp +47 -0
- netgen/include/csg/algprim.hpp +563 -0
- netgen/include/csg/brick.hpp +150 -0
- netgen/include/csg/csg.hpp +43 -0
- netgen/include/csg/csgeom.hpp +389 -0
- netgen/include/csg/csgparser.hpp +101 -0
- netgen/include/csg/curve2d.hpp +67 -0
- netgen/include/csg/edgeflw.hpp +112 -0
- netgen/include/csg/explicitcurve2d.hpp +113 -0
- netgen/include/csg/extrusion.hpp +185 -0
- netgen/include/csg/gencyl.hpp +70 -0
- netgen/include/csg/geoml.hpp +16 -0
- netgen/include/csg/identify.hpp +213 -0
- netgen/include/csg/manifold.hpp +29 -0
- netgen/include/csg/meshsurf.hpp +46 -0
- netgen/include/csg/polyhedra.hpp +121 -0
- netgen/include/csg/revolution.hpp +180 -0
- netgen/include/csg/singularref.hpp +84 -0
- netgen/include/csg/solid.hpp +295 -0
- netgen/include/csg/specpoin.hpp +194 -0
- netgen/include/csg/spline3d.hpp +99 -0
- netgen/include/csg/splinesurface.hpp +85 -0
- netgen/include/csg/surface.hpp +394 -0
- netgen/include/csg/triapprox.hpp +63 -0
- netgen/include/csg/vscsg.hpp +34 -0
- netgen/include/general/autodiff.hpp +356 -0
- netgen/include/general/autoptr.hpp +39 -0
- netgen/include/general/gzstream.h +121 -0
- netgen/include/general/hashtabl.hpp +1692 -0
- netgen/include/general/myadt.hpp +48 -0
- netgen/include/general/mystring.hpp +226 -0
- netgen/include/general/netgenout.hpp +205 -0
- netgen/include/general/ngarray.hpp +797 -0
- netgen/include/general/ngbitarray.hpp +149 -0
- netgen/include/general/ngpython.hpp +74 -0
- netgen/include/general/optmem.hpp +44 -0
- netgen/include/general/parthreads.hpp +138 -0
- netgen/include/general/seti.hpp +50 -0
- netgen/include/general/sort.hpp +47 -0
- netgen/include/general/spbita2d.hpp +59 -0
- netgen/include/general/stack.hpp +114 -0
- netgen/include/general/table.hpp +280 -0
- netgen/include/general/template.hpp +509 -0
- netgen/include/geom2d/csg2d.hpp +750 -0
- netgen/include/geom2d/geometry2d.hpp +280 -0
- netgen/include/geom2d/spline2d.hpp +234 -0
- netgen/include/geom2d/vsgeom2d.hpp +28 -0
- netgen/include/gprim/adtree.hpp +1392 -0
- netgen/include/gprim/geom2d.hpp +858 -0
- netgen/include/gprim/geom3d.hpp +749 -0
- netgen/include/gprim/geomfuncs.hpp +212 -0
- netgen/include/gprim/geomobjects.hpp +544 -0
- netgen/include/gprim/geomops.hpp +404 -0
- netgen/include/gprim/geomtest3d.hpp +101 -0
- netgen/include/gprim/gprim.hpp +33 -0
- netgen/include/gprim/spline.hpp +778 -0
- netgen/include/gprim/splinegeometry.hpp +73 -0
- netgen/include/gprim/transform3d.hpp +216 -0
- netgen/include/include/acisgeom.hpp +3 -0
- netgen/include/include/csg.hpp +1 -0
- netgen/include/include/geometry2d.hpp +1 -0
- netgen/include/include/gprim.hpp +1 -0
- netgen/include/include/incopengl.hpp +62 -0
- netgen/include/include/inctcl.hpp +13 -0
- netgen/include/include/incvis.hpp +6 -0
- netgen/include/include/linalg.hpp +1 -0
- netgen/include/include/meshing.hpp +1 -0
- netgen/include/include/myadt.hpp +1 -0
- netgen/include/include/mydefs.hpp +70 -0
- netgen/include/include/mystdlib.h +59 -0
- netgen/include/include/netgen_config.hpp +27 -0
- netgen/include/include/netgen_version.hpp +9 -0
- netgen/include/include/nginterface_v2_impl.hpp +395 -0
- netgen/include/include/ngsimd.hpp +1 -0
- netgen/include/include/occgeom.hpp +1 -0
- netgen/include/include/opti.hpp +1 -0
- netgen/include/include/parallel.hpp +1 -0
- netgen/include/include/stlgeom.hpp +1 -0
- netgen/include/include/visual.hpp +1 -0
- netgen/include/interface/rw_medit.hpp +11 -0
- netgen/include/interface/writeuser.hpp +80 -0
- netgen/include/linalg/densemat.hpp +414 -0
- netgen/include/linalg/linalg.hpp +29 -0
- netgen/include/linalg/opti.hpp +142 -0
- netgen/include/linalg/polynomial.hpp +47 -0
- netgen/include/linalg/vector.hpp +217 -0
- netgen/include/meshing/adfront2.hpp +274 -0
- netgen/include/meshing/adfront3.hpp +332 -0
- netgen/include/meshing/basegeom.hpp +370 -0
- netgen/include/meshing/bcfunctions.hpp +53 -0
- netgen/include/meshing/bisect.hpp +72 -0
- netgen/include/meshing/boundarylayer.hpp +113 -0
- netgen/include/meshing/classifyhpel.hpp +1984 -0
- netgen/include/meshing/clusters.hpp +46 -0
- netgen/include/meshing/curvedelems.hpp +274 -0
- netgen/include/meshing/delaunay2d.hpp +73 -0
- netgen/include/meshing/fieldlines.hpp +103 -0
- netgen/include/meshing/findip.hpp +198 -0
- netgen/include/meshing/findip2.hpp +103 -0
- netgen/include/meshing/geomsearch.hpp +69 -0
- netgen/include/meshing/global.hpp +54 -0
- netgen/include/meshing/hpref_hex.hpp +330 -0
- netgen/include/meshing/hpref_prism.hpp +3405 -0
- netgen/include/meshing/hpref_pyramid.hpp +154 -0
- netgen/include/meshing/hpref_quad.hpp +2082 -0
- netgen/include/meshing/hpref_segm.hpp +122 -0
- netgen/include/meshing/hpref_tet.hpp +4230 -0
- netgen/include/meshing/hpref_trig.hpp +848 -0
- netgen/include/meshing/hprefinement.hpp +366 -0
- netgen/include/meshing/improve2.hpp +178 -0
- netgen/include/meshing/improve3.hpp +151 -0
- netgen/include/meshing/localh.hpp +223 -0
- netgen/include/meshing/meshclass.hpp +1076 -0
- netgen/include/meshing/meshfunc.hpp +47 -0
- netgen/include/meshing/meshing.hpp +63 -0
- netgen/include/meshing/meshing2.hpp +163 -0
- netgen/include/meshing/meshing3.hpp +123 -0
- netgen/include/meshing/meshtool.hpp +90 -0
- netgen/include/meshing/meshtype.hpp +1930 -0
- netgen/include/meshing/msghandler.hpp +62 -0
- netgen/include/meshing/paralleltop.hpp +172 -0
- netgen/include/meshing/python_mesh.hpp +206 -0
- netgen/include/meshing/ruler2.hpp +172 -0
- netgen/include/meshing/ruler3.hpp +211 -0
- netgen/include/meshing/soldata.hpp +141 -0
- netgen/include/meshing/specials.hpp +17 -0
- netgen/include/meshing/surfacegeom.hpp +73 -0
- netgen/include/meshing/topology.hpp +1003 -0
- netgen/include/meshing/validate.hpp +21 -0
- netgen/include/meshing/visual_interface.hpp +71 -0
- netgen/include/mydefs.hpp +70 -0
- netgen/include/nginterface.h +474 -0
- netgen/include/nginterface_v2.hpp +406 -0
- netgen/include/nglib.h +697 -0
- netgen/include/nglib_occ.h +50 -0
- netgen/include/occ/occ_edge.hpp +47 -0
- netgen/include/occ/occ_face.hpp +52 -0
- netgen/include/occ/occ_solid.hpp +23 -0
- netgen/include/occ/occ_utils.hpp +376 -0
- netgen/include/occ/occ_vertex.hpp +30 -0
- netgen/include/occ/occgeom.hpp +659 -0
- netgen/include/occ/occmeshsurf.hpp +168 -0
- netgen/include/occ/vsocc.hpp +33 -0
- netgen/include/pybind11/LICENSE +29 -0
- netgen/include/pybind11/attr.h +722 -0
- netgen/include/pybind11/buffer_info.h +208 -0
- netgen/include/pybind11/cast.h +2361 -0
- netgen/include/pybind11/chrono.h +228 -0
- netgen/include/pybind11/common.h +2 -0
- netgen/include/pybind11/complex.h +74 -0
- 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 +823 -0
- netgen/include/pybind11/detail/common.h +1348 -0
- netgen/include/pybind11/detail/cpp_conduit.h +75 -0
- netgen/include/pybind11/detail/descr.h +226 -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 +538 -0
- netgen/include/pybind11/detail/internals.h +799 -0
- 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 +1591 -0
- netgen/include/pybind11/detail/typeid.h +65 -0
- netgen/include/pybind11/detail/using_smart_holder.h +22 -0
- netgen/include/pybind11/detail/value_and_holder.h +90 -0
- netgen/include/pybind11/eigen/common.h +9 -0
- netgen/include/pybind11/eigen/matrix.h +723 -0
- netgen/include/pybind11/eigen/tensor.h +521 -0
- netgen/include/pybind11/eigen.h +12 -0
- netgen/include/pybind11/embed.h +320 -0
- netgen/include/pybind11/eval.h +161 -0
- netgen/include/pybind11/functional.h +147 -0
- netgen/include/pybind11/gil.h +199 -0
- netgen/include/pybind11/gil_safe_call_once.h +102 -0
- netgen/include/pybind11/gil_simple.h +37 -0
- netgen/include/pybind11/iostream.h +265 -0
- netgen/include/pybind11/native_enum.h +67 -0
- netgen/include/pybind11/numpy.h +2312 -0
- netgen/include/pybind11/operators.h +202 -0
- netgen/include/pybind11/options.h +92 -0
- netgen/include/pybind11/pybind11.h +3645 -0
- netgen/include/pybind11/pytypes.h +2680 -0
- netgen/include/pybind11/stl/filesystem.h +114 -0
- netgen/include/pybind11/stl.h +666 -0
- netgen/include/pybind11/stl_bind.h +858 -0
- netgen/include/pybind11/subinterpreter.h +299 -0
- netgen/include/pybind11/trampoline_self_life_support.h +65 -0
- netgen/include/pybind11/type_caster_pyobject_ptr.h +61 -0
- netgen/include/pybind11/typing.h +298 -0
- netgen/include/pybind11/warnings.h +75 -0
- netgen/include/stlgeom/meshstlsurface.hpp +67 -0
- netgen/include/stlgeom/stlgeom.hpp +491 -0
- netgen/include/stlgeom/stlline.hpp +193 -0
- netgen/include/stlgeom/stltool.hpp +331 -0
- netgen/include/stlgeom/stltopology.hpp +419 -0
- netgen/include/stlgeom/vsstl.hpp +58 -0
- netgen/include/visualization/meshdoc.hpp +42 -0
- netgen/include/visualization/mvdraw.hpp +325 -0
- netgen/include/visualization/vispar.hpp +128 -0
- netgen/include/visualization/visual.hpp +28 -0
- netgen/include/visualization/visual_api.hpp +10 -0
- netgen/include/visualization/vssolution.hpp +399 -0
- netgen/lib/libnggui.lib +0 -0
- netgen/lib/ngcore.lib +0 -0
- netgen/lib/nglib.lib +0 -0
- netgen/lib/togl.lib +0 -0
- netgen/libnggui.dll +0 -0
- netgen/libngguipy.lib +0 -0
- netgen/libngguipy.pyd +0 -0
- netgen/libngpy/_NgOCC.pyi +1545 -0
- netgen/libngpy/__init__.pyi +7 -0
- netgen/libngpy/_csg.pyi +259 -0
- netgen/libngpy/_geom2d.pyi +323 -0
- netgen/libngpy/_meshing.pyi +1111 -0
- netgen/libngpy/_stl.pyi +131 -0
- netgen/libngpy.lib +0 -0
- netgen/libngpy.pyd +0 -0
- netgen/meshing.py +65 -0
- netgen/ngcore.dll +0 -0
- netgen/nglib.dll +0 -0
- netgen/occ.py +52 -0
- netgen/read_gmsh.py +259 -0
- netgen/read_meshio.py +22 -0
- netgen/stl.py +2 -0
- netgen/togl.dll +0 -0
- netgen/version.py +2 -0
- netgen/webgui.py +529 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/boundarycondition.geo +16 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/boxcyl.geo +32 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/circle_on_cube.geo +27 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cone.geo +13 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cube.geo +16 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubeandring.geo +55 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubeandspheres.geo +21 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubemcyl.geo +18 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubemsphere.geo +19 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cylinder.geo +12 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cylsphere.geo +12 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/doc/ng4.pdf +0 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/ellipsoid.geo +8 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/ellipticcyl.geo +10 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/extrusion.geo +99 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/fichera.geo +24 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/frame.step +11683 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/hinge.stl +8486 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/lshape3d.geo +26 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/manyholes.geo +26 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/manyholes2.geo +26 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/matrix.geo +27 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/ortho.geo +11 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/part1.stl +2662 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/period.geo +33 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/py_tutorials/exportNeutral.py +26 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/py_tutorials/mesh.py +19 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/py_tutorials/shaft.geo +65 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/revolution.geo +18 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/screw.step +1694 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/sculpture.geo +13 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/shaft.geo +65 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/shell.geo +10 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/sphere.geo +8 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/sphereincube.geo +17 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/square.in2d +35 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/squarecircle.in2d +48 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/squarehole.in2d +47 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/torus.geo +8 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/trafo.geo +57 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/twobricks.geo +15 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/twocubes.geo +18 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/twocyl.geo +16 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/METADATA +15 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/RECORD +340 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/WHEEL +5 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/entry_points.txt +2 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/licenses/AUTHORS +1 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/licenses/LICENSE +504 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/top_level.txt +2 -0
- pyngcore/__init__.py +1 -0
- pyngcore/pyngcore.cp314-win_amd64.pyd +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright (c) 2024 The pybind Community.
|
|
2
|
+
|
|
3
|
+
#pragma once
|
|
4
|
+
|
|
5
|
+
#include <pybind11/pytypes.h>
|
|
6
|
+
|
|
7
|
+
#include "common.h"
|
|
8
|
+
#include "internals.h"
|
|
9
|
+
|
|
10
|
+
#include <typeinfo>
|
|
11
|
+
|
|
12
|
+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
|
13
|
+
PYBIND11_NAMESPACE_BEGIN(detail)
|
|
14
|
+
|
|
15
|
+
// Forward declaration needed here: Refactoring opportunity.
|
|
16
|
+
extern "C" inline PyObject *pybind11_object_new(PyTypeObject *type, PyObject *, PyObject *);
|
|
17
|
+
|
|
18
|
+
inline bool type_is_managed_by_our_internals(PyTypeObject *type_obj) {
|
|
19
|
+
#if defined(PYPY_VERSION)
|
|
20
|
+
auto &internals = get_internals();
|
|
21
|
+
return bool(internals.registered_types_py.find(type_obj)
|
|
22
|
+
!= internals.registered_types_py.end());
|
|
23
|
+
#else
|
|
24
|
+
return bool(type_obj->tp_new == pybind11_object_new);
|
|
25
|
+
#endif
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
inline bool is_instance_method_of_type(PyTypeObject *type_obj, PyObject *attr_name) {
|
|
29
|
+
PyObject *descr = _PyType_Lookup(type_obj, attr_name);
|
|
30
|
+
return bool((descr != nullptr) && PyInstanceMethod_Check(descr));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
inline object try_get_cpp_conduit_method(PyObject *obj) {
|
|
34
|
+
if (PyType_Check(obj)) {
|
|
35
|
+
return object();
|
|
36
|
+
}
|
|
37
|
+
PyTypeObject *type_obj = Py_TYPE(obj);
|
|
38
|
+
str attr_name("_pybind11_conduit_v1_");
|
|
39
|
+
bool assumed_to_be_callable = false;
|
|
40
|
+
if (type_is_managed_by_our_internals(type_obj)) {
|
|
41
|
+
if (!is_instance_method_of_type(type_obj, attr_name.ptr())) {
|
|
42
|
+
return object();
|
|
43
|
+
}
|
|
44
|
+
assumed_to_be_callable = true;
|
|
45
|
+
}
|
|
46
|
+
PyObject *method = PyObject_GetAttr(obj, attr_name.ptr());
|
|
47
|
+
if (method == nullptr) {
|
|
48
|
+
PyErr_Clear();
|
|
49
|
+
return object();
|
|
50
|
+
}
|
|
51
|
+
if (!assumed_to_be_callable && PyCallable_Check(method) == 0) {
|
|
52
|
+
Py_DECREF(method);
|
|
53
|
+
return object();
|
|
54
|
+
}
|
|
55
|
+
return reinterpret_steal<object>(method);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
inline void *try_raw_pointer_ephemeral_from_cpp_conduit(handle src,
|
|
59
|
+
const std::type_info *cpp_type_info) {
|
|
60
|
+
object method = try_get_cpp_conduit_method(src.ptr());
|
|
61
|
+
if (method) {
|
|
62
|
+
capsule cpp_type_info_capsule(const_cast<void *>(static_cast<const void *>(cpp_type_info)),
|
|
63
|
+
typeid(std::type_info).name());
|
|
64
|
+
object cpp_conduit = method(bytes(PYBIND11_PLATFORM_ABI_ID),
|
|
65
|
+
cpp_type_info_capsule,
|
|
66
|
+
bytes("raw_pointer_ephemeral"));
|
|
67
|
+
if (isinstance<capsule>(cpp_conduit)) {
|
|
68
|
+
return reinterpret_borrow<capsule>(cpp_conduit).get_pointer();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return nullptr;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
PYBIND11_NAMESPACE_END(detail)
|
|
75
|
+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/*
|
|
2
|
+
pybind11/detail/descr.h: Helper type for concatenating type signatures at compile time
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
|
|
5
|
+
|
|
6
|
+
All rights reserved. Use of this source code is governed by a
|
|
7
|
+
BSD-style license that can be found in the LICENSE file.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include "common.h"
|
|
13
|
+
|
|
14
|
+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
|
15
|
+
PYBIND11_NAMESPACE_BEGIN(detail)
|
|
16
|
+
|
|
17
|
+
#if !defined(_MSC_VER)
|
|
18
|
+
# define PYBIND11_DESCR_CONSTEXPR static constexpr
|
|
19
|
+
#else
|
|
20
|
+
# define PYBIND11_DESCR_CONSTEXPR const
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
/* Concatenate type signatures at compile time */
|
|
24
|
+
template <size_t N, typename... Ts>
|
|
25
|
+
struct descr {
|
|
26
|
+
char text[N + 1]{'\0'};
|
|
27
|
+
|
|
28
|
+
constexpr descr() = default;
|
|
29
|
+
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
30
|
+
constexpr descr(char const (&s)[N + 1]) : descr(s, make_index_sequence<N>()) {}
|
|
31
|
+
|
|
32
|
+
template <size_t... Is>
|
|
33
|
+
constexpr descr(char const (&s)[N + 1], index_sequence<Is...>) : text{s[Is]..., '\0'} {}
|
|
34
|
+
|
|
35
|
+
template <typename... Chars>
|
|
36
|
+
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
37
|
+
constexpr descr(char c, Chars... cs) : text{c, static_cast<char>(cs)..., '\0'} {}
|
|
38
|
+
|
|
39
|
+
static constexpr std::array<const std::type_info *, sizeof...(Ts) + 1> types() {
|
|
40
|
+
return {{&typeid(Ts)..., nullptr}};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
template <size_t N1, size_t N2, typename... Ts1, typename... Ts2, size_t... Is1, size_t... Is2>
|
|
45
|
+
constexpr descr<N1 + N2, Ts1..., Ts2...> plus_impl(const descr<N1, Ts1...> &a,
|
|
46
|
+
const descr<N2, Ts2...> &b,
|
|
47
|
+
index_sequence<Is1...>,
|
|
48
|
+
index_sequence<Is2...>) {
|
|
49
|
+
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(b);
|
|
50
|
+
return {a.text[Is1]..., b.text[Is2]...};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
template <size_t N1, size_t N2, typename... Ts1, typename... Ts2>
|
|
54
|
+
constexpr descr<N1 + N2, Ts1..., Ts2...> operator+(const descr<N1, Ts1...> &a,
|
|
55
|
+
const descr<N2, Ts2...> &b) {
|
|
56
|
+
return plus_impl(a, b, make_index_sequence<N1>(), make_index_sequence<N2>());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
template <size_t N>
|
|
60
|
+
constexpr descr<N - 1> const_name(char const (&text)[N]) {
|
|
61
|
+
return descr<N - 1>(text);
|
|
62
|
+
}
|
|
63
|
+
constexpr descr<0> const_name(char const (&)[1]) { return {}; }
|
|
64
|
+
|
|
65
|
+
template <size_t Rem, size_t... Digits>
|
|
66
|
+
struct int_to_str : int_to_str<Rem / 10, Rem % 10, Digits...> {};
|
|
67
|
+
template <size_t... Digits>
|
|
68
|
+
struct int_to_str<0, Digits...> {
|
|
69
|
+
// WARNING: This only works with C++17 or higher.
|
|
70
|
+
static constexpr auto digits = descr<sizeof...(Digits)>(('0' + Digits)...);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Ternary description (like std::conditional)
|
|
74
|
+
template <bool B, size_t N1, size_t N2>
|
|
75
|
+
constexpr enable_if_t<B, descr<N1 - 1>> const_name(char const (&text1)[N1], char const (&)[N2]) {
|
|
76
|
+
return const_name(text1);
|
|
77
|
+
}
|
|
78
|
+
template <bool B, size_t N1, size_t N2>
|
|
79
|
+
constexpr enable_if_t<!B, descr<N2 - 1>> const_name(char const (&)[N1], char const (&text2)[N2]) {
|
|
80
|
+
return const_name(text2);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
template <bool B, typename T1, typename T2>
|
|
84
|
+
constexpr enable_if_t<B, T1> const_name(const T1 &d, const T2 &) {
|
|
85
|
+
return d;
|
|
86
|
+
}
|
|
87
|
+
template <bool B, typename T1, typename T2>
|
|
88
|
+
constexpr enable_if_t<!B, T2> const_name(const T1 &, const T2 &d) {
|
|
89
|
+
return d;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
template <size_t Size>
|
|
93
|
+
auto constexpr const_name() -> remove_cv_t<decltype(int_to_str<Size / 10, Size % 10>::digits)> {
|
|
94
|
+
return int_to_str<Size / 10, Size % 10>::digits;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
template <typename Type>
|
|
98
|
+
constexpr descr<1, Type> const_name() {
|
|
99
|
+
return {'%'};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Use a different name based on whether the parameter is used as input or output
|
|
103
|
+
template <size_t N1, size_t N2>
|
|
104
|
+
constexpr descr<N1 + N2 + 1> io_name(char const (&text1)[N1], char const (&text2)[N2]) {
|
|
105
|
+
return const_name("@") + const_name(text1) + const_name("@") + const_name(text2)
|
|
106
|
+
+ const_name("@");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Ternary description for io_name (like the numeric type_caster)
|
|
110
|
+
template <bool B, size_t N1, size_t N2, size_t N3, size_t N4>
|
|
111
|
+
constexpr enable_if_t<B, descr<N1 + N2 + 1>>
|
|
112
|
+
io_name(char const (&text1)[N1], char const (&text2)[N2], char const (&)[N3], char const (&)[N4]) {
|
|
113
|
+
return io_name(text1, text2);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
template <bool B, size_t N1, size_t N2, size_t N3, size_t N4>
|
|
117
|
+
constexpr enable_if_t<!B, descr<N3 + N4 + 1>>
|
|
118
|
+
io_name(char const (&)[N1], char const (&)[N2], char const (&text3)[N3], char const (&text4)[N4]) {
|
|
119
|
+
return io_name(text3, text4);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// If "_" is defined as a macro, py::detail::_ cannot be provided.
|
|
123
|
+
// It is therefore best to use py::detail::const_name universally.
|
|
124
|
+
// This block is for backward compatibility only.
|
|
125
|
+
// (The const_name code is repeated to avoid introducing a "_" #define ourselves.)
|
|
126
|
+
#ifndef _
|
|
127
|
+
# define PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY
|
|
128
|
+
template <size_t N>
|
|
129
|
+
constexpr descr<N - 1> _(char const (&text)[N]) {
|
|
130
|
+
return const_name<N>(text);
|
|
131
|
+
}
|
|
132
|
+
template <bool B, size_t N1, size_t N2>
|
|
133
|
+
constexpr enable_if_t<B, descr<N1 - 1>> _(char const (&text1)[N1], char const (&text2)[N2]) {
|
|
134
|
+
return const_name<B, N1, N2>(text1, text2);
|
|
135
|
+
}
|
|
136
|
+
template <bool B, size_t N1, size_t N2>
|
|
137
|
+
constexpr enable_if_t<!B, descr<N2 - 1>> _(char const (&text1)[N1], char const (&text2)[N2]) {
|
|
138
|
+
return const_name<B, N1, N2>(text1, text2);
|
|
139
|
+
}
|
|
140
|
+
template <bool B, typename T1, typename T2>
|
|
141
|
+
constexpr enable_if_t<B, T1> _(const T1 &d1, const T2 &d2) {
|
|
142
|
+
return const_name<B, T1, T2>(d1, d2);
|
|
143
|
+
}
|
|
144
|
+
template <bool B, typename T1, typename T2>
|
|
145
|
+
constexpr enable_if_t<!B, T2> _(const T1 &d1, const T2 &d2) {
|
|
146
|
+
return const_name<B, T1, T2>(d1, d2);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
template <size_t Size>
|
|
150
|
+
auto constexpr _() -> remove_cv_t<decltype(int_to_str<Size / 10, Size % 10>::digits)> {
|
|
151
|
+
return const_name<Size>();
|
|
152
|
+
}
|
|
153
|
+
template <typename Type>
|
|
154
|
+
constexpr descr<1, Type> _() {
|
|
155
|
+
return const_name<Type>();
|
|
156
|
+
}
|
|
157
|
+
#endif // #ifndef _
|
|
158
|
+
|
|
159
|
+
constexpr descr<0> concat() { return {}; }
|
|
160
|
+
constexpr descr<0> union_concat() { return {}; }
|
|
161
|
+
|
|
162
|
+
template <size_t N, typename... Ts>
|
|
163
|
+
constexpr descr<N, Ts...> concat(const descr<N, Ts...> &descr) {
|
|
164
|
+
return descr;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
template <size_t N, typename... Ts>
|
|
168
|
+
constexpr descr<N, Ts...> union_concat(const descr<N, Ts...> &descr) {
|
|
169
|
+
return descr;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
template <size_t N1, size_t N2, typename... Ts1, typename... Ts2>
|
|
173
|
+
constexpr descr<N1 + N2 + 3, Ts1..., Ts2...> operator|(const descr<N1, Ts1...> &a,
|
|
174
|
+
const descr<N2, Ts2...> &b) {
|
|
175
|
+
return a + const_name(" | ") + b;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
#ifdef __cpp_fold_expressions
|
|
179
|
+
template <size_t N1, size_t N2, typename... Ts1, typename... Ts2>
|
|
180
|
+
constexpr descr<N1 + N2 + 2, Ts1..., Ts2...> operator,(const descr<N1, Ts1...> &a,
|
|
181
|
+
const descr<N2, Ts2...> &b) {
|
|
182
|
+
return a + const_name(", ") + b;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
template <size_t N, typename... Ts, typename... Args>
|
|
186
|
+
constexpr auto concat(const descr<N, Ts...> &d, const Args &...args) {
|
|
187
|
+
return (d, ..., args);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
template <size_t N, typename... Ts, typename... Args>
|
|
191
|
+
constexpr auto union_concat(const descr<N, Ts...> &d, const Args &...args) {
|
|
192
|
+
return (d | ... | args);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
#else
|
|
196
|
+
template <size_t N, typename... Ts, typename... Args>
|
|
197
|
+
constexpr auto concat(const descr<N, Ts...> &d, const Args &...args)
|
|
198
|
+
-> decltype(std::declval<descr<N + 2, Ts...>>() + concat(args...)) {
|
|
199
|
+
return d + const_name(", ") + concat(args...);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
template <size_t N, typename... Ts, typename... Args>
|
|
203
|
+
constexpr auto union_concat(const descr<N, Ts...> &d, const Args &...args)
|
|
204
|
+
-> decltype(std::declval<descr<N + 3, Ts...>>() + union_concat(args...)) {
|
|
205
|
+
return d + const_name(" | ") + union_concat(args...);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
#endif
|
|
209
|
+
|
|
210
|
+
template <size_t N, typename... Ts>
|
|
211
|
+
constexpr descr<N + 2, Ts...> type_descr(const descr<N, Ts...> &descr) {
|
|
212
|
+
return const_name("{") + descr + const_name("}");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
template <size_t N, typename... Ts>
|
|
216
|
+
constexpr descr<N + 4, Ts...> arg_descr(const descr<N, Ts...> &descr) {
|
|
217
|
+
return const_name("@^") + descr + const_name("@!");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
template <size_t N, typename... Ts>
|
|
221
|
+
constexpr descr<N + 4, Ts...> return_descr(const descr<N, Ts...> &descr) {
|
|
222
|
+
return const_name("@$") + descr + const_name("@!");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
PYBIND11_NAMESPACE_END(detail)
|
|
226
|
+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright (c) 2021 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 <type_traits>
|
|
10
|
+
|
|
11
|
+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
|
12
|
+
PYBIND11_NAMESPACE_BEGIN(detail)
|
|
13
|
+
|
|
14
|
+
template <typename To, typename From, typename SFINAE = void>
|
|
15
|
+
struct dynamic_raw_ptr_cast_is_possible : std::false_type {};
|
|
16
|
+
|
|
17
|
+
template <typename To, typename From>
|
|
18
|
+
struct dynamic_raw_ptr_cast_is_possible<
|
|
19
|
+
To,
|
|
20
|
+
From,
|
|
21
|
+
detail::enable_if_t<!std::is_same<To, void>::value && std::is_polymorphic<From>::value>>
|
|
22
|
+
: std::true_type {};
|
|
23
|
+
|
|
24
|
+
template <typename To,
|
|
25
|
+
typename From,
|
|
26
|
+
detail::enable_if_t<!dynamic_raw_ptr_cast_is_possible<To, From>::value, int> = 0>
|
|
27
|
+
To *dynamic_raw_ptr_cast_if_possible(From * /*ptr*/) {
|
|
28
|
+
return nullptr;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
template <typename To,
|
|
32
|
+
typename From,
|
|
33
|
+
detail::enable_if_t<dynamic_raw_ptr_cast_is_possible<To, From>::value, int> = 0>
|
|
34
|
+
To *dynamic_raw_ptr_cast_if_possible(From *ptr) {
|
|
35
|
+
return dynamic_cast<To *>(ptr);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
PYBIND11_NAMESPACE_END(detail)
|
|
39
|
+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
pybind11/detail/exception_translation.h: means to translate C++ exceptions to Python exceptions
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2024 The Pybind Development Team.
|
|
5
|
+
|
|
6
|
+
All rights reserved. Use of this source code is governed by a
|
|
7
|
+
BSD-style license that can be found in the LICENSE file.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include "common.h"
|
|
13
|
+
#include "internals.h"
|
|
14
|
+
|
|
15
|
+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
|
16
|
+
PYBIND11_NAMESPACE_BEGIN(detail)
|
|
17
|
+
|
|
18
|
+
// Apply all the extensions translators from a list
|
|
19
|
+
// Return true if one of the translators completed without raising an exception
|
|
20
|
+
// itself. Return of false indicates that if there are other translators
|
|
21
|
+
// available, they should be tried.
|
|
22
|
+
inline bool apply_exception_translators(std::forward_list<ExceptionTranslator> &translators) {
|
|
23
|
+
auto last_exception = std::current_exception();
|
|
24
|
+
|
|
25
|
+
for (auto &translator : translators) {
|
|
26
|
+
try {
|
|
27
|
+
translator(last_exception);
|
|
28
|
+
return true;
|
|
29
|
+
} catch (...) {
|
|
30
|
+
last_exception = std::current_exception();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
inline void try_translate_exceptions() {
|
|
37
|
+
/* When an exception is caught, give each registered exception
|
|
38
|
+
translator a chance to translate it to a Python exception. First
|
|
39
|
+
all module-local translators will be tried in reverse order of
|
|
40
|
+
registration. If none of the module-locale translators handle
|
|
41
|
+
the exception (or there are no module-locale translators) then
|
|
42
|
+
the global translators will be tried, also in reverse order of
|
|
43
|
+
registration.
|
|
44
|
+
|
|
45
|
+
A translator may choose to do one of the following:
|
|
46
|
+
|
|
47
|
+
- catch the exception and call py::set_error()
|
|
48
|
+
to set a standard (or custom) Python exception, or
|
|
49
|
+
- do nothing and let the exception fall through to the next translator, or
|
|
50
|
+
- delegate translation to the next translator by throwing a new type of exception.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
bool handled = with_exception_translators(
|
|
54
|
+
[&](std::forward_list<ExceptionTranslator> &exception_translators,
|
|
55
|
+
std::forward_list<ExceptionTranslator> &local_exception_translators) {
|
|
56
|
+
if (detail::apply_exception_translators(local_exception_translators)) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (detail::apply_exception_translators(exception_translators)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (!handled) {
|
|
66
|
+
set_error(PyExc_SystemError, "Exception escaped from default exception translator!");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
PYBIND11_NAMESPACE_END(detail)
|
|
71
|
+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// Copyright (c) 2024-2025 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
|
+
// For background see the description of PR google/pybind11clif#30099.
|
|
6
|
+
|
|
7
|
+
#pragma once
|
|
8
|
+
|
|
9
|
+
#include <pybind11/attr.h>
|
|
10
|
+
#include <pybind11/conduit/pybind11_platform_abi_id.h>
|
|
11
|
+
#include <pybind11/pytypes.h>
|
|
12
|
+
|
|
13
|
+
#include "common.h"
|
|
14
|
+
|
|
15
|
+
#include <cstring>
|
|
16
|
+
#include <utility>
|
|
17
|
+
|
|
18
|
+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
|
19
|
+
PYBIND11_NAMESPACE_BEGIN(detail)
|
|
20
|
+
|
|
21
|
+
struct function_record_PyObject {
|
|
22
|
+
PyObject_HEAD
|
|
23
|
+
function_record *cpp_func_rec;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
PYBIND11_NAMESPACE_BEGIN(function_record_PyTypeObject_methods)
|
|
27
|
+
|
|
28
|
+
PyObject *tp_new_impl(PyTypeObject *type, PyObject *args, PyObject *kwds);
|
|
29
|
+
PyObject *tp_alloc_impl(PyTypeObject *type, Py_ssize_t nitems);
|
|
30
|
+
int tp_init_impl(PyObject *self, PyObject *args, PyObject *kwds);
|
|
31
|
+
void tp_dealloc_impl(PyObject *self);
|
|
32
|
+
void tp_free_impl(void *self);
|
|
33
|
+
|
|
34
|
+
static PyObject *reduce_ex_impl(PyObject *self, PyObject *, PyObject *);
|
|
35
|
+
|
|
36
|
+
static PyMethodDef tp_methods_impl[]
|
|
37
|
+
= {{"__reduce_ex__",
|
|
38
|
+
// reduce_ex_impl is a PyCFunctionWithKeywords, but PyMethodDef
|
|
39
|
+
// requires a PyCFunction. The cast through void* is safe and
|
|
40
|
+
// idiomatic with METH_KEYWORDS, and it successfully sidesteps
|
|
41
|
+
// unhelpful compiler warnings.
|
|
42
|
+
// NOLINTNEXTLINE(bugprone-casting-through-void)
|
|
43
|
+
reinterpret_cast<PyCFunction>(reinterpret_cast<void *>(reduce_ex_impl)),
|
|
44
|
+
METH_VARARGS | METH_KEYWORDS,
|
|
45
|
+
nullptr},
|
|
46
|
+
{nullptr, nullptr, 0, nullptr}};
|
|
47
|
+
|
|
48
|
+
// Python 3.12+ emits a DeprecationWarning for heap types whose tp_name does
|
|
49
|
+
// not contain a dot ('.') and that lack a __module__ attribute. For pybind11's
|
|
50
|
+
// internal function_record type, we do not have an actual module object to
|
|
51
|
+
// attach, so we cannot use PyType_FromModuleAndSpec (introduced in Python 3.9)
|
|
52
|
+
// to set __module__ automatically.
|
|
53
|
+
//
|
|
54
|
+
// As a workaround, we define a "qualified" type name that includes a dummy
|
|
55
|
+
// module name (PYBIND11_DUMMY_MODULE_NAME). This is non‑idiomatic but avoids
|
|
56
|
+
// the deprecation warning, and results in reprs like
|
|
57
|
+
//
|
|
58
|
+
// <class 'pybind11_builtins.pybind11_detail_function_record_...'>
|
|
59
|
+
//
|
|
60
|
+
// even though no real pybind11_builtins module exists. If pybind11 gains an
|
|
61
|
+
// actual module object in the future, this code should switch to
|
|
62
|
+
// PyType_FromModuleAndSpec for Python 3.9+ and drop the dummy module
|
|
63
|
+
// workaround.
|
|
64
|
+
//
|
|
65
|
+
// Note that this name is versioned.
|
|
66
|
+
#define PYBIND11_DETAIL_FUNCTION_RECORD_TP_PLAINNAME \
|
|
67
|
+
"pybind11_detail_function_record_" PYBIND11_DETAIL_FUNCTION_RECORD_ABI_ID \
|
|
68
|
+
"_" PYBIND11_PLATFORM_ABI_ID
|
|
69
|
+
constexpr char tp_plainname_impl[] = PYBIND11_DETAIL_FUNCTION_RECORD_TP_PLAINNAME;
|
|
70
|
+
constexpr char tp_qualname_impl[]
|
|
71
|
+
= PYBIND11_DUMMY_MODULE_NAME "." PYBIND11_DETAIL_FUNCTION_RECORD_TP_PLAINNAME;
|
|
72
|
+
|
|
73
|
+
PYBIND11_NAMESPACE_END(function_record_PyTypeObject_methods)
|
|
74
|
+
|
|
75
|
+
static PyType_Slot function_record_PyType_Slots[] = {
|
|
76
|
+
{Py_tp_dealloc,
|
|
77
|
+
reinterpret_cast<void *>(function_record_PyTypeObject_methods::tp_dealloc_impl)},
|
|
78
|
+
{Py_tp_methods,
|
|
79
|
+
reinterpret_cast<void *>(function_record_PyTypeObject_methods::tp_methods_impl)},
|
|
80
|
+
{Py_tp_init, reinterpret_cast<void *>(function_record_PyTypeObject_methods::tp_init_impl)},
|
|
81
|
+
{Py_tp_alloc, reinterpret_cast<void *>(function_record_PyTypeObject_methods::tp_alloc_impl)},
|
|
82
|
+
{Py_tp_new, reinterpret_cast<void *>(function_record_PyTypeObject_methods::tp_new_impl)},
|
|
83
|
+
{Py_tp_free, reinterpret_cast<void *>(function_record_PyTypeObject_methods::tp_free_impl)},
|
|
84
|
+
{0, nullptr}};
|
|
85
|
+
|
|
86
|
+
static PyType_Spec function_record_PyType_Spec
|
|
87
|
+
= {function_record_PyTypeObject_methods::tp_qualname_impl,
|
|
88
|
+
sizeof(function_record_PyObject),
|
|
89
|
+
0,
|
|
90
|
+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
|
|
91
|
+
function_record_PyType_Slots};
|
|
92
|
+
|
|
93
|
+
inline PyTypeObject *get_function_record_PyTypeObject() {
|
|
94
|
+
PyTypeObject *&py_type_obj = detail::get_local_internals().function_record_py_type;
|
|
95
|
+
if (!py_type_obj) {
|
|
96
|
+
PyObject *py_obj = PyType_FromSpec(&function_record_PyType_Spec);
|
|
97
|
+
if (py_obj == nullptr) {
|
|
98
|
+
throw error_already_set();
|
|
99
|
+
}
|
|
100
|
+
py_type_obj = reinterpret_cast<PyTypeObject *>(py_obj);
|
|
101
|
+
}
|
|
102
|
+
return py_type_obj;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
inline bool is_function_record_PyObject(PyObject *obj) {
|
|
106
|
+
if (PyType_Check(obj) != 0) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
PyTypeObject *obj_type = Py_TYPE(obj);
|
|
110
|
+
|
|
111
|
+
PyTypeObject *frtype = get_function_record_PyTypeObject();
|
|
112
|
+
|
|
113
|
+
// Fast path (pointer comparison).
|
|
114
|
+
if (obj_type == frtype) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
// This works across extension modules. Note that tp_name is versioned.
|
|
118
|
+
if (strcmp(obj_type->tp_name, function_record_PyTypeObject_methods::tp_qualname_impl) == 0
|
|
119
|
+
|| strcmp(obj_type->tp_name, function_record_PyTypeObject_methods::tp_plainname_impl)
|
|
120
|
+
== 0) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
inline function_record *function_record_ptr_from_PyObject(PyObject *obj) {
|
|
127
|
+
if (is_function_record_PyObject(obj)) {
|
|
128
|
+
return ((detail::function_record_PyObject *) obj)->cpp_func_rec;
|
|
129
|
+
}
|
|
130
|
+
return nullptr;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
inline object function_record_PyObject_New() {
|
|
134
|
+
auto *py_func_rec = PyObject_New(function_record_PyObject, get_function_record_PyTypeObject());
|
|
135
|
+
if (py_func_rec == nullptr) {
|
|
136
|
+
throw error_already_set();
|
|
137
|
+
}
|
|
138
|
+
py_func_rec->cpp_func_rec = nullptr; // For clarity/purity. Redundant in practice.
|
|
139
|
+
return reinterpret_steal<object>((PyObject *) py_func_rec);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
PYBIND11_NAMESPACE_BEGIN(function_record_PyTypeObject_methods)
|
|
143
|
+
|
|
144
|
+
// Guard against accidents & oversights, in particular when porting to future Python versions.
|
|
145
|
+
inline PyObject *tp_new_impl(PyTypeObject *, PyObject *, PyObject *) {
|
|
146
|
+
pybind11_fail("UNEXPECTED CALL OF function_record_PyTypeObject_methods::tp_new_impl");
|
|
147
|
+
// return nullptr; // Unreachable.
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
inline PyObject *tp_alloc_impl(PyTypeObject *, Py_ssize_t) {
|
|
151
|
+
pybind11_fail("UNEXPECTED CALL OF function_record_PyTypeObject_methods::tp_alloc_impl");
|
|
152
|
+
// return nullptr; // Unreachable.
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
inline int tp_init_impl(PyObject *, PyObject *, PyObject *) {
|
|
156
|
+
pybind11_fail("UNEXPECTED CALL OF function_record_PyTypeObject_methods::tp_init_impl");
|
|
157
|
+
// return -1; // Unreachable.
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
inline void tp_free_impl(void *) {
|
|
161
|
+
pybind11_fail("UNEXPECTED CALL OF function_record_PyTypeObject_methods::tp_free_impl");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
inline PyObject *reduce_ex_impl(PyObject *self, PyObject *, PyObject *) {
|
|
165
|
+
// Deliberately ignoring the arguments for simplicity (expected is `protocol: int`).
|
|
166
|
+
const function_record *rec = function_record_ptr_from_PyObject(self);
|
|
167
|
+
if (rec == nullptr) {
|
|
168
|
+
pybind11_fail(
|
|
169
|
+
"FATAL: function_record_PyTypeObject reduce_ex_impl(): cannot obtain cpp_func_rec.");
|
|
170
|
+
}
|
|
171
|
+
if (rec->name != nullptr && rec->name[0] != '\0' && rec->scope
|
|
172
|
+
&& PyModule_Check(rec->scope.ptr()) != 0) {
|
|
173
|
+
object scope_module = get_scope_module(rec->scope);
|
|
174
|
+
if (scope_module) {
|
|
175
|
+
auto builtins = reinterpret_borrow<dict>(PyEval_GetBuiltins());
|
|
176
|
+
auto builtins_eval = builtins["eval"];
|
|
177
|
+
auto reconstruct_args = make_tuple(str("__import__('importlib').import_module('")
|
|
178
|
+
+ scope_module + str("')"));
|
|
179
|
+
return make_tuple(std::move(builtins_eval), std::move(reconstruct_args))
|
|
180
|
+
.release()
|
|
181
|
+
.ptr();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
set_error(PyExc_RuntimeError, repr(self) + str(" is not pickleable."));
|
|
185
|
+
return nullptr;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
PYBIND11_NAMESPACE_END(function_record_PyTypeObject_methods)
|
|
189
|
+
|
|
190
|
+
PYBIND11_NAMESPACE_END(detail)
|
|
191
|
+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
|