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,1348 @@
1
+ /*
2
+ pybind11/detail/common.h -- Basic macros
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 <pybind11/conduit/wrap_include_python_h.h>
13
+ #if PY_VERSION_HEX < 0x03080000
14
+ # error "PYTHON < 3.8 IS UNSUPPORTED. pybind11 v2.13 was the last to support Python 3.7."
15
+ #endif
16
+
17
+ // Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html
18
+ // See also: https://github.com/python/cpython/blob/HEAD/Include/patchlevel.h
19
+ /* -- start version constants -- */
20
+ #define PYBIND11_VERSION_MAJOR 3
21
+ #define PYBIND11_VERSION_MINOR 0
22
+ #define PYBIND11_VERSION_MICRO 1
23
+ // ALPHA = 0xA, BETA = 0xB, GAMMA = 0xC (release candidate), FINAL = 0xF (stable release)
24
+ // - The release level is set to "alpha" for development versions.
25
+ // Use 0xA0 (LEVEL=0xA, SERIAL=0) for development versions.
26
+ // - For stable releases, set the serial to 0.
27
+ #define PYBIND11_VERSION_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL
28
+ #define PYBIND11_VERSION_RELEASE_SERIAL 0
29
+ // String version of (micro, release level, release serial), e.g.: 0a0, 0b1, 0rc1, 0
30
+ #define PYBIND11_VERSION_PATCH 1
31
+ /* -- end version constants -- */
32
+
33
+ #if !defined(Py_PACK_FULL_VERSION)
34
+ // Stable API since Python 3.14.0a4
35
+ # define Py_PACK_FULL_VERSION(X, Y, Z, LEVEL, SERIAL) \
36
+ ((((X) & 0xff) << 24) | (((Y) & 0xff) << 16) | (((Z) & 0xff) << 8) \
37
+ | (((LEVEL) & 0xf) << 4) | (((SERIAL) & 0xf) << 0))
38
+ #endif
39
+ // Version as a single 4-byte hex number, e.g. 0x030C04B5 == 3.12.4b5.
40
+ #define PYBIND11_VERSION_HEX \
41
+ Py_PACK_FULL_VERSION(PYBIND11_VERSION_MAJOR, \
42
+ PYBIND11_VERSION_MINOR, \
43
+ PYBIND11_VERSION_MICRO, \
44
+ PYBIND11_VERSION_RELEASE_LEVEL, \
45
+ PYBIND11_VERSION_RELEASE_SERIAL)
46
+
47
+ #include "pybind11_namespace_macros.h"
48
+
49
+ #if !(defined(_MSC_VER) && __cplusplus == 199711L)
50
+ # if __cplusplus >= 201402L
51
+ # define PYBIND11_CPP14
52
+ # if __cplusplus >= 201703L
53
+ # define PYBIND11_CPP17
54
+ # if __cplusplus >= 202002L
55
+ # define PYBIND11_CPP20
56
+ // Please update tests/pybind11_tests.cpp `cpp_std()` when adding a macro here.
57
+ # endif
58
+ # endif
59
+ # endif
60
+ #elif defined(_MSC_VER) && __cplusplus == 199711L
61
+ // MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully
62
+ // implemented). Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3
63
+ // or newer.
64
+ # if _MSVC_LANG >= 201402L
65
+ # define PYBIND11_CPP14
66
+ # if _MSVC_LANG > 201402L
67
+ # define PYBIND11_CPP17
68
+ # if _MSVC_LANG >= 202002L
69
+ # define PYBIND11_CPP20
70
+ # endif
71
+ # endif
72
+ # endif
73
+ #endif
74
+
75
+ // These PYBIND11_HAS_... macros are consolidated in pybind11/detail/common.h
76
+ // to simplify backward compatibility handling for users (e.g., via #ifdef checks):
77
+ #define PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS 1
78
+ #define PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT 1
79
+ #define PYBIND11_HAS_CPP_CONDUIT 1
80
+ #define PYBIND11_HAS_NATIVE_ENUM 1
81
+
82
+ #if defined(PYBIND11_CPP17) && defined(__has_include)
83
+ # if __has_include(<filesystem>)
84
+ # define PYBIND11_HAS_FILESYSTEM 1
85
+ # elif __has_include(<experimental/filesystem>)
86
+ # define PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM 1
87
+ # endif
88
+ #endif
89
+
90
+ #if defined(__cpp_lib_launder) && !(defined(_MSC_VER) && (_MSC_VER < 1914))
91
+ # define PYBIND11_STD_LAUNDER std::launder
92
+ # define PYBIND11_HAS_STD_LAUNDER 1
93
+ #else
94
+ # define PYBIND11_STD_LAUNDER
95
+ # define PYBIND11_HAS_STD_LAUNDER 0
96
+ #endif
97
+
98
+ #if defined(PYBIND11_CPP20)
99
+ # define PYBIND11_CONSTINIT constinit
100
+ # define PYBIND11_DTOR_CONSTEXPR constexpr
101
+ #else
102
+ # define PYBIND11_CONSTINIT
103
+ # define PYBIND11_DTOR_CONSTEXPR
104
+ #endif
105
+
106
+ // Compiler version assertions
107
+ #if defined(__INTEL_COMPILER)
108
+ # if __INTEL_COMPILER < 1800
109
+ # error pybind11 requires Intel C++ compiler v18 or newer
110
+ # elif __INTEL_COMPILER < 1900 && defined(PYBIND11_CPP14)
111
+ # error pybind11 supports only C++11 with Intel C++ compiler v18. Use v19 or newer for C++14.
112
+ # endif
113
+ /* The following pragma cannot be pop'ed:
114
+ https://community.intel.com/t5/Intel-C-Compiler/Inline-and-no-inline-warning/td-p/1216764 */
115
+ # pragma warning disable 2196 // warning #2196: routine is both "inline" and "noinline"
116
+ #elif defined(__clang__) && !defined(__apple_build_version__)
117
+ # if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 3)
118
+ # error pybind11 requires clang 3.3 or newer
119
+ # endif
120
+ #elif defined(__clang__)
121
+ // Apple changes clang version macros to its Xcode version; the first Xcode release based on
122
+ // (upstream) clang 3.3 was Xcode 5:
123
+ # if __clang_major__ < 5
124
+ # error pybind11 requires Xcode/clang 5.0 or newer
125
+ # endif
126
+ #elif defined(__GNUG__)
127
+ # if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
128
+ # error pybind11 requires gcc 4.8 or newer
129
+ # endif
130
+ #elif defined(_MSC_VER)
131
+ # if _MSC_VER < 1910
132
+ # error pybind11 2.10+ requires MSVC 2017 or newer
133
+ # endif
134
+ #endif
135
+
136
+ #if !defined(PYBIND11_EXPORT)
137
+ # if defined(WIN32) || defined(_WIN32)
138
+ # define PYBIND11_EXPORT __declspec(dllexport)
139
+ # else
140
+ # define PYBIND11_EXPORT __attribute__((visibility("default")))
141
+ # endif
142
+ #endif
143
+
144
+ // For CUDA, GCC7, GCC8:
145
+ // PYBIND11_NOINLINE_FORCED is incompatible with `-Wattributes -Werror`.
146
+ // When defining PYBIND11_NOINLINE_FORCED, it is best to also use `-Wno-attributes`.
147
+ // However, the measured shared-library size saving when using noinline are only
148
+ // 1.7% for CUDA, -0.2% for GCC7, and 0.0% for GCC8 (using -DCMAKE_BUILD_TYPE=MinSizeRel,
149
+ // the default under pybind11/tests).
150
+ #if !defined(PYBIND11_NOINLINE_FORCED) \
151
+ && (defined(__CUDACC__) || (defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8)))
152
+ # define PYBIND11_NOINLINE_DISABLED
153
+ #endif
154
+
155
+ // The PYBIND11_NOINLINE macro is for function DEFINITIONS.
156
+ // In contrast, FORWARD DECLARATIONS should never use this macro:
157
+ // https://stackoverflow.com/questions/9317473/forward-declaration-of-inline-functions
158
+ #if defined(PYBIND11_NOINLINE_DISABLED) // Option for maximum portability and experimentation.
159
+ # define PYBIND11_NOINLINE inline
160
+ #elif defined(_MSC_VER)
161
+ # define PYBIND11_NOINLINE __declspec(noinline) inline
162
+ #else
163
+ # define PYBIND11_NOINLINE __attribute__((noinline)) inline
164
+ #endif
165
+
166
+ #if defined(__MINGW32__)
167
+ // For unknown reasons all PYBIND11_DEPRECATED member trigger a warning when declared
168
+ // whether it is used or not
169
+ # define PYBIND11_DEPRECATED(reason)
170
+ #elif defined(PYBIND11_CPP14)
171
+ # define PYBIND11_DEPRECATED(reason) [[deprecated(reason)]]
172
+ #else
173
+ # define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason)))
174
+ #endif
175
+
176
+ #if defined(PYBIND11_CPP17)
177
+ # define PYBIND11_MAYBE_UNUSED [[maybe_unused]]
178
+ #elif defined(_MSC_VER) && !defined(__clang__)
179
+ # define PYBIND11_MAYBE_UNUSED
180
+ #else
181
+ # define PYBIND11_MAYBE_UNUSED __attribute__((__unused__))
182
+ #endif
183
+
184
+ // https://en.cppreference.com/w/c/chrono/localtime
185
+ #if defined(__STDC_LIB_EXT1__) && !defined(__STDC_WANT_LIB_EXT1__)
186
+ # define __STDC_WANT_LIB_EXT1__
187
+ #endif
188
+
189
+ #ifdef __has_include
190
+ // std::optional (but including it in c++14 mode isn't allowed)
191
+ # if defined(PYBIND11_CPP17) && __has_include(<optional>)
192
+ # define PYBIND11_HAS_OPTIONAL 1
193
+ # endif
194
+ // std::experimental::optional (but not allowed in c++11 mode)
195
+ # if defined(PYBIND11_CPP14) && (__has_include(<experimental/optional>) && \
196
+ !__has_include(<optional>))
197
+ # define PYBIND11_HAS_EXP_OPTIONAL 1
198
+ # endif
199
+ // std::variant
200
+ # if defined(PYBIND11_CPP17) && __has_include(<variant>)
201
+ # define PYBIND11_HAS_VARIANT 1
202
+ # endif
203
+ #elif defined(_MSC_VER) && defined(PYBIND11_CPP17)
204
+ # define PYBIND11_HAS_OPTIONAL 1
205
+ # define PYBIND11_HAS_VARIANT 1
206
+ #endif
207
+
208
+ #if defined(PYBIND11_CPP17) \
209
+ && ((defined(__has_include) && __has_include(<string_view>)) || defined(_MSC_VER))
210
+ # define PYBIND11_HAS_STRING_VIEW 1
211
+ #endif
212
+
213
+ #if (defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
214
+ # define PYBIND11_SIMPLE_GIL_MANAGEMENT
215
+ #endif
216
+
217
+ #include <cstddef>
218
+ #include <cstring>
219
+ #include <exception>
220
+ #include <forward_list>
221
+ #include <memory>
222
+ #include <stdexcept>
223
+ #include <string>
224
+ #include <type_traits>
225
+ #include <typeindex>
226
+ #include <unordered_map>
227
+ #include <unordered_set>
228
+ #include <vector>
229
+ #if defined(__has_include)
230
+ # if __has_include(<version>)
231
+ # include <version>
232
+ # endif
233
+ #endif
234
+
235
+ // For libc++, the exceptions should be exported,
236
+ // otherwise, the exception translation would be incorrect.
237
+ // IMPORTANT: This code block must stay BELOW the #include <exception> above (see PR #5390).
238
+ #if !defined(PYBIND11_EXPORT_EXCEPTION)
239
+ # if defined(_LIBCPP_EXCEPTION)
240
+ # define PYBIND11_EXPORT_EXCEPTION PYBIND11_EXPORT
241
+ # else
242
+ # define PYBIND11_EXPORT_EXCEPTION
243
+ # endif
244
+ #endif
245
+
246
+ // Must be after including <version> or one of the other headers specified by the standard
247
+ #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
248
+ # define PYBIND11_HAS_U8STRING 1
249
+ #endif
250
+
251
+ // See description of PR #4246:
252
+ #if !defined(PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF) && !defined(NDEBUG) \
253
+ && !defined(PYPY_VERSION) && !defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF)
254
+ # define PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
255
+ #endif
256
+
257
+ // Slightly faster code paths are available when PYBIND11_HAS_SUBINTERPRETER_SUPPORT is *not*
258
+ // defined, so avoid defining it for implementations that do not support subinterpreters. However,
259
+ // defining it unnecessarily is not expected to break anything.
260
+ // This can be overridden by the user with -DPYBIND11_HAS_SUBINTERPRETER_SUPPORT=1 or 0
261
+ #ifndef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
262
+ # if PY_VERSION_HEX >= 0x030C0000 && !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON)
263
+ # define PYBIND11_HAS_SUBINTERPRETER_SUPPORT 1
264
+ # endif
265
+ #else
266
+ # if PYBIND11_HAS_SUBINTERPRETER_SUPPORT == 0
267
+ # undef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
268
+ # endif
269
+ #endif
270
+
271
+ // 3.13 Compatibility
272
+ #if 0x030D0000 <= PY_VERSION_HEX
273
+ # define PYBIND11_TYPE_IS_TYPE_HINT "typing.TypeIs"
274
+ # define PYBIND11_CAPSULE_TYPE_TYPE_HINT "types.CapsuleType"
275
+ #else
276
+ # define PYBIND11_TYPE_IS_TYPE_HINT "typing_extensions.TypeIs"
277
+ # define PYBIND11_CAPSULE_TYPE_TYPE_HINT "typing_extensions.CapsuleType"
278
+ #endif
279
+
280
+ // 3.12 Compatibility
281
+ #if 0x030C0000 <= PY_VERSION_HEX
282
+ # define PYBIND11_BUFFER_TYPE_HINT "collections.abc.Buffer"
283
+ #else
284
+ # define PYBIND11_BUFFER_TYPE_HINT "typing_extensions.Buffer"
285
+ #endif
286
+
287
+ // 3.11 Compatibility
288
+ #if 0x030B0000 <= PY_VERSION_HEX
289
+ # define PYBIND11_NEVER_TYPE_HINT "typing.Never"
290
+ #else
291
+ # define PYBIND11_NEVER_TYPE_HINT "typing_extensions.Never"
292
+ #endif
293
+
294
+ // 3.10 Compatibility
295
+ #if 0x030A0000 <= PY_VERSION_HEX
296
+ # define PYBIND11_TYPE_GUARD_TYPE_HINT "typing.TypeGuard"
297
+ #else
298
+ # define PYBIND11_TYPE_GUARD_TYPE_HINT "typing_extensions.TypeGuard"
299
+ #endif
300
+
301
+ // #define PYBIND11_STR_LEGACY_PERMISSIVE
302
+ // If DEFINED, pybind11::str can hold PyUnicodeObject or PyBytesObject
303
+ // (probably surprising and never documented, but this was the
304
+ // legacy behavior until and including v2.6.x). As a side-effect,
305
+ // pybind11::isinstance<str>() is true for both pybind11::str and
306
+ // pybind11::bytes.
307
+ // If UNDEFINED, pybind11::str can only hold PyUnicodeObject, and
308
+ // pybind11::isinstance<str>() is true only for pybind11::str.
309
+ // However, for Python 2 only (!), the pybind11::str caster
310
+ // implicitly decoded bytes to PyUnicodeObject. This was to ease
311
+ // the transition from the legacy behavior to the non-permissive
312
+ // behavior.
313
+
314
+ /// Compatibility macros for Python 2 / Python 3 versions TODO: remove
315
+ #define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyInstanceMethod_New(ptr)
316
+ #define PYBIND11_INSTANCE_METHOD_CHECK PyInstanceMethod_Check
317
+ #define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyInstanceMethod_GET_FUNCTION
318
+ #define PYBIND11_BYTES_CHECK PyBytes_Check
319
+ #define PYBIND11_BYTES_FROM_STRING PyBytes_FromString
320
+ #define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyBytes_FromStringAndSize
321
+ #define PYBIND11_BYTES_AS_STRING_AND_SIZE PyBytes_AsStringAndSize
322
+ #define PYBIND11_BYTES_AS_STRING PyBytes_AsString
323
+ #define PYBIND11_BYTES_SIZE PyBytes_Size
324
+ #define PYBIND11_LONG_CHECK(o) PyLong_Check(o)
325
+ #define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o)
326
+ #define PYBIND11_LONG_FROM_SIGNED(o) PyLong_FromSsize_t((ssize_t) (o))
327
+ #define PYBIND11_LONG_FROM_UNSIGNED(o) PyLong_FromSize_t((size_t) (o))
328
+ #define PYBIND11_BYTES_NAME "bytes"
329
+ #define PYBIND11_STRING_NAME "str"
330
+ #define PYBIND11_SLICE_OBJECT PyObject
331
+ #define PYBIND11_FROM_STRING PyUnicode_FromString
332
+ #define PYBIND11_STR_TYPE ::pybind11::str
333
+ #define PYBIND11_BOOL_ATTR "__bool__"
334
+ #define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_bool)
335
+ #define PYBIND11_BUILTINS_MODULE "builtins"
336
+ // Providing a separate declaration to make Clang's -Wmissing-prototypes happy.
337
+ // See comment for PYBIND11_MODULE below for why this is marked "maybe unused".
338
+ #define PYBIND11_PLUGIN_DECL(name) \
339
+ extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT PyObject *PyInit_##name();
340
+ #define PYBIND11_PLUGIN_IMPL(name) \
341
+ PYBIND11_PLUGIN_DECL(name) \
342
+ extern "C" PYBIND11_EXPORT PyObject *PyInit_##name()
343
+
344
+ #define PYBIND11_TRY_NEXT_OVERLOAD ((PyObject *) 1) // special failure return code
345
+ #define PYBIND11_STRINGIFY(x) #x
346
+ #define PYBIND11_TOSTRING(x) PYBIND11_STRINGIFY(x)
347
+ #define PYBIND11_CONCAT(first, second) first##second
348
+ #define PYBIND11_ENSURE_INTERNALS_READY \
349
+ { \
350
+ pybind11::detail::get_internals_pp_manager().unref(); \
351
+ pybind11::detail::get_internals(); \
352
+ }
353
+
354
+ #if !defined(GRAALVM_PYTHON)
355
+ # define PYBIND11_PYCFUNCTION_GET_DOC(func) ((func)->m_ml->ml_doc)
356
+ # define PYBIND11_PYCFUNCTION_SET_DOC(func, doc) \
357
+ do { \
358
+ (func)->m_ml->ml_doc = (doc); \
359
+ } while (0)
360
+ #else
361
+ # define PYBIND11_PYCFUNCTION_GET_DOC(func) (GraalPyCFunction_GetDoc((PyObject *) (func)))
362
+ # define PYBIND11_PYCFUNCTION_SET_DOC(func, doc) \
363
+ do { \
364
+ GraalPyCFunction_SetDoc((PyObject *) (func), (doc)); \
365
+ } while (0)
366
+ #endif
367
+
368
+ #define PYBIND11_CHECK_PYTHON_VERSION \
369
+ { \
370
+ const char *compiled_ver \
371
+ = PYBIND11_TOSTRING(PY_MAJOR_VERSION) "." PYBIND11_TOSTRING(PY_MINOR_VERSION); \
372
+ const char *runtime_ver = Py_GetVersion(); \
373
+ size_t len = std::strlen(compiled_ver); \
374
+ if (std::strncmp(runtime_ver, compiled_ver, len) != 0 \
375
+ || (runtime_ver[len] >= '0' && runtime_ver[len] <= '9')) { \
376
+ PyErr_Format(PyExc_ImportError, \
377
+ "Python version mismatch: module was compiled for Python %s, " \
378
+ "but the interpreter version is incompatible: %s.", \
379
+ compiled_ver, \
380
+ runtime_ver); \
381
+ return nullptr; \
382
+ } \
383
+ }
384
+
385
+ #define PYBIND11_CATCH_INIT_EXCEPTIONS \
386
+ catch (pybind11::error_already_set & e) { \
387
+ pybind11::raise_from(e, PyExc_ImportError, "initialization failed"); \
388
+ } \
389
+ catch (const std::exception &e) { \
390
+ ::pybind11::set_error(PyExc_ImportError, e.what()); \
391
+ }
392
+
393
+ /** \rst
394
+ ***Deprecated in favor of PYBIND11_MODULE***
395
+
396
+ This macro creates the entry point that will be invoked when the Python interpreter
397
+ imports a plugin library. Please create a `module_` in the function body and return
398
+ the pointer to its underlying Python object at the end.
399
+
400
+ .. code-block:: cpp
401
+
402
+ PYBIND11_PLUGIN(example) {
403
+ pybind11::module_ m("example", "pybind11 example plugin");
404
+ /// Set up bindings here
405
+ return m.ptr();
406
+ }
407
+ \endrst */
408
+ #define PYBIND11_PLUGIN(name) \
409
+ PYBIND11_DEPRECATED("PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE") \
410
+ static PyObject *pybind11_init(); \
411
+ PYBIND11_PLUGIN_IMPL(name) { \
412
+ PYBIND11_CHECK_PYTHON_VERSION \
413
+ PYBIND11_ENSURE_INTERNALS_READY \
414
+ try { \
415
+ return pybind11_init(); \
416
+ } \
417
+ PYBIND11_CATCH_INIT_EXCEPTIONS \
418
+ return nullptr; \
419
+ } \
420
+ PyObject *pybind11_init()
421
+
422
+ // this push is for the next several macros
423
+ PYBIND11_WARNING_PUSH
424
+ PYBIND11_WARNING_DISABLE_CLANG("-Wgnu-zero-variadic-macro-arguments")
425
+
426
+ /**
427
+ Create a PyInit_ function for this module.
428
+
429
+ Note that this is run once for each (sub-)interpreter the module is imported into, including
430
+ possibly concurrently. The PyModuleDef is allowed to be static, but the PyObject* resulting from
431
+ PyModuleDef_Init should be treated like any other PyObject (so not shared across interpreters).
432
+ */
433
+ #define PYBIND11_MODULE_PYINIT(name, pre_init, ...) \
434
+ static int PYBIND11_CONCAT(pybind11_exec_, name)(PyObject *); \
435
+ PYBIND11_PLUGIN_IMPL(name) { \
436
+ PYBIND11_CHECK_PYTHON_VERSION \
437
+ pre_init; \
438
+ PYBIND11_ENSURE_INTERNALS_READY \
439
+ static ::pybind11::detail::slots_array mod_def_slots = ::pybind11::detail::init_slots( \
440
+ &PYBIND11_CONCAT(pybind11_exec_, name), ##__VA_ARGS__); \
441
+ static PyModuleDef def{/* m_base */ PyModuleDef_HEAD_INIT, \
442
+ /* m_name */ PYBIND11_TOSTRING(name), \
443
+ /* m_doc */ nullptr, \
444
+ /* m_size */ 0, \
445
+ /* m_methods */ nullptr, \
446
+ /* m_slots */ mod_def_slots.data(), \
447
+ /* m_traverse */ nullptr, \
448
+ /* m_clear */ nullptr, \
449
+ /* m_free */ nullptr}; \
450
+ return PyModuleDef_Init(&def); \
451
+ }
452
+
453
+ #define PYBIND11_MODULE_EXEC(name, variable) \
454
+ static void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ &); \
455
+ int PYBIND11_CONCAT(pybind11_exec_, name)(PyObject * pm) { \
456
+ try { \
457
+ auto m = pybind11::reinterpret_borrow<::pybind11::module_>(pm); \
458
+ if (!pybind11::detail::get_cached_module(m.attr("__spec__").attr("name"))) { \
459
+ PYBIND11_CONCAT(pybind11_init_, name)(m); \
460
+ pybind11::detail::cache_completed_module(m); \
461
+ } \
462
+ return 0; \
463
+ } \
464
+ PYBIND11_CATCH_INIT_EXCEPTIONS \
465
+ return -1; \
466
+ } \
467
+ void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ \
468
+ & variable) // NOLINT(bugprone-macro-parentheses)
469
+
470
+ /** \rst
471
+ This macro creates the entry point that will be invoked when the Python interpreter
472
+ imports an extension module. The module name is given as the first argument and it
473
+ should not be in quotes. The second macro argument defines a variable of type
474
+ ``py::module_`` which can be used to initialize the module.
475
+
476
+ The entry point is marked as "maybe unused" to aid dead-code detection analysis:
477
+ since the entry point is typically only looked up at runtime and not referenced
478
+ during translation, it would otherwise appear as unused ("dead") code.
479
+
480
+ .. code-block:: cpp
481
+
482
+ PYBIND11_MODULE(example, m) {
483
+ m.doc() = "pybind11 example module";
484
+
485
+ // Add bindings here
486
+ m.def("foo", []() {
487
+ return "Hello, World!";
488
+ });
489
+ }
490
+
491
+ The third and subsequent macro arguments are optional (available since 2.13.0), and
492
+ can be used to mark the extension module as supporting various Python features.
493
+
494
+ - ``mod_gil_not_used()``
495
+ - ``multiple_interpreters::per_interpreter_gil()``
496
+ - ``multiple_interpreters::shared_gil()``
497
+ - ``multiple_interpreters::not_supported()``
498
+
499
+ .. code-block:: cpp
500
+
501
+ PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
502
+ m.doc() = "pybind11 example module safe to run without the GIL";
503
+ m.def("foo", []() {
504
+ return "Hello, Free-threaded World!";
505
+ });
506
+ }
507
+
508
+ \endrst */
509
+ #define PYBIND11_MODULE(name, variable, ...) \
510
+ PYBIND11_MODULE_PYINIT( \
511
+ name, (pybind11::detail::get_num_interpreters_seen() += 1), ##__VA_ARGS__) \
512
+ PYBIND11_MODULE_EXEC(name, variable)
513
+
514
+ // pop gnu-zero-variadic-macro-arguments
515
+ PYBIND11_WARNING_POP
516
+
517
+ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
518
+
519
+ using ssize_t = Py_ssize_t;
520
+ using size_t = std::size_t;
521
+
522
+ template <typename IntType>
523
+ inline ssize_t ssize_t_cast(const IntType &val) {
524
+ static_assert(sizeof(IntType) <= sizeof(ssize_t), "Implicit narrowing is not permitted.");
525
+ return static_cast<ssize_t>(val);
526
+ }
527
+
528
+ /// Approach used to cast a previously unknown C++ instance into a Python object
529
+ enum class return_value_policy : uint8_t {
530
+ /** This is the default return value policy, which falls back to the policy
531
+ return_value_policy::take_ownership when the return value is a pointer.
532
+ Otherwise, it uses return_value::move or return_value::copy for rvalue
533
+ and lvalue references, respectively. See below for a description of what
534
+ all of these different policies do. */
535
+ automatic = 0,
536
+
537
+ /** As above, but use policy return_value_policy::reference when the return
538
+ value is a pointer. This is the default conversion policy for function
539
+ arguments when calling Python functions manually from C++ code (i.e. via
540
+ handle::operator()). You probably won't need to use this. */
541
+ automatic_reference,
542
+
543
+ /** Reference an existing object (i.e. do not create a new copy) and take
544
+ ownership. Python will call the destructor and delete operator when the
545
+ object's reference count reaches zero. Undefined behavior ensues when
546
+ the C++ side does the same.. */
547
+ take_ownership,
548
+
549
+ /** Create a new copy of the returned object, which will be owned by
550
+ Python. This policy is comparably safe because the lifetimes of the two
551
+ instances are decoupled. */
552
+ copy,
553
+
554
+ /** Use std::move to move the return value contents into a new instance
555
+ that will be owned by Python. This policy is comparably safe because the
556
+ lifetimes of the two instances (move source and destination) are
557
+ decoupled. */
558
+ move,
559
+
560
+ /** Reference an existing object, but do not take ownership. The C++ side
561
+ is responsible for managing the object's lifetime and deallocating it
562
+ when it is no longer used. Warning: undefined behavior will ensue when
563
+ the C++ side deletes an object that is still referenced and used by
564
+ Python. */
565
+ reference,
566
+
567
+ /** This policy only applies to methods and properties. It references the
568
+ object without taking ownership similar to the above
569
+ return_value_policy::reference policy. In contrast to that policy, the
570
+ function or property's implicit this argument (called the parent) is
571
+ considered to be the owner of the return value (the child).
572
+ pybind11 then couples the lifetime of the parent to the child via a
573
+ reference relationship that ensures that the parent cannot be garbage
574
+ collected while Python is still using the child. More advanced
575
+ variations of this scheme are also possible using combinations of
576
+ return_value_policy::reference and the keep_alive call policy */
577
+ reference_internal
578
+ };
579
+
580
+ PYBIND11_NAMESPACE_BEGIN(detail)
581
+
582
+ inline static constexpr int log2(size_t n, int k = 0) {
583
+ return (n <= 1) ? k : log2(n >> 1, k + 1);
584
+ }
585
+
586
+ // Returns the size as a multiple of sizeof(void *), rounded up.
587
+ inline static constexpr size_t size_in_ptrs(size_t s) {
588
+ return 1 + ((s - 1) >> log2(sizeof(void *)));
589
+ }
590
+
591
+ /**
592
+ * The space to allocate for simple layout instance holders (see below) in multiple of the size of
593
+ * a pointer (e.g. 2 means 16 bytes on 64-bit architectures). The default is the minimum required
594
+ * to holder either a std::unique_ptr or std::shared_ptr (which is almost always
595
+ * sizeof(std::shared_ptr<T>)).
596
+ */
597
+ constexpr size_t instance_simple_holder_in_ptrs() {
598
+ static_assert(sizeof(std::shared_ptr<int>) >= sizeof(std::unique_ptr<int>),
599
+ "pybind assumes std::shared_ptrs are at least as big as std::unique_ptrs");
600
+ return size_in_ptrs(sizeof(std::shared_ptr<int>));
601
+ }
602
+
603
+ // Forward declarations
604
+ struct type_info;
605
+ struct value_and_holder;
606
+
607
+ struct nonsimple_values_and_holders {
608
+ void **values_and_holders;
609
+ uint8_t *status;
610
+ };
611
+
612
+ /// The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
613
+ struct instance {
614
+ PyObject_HEAD
615
+ /// Storage for pointers and holder; see simple_layout, below, for a description
616
+ union {
617
+ void *simple_value_holder[1 + instance_simple_holder_in_ptrs()];
618
+ nonsimple_values_and_holders nonsimple;
619
+ };
620
+ /// Weak references
621
+ PyObject *weakrefs;
622
+ /// If true, the pointer is owned which means we're free to manage it with a holder.
623
+ bool owned : 1;
624
+ /**
625
+ * An instance has two possible value/holder layouts.
626
+ *
627
+ * Simple layout (when this flag is true), means the `simple_value_holder` is set with a
628
+ * pointer and the holder object governing that pointer, i.e. [val1*][holder]. This layout is
629
+ * applied whenever there is no python-side multiple inheritance of bound C++ types *and* the
630
+ * type's holder will fit in the default space (which is large enough to hold either a
631
+ * std::unique_ptr or std::shared_ptr).
632
+ *
633
+ * Non-simple layout applies when using custom holders that require more space than
634
+ * `shared_ptr` (which is typically the size of two pointers), or when multiple inheritance is
635
+ * used on the python side. Non-simple layout allocates the required amount of memory to have
636
+ * multiple bound C++ classes as parents. Under this layout, `nonsimple.values_and_holders` is
637
+ * set to a pointer to allocated space of the required space to hold a sequence of value
638
+ * pointers and holders followed `status`, a set of bit flags (1 byte each), i.e.
639
+ * [val1*][holder1][val2*][holder2]...[bb...] where each [block] is rounded up to a multiple
640
+ * of `sizeof(void *)`. `nonsimple.status` is, for convenience, a pointer to the beginning of
641
+ * the [bb...] block (but not independently allocated).
642
+ *
643
+ * Status bits indicate whether the associated holder is constructed (&
644
+ * status_holder_constructed) and whether the value pointer is registered (&
645
+ * status_instance_registered) in `registered_instances`.
646
+ */
647
+ bool simple_layout : 1;
648
+ /// For simple layout, tracks whether the holder has been constructed
649
+ bool simple_holder_constructed : 1;
650
+ /// For simple layout, tracks whether the instance is registered in `registered_instances`
651
+ bool simple_instance_registered : 1;
652
+ /// If true, get_internals().patients has an entry for this object
653
+ bool has_patients : 1;
654
+ /// If true, this Python object needs to be kept alive for the lifetime of the C++ value.
655
+ bool is_alias : 1;
656
+
657
+ /// Initializes all of the above type/values/holders data (but not the instance values
658
+ /// themselves)
659
+ void allocate_layout();
660
+
661
+ /// Destroys/deallocates all of the above
662
+ void deallocate_layout();
663
+
664
+ /// Returns the value_and_holder wrapper for the given type (or the first, if `find_type`
665
+ /// omitted). Returns a default-constructed (with `.inst = nullptr`) object on failure if
666
+ /// `throw_if_missing` is false.
667
+ value_and_holder get_value_and_holder(const type_info *find_type = nullptr,
668
+ bool throw_if_missing = true);
669
+
670
+ /// Bit values for the non-simple status flags
671
+ static constexpr uint8_t status_holder_constructed = 1;
672
+ static constexpr uint8_t status_instance_registered = 2;
673
+ };
674
+
675
+ static_assert(std::is_standard_layout<instance>::value,
676
+ "Internal error: `pybind11::detail::instance` is not standard layout!");
677
+
678
+ // Some older compilers (e.g. gcc 9.4.0) require
679
+ // static_assert(always_false<T>::value, "...");
680
+ // instead of
681
+ // static_assert(false, "...");
682
+ // to trigger the static_assert() in a template only if it is actually instantiated.
683
+ template <typename>
684
+ struct always_false : std::false_type {};
685
+
686
+ /// from __cpp_future__ import (convenient aliases from C++14/17)
687
+ #if defined(PYBIND11_CPP14)
688
+ using std::conditional_t;
689
+ using std::enable_if_t;
690
+ using std::remove_cv_t;
691
+ using std::remove_reference_t;
692
+ #else
693
+ template <bool B, typename T = void>
694
+ using enable_if_t = typename std::enable_if<B, T>::type;
695
+ template <bool B, typename T, typename F>
696
+ using conditional_t = typename std::conditional<B, T, F>::type;
697
+ template <typename T>
698
+ using remove_cv_t = typename std::remove_cv<T>::type;
699
+ template <typename T>
700
+ using remove_reference_t = typename std::remove_reference<T>::type;
701
+ #endif
702
+
703
+ #if defined(PYBIND11_CPP20) && defined(__cpp_lib_remove_cvref)
704
+ using std::remove_cvref;
705
+ using std::remove_cvref_t;
706
+ #else
707
+ template <class T>
708
+ struct remove_cvref {
709
+ using type = remove_cv_t<remove_reference_t<T>>;
710
+ };
711
+ template <class T>
712
+ using remove_cvref_t = typename remove_cvref<T>::type;
713
+ #endif
714
+
715
+ /// Example usage: is_same_ignoring_cvref<T, PyObject *>::value
716
+ template <typename T, typename U>
717
+ using is_same_ignoring_cvref = std::is_same<detail::remove_cvref_t<T>, U>;
718
+
719
+ /// Index sequences
720
+ #if defined(PYBIND11_CPP14)
721
+ using std::index_sequence;
722
+ using std::make_index_sequence;
723
+ #else
724
+ template <size_t...>
725
+ struct index_sequence {};
726
+ // Comments about the algorithm below.
727
+ //
728
+ // Credit: This is based on an algorithm by taocpp here:
729
+ // https://github.com/taocpp/sequences/blob/main/include/tao/seq/make_integer_sequence.hpp
730
+ // but significantly simplified.
731
+ //
732
+ // We build up a sequence S by repeatedly doubling its length and sometimes adding 1 to the end.
733
+ // E.g. if the current S is 0...3, then we either go to 0...7 or 0...8 on the next pass.
734
+ // The goal is to end with S = 0...N-1.
735
+ // The key insight is that the times we need to add an additional digit to S correspond
736
+ // exactly to the 1's in the binary representation of the number N.
737
+ //
738
+ // Invariants:
739
+ // - digit is a power of 2
740
+ // - N_digit_is_1 is whether N's binary representation has a 1 in that digit's position.
741
+ // - end <= N
742
+ // - S is 0...end-1.
743
+ // - if digit > 0, end * digit * 2 <= N < (end+1) * digit * 2
744
+ //
745
+ // The process starts with digit > N, end = 0, and S is empty.
746
+ // The process concludes with digit=0, in which case, end == N and S is 0...N-1.
747
+
748
+ template <size_t digit, bool N_digit_is_1, size_t N, size_t end, size_t... S> // N_digit_is_1=false
749
+ struct make_index_sequence_impl
750
+ : make_index_sequence_impl<digit / 2, (N & (digit / 2)) != 0, N, 2 * end, S..., (S + end)...> {
751
+ };
752
+ template <size_t digit, size_t N, size_t end, size_t... S>
753
+ struct make_index_sequence_impl<digit, true, N, end, S...>
754
+ : make_index_sequence_impl<digit / 2,
755
+ (N & (digit / 2)) != 0,
756
+ N,
757
+ 2 * end + 1,
758
+ S...,
759
+ (S + end)...,
760
+ 2 * end> {};
761
+ template <size_t N, size_t end, size_t... S>
762
+ struct make_index_sequence_impl<0, false, N, end, S...> {
763
+ using type = index_sequence<S...>;
764
+ };
765
+ constexpr size_t next_power_of_2(size_t N) { return N == 0 ? 1 : next_power_of_2(N >> 1) << 1; }
766
+ template <size_t N>
767
+ using make_index_sequence =
768
+ typename make_index_sequence_impl<next_power_of_2(N), false, N, 0>::type;
769
+ #endif
770
+
771
+ /// Make an index sequence of the indices of true arguments
772
+ template <typename ISeq, size_t, bool...>
773
+ struct select_indices_impl {
774
+ using type = ISeq;
775
+ };
776
+ template <size_t... IPrev, size_t I, bool B, bool... Bs>
777
+ struct select_indices_impl<index_sequence<IPrev...>, I, B, Bs...>
778
+ : select_indices_impl<conditional_t<B, index_sequence<IPrev..., I>, index_sequence<IPrev...>>,
779
+ I + 1,
780
+ Bs...> {};
781
+ template <bool... Bs>
782
+ using select_indices = typename select_indices_impl<index_sequence<>, 0, Bs...>::type;
783
+
784
+ /// Backports of std::bool_constant and std::negation to accommodate older compilers
785
+ template <bool B>
786
+ using bool_constant = std::integral_constant<bool, B>;
787
+ template <typename T>
788
+ struct negation : bool_constant<!T::value> {};
789
+
790
+ // PGI/Intel cannot detect operator delete with the "compatible" void_t impl, so
791
+ // using the new one (C++14 defect, so generally works on newer compilers, even
792
+ // if not in C++17 mode)
793
+ #if defined(__PGIC__) || defined(__INTEL_COMPILER)
794
+ template <typename...>
795
+ using void_t = void;
796
+ #else
797
+ template <typename...>
798
+ struct void_t_impl {
799
+ using type = void;
800
+ };
801
+ template <typename... Ts>
802
+ using void_t = typename void_t_impl<Ts...>::type;
803
+ #endif
804
+
805
+ /// Compile-time all/any/none of that check the boolean value of all template types
806
+ #if defined(__cpp_fold_expressions) && !(defined(_MSC_VER) && (_MSC_VER < 1916))
807
+ template <class... Ts>
808
+ using all_of = bool_constant<(Ts::value && ...)>;
809
+ template <class... Ts>
810
+ using any_of = bool_constant<(Ts::value || ...)>;
811
+ #elif !defined(_MSC_VER)
812
+ template <bool...>
813
+ struct bools {};
814
+ template <class... Ts>
815
+ using all_of = std::is_same<bools<Ts::value..., true>, bools<true, Ts::value...>>;
816
+ template <class... Ts>
817
+ using any_of = negation<all_of<negation<Ts>...>>;
818
+ #else
819
+ // MSVC has trouble with the above, but supports std::conjunction, which we can use instead (albeit
820
+ // at a slight loss of compilation efficiency).
821
+ template <class... Ts>
822
+ using all_of = std::conjunction<Ts...>;
823
+ template <class... Ts>
824
+ using any_of = std::disjunction<Ts...>;
825
+ #endif
826
+ template <class... Ts>
827
+ using none_of = negation<any_of<Ts...>>;
828
+
829
+ template <class T, template <class> class... Predicates>
830
+ using satisfies_all_of = all_of<Predicates<T>...>;
831
+ template <class T, template <class> class... Predicates>
832
+ using satisfies_any_of = any_of<Predicates<T>...>;
833
+ template <class T, template <class> class... Predicates>
834
+ using satisfies_none_of = none_of<Predicates<T>...>;
835
+
836
+ /// Strip the class from a method type
837
+ template <typename T>
838
+ struct remove_class {};
839
+ template <typename C, typename R, typename... A>
840
+ struct remove_class<R (C::*)(A...)> {
841
+ using type = R(A...);
842
+ };
843
+ template <typename C, typename R, typename... A>
844
+ struct remove_class<R (C::*)(A...) const> {
845
+ using type = R(A...);
846
+ };
847
+ #ifdef __cpp_noexcept_function_type
848
+ template <typename C, typename R, typename... A>
849
+ struct remove_class<R (C::*)(A...) noexcept> {
850
+ using type = R(A...);
851
+ };
852
+ template <typename C, typename R, typename... A>
853
+ struct remove_class<R (C::*)(A...) const noexcept> {
854
+ using type = R(A...);
855
+ };
856
+ #endif
857
+ /// Helper template to strip away type modifiers
858
+ template <typename T>
859
+ struct intrinsic_type {
860
+ using type = T;
861
+ };
862
+ template <typename T>
863
+ struct intrinsic_type<const T> {
864
+ using type = typename intrinsic_type<T>::type;
865
+ };
866
+ template <typename T>
867
+ struct intrinsic_type<T *> {
868
+ using type = typename intrinsic_type<T>::type;
869
+ };
870
+ template <typename T>
871
+ struct intrinsic_type<T &> {
872
+ using type = typename intrinsic_type<T>::type;
873
+ };
874
+ template <typename T>
875
+ struct intrinsic_type<T &&> {
876
+ using type = typename intrinsic_type<T>::type;
877
+ };
878
+ template <typename T, size_t N>
879
+ struct intrinsic_type<const T[N]> {
880
+ using type = typename intrinsic_type<T>::type;
881
+ };
882
+ template <typename T, size_t N>
883
+ struct intrinsic_type<T[N]> {
884
+ using type = typename intrinsic_type<T>::type;
885
+ };
886
+ template <typename T>
887
+ using intrinsic_t = typename intrinsic_type<T>::type;
888
+
889
+ /// Helper type to replace 'void' in some expressions
890
+ struct void_type {};
891
+
892
+ /// Helper template which holds a list of types
893
+ template <typename...>
894
+ struct type_list {};
895
+
896
+ /// Compile-time integer sum
897
+ #ifdef __cpp_fold_expressions
898
+ template <typename... Ts>
899
+ constexpr size_t constexpr_sum(Ts... ns) {
900
+ return (0 + ... + size_t{ns});
901
+ }
902
+ #else
903
+ constexpr size_t constexpr_sum() { return 0; }
904
+ template <typename T, typename... Ts>
905
+ constexpr size_t constexpr_sum(T n, Ts... ns) {
906
+ return size_t{n} + constexpr_sum(ns...);
907
+ }
908
+ #endif
909
+
910
+ PYBIND11_NAMESPACE_BEGIN(constexpr_impl)
911
+ /// Implementation details for constexpr functions
912
+ constexpr int first(int i) { return i; }
913
+ template <typename T, typename... Ts>
914
+ constexpr int first(int i, T v, Ts... vs) {
915
+ return v ? i : first(i + 1, vs...);
916
+ }
917
+
918
+ constexpr int last(int /*i*/, int result) { return result; }
919
+ template <typename T, typename... Ts>
920
+ constexpr int last(int i, int result, T v, Ts... vs) {
921
+ return last(i + 1, v ? i : result, vs...);
922
+ }
923
+ PYBIND11_NAMESPACE_END(constexpr_impl)
924
+
925
+ /// Return the index of the first type in Ts which satisfies Predicate<T>.
926
+ /// Returns sizeof...(Ts) if none match.
927
+ template <template <typename> class Predicate, typename... Ts>
928
+ constexpr int constexpr_first() {
929
+ return constexpr_impl::first(0, Predicate<Ts>::value...);
930
+ }
931
+
932
+ /// Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match.
933
+ template <template <typename> class Predicate, typename... Ts>
934
+ constexpr int constexpr_last() {
935
+ return constexpr_impl::last(0, -1, Predicate<Ts>::value...);
936
+ }
937
+
938
+ /// Return the Nth element from the parameter pack
939
+ template <size_t N, typename T, typename... Ts>
940
+ struct pack_element {
941
+ using type = typename pack_element<N - 1, Ts...>::type;
942
+ };
943
+ template <typename T, typename... Ts>
944
+ struct pack_element<0, T, Ts...> {
945
+ using type = T;
946
+ };
947
+
948
+ /// Return the one and only type which matches the predicate, or Default if none match.
949
+ /// If more than one type matches the predicate, fail at compile-time.
950
+ template <template <typename> class Predicate, typename Default, typename... Ts>
951
+ struct exactly_one {
952
+ static constexpr auto found = constexpr_sum(Predicate<Ts>::value...);
953
+ static_assert(found <= 1, "Found more than one type matching the predicate");
954
+
955
+ static constexpr auto index = found ? constexpr_first<Predicate, Ts...>() : 0;
956
+ using type = conditional_t<found, typename pack_element<index, Ts...>::type, Default>;
957
+ };
958
+ template <template <typename> class P, typename Default>
959
+ struct exactly_one<P, Default> {
960
+ using type = Default;
961
+ };
962
+
963
+ template <template <typename> class Predicate, typename Default, typename... Ts>
964
+ using exactly_one_t = typename exactly_one<Predicate, Default, Ts...>::type;
965
+
966
+ /// Defer the evaluation of type T until types Us are instantiated
967
+ template <typename T, typename... /*Us*/>
968
+ struct deferred_type {
969
+ using type = T;
970
+ };
971
+ template <typename T, typename... Us>
972
+ using deferred_t = typename deferred_type<T, Us...>::type;
973
+
974
+ /// Like is_base_of, but requires a strict base (i.e. `is_strict_base_of<T, T>::value == false`,
975
+ /// unlike `std::is_base_of`)
976
+ template <typename Base, typename Derived>
977
+ using is_strict_base_of
978
+ = bool_constant<std::is_base_of<Base, Derived>::value && !std::is_same<Base, Derived>::value>;
979
+
980
+ /// Like is_base_of, but also requires that the base type is accessible (i.e. that a Derived
981
+ /// pointer can be converted to a Base pointer) For unions, `is_base_of<T, T>::value` is False, so
982
+ /// we need to check `is_same` as well.
983
+ template <typename Base, typename Derived>
984
+ using is_accessible_base_of
985
+ = bool_constant<(std::is_same<Base, Derived>::value || std::is_base_of<Base, Derived>::value)
986
+ && std::is_convertible<Derived *, Base *>::value>;
987
+
988
+ template <template <typename...> class Base>
989
+ struct is_template_base_of_impl {
990
+ template <typename... Us>
991
+ static std::true_type check(Base<Us...> *);
992
+ static std::false_type check(...);
993
+ };
994
+
995
+ /// Check if a template is the base of a type. For example:
996
+ /// `is_template_base_of<Base, T>` is true if `struct T : Base<U> {}` where U can be anything
997
+ template <template <typename...> class Base, typename T>
998
+ // Sadly, all MSVC versions incl. 2022 need the workaround, even in C++20 mode.
999
+ // See also: https://github.com/pybind/pybind11/pull/3741
1000
+ #if !defined(_MSC_VER)
1001
+ using is_template_base_of
1002
+ = decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T> *) nullptr));
1003
+ #else
1004
+ struct is_template_base_of
1005
+ : decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T> *) nullptr)){};
1006
+ #endif
1007
+
1008
+ /// Check if T is an instantiation of the template `Class`. For example:
1009
+ /// `is_instantiation<shared_ptr, T>` is true if `T == shared_ptr<U>` where U can be anything.
1010
+ template <template <typename...> class Class, typename T>
1011
+ struct is_instantiation : std::false_type {};
1012
+ template <template <typename...> class Class, typename... Us>
1013
+ struct is_instantiation<Class, Class<Us...>> : std::true_type {};
1014
+
1015
+ /// Check if T is std::shared_ptr<U> where U can be anything
1016
+ template <typename T>
1017
+ using is_shared_ptr = is_instantiation<std::shared_ptr, T>;
1018
+
1019
+ /// Check if T looks like an input iterator
1020
+ template <typename T, typename = void>
1021
+ struct is_input_iterator : std::false_type {};
1022
+ template <typename T>
1023
+ struct is_input_iterator<T,
1024
+ void_t<decltype(*std::declval<T &>()), decltype(++std::declval<T &>())>>
1025
+ : std::true_type {};
1026
+
1027
+ template <typename T>
1028
+ using is_function_pointer
1029
+ = bool_constant<std::is_pointer<T>::value
1030
+ && std::is_function<typename std::remove_pointer<T>::type>::value>;
1031
+
1032
+ template <typename F>
1033
+ struct strip_function_object {
1034
+ // If you are encountering an
1035
+ // 'error: name followed by "::" must be a class or namespace name'
1036
+ // with the Intel compiler and a noexcept function here,
1037
+ // try to use noexcept(true) instead of plain noexcept.
1038
+ using type = typename remove_class<decltype(&F::operator())>::type;
1039
+ };
1040
+
1041
+ // Extracts the function signature from a function, function pointer or lambda.
1042
+ template <typename Function, typename F = remove_reference_t<Function>>
1043
+ using function_signature_t = conditional_t<
1044
+ std::is_function<F>::value,
1045
+ F,
1046
+ typename conditional_t<std::is_pointer<F>::value || std::is_member_pointer<F>::value,
1047
+ std::remove_pointer<F>,
1048
+ strip_function_object<F>>::type>;
1049
+
1050
+ /// Returns true if the type looks like a lambda: that is, isn't a function, pointer or member
1051
+ /// pointer. Note that this can catch all sorts of other things, too; this is intended to be used
1052
+ /// in a place where passing a lambda makes sense.
1053
+ template <typename T>
1054
+ using is_lambda = satisfies_none_of<remove_reference_t<T>,
1055
+ std::is_function,
1056
+ std::is_pointer,
1057
+ std::is_member_pointer>;
1058
+
1059
+ // [workaround(intel)] Internal error on fold expression
1060
+ /// Apply a function over each element of a parameter pack
1061
+ #if defined(__cpp_fold_expressions) && !defined(__INTEL_COMPILER)
1062
+ // Intel compiler produces an internal error on this fold expression (tested with ICC 19.0.2)
1063
+ # define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (((PATTERN), void()), ...)
1064
+ #else
1065
+ using expand_side_effects = bool[];
1066
+ # define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) \
1067
+ (void) pybind11::detail::expand_side_effects { ((PATTERN), void(), false)..., false }
1068
+ #endif
1069
+
1070
+ PYBIND11_NAMESPACE_END(detail)
1071
+
1072
+ /// C++ bindings of builtin Python exceptions
1073
+ class PYBIND11_EXPORT_EXCEPTION builtin_exception : public std::runtime_error {
1074
+ public:
1075
+ using std::runtime_error::runtime_error;
1076
+ /// Set the error using the Python C API
1077
+ virtual void set_error() const = 0;
1078
+ };
1079
+
1080
+ #define PYBIND11_RUNTIME_EXCEPTION(name, type) \
1081
+ class PYBIND11_EXPORT_EXCEPTION name : public builtin_exception { \
1082
+ public: \
1083
+ using builtin_exception::builtin_exception; \
1084
+ name() : name("") {} \
1085
+ void set_error() const override { PyErr_SetString(type, what()); } \
1086
+ };
1087
+
1088
+ PYBIND11_RUNTIME_EXCEPTION(stop_iteration, PyExc_StopIteration)
1089
+ PYBIND11_RUNTIME_EXCEPTION(index_error, PyExc_IndexError)
1090
+ PYBIND11_RUNTIME_EXCEPTION(key_error, PyExc_KeyError)
1091
+ PYBIND11_RUNTIME_EXCEPTION(value_error, PyExc_ValueError)
1092
+ PYBIND11_RUNTIME_EXCEPTION(type_error, PyExc_TypeError)
1093
+ PYBIND11_RUNTIME_EXCEPTION(buffer_error, PyExc_BufferError)
1094
+ PYBIND11_RUNTIME_EXCEPTION(import_error, PyExc_ImportError)
1095
+ PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError)
1096
+ PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or
1097
+ /// handle::call fail due to a type
1098
+ /// casting error
1099
+ PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used internally
1100
+
1101
+ [[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason) {
1102
+ assert(!PyErr_Occurred());
1103
+ throw std::runtime_error(reason);
1104
+ }
1105
+ [[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const std::string &reason) {
1106
+ assert(!PyErr_Occurred());
1107
+ throw std::runtime_error(reason);
1108
+ }
1109
+
1110
+ template <typename T, typename SFINAE = void>
1111
+ struct format_descriptor {};
1112
+
1113
+ template <typename T>
1114
+ struct format_descriptor<
1115
+ T,
1116
+ detail::enable_if_t<detail::is_same_ignoring_cvref<T, PyObject *>::value>> {
1117
+ static constexpr const char c = 'O';
1118
+ static constexpr const char value[2] = {c, '\0'};
1119
+ static std::string format() { return std::string(1, c); }
1120
+ };
1121
+
1122
+ PYBIND11_NAMESPACE_BEGIN(detail)
1123
+ // Returns the index of the given type in the type char array below, and in the list in numpy.h
1124
+ // The order here is: bool; 8 ints ((signed,unsigned)x(8,16,32,64)bits); float,double,long double;
1125
+ // complex float,double,long double. Note that the long double types only participate when long
1126
+ // double is actually longer than double (it isn't under MSVC).
1127
+ // NB: not only the string below but also complex.h and numpy.h rely on this order.
1128
+ template <typename T, typename SFINAE = void>
1129
+ struct is_fmt_numeric {
1130
+ static constexpr bool value = false;
1131
+ };
1132
+ template <typename T>
1133
+ struct is_fmt_numeric<T, enable_if_t<std::is_arithmetic<T>::value>> {
1134
+ static constexpr bool value = true;
1135
+ static constexpr int index
1136
+ = std::is_same<T, bool>::value
1137
+ ? 0
1138
+ : 1
1139
+ + (std::is_integral<T>::value
1140
+ ? detail::log2(sizeof(T)) * 2 + std::is_unsigned<T>::value
1141
+ : 8
1142
+ + (std::is_same<T, double>::value ? 1
1143
+ : std::is_same<T, long double>::value ? 2
1144
+ : 0));
1145
+ };
1146
+ PYBIND11_NAMESPACE_END(detail)
1147
+
1148
+ template <typename T>
1149
+ struct format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>> {
1150
+ static constexpr const char c = "?bBhHiIqQfdg"[detail::is_fmt_numeric<T>::index];
1151
+ static constexpr const char value[2] = {c, '\0'};
1152
+ static std::string format() { return std::string(1, c); }
1153
+ };
1154
+
1155
+ #if !defined(PYBIND11_CPP17)
1156
+
1157
+ template <typename T>
1158
+ constexpr const char
1159
+ format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>>::value[2];
1160
+
1161
+ #endif
1162
+
1163
+ /// RAII wrapper that temporarily clears any Python error state
1164
+ struct error_scope {
1165
+ PyObject *type, *value, *trace;
1166
+ error_scope() { PyErr_Fetch(&type, &value, &trace); }
1167
+ error_scope(const error_scope &) = delete;
1168
+ error_scope &operator=(const error_scope &) = delete;
1169
+ ~error_scope() { PyErr_Restore(type, value, trace); }
1170
+ };
1171
+
1172
+ /// Dummy destructor wrapper that can be used to expose classes with a private destructor
1173
+ struct nodelete {
1174
+ template <typename T>
1175
+ void operator()(T *) {}
1176
+ };
1177
+
1178
+ PYBIND11_NAMESPACE_BEGIN(detail)
1179
+ template <typename... Args>
1180
+ struct overload_cast_impl {
1181
+ template <typename Return>
1182
+ constexpr auto operator()(Return (*pf)(Args...)) const noexcept -> decltype(pf) {
1183
+ return pf;
1184
+ }
1185
+
1186
+ template <typename Return, typename Class>
1187
+ constexpr auto operator()(Return (Class::*pmf)(Args...), std::false_type = {}) const noexcept
1188
+ -> decltype(pmf) {
1189
+ return pmf;
1190
+ }
1191
+
1192
+ template <typename Return, typename Class>
1193
+ constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept
1194
+ -> decltype(pmf) {
1195
+ return pmf;
1196
+ }
1197
+ };
1198
+ PYBIND11_NAMESPACE_END(detail)
1199
+
1200
+ // overload_cast requires variable templates: C++14
1201
+ #if defined(PYBIND11_CPP14)
1202
+ # define PYBIND11_OVERLOAD_CAST 1
1203
+ /// Syntax sugar for resolving overloaded function pointers:
1204
+ /// - regular: static_cast<Return (Class::*)(Arg0, Arg1, Arg2)>(&Class::func)
1205
+ /// - sweet: overload_cast<Arg0, Arg1, Arg2>(&Class::func)
1206
+ template <typename... Args>
1207
+ static constexpr detail::overload_cast_impl<Args...> overload_cast{};
1208
+ #endif
1209
+
1210
+ /// Const member function selector for overload_cast
1211
+ /// - regular: static_cast<Return (Class::*)(Arg) const>(&Class::func)
1212
+ /// - sweet: overload_cast<Arg>(&Class::func, const_)
1213
+ static constexpr auto const_ = std::true_type{};
1214
+
1215
+ #if !defined(PYBIND11_CPP14) // no overload_cast: providing something that static_assert-fails:
1216
+ template <typename... Args>
1217
+ struct overload_cast {
1218
+ static_assert(detail::deferred_t<std::false_type, Args...>::value,
1219
+ "pybind11::overload_cast<...> requires compiling in C++14 mode");
1220
+ };
1221
+ #endif // overload_cast
1222
+
1223
+ PYBIND11_NAMESPACE_BEGIN(detail)
1224
+
1225
+ // Adaptor for converting arbitrary container arguments into a vector; implicitly convertible from
1226
+ // any standard container (or C-style array) supporting std::begin/std::end, any singleton
1227
+ // arithmetic type (if T is arithmetic), or explicitly constructible from an iterator pair.
1228
+ template <typename T>
1229
+ class any_container {
1230
+ std::vector<T> v;
1231
+
1232
+ public:
1233
+ any_container() = default;
1234
+
1235
+ // Can construct from a pair of iterators
1236
+ template <typename It, typename = enable_if_t<is_input_iterator<It>::value>>
1237
+ any_container(It first, It last) : v(first, last) {}
1238
+
1239
+ // Implicit conversion constructor from any arbitrary container type
1240
+ // with values convertible to T
1241
+ template <typename Container,
1242
+ typename = enable_if_t<
1243
+ std::is_convertible<decltype(*std::begin(std::declval<const Container &>())),
1244
+ T>::value>>
1245
+ // NOLINTNEXTLINE(google-explicit-constructor)
1246
+ any_container(const Container &c) : any_container(std::begin(c), std::end(c)) {}
1247
+
1248
+ // initializer_list's aren't deducible, so don't get matched by the above template;
1249
+ // we need this to explicitly allow implicit conversion from one:
1250
+ template <typename TIn, typename = enable_if_t<std::is_convertible<TIn, T>::value>>
1251
+ any_container(const std::initializer_list<TIn> &c) : any_container(c.begin(), c.end()) {}
1252
+
1253
+ // Avoid copying if given an rvalue vector of the correct type.
1254
+ // NOLINTNEXTLINE(google-explicit-constructor)
1255
+ any_container(std::vector<T> &&v) : v(std::move(v)) {}
1256
+
1257
+ // Moves the vector out of an rvalue any_container
1258
+ // NOLINTNEXTLINE(google-explicit-constructor)
1259
+ operator std::vector<T> &&() && { return std::move(v); }
1260
+
1261
+ // Dereferencing obtains a reference to the underlying vector
1262
+ std::vector<T> &operator*() { return v; }
1263
+ const std::vector<T> &operator*() const { return v; }
1264
+
1265
+ // -> lets you call methods on the underlying vector
1266
+ std::vector<T> *operator->() { return &v; }
1267
+ const std::vector<T> *operator->() const { return &v; }
1268
+ };
1269
+
1270
+ // Forward-declaration; see detail/class.h
1271
+ std::string get_fully_qualified_tp_name(PyTypeObject *);
1272
+
1273
+ template <typename T>
1274
+ inline static std::shared_ptr<T>
1275
+ try_get_shared_from_this(std::enable_shared_from_this<T> *holder_value_ptr) {
1276
+ // Pre C++17, this code path exploits undefined behavior, but is known to work on many platforms.
1277
+ // Use at your own risk!
1278
+ // See also https://en.cppreference.com/w/cpp/memory/enable_shared_from_this, and in particular
1279
+ // the `std::shared_ptr<Good> gp1 = not_so_good.getptr();` and `try`-`catch` parts of the example.
1280
+ #if defined(__cpp_lib_enable_shared_from_this) && (!defined(_MSC_VER) || _MSC_VER >= 1912)
1281
+ return holder_value_ptr->weak_from_this().lock();
1282
+ #else
1283
+ try {
1284
+ return holder_value_ptr->shared_from_this();
1285
+ } catch (const std::bad_weak_ptr &) {
1286
+ return nullptr;
1287
+ }
1288
+ #endif
1289
+ }
1290
+
1291
+ // For silencing "unused" compiler warnings in special situations.
1292
+ template <typename... Args>
1293
+ #if defined(_MSC_VER) && _MSC_VER < 1920 // MSVC 2017
1294
+ constexpr
1295
+ #endif
1296
+ inline void
1297
+ silence_unused_warnings(Args &&...) {
1298
+ }
1299
+
1300
+ // MSVC warning C4100: Unreferenced formal parameter
1301
+ #if defined(_MSC_VER) && _MSC_VER <= 1916
1302
+ # define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...) \
1303
+ detail::silence_unused_warnings(__VA_ARGS__)
1304
+ #else
1305
+ # define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...)
1306
+ #endif
1307
+
1308
+ // GCC -Wunused-but-set-parameter All GCC versions (as of July 2021).
1309
+ #if defined(__GNUG__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
1310
+ # define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...) \
1311
+ detail::silence_unused_warnings(__VA_ARGS__)
1312
+ #else
1313
+ # define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...)
1314
+ #endif
1315
+
1316
+ #if defined(__clang__) \
1317
+ && (defined(__apple_build_version__) /* AppleClang 13.0.0.13000029 was the only data point \
1318
+ available. */ \
1319
+ || (__clang_major__ >= 7 \
1320
+ && __clang_major__ <= 12) /* Clang 3, 5, 13, 14, 15 do not generate the warning. */ \
1321
+ )
1322
+ # define PYBIND11_DETECTED_CLANG_WITH_MISLEADING_CALL_STD_MOVE_EXPLICITLY_WARNING
1323
+ // Example:
1324
+ // tests/test_kwargs_and_defaults.cpp:46:68: error: local variable 'args' will be copied despite
1325
+ // being returned by name [-Werror,-Wreturn-std-move]
1326
+ // m.def("args_function", [](py::args args) -> py::tuple { return args; });
1327
+ // ^~~~
1328
+ // test_kwargs_and_defaults.cpp:46:68: note: call 'std::move' explicitly to avoid copying
1329
+ // m.def("args_function", [](py::args args) -> py::tuple { return args; });
1330
+ // ^~~~
1331
+ // std::move(args)
1332
+ #endif
1333
+
1334
+ // Pybind offers detailed error messages by default for all builts that are debug (through the
1335
+ // negation of NDEBUG). This can also be manually enabled by users, for any builds, through
1336
+ // defining PYBIND11_DETAILED_ERROR_MESSAGES. This information is primarily useful for those
1337
+ // who are writing (as opposed to merely using) libraries that use pybind11.
1338
+ #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) && !defined(NDEBUG)
1339
+ # define PYBIND11_DETAILED_ERROR_MESSAGES
1340
+ #endif
1341
+
1342
+ // CPython 3.11+ provides Py_TPFLAGS_MANAGED_DICT, but PyPy3.11 does not, see PR #5508.
1343
+ #if PY_VERSION_HEX < 0x030B0000 || defined(PYPY_VERSION)
1344
+ # define PYBIND11_BACKWARD_COMPATIBILITY_TP_DICTOFFSET
1345
+ #endif
1346
+
1347
+ PYBIND11_NAMESPACE_END(detail)
1348
+ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)