Nuitka-winsvc 2.4.11__cp311-cp311-win_amd64.whl → 2.5.6__cp311-cp311-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.

Potentially problematic release.


This version of Nuitka-winsvc might be problematic. Click here for more details.

Files changed (304) hide show
  1. {Nuitka_winsvc-2.4.11.dist-info → Nuitka_winsvc-2.5.6.dist-info}/METADATA +56 -109
  2. {Nuitka_winsvc-2.4.11.dist-info → Nuitka_winsvc-2.5.6.dist-info}/RECORD +304 -280
  3. {Nuitka_winsvc-2.4.11.dist-info → Nuitka_winsvc-2.5.6.dist-info}/WHEEL +1 -1
  4. nuitka/Builtins.py +31 -0
  5. nuitka/HardImportRegistry.py +8 -0
  6. nuitka/MainControl.py +9 -4
  7. nuitka/OptionParsing.py +108 -54
  8. nuitka/Options.py +69 -13
  9. nuitka/OutputDirectories.py +7 -2
  10. nuitka/PostProcessing.py +69 -38
  11. nuitka/Progress.py +16 -1
  12. nuitka/PythonVersions.py +2 -1
  13. nuitka/Serialization.py +4 -2
  14. nuitka/Tracing.py +69 -1
  15. nuitka/Version.py +2 -2
  16. nuitka/build/Backend.scons +45 -5
  17. nuitka/build/CCompilerVersion.scons +6 -0
  18. nuitka/build/Onefile.scons +6 -0
  19. nuitka/build/SconsCaching.py +4 -0
  20. nuitka/build/SconsCompilerSettings.py +14 -3
  21. nuitka/build/SconsInterface.py +3 -0
  22. nuitka/build/SconsUtils.py +5 -0
  23. nuitka/build/include/nuitka/allocator.h +124 -1
  24. nuitka/build/include/nuitka/calling.h +6 -6
  25. nuitka/build/include/nuitka/compiled_asyncgen.h +10 -7
  26. nuitka/build/include/nuitka/compiled_frame.h +2 -1
  27. nuitka/build/include/nuitka/constants.h +8 -0
  28. nuitka/build/include/nuitka/debug_settings.h +60 -0
  29. nuitka/build/include/nuitka/exceptions.h +264 -121
  30. nuitka/build/include/nuitka/helper/attributes.h +0 -4
  31. nuitka/build/include/nuitka/helper/calling_generated.h +52 -52
  32. nuitka/build/include/nuitka/helper/comparisons_dual_eq.h +47 -0
  33. nuitka/build/include/nuitka/helper/comparisons_dual_ge.h +39 -0
  34. nuitka/build/include/nuitka/helper/comparisons_dual_gt.h +39 -0
  35. nuitka/build/include/nuitka/helper/comparisons_dual_le.h +47 -0
  36. nuitka/build/include/nuitka/helper/comparisons_dual_lt.h +47 -0
  37. nuitka/build/include/nuitka/helper/comparisons_dual_ne.h +39 -0
  38. nuitka/build/include/nuitka/helper/dictionaries.h +75 -31
  39. nuitka/build/include/nuitka/helper/ints.h +86 -37
  40. nuitka/build/include/nuitka/helper/iterators.h +82 -34
  41. nuitka/build/include/nuitka/helper/operations.h +3 -0
  42. nuitka/build/include/nuitka/helper/operations_binary_add.h +6 -0
  43. nuitka/build/include/nuitka/helper/operations_binary_dual_add.h +34 -0
  44. nuitka/build/include/nuitka/helper/operations_binary_sub.h +6 -0
  45. nuitka/build/include/nuitka/helper/operations_inplace_add.h +3 -0
  46. nuitka/build/include/nuitka/helper/operations_inplace_sub.h +3 -0
  47. nuitka/build/include/nuitka/helper/raising.h +47 -28
  48. nuitka/build/include/nuitka/helper/richcomparisons.h +7 -0
  49. nuitka/build/include/nuitka/helper/tuples.h +12 -0
  50. nuitka/build/include/nuitka/helpers.h +12 -2
  51. nuitka/build/include/nuitka/prelude.h +36 -25
  52. nuitka/build/include/nuitka/printing.h +9 -7
  53. nuitka/build/include/nuitka/threading.h +15 -1
  54. nuitka/build/include/nuitka/type_aliases.h +3 -0
  55. nuitka/build/inline_copy/stubgen/astunparse.py +938 -0
  56. nuitka/build/inline_copy/stubgen/six.py +998 -0
  57. nuitka/build/inline_copy/stubgen/stubgen.py +307 -0
  58. nuitka/build/static_src/CompiledAsyncgenType.c +45 -39
  59. nuitka/build/static_src/CompiledCellType.c +6 -4
  60. nuitka/build/static_src/CompiledCodeHelpers.c +106 -40
  61. nuitka/build/static_src/CompiledCoroutineType.c +41 -31
  62. nuitka/build/static_src/CompiledFrameType.c +110 -79
  63. nuitka/build/static_src/CompiledFunctionType.c +173 -151
  64. nuitka/build/static_src/CompiledGeneratorType.c +51 -49
  65. nuitka/build/static_src/CompiledGeneratorTypeUncompiledIntegration.c +433 -46
  66. nuitka/build/static_src/CompiledMethodType.c +6 -12
  67. nuitka/build/static_src/HelpersAllocator.c +266 -28
  68. nuitka/build/static_src/HelpersAttributes.c +0 -21
  69. nuitka/build/static_src/HelpersBuiltin.c +23 -14
  70. nuitka/build/static_src/HelpersCalling.c +7 -7
  71. nuitka/build/static_src/HelpersCallingGenerated.c +70 -70
  72. nuitka/build/static_src/HelpersComparisonDualEq.c +183 -0
  73. nuitka/build/static_src/HelpersComparisonDualGe.c +121 -0
  74. nuitka/build/static_src/HelpersComparisonDualGt.c +121 -0
  75. nuitka/build/static_src/HelpersComparisonDualLe.c +183 -0
  76. nuitka/build/static_src/HelpersComparisonDualLt.c +183 -0
  77. nuitka/build/static_src/HelpersComparisonDualNe.c +121 -0
  78. nuitka/build/static_src/HelpersComparisonEq.c +18 -4
  79. nuitka/build/static_src/HelpersComparisonGe.c +18 -4
  80. nuitka/build/static_src/HelpersComparisonGt.c +18 -4
  81. nuitka/build/static_src/HelpersComparisonLe.c +18 -4
  82. nuitka/build/static_src/HelpersComparisonLt.c +18 -4
  83. nuitka/build/static_src/HelpersComparisonNe.c +18 -4
  84. nuitka/build/static_src/HelpersConsole.c +34 -8
  85. nuitka/build/static_src/HelpersConstantsBlob.c +4 -2
  86. nuitka/build/static_src/HelpersDeepcopy.c +1 -0
  87. nuitka/build/static_src/HelpersDictionaries.c +195 -36
  88. nuitka/build/static_src/HelpersDictionariesGenerated.c +12 -107
  89. nuitka/build/static_src/HelpersExceptions.c +24 -50
  90. nuitka/build/static_src/HelpersFiles.c +79 -5
  91. nuitka/build/static_src/HelpersImport.c +13 -9
  92. nuitka/build/static_src/HelpersImportHard.c +23 -46
  93. nuitka/build/static_src/HelpersLists.c +98 -9
  94. nuitka/build/static_src/HelpersOperationBinaryAdd.c +224 -6
  95. nuitka/build/static_src/HelpersOperationBinaryAddUtils.c +3 -0
  96. nuitka/build/static_src/HelpersOperationBinaryBitand.c +5 -5
  97. nuitka/build/static_src/HelpersOperationBinaryBitor.c +5 -5
  98. nuitka/build/static_src/HelpersOperationBinaryBitxor.c +5 -5
  99. nuitka/build/static_src/HelpersOperationBinaryDivmod.c +8 -2
  100. nuitka/build/static_src/HelpersOperationBinaryDualAdd.c +172 -0
  101. nuitka/build/static_src/HelpersOperationBinaryFloordiv.c +14 -8
  102. nuitka/build/static_src/HelpersOperationBinaryLshift.c +36 -36
  103. nuitka/build/static_src/HelpersOperationBinaryMatmult.c +1 -0
  104. nuitka/build/static_src/HelpersOperationBinaryMod.c +22 -10
  105. nuitka/build/static_src/HelpersOperationBinaryMult.c +17 -7
  106. nuitka/build/static_src/HelpersOperationBinaryOlddiv.c +14 -8
  107. nuitka/build/static_src/HelpersOperationBinaryPow.c +24 -24
  108. nuitka/build/static_src/HelpersOperationBinaryRshift.c +4 -4
  109. nuitka/build/static_src/HelpersOperationBinarySub.c +229 -8
  110. nuitka/build/static_src/HelpersOperationBinaryTruediv.c +8 -2
  111. nuitka/build/static_src/HelpersOperationInplaceAdd.c +162 -10
  112. nuitka/build/static_src/HelpersOperationInplaceBitand.c +5 -5
  113. nuitka/build/static_src/HelpersOperationInplaceBitor.c +5 -5
  114. nuitka/build/static_src/HelpersOperationInplaceBitxor.c +5 -5
  115. nuitka/build/static_src/HelpersOperationInplaceFloordiv.c +11 -6
  116. nuitka/build/static_src/HelpersOperationInplaceLshift.c +20 -20
  117. nuitka/build/static_src/HelpersOperationInplaceMatmult.c +1 -0
  118. nuitka/build/static_src/HelpersOperationInplaceMod.c +11 -6
  119. nuitka/build/static_src/HelpersOperationInplaceMult.c +11 -6
  120. nuitka/build/static_src/HelpersOperationInplaceOlddiv.c +11 -6
  121. nuitka/build/static_src/HelpersOperationInplacePow.c +20 -20
  122. nuitka/build/static_src/HelpersOperationInplaceRshift.c +4 -4
  123. nuitka/build/static_src/HelpersOperationInplaceSub.c +163 -10
  124. nuitka/build/static_src/HelpersOperationInplaceTruediv.c +6 -1
  125. nuitka/build/static_src/HelpersProfiling.c +1 -1
  126. nuitka/build/static_src/HelpersRaising.c +255 -310
  127. nuitka/build/static_src/HelpersStrings.c +1 -1
  128. nuitka/build/static_src/HelpersTuples.c +2 -2
  129. nuitka/build/static_src/HelpersTypes.c +98 -2
  130. nuitka/build/static_src/MainProgram.c +132 -28
  131. nuitka/build/static_src/MetaPathBasedLoader.c +18 -19
  132. nuitka/build/static_src/MetaPathBasedLoaderResourceReaderFiles.c +134 -11
  133. nuitka/build/static_src/OnefileBootstrap.c +6 -1
  134. nuitka/code_generation/AsyncgenCodes.py +2 -6
  135. nuitka/code_generation/BinaryOperationHelperDefinitions.py +269 -167
  136. nuitka/code_generation/BuiltinCodes.py +9 -1
  137. nuitka/code_generation/CallCodes.py +16 -16
  138. nuitka/code_generation/CodeGeneration.py +14 -2
  139. nuitka/code_generation/CodeHelperSelection.py +1 -1
  140. nuitka/code_generation/CodeHelpers.py +4 -1
  141. nuitka/code_generation/CodeObjectCodes.py +2 -2
  142. nuitka/code_generation/ComparisonCodes.py +13 -2
  143. nuitka/code_generation/ComparisonHelperDefinitions.py +23 -8
  144. nuitka/code_generation/Contexts.py +28 -16
  145. nuitka/code_generation/CoroutineCodes.py +2 -6
  146. nuitka/code_generation/DictCodes.py +3 -3
  147. nuitka/code_generation/ErrorCodes.py +34 -50
  148. nuitka/code_generation/ExceptionCodes.py +165 -96
  149. nuitka/code_generation/ExpressionCTypeSelectionHelpers.py +25 -10
  150. nuitka/code_generation/FrameCodes.py +4 -11
  151. nuitka/code_generation/FunctionCodes.py +2 -6
  152. nuitka/code_generation/GeneratorCodes.py +2 -6
  153. nuitka/code_generation/GlobalConstants.py +8 -2
  154. nuitka/code_generation/GlobalsLocalsCodes.py +2 -2
  155. nuitka/code_generation/IteratorCodes.py +67 -54
  156. nuitka/code_generation/LineNumberCodes.py +1 -3
  157. nuitka/code_generation/ModuleCodes.py +28 -4
  158. nuitka/code_generation/OperationCodes.py +51 -20
  159. nuitka/code_generation/PackageResourceCodes.py +37 -0
  160. nuitka/code_generation/RaisingCodes.py +164 -90
  161. nuitka/code_generation/Reports.py +13 -5
  162. nuitka/code_generation/ReturnCodes.py +2 -16
  163. nuitka/code_generation/TryCodes.py +12 -24
  164. nuitka/code_generation/TypeAliasCodes.py +48 -0
  165. nuitka/code_generation/VariableCodes.py +99 -40
  166. nuitka/code_generation/VariableDeclarations.py +8 -8
  167. nuitka/code_generation/YieldCodes.py +1 -1
  168. nuitka/code_generation/c_types/CTypeBases.py +10 -2
  169. nuitka/code_generation/c_types/CTypeModuleDictVariables.py +3 -0
  170. nuitka/code_generation/c_types/CTypeNuitkaBooleans.py +3 -4
  171. nuitka/code_generation/c_types/CTypeNuitkaInts.py +70 -25
  172. nuitka/code_generation/c_types/CTypeNuitkaVoids.py +1 -1
  173. nuitka/code_generation/c_types/CTypePyObjectPointers.py +16 -6
  174. nuitka/code_generation/templates/CodeTemplatesAsyncgens.py +2 -2
  175. nuitka/code_generation/templates/CodeTemplatesConstants.py +11 -3
  176. nuitka/code_generation/templates/CodeTemplatesCoroutines.py +2 -2
  177. nuitka/code_generation/templates/CodeTemplatesExceptions.py +15 -16
  178. nuitka/code_generation/templates/CodeTemplatesFrames.py +18 -10
  179. nuitka/code_generation/templates/CodeTemplatesFunction.py +2 -2
  180. nuitka/code_generation/templates/CodeTemplatesGeneratorFunction.py +2 -2
  181. nuitka/code_generation/templates/CodeTemplatesIterators.py +1 -35
  182. nuitka/code_generation/templates/CodeTemplatesModules.py +34 -4
  183. nuitka/code_generation/templates/CodeTemplatesVariables.py +76 -0
  184. nuitka/code_generation/templates_c/CodeTemplateCallsMixed.c.j2 +3 -3
  185. nuitka/code_generation/templates_c/CodeTemplateCallsPositional.c.j2 +3 -3
  186. nuitka/code_generation/templates_c/HelperDictionaryCopy.c.j2 +4 -106
  187. nuitka/code_generation/templates_c/HelperImportHard.c.j2 +1 -2
  188. nuitka/code_generation/templates_c/HelperLongTools.c.j2 +1 -1
  189. nuitka/code_generation/templates_c/HelperOperationBinaryDual.c.j2 +115 -0
  190. nuitka/code_generation/templates_c/HelperOperationComparisonBytes.c.j2 +9 -9
  191. nuitka/code_generation/templates_c/HelperOperationComparisonDual.c.j2 +86 -0
  192. nuitka/code_generation/templates_c/HelperOperationComparisonFloat.c.j2 +1 -1
  193. nuitka/code_generation/templates_c/HelperOperationComparisonInt.c.j2 +1 -1
  194. nuitka/code_generation/templates_c/HelperOperationComparisonList.c.j2 +9 -9
  195. nuitka/code_generation/templates_c/HelperOperationComparisonLong.c.j2 +7 -7
  196. nuitka/code_generation/templates_c/HelperOperationComparisonStr.c.j2 +9 -9
  197. nuitka/code_generation/templates_c/HelperOperationComparisonTuple.c.j2 +7 -7
  198. nuitka/code_generation/templates_c/HelperOperationComparisonUnicode.c.j2 +4 -4
  199. nuitka/code_generation/templates_c/HelperSlotsBinary.c.j2 +1 -1
  200. nuitka/code_generation/templates_c/HelperSlotsInt.c.j2 +31 -31
  201. nuitka/code_generation/templates_c/HelperSlotsLong.c.j2 +1 -1
  202. nuitka/containers/Namedtuples.py +6 -0
  203. nuitka/containers/OrderedSets.py +105 -5
  204. nuitka/distutils/Build.py +14 -0
  205. nuitka/distutils/DistutilCommands.py +50 -10
  206. nuitka/finalizations/Finalization.py +3 -3
  207. nuitka/finalizations/FinalizeMarkups.py +10 -14
  208. nuitka/freezer/DependsExe.py +5 -2
  209. nuitka/freezer/DllDependenciesMacOS.py +18 -1
  210. nuitka/freezer/DllDependenciesWin32.py +26 -12
  211. nuitka/freezer/ImportDetection.py +6 -0
  212. nuitka/freezer/IncludedDataFiles.py +37 -6
  213. nuitka/freezer/Onefile.py +1 -0
  214. nuitka/freezer/Standalone.py +72 -18
  215. nuitka/importing/Importing.py +33 -6
  216. nuitka/importing/Recursion.py +5 -2
  217. nuitka/importing/StandardLibrary.py +57 -59
  218. nuitka/nodes/AsyncgenNodes.py +3 -6
  219. nuitka/nodes/BuiltinIteratorNodes.py +2 -2
  220. nuitka/nodes/BuiltinRefNodes.py +14 -30
  221. nuitka/nodes/ChildrenHavingMixins.py +439 -46
  222. nuitka/nodes/ConditionalNodes.py +3 -2
  223. nuitka/nodes/CoroutineNodes.py +3 -6
  224. nuitka/nodes/DictionaryNodes.py +1 -1
  225. nuitka/nodes/ExceptionNodes.py +102 -26
  226. nuitka/nodes/ExpressionBasesGenerated.py +288 -4
  227. nuitka/nodes/FrameNodes.py +22 -11
  228. nuitka/nodes/FunctionNodes.py +3 -3
  229. nuitka/nodes/GeneratorNodes.py +3 -6
  230. nuitka/nodes/HardImportNodesGenerated.py +182 -0
  231. nuitka/nodes/ImportNodes.py +2 -2
  232. nuitka/nodes/NodeBases.py +28 -1
  233. nuitka/nodes/NodeMakingHelpers.py +71 -50
  234. nuitka/nodes/OperatorNodesUnary.py +128 -3
  235. nuitka/nodes/OsSysNodes.py +37 -6
  236. nuitka/nodes/OutlineNodes.py +2 -2
  237. nuitka/nodes/StatementBasesGenerated.py +0 -2
  238. nuitka/nodes/StatementNodes.py +8 -7
  239. nuitka/nodes/SubscriptNodes.py +1 -1
  240. nuitka/nodes/TypeNodes.py +28 -1
  241. nuitka/nodes/VariableAssignNodes.py +2 -1
  242. nuitka/nodes/shapes/BuiltinTypeShapes.py +24 -7
  243. nuitka/nodes/shapes/IteratorShapes.py +71 -0
  244. nuitka/nodes/shapes/ShapeMixins.py +18 -0
  245. nuitka/nodes/shapes/StandardShapes.py +47 -44
  246. nuitka/optimizations/BytecodeDemotion.py +2 -1
  247. nuitka/plugins/PluginBase.py +64 -22
  248. nuitka/plugins/Plugins.py +16 -3
  249. nuitka/plugins/standard/AntiBloatPlugin.py +23 -12
  250. nuitka/plugins/standard/DllFilesPlugin.py +78 -2
  251. nuitka/plugins/standard/ImplicitImports.py +5 -15
  252. nuitka/plugins/standard/KivyPlugin.py +3 -12
  253. nuitka/plugins/standard/MatplotlibPlugin.py +12 -1
  254. nuitka/plugins/standard/MultiprocessingPlugin.py +11 -20
  255. nuitka/plugins/standard/OptionsNannyPlugin.py +5 -4
  256. nuitka/plugins/standard/PlaywrightPlugin.py +184 -0
  257. nuitka/plugins/standard/PySidePyQtPlugin.py +8 -0
  258. nuitka/plugins/standard/TkinterPlugin.py +23 -3
  259. nuitka/plugins/standard/TransformersPlugin.py +70 -275
  260. nuitka/plugins/standard/standard.nuitka-package.config.yml +413 -30
  261. nuitka/plugins/standard/stdlib3.nuitka-package.config.yml +35 -2
  262. nuitka/reports/CompilationReportReader.py +12 -0
  263. nuitka/reports/Reports.py +11 -0
  264. nuitka/specs/BuiltinParameterSpecs.py +5 -1
  265. nuitka/specs/HardImportSpecs.py +7 -0
  266. nuitka/specs/ParameterSpecs.py +4 -4
  267. nuitka/tools/environments/Virtualenv.py +13 -5
  268. nuitka/tools/general/dll_report/__main__.py +10 -1
  269. nuitka/tools/onefile_compressor/OnefileCompressor.py +1 -1
  270. nuitka/tools/podman/__main__.py +4 -2
  271. nuitka/tools/specialize/CTypeDescriptions.py +158 -9
  272. nuitka/tools/specialize/SpecializeC.py +218 -56
  273. nuitka/tools/testing/Common.py +69 -62
  274. nuitka/tools/testing/compare_with_cpython/__main__.py +3 -1
  275. nuitka/tools/testing/measure_construct_performance/__main__.py +1 -8
  276. nuitka/tools/testing/run_nuitka_tests/__main__.py +77 -11
  277. nuitka/tools/watch/AutoStage.py +1 -0
  278. nuitka/tree/Building.py +10 -37
  279. nuitka/tree/ComplexCallHelperFunctions.py +4 -0
  280. nuitka/tree/ReformulationAssertStatements.py +31 -14
  281. nuitka/tree/ReformulationAssignmentStatements.py +5 -1
  282. nuitka/tree/ReformulationClasses3.py +94 -19
  283. nuitka/tree/ReformulationDictionaryCreation.py +1 -0
  284. nuitka/tree/ReformulationFunctionStatements.py +1 -1
  285. nuitka/tree/ReformulationMatchStatements.py +3 -1
  286. nuitka/tree/ReformulationYieldExpressions.py +23 -5
  287. nuitka/utils/CommandLineOptions.py +27 -3
  288. nuitka/utils/Download.py +2 -2
  289. nuitka/utils/Execution.py +36 -31
  290. nuitka/utils/FileOperations.py +18 -39
  291. nuitka/utils/Hashing.py +5 -1
  292. nuitka/utils/Importing.py +2 -14
  293. nuitka/utils/InlineCopies.py +52 -0
  294. nuitka/utils/InstalledPythons.py +9 -4
  295. nuitka/utils/Json.py +2 -2
  296. nuitka/utils/PackageResources.py +44 -0
  297. nuitka/utils/SharedLibraries.py +24 -0
  298. nuitka/utils/Signing.py +9 -1
  299. nuitka/utils/Utils.py +1 -0
  300. {Nuitka_winsvc-2.4.11.data → Nuitka_winsvc-2.5.6.data}/scripts/nuitka-run.cmd +0 -0
  301. {Nuitka_winsvc-2.4.11.data → Nuitka_winsvc-2.5.6.data}/scripts/nuitka.cmd +0 -0
  302. {Nuitka_winsvc-2.4.11.dist-info → Nuitka_winsvc-2.5.6.dist-info}/LICENSE.txt +0 -0
  303. {Nuitka_winsvc-2.4.11.dist-info → Nuitka_winsvc-2.5.6.dist-info}/entry_points.txt +0 -0
  304. {Nuitka_winsvc-2.4.11.dist-info → Nuitka_winsvc-2.5.6.dist-info}/top_level.txt +0 -0
@@ -40,35 +40,6 @@ NUITKA_MAY_BE_UNUSED static inline void ASSERT_NORMALIZED_EXCEPTION_VALUE(PyObje
40
40
  assert(PyExceptionInstance_Check(exception_value));
41
41
  }
42
42
 
43
- extern void Nuitka_Err_NormalizeException(PyThreadState *tstate, PyObject **exc, PyObject **val,
44
- PyTracebackObject **tb);
45
-
46
- // Normalize an exception, may release old values and replace them, expects
47
- // references passed and returns them.
48
- NUITKA_MAY_BE_UNUSED static inline void NORMALIZE_EXCEPTION(PyThreadState *tstate, PyObject **exception_type,
49
- PyObject **exception_value,
50
- PyTracebackObject **exception_tb) {
51
- #if _DEBUG_EXCEPTIONS
52
- PRINT_STRING("NORMALIZE_EXCEPTION: Enter\n");
53
- PRINT_EXCEPTION(*exception_type, *exception_value, *exception_tb);
54
- #endif
55
- CHECK_OBJECT_X(*exception_type);
56
- CHECK_OBJECT_X(*exception_value);
57
- if (exception_tb) {
58
- CHECK_OBJECT_X(*exception_tb);
59
- }
60
-
61
- // TODO: Often we already know this to be true.
62
- if (*exception_type != Py_None && *exception_type != NULL) {
63
- Nuitka_Err_NormalizeException(tstate, exception_type, exception_value, exception_tb);
64
- }
65
-
66
- #if _DEBUG_EXCEPTIONS
67
- PRINT_STRING("NORMALIZE_EXCEPTION: Leave\n");
68
- PRINT_EXCEPTION(*exception_type, *exception_value, exception_tb ? *exception_tb : NULL);
69
- #endif
70
- }
71
-
72
43
  // Clear error, which likely set, similar to "_PyErr_Clear(tstate)" and "PyErr_Clear"
73
44
  NUITKA_MAY_BE_UNUSED static inline void CLEAR_ERROR_OCCURRED(PyThreadState *tstate) {
74
45
  #if PYTHON_VERSION < 0x3c0
@@ -209,6 +180,7 @@ NUITKA_MAY_BE_UNUSED static PyTracebackObject *ADD_TRACEBACK(PyTracebackObject *
209
180
 
210
181
  PyTracebackObject *traceback_new = MAKE_TRACEBACK(frame, lineno);
211
182
  traceback_new->tb_next = exception_tb;
183
+ Py_INCREF(exception_tb);
212
184
  return traceback_new;
213
185
  }
214
186
 
@@ -366,6 +338,14 @@ NUITKA_MAY_BE_UNUSED inline static void SET_CURRENT_EXCEPTION(PyThreadState *tst
366
338
  #endif
367
339
  }
368
340
 
341
+ // Normalize an exception, may release old values and replace them, expects
342
+ // references passed and returns them.
343
+ NUITKA_MAY_BE_UNUSED static inline void NORMALIZE_EXCEPTION(PyThreadState *tstate, PyObject **exception_type,
344
+ PyObject **exception_value,
345
+ PyTracebackObject **exception_tb);
346
+
347
+ extern PyObject *NORMALIZE_EXCEPTION_VALUE_FOR_RAISE(PyThreadState *tstate, PyObject *exception_type);
348
+
369
349
  // Helper that sets the current thread exception, and has no reference passed.
370
350
  // Similar to "PyErr_SetNone".
371
351
  NUITKA_MAY_BE_UNUSED inline static void SET_CURRENT_EXCEPTION_TYPE0(PyThreadState *tstate, PyObject *exception_type) {
@@ -392,11 +372,11 @@ NUITKA_MAY_BE_UNUSED inline static void SET_CURRENT_EXCEPTION_TYPE0(PyThreadStat
392
372
  #else
393
373
  PyObject *old_exception = tstate->current_exception;
394
374
  ASSERT_NORMALIZED_EXCEPTION_VALUE_X(old_exception);
395
- PyObject *exception_value = NULL;
396
- NORMALIZE_EXCEPTION(tstate, &exception_type, &exception_value, NULL);
375
+
376
+ // TODO: Make the call, exception creation on the outside somehow.
377
+ PyObject *exception_value = NORMALIZE_EXCEPTION_VALUE_FOR_RAISE(tstate, exception_type);
397
378
  ASSERT_NORMALIZED_EXCEPTION_VALUE(exception_value);
398
379
  tstate->current_exception = exception_value;
399
- Py_DECREF(exception_type);
400
380
 
401
381
  #if _DEBUG_EXCEPTIONS
402
382
  PRINT_STRING("SET_CURRENT_EXCEPTION_TYPE0:\n");
@@ -436,13 +416,14 @@ SET_CURRENT_EXCEPTION_TYPE0_VALUE0(PyThreadState *tstate, PyObject *exception_ty
436
416
  PyObject *old_exception_value = tstate->current_exception;
437
417
  ASSERT_NORMALIZED_EXCEPTION_VALUE_X(old_exception_value);
438
418
 
419
+ // TODO: Make the call on the outside.
439
420
  NORMALIZE_EXCEPTION(tstate, &exception_type, &exception_value, NULL);
440
421
  ASSERT_NORMALIZED_EXCEPTION_VALUE(exception_value);
441
422
  tstate->current_exception = exception_value;
442
423
  Py_INCREF(exception_value);
443
424
 
444
425
  #if _DEBUG_EXCEPTIONS
445
- PRINT_STRING("SET_CURRENT_EXCEPTION_TYPE_0VALUE0:\n");
426
+ PRINT_STRING("SET_CURRENT_EXCEPTION_TYPE_0_VALUE0:\n");
446
427
  PRINT_CURRENT_EXCEPTION();
447
428
  #endif
448
429
 
@@ -450,8 +431,13 @@ SET_CURRENT_EXCEPTION_TYPE0_VALUE0(PyThreadState *tstate, PyObject *exception_ty
450
431
  #endif
451
432
  }
452
433
 
434
+ // TODO: For Python3.12 it would be nice to know it's normalized already, so we
435
+ // can avoid the call to "NORMALIZE_EXCEPTION".
453
436
  NUITKA_MAY_BE_UNUSED inline static void
454
437
  SET_CURRENT_EXCEPTION_TYPE0_VALUE1(PyThreadState *tstate, PyObject *exception_type, PyObject *exception_value) {
438
+ CHECK_OBJECT(exception_type);
439
+ CHECK_OBJECT(exception_value);
440
+
455
441
  #if PYTHON_VERSION < 0x3c0
456
442
  PyObject *old_exception_type = tstate->curexc_type;
457
443
  PyObject *old_exception_value = tstate->curexc_value;
@@ -474,6 +460,7 @@ SET_CURRENT_EXCEPTION_TYPE0_VALUE1(PyThreadState *tstate, PyObject *exception_ty
474
460
  PyObject *old_exception_value = tstate->current_exception;
475
461
  ASSERT_NORMALIZED_EXCEPTION_VALUE_X(old_exception_value);
476
462
 
463
+ // TODO: Make the call, exception creation on the outside somehow.
477
464
  NORMALIZE_EXCEPTION(tstate, &exception_type, &exception_value, NULL);
478
465
  ASSERT_NORMALIZED_EXCEPTION_VALUE_X(exception_value);
479
466
  tstate->current_exception = exception_value;
@@ -494,10 +481,6 @@ NUITKA_MAY_BE_UNUSED inline static void SET_CURRENT_EXCEPTION_TYPE0_STR(PyThread
494
481
  char const *value) {
495
482
  PyObject *exception_value = Nuitka_String_FromString(value);
496
483
 
497
- #if PYTHON_VERSION >= 0x3c0
498
- NORMALIZE_EXCEPTION(tstate, &exception_type, &exception_value, NULL);
499
- #endif
500
-
501
484
  SET_CURRENT_EXCEPTION_TYPE0_VALUE1(tstate, exception_type, exception_value);
502
485
  }
503
486
 
@@ -618,55 +601,7 @@ NUITKA_MAY_BE_UNUSED static inline PyTracebackObject *GET_EXCEPTION_TRACEBACK(Py
618
601
  PyBaseExceptionObject *exc_object = (PyBaseExceptionObject *)(exception_value);
619
602
  return (PyTracebackObject *)exc_object->traceback;
620
603
  }
621
- #endif
622
-
623
- // Publish an exception, erasing the values of the variables.
624
- NUITKA_MAY_BE_UNUSED static inline void PUBLISH_CURRENT_EXCEPTION(PyThreadState *tstate, PyObject **exception_type,
625
- PyObject **exception_value,
626
- PyTracebackObject **exception_tb) {
627
- #if _DEBUG_EXCEPTIONS
628
- PRINT_STRING("PUBLISH_CURRENT_EXCEPTION:\n");
629
- #endif
630
- NORMALIZE_EXCEPTION(tstate, exception_type, exception_value, exception_tb);
631
- ATTACH_TRACEBACK_TO_EXCEPTION_VALUE(*exception_value, *exception_tb);
632
-
633
- struct Nuitka_ExceptionStackItem exc_state;
634
-
635
- #if PYTHON_VERSION < 0x3b0
636
- exc_state.exception_type = *exception_type;
637
- #endif
638
- exc_state.exception_value = *exception_value;
639
- #if PYTHON_VERSION < 0x3b0
640
- exc_state.exception_tb = *exception_tb;
641
- #endif
642
-
643
- SET_CURRENT_EXCEPTION(tstate, &exc_state);
644
-
645
- #if PYTHON_VERSION >= 0x3b0
646
- // TODO: We shouldn't get these in the first place, we don't transfer the
647
- // type anymore and the exception tb could come in already attached.
648
- Py_DECREF(*exception_type);
649
- Py_XDECREF(*exception_tb);
650
- #endif
651
-
652
- *exception_type = NULL;
653
- *exception_value = NULL;
654
- *exception_tb = NULL;
655
- }
656
604
 
657
- #if PYTHON_VERSION >= 0x300
658
- // Attach the exception context if necessary.
659
- NUITKA_MAY_BE_UNUSED static inline void ADD_EXCEPTION_CONTEXT(PyThreadState *tstate, PyObject **exception_type,
660
- PyObject **exception_value) {
661
- PyObject *context = EXC_VALUE(tstate);
662
-
663
- if (context != NULL) {
664
- NORMALIZE_EXCEPTION(tstate, exception_type, exception_value, NULL);
665
-
666
- Py_INCREF(context);
667
- PyException_SetContext(*exception_value, context);
668
- }
669
- }
670
605
  #endif
671
606
 
672
607
  NUITKA_MAY_BE_UNUSED static bool EXCEPTION_MATCH_BOOL_SINGLE(PyThreadState *tstate, PyObject *exception_value,
@@ -736,20 +671,6 @@ NUITKA_MAY_BE_UNUSED static bool CHECK_AND_CLEAR_ATTRIBUTE_ERROR_OCCURRED(PyThre
736
671
  return _CHECK_AND_CLEAR_EXCEPTION_OCCURRED(tstate, PyExc_AttributeError);
737
672
  }
738
673
 
739
- // Format a NameError exception for a variable name, chains with existing exception.
740
- extern void SET_CURRENT_EXCEPTION_NAME_ERROR(PyThreadState *tstate, PyObject *variable_name);
741
-
742
- #if PYTHON_VERSION < 0x340
743
- // Same as SET_CURRENT_EXCEPTION_NAME_ERROR with different wording, sometimes for Python2.
744
- extern void SET_CURRENT_EXCEPTION_GLOBAL_NAME_ERROR(PyThreadState *tstate, PyObject *variable_name);
745
- #endif
746
-
747
- // Format a UnboundLocalError exception for a variable name.
748
- extern void FORMAT_UNBOUND_LOCAL_ERROR(PyObject **exception_type, PyObject **exception_value, PyObject *variable_name);
749
-
750
- extern void FORMAT_UNBOUND_CLOSURE_ERROR(PyObject **exception_type, PyObject **exception_value,
751
- PyObject *variable_name);
752
-
753
674
  #if PYTHON_VERSION >= 0x3c0
754
675
  NUITKA_MAY_BE_UNUSED static PyObject *MAKE_TUPLE1(PyThreadState *tstate, PyObject *element1);
755
676
 
@@ -794,6 +715,8 @@ struct Nuitka_ExceptionPreservationItem {
794
715
  PyTracebackObject *exception_tb;
795
716
  };
796
717
 
718
+ static const struct Nuitka_ExceptionPreservationItem Empty_Nuitka_ExceptionPreservationItem = {0};
719
+
797
720
  // Fetch the current exception into state, transfers reference coming from tstate ownership. Old values are overwritten.
798
721
  NUITKA_MAY_BE_UNUSED static void FETCH_ERROR_OCCURRED_STATE(PyThreadState *tstate,
799
722
  struct Nuitka_ExceptionPreservationItem *exception_state) {
@@ -888,7 +811,7 @@ ASSIGN_ARGS_FROM_EXCEPTION_PRESERVATION_STATE(struct Nuitka_ExceptionPreservatio
888
811
  }
889
812
 
890
813
  NUITKA_MAY_BE_UNUSED static PyTracebackObject *
891
- GET_EXCEPTION_STATE_TRACEBACK(struct Nuitka_ExceptionPreservationItem const *exception_state) {
814
+ GET_EXCEPTION_STATE_TRACEBACK(struct Nuitka_ExceptionPreservationItem *exception_state) {
892
815
  return exception_state->exception_tb;
893
816
  }
894
817
 
@@ -897,6 +820,7 @@ NUITKA_MAY_BE_UNUSED static void SET_EXCEPTION_STATE_TRACEBACK(struct Nuitka_Exc
897
820
  PyTracebackObject *exception_tb) {
898
821
  CHECK_OBJECT_X(exception_state->exception_tb);
899
822
  CHECK_OBJECT_X(exception_tb);
823
+
900
824
  Py_XDECREF(exception_state->exception_tb);
901
825
  exception_state->exception_tb = exception_tb;
902
826
  }
@@ -930,6 +854,8 @@ struct Nuitka_ExceptionPreservationItem {
930
854
  PyObject *exception_value;
931
855
  };
932
856
 
857
+ static const struct Nuitka_ExceptionPreservationItem Empty_Nuitka_ExceptionPreservationItem = {0};
858
+
933
859
  // Fetch the current exception into state, transfers reference coming from tstate ownership. Old value is overwritten.
934
860
  NUITKA_MAY_BE_UNUSED static void FETCH_ERROR_OCCURRED_STATE(PyThreadState *tstate,
935
861
  struct Nuitka_ExceptionPreservationItem *exception_state) {
@@ -961,7 +887,7 @@ RESTORE_ERROR_OCCURRED_STATE(PyThreadState *tstate, struct Nuitka_ExceptionPrese
961
887
  tstate->current_exception = exception_state->exception_value;
962
888
 
963
889
  #if _DEBUG_EXCEPTIONS
964
- PRINT_STRING("RESTORE_ERROR_OCCURRED:\n");
890
+ PRINT_STRING("RESTORE_ERROR_OCCURRED_STATE:\n");
965
891
  PRINT_CURRENT_EXCEPTION();
966
892
  #endif
967
893
 
@@ -1082,19 +1008,79 @@ CHECK_EXCEPTION_STATE_X(struct Nuitka_ExceptionPreservationItem const *exception
1082
1008
 
1083
1009
  #endif
1084
1010
 
1011
+ NUITKA_MAY_BE_UNUSED inline static void SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0(
1012
+ PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state, PyObject *exception_type) {
1013
+
1014
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_ARGS(tstate, exception_state, exception_type, NULL, NULL);
1015
+ }
1016
+
1017
+ extern PyObject *CALL_FUNCTION_WITH_SINGLE_ARG(PyThreadState *tstate, PyObject *called, PyObject *arg);
1018
+
1019
+ NUITKA_MAY_BE_UNUSED inline static void
1020
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_VALUE1(PyThreadState *tstate,
1021
+ struct Nuitka_ExceptionPreservationItem *exception_state,
1022
+ PyObject *exception_type, PyObject *exception_value) {
1023
+ #if PYTHON_VERSION < 0x3c0
1024
+ Py_INCREF(exception_type);
1025
+
1026
+ exception_state->exception_type = exception_type;
1027
+ exception_state->exception_value = exception_value;
1028
+ exception_state->exception_tb = NULL;
1029
+ #else
1030
+ PyObject *exc = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, exception_type, exception_value);
1031
+ exception_state->exception_value = exc;
1032
+ Py_DECREF(exception_value);
1033
+ #endif
1034
+ }
1035
+
1036
+ NUITKA_MAY_BE_UNUSED inline static void
1037
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_VALUE1_NORMALIZED(PyThreadState *tstate,
1038
+ struct Nuitka_ExceptionPreservationItem *exception_state,
1039
+ PyObject *exception_type, PyObject *exception_value) {
1040
+ #if PYTHON_VERSION < 0x3c0
1041
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_VALUE1(tstate, exception_state, exception_type, exception_value);
1042
+ #else
1043
+ exception_state->exception_value = exception_value;
1044
+ #endif
1045
+ }
1046
+
1047
+ NUITKA_MAY_BE_UNUSED inline static void
1048
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_VALUE0(PyThreadState *tstate,
1049
+ struct Nuitka_ExceptionPreservationItem *exception_state,
1050
+ PyObject *exception_type, PyObject *exception_value) {
1051
+ // TODO: Add variants for normalized values only.
1052
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_ARGS(tstate, exception_state, exception_type, exception_value, NULL);
1053
+ }
1054
+
1085
1055
  NUITKA_MAY_BE_UNUSED inline static void
1086
1056
  SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_STR(PyThreadState *tstate,
1087
1057
  struct Nuitka_ExceptionPreservationItem *exception_state,
1088
1058
  PyObject *exception_type, char const *value) {
1089
1059
  PyObject *exception_value = Nuitka_String_FromString(value);
1090
1060
 
1091
- SET_EXCEPTION_PRESERVATION_STATE_FROM_ARGS(tstate, exception_state, exception_type, exception_value, NULL);
1092
- Py_DECREF(exception_value);
1061
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_VALUE1(tstate, exception_state, exception_type, exception_value);
1093
1062
  }
1094
1063
 
1064
+ #define SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_FORMAT1(tstate, exception_state, exception_type, message, arg1) \
1065
+ { \
1066
+ PyObject *exception_value = Nuitka_String_FromFormat(message, arg1); \
1067
+ CHECK_OBJECT(exception_value); \
1068
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_VALUE1(tstate, exception_state, exception_type, exception_value); \
1069
+ }
1070
+
1071
+ #define SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_FORMAT2(tstate, exception_state, exception_type, message, arg1, \
1072
+ arg2) \
1073
+ { \
1074
+ PyObject *exception_value = Nuitka_String_FromFormat(message, arg1, arg2); \
1075
+ CHECK_OBJECT(exception_value); \
1076
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_VALUE1(tstate, exception_state, exception_type, exception_value); \
1077
+ }
1078
+
1095
1079
  NUITKA_MAY_BE_UNUSED static bool EXCEPTION_MATCH_GENERATOR(PyThreadState *tstate, PyObject *exception_value) {
1096
1080
  CHECK_OBJECT(exception_value);
1097
1081
 
1082
+ // TODO: For Python3.12 this must be done differently to be a lot better.
1083
+
1098
1084
  // We need to check the class.
1099
1085
  if (PyExceptionInstance_Check(exception_value)) {
1100
1086
  exception_value = PyExceptionInstance_Class(exception_value);
@@ -1136,6 +1122,15 @@ NUITKA_MAY_BE_UNUSED static bool EXCEPTION_MATCH_GENERATOR(PyThreadState *tstate
1136
1122
  return false;
1137
1123
  }
1138
1124
 
1125
+ NUITKA_MAY_BE_UNUSED static bool
1126
+ EXCEPTION_STATE_MATCH_GENERATOR(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state) {
1127
+ #if PYTHON_VERSION < 0x3c0
1128
+ return EXCEPTION_MATCH_GENERATOR(tstate, exception_state->exception_type);
1129
+ #else
1130
+ return EXCEPTION_MATCH_GENERATOR(tstate, exception_state->exception_value);
1131
+ #endif
1132
+ }
1133
+
1139
1134
  NUITKA_MAY_BE_UNUSED static bool EXCEPTION_MATCH_BOOL_SINGLE(PyThreadState *tstate, PyObject *exception_value,
1140
1135
  PyObject *exception_checked) {
1141
1136
  CHECK_OBJECT(exception_value);
@@ -1152,10 +1147,13 @@ NUITKA_MAY_BE_UNUSED static bool EXCEPTION_MATCH_BOOL_SINGLE(PyThreadState *tsta
1152
1147
  }
1153
1148
 
1154
1149
  if (PyExceptionClass_Check(exception_value)) {
1150
+ #if PYTHON_VERSION < 0x300
1155
1151
  // Save the current exception, if any, we must preserve it.
1156
1152
  struct Nuitka_ExceptionPreservationItem saved_exception_state;
1157
1153
  FETCH_ERROR_OCCURRED_STATE(tstate, &saved_exception_state);
1158
1154
 
1155
+ // Python3.10 at least uses PyType_IsSubtype and needs no
1156
+ // fetch restore.
1159
1157
  int res = PyObject_IsSubclass(exception_value, exception_checked);
1160
1158
 
1161
1159
  // This function must not fail, so print the error here */
@@ -1166,6 +1164,10 @@ NUITKA_MAY_BE_UNUSED static bool EXCEPTION_MATCH_BOOL_SINGLE(PyThreadState *tsta
1166
1164
  RESTORE_ERROR_OCCURRED_STATE(tstate, &saved_exception_state);
1167
1165
 
1168
1166
  return res == 1;
1167
+ #else
1168
+ int res = Nuitka_Type_IsSubtype((PyTypeObject *)exception_value, (PyTypeObject *)exception_checked);
1169
+ return res == 1;
1170
+ #endif
1169
1171
  }
1170
1172
 
1171
1173
  return false;
@@ -1270,29 +1272,170 @@ NUITKA_MAY_BE_UNUSED static inline int EXCEPTION_MATCH_BOOL(PyThreadState *tstat
1270
1272
  }
1271
1273
  }
1272
1274
 
1273
- #if PYTHON_VERSION >= 0x3c0
1275
+ // Normalize an exception type to a value.
1274
1276
 
1275
- // Python3.12: TODO: Must get rid of those by generating code with exception_state
1276
- NUITKA_MAY_BE_UNUSED static void FETCH_ERROR_OCCURRED(PyThreadState *tstate, PyObject **exception_type,
1277
- PyObject **exception_value,
1278
- PyTracebackObject **exception_traceback) {
1277
+ extern void Nuitka_Err_NormalizeException(PyThreadState *tstate, PyObject **exc, PyObject **val,
1278
+ PyTracebackObject **tb);
1279
+
1280
+ // Normalize an exception, may release old values and replace them, expects
1281
+ // references passed and returns them.
1282
+ NUITKA_MAY_BE_UNUSED static inline void NORMALIZE_EXCEPTION(PyThreadState *tstate, PyObject **exception_type,
1283
+ PyObject **exception_value,
1284
+ PyTracebackObject **exception_tb) {
1285
+ #if _DEBUG_EXCEPTIONS
1286
+ PRINT_STRING("NORMALIZE_EXCEPTION: Enter\n");
1287
+ PRINT_EXCEPTION(*exception_type, *exception_value, *exception_tb);
1288
+ #endif
1289
+ CHECK_OBJECT_X(*exception_type);
1290
+ CHECK_OBJECT_X(*exception_value);
1291
+ if (exception_tb) {
1292
+ CHECK_OBJECT_X(*exception_tb);
1293
+ }
1279
1294
 
1280
- struct Nuitka_ExceptionPreservationItem exception_state;
1281
- FETCH_ERROR_OCCURRED_STATE(tstate, &exception_state);
1282
- ASSIGN_ARGS_FROM_EXCEPTION_PRESERVATION_STATE(&exception_state, exception_type, exception_value,
1283
- exception_traceback);
1284
- RELEASE_ERROR_OCCURRED_STATE_X(&exception_state);
1295
+ // TODO: Often we already know this to be true.
1296
+ if (*exception_type != Py_None && *exception_type != NULL) {
1297
+ Nuitka_Err_NormalizeException(tstate, exception_type, exception_value, exception_tb);
1298
+ }
1299
+
1300
+ #if _DEBUG_EXCEPTIONS
1301
+ PRINT_STRING("NORMALIZE_EXCEPTION: Leave\n");
1302
+ PRINT_EXCEPTION(*exception_type, *exception_value, exception_tb ? *exception_tb : NULL);
1303
+ #endif
1285
1304
  }
1286
1305
 
1287
- NUITKA_MAY_BE_UNUSED static void RESTORE_ERROR_OCCURRED(PyThreadState *tstate, PyObject *exception_type,
1288
- PyObject *exception_value, PyTracebackObject *exception_tb) {
1289
- struct Nuitka_ExceptionPreservationItem exception_state;
1290
- SET_EXCEPTION_PRESERVATION_STATE_FROM_ARGS(tstate, &exception_state, exception_type, exception_value, exception_tb);
1291
- Py_XDECREF(exception_type);
1292
- Py_XDECREF(exception_value);
1293
- Py_XDECREF(exception_tb);
1306
+ #if PYTHON_VERSION < 0x3c0
1307
+ // Normalize an exception, may release old values and replace them, expects
1308
+ // references passed and returns them.
1309
+ static inline void NORMALIZE_EXCEPTION_STATE(PyThreadState *tstate,
1310
+ struct Nuitka_ExceptionPreservationItem *exception_state) {
1311
+ CHECK_EXCEPTION_STATE_X(exception_state);
1312
+
1313
+ NORMALIZE_EXCEPTION(tstate, &exception_state->exception_type, &exception_state->exception_value,
1314
+ &exception_state->exception_tb);
1315
+ }
1316
+ #endif
1317
+
1318
+ extern PyObject *CALL_FUNCTION_NO_ARGS(PyThreadState *tstate, PyObject *called);
1319
+
1320
+ // Publish an exception, erasing the values of the variables.
1321
+ NUITKA_MAY_BE_UNUSED static inline void
1322
+ PUBLISH_CURRENT_EXCEPTION(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state) {
1323
+ #if _DEBUG_EXCEPTIONS
1324
+ PRINT_STRING("PUBLISH_CURRENT_EXCEPTION:\n");
1325
+ PRINT_EXCEPTION_STATE(exception_state);
1326
+ #endif
1327
+
1328
+ #if PYTHON_VERSION < 0x3c0
1329
+ NORMALIZE_EXCEPTION_STATE(tstate, exception_state);
1330
+ ATTACH_TRACEBACK_TO_EXCEPTION_VALUE(exception_state->exception_value, exception_state->exception_tb);
1331
+ #endif
1332
+
1333
+ struct Nuitka_ExceptionStackItem exc_state;
1334
+
1335
+ #if PYTHON_VERSION < 0x3b0
1336
+ exc_state.exception_type = exception_state->exception_type;
1337
+ #endif
1338
+ exc_state.exception_value = exception_state->exception_value;
1339
+ #if PYTHON_VERSION < 0x3b0
1340
+ exc_state.exception_tb = exception_state->exception_tb;
1341
+ #endif
1342
+
1343
+ SET_CURRENT_EXCEPTION(tstate, &exc_state);
1344
+
1345
+ #if PYTHON_VERSION >= 0x3b0 && PYTHON_VERSION < 0x3c0
1346
+ // TODO: We shouldn't get these in the first place, we don't transfer the
1347
+ // type anymore and the exception tb could come in already attached.
1348
+ Py_DECREF(exception_state->exception_type);
1349
+ Py_XDECREF(exception_state->exception_tb);
1350
+ #endif
1351
+
1352
+ INIT_ERROR_OCCURRED_STATE(exception_state);
1353
+ }
1354
+
1355
+ NUITKA_MAY_BE_UNUSED static bool
1356
+ _CHECK_AND_CLEAR_EXCEPTION_STATE(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state,
1357
+ PyObject *exception_type) {
1358
+ #if PYTHON_VERSION < 0x3c0
1359
+ PyObject *exception_current = exception_state->exception_type;
1360
+ #else
1361
+ PyObject *exception_current = exception_state->exception_value;
1362
+ ASSERT_NORMALIZED_EXCEPTION_VALUE_X(exception_current);
1363
+ #endif
1364
+ if (exception_current == NULL) {
1365
+ return true;
1366
+ } else if (EXCEPTION_MATCH_BOOL_SINGLE(tstate, exception_current, exception_type)) {
1367
+ CHECK_OBJECT(exception_current);
1368
+
1369
+ RELEASE_ERROR_OCCURRED_STATE(exception_state);
1370
+ INIT_ERROR_OCCURRED_STATE(exception_state);
1371
+
1372
+ return true;
1373
+ } else {
1374
+ return false;
1375
+ }
1376
+ }
1377
+
1378
+ // TODO: Get rid of "CHECK_AND_CLEAR_STOP_ITERATION_OCCURRED" and rename this to
1379
+ // its name.
1380
+ NUITKA_MAY_BE_UNUSED static bool
1381
+ CHECK_AND_CLEAR_STOP_ITERATION_STATE(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state) {
1382
+ return _CHECK_AND_CLEAR_EXCEPTION_STATE(tstate, exception_state, PyExc_StopIteration);
1383
+ }
1384
+
1385
+ // Format a UnboundLocalError exception for a variable name. TODO: This is more
1386
+ // for "raising.h" it seems.
1387
+ extern void FORMAT_UNBOUND_LOCAL_ERROR(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state,
1388
+ PyObject *variable_name);
1389
+
1390
+ extern void FORMAT_UNBOUND_CLOSURE_ERROR(PyThreadState *tstate,
1391
+ struct Nuitka_ExceptionPreservationItem *exception_state,
1392
+ PyObject *variable_name);
1393
+
1394
+ #if PYTHON_VERSION >= 0x300
1395
+ static inline PyBaseExceptionObject *_PyBaseExceptionObject_cast(PyObject *exc) {
1396
+ assert(PyExceptionInstance_Check(exc));
1397
+ return (PyBaseExceptionObject *)exc;
1398
+ }
1399
+
1400
+ // Exception context, replacement for "PyException_GetContext", it however gives no
1401
+ // reference.
1402
+ NUITKA_MAY_BE_UNUSED static inline PyObject *Nuitka_Exception_GetContext(PyObject *self) {
1403
+ return _PyBaseExceptionObject_cast(self)->context;
1404
+ }
1405
+
1406
+ // Exception context, replacement for "PyException_SetContext" it however doesn't
1407
+ // consume a reference.
1408
+ NUITKA_MAY_BE_UNUSED static inline void Nuitka_Exception_SetContext(PyObject *self, PyObject *context) {
1409
+ CHECK_OBJECT(context);
1410
+
1411
+ Py_INCREF(context);
1412
+ Py_XSETREF(_PyBaseExceptionObject_cast(self)->context, context);
1413
+ }
1414
+
1415
+ NUITKA_MAY_BE_UNUSED static inline void Nuitka_Exception_DeleteContext(PyObject *self) {
1416
+ Py_XSETREF(_PyBaseExceptionObject_cast(self)->context, NULL);
1417
+ }
1418
+
1419
+ #if PYTHON_VERSION >= 0x300
1420
+ // Attach the exception context if necessary.
1421
+ NUITKA_MAY_BE_UNUSED static inline void
1422
+ ADD_EXCEPTION_CONTEXT(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state) {
1423
+ PyObject *context = EXC_VALUE(tstate);
1424
+
1425
+ if (context != NULL) {
1426
+ #if PYTHON_VERSION < 0x3c0
1427
+ NORMALIZE_EXCEPTION_STATE(tstate, exception_state);
1428
+ #endif
1429
+ Nuitka_Exception_SetContext(exception_state->exception_value, context);
1430
+ }
1431
+ }
1432
+ #endif
1294
1433
 
1295
- RESTORE_ERROR_OCCURRED_STATE(tstate, &exception_state);
1434
+ // Our replacement for "PyException_SetCause", consumes a reference.
1435
+ NUITKA_MAY_BE_UNUSED static inline void Nuitka_Exception_SetCause(PyObject *self, PyObject *cause) {
1436
+ PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self);
1437
+ base_self->suppress_context = 1;
1438
+ Py_XSETREF(base_self->cause, cause);
1296
1439
  }
1297
1440
 
1298
1441
  #endif
@@ -39,10 +39,6 @@ extern PyObject *FIND_ATTRIBUTE_IN_CLASS(PyClassObject *class_object, PyObject *
39
39
  #endif
40
40
 
41
41
  extern PyObject *LOOKUP_MODULE_VALUE(PyDictObject *module_dict, PyObject *var_name);
42
- extern PyObject *GET_MODULE_VARIABLE_VALUE_FALLBACK(PyThreadState *tstate, PyObject *variable_name);
43
- #if PYTHON_VERSION < 0x340
44
- extern PyObject *GET_MODULE_VARIABLE_VALUE_FALLBACK_IN_FUNCTION(PyThreadState *tstate, PyObject *variable_name);
45
- #endif
46
42
 
47
43
  // In case of DLL usage, this avoids looking up the symbol from it.
48
44
  extern getattrofunc PyObject_GenericGetAttr_resolved;