pytron-kit 0.3.12__py3-none-macosx_11_0_universal2.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 (419) hide show
  1. pytron/__init__.py +112 -0
  2. pytron/application.py +562 -0
  3. pytron/apputils/__init__.py +0 -0
  4. pytron/apputils/chrome_ipc.py +203 -0
  5. pytron/apputils/codegen.py +261 -0
  6. pytron/apputils/config.py +303 -0
  7. pytron/apputils/deadmansswitch.py +47 -0
  8. pytron/apputils/extras.py +76 -0
  9. pytron/apputils/native.py +148 -0
  10. pytron/apputils/shell.py +73 -0
  11. pytron/apputils/windows.py +286 -0
  12. pytron/cli.py +384 -0
  13. pytron/commands/__init__.py +0 -0
  14. pytron/commands/android.py +28 -0
  15. pytron/commands/build.py +26 -0
  16. pytron/commands/doctor.py +221 -0
  17. pytron/commands/engine.py +23 -0
  18. pytron/commands/frontend.py +60 -0
  19. pytron/commands/harvest.py +112 -0
  20. pytron/commands/helpers.py +239 -0
  21. pytron/commands/info.py +50 -0
  22. pytron/commands/init.py +521 -0
  23. pytron/commands/install.py +294 -0
  24. pytron/commands/login.py +130 -0
  25. pytron/commands/package.py +228 -0
  26. pytron/commands/plugin.py +442 -0
  27. pytron/commands/run.py +312 -0
  28. pytron/commands/scan.py +210 -0
  29. pytron/commands/show.py +23 -0
  30. pytron/commands/uninstall.py +150 -0
  31. pytron/commands/utils.py +42 -0
  32. pytron/commands/workflow.py +95 -0
  33. pytron/console.py +133 -0
  34. pytron/core.py +18 -0
  35. pytron/dependencies/WebView2Loader.dll +0 -0
  36. pytron/dependencies/__init__.py +1 -0
  37. pytron/dependencies/pytron_native.so +0 -0
  38. pytron/engines/chrome/adapter.py +445 -0
  39. pytron/engines/chrome/engine.py +576 -0
  40. pytron/engines/chrome/forge.py +147 -0
  41. pytron/engines/chrome/shell/package.json +8 -0
  42. pytron/engines/chrome/shell/preload.js +12 -0
  43. pytron/engines/chrome/shell/shell.js +534 -0
  44. pytron/exceptions.py +36 -0
  45. pytron/inspector.py +201 -0
  46. pytron/inspector_ui.py +512 -0
  47. pytron/installer/Installation.nsi +236 -0
  48. pytron/installer/header.bmp +0 -0
  49. pytron/installer/pytron.ico +0 -0
  50. pytron/installer/sidebar.bmp +0 -0
  51. pytron/llms.md +98 -0
  52. pytron/manifests/README.md +29 -0
  53. pytron/manifests/windows-utf8.manifest +44 -0
  54. pytron/menu.py +128 -0
  55. pytron/nsis-setup.exe +0 -0
  56. pytron/pack/__init__.py +0 -0
  57. pytron/pack/assets.py +131 -0
  58. pytron/pack/compilers.py +289 -0
  59. pytron/pack/crystal.py +297 -0
  60. pytron/pack/graph.py +377 -0
  61. pytron/pack/inference.py +157 -0
  62. pytron/pack/installers.py +402 -0
  63. pytron/pack/introspect.py +357 -0
  64. pytron/pack/metadata.py +213 -0
  65. pytron/pack/modules.py +618 -0
  66. pytron/pack/nuitka.py +108 -0
  67. pytron/pack/pipeline.py +107 -0
  68. pytron/pack/pyinstaller.py +176 -0
  69. pytron/pack/rust_engine.py +273 -0
  70. pytron/pack/secure.py +309 -0
  71. pytron/pack/secure_loader/bin/pytron_rust_bootloader +0 -0
  72. pytron/pack/secure_loader/icon.ico +0 -0
  73. pytron/pack/utils.py +110 -0
  74. pytron/pack/virtual_root.py +124 -0
  75. pytron/platforms/__init__.py +0 -0
  76. pytron/platforms/android/__init__.py +3 -0
  77. pytron/platforms/android/android.py +103 -0
  78. pytron/platforms/android/builder.py +736 -0
  79. pytron/platforms/android/ops/build.py +79 -0
  80. pytron/platforms/android/ops/init.py +63 -0
  81. pytron/platforms/android/ops/run.py +79 -0
  82. pytron/platforms/android/ops/sync.py +770 -0
  83. pytron/platforms/android/ops/utils.py +8 -0
  84. pytron/platforms/android/shell/README.md +30 -0
  85. pytron/platforms/android/shell/app/build.gradle +64 -0
  86. pytron/platforms/android/shell/app/src/main/AndroidManifest.xml +29 -0
  87. pytron/platforms/android/shell/app/src/main/assets/python/main.py +86 -0
  88. pytron/platforms/android/shell/app/src/main/assets/python/python314.zip +0 -0
  89. pytron/platforms/android/shell/app/src/main/cpp/CMakeLists.txt +25 -0
  90. pytron/platforms/android/shell/app/src/main/cpp/include/Python.h +155 -0
  91. pytron/platforms/android/shell/app/src/main/cpp/include/abstract.h +915 -0
  92. pytron/platforms/android/shell/app/src/main/cpp/include/audit.h +30 -0
  93. pytron/platforms/android/shell/app/src/main/cpp/include/bltinmodule.h +14 -0
  94. pytron/platforms/android/shell/app/src/main/cpp/include/boolobject.h +54 -0
  95. pytron/platforms/android/shell/app/src/main/cpp/include/bytearrayobject.h +44 -0
  96. pytron/platforms/android/shell/app/src/main/cpp/include/bytesobject.h +66 -0
  97. pytron/platforms/android/shell/app/src/main/cpp/include/ceval.h +145 -0
  98. pytron/platforms/android/shell/app/src/main/cpp/include/codecs.h +176 -0
  99. pytron/platforms/android/shell/app/src/main/cpp/include/compile.h +22 -0
  100. pytron/platforms/android/shell/app/src/main/cpp/include/complexobject.h +30 -0
  101. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/abstract.h +104 -0
  102. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/audit.h +8 -0
  103. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/bytearrayobject.h +38 -0
  104. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/bytesobject.h +42 -0
  105. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/cellobject.h +50 -0
  106. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/ceval.h +43 -0
  107. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/classobject.h +71 -0
  108. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/code.h +340 -0
  109. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/compile.h +50 -0
  110. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/complexobject.h +33 -0
  111. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/context.h +107 -0
  112. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/critical_section.h +154 -0
  113. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/descrobject.h +62 -0
  114. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/dictobject.h +105 -0
  115. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/fileobject.h +16 -0
  116. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/fileutils.h +16 -0
  117. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/floatobject.h +27 -0
  118. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/frameobject.h +35 -0
  119. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/funcobject.h +185 -0
  120. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/genobject.h +56 -0
  121. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/import.h +30 -0
  122. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/initconfig.h +334 -0
  123. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/listobject.h +53 -0
  124. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/lock.h +74 -0
  125. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/longintrepr.h +184 -0
  126. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/longobject.h +89 -0
  127. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/memoryobject.h +50 -0
  128. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/methodobject.h +66 -0
  129. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/modsupport.h +26 -0
  130. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/monitoring.h +269 -0
  131. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/object.h +493 -0
  132. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/objimpl.h +104 -0
  133. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/odictobject.h +43 -0
  134. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/picklebufobject.h +31 -0
  135. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pthread_stubs.h +105 -0
  136. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyatomic.h +614 -0
  137. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyatomic_gcc.h +615 -0
  138. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyatomic_msc.h +1197 -0
  139. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyatomic_std.h +1112 -0
  140. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyctype.h +39 -0
  141. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pydebug.h +38 -0
  142. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyerrors.h +132 -0
  143. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyfpe.h +15 -0
  144. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyframe.h +45 -0
  145. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyhash.h +54 -0
  146. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pylifecycle.h +89 -0
  147. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pymem.h +84 -0
  148. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pystate.h +275 -0
  149. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pystats.h +194 -0
  150. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pythonrun.h +96 -0
  151. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pythread.h +43 -0
  152. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pytime.h +27 -0
  153. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/setobject.h +71 -0
  154. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/traceback.h +13 -0
  155. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/tracemalloc.h +32 -0
  156. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/tupleobject.h +40 -0
  157. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/unicodeobject.h +773 -0
  158. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/warnings.h +20 -0
  159. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/weakrefobject.h +66 -0
  160. pytron/platforms/android/shell/app/src/main/cpp/include/critical_section.h +16 -0
  161. pytron/platforms/android/shell/app/src/main/cpp/include/datetime.h +267 -0
  162. pytron/platforms/android/shell/app/src/main/cpp/include/descrobject.h +100 -0
  163. pytron/platforms/android/shell/app/src/main/cpp/include/dictobject.h +108 -0
  164. pytron/platforms/android/shell/app/src/main/cpp/include/dynamic_annotations.h +499 -0
  165. pytron/platforms/android/shell/app/src/main/cpp/include/enumobject.h +17 -0
  166. pytron/platforms/android/shell/app/src/main/cpp/include/errcode.h +45 -0
  167. pytron/platforms/android/shell/app/src/main/cpp/include/exports.h +105 -0
  168. pytron/platforms/android/shell/app/src/main/cpp/include/fileobject.h +41 -0
  169. pytron/platforms/android/shell/app/src/main/cpp/include/fileutils.h +62 -0
  170. pytron/platforms/android/shell/app/src/main/cpp/include/floatobject.h +54 -0
  171. pytron/platforms/android/shell/app/src/main/cpp/include/frameobject.h +20 -0
  172. pytron/platforms/android/shell/app/src/main/cpp/include/genericaliasobject.h +14 -0
  173. pytron/platforms/android/shell/app/src/main/cpp/include/import.h +103 -0
  174. pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/atomic.h +392 -0
  175. pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/internal.h +969 -0
  176. pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/prim.h +329 -0
  177. pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/track.h +147 -0
  178. pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/types.h +721 -0
  179. pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc.h +565 -0
  180. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_abstract.h +61 -0
  181. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_asdl.h +112 -0
  182. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ast.h +945 -0
  183. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ast_state.h +271 -0
  184. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_atexit.h +31 -0
  185. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_audit.h +35 -0
  186. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_backoff.h +133 -0
  187. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_bitutils.h +186 -0
  188. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_blocks_output_buffer.h +321 -0
  189. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_brc.h +73 -0
  190. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_bytes_methods.h +82 -0
  191. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_bytesobject.h +149 -0
  192. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_c_array.h +39 -0
  193. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_call.h +206 -0
  194. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_capsule.h +17 -0
  195. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_cell.h +75 -0
  196. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ceval.h +390 -0
  197. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ceval_state.h +48 -0
  198. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_code.h +671 -0
  199. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_codecs.h +76 -0
  200. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_compile.h +230 -0
  201. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_complexobject.h +34 -0
  202. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_condvar.h +93 -0
  203. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_context.h +59 -0
  204. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_critical_section.h +237 -0
  205. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_crossinterp.h +406 -0
  206. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_crossinterp_data_registry.h +41 -0
  207. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_debug_offsets.h +379 -0
  208. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_descrobject.h +28 -0
  209. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_dict.h +410 -0
  210. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_dict_state.h +28 -0
  211. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_dtoa.h +40 -0
  212. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_emscripten_signal.h +30 -0
  213. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_emscripten_trampoline.h +70 -0
  214. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_exceptions.h +40 -0
  215. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_faulthandler.h +100 -0
  216. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_fileutils.h +320 -0
  217. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_fileutils_windows.h +98 -0
  218. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_floatobject.h +49 -0
  219. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_flowgraph.h +47 -0
  220. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_format.h +27 -0
  221. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_frame.h +61 -0
  222. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_freelist.h +111 -0
  223. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_freelist_state.h +70 -0
  224. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_function.h +53 -0
  225. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_gc.h +378 -0
  226. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_genobject.h +43 -0
  227. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_getopt.h +22 -0
  228. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_gil.h +66 -0
  229. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_global_objects.h +34 -0
  230. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_global_objects_fini_generated.h +1592 -0
  231. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_global_strings.h +854 -0
  232. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_hamt.h +113 -0
  233. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_hashtable.h +150 -0
  234. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_import.h +141 -0
  235. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_importdl.h +139 -0
  236. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_index_pool.h +36 -0
  237. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_initconfig.h +197 -0
  238. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_instruction_sequence.h +83 -0
  239. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_instruments.h +127 -0
  240. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interp.h +109 -0
  241. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interp_structs.h +977 -0
  242. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interpframe.h +401 -0
  243. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interpframe_structs.h +95 -0
  244. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interpolation.h +26 -0
  245. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_intrinsics.h +51 -0
  246. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_jit.h +29 -0
  247. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_list.h +81 -0
  248. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_llist.h +106 -0
  249. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_lock.h +236 -0
  250. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_long.h +319 -0
  251. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_magic_number.h +305 -0
  252. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_memoryobject.h +20 -0
  253. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_mimalloc.h +69 -0
  254. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_modsupport.h +99 -0
  255. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_moduleobject.h +62 -0
  256. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_namespace.h +21 -0
  257. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object.h +1029 -0
  258. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object_alloc.h +71 -0
  259. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object_deferred.h +32 -0
  260. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object_stack.h +95 -0
  261. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object_state.h +49 -0
  262. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_obmalloc.h +702 -0
  263. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_obmalloc_init.h +66 -0
  264. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_opcode_metadata.h +2117 -0
  265. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_opcode_utils.h +90 -0
  266. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_optimizer.h +318 -0
  267. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_parking_lot.h +97 -0
  268. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_parser.h +78 -0
  269. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pathconfig.h +26 -0
  270. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pyarena.h +68 -0
  271. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pyatomic_ft_wrappers.h +174 -0
  272. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pybuffer.h +21 -0
  273. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pyerrors.h +213 -0
  274. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pyhash.h +91 -0
  275. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pylifecycle.h +136 -0
  276. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pymath.h +205 -0
  277. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pymem.h +145 -0
  278. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pymem_init.h +103 -0
  279. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pystate.h +339 -0
  280. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pystats.h +21 -0
  281. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pythonrun.h +68 -0
  282. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pythread.h +172 -0
  283. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_qsbr.h +172 -0
  284. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_range.h +21 -0
  285. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_runtime.h +63 -0
  286. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_runtime_init.h +239 -0
  287. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_runtime_init_generated.h +1589 -0
  288. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_runtime_structs.h +310 -0
  289. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_semaphore.h +67 -0
  290. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_setobject.h +41 -0
  291. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_signal.h +108 -0
  292. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_sliceobject.h +20 -0
  293. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_stackref.h +791 -0
  294. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_stats.h +97 -0
  295. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_strhex.h +39 -0
  296. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_structs.h +88 -0
  297. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_structseq.h +40 -0
  298. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_symtable.h +201 -0
  299. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_sysmodule.h +32 -0
  300. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_template.h +26 -0
  301. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_time.h +334 -0
  302. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_token.h +110 -0
  303. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_traceback.h +111 -0
  304. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_tracemalloc.h +164 -0
  305. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_tstate.h +88 -0
  306. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_tuple.h +75 -0
  307. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_typedefs.h +18 -0
  308. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_typeobject.h +155 -0
  309. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_typevarobject.h +28 -0
  310. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ucnhash.h +36 -0
  311. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_unicodeobject.h +308 -0
  312. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_unicodeobject_generated.h +3132 -0
  313. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_unionobject.h +26 -0
  314. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_uniqueid.h +57 -0
  315. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_uop_ids.h +335 -0
  316. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_uop_metadata.h +1204 -0
  317. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_warnings.h +21 -0
  318. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_weakref.h +133 -0
  319. pytron/platforms/android/shell/app/src/main/cpp/include/intrcheck.h +23 -0
  320. pytron/platforms/android/shell/app/src/main/cpp/include/iterobject.h +24 -0
  321. pytron/platforms/android/shell/app/src/main/cpp/include/listobject.h +55 -0
  322. pytron/platforms/android/shell/app/src/main/cpp/include/lock.h +16 -0
  323. pytron/platforms/android/shell/app/src/main/cpp/include/longobject.h +178 -0
  324. pytron/platforms/android/shell/app/src/main/cpp/include/marshal.h +31 -0
  325. pytron/platforms/android/shell/app/src/main/cpp/include/memoryobject.h +34 -0
  326. pytron/platforms/android/shell/app/src/main/cpp/include/methodobject.h +146 -0
  327. pytron/platforms/android/shell/app/src/main/cpp/include/modsupport.h +146 -0
  328. pytron/platforms/android/shell/app/src/main/cpp/include/moduleobject.h +122 -0
  329. pytron/platforms/android/shell/app/src/main/cpp/include/monitoring.h +18 -0
  330. pytron/platforms/android/shell/app/src/main/cpp/include/object.h +828 -0
  331. pytron/platforms/android/shell/app/src/main/cpp/include/objimpl.h +211 -0
  332. pytron/platforms/android/shell/app/src/main/cpp/include/opcode.h +43 -0
  333. pytron/platforms/android/shell/app/src/main/cpp/include/opcode_ids.h +259 -0
  334. pytron/platforms/android/shell/app/src/main/cpp/include/osdefs.h +57 -0
  335. pytron/platforms/android/shell/app/src/main/cpp/include/osmodule.h +17 -0
  336. pytron/platforms/android/shell/app/src/main/cpp/include/patchlevel.h +49 -0
  337. pytron/platforms/android/shell/app/src/main/cpp/include/py_curses.h +117 -0
  338. pytron/platforms/android/shell/app/src/main/cpp/include/pyatomic.h +16 -0
  339. pytron/platforms/android/shell/app/src/main/cpp/include/pybuffer.h +145 -0
  340. pytron/platforms/android/shell/app/src/main/cpp/include/pycapsule.h +58 -0
  341. pytron/platforms/android/shell/app/src/main/cpp/include/pyconfig.h +2088 -0
  342. pytron/platforms/android/shell/app/src/main/cpp/include/pydtrace.h +59 -0
  343. pytron/platforms/android/shell/app/src/main/cpp/include/pyerrors.h +335 -0
  344. pytron/platforms/android/shell/app/src/main/cpp/include/pyexpat.h +62 -0
  345. pytron/platforms/android/shell/app/src/main/cpp/include/pyframe.h +26 -0
  346. pytron/platforms/android/shell/app/src/main/cpp/include/pyhash.h +59 -0
  347. pytron/platforms/android/shell/app/src/main/cpp/include/pylifecycle.h +80 -0
  348. pytron/platforms/android/shell/app/src/main/cpp/include/pymacconfig.h +91 -0
  349. pytron/platforms/android/shell/app/src/main/cpp/include/pymacro.h +243 -0
  350. pytron/platforms/android/shell/app/src/main/cpp/include/pymath.h +65 -0
  351. pytron/platforms/android/shell/app/src/main/cpp/include/pymem.h +110 -0
  352. pytron/platforms/android/shell/app/src/main/cpp/include/pyport.h +710 -0
  353. pytron/platforms/android/shell/app/src/main/cpp/include/pystate.h +132 -0
  354. pytron/platforms/android/shell/app/src/main/cpp/include/pystats.h +28 -0
  355. pytron/platforms/android/shell/app/src/main/cpp/include/pystrcmp.h +23 -0
  356. pytron/platforms/android/shell/app/src/main/cpp/include/pystrtod.h +37 -0
  357. pytron/platforms/android/shell/app/src/main/cpp/include/pythonrun.h +42 -0
  358. pytron/platforms/android/shell/app/src/main/cpp/include/pythread.h +131 -0
  359. pytron/platforms/android/shell/app/src/main/cpp/include/pytypedefs.h +30 -0
  360. pytron/platforms/android/shell/app/src/main/cpp/include/rangeobject.h +27 -0
  361. pytron/platforms/android/shell/app/src/main/cpp/include/refcount.h +555 -0
  362. pytron/platforms/android/shell/app/src/main/cpp/include/setobject.h +49 -0
  363. pytron/platforms/android/shell/app/src/main/cpp/include/sliceobject.h +69 -0
  364. pytron/platforms/android/shell/app/src/main/cpp/include/structmember.h +56 -0
  365. pytron/platforms/android/shell/app/src/main/cpp/include/structseq.h +46 -0
  366. pytron/platforms/android/shell/app/src/main/cpp/include/sysmodule.h +27 -0
  367. pytron/platforms/android/shell/app/src/main/cpp/include/traceback.h +26 -0
  368. pytron/platforms/android/shell/app/src/main/cpp/include/tupleobject.h +46 -0
  369. pytron/platforms/android/shell/app/src/main/cpp/include/typeslots.h +96 -0
  370. pytron/platforms/android/shell/app/src/main/cpp/include/unicodeobject.h +1029 -0
  371. pytron/platforms/android/shell/app/src/main/cpp/include/warnings.h +45 -0
  372. pytron/platforms/android/shell/app/src/main/cpp/include/weakrefobject.h +46 -0
  373. pytron/platforms/android/shell/app/src/main/cpp/pytron_bridge.cpp +224 -0
  374. pytron/platforms/android/shell/app/src/main/java/com/pytron/shell/MainActivity.kt +208 -0
  375. pytron/platforms/android/shell/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  376. pytron/platforms/android/shell/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  377. pytron/platforms/android/shell/build.gradle +11 -0
  378. pytron/platforms/android/shell/gradle/wrapper/gradle-wrapper.jar +0 -0
  379. pytron/platforms/android/shell/gradle/wrapper/gradle-wrapper.properties +5 -0
  380. pytron/platforms/android/shell/gradle.properties +2 -0
  381. pytron/platforms/android/shell/gradlew.bat +85 -0
  382. pytron/platforms/android/shell/settings.gradle +16 -0
  383. pytron/platforms/darwin.py +82 -0
  384. pytron/platforms/darwin_ops/libs.py +31 -0
  385. pytron/platforms/darwin_ops/system.py +182 -0
  386. pytron/platforms/darwin_ops/utils.py +85 -0
  387. pytron/platforms/darwin_ops/webview.py +5 -0
  388. pytron/platforms/darwin_ops/window.py +102 -0
  389. pytron/platforms/interface.py +152 -0
  390. pytron/platforms/linux.py +82 -0
  391. pytron/platforms/linux_ops/libs.py +49 -0
  392. pytron/platforms/linux_ops/system.py +316 -0
  393. pytron/platforms/linux_ops/utils.py +19 -0
  394. pytron/platforms/linux_ops/webview.py +5 -0
  395. pytron/platforms/linux_ops/window.py +115 -0
  396. pytron/platforms/windows.py +136 -0
  397. pytron/platforms/windows_ops/__init__.py +0 -0
  398. pytron/platforms/windows_ops/constants.py +126 -0
  399. pytron/platforms/windows_ops/system.py +518 -0
  400. pytron/platforms/windows_ops/utils.py +3 -0
  401. pytron/platforms/windows_ops/webview.py +5 -0
  402. pytron/platforms/windows_ops/window.py +361 -0
  403. pytron/plugin.py +467 -0
  404. pytron/rcedit-x64.exe +0 -0
  405. pytron/router.py +146 -0
  406. pytron/serializer.py +240 -0
  407. pytron/shortcuts.py +279 -0
  408. pytron/state.py +76 -0
  409. pytron/tray.py +399 -0
  410. pytron/updater.py +181 -0
  411. pytron/utf8_hook.py +112 -0
  412. pytron/utils.py +44 -0
  413. pytron/webview.py +722 -0
  414. pytron_kit-0.3.12.dist-info/METADATA +131 -0
  415. pytron_kit-0.3.12.dist-info/RECORD +419 -0
  416. pytron_kit-0.3.12.dist-info/WHEEL +5 -0
  417. pytron_kit-0.3.12.dist-info/entry_points.txt +2 -0
  418. pytron_kit-0.3.12.dist-info/licenses/LICENSE +201 -0
  419. pytron_kit-0.3.12.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1029 @@
1
+ #ifndef Py_INTERNAL_OBJECT_H
2
+ #define Py_INTERNAL_OBJECT_H
3
+ #ifdef __cplusplus
4
+ extern "C" {
5
+ #endif
6
+
7
+ #ifndef Py_BUILD_CORE
8
+ # error "this header requires Py_BUILD_CORE define"
9
+ #endif
10
+
11
+ #include "pycore_emscripten_trampoline.h" // _PyCFunction_TrampolineCall()
12
+ #include "pycore_gc.h" // _PyObject_GC_TRACK()
13
+ #include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_PTR_ACQUIRE()
14
+ #include "pycore_pystate.h" // _PyInterpreterState_GET()
15
+ #include "pycore_runtime.h" // _PyRuntime
16
+ #include "pycore_typeobject.h" // _PyStaticType_GetState()
17
+ #include "pycore_uniqueid.h" // _PyObject_ThreadIncrefSlow()
18
+
19
+ #include <stdbool.h> // bool
20
+
21
+
22
+ // This value is added to `ob_ref_shared` for objects that use deferred
23
+ // reference counting so that they are not immediately deallocated when the
24
+ // non-deferred reference count drops to zero.
25
+ //
26
+ // The value is half the maximum shared refcount because the low two bits of
27
+ // `ob_ref_shared` are used for flags.
28
+ #define _Py_REF_DEFERRED (PY_SSIZE_T_MAX / 8)
29
+
30
+ /* For backwards compatibility -- Do not use this */
31
+ #define _Py_IsImmortalLoose(op) _Py_IsImmortal
32
+
33
+
34
+ /* Check if an object is consistent. For example, ensure that the reference
35
+ counter is greater than or equal to 1, and ensure that ob_type is not NULL.
36
+
37
+ Call _PyObject_AssertFailed() if the object is inconsistent.
38
+
39
+ If check_content is zero, only check header fields: reduce the overhead.
40
+
41
+ The function always return 1. The return value is just here to be able to
42
+ write:
43
+
44
+ assert(_PyObject_CheckConsistency(obj, 1)); */
45
+ extern int _PyObject_CheckConsistency(PyObject *op, int check_content);
46
+
47
+ extern void _PyDebugAllocatorStats(FILE *out, const char *block_name,
48
+ int num_blocks, size_t sizeof_block);
49
+
50
+ extern void _PyObject_DebugTypeStats(FILE *out);
51
+
52
+ #ifdef Py_TRACE_REFS
53
+ // Forget a reference registered by _Py_NewReference(). Function called by
54
+ // _Py_Dealloc().
55
+ //
56
+ // On a free list, the function can be used before modifying an object to
57
+ // remove the object from traced objects. Then _Py_NewReference() or
58
+ // _Py_NewReferenceNoTotal() should be called again on the object to trace
59
+ // it again.
60
+ extern void _Py_ForgetReference(PyObject *);
61
+ #endif
62
+
63
+ // Export for shared _testinternalcapi extension
64
+ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
65
+
66
+ /* We need to maintain an internal copy of Py{Var}Object_HEAD_INIT to avoid
67
+ designated initializer conflicts in C++20. If we use the definition in
68
+ object.h, we will be mixing designated and non-designated initializers in
69
+ pycore objects which is forbiddent in C++20. However, if we then use
70
+ designated initializers in object.h then Extensions without designated break.
71
+ Furthermore, we can't use designated initializers in Extensions since these
72
+ are not supported pre-C++20. Thus, keeping an internal copy here is the most
73
+ backwards compatible solution */
74
+ #if defined(Py_GIL_DISABLED)
75
+ #define _PyObject_HEAD_INIT(type) \
76
+ { \
77
+ .ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL, \
78
+ .ob_flags = _Py_STATICALLY_ALLOCATED_FLAG, \
79
+ .ob_gc_bits = _PyGC_BITS_DEFERRED, \
80
+ .ob_type = (type) \
81
+ }
82
+ #else
83
+ #if SIZEOF_VOID_P > 4
84
+ #define _PyObject_HEAD_INIT(type) \
85
+ { \
86
+ .ob_refcnt = _Py_IMMORTAL_INITIAL_REFCNT, \
87
+ .ob_flags = _Py_STATIC_FLAG_BITS, \
88
+ .ob_type = (type) \
89
+ }
90
+ #else
91
+ #define _PyObject_HEAD_INIT(type) \
92
+ { \
93
+ .ob_refcnt = _Py_STATIC_IMMORTAL_INITIAL_REFCNT, \
94
+ .ob_type = (type) \
95
+ }
96
+ #endif
97
+ #endif
98
+ #define _PyVarObject_HEAD_INIT(type, size) \
99
+ { \
100
+ .ob_base = _PyObject_HEAD_INIT(type), \
101
+ .ob_size = size \
102
+ }
103
+
104
+ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
105
+ const char *func,
106
+ const char *message);
107
+
108
+ #define _Py_FatalRefcountError(message) \
109
+ _Py_FatalRefcountErrorFunc(__func__, (message))
110
+
111
+ #define _PyReftracerTrack(obj, operation) \
112
+ do { \
113
+ struct _reftracer_runtime_state *tracer = &_PyRuntime.ref_tracer; \
114
+ if (tracer->tracer_func != NULL) { \
115
+ void *data = tracer->tracer_data; \
116
+ tracer->tracer_func((obj), (operation), data); \
117
+ } \
118
+ } while(0)
119
+
120
+ #ifdef Py_REF_DEBUG
121
+ /* The symbol is only exposed in the API for the sake of extensions
122
+ built against the pre-3.12 stable ABI. */
123
+ PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
124
+
125
+ extern void _Py_AddRefTotal(PyThreadState *, Py_ssize_t);
126
+ extern PyAPI_FUNC(void) _Py_IncRefTotal(PyThreadState *);
127
+ extern PyAPI_FUNC(void) _Py_DecRefTotal(PyThreadState *);
128
+
129
+ # define _Py_DEC_REFTOTAL(interp) \
130
+ interp->object_state.reftotal--
131
+ #endif
132
+
133
+ // Increment reference count by n
134
+ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
135
+ {
136
+ if (_Py_IsImmortal(op)) {
137
+ _Py_INCREF_IMMORTAL_STAT_INC();
138
+ return;
139
+ }
140
+ #ifndef Py_GIL_DISABLED
141
+ Py_ssize_t refcnt = _Py_REFCNT(op);
142
+ Py_ssize_t new_refcnt = refcnt + n;
143
+ if (new_refcnt >= (Py_ssize_t)_Py_IMMORTAL_MINIMUM_REFCNT) {
144
+ new_refcnt = _Py_IMMORTAL_INITIAL_REFCNT;
145
+ }
146
+ # if SIZEOF_VOID_P > 4
147
+ op->ob_refcnt = (PY_UINT32_T)new_refcnt;
148
+ # else
149
+ op->ob_refcnt = new_refcnt;
150
+ # endif
151
+ # ifdef Py_REF_DEBUG
152
+ _Py_AddRefTotal(_PyThreadState_GET(), new_refcnt - refcnt);
153
+ # endif
154
+ #else
155
+ if (_Py_IsOwnedByCurrentThread(op)) {
156
+ uint32_t local = op->ob_ref_local;
157
+ Py_ssize_t refcnt = (Py_ssize_t)local + n;
158
+ # if PY_SSIZE_T_MAX > UINT32_MAX
159
+ if (refcnt > (Py_ssize_t)UINT32_MAX) {
160
+ // Make the object immortal if the 32-bit local reference count
161
+ // would overflow.
162
+ refcnt = _Py_IMMORTAL_REFCNT_LOCAL;
163
+ }
164
+ # endif
165
+ _Py_atomic_store_uint32_relaxed(&op->ob_ref_local, (uint32_t)refcnt);
166
+ }
167
+ else {
168
+ _Py_atomic_add_ssize(&op->ob_ref_shared, (n << _Py_REF_SHARED_SHIFT));
169
+ }
170
+ # ifdef Py_REF_DEBUG
171
+ _Py_AddRefTotal(_PyThreadState_GET(), n);
172
+ # endif
173
+ #endif
174
+ // Although the ref count was increased by `n` (which may be greater than 1)
175
+ // it is only a single increment (i.e. addition) operation, so only 1 refcnt
176
+ // increment operation is counted.
177
+ _Py_INCREF_STAT_INC();
178
+ }
179
+ #define _Py_RefcntAdd(op, n) _Py_RefcntAdd(_PyObject_CAST(op), n)
180
+
181
+ // Checks if an object has a single, unique reference. If the caller holds a
182
+ // unique reference, it may be able to safely modify the object in-place.
183
+ static inline int
184
+ _PyObject_IsUniquelyReferenced(PyObject *ob)
185
+ {
186
+ #if !defined(Py_GIL_DISABLED)
187
+ return Py_REFCNT(ob) == 1;
188
+ #else
189
+ // NOTE: the entire ob_ref_shared field must be zero, including flags, to
190
+ // ensure that other threads cannot concurrently create new references to
191
+ // this object.
192
+ return (_Py_IsOwnedByCurrentThread(ob) &&
193
+ _Py_atomic_load_uint32_relaxed(&ob->ob_ref_local) == 1 &&
194
+ _Py_atomic_load_ssize_relaxed(&ob->ob_ref_shared) == 0);
195
+ #endif
196
+ }
197
+
198
+ PyAPI_FUNC(void) _Py_SetImmortal(PyObject *op);
199
+ PyAPI_FUNC(void) _Py_SetImmortalUntracked(PyObject *op);
200
+
201
+ // Makes an immortal object mortal again with the specified refcnt. Should only
202
+ // be used during runtime finalization.
203
+ static inline void _Py_SetMortal(PyObject *op, short refcnt)
204
+ {
205
+ if (op) {
206
+ assert(_Py_IsImmortal(op));
207
+ #ifdef Py_GIL_DISABLED
208
+ op->ob_tid = _Py_UNOWNED_TID;
209
+ op->ob_ref_local = 0;
210
+ op->ob_ref_shared = _Py_REF_SHARED(refcnt, _Py_REF_MERGED);
211
+ #else
212
+ op->ob_refcnt = refcnt;
213
+ #endif
214
+ }
215
+ }
216
+
217
+ /* _Py_ClearImmortal() should only be used during runtime finalization. */
218
+ static inline void _Py_ClearImmortal(PyObject *op)
219
+ {
220
+ if (op) {
221
+ _Py_SetMortal(op, 1);
222
+ Py_DECREF(op);
223
+ }
224
+ }
225
+ #define _Py_ClearImmortal(op) \
226
+ do { \
227
+ _Py_ClearImmortal(_PyObject_CAST(op)); \
228
+ op = NULL; \
229
+ } while (0)
230
+
231
+ #if !defined(Py_GIL_DISABLED)
232
+ static inline void
233
+ _Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
234
+ {
235
+ if (_Py_IsImmortal(op)) {
236
+ _Py_DECREF_IMMORTAL_STAT_INC();
237
+ return;
238
+ }
239
+ _Py_DECREF_STAT_INC();
240
+ #ifdef Py_REF_DEBUG
241
+ _Py_DEC_REFTOTAL(PyInterpreterState_Get());
242
+ #endif
243
+ if (--op->ob_refcnt != 0) {
244
+ assert(op->ob_refcnt > 0);
245
+ }
246
+ else {
247
+ #ifdef Py_TRACE_REFS
248
+ _Py_ForgetReference(op);
249
+ #endif
250
+ _PyReftracerTrack(op, PyRefTracer_DESTROY);
251
+ destruct(op);
252
+ }
253
+ }
254
+
255
+ static inline void
256
+ _Py_DECREF_NO_DEALLOC(PyObject *op)
257
+ {
258
+ if (_Py_IsImmortal(op)) {
259
+ _Py_DECREF_IMMORTAL_STAT_INC();
260
+ return;
261
+ }
262
+ _Py_DECREF_STAT_INC();
263
+ #ifdef Py_REF_DEBUG
264
+ _Py_DEC_REFTOTAL(PyInterpreterState_Get());
265
+ #endif
266
+ op->ob_refcnt--;
267
+ #ifdef Py_DEBUG
268
+ if (op->ob_refcnt <= 0) {
269
+ _Py_FatalRefcountError("Expected a positive remaining refcount");
270
+ }
271
+ #endif
272
+ }
273
+
274
+ #else
275
+ // TODO: implement Py_DECREF specializations for Py_GIL_DISABLED build
276
+ static inline void
277
+ _Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
278
+ {
279
+ Py_DECREF(op);
280
+ }
281
+
282
+ static inline void
283
+ _Py_DECREF_NO_DEALLOC(PyObject *op)
284
+ {
285
+ Py_DECREF(op);
286
+ }
287
+
288
+ static inline int
289
+ _Py_REF_IS_MERGED(Py_ssize_t ob_ref_shared)
290
+ {
291
+ return (ob_ref_shared & _Py_REF_SHARED_FLAG_MASK) == _Py_REF_MERGED;
292
+ }
293
+
294
+ static inline int
295
+ _Py_REF_IS_QUEUED(Py_ssize_t ob_ref_shared)
296
+ {
297
+ return (ob_ref_shared & _Py_REF_SHARED_FLAG_MASK) == _Py_REF_QUEUED;
298
+ }
299
+
300
+ // Merge the local and shared reference count fields and add `extra` to the
301
+ // refcount when merging.
302
+ Py_ssize_t _Py_ExplicitMergeRefcount(PyObject *op, Py_ssize_t extra);
303
+ #endif // !defined(Py_GIL_DISABLED)
304
+
305
+ #ifdef Py_REF_DEBUG
306
+ # undef _Py_DEC_REFTOTAL
307
+ #endif
308
+
309
+
310
+ extern int _PyType_CheckConsistency(PyTypeObject *type);
311
+ extern int _PyDict_CheckConsistency(PyObject *mp, int check_content);
312
+
313
+ // Fast inlined version of PyType_HasFeature()
314
+ static inline int
315
+ _PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
316
+ return ((FT_ATOMIC_LOAD_ULONG_RELAXED(type->tp_flags) & feature) != 0);
317
+ }
318
+
319
+ extern void _PyType_InitCache(PyInterpreterState *interp);
320
+
321
+ extern PyStatus _PyObject_InitState(PyInterpreterState *interp);
322
+ extern void _PyObject_FiniState(PyInterpreterState *interp);
323
+ extern bool _PyRefchain_IsTraced(PyInterpreterState *interp, PyObject *obj);
324
+
325
+ // Macros used for per-thread reference counting in the free threading build.
326
+ // They resolve to normal Py_INCREF/DECREF calls in the default build.
327
+ //
328
+ // The macros are used for only a few references that would otherwise cause
329
+ // scaling bottlenecks in the free threading build:
330
+ // - The reference from an object to `ob_type`.
331
+ // - The reference from a function to `func_code`.
332
+ // - The reference from a function to `func_globals` and `func_builtins`.
333
+ //
334
+ // It's safe, but not performant or necessary, to use these macros for other
335
+ // references to code, type, or dict objects. It's also safe to mix their
336
+ // usage with normal Py_INCREF/DECREF calls.
337
+ //
338
+ // See also Include/internal/pycore_dict.h for _Py_INCREF_DICT/_Py_DECREF_DICT.
339
+ #ifndef Py_GIL_DISABLED
340
+ # define _Py_INCREF_TYPE Py_INCREF
341
+ # define _Py_DECREF_TYPE Py_DECREF
342
+ # define _Py_INCREF_CODE Py_INCREF
343
+ # define _Py_DECREF_CODE Py_DECREF
344
+ #else
345
+ static inline void
346
+ _Py_THREAD_INCREF_OBJECT(PyObject *obj, Py_ssize_t unique_id)
347
+ {
348
+ _PyThreadStateImpl *tstate = (_PyThreadStateImpl *)_PyThreadState_GET();
349
+
350
+ // The table index is `unique_id - 1` because 0 is not a valid unique id.
351
+ // Unsigned comparison so that `idx=-1` is handled by the "else".
352
+ size_t idx = (size_t)(unique_id - 1);
353
+ if (idx < (size_t)tstate->refcounts.size) {
354
+ # ifdef Py_REF_DEBUG
355
+ _Py_INCREF_IncRefTotal();
356
+ # endif
357
+ _Py_INCREF_STAT_INC();
358
+ tstate->refcounts.values[idx]++;
359
+ }
360
+ else {
361
+ // The slow path resizes the per-thread refcount array if necessary.
362
+ // It handles the unique_id=0 case to keep the inlinable function smaller.
363
+ _PyObject_ThreadIncrefSlow(obj, idx);
364
+ }
365
+ }
366
+
367
+ static inline void
368
+ _Py_INCREF_TYPE(PyTypeObject *type)
369
+ {
370
+ if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
371
+ assert(_Py_IsImmortal(type));
372
+ _Py_INCREF_IMMORTAL_STAT_INC();
373
+ return;
374
+ }
375
+
376
+ // gh-122974: GCC 11 warns about the access to PyHeapTypeObject fields when
377
+ // _Py_INCREF_TYPE() is called on a statically allocated type. The
378
+ // _PyType_HasFeature check above ensures that the type is a heap type.
379
+ #if defined(__GNUC__) && __GNUC__ >= 11
380
+ # pragma GCC diagnostic push
381
+ # pragma GCC diagnostic ignored "-Warray-bounds"
382
+ #endif
383
+ _Py_THREAD_INCREF_OBJECT((PyObject *)type, ((PyHeapTypeObject *)type)->unique_id);
384
+ #if defined(__GNUC__) && __GNUC__ >= 11
385
+ # pragma GCC diagnostic pop
386
+ #endif
387
+ }
388
+
389
+ static inline void
390
+ _Py_INCREF_CODE(PyCodeObject *co)
391
+ {
392
+ _Py_THREAD_INCREF_OBJECT((PyObject *)co, co->_co_unique_id);
393
+ }
394
+
395
+ static inline void
396
+ _Py_THREAD_DECREF_OBJECT(PyObject *obj, Py_ssize_t unique_id)
397
+ {
398
+ _PyThreadStateImpl *tstate = (_PyThreadStateImpl *)_PyThreadState_GET();
399
+
400
+ // The table index is `unique_id - 1` because 0 is not a valid unique id.
401
+ // Unsigned comparison so that `idx=-1` is handled by the "else".
402
+ size_t idx = (size_t)(unique_id - 1);
403
+ if (idx < (size_t)tstate->refcounts.size) {
404
+ # ifdef Py_REF_DEBUG
405
+ _Py_DECREF_DecRefTotal();
406
+ # endif
407
+ _Py_DECREF_STAT_INC();
408
+ tstate->refcounts.values[idx]--;
409
+ }
410
+ else {
411
+ // Directly decref the object if the id is not assigned or if
412
+ // per-thread refcounting has been disabled on this object.
413
+ Py_DECREF(obj);
414
+ }
415
+ }
416
+
417
+ static inline void
418
+ _Py_DECREF_TYPE(PyTypeObject *type)
419
+ {
420
+ if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
421
+ assert(_Py_IsImmortal(type));
422
+ _Py_DECREF_IMMORTAL_STAT_INC();
423
+ return;
424
+ }
425
+ PyHeapTypeObject *ht = (PyHeapTypeObject *)type;
426
+ _Py_THREAD_DECREF_OBJECT((PyObject *)type, ht->unique_id);
427
+ }
428
+
429
+ static inline void
430
+ _Py_DECREF_CODE(PyCodeObject *co)
431
+ {
432
+ _Py_THREAD_DECREF_OBJECT((PyObject *)co, co->_co_unique_id);
433
+ }
434
+ #endif
435
+
436
+ #ifndef Py_GIL_DISABLED
437
+ #ifdef Py_REF_DEBUG
438
+
439
+ static inline void Py_DECREF_MORTAL(const char *filename, int lineno, PyObject *op)
440
+ {
441
+ if (op->ob_refcnt <= 0) {
442
+ _Py_NegativeRefcount(filename, lineno, op);
443
+ }
444
+ _Py_DECREF_STAT_INC();
445
+ assert(!_Py_IsStaticImmortal(op));
446
+ if (!_Py_IsImmortal(op)) {
447
+ _Py_DECREF_DecRefTotal();
448
+ }
449
+ if (--op->ob_refcnt == 0) {
450
+ _Py_Dealloc(op);
451
+ }
452
+ }
453
+ #define Py_DECREF_MORTAL(op) Py_DECREF_MORTAL(__FILE__, __LINE__, _PyObject_CAST(op))
454
+
455
+ static inline void _Py_DECREF_MORTAL_SPECIALIZED(const char *filename, int lineno, PyObject *op, destructor destruct)
456
+ {
457
+ if (op->ob_refcnt <= 0) {
458
+ _Py_NegativeRefcount(filename, lineno, op);
459
+ }
460
+ _Py_DECREF_STAT_INC();
461
+ assert(!_Py_IsStaticImmortal(op));
462
+ if (!_Py_IsImmortal(op)) {
463
+ _Py_DECREF_DecRefTotal();
464
+ }
465
+ if (--op->ob_refcnt == 0) {
466
+ #ifdef Py_TRACE_REFS
467
+ _Py_ForgetReference(op);
468
+ #endif
469
+ _PyReftracerTrack(op, PyRefTracer_DESTROY);
470
+ destruct(op);
471
+ }
472
+ }
473
+ #define Py_DECREF_MORTAL_SPECIALIZED(op, destruct) _Py_DECREF_MORTAL_SPECIALIZED(__FILE__, __LINE__, op, destruct)
474
+
475
+ #else
476
+
477
+ static inline void Py_DECREF_MORTAL(PyObject *op)
478
+ {
479
+ assert(!_Py_IsStaticImmortal(op));
480
+ _Py_DECREF_STAT_INC();
481
+ if (--op->ob_refcnt == 0) {
482
+ _Py_Dealloc(op);
483
+ }
484
+ }
485
+ #define Py_DECREF_MORTAL(op) Py_DECREF_MORTAL(_PyObject_CAST(op))
486
+
487
+ static inline void Py_DECREF_MORTAL_SPECIALIZED(PyObject *op, destructor destruct)
488
+ {
489
+ assert(!_Py_IsStaticImmortal(op));
490
+ _Py_DECREF_STAT_INC();
491
+ if (--op->ob_refcnt == 0) {
492
+ _PyReftracerTrack(op, PyRefTracer_DESTROY);
493
+ destruct(op);
494
+ }
495
+ }
496
+ #define Py_DECREF_MORTAL_SPECIALIZED(op, destruct) Py_DECREF_MORTAL_SPECIALIZED(_PyObject_CAST(op), destruct)
497
+
498
+ #endif
499
+ #endif
500
+
501
+ /* Inline functions trading binary compatibility for speed:
502
+ _PyObject_Init() is the fast version of PyObject_Init(), and
503
+ _PyObject_InitVar() is the fast version of PyObject_InitVar().
504
+
505
+ These inline functions must not be called with op=NULL. */
506
+ static inline void
507
+ _PyObject_Init(PyObject *op, PyTypeObject *typeobj)
508
+ {
509
+ assert(op != NULL);
510
+ Py_SET_TYPE(op, typeobj);
511
+ assert(_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE) || _Py_IsImmortal(typeobj));
512
+ _Py_INCREF_TYPE(typeobj);
513
+ _Py_NewReference(op);
514
+ }
515
+
516
+ static inline void
517
+ _PyObject_InitVar(PyVarObject *op, PyTypeObject *typeobj, Py_ssize_t size)
518
+ {
519
+ assert(op != NULL);
520
+ assert(typeobj != &PyLong_Type);
521
+ _PyObject_Init((PyObject *)op, typeobj);
522
+ Py_SET_SIZE(op, size);
523
+ }
524
+
525
+ // Macros to accept any type for the parameter, and to automatically pass
526
+ // the filename and the filename (if NDEBUG is not defined) where the macro
527
+ // is called.
528
+ #ifdef NDEBUG
529
+ # define _PyObject_GC_TRACK(op) \
530
+ _PyObject_GC_TRACK(_PyObject_CAST(op))
531
+ # define _PyObject_GC_UNTRACK(op) \
532
+ _PyObject_GC_UNTRACK(_PyObject_CAST(op))
533
+ #else
534
+ # define _PyObject_GC_TRACK(op) \
535
+ _PyObject_GC_TRACK(__FILE__, __LINE__, _PyObject_CAST(op))
536
+ # define _PyObject_GC_UNTRACK(op) \
537
+ _PyObject_GC_UNTRACK(__FILE__, __LINE__, _PyObject_CAST(op))
538
+ #endif
539
+
540
+ #ifdef Py_GIL_DISABLED
541
+
542
+ /* Tries to increment an object's reference count
543
+ *
544
+ * This is a specialized version of _Py_TryIncref that only succeeds if the
545
+ * object is immortal or local to this thread. It does not handle the case
546
+ * where the reference count modification requires an atomic operation. This
547
+ * allows call sites to specialize for the immortal/local case.
548
+ */
549
+ static inline int
550
+ _Py_TryIncrefFast(PyObject *op) {
551
+ uint32_t local = _Py_atomic_load_uint32_relaxed(&op->ob_ref_local);
552
+ local += 1;
553
+ if (local == 0) {
554
+ // immortal
555
+ _Py_INCREF_IMMORTAL_STAT_INC();
556
+ return 1;
557
+ }
558
+ if (_Py_IsOwnedByCurrentThread(op)) {
559
+ _Py_INCREF_STAT_INC();
560
+ _Py_atomic_store_uint32_relaxed(&op->ob_ref_local, local);
561
+ #ifdef Py_REF_DEBUG
562
+ _Py_IncRefTotal(_PyThreadState_GET());
563
+ #endif
564
+ return 1;
565
+ }
566
+ return 0;
567
+ }
568
+
569
+ static inline int
570
+ _Py_TryIncRefShared(PyObject *op)
571
+ {
572
+ Py_ssize_t shared = _Py_atomic_load_ssize_relaxed(&op->ob_ref_shared);
573
+ for (;;) {
574
+ // If the shared refcount is zero and the object is either merged
575
+ // or may not have weak references, then we cannot incref it.
576
+ if (shared == 0 || shared == _Py_REF_MERGED) {
577
+ return 0;
578
+ }
579
+
580
+ if (_Py_atomic_compare_exchange_ssize(
581
+ &op->ob_ref_shared,
582
+ &shared,
583
+ shared + (1 << _Py_REF_SHARED_SHIFT))) {
584
+ #ifdef Py_REF_DEBUG
585
+ _Py_IncRefTotal(_PyThreadState_GET());
586
+ #endif
587
+ _Py_INCREF_STAT_INC();
588
+ return 1;
589
+ }
590
+ }
591
+ }
592
+
593
+ /* Tries to incref the object op and ensures that *src still points to it. */
594
+ static inline int
595
+ _Py_TryIncrefCompare(PyObject **src, PyObject *op)
596
+ {
597
+ if (_Py_TryIncrefFast(op)) {
598
+ return 1;
599
+ }
600
+ if (!_Py_TryIncRefShared(op)) {
601
+ return 0;
602
+ }
603
+ if (op != _Py_atomic_load_ptr(src)) {
604
+ Py_DECREF(op);
605
+ return 0;
606
+ }
607
+ return 1;
608
+ }
609
+
610
+ /* Loads and increfs an object from ptr, which may contain a NULL value.
611
+ Safe with concurrent (atomic) updates to ptr.
612
+ NOTE: The writer must set maybe-weakref on the stored object! */
613
+ static inline PyObject *
614
+ _Py_XGetRef(PyObject **ptr)
615
+ {
616
+ for (;;) {
617
+ PyObject *value = _PyObject_CAST(_Py_atomic_load_ptr(ptr));
618
+ if (value == NULL) {
619
+ return value;
620
+ }
621
+ if (_Py_TryIncrefCompare(ptr, value)) {
622
+ return value;
623
+ }
624
+ }
625
+ }
626
+
627
+ /* Attempts to loads and increfs an object from ptr. Returns NULL
628
+ on failure, which may be due to a NULL value or a concurrent update. */
629
+ static inline PyObject *
630
+ _Py_TryXGetRef(PyObject **ptr)
631
+ {
632
+ PyObject *value = _PyObject_CAST(_Py_atomic_load_ptr(ptr));
633
+ if (value == NULL) {
634
+ return value;
635
+ }
636
+ if (_Py_TryIncrefCompare(ptr, value)) {
637
+ return value;
638
+ }
639
+ return NULL;
640
+ }
641
+
642
+ /* Like Py_NewRef but also optimistically sets _Py_REF_MAYBE_WEAKREF
643
+ on objects owned by a different thread. */
644
+ static inline PyObject *
645
+ _Py_NewRefWithLock(PyObject *op)
646
+ {
647
+ if (_Py_TryIncrefFast(op)) {
648
+ return op;
649
+ }
650
+ #ifdef Py_REF_DEBUG
651
+ _Py_IncRefTotal(_PyThreadState_GET());
652
+ #endif
653
+ _Py_INCREF_STAT_INC();
654
+ for (;;) {
655
+ Py_ssize_t shared = _Py_atomic_load_ssize_relaxed(&op->ob_ref_shared);
656
+ Py_ssize_t new_shared = shared + (1 << _Py_REF_SHARED_SHIFT);
657
+ if ((shared & _Py_REF_SHARED_FLAG_MASK) == 0) {
658
+ new_shared |= _Py_REF_MAYBE_WEAKREF;
659
+ }
660
+ if (_Py_atomic_compare_exchange_ssize(
661
+ &op->ob_ref_shared,
662
+ &shared,
663
+ new_shared)) {
664
+ return op;
665
+ }
666
+ }
667
+ }
668
+
669
+ static inline PyObject *
670
+ _Py_XNewRefWithLock(PyObject *obj)
671
+ {
672
+ if (obj == NULL) {
673
+ return NULL;
674
+ }
675
+ return _Py_NewRefWithLock(obj);
676
+ }
677
+
678
+ static inline void
679
+ _PyObject_SetMaybeWeakref(PyObject *op)
680
+ {
681
+ if (_Py_IsImmortal(op)) {
682
+ return;
683
+ }
684
+ for (;;) {
685
+ Py_ssize_t shared = _Py_atomic_load_ssize_relaxed(&op->ob_ref_shared);
686
+ if ((shared & _Py_REF_SHARED_FLAG_MASK) != 0) {
687
+ // Nothing to do if it's in WEAKREFS, QUEUED, or MERGED states.
688
+ return;
689
+ }
690
+ if (_Py_atomic_compare_exchange_ssize(
691
+ &op->ob_ref_shared, &shared, shared | _Py_REF_MAYBE_WEAKREF)) {
692
+ return;
693
+ }
694
+ }
695
+ }
696
+
697
+ extern PyAPI_FUNC(int) _PyObject_ResurrectEndSlow(PyObject *op);
698
+ #endif
699
+
700
+ // Temporarily resurrects an object during deallocation. The refcount is set
701
+ // to one.
702
+ static inline void
703
+ _PyObject_ResurrectStart(PyObject *op)
704
+ {
705
+ assert(Py_REFCNT(op) == 0);
706
+ #ifdef Py_REF_DEBUG
707
+ _Py_IncRefTotal(_PyThreadState_GET());
708
+ #endif
709
+ #ifdef Py_GIL_DISABLED
710
+ _Py_atomic_store_uintptr_relaxed(&op->ob_tid, _Py_ThreadId());
711
+ _Py_atomic_store_uint32_relaxed(&op->ob_ref_local, 1);
712
+ _Py_atomic_store_ssize_relaxed(&op->ob_ref_shared, 0);
713
+ #else
714
+ Py_SET_REFCNT(op, 1);
715
+ #endif
716
+ #ifdef Py_TRACE_REFS
717
+ _Py_ResurrectReference(op);
718
+ #endif
719
+ }
720
+
721
+ // Undoes an object resurrection by decrementing the refcount without calling
722
+ // _Py_Dealloc(). Returns 0 if the object is dead (the normal case), and
723
+ // deallocation should continue. Returns 1 if the object is still alive.
724
+ static inline int
725
+ _PyObject_ResurrectEnd(PyObject *op)
726
+ {
727
+ #ifdef Py_REF_DEBUG
728
+ _Py_DecRefTotal(_PyThreadState_GET());
729
+ #endif
730
+ #ifndef Py_GIL_DISABLED
731
+ Py_SET_REFCNT(op, Py_REFCNT(op) - 1);
732
+ if (Py_REFCNT(op) == 0) {
733
+ # ifdef Py_TRACE_REFS
734
+ _Py_ForgetReference(op);
735
+ # endif
736
+ return 0;
737
+ }
738
+ return 1;
739
+ #else
740
+ uint32_t local = _Py_atomic_load_uint32_relaxed(&op->ob_ref_local);
741
+ Py_ssize_t shared = _Py_atomic_load_ssize_acquire(&op->ob_ref_shared);
742
+ if (_Py_IsOwnedByCurrentThread(op) && local == 1 && shared == 0) {
743
+ // Fast-path: object has a single refcount and is owned by this thread
744
+ _Py_atomic_store_uint32_relaxed(&op->ob_ref_local, 0);
745
+ # ifdef Py_TRACE_REFS
746
+ _Py_ForgetReference(op);
747
+ # endif
748
+ return 0;
749
+ }
750
+ // Slow-path: object has a shared refcount or is not owned by this thread
751
+ return _PyObject_ResurrectEndSlow(op);
752
+ #endif
753
+ }
754
+
755
+ /* Tries to incref op and returns 1 if successful or 0 otherwise. */
756
+ static inline int
757
+ _Py_TryIncref(PyObject *op)
758
+ {
759
+ #ifdef Py_GIL_DISABLED
760
+ return _Py_TryIncrefFast(op) || _Py_TryIncRefShared(op);
761
+ #else
762
+ if (Py_REFCNT(op) > 0) {
763
+ Py_INCREF(op);
764
+ return 1;
765
+ }
766
+ return 0;
767
+ #endif
768
+ }
769
+
770
+ #ifdef Py_REF_DEBUG
771
+ extern void _PyInterpreterState_FinalizeRefTotal(PyInterpreterState *);
772
+ extern void _Py_FinalizeRefTotal(_PyRuntimeState *);
773
+ extern void _PyDebug_PrintTotalRefs(void);
774
+ #endif
775
+
776
+ #ifdef Py_TRACE_REFS
777
+ extern void _Py_AddToAllObjects(PyObject *op);
778
+ extern void _Py_PrintReferences(PyInterpreterState *, FILE *);
779
+ extern void _Py_PrintReferenceAddresses(PyInterpreterState *, FILE *);
780
+ #endif
781
+
782
+
783
+ /* Return the *address* of the object's weaklist. The address may be
784
+ * dereferenced to get the current head of the weaklist. This is useful
785
+ * for iterating over the linked list of weakrefs, especially when the
786
+ * list is being modified externally (e.g. refs getting removed).
787
+ *
788
+ * The returned pointer should not be used to change the head of the list
789
+ * nor should it be used to add, remove, or swap any refs in the list.
790
+ * That is the sole responsibility of the code in weakrefobject.c.
791
+ */
792
+ static inline PyObject **
793
+ _PyObject_GET_WEAKREFS_LISTPTR(PyObject *op)
794
+ {
795
+ if (PyType_Check(op) &&
796
+ ((PyTypeObject *)op)->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
797
+ PyInterpreterState *interp = _PyInterpreterState_GET();
798
+ managed_static_type_state *state = _PyStaticType_GetState(
799
+ interp, (PyTypeObject *)op);
800
+ return _PyStaticType_GET_WEAKREFS_LISTPTR(state);
801
+ }
802
+ // Essentially _PyObject_GET_WEAKREFS_LISTPTR_FROM_OFFSET():
803
+ Py_ssize_t offset = Py_TYPE(op)->tp_weaklistoffset;
804
+ return (PyObject **)((char *)op + offset);
805
+ }
806
+
807
+ /* This is a special case of _PyObject_GET_WEAKREFS_LISTPTR().
808
+ * Only the most fundamental lookup path is used.
809
+ * Consequently, static types should not be used.
810
+ *
811
+ * For static builtin types the returned pointer will always point
812
+ * to a NULL tp_weaklist. This is fine for any deallocation cases,
813
+ * since static types are never deallocated and static builtin types
814
+ * are only finalized at the end of runtime finalization.
815
+ *
816
+ * If the weaklist for static types is actually needed then use
817
+ * _PyObject_GET_WEAKREFS_LISTPTR().
818
+ */
819
+ static inline PyWeakReference **
820
+ _PyObject_GET_WEAKREFS_LISTPTR_FROM_OFFSET(PyObject *op)
821
+ {
822
+ assert(!PyType_Check(op) ||
823
+ ((PyTypeObject *)op)->tp_flags & Py_TPFLAGS_HEAPTYPE);
824
+ Py_ssize_t offset = Py_TYPE(op)->tp_weaklistoffset;
825
+ return (PyWeakReference **)((char *)op + offset);
826
+ }
827
+
828
+ // Fast inlined version of PyType_IS_GC()
829
+ #define _PyType_IS_GC(t) _PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
830
+
831
+ // Fast inlined version of PyObject_IS_GC()
832
+ static inline int
833
+ _PyObject_IS_GC(PyObject *obj)
834
+ {
835
+ PyTypeObject *type = Py_TYPE(obj);
836
+ return (_PyType_IS_GC(type)
837
+ && (type->tp_is_gc == NULL || type->tp_is_gc(obj)));
838
+ }
839
+
840
+ // Fast inlined version of PyObject_Hash()
841
+ static inline Py_hash_t
842
+ _PyObject_HashFast(PyObject *op)
843
+ {
844
+ if (PyUnicode_CheckExact(op)) {
845
+ Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED(
846
+ _PyASCIIObject_CAST(op)->hash);
847
+ if (hash != -1) {
848
+ return hash;
849
+ }
850
+ }
851
+ return PyObject_Hash(op);
852
+ }
853
+
854
+ static inline size_t
855
+ _PyType_PreHeaderSize(PyTypeObject *tp)
856
+ {
857
+ return (
858
+ #ifndef Py_GIL_DISABLED
859
+ (size_t)_PyType_IS_GC(tp) * sizeof(PyGC_Head) +
860
+ #endif
861
+ (size_t)_PyType_HasFeature(tp, Py_TPFLAGS_PREHEADER) * 2 * sizeof(PyObject *)
862
+ );
863
+ }
864
+
865
+ void _PyObject_GC_Link(PyObject *op);
866
+
867
+ // Usage: assert(_Py_CheckSlotResult(obj, "__getitem__", result != NULL));
868
+ extern int _Py_CheckSlotResult(
869
+ PyObject *obj,
870
+ const char *slot_name,
871
+ int success);
872
+
873
+ // Test if a type supports weak references
874
+ static inline int _PyType_SUPPORTS_WEAKREFS(PyTypeObject *type) {
875
+ return (type->tp_weaklistoffset != 0);
876
+ }
877
+
878
+ extern PyObject* _PyType_AllocNoTrack(PyTypeObject *type, Py_ssize_t nitems);
879
+ PyAPI_FUNC(PyObject *) _PyType_NewManagedObject(PyTypeObject *type);
880
+
881
+ extern PyTypeObject* _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
882
+ extern PyObject* _PyType_GetDocFromInternalDoc(const char *, const char *);
883
+ extern PyObject* _PyType_GetTextSignatureFromInternalDoc(const char *, const char *, int);
884
+ extern int _PyObject_SetAttributeErrorContext(PyObject *v, PyObject* name);
885
+
886
+ void _PyObject_InitInlineValues(PyObject *obj, PyTypeObject *tp);
887
+ extern int _PyObject_StoreInstanceAttribute(PyObject *obj,
888
+ PyObject *name, PyObject *value);
889
+ extern bool _PyObject_TryGetInstanceAttribute(PyObject *obj, PyObject *name,
890
+ PyObject **attr);
891
+ extern PyObject *_PyType_LookupRefAndVersion(PyTypeObject *, PyObject *,
892
+ unsigned int *);
893
+
894
+ // Internal API to look for a name through the MRO.
895
+ // This stores a stack reference in out and returns the value of
896
+ // type->tp_version or zero if name is missing. It doesn't set an exception!
897
+ extern unsigned int
898
+ _PyType_LookupStackRefAndVersion(PyTypeObject *type, PyObject *name, _PyStackRef *out);
899
+
900
+ // Cache the provided init method in the specialization cache of type if the
901
+ // provided type version matches the current version of the type.
902
+ //
903
+ // The cached value is borrowed and is only valid if guarded by a type
904
+ // version check. In free-threaded builds the init method must also use
905
+ // deferred reference counting.
906
+ //
907
+ // Returns 1 if the value was cached or 0 otherwise.
908
+ extern int _PyType_CacheInitForSpecialization(PyHeapTypeObject *type,
909
+ PyObject *init,
910
+ unsigned int tp_version);
911
+
912
+ #ifdef Py_GIL_DISABLED
913
+ # define MANAGED_DICT_OFFSET (((Py_ssize_t)sizeof(PyObject *))*-1)
914
+ # define MANAGED_WEAKREF_OFFSET (((Py_ssize_t)sizeof(PyObject *))*-2)
915
+ #else
916
+ # define MANAGED_DICT_OFFSET (((Py_ssize_t)sizeof(PyObject *))*-3)
917
+ # define MANAGED_WEAKREF_OFFSET (((Py_ssize_t)sizeof(PyObject *))*-4)
918
+ #endif
919
+
920
+ typedef union {
921
+ PyDictObject *dict;
922
+ } PyManagedDictPointer;
923
+
924
+ static inline PyManagedDictPointer *
925
+ _PyObject_ManagedDictPointer(PyObject *obj)
926
+ {
927
+ assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
928
+ return (PyManagedDictPointer *)((char *)obj + MANAGED_DICT_OFFSET);
929
+ }
930
+
931
+ static inline PyDictObject *
932
+ _PyObject_GetManagedDict(PyObject *obj)
933
+ {
934
+ PyManagedDictPointer *dorv = _PyObject_ManagedDictPointer(obj);
935
+ return (PyDictObject *)FT_ATOMIC_LOAD_PTR_ACQUIRE(dorv->dict);
936
+ }
937
+
938
+ static inline PyDictValues *
939
+ _PyObject_InlineValues(PyObject *obj)
940
+ {
941
+ PyTypeObject *tp = Py_TYPE(obj);
942
+ assert(tp->tp_basicsize > 0 && (size_t)tp->tp_basicsize % sizeof(PyObject *) == 0);
943
+ assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_INLINE_VALUES);
944
+ assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
945
+ return (PyDictValues *)((char *)obj + tp->tp_basicsize);
946
+ }
947
+
948
+ extern PyObject ** _PyObject_ComputedDictPointer(PyObject *);
949
+ extern int _PyObject_IsInstanceDictEmpty(PyObject *);
950
+
951
+ // Export for 'math' shared extension
952
+ PyAPI_FUNC(PyObject*) _PyObject_LookupSpecial(PyObject *, PyObject *);
953
+ PyAPI_FUNC(int) _PyObject_LookupSpecialMethod(PyObject *attr, _PyStackRef *method_and_self);
954
+
955
+ // Calls the method named `attr` on `self`, but does not set an exception if
956
+ // the attribute does not exist.
957
+ PyAPI_FUNC(PyObject *)
958
+ _PyObject_MaybeCallSpecialNoArgs(PyObject *self, PyObject *attr);
959
+
960
+ PyAPI_FUNC(PyObject *)
961
+ _PyObject_MaybeCallSpecialOneArg(PyObject *self, PyObject *attr, PyObject *arg);
962
+
963
+ extern int _PyObject_IsAbstract(PyObject *);
964
+
965
+ PyAPI_FUNC(int) _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);
966
+ extern PyObject* _PyObject_NextNotImplemented(PyObject *);
967
+
968
+ // Pickle support.
969
+ // Export for '_datetime' shared extension
970
+ PyAPI_FUNC(PyObject*) _PyObject_GetState(PyObject *);
971
+
972
+ /* C function call trampolines to mitigate bad function pointer casts.
973
+ *
974
+ * Typical native ABIs ignore additional arguments or fill in missing
975
+ * values with 0/NULL in function pointer cast. Compilers do not show
976
+ * warnings when a function pointer is explicitly casted to an
977
+ * incompatible type.
978
+ *
979
+ * Bad fpcasts are an issue in WebAssembly. WASM's indirect_call has strict
980
+ * function signature checks. Argument count, types, and return type must
981
+ * match.
982
+ *
983
+ * Third party code unintentionally rely on problematic fpcasts. The call
984
+ * trampoline mitigates common occurrences of bad fpcasts on Emscripten.
985
+ */
986
+ #if !(defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE))
987
+ #define _PyCFunction_TrampolineCall(meth, self, args) \
988
+ (meth)((self), (args))
989
+ #define _PyCFunctionWithKeywords_TrampolineCall(meth, self, args, kw) \
990
+ (meth)((self), (args), (kw))
991
+ #endif // __EMSCRIPTEN__ && PY_CALL_TRAMPOLINE
992
+
993
+ // Export these 2 symbols for '_pickle' shared extension
994
+ PyAPI_DATA(PyTypeObject) _PyNone_Type;
995
+ PyAPI_DATA(PyTypeObject) _PyNotImplemented_Type;
996
+
997
+ // Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.
998
+ // Export for the stable ABI.
999
+ PyAPI_DATA(int) _Py_SwappedOp[];
1000
+
1001
+ extern void _Py_GetConstant_Init(void);
1002
+
1003
+ enum _PyAnnotateFormat {
1004
+ _Py_ANNOTATE_FORMAT_VALUE = 1,
1005
+ _Py_ANNOTATE_FORMAT_VALUE_WITH_FAKE_GLOBALS = 2,
1006
+ _Py_ANNOTATE_FORMAT_FORWARDREF = 3,
1007
+ _Py_ANNOTATE_FORMAT_STRING = 4,
1008
+ };
1009
+
1010
+ int _PyObject_SetDict(PyObject *obj, PyObject *value);
1011
+
1012
+ #ifndef Py_GIL_DISABLED
1013
+ static inline Py_ALWAYS_INLINE void _Py_INCREF_MORTAL(PyObject *op)
1014
+ {
1015
+ assert(!_Py_IsStaticImmortal(op));
1016
+ op->ob_refcnt++;
1017
+ _Py_INCREF_STAT_INC();
1018
+ #if defined(Py_REF_DEBUG) && !defined(Py_LIMITED_API)
1019
+ if (!_Py_IsImmortal(op)) {
1020
+ _Py_INCREF_IncRefTotal();
1021
+ }
1022
+ #endif
1023
+ }
1024
+ #endif
1025
+
1026
+ #ifdef __cplusplus
1027
+ }
1028
+ #endif
1029
+ #endif /* !Py_INTERNAL_OBJECT_H */