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.
Files changed (340) hide show
  1. netgen/NgOCC.py +7 -0
  2. netgen/__init__.py +114 -0
  3. netgen/__init__.pyi +22 -0
  4. netgen/__main__.py +53 -0
  5. netgen/cmake/NetgenConfig.cmake +79 -0
  6. netgen/cmake/netgen-targets-release.cmake +69 -0
  7. netgen/cmake/netgen-targets.cmake +146 -0
  8. netgen/config/__init__.py +1 -0
  9. netgen/config/__init__.pyi +52 -0
  10. netgen/config/__main__.py +4 -0
  11. netgen/config/config.py +68 -0
  12. netgen/config/config.pyi +54 -0
  13. netgen/csg.py +25 -0
  14. netgen/geom2d.py +178 -0
  15. netgen/gui.py +82 -0
  16. netgen/include/core/archive.hpp +1256 -0
  17. netgen/include/core/array.hpp +1760 -0
  18. netgen/include/core/autodiff.hpp +1131 -0
  19. netgen/include/core/autodiffdiff.hpp +733 -0
  20. netgen/include/core/bitarray.hpp +240 -0
  21. netgen/include/core/concurrentqueue.h +3619 -0
  22. netgen/include/core/exception.hpp +145 -0
  23. netgen/include/core/flags.hpp +199 -0
  24. netgen/include/core/hashtable.hpp +1281 -0
  25. netgen/include/core/localheap.hpp +318 -0
  26. netgen/include/core/logging.hpp +117 -0
  27. netgen/include/core/memtracer.hpp +221 -0
  28. netgen/include/core/mpi4py_pycapi.h +245 -0
  29. netgen/include/core/mpi_wrapper.hpp +643 -0
  30. netgen/include/core/ng_mpi.hpp +94 -0
  31. netgen/include/core/ng_mpi_generated_declarations.hpp +155 -0
  32. netgen/include/core/ng_mpi_native.hpp +25 -0
  33. netgen/include/core/ngcore.hpp +32 -0
  34. netgen/include/core/ngcore_api.hpp +152 -0
  35. netgen/include/core/ngstream.hpp +115 -0
  36. netgen/include/core/paje_trace.hpp +279 -0
  37. netgen/include/core/profiler.hpp +382 -0
  38. netgen/include/core/python_ngcore.hpp +457 -0
  39. netgen/include/core/ranges.hpp +109 -0
  40. netgen/include/core/register_archive.hpp +100 -0
  41. netgen/include/core/signal.hpp +82 -0
  42. netgen/include/core/simd.hpp +160 -0
  43. netgen/include/core/simd_arm64.hpp +407 -0
  44. netgen/include/core/simd_avx.hpp +394 -0
  45. netgen/include/core/simd_avx512.hpp +285 -0
  46. netgen/include/core/simd_generic.hpp +1053 -0
  47. netgen/include/core/simd_math.hpp +178 -0
  48. netgen/include/core/simd_sse.hpp +289 -0
  49. netgen/include/core/statushandler.hpp +37 -0
  50. netgen/include/core/symboltable.hpp +153 -0
  51. netgen/include/core/table.hpp +810 -0
  52. netgen/include/core/taskmanager.hpp +1161 -0
  53. netgen/include/core/type_traits.hpp +65 -0
  54. netgen/include/core/utils.hpp +385 -0
  55. netgen/include/core/version.hpp +102 -0
  56. netgen/include/core/xbool.hpp +47 -0
  57. netgen/include/csg/algprim.hpp +563 -0
  58. netgen/include/csg/brick.hpp +150 -0
  59. netgen/include/csg/csg.hpp +43 -0
  60. netgen/include/csg/csgeom.hpp +389 -0
  61. netgen/include/csg/csgparser.hpp +101 -0
  62. netgen/include/csg/curve2d.hpp +67 -0
  63. netgen/include/csg/edgeflw.hpp +112 -0
  64. netgen/include/csg/explicitcurve2d.hpp +113 -0
  65. netgen/include/csg/extrusion.hpp +185 -0
  66. netgen/include/csg/gencyl.hpp +70 -0
  67. netgen/include/csg/geoml.hpp +16 -0
  68. netgen/include/csg/identify.hpp +213 -0
  69. netgen/include/csg/manifold.hpp +29 -0
  70. netgen/include/csg/meshsurf.hpp +46 -0
  71. netgen/include/csg/polyhedra.hpp +121 -0
  72. netgen/include/csg/revolution.hpp +180 -0
  73. netgen/include/csg/singularref.hpp +84 -0
  74. netgen/include/csg/solid.hpp +295 -0
  75. netgen/include/csg/specpoin.hpp +194 -0
  76. netgen/include/csg/spline3d.hpp +99 -0
  77. netgen/include/csg/splinesurface.hpp +85 -0
  78. netgen/include/csg/surface.hpp +394 -0
  79. netgen/include/csg/triapprox.hpp +63 -0
  80. netgen/include/csg/vscsg.hpp +34 -0
  81. netgen/include/general/autodiff.hpp +356 -0
  82. netgen/include/general/autoptr.hpp +39 -0
  83. netgen/include/general/gzstream.h +121 -0
  84. netgen/include/general/hashtabl.hpp +1692 -0
  85. netgen/include/general/myadt.hpp +48 -0
  86. netgen/include/general/mystring.hpp +226 -0
  87. netgen/include/general/netgenout.hpp +205 -0
  88. netgen/include/general/ngarray.hpp +797 -0
  89. netgen/include/general/ngbitarray.hpp +149 -0
  90. netgen/include/general/ngpython.hpp +74 -0
  91. netgen/include/general/optmem.hpp +44 -0
  92. netgen/include/general/parthreads.hpp +138 -0
  93. netgen/include/general/seti.hpp +50 -0
  94. netgen/include/general/sort.hpp +47 -0
  95. netgen/include/general/spbita2d.hpp +59 -0
  96. netgen/include/general/stack.hpp +114 -0
  97. netgen/include/general/table.hpp +280 -0
  98. netgen/include/general/template.hpp +509 -0
  99. netgen/include/geom2d/csg2d.hpp +750 -0
  100. netgen/include/geom2d/geometry2d.hpp +280 -0
  101. netgen/include/geom2d/spline2d.hpp +234 -0
  102. netgen/include/geom2d/vsgeom2d.hpp +28 -0
  103. netgen/include/gprim/adtree.hpp +1392 -0
  104. netgen/include/gprim/geom2d.hpp +858 -0
  105. netgen/include/gprim/geom3d.hpp +749 -0
  106. netgen/include/gprim/geomfuncs.hpp +212 -0
  107. netgen/include/gprim/geomobjects.hpp +544 -0
  108. netgen/include/gprim/geomops.hpp +404 -0
  109. netgen/include/gprim/geomtest3d.hpp +101 -0
  110. netgen/include/gprim/gprim.hpp +33 -0
  111. netgen/include/gprim/spline.hpp +778 -0
  112. netgen/include/gprim/splinegeometry.hpp +73 -0
  113. netgen/include/gprim/transform3d.hpp +216 -0
  114. netgen/include/include/acisgeom.hpp +3 -0
  115. netgen/include/include/csg.hpp +1 -0
  116. netgen/include/include/geometry2d.hpp +1 -0
  117. netgen/include/include/gprim.hpp +1 -0
  118. netgen/include/include/incopengl.hpp +62 -0
  119. netgen/include/include/inctcl.hpp +13 -0
  120. netgen/include/include/incvis.hpp +6 -0
  121. netgen/include/include/linalg.hpp +1 -0
  122. netgen/include/include/meshing.hpp +1 -0
  123. netgen/include/include/myadt.hpp +1 -0
  124. netgen/include/include/mydefs.hpp +70 -0
  125. netgen/include/include/mystdlib.h +59 -0
  126. netgen/include/include/netgen_config.hpp +27 -0
  127. netgen/include/include/netgen_version.hpp +9 -0
  128. netgen/include/include/nginterface_v2_impl.hpp +395 -0
  129. netgen/include/include/ngsimd.hpp +1 -0
  130. netgen/include/include/occgeom.hpp +1 -0
  131. netgen/include/include/opti.hpp +1 -0
  132. netgen/include/include/parallel.hpp +1 -0
  133. netgen/include/include/stlgeom.hpp +1 -0
  134. netgen/include/include/visual.hpp +1 -0
  135. netgen/include/interface/rw_medit.hpp +11 -0
  136. netgen/include/interface/writeuser.hpp +80 -0
  137. netgen/include/linalg/densemat.hpp +414 -0
  138. netgen/include/linalg/linalg.hpp +29 -0
  139. netgen/include/linalg/opti.hpp +142 -0
  140. netgen/include/linalg/polynomial.hpp +47 -0
  141. netgen/include/linalg/vector.hpp +217 -0
  142. netgen/include/meshing/adfront2.hpp +274 -0
  143. netgen/include/meshing/adfront3.hpp +332 -0
  144. netgen/include/meshing/basegeom.hpp +370 -0
  145. netgen/include/meshing/bcfunctions.hpp +53 -0
  146. netgen/include/meshing/bisect.hpp +72 -0
  147. netgen/include/meshing/boundarylayer.hpp +113 -0
  148. netgen/include/meshing/classifyhpel.hpp +1984 -0
  149. netgen/include/meshing/clusters.hpp +46 -0
  150. netgen/include/meshing/curvedelems.hpp +274 -0
  151. netgen/include/meshing/delaunay2d.hpp +73 -0
  152. netgen/include/meshing/fieldlines.hpp +103 -0
  153. netgen/include/meshing/findip.hpp +198 -0
  154. netgen/include/meshing/findip2.hpp +103 -0
  155. netgen/include/meshing/geomsearch.hpp +69 -0
  156. netgen/include/meshing/global.hpp +54 -0
  157. netgen/include/meshing/hpref_hex.hpp +330 -0
  158. netgen/include/meshing/hpref_prism.hpp +3405 -0
  159. netgen/include/meshing/hpref_pyramid.hpp +154 -0
  160. netgen/include/meshing/hpref_quad.hpp +2082 -0
  161. netgen/include/meshing/hpref_segm.hpp +122 -0
  162. netgen/include/meshing/hpref_tet.hpp +4230 -0
  163. netgen/include/meshing/hpref_trig.hpp +848 -0
  164. netgen/include/meshing/hprefinement.hpp +366 -0
  165. netgen/include/meshing/improve2.hpp +178 -0
  166. netgen/include/meshing/improve3.hpp +151 -0
  167. netgen/include/meshing/localh.hpp +223 -0
  168. netgen/include/meshing/meshclass.hpp +1076 -0
  169. netgen/include/meshing/meshfunc.hpp +47 -0
  170. netgen/include/meshing/meshing.hpp +63 -0
  171. netgen/include/meshing/meshing2.hpp +163 -0
  172. netgen/include/meshing/meshing3.hpp +123 -0
  173. netgen/include/meshing/meshtool.hpp +90 -0
  174. netgen/include/meshing/meshtype.hpp +1930 -0
  175. netgen/include/meshing/msghandler.hpp +62 -0
  176. netgen/include/meshing/paralleltop.hpp +172 -0
  177. netgen/include/meshing/python_mesh.hpp +206 -0
  178. netgen/include/meshing/ruler2.hpp +172 -0
  179. netgen/include/meshing/ruler3.hpp +211 -0
  180. netgen/include/meshing/soldata.hpp +141 -0
  181. netgen/include/meshing/specials.hpp +17 -0
  182. netgen/include/meshing/surfacegeom.hpp +73 -0
  183. netgen/include/meshing/topology.hpp +1003 -0
  184. netgen/include/meshing/validate.hpp +21 -0
  185. netgen/include/meshing/visual_interface.hpp +71 -0
  186. netgen/include/mydefs.hpp +70 -0
  187. netgen/include/nginterface.h +474 -0
  188. netgen/include/nginterface_v2.hpp +406 -0
  189. netgen/include/nglib.h +697 -0
  190. netgen/include/nglib_occ.h +50 -0
  191. netgen/include/occ/occ_edge.hpp +47 -0
  192. netgen/include/occ/occ_face.hpp +52 -0
  193. netgen/include/occ/occ_solid.hpp +23 -0
  194. netgen/include/occ/occ_utils.hpp +376 -0
  195. netgen/include/occ/occ_vertex.hpp +30 -0
  196. netgen/include/occ/occgeom.hpp +659 -0
  197. netgen/include/occ/occmeshsurf.hpp +168 -0
  198. netgen/include/occ/vsocc.hpp +33 -0
  199. netgen/include/pybind11/LICENSE +29 -0
  200. netgen/include/pybind11/attr.h +722 -0
  201. netgen/include/pybind11/buffer_info.h +208 -0
  202. netgen/include/pybind11/cast.h +2361 -0
  203. netgen/include/pybind11/chrono.h +228 -0
  204. netgen/include/pybind11/common.h +2 -0
  205. netgen/include/pybind11/complex.h +74 -0
  206. netgen/include/pybind11/conduit/README.txt +15 -0
  207. netgen/include/pybind11/conduit/pybind11_conduit_v1.h +116 -0
  208. netgen/include/pybind11/conduit/pybind11_platform_abi_id.h +87 -0
  209. netgen/include/pybind11/conduit/wrap_include_python_h.h +72 -0
  210. netgen/include/pybind11/critical_section.h +56 -0
  211. netgen/include/pybind11/detail/class.h +823 -0
  212. netgen/include/pybind11/detail/common.h +1348 -0
  213. netgen/include/pybind11/detail/cpp_conduit.h +75 -0
  214. netgen/include/pybind11/detail/descr.h +226 -0
  215. netgen/include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h +39 -0
  216. netgen/include/pybind11/detail/exception_translation.h +71 -0
  217. netgen/include/pybind11/detail/function_record_pyobject.h +191 -0
  218. netgen/include/pybind11/detail/init.h +538 -0
  219. netgen/include/pybind11/detail/internals.h +799 -0
  220. netgen/include/pybind11/detail/native_enum_data.h +209 -0
  221. netgen/include/pybind11/detail/pybind11_namespace_macros.h +82 -0
  222. netgen/include/pybind11/detail/struct_smart_holder.h +378 -0
  223. netgen/include/pybind11/detail/type_caster_base.h +1591 -0
  224. netgen/include/pybind11/detail/typeid.h +65 -0
  225. netgen/include/pybind11/detail/using_smart_holder.h +22 -0
  226. netgen/include/pybind11/detail/value_and_holder.h +90 -0
  227. netgen/include/pybind11/eigen/common.h +9 -0
  228. netgen/include/pybind11/eigen/matrix.h +723 -0
  229. netgen/include/pybind11/eigen/tensor.h +521 -0
  230. netgen/include/pybind11/eigen.h +12 -0
  231. netgen/include/pybind11/embed.h +320 -0
  232. netgen/include/pybind11/eval.h +161 -0
  233. netgen/include/pybind11/functional.h +147 -0
  234. netgen/include/pybind11/gil.h +199 -0
  235. netgen/include/pybind11/gil_safe_call_once.h +102 -0
  236. netgen/include/pybind11/gil_simple.h +37 -0
  237. netgen/include/pybind11/iostream.h +265 -0
  238. netgen/include/pybind11/native_enum.h +67 -0
  239. netgen/include/pybind11/numpy.h +2312 -0
  240. netgen/include/pybind11/operators.h +202 -0
  241. netgen/include/pybind11/options.h +92 -0
  242. netgen/include/pybind11/pybind11.h +3645 -0
  243. netgen/include/pybind11/pytypes.h +2680 -0
  244. netgen/include/pybind11/stl/filesystem.h +114 -0
  245. netgen/include/pybind11/stl.h +666 -0
  246. netgen/include/pybind11/stl_bind.h +858 -0
  247. netgen/include/pybind11/subinterpreter.h +299 -0
  248. netgen/include/pybind11/trampoline_self_life_support.h +65 -0
  249. netgen/include/pybind11/type_caster_pyobject_ptr.h +61 -0
  250. netgen/include/pybind11/typing.h +298 -0
  251. netgen/include/pybind11/warnings.h +75 -0
  252. netgen/include/stlgeom/meshstlsurface.hpp +67 -0
  253. netgen/include/stlgeom/stlgeom.hpp +491 -0
  254. netgen/include/stlgeom/stlline.hpp +193 -0
  255. netgen/include/stlgeom/stltool.hpp +331 -0
  256. netgen/include/stlgeom/stltopology.hpp +419 -0
  257. netgen/include/stlgeom/vsstl.hpp +58 -0
  258. netgen/include/visualization/meshdoc.hpp +42 -0
  259. netgen/include/visualization/mvdraw.hpp +325 -0
  260. netgen/include/visualization/vispar.hpp +128 -0
  261. netgen/include/visualization/visual.hpp +28 -0
  262. netgen/include/visualization/visual_api.hpp +10 -0
  263. netgen/include/visualization/vssolution.hpp +399 -0
  264. netgen/lib/libnggui.lib +0 -0
  265. netgen/lib/ngcore.lib +0 -0
  266. netgen/lib/nglib.lib +0 -0
  267. netgen/lib/togl.lib +0 -0
  268. netgen/libnggui.dll +0 -0
  269. netgen/libngguipy.lib +0 -0
  270. netgen/libngguipy.pyd +0 -0
  271. netgen/libngpy/_NgOCC.pyi +1545 -0
  272. netgen/libngpy/__init__.pyi +7 -0
  273. netgen/libngpy/_csg.pyi +259 -0
  274. netgen/libngpy/_geom2d.pyi +323 -0
  275. netgen/libngpy/_meshing.pyi +1111 -0
  276. netgen/libngpy/_stl.pyi +131 -0
  277. netgen/libngpy.lib +0 -0
  278. netgen/libngpy.pyd +0 -0
  279. netgen/meshing.py +65 -0
  280. netgen/ngcore.dll +0 -0
  281. netgen/nglib.dll +0 -0
  282. netgen/occ.py +52 -0
  283. netgen/read_gmsh.py +259 -0
  284. netgen/read_meshio.py +22 -0
  285. netgen/stl.py +2 -0
  286. netgen/togl.dll +0 -0
  287. netgen/version.py +2 -0
  288. netgen/webgui.py +529 -0
  289. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/boundarycondition.geo +16 -0
  290. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/boxcyl.geo +32 -0
  291. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/circle_on_cube.geo +27 -0
  292. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cone.geo +13 -0
  293. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cube.geo +16 -0
  294. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubeandring.geo +55 -0
  295. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubeandspheres.geo +21 -0
  296. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubemcyl.geo +18 -0
  297. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubemsphere.geo +19 -0
  298. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cylinder.geo +12 -0
  299. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cylsphere.geo +12 -0
  300. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/doc/ng4.pdf +0 -0
  301. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/ellipsoid.geo +8 -0
  302. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/ellipticcyl.geo +10 -0
  303. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/extrusion.geo +99 -0
  304. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/fichera.geo +24 -0
  305. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/frame.step +11683 -0
  306. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/hinge.stl +8486 -0
  307. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/lshape3d.geo +26 -0
  308. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/manyholes.geo +26 -0
  309. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/manyholes2.geo +26 -0
  310. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/matrix.geo +27 -0
  311. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/ortho.geo +11 -0
  312. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/part1.stl +2662 -0
  313. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/period.geo +33 -0
  314. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/py_tutorials/exportNeutral.py +26 -0
  315. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/py_tutorials/mesh.py +19 -0
  316. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/py_tutorials/shaft.geo +65 -0
  317. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/revolution.geo +18 -0
  318. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/screw.step +1694 -0
  319. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/sculpture.geo +13 -0
  320. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/shaft.geo +65 -0
  321. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/shell.geo +10 -0
  322. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/sphere.geo +8 -0
  323. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/sphereincube.geo +17 -0
  324. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/square.in2d +35 -0
  325. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/squarecircle.in2d +48 -0
  326. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/squarehole.in2d +47 -0
  327. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/torus.geo +8 -0
  328. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/trafo.geo +57 -0
  329. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/twobricks.geo +15 -0
  330. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/twocubes.geo +18 -0
  331. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/twocyl.geo +16 -0
  332. netgen_mesher-6.2.2506.post35.dev0.dist-info/METADATA +15 -0
  333. netgen_mesher-6.2.2506.post35.dev0.dist-info/RECORD +340 -0
  334. netgen_mesher-6.2.2506.post35.dev0.dist-info/WHEEL +5 -0
  335. netgen_mesher-6.2.2506.post35.dev0.dist-info/entry_points.txt +2 -0
  336. netgen_mesher-6.2.2506.post35.dev0.dist-info/licenses/AUTHORS +1 -0
  337. netgen_mesher-6.2.2506.post35.dev0.dist-info/licenses/LICENSE +504 -0
  338. netgen_mesher-6.2.2506.post35.dev0.dist-info/top_level.txt +2 -0
  339. pyngcore/__init__.py +1 -0
  340. pyngcore/pyngcore.cp314-win_amd64.pyd +0 -0
@@ -0,0 +1,209 @@
1
+ // Copyright (c) 2022-2025 The pybind Community.
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 "../pytypes.h"
8
+ #include "common.h"
9
+ #include "internals.h"
10
+
11
+ #include <cassert>
12
+ #include <sstream>
13
+ #include <string>
14
+ #include <typeindex>
15
+
16
+ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
17
+ PYBIND11_NAMESPACE_BEGIN(detail)
18
+
19
+ // This is a separate function only to enable easy unit testing.
20
+ inline std::string
21
+ native_enum_missing_finalize_error_message(const std::string &enum_name_encoded) {
22
+ return "pybind11::native_enum<...>(\"" + enum_name_encoded + "\", ...): MISSING .finalize()";
23
+ }
24
+
25
+ class native_enum_data {
26
+ public:
27
+ native_enum_data(const object &parent_scope,
28
+ const char *enum_name,
29
+ const char *native_type_name,
30
+ const char *class_doc,
31
+ const std::type_index &enum_type_index)
32
+ : enum_name_encoded{enum_name}, native_type_name_encoded{native_type_name},
33
+ enum_type_index{enum_type_index}, parent_scope(parent_scope), enum_name{enum_name},
34
+ native_type_name{native_type_name}, class_doc(class_doc), export_values_flag{false},
35
+ finalize_needed{false} {}
36
+
37
+ void finalize();
38
+
39
+ native_enum_data(const native_enum_data &) = delete;
40
+ native_enum_data &operator=(const native_enum_data &) = delete;
41
+
42
+ #if !defined(NDEBUG)
43
+ // This dtor cannot easily be unit tested because it terminates the process.
44
+ ~native_enum_data() {
45
+ if (finalize_needed) {
46
+ pybind11_fail(native_enum_missing_finalize_error_message(enum_name_encoded));
47
+ }
48
+ }
49
+ #endif
50
+
51
+ protected:
52
+ void disarm_finalize_check(const char *error_context) {
53
+ if (!finalize_needed) {
54
+ pybind11_fail("pybind11::native_enum<...>(\"" + enum_name_encoded
55
+ + "\"): " + error_context);
56
+ }
57
+ finalize_needed = false;
58
+ }
59
+
60
+ void arm_finalize_check() {
61
+ assert(!finalize_needed); // Catch redundant calls.
62
+ finalize_needed = true;
63
+ }
64
+
65
+ std::string enum_name_encoded;
66
+ std::string native_type_name_encoded;
67
+ std::type_index enum_type_index;
68
+
69
+ private:
70
+ object parent_scope;
71
+ str enum_name;
72
+ str native_type_name;
73
+ std::string class_doc;
74
+
75
+ protected:
76
+ list members;
77
+ list member_docs;
78
+ bool export_values_flag : 1; // Attention: It is best to keep the bools together.
79
+
80
+ private:
81
+ bool finalize_needed : 1;
82
+ };
83
+
84
+ inline void global_internals_native_enum_type_map_set_item(const std::type_index &enum_type_index,
85
+ PyObject *py_enum) {
86
+ with_internals(
87
+ [&](internals &internals) { internals.native_enum_type_map[enum_type_index] = py_enum; });
88
+ }
89
+
90
+ inline handle
91
+ global_internals_native_enum_type_map_get_item(const std::type_index &enum_type_index) {
92
+ return with_internals([&](internals &internals) {
93
+ auto found = internals.native_enum_type_map.find(enum_type_index);
94
+ if (found != internals.native_enum_type_map.end()) {
95
+ return handle(found->second);
96
+ }
97
+ return handle();
98
+ });
99
+ }
100
+
101
+ inline bool
102
+ global_internals_native_enum_type_map_contains(const std::type_index &enum_type_index) {
103
+ return with_internals([&](internals &internals) {
104
+ return internals.native_enum_type_map.count(enum_type_index) != 0;
105
+ });
106
+ }
107
+
108
+ inline object import_or_getattr(const std::string &fully_qualified_name,
109
+ const std::string &append_to_exception_message) {
110
+ std::istringstream stream(fully_qualified_name);
111
+ std::string part;
112
+
113
+ if (!std::getline(stream, part, '.') || part.empty()) {
114
+ std::string msg = "Invalid fully-qualified name `";
115
+ msg += fully_qualified_name;
116
+ msg += "`";
117
+ msg += append_to_exception_message;
118
+ throw value_error(msg);
119
+ }
120
+
121
+ auto curr_scope = reinterpret_steal<object>(PyImport_ImportModule(part.c_str()));
122
+ if (!curr_scope) {
123
+ std::string msg = "Failed to import top-level module `";
124
+ msg += part;
125
+ msg += "`";
126
+ msg += append_to_exception_message;
127
+ raise_from(PyExc_ImportError, msg.c_str());
128
+ throw error_already_set();
129
+ }
130
+
131
+ // Now recursively getattr or import remaining parts
132
+ std::string curr_path = part;
133
+ while (std::getline(stream, part, '.')) {
134
+ if (part.empty()) {
135
+ std::string msg = "Invalid fully-qualified name `";
136
+ msg += fully_qualified_name;
137
+ msg += "`";
138
+ msg += append_to_exception_message;
139
+ throw value_error(msg);
140
+ }
141
+ std::string next_path = curr_path;
142
+ next_path += ".";
143
+ next_path += part;
144
+ auto next_scope
145
+ = reinterpret_steal<object>(PyObject_GetAttrString(curr_scope.ptr(), part.c_str()));
146
+ if (!next_scope) {
147
+ error_fetch_and_normalize stored_getattr_error("getattr");
148
+ // Try importing the next level
149
+ next_scope = reinterpret_steal<object>(PyImport_ImportModule(next_path.c_str()));
150
+ if (!next_scope) {
151
+ error_fetch_and_normalize stored_import_error("import");
152
+ std::string msg = "Failed to import or getattr `";
153
+ msg += part;
154
+ msg += "` from `";
155
+ msg += curr_path;
156
+ msg += "`";
157
+ msg += append_to_exception_message;
158
+ msg += "\n-------- getattr exception --------\n";
159
+ msg += stored_getattr_error.error_string();
160
+ msg += "\n-------- import exception --------\n";
161
+ msg += stored_import_error.error_string();
162
+ throw import_error(msg.c_str());
163
+ }
164
+ }
165
+ curr_scope = next_scope;
166
+ curr_path = next_path;
167
+ }
168
+ return curr_scope;
169
+ }
170
+
171
+ inline void native_enum_data::finalize() {
172
+ disarm_finalize_check("DOUBLE finalize");
173
+ if (hasattr(parent_scope, enum_name)) {
174
+ pybind11_fail("pybind11::native_enum<...>(\"" + enum_name_encoded
175
+ + "\"): an object with that name is already defined");
176
+ }
177
+ auto py_enum_type = import_or_getattr(native_type_name, " (native_type_name)");
178
+ auto py_enum = py_enum_type(enum_name, members);
179
+ object module_name = get_module_name_if_available(parent_scope);
180
+ if (module_name) {
181
+ py_enum.attr("__module__") = module_name;
182
+ }
183
+ if (hasattr(parent_scope, "__qualname__")) {
184
+ const auto parent_qualname = parent_scope.attr("__qualname__").cast<std::string>();
185
+ py_enum.attr("__qualname__") = str(parent_qualname + "." + enum_name.cast<std::string>());
186
+ }
187
+ parent_scope.attr(enum_name) = py_enum;
188
+ if (export_values_flag) {
189
+ for (auto member : members) {
190
+ auto member_name = member[int_(0)];
191
+ if (hasattr(parent_scope, member_name)) {
192
+ pybind11_fail("pybind11::native_enum<...>(\"" + enum_name_encoded + "\").value(\""
193
+ + member_name.cast<std::string>()
194
+ + "\"): an object with that name is already defined");
195
+ }
196
+ parent_scope.attr(member_name) = py_enum[member_name];
197
+ }
198
+ }
199
+ if (!class_doc.empty()) {
200
+ py_enum.attr("__doc__") = class_doc.c_str();
201
+ }
202
+ for (auto doc : member_docs) {
203
+ py_enum[doc[int_(0)]].attr("__doc__") = doc[int_(1)];
204
+ }
205
+ global_internals_native_enum_type_map_set_item(enum_type_index, py_enum.release().ptr());
206
+ }
207
+
208
+ PYBIND11_NAMESPACE_END(detail)
209
+ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
@@ -0,0 +1,82 @@
1
+ // Copyright (c) 2016-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
+ #pragma once
6
+
7
+ // PLEASE DO NOT ADD ANY INCLUDES HERE
8
+
9
+ // Define some generic pybind11 helper macros for warning management.
10
+ //
11
+ // Note that compiler-specific push/pop pairs are baked into the
12
+ // PYBIND11_NAMESPACE_BEGIN/PYBIND11_NAMESPACE_END pair of macros. Therefore manual
13
+ // PYBIND11_WARNING_PUSH/PYBIND11_WARNING_POP are usually only needed in `#include` sections.
14
+ //
15
+ // If you find you need to suppress a warning, please try to make the suppression as local as
16
+ // possible using these macros. Please also be sure to push/pop with the pybind11 macros. Please
17
+ // only use compiler specifics if you need to check specific versions, e.g. Apple Clang vs. vanilla
18
+ // Clang.
19
+ #if defined(_MSC_VER)
20
+ # define PYBIND11_COMPILER_MSVC
21
+ # define PYBIND11_PRAGMA(...) __pragma(__VA_ARGS__)
22
+ # define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning(push))
23
+ # define PYBIND11_WARNING_POP PYBIND11_PRAGMA(warning(pop))
24
+ #elif defined(__INTEL_COMPILER)
25
+ # define PYBIND11_COMPILER_INTEL
26
+ # define PYBIND11_PRAGMA(...) _Pragma(#__VA_ARGS__)
27
+ # define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning push)
28
+ # define PYBIND11_WARNING_POP PYBIND11_PRAGMA(warning pop)
29
+ #elif defined(__clang__)
30
+ # define PYBIND11_COMPILER_CLANG
31
+ # define PYBIND11_PRAGMA(...) _Pragma(#__VA_ARGS__)
32
+ # define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(clang diagnostic push)
33
+ # define PYBIND11_WARNING_POP PYBIND11_PRAGMA(clang diagnostic pop)
34
+ #elif defined(__GNUC__)
35
+ # define PYBIND11_COMPILER_GCC
36
+ # define PYBIND11_PRAGMA(...) _Pragma(#__VA_ARGS__)
37
+ # define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(GCC diagnostic push)
38
+ # define PYBIND11_WARNING_POP PYBIND11_PRAGMA(GCC diagnostic pop)
39
+ #endif
40
+
41
+ #ifdef PYBIND11_COMPILER_MSVC
42
+ # define PYBIND11_WARNING_DISABLE_MSVC(name) PYBIND11_PRAGMA(warning(disable : name))
43
+ #else
44
+ # define PYBIND11_WARNING_DISABLE_MSVC(name)
45
+ #endif
46
+
47
+ #ifdef PYBIND11_COMPILER_CLANG
48
+ # define PYBIND11_WARNING_DISABLE_CLANG(name) PYBIND11_PRAGMA(clang diagnostic ignored name)
49
+ #else
50
+ # define PYBIND11_WARNING_DISABLE_CLANG(name)
51
+ #endif
52
+
53
+ #ifdef PYBIND11_COMPILER_GCC
54
+ # define PYBIND11_WARNING_DISABLE_GCC(name) PYBIND11_PRAGMA(GCC diagnostic ignored name)
55
+ #else
56
+ # define PYBIND11_WARNING_DISABLE_GCC(name)
57
+ #endif
58
+
59
+ #ifdef PYBIND11_COMPILER_INTEL
60
+ # define PYBIND11_WARNING_DISABLE_INTEL(name) PYBIND11_PRAGMA(warning disable name)
61
+ #else
62
+ # define PYBIND11_WARNING_DISABLE_INTEL(name)
63
+ #endif
64
+
65
+ #define PYBIND11_NAMESPACE_BEGIN(name) \
66
+ namespace name { \
67
+ PYBIND11_WARNING_PUSH
68
+
69
+ #define PYBIND11_NAMESPACE_END(name) \
70
+ PYBIND11_WARNING_POP \
71
+ }
72
+
73
+ // Robust support for some features and loading modules compiled against different pybind versions
74
+ // requires forcing hidden visibility on pybind code, so we enforce this by setting the attribute
75
+ // on the main `pybind11` namespace.
76
+ #if !defined(PYBIND11_NAMESPACE)
77
+ # if defined(__GNUG__) && !defined(_WIN32)
78
+ # define PYBIND11_NAMESPACE pybind11 __attribute__((visibility("hidden")))
79
+ # else
80
+ # define PYBIND11_NAMESPACE pybind11
81
+ # endif
82
+ #endif
@@ -0,0 +1,378 @@
1
+ // Copyright (c) 2020-2024 The Pybind Development Team.
2
+ // All rights reserved. Use of this source code is governed by a
3
+ // BSD-style license that can be found in the LICENSE file.
4
+
5
+ /* Proof-of-Concept for smart pointer interoperability.
6
+
7
+ High-level aspects:
8
+
9
+ * Support all `unique_ptr`, `shared_ptr` interops that are feasible.
10
+
11
+ * Cleanly and clearly report all interops that are infeasible.
12
+
13
+ * Meant to fit into a `PyObject`, as a holder for C++ objects.
14
+
15
+ * Support a system design that makes it impossible to trigger
16
+ C++ Undefined Behavior, especially from Python.
17
+
18
+ * Support a system design with clean runtime inheritance casting. From this
19
+ it follows that the `smart_holder` needs to be type-erased (`void*`).
20
+
21
+ * Handling of RTTI for the type-erased held pointer is NOT implemented here.
22
+ It is the responsibility of the caller to ensure that `static_cast<T *>`
23
+ is well-formed when calling `as_*` member functions. Inheritance casting
24
+ needs to be handled in a different layer (similar to the code organization
25
+ in boost/python/object/inheritance.hpp).
26
+
27
+ Details:
28
+
29
+ * The "root holder" chosen here is a `shared_ptr<void>` (named `vptr` in this
30
+ implementation). This choice is practically inevitable because `shared_ptr`
31
+ has only very limited support for inspecting and accessing its deleter.
32
+
33
+ * If created from a raw pointer, or a `unique_ptr` without a custom deleter,
34
+ `vptr` always uses a custom deleter, to support `unique_ptr`-like disowning.
35
+ The custom deleters could be extended to included life-time management for
36
+ external objects (e.g. `PyObject`).
37
+
38
+ * If created from an external `shared_ptr`, or a `unique_ptr` with a custom
39
+ deleter, including life-time management for external objects is infeasible.
40
+
41
+ * By choice, the smart_holder is movable but not copyable, to keep the design
42
+ simple, and to guard against accidental copying overhead.
43
+
44
+ * The `void_cast_raw_ptr` option is needed to make the `smart_holder` `vptr`
45
+ member invisible to the `shared_from_this` mechanism, in case the lifetime
46
+ of a `PyObject` is tied to the pointee.
47
+ */
48
+
49
+ #pragma once
50
+
51
+ #include "pybind11_namespace_macros.h"
52
+
53
+ #include <cstring>
54
+ #include <functional>
55
+ #include <memory>
56
+ #include <stdexcept>
57
+ #include <string>
58
+ #include <type_traits>
59
+ #include <typeinfo>
60
+ #include <utility>
61
+
62
+ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
63
+ PYBIND11_NAMESPACE_BEGIN(memory)
64
+
65
+ // Default fallback.
66
+ static constexpr bool type_has_shared_from_this(...) { return false; }
67
+
68
+ // This overload uses SFINAE to skip enable_shared_from_this checks when the
69
+ // base is inaccessible (e.g. private inheritance).
70
+ template <typename T>
71
+ static auto type_has_shared_from_this(const T *ptr)
72
+ -> decltype(static_cast<const std::enable_shared_from_this<T> *>(ptr), true) {
73
+ return true;
74
+ }
75
+
76
+ // Inaccessible base → substitution failure → fallback overload selected
77
+ template <typename T>
78
+ static constexpr bool type_has_shared_from_this(const void *) {
79
+ return false;
80
+ }
81
+
82
+ struct guarded_delete {
83
+ // NOTE: PYBIND11_INTERNALS_VERSION needs to be bumped if changes are made to this struct.
84
+ std::weak_ptr<void> released_ptr; // Trick to keep the smart_holder memory footprint small.
85
+ std::function<void(void *)> del_fun; // Rare case.
86
+ void (*del_ptr)(void *); // Common case.
87
+ bool use_del_fun;
88
+ bool armed_flag;
89
+ guarded_delete(std::function<void(void *)> &&del_fun, bool armed_flag)
90
+ : del_fun{std::move(del_fun)}, del_ptr{nullptr}, use_del_fun{true},
91
+ armed_flag{armed_flag} {}
92
+ guarded_delete(void (*del_ptr)(void *), bool armed_flag)
93
+ : del_ptr{del_ptr}, use_del_fun{false}, armed_flag{armed_flag} {}
94
+ void operator()(void *raw_ptr) const {
95
+ if (armed_flag) {
96
+ if (use_del_fun) {
97
+ del_fun(raw_ptr);
98
+ } else {
99
+ del_ptr(raw_ptr);
100
+ }
101
+ }
102
+ }
103
+ };
104
+
105
+ inline guarded_delete *get_guarded_delete(const std::shared_ptr<void> &ptr) {
106
+ return std::get_deleter<guarded_delete>(ptr);
107
+ }
108
+
109
+ using get_guarded_delete_fn = guarded_delete *(*) (const std::shared_ptr<void> &);
110
+
111
+ template <typename T, typename std::enable_if<std::is_destructible<T>::value, int>::type = 0>
112
+ inline void std_default_delete_if_destructible(void *raw_ptr) {
113
+ std::default_delete<T>{}(static_cast<T *>(raw_ptr));
114
+ }
115
+
116
+ template <typename T, typename std::enable_if<!std::is_destructible<T>::value, int>::type = 0>
117
+ inline void std_default_delete_if_destructible(void *) {
118
+ // This noop operator is needed to avoid a compilation error (for `delete raw_ptr;`), but
119
+ // throwing an exception from a destructor will std::terminate the process. Therefore the
120
+ // runtime check for lifetime-management correctness is implemented elsewhere (in
121
+ // ensure_pointee_is_destructible()).
122
+ }
123
+
124
+ template <typename T>
125
+ guarded_delete make_guarded_std_default_delete(bool armed_flag) {
126
+ return guarded_delete(std_default_delete_if_destructible<T>, armed_flag);
127
+ }
128
+
129
+ template <typename T, typename D>
130
+ struct custom_deleter {
131
+ // NOTE: PYBIND11_INTERNALS_VERSION needs to be bumped if changes are made to this struct.
132
+ D deleter;
133
+ explicit custom_deleter(D &&deleter) : deleter{std::forward<D>(deleter)} {}
134
+ void operator()(void *raw_ptr) { deleter(static_cast<T *>(raw_ptr)); }
135
+ };
136
+
137
+ template <typename T, typename D>
138
+ guarded_delete make_guarded_custom_deleter(D &&uqp_del, bool armed_flag) {
139
+ return guarded_delete(
140
+ std::function<void(void *)>(custom_deleter<T, D>(std::forward<D>(uqp_del))), armed_flag);
141
+ }
142
+
143
+ template <typename T, typename D>
144
+ constexpr bool uqp_del_is_std_default_delete() {
145
+ return std::is_same<D, std::default_delete<T>>::value
146
+ || std::is_same<D, std::default_delete<T const>>::value;
147
+ }
148
+
149
+ inline bool type_info_equal_across_dso_boundaries(const std::type_info &a,
150
+ const std::type_info &b) {
151
+ // RTTI pointer comparison may fail across DSOs (e.g., macOS libc++).
152
+ // Fallback to name comparison, which is generally safe and ABI-stable enough for our use.
153
+ return a == b || std::strcmp(a.name(), b.name()) == 0;
154
+ }
155
+
156
+ struct smart_holder {
157
+ // NOTE: PYBIND11_INTERNALS_VERSION needs to be bumped if changes are made to this struct.
158
+ const std::type_info *rtti_uqp_del = nullptr;
159
+ std::shared_ptr<void> vptr;
160
+ bool vptr_is_using_noop_deleter : 1;
161
+ bool vptr_is_using_std_default_delete : 1;
162
+ bool vptr_is_external_shared_ptr : 1;
163
+ bool is_populated : 1;
164
+ bool is_disowned : 1;
165
+
166
+ // Design choice: smart_holder is movable but not copyable.
167
+ smart_holder(smart_holder &&) = default;
168
+ smart_holder(const smart_holder &) = delete;
169
+ smart_holder &operator=(smart_holder &&) = delete;
170
+ smart_holder &operator=(const smart_holder &) = delete;
171
+
172
+ smart_holder()
173
+ : vptr_is_using_noop_deleter{false}, vptr_is_using_std_default_delete{false},
174
+ vptr_is_external_shared_ptr{false}, is_populated{false}, is_disowned{false} {}
175
+
176
+ bool has_pointee() const { return vptr != nullptr; }
177
+
178
+ template <typename T>
179
+ static void ensure_pointee_is_destructible(const char *context) {
180
+ if (!std::is_destructible<T>::value) {
181
+ throw std::invalid_argument(std::string("Pointee is not destructible (") + context
182
+ + ").");
183
+ }
184
+ }
185
+
186
+ void ensure_is_populated(const char *context) const {
187
+ if (!is_populated) {
188
+ throw std::runtime_error(std::string("Unpopulated holder (") + context + ").");
189
+ }
190
+ }
191
+ void ensure_is_not_disowned(const char *context) const {
192
+ if (is_disowned) {
193
+ throw std::runtime_error(std::string("Holder was disowned already (") + context
194
+ + ").");
195
+ }
196
+ }
197
+
198
+ void ensure_vptr_is_using_std_default_delete(const char *context) const {
199
+ if (vptr_is_external_shared_ptr) {
200
+ throw std::invalid_argument(std::string("Cannot disown external shared_ptr (")
201
+ + context + ").");
202
+ }
203
+ if (vptr_is_using_noop_deleter) {
204
+ throw std::invalid_argument(std::string("Cannot disown non-owning holder (") + context
205
+ + ").");
206
+ }
207
+ if (!vptr_is_using_std_default_delete) {
208
+ throw std::invalid_argument(std::string("Cannot disown custom deleter (") + context
209
+ + ").");
210
+ }
211
+ }
212
+
213
+ template <typename T, typename D>
214
+ void ensure_compatible_uqp_del(const char *context) const {
215
+ if (!rtti_uqp_del) {
216
+ if (!uqp_del_is_std_default_delete<T, D>()) {
217
+ throw std::invalid_argument(std::string("Missing unique_ptr deleter (") + context
218
+ + ").");
219
+ }
220
+ ensure_vptr_is_using_std_default_delete(context);
221
+ return;
222
+ }
223
+ if (uqp_del_is_std_default_delete<T, D>() && vptr_is_using_std_default_delete) {
224
+ return;
225
+ }
226
+ if (!type_info_equal_across_dso_boundaries(typeid(D), *rtti_uqp_del)) {
227
+ throw std::invalid_argument(std::string("Incompatible unique_ptr deleter (") + context
228
+ + ").");
229
+ }
230
+ }
231
+
232
+ void ensure_has_pointee(const char *context) const {
233
+ if (!has_pointee()) {
234
+ throw std::invalid_argument(std::string("Disowned holder (") + context + ").");
235
+ }
236
+ }
237
+
238
+ void ensure_use_count_1(const char *context) const {
239
+ if (vptr == nullptr) {
240
+ throw std::invalid_argument(std::string("Cannot disown nullptr (") + context + ").");
241
+ }
242
+ // In multithreaded environments accessing use_count can lead to
243
+ // race conditions, but in the context of Python it is a bug (elsewhere)
244
+ // if the Global Interpreter Lock (GIL) is not being held when this code
245
+ // is reached.
246
+ // PYBIND11:REMINDER: This may need to be protected by a mutex in free-threaded Python.
247
+ if (vptr.use_count() != 1) {
248
+ throw std::invalid_argument(std::string("Cannot disown use_count != 1 (") + context
249
+ + ").");
250
+ }
251
+ }
252
+
253
+ void reset_vptr_deleter_armed_flag(const get_guarded_delete_fn ggd_fn, bool armed_flag) const {
254
+ auto *gd = ggd_fn(vptr);
255
+ if (gd == nullptr) {
256
+ throw std::runtime_error(
257
+ "smart_holder::reset_vptr_deleter_armed_flag() called in an invalid context.");
258
+ }
259
+ gd->armed_flag = armed_flag;
260
+ }
261
+
262
+ // Caller is responsible for precondition: ensure_compatible_uqp_del<T, D>() must succeed.
263
+ template <typename T, typename D>
264
+ std::unique_ptr<D> extract_deleter(const char *context,
265
+ const get_guarded_delete_fn ggd_fn) const {
266
+ auto *gd = ggd_fn(vptr);
267
+ if (gd && gd->use_del_fun) {
268
+ const auto &custom_deleter_ptr = gd->del_fun.template target<custom_deleter<T, D>>();
269
+ if (custom_deleter_ptr == nullptr) {
270
+ throw std::runtime_error(
271
+ std::string("smart_holder::extract_deleter() precondition failure (") + context
272
+ + ").");
273
+ }
274
+ static_assert(std::is_copy_constructible<D>::value,
275
+ "Required for compatibility with smart_holder functionality.");
276
+ return std::unique_ptr<D>(new D(custom_deleter_ptr->deleter));
277
+ }
278
+ return nullptr;
279
+ }
280
+
281
+ static smart_holder from_raw_ptr_unowned(void *raw_ptr) {
282
+ smart_holder hld;
283
+ hld.vptr.reset(raw_ptr, [](void *) {});
284
+ hld.vptr_is_using_noop_deleter = true;
285
+ hld.is_populated = true;
286
+ return hld;
287
+ }
288
+
289
+ template <typename T>
290
+ T *as_raw_ptr_unowned() const {
291
+ return static_cast<T *>(vptr.get());
292
+ }
293
+
294
+ template <typename T>
295
+ static smart_holder from_raw_ptr_take_ownership(T *raw_ptr, bool void_cast_raw_ptr = false) {
296
+ ensure_pointee_is_destructible<T>("from_raw_ptr_take_ownership");
297
+ smart_holder hld;
298
+ auto gd = make_guarded_std_default_delete<T>(true);
299
+ if (void_cast_raw_ptr) {
300
+ hld.vptr.reset(static_cast<void *>(raw_ptr), std::move(gd));
301
+ } else {
302
+ hld.vptr.reset(raw_ptr, std::move(gd));
303
+ }
304
+ hld.vptr_is_using_std_default_delete = true;
305
+ hld.is_populated = true;
306
+ return hld;
307
+ }
308
+
309
+ // Caller is responsible for ensuring the complex preconditions
310
+ // (see `smart_holder_type_caster_support::load_helper`).
311
+ void disown(const get_guarded_delete_fn ggd_fn) {
312
+ reset_vptr_deleter_armed_flag(ggd_fn, false);
313
+ is_disowned = true;
314
+ }
315
+
316
+ // Caller is responsible for ensuring the complex preconditions
317
+ // (see `smart_holder_type_caster_support::load_helper`).
318
+ void reclaim_disowned(const get_guarded_delete_fn ggd_fn) {
319
+ reset_vptr_deleter_armed_flag(ggd_fn, true);
320
+ is_disowned = false;
321
+ }
322
+
323
+ // Caller is responsible for ensuring the complex preconditions
324
+ // (see `smart_holder_type_caster_support::load_helper`).
325
+ void release_disowned() { vptr.reset(); }
326
+
327
+ void ensure_can_release_ownership(const char *context = "ensure_can_release_ownership") const {
328
+ ensure_is_not_disowned(context);
329
+ ensure_vptr_is_using_std_default_delete(context);
330
+ ensure_use_count_1(context);
331
+ }
332
+
333
+ // Caller is responsible for ensuring the complex preconditions
334
+ // (see `smart_holder_type_caster_support::load_helper`).
335
+ void release_ownership(const get_guarded_delete_fn ggd_fn) {
336
+ reset_vptr_deleter_armed_flag(ggd_fn, false);
337
+ release_disowned();
338
+ }
339
+
340
+ template <typename T, typename D>
341
+ static smart_holder from_unique_ptr(std::unique_ptr<T, D> &&unq_ptr,
342
+ void *void_ptr = nullptr) {
343
+ smart_holder hld;
344
+ hld.rtti_uqp_del = &typeid(D);
345
+ hld.vptr_is_using_std_default_delete = uqp_del_is_std_default_delete<T, D>();
346
+ guarded_delete gd{nullptr, false};
347
+ if (hld.vptr_is_using_std_default_delete) {
348
+ gd = make_guarded_std_default_delete<T>(true);
349
+ } else {
350
+ gd = make_guarded_custom_deleter<T, D>(std::move(unq_ptr.get_deleter()), true);
351
+ }
352
+ if (void_ptr != nullptr) {
353
+ hld.vptr.reset(void_ptr, std::move(gd));
354
+ } else {
355
+ hld.vptr.reset(unq_ptr.get(), std::move(gd));
356
+ }
357
+ (void) unq_ptr.release();
358
+ hld.is_populated = true;
359
+ return hld;
360
+ }
361
+
362
+ template <typename T>
363
+ static smart_holder from_shared_ptr(const std::shared_ptr<T> &shd_ptr) {
364
+ smart_holder hld;
365
+ hld.vptr = std::static_pointer_cast<void>(shd_ptr);
366
+ hld.vptr_is_external_shared_ptr = true;
367
+ hld.is_populated = true;
368
+ return hld;
369
+ }
370
+
371
+ template <typename T>
372
+ std::shared_ptr<T> as_shared_ptr() const {
373
+ return std::static_pointer_cast<T>(vptr);
374
+ }
375
+ };
376
+
377
+ PYBIND11_NAMESPACE_END(memory)
378
+ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)