Nuitka-winsvc 2.4.8__cp311-cp311-win_amd64.whl → 2.5.1__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 (294) hide show
  1. {Nuitka_winsvc-2.4.8.dist-info → Nuitka_winsvc-2.5.1.dist-info}/METADATA +2 -1
  2. {Nuitka_winsvc-2.4.8.dist-info → Nuitka_winsvc-2.5.1.dist-info}/RECORD +294 -271
  3. {Nuitka_winsvc-2.4.8.dist-info → Nuitka_winsvc-2.5.1.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 +105 -52
  8. nuitka/Options.py +73 -16
  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 +12 -2
  20. nuitka/build/SconsCompilerSettings.py +17 -6
  21. nuitka/build/SconsInterface.py +1 -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 +6 -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 +65 -29
  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/helpers.h +12 -2
  50. nuitka/build/include/nuitka/prelude.h +35 -25
  51. nuitka/build/include/nuitka/printing.h +9 -7
  52. nuitka/build/include/nuitka/threading.h +15 -1
  53. nuitka/build/include/nuitka/type_aliases.h +3 -0
  54. nuitka/build/inline_copy/stubgen/astunparse.py +938 -0
  55. nuitka/build/inline_copy/stubgen/six.py +998 -0
  56. nuitka/build/inline_copy/stubgen/stubgen.py +307 -0
  57. nuitka/build/static_src/CompiledAsyncgenType.c +45 -39
  58. nuitka/build/static_src/CompiledCellType.c +6 -4
  59. nuitka/build/static_src/CompiledCodeHelpers.c +104 -40
  60. nuitka/build/static_src/CompiledCoroutineType.c +40 -30
  61. nuitka/build/static_src/CompiledFrameType.c +110 -79
  62. nuitka/build/static_src/CompiledFunctionType.c +173 -151
  63. nuitka/build/static_src/CompiledGeneratorType.c +51 -49
  64. nuitka/build/static_src/CompiledGeneratorTypeUncompiledIntegration.c +424 -46
  65. nuitka/build/static_src/CompiledMethodType.c +10 -13
  66. nuitka/build/static_src/HelpersAllocator.c +270 -32
  67. nuitka/build/static_src/HelpersAttributes.c +0 -21
  68. nuitka/build/static_src/HelpersBuiltin.c +22 -13
  69. nuitka/build/static_src/HelpersCalling.c +7 -7
  70. nuitka/build/static_src/HelpersCallingGenerated.c +70 -70
  71. nuitka/build/static_src/HelpersComparisonDualEq.c +183 -0
  72. nuitka/build/static_src/HelpersComparisonDualGe.c +121 -0
  73. nuitka/build/static_src/HelpersComparisonDualGt.c +121 -0
  74. nuitka/build/static_src/HelpersComparisonDualLe.c +183 -0
  75. nuitka/build/static_src/HelpersComparisonDualLt.c +183 -0
  76. nuitka/build/static_src/HelpersComparisonDualNe.c +121 -0
  77. nuitka/build/static_src/HelpersComparisonEq.c +18 -4
  78. nuitka/build/static_src/HelpersComparisonEqUtils.c +1 -0
  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 +10 -4
  86. nuitka/build/static_src/HelpersDictionaries.c +181 -34
  87. nuitka/build/static_src/HelpersDictionariesGenerated.c +0 -106
  88. nuitka/build/static_src/HelpersExceptions.c +24 -50
  89. nuitka/build/static_src/HelpersFiles.c +79 -5
  90. nuitka/build/static_src/HelpersImport.c +13 -9
  91. nuitka/build/static_src/HelpersImportHard.c +23 -46
  92. nuitka/build/static_src/HelpersLists.c +98 -9
  93. nuitka/build/static_src/HelpersMatching.c +1 -1
  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 +1 -1
  129. nuitka/build/static_src/HelpersTypes.c +98 -2
  130. nuitka/build/static_src/MainProgram.c +117 -29
  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 +73 -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 +0 -105
  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 +13 -3
  209. nuitka/freezer/DllDependenciesMacOS.py +18 -1
  210. nuitka/freezer/DllDependenciesWin32.py +26 -12
  211. nuitka/freezer/ImportDetection.py +3 -0
  212. nuitka/freezer/IncludedDataFiles.py +31 -8
  213. nuitka/freezer/IncludedEntryPoints.py +3 -2
  214. nuitka/freezer/Standalone.py +76 -18
  215. nuitka/importing/Importing.py +33 -6
  216. nuitka/importing/Recursion.py +12 -1
  217. nuitka/importing/StandardLibrary.py +57 -59
  218. nuitka/nodes/AsyncgenNodes.py +3 -6
  219. nuitka/nodes/BuiltinIteratorNodes.py +1 -1
  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/ExceptionNodes.py +102 -26
  225. nuitka/nodes/ExpressionBasesGenerated.py +288 -4
  226. nuitka/nodes/FrameNodes.py +22 -11
  227. nuitka/nodes/FunctionNodes.py +3 -3
  228. nuitka/nodes/GeneratorNodes.py +3 -6
  229. nuitka/nodes/HardImportNodesGenerated.py +182 -0
  230. nuitka/nodes/ImportNodes.py +2 -2
  231. nuitka/nodes/NodeBases.py +28 -1
  232. nuitka/nodes/NodeMakingHelpers.py +71 -50
  233. nuitka/nodes/OperatorNodesUnary.py +128 -3
  234. nuitka/nodes/OsSysNodes.py +37 -6
  235. nuitka/nodes/OutlineNodes.py +2 -2
  236. nuitka/nodes/StatementBasesGenerated.py +0 -2
  237. nuitka/nodes/StatementNodes.py +8 -7
  238. nuitka/nodes/SubscriptNodes.py +1 -1
  239. nuitka/nodes/TypeNodes.py +28 -1
  240. nuitka/nodes/shapes/BuiltinTypeShapes.py +24 -7
  241. nuitka/nodes/shapes/ShapeMixins.py +17 -0
  242. nuitka/nodes/shapes/StandardShapes.py +53 -1
  243. nuitka/optimizations/BytecodeDemotion.py +2 -1
  244. nuitka/plugins/PluginBase.py +64 -22
  245. nuitka/plugins/Plugins.py +6 -3
  246. nuitka/plugins/standard/AntiBloatPlugin.py +23 -12
  247. nuitka/plugins/standard/ImplicitImports.py +1 -13
  248. nuitka/plugins/standard/KivyPlugin.py +3 -12
  249. nuitka/plugins/standard/MatplotlibPlugin.py +12 -1
  250. nuitka/plugins/standard/MultiprocessingPlugin.py +11 -20
  251. nuitka/plugins/standard/PlaywrightPlugin.py +184 -0
  252. nuitka/plugins/standard/PySidePyQtPlugin.py +8 -0
  253. nuitka/plugins/standard/TkinterPlugin.py +0 -56
  254. nuitka/plugins/standard/TransformersPlugin.py +70 -275
  255. nuitka/plugins/standard/standard.nuitka-package.config.yml +510 -28
  256. nuitka/plugins/standard/stdlib3.nuitka-package.config.yml +35 -2
  257. nuitka/reports/CompilationReportReader.py +12 -0
  258. nuitka/reports/Reports.py +11 -0
  259. nuitka/specs/BuiltinParameterSpecs.py +5 -1
  260. nuitka/specs/HardImportSpecs.py +7 -0
  261. nuitka/specs/ParameterSpecs.py +4 -4
  262. nuitka/tools/general/dll_report/__main__.py +10 -1
  263. nuitka/tools/onefile_compressor/OnefileCompressor.py +1 -1
  264. nuitka/tools/specialize/CTypeDescriptions.py +158 -9
  265. nuitka/tools/specialize/SpecializeC.py +218 -56
  266. nuitka/tools/testing/Common.py +70 -63
  267. nuitka/tools/testing/compare_with_cpython/__main__.py +3 -1
  268. nuitka/tools/testing/measure_construct_performance/__main__.py +1 -8
  269. nuitka/tools/testing/run_nuitka_tests/__main__.py +77 -11
  270. nuitka/tools/watch/AutoStage.py +1 -0
  271. nuitka/tree/Building.py +10 -37
  272. nuitka/tree/ComplexCallHelperFunctions.py +4 -0
  273. nuitka/tree/ReformulationAssertStatements.py +31 -14
  274. nuitka/tree/ReformulationAssignmentStatements.py +5 -1
  275. nuitka/tree/ReformulationClasses3.py +94 -19
  276. nuitka/tree/ReformulationDictionaryCreation.py +1 -0
  277. nuitka/tree/ReformulationFunctionStatements.py +1 -1
  278. nuitka/tree/ReformulationMatchStatements.py +3 -1
  279. nuitka/tree/ReformulationYieldExpressions.py +23 -5
  280. nuitka/utils/CommandLineOptions.py +27 -3
  281. nuitka/utils/Download.py +2 -2
  282. nuitka/utils/Execution.py +36 -31
  283. nuitka/utils/FileOperations.py +39 -54
  284. nuitka/utils/Importing.py +2 -14
  285. nuitka/utils/InlineCopies.py +52 -0
  286. nuitka/utils/InstalledPythons.py +9 -4
  287. nuitka/utils/Json.py +2 -2
  288. nuitka/utils/PackageResources.py +44 -0
  289. nuitka/utils/Utils.py +17 -0
  290. {Nuitka_winsvc-2.4.8.data → Nuitka_winsvc-2.5.1.data}/scripts/nuitka-run.cmd +0 -0
  291. {Nuitka_winsvc-2.4.8.data → Nuitka_winsvc-2.5.1.data}/scripts/nuitka.cmd +0 -0
  292. {Nuitka_winsvc-2.4.8.dist-info → Nuitka_winsvc-2.5.1.dist-info}/LICENSE.txt +0 -0
  293. {Nuitka_winsvc-2.4.8.dist-info → Nuitka_winsvc-2.5.1.dist-info}/entry_points.txt +0 -0
  294. {Nuitka_winsvc-2.4.8.dist-info → Nuitka_winsvc-2.5.1.dist-info}/top_level.txt +0 -0
@@ -10,23 +10,21 @@
10
10
  #include "nuitka/prelude.h"
11
11
  #endif
12
12
 
13
- static void FORMAT_TYPE_ERROR1(PyObject **exception_type, PyObject **exception_value, char const *format,
14
- char const *arg) {
15
- *exception_type = PyExc_TypeError;
16
- Py_INCREF(*exception_type);
13
+ static void FORMAT_TYPE_ERROR1(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state,
14
+ char const *format, char const *arg) {
15
+ PyObject *exception_value = Nuitka_String_FromFormat(format, arg);
16
+ CHECK_OBJECT(exception_value);
17
17
 
18
- *exception_value = Nuitka_String_FromFormat(format, arg);
19
- CHECK_OBJECT(*exception_value);
18
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_VALUE1(tstate, exception_state, PyExc_TypeError, exception_value);
20
19
  }
21
20
 
22
21
  #if PYTHON_VERSION >= 0x270
23
- static void FORMAT_TYPE_ERROR2(PyObject **exception_type, PyObject **exception_value, char const *format,
24
- char const *arg1, char const *arg2) {
25
- *exception_type = PyExc_TypeError;
26
- Py_INCREF(*exception_type);
22
+ static void FORMAT_TYPE_ERROR2(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state,
23
+ char const *format, char const *arg1, char const *arg2) {
24
+ PyObject *exception_value = Nuitka_String_FromFormat(format, arg1, arg2);
25
+ CHECK_OBJECT(exception_value);
27
26
 
28
- *exception_value = Nuitka_String_FromFormat(format, arg1, arg2);
29
- CHECK_OBJECT(*exception_value);
27
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_VALUE1(tstate, exception_state, PyExc_TypeError, exception_value);
30
28
  }
31
29
  #endif
32
30
 
@@ -38,66 +36,57 @@ static void FORMAT_TYPE_ERROR2(PyObject **exception_type, PyObject **exception_v
38
36
  #define WRONG_EXCEPTION_TYPE_ERROR_MESSAGE "exceptions must derive from BaseException"
39
37
  #endif
40
38
 
41
- void RAISE_EXCEPTION_WITH_TYPE(PyThreadState *tstate, PyObject **exception_type, PyObject **exception_value,
42
- PyTracebackObject **exception_tb) {
43
- *exception_value = NULL;
44
- *exception_tb = NULL;
45
-
46
- #if PYTHON_VERSION < 0x300
47
- // Next, repeatedly, replace a tuple exception with its first item
48
- while (PyTuple_Check(*exception_type) && PyTuple_GET_SIZE(*exception_type) > 0) {
49
- PyObject *tmp = *exception_type;
50
- *exception_type = PyTuple_GET_ITEM(*exception_type, 0);
51
- Py_INCREF(*exception_type);
39
+ // Next, replace a tuple in exception type creation with its first item
40
+ #if PYTHON_VERSION < 0x3c0
41
+ static void UNPACK_TUPLE_EXCEPTION_TYPE(struct Nuitka_ExceptionPreservationItem *exception_state) {
42
+ while (unlikely(PyTuple_Check(exception_state->exception_type)) &&
43
+ PyTuple_GET_SIZE(exception_state->exception_type) > 0) {
44
+ PyObject *tmp = exception_state->exception_type;
45
+ exception_state->exception_type = PyTuple_GET_ITEM(exception_state->exception_type, 0);
46
+ Py_INCREF(exception_state->exception_type);
52
47
  Py_DECREF(tmp);
53
48
  }
49
+ }
54
50
  #endif
55
51
 
56
- if (PyExceptionClass_Check(*exception_type)) {
57
- NORMALIZE_EXCEPTION(tstate, exception_type, exception_value, exception_tb);
58
- #if PYTHON_VERSION >= 0x270
59
- // TODO: It seems NORMALIZE_EXCEPTION already does this?
60
- if (unlikely(!PyExceptionInstance_Check(*exception_value))) {
61
- assert(false);
62
-
63
- PyObject *old_exception_type = *exception_type;
64
- PyObject *old_exception_value = *exception_value;
65
-
66
- FORMAT_TYPE_ERROR2(exception_type, exception_value,
67
- "calling %s() should have returned an instance of BaseException, not '%s'",
68
- Py_TYPE(*exception_type)->tp_name, Py_TYPE(*exception_value)->tp_name);
69
-
70
- Py_DECREF(old_exception_type);
71
- Py_DECREF(old_exception_value);
52
+ #if PYTHON_VERSION < 0x3c0
53
+ void RAISE_EXCEPTION_WITH_TYPE(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state) {
54
+ exception_state->exception_value = NULL;
55
+ exception_state->exception_tb = NULL;
72
56
 
73
- return;
74
- }
57
+ #if PYTHON_VERSION < 0x300
58
+ // Next, repeatedly, replace a tuple exception with its first item
59
+ UNPACK_TUPLE_EXCEPTION_TYPE(exception_state);
75
60
  #endif
76
61
 
62
+ if (PyExceptionClass_Check(exception_state->exception_type)) {
63
+ NORMALIZE_EXCEPTION(tstate, &exception_state->exception_type, &exception_state->exception_value,
64
+ &exception_state->exception_tb);
65
+
77
66
  #if PYTHON_VERSION >= 0x300
78
- CHAIN_EXCEPTION(tstate, *exception_value);
67
+ CHAIN_EXCEPTION(tstate, exception_state->exception_value);
79
68
  #endif
80
69
  return;
81
- } else if (PyExceptionInstance_Check(*exception_type)) {
82
- *exception_value = *exception_type;
83
- *exception_type = PyExceptionInstance_Class(*exception_type);
84
- Py_INCREF(*exception_type);
70
+ } else if (PyExceptionInstance_Check(exception_state->exception_type)) {
71
+ exception_state->exception_value = exception_state->exception_type;
72
+ exception_state->exception_type = PyExceptionInstance_Class(exception_state->exception_type);
73
+ Py_INCREF(exception_state->exception_type);
85
74
 
86
75
  #if PYTHON_VERSION >= 0x300
87
- CHAIN_EXCEPTION(tstate, *exception_value);
76
+ CHAIN_EXCEPTION(tstate, exception_state->exception_value);
88
77
 
89
78
  // Note: Cannot be assigned here.
90
- assert(*exception_tb == NULL);
91
- *exception_tb = GET_EXCEPTION_TRACEBACK(*exception_value);
92
- Py_XINCREF(*exception_tb);
79
+ assert(exception_state->exception_tb == NULL);
80
+ exception_state->exception_tb = GET_EXCEPTION_TRACEBACK(exception_state->exception_value);
81
+ Py_XINCREF(exception_state->exception_tb);
93
82
  #endif
94
83
 
95
84
  return;
96
85
  } else {
97
- PyObject *old_exception_type = *exception_type;
86
+ PyObject *old_exception_type = exception_state->exception_type;
98
87
 
99
- FORMAT_TYPE_ERROR1(exception_type, exception_value, WRONG_EXCEPTION_TYPE_ERROR_MESSAGE,
100
- Py_TYPE(*exception_type)->tp_name);
88
+ FORMAT_TYPE_ERROR1(tstate, exception_state, WRONG_EXCEPTION_TYPE_ERROR_MESSAGE,
89
+ Py_TYPE(exception_state->exception_type)->tp_name);
101
90
 
102
91
  Py_DECREF(old_exception_type);
103
92
 
@@ -105,332 +94,262 @@ void RAISE_EXCEPTION_WITH_TYPE(PyThreadState *tstate, PyObject **exception_type,
105
94
  }
106
95
  }
107
96
 
108
- #if PYTHON_VERSION >= 0x300
109
- void RAISE_EXCEPTION_WITH_CAUSE(PyThreadState *tstate, PyObject **exception_type, PyObject **exception_value,
110
- PyTracebackObject **exception_tb, PyObject *exception_cause) {
111
- CHECK_OBJECT(*exception_type);
112
- CHECK_OBJECT(exception_cause);
113
- *exception_tb = NULL;
97
+ void RAISE_EXCEPTION_WITH_TYPE_AND_VALUE(PyThreadState *tstate,
98
+ struct Nuitka_ExceptionPreservationItem *exception_state) {
99
+ CHECK_EXCEPTION_STATE(exception_state);
114
100
 
115
- // None is not a cause.
116
- if (exception_cause == Py_None) {
117
- Py_DECREF_IMMORTAL(exception_cause);
118
- exception_cause = NULL;
119
- } else if (PyExceptionClass_Check(exception_cause)) {
120
- PyObject *old_exception_cause = exception_cause;
121
- exception_cause = PyObject_CallObject(exception_cause, NULL);
122
- Py_DECREF(old_exception_cause);
101
+ exception_state->exception_tb = NULL;
123
102
 
124
- if (unlikely(exception_cause == NULL)) {
125
- Py_DECREF(*exception_type);
126
- Py_XDECREF(*exception_tb);
103
+ // Non-empty tuple exceptions are the first element.
104
+ UNPACK_TUPLE_EXCEPTION_TYPE(exception_state);
127
105
 
128
- struct Nuitka_ExceptionPreservationItem exception_state;
129
- FETCH_ERROR_OCCURRED_STATE(tstate, &exception_state);
106
+ if (PyExceptionClass_Check(exception_state->exception_type)) {
107
+ NORMALIZE_EXCEPTION_STATE(tstate, exception_state);
108
+ #if PYTHON_VERSION >= 0x270
109
+ if (unlikely(!PyExceptionInstance_Check(exception_state->exception_value))) {
110
+ char const *exception_type_type = Py_TYPE(exception_state->exception_type)->tp_name;
111
+ char const *exception_value_type = Py_TYPE(exception_state->exception_value)->tp_name;
130
112
 
131
- ASSIGN_ARGS_FROM_EXCEPTION_PRESERVATION_STATE(&exception_state, exception_type, exception_value,
132
- exception_tb);
133
- RELEASE_ERROR_OCCURRED_STATE(&exception_state);
113
+ RELEASE_ERROR_OCCURRED_STATE(exception_state);
134
114
 
135
- return;
115
+ FORMAT_TYPE_ERROR2(tstate, exception_state,
116
+ "calling %s() should have returned an instance of BaseException, not '%s'",
117
+ exception_type_type, exception_value_type);
136
118
  }
137
- }
138
-
139
- if (unlikely(exception_cause != NULL && !PyExceptionInstance_Check(exception_cause))) {
140
- Py_DECREF(*exception_type);
141
- Py_XDECREF(*exception_tb);
142
-
143
- PyObject *old_exception_cause = exception_cause;
144
-
145
- #ifdef _NUITKA_FULL_COMPAT
146
- SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "exception causes must derive from BaseException");
147
- FETCH_ERROR_OCCURRED(tstate, exception_type, exception_value, exception_tb);
148
- #else
149
- FORMAT_TYPE_ERROR1(exception_type, exception_value,
150
- "exception causes must derive from BaseException (%s does not)",
151
- Py_TYPE(exception_cause)->tp_name);
152
119
  #endif
153
120
 
154
- Py_XDECREF(old_exception_cause);
155
121
  return;
156
- }
157
-
158
- if (PyExceptionClass_Check(*exception_type)) {
159
- NORMALIZE_EXCEPTION(tstate, exception_type, exception_value, exception_tb);
160
-
161
- if (unlikely(!PyExceptionInstance_Check(*exception_value))) {
162
- Py_DECREF(*exception_tb);
163
- Py_XDECREF(exception_cause);
164
-
165
- PyObject *old_exception_type = *exception_type;
166
- PyObject *old_exception_value = *exception_value;
167
-
168
- FORMAT_TYPE_ERROR2(exception_type, exception_value,
169
- "calling %s() should have returned an instance of BaseException, not '%s'",
170
- Py_TYPE(*exception_type)->tp_name, Py_TYPE(*exception_value)->tp_name);
171
-
172
- Py_DECREF(old_exception_type);
173
- Py_XDECREF(old_exception_value);
122
+ } else if (PyExceptionInstance_Check(exception_state->exception_type)) {
123
+ if (unlikely(exception_state->exception_value != NULL && exception_state->exception_value != Py_None)) {
124
+ RELEASE_ERROR_OCCURRED_STATE(exception_state);
125
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_STR(tstate, exception_state, PyExc_TypeError,
126
+ "instance exception may not have a separate value");
174
127
 
175
128
  return;
176
129
  }
177
130
 
178
- PyException_SetCause(*exception_value, exception_cause);
179
-
180
- CHAIN_EXCEPTION(tstate, *exception_value);
181
- return;
182
- } else if (PyExceptionInstance_Check(*exception_type)) {
183
- *exception_value = *exception_type;
184
- *exception_type = PyExceptionInstance_Class(*exception_type);
185
- Py_INCREF(*exception_type);
186
-
187
- PyException_SetCause(*exception_value, exception_cause);
131
+ // The type is rather a value, so we are overriding it here.
132
+ exception_state->exception_value = exception_state->exception_type;
133
+ exception_state->exception_type = PyExceptionInstance_Class(exception_state->exception_type);
134
+ Py_INCREF(exception_state->exception_type);
188
135
 
189
- CHAIN_EXCEPTION(tstate, *exception_value);
190
136
  return;
191
137
  } else {
192
- Py_XDECREF(exception_cause);
138
+ char const *exception_type_type = Py_TYPE(exception_state->exception_type)->tp_name;
193
139
 
194
- PyObject *old_exception_type = *exception_type;
140
+ RELEASE_ERROR_OCCURRED_STATE(exception_state);
195
141
 
196
- FORMAT_TYPE_ERROR1(exception_type, exception_value, WRONG_EXCEPTION_TYPE_ERROR_MESSAGE,
197
- Py_TYPE(*exception_type)->tp_name);
198
-
199
- Py_DECREF(old_exception_type);
142
+ FORMAT_TYPE_ERROR1(tstate, exception_state, WRONG_EXCEPTION_TYPE_ERROR_MESSAGE, exception_type_type);
200
143
 
201
144
  return;
202
145
  }
203
146
  }
204
- #endif
205
147
 
206
- void RAISE_EXCEPTION_WITH_VALUE(PyThreadState *tstate, PyObject **exception_type, PyObject **exception_value,
207
- PyTracebackObject **exception_tb) {
208
- CHECK_OBJECT(*exception_type);
209
- CHECK_OBJECT(*exception_value);
210
- *exception_tb = NULL;
148
+ #else
211
149
 
212
- // Non-empty tuple exceptions are the first element.
213
- while (unlikely(PyTuple_Check(*exception_type) && PyTuple_GET_SIZE(*exception_type) > 0)) {
214
- *exception_type = PyTuple_GET_ITEM(*exception_type, 0);
215
- }
150
+ void RAISE_EXCEPTION_WITH_VALUE(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state) {
151
+ ASSERT_NORMALIZED_EXCEPTION_VALUE(exception_state->exception_value);
216
152
 
217
- if (PyExceptionClass_Check(*exception_type)) {
218
- NORMALIZE_EXCEPTION(tstate, exception_type, exception_value, exception_tb);
219
- #if PYTHON_VERSION >= 0x270
220
- if (unlikely(!PyExceptionInstance_Check(*exception_value))) {
221
- PyObject *old_exception_type = *exception_type;
222
- PyObject *old_exception_value = *exception_type;
153
+ CHAIN_EXCEPTION(tstate, exception_state->exception_value);
154
+ }
155
+ #endif
223
156
 
224
- FORMAT_TYPE_ERROR2(exception_type, exception_value,
225
- "calling %s() should have returned an instance of BaseException, not '%s'",
226
- Py_TYPE(*exception_type)->tp_name, Py_TYPE(*exception_value)->tp_name);
157
+ #if PYTHON_VERSION >= 0x300
158
+ void RAISE_EXCEPTION_WITH_CAUSE(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state,
159
+ PyObject *exception_cause) {
160
+ CHECK_EXCEPTION_STATE(exception_state);
161
+ CHECK_OBJECT(exception_cause);
227
162
 
228
- Py_DECREF(old_exception_type);
229
- Py_DECREF(old_exception_value);
230
- }
163
+ #if PYTHON_VERSION < 0x3c0
164
+ exception_state->exception_tb = NULL;
231
165
  #endif
232
166
 
233
- return;
234
- } else if (PyExceptionInstance_Check(*exception_type)) {
235
- if (unlikely(*exception_value != NULL && *exception_value != Py_None)) {
236
- Py_DECREF(*exception_type);
237
- Py_DECREF(*exception_value);
167
+ // None is not a cause.
168
+ if (exception_cause == Py_None) {
169
+ Py_DECREF_IMMORTAL(exception_cause);
170
+ exception_cause = NULL;
171
+ } else if (PyExceptionClass_Check(exception_cause)) {
172
+ PyObject *old_exception_cause = exception_cause;
173
+ exception_cause = CALL_FUNCTION_NO_ARGS(tstate, exception_cause);
174
+ Py_DECREF(old_exception_cause);
238
175
 
239
- *exception_type = PyExc_TypeError;
240
- Py_INCREF(PyExc_TypeError);
241
- *exception_value = Nuitka_String_FromString("instance exception may not have a separate value");
176
+ if (unlikely(exception_cause == NULL)) {
177
+ RELEASE_ERROR_OCCURRED_STATE(exception_state);
178
+ FETCH_ERROR_OCCURRED_STATE(tstate, exception_state);
242
179
 
243
180
  return;
244
181
  }
182
+ }
245
183
 
246
- // The type is rather a value, so we are overriding it here.
247
- *exception_value = *exception_type;
248
- *exception_type = PyExceptionInstance_Class(*exception_type);
249
- Py_INCREF(*exception_type);
184
+ if (unlikely(exception_cause != NULL && !PyExceptionInstance_Check(exception_cause))) {
185
+ RELEASE_ERROR_OCCURRED_STATE(exception_state);
186
+
187
+ #ifdef _NUITKA_FULL_COMPAT
188
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_STR(tstate, exception_state, PyExc_TypeError,
189
+ "exception causes must derive from BaseException");
190
+ #else
191
+ FORMAT_TYPE_ERROR1(tstate, exception_state, "exception causes must derive from BaseException (%s does not)",
192
+ Py_TYPE(exception_cause)->tp_name);
193
+ #endif
250
194
 
251
195
  return;
252
- } else {
253
- PyObject *old_exception_type = *exception_type;
196
+ }
254
197
 
255
- FORMAT_TYPE_ERROR1(exception_type, exception_value, WRONG_EXCEPTION_TYPE_ERROR_MESSAGE,
256
- Py_TYPE(*exception_type)->tp_name);
198
+ #if PYTHON_VERSION < 0x3c0
199
+ if (PyExceptionClass_Check(exception_state->exception_type)) {
200
+ char const *exception_type_type = Py_TYPE(exception_state->exception_type)->tp_name;
257
201
 
258
- Py_DECREF(old_exception_type);
202
+ NORMALIZE_EXCEPTION_STATE(tstate, exception_state);
259
203
 
260
- return;
261
- }
262
- }
204
+ if (unlikely(!PyExceptionInstance_Check(exception_state->exception_value))) {
205
+ Py_XDECREF(exception_cause);
263
206
 
264
- void RAISE_EXCEPTION_IMPLICIT(PyThreadState *tstate, PyObject **exception_type, PyObject **exception_value,
265
- PyTracebackObject **exception_tb) {
266
- CHECK_OBJECT(*exception_type);
267
- CHECK_OBJECT(*exception_value);
268
- *exception_tb = NULL;
207
+ char const *exception_value_type = Py_TYPE(exception_state->exception_value)->tp_name;
269
208
 
270
- // Non-empty tuple exceptions are the first element.
271
- while (unlikely(PyTuple_Check(*exception_type) && PyTuple_GET_SIZE(*exception_type) > 0)) {
272
- *exception_type = PyTuple_GET_ITEM(*exception_type, 0);
273
- }
209
+ RELEASE_ERROR_OCCURRED_STATE(exception_state);
274
210
 
275
- if (PyExceptionClass_Check(*exception_type)) {
276
- #if PYTHON_VERSION >= 0x340
277
- NORMALIZE_EXCEPTION(tstate, exception_type, exception_value, exception_tb);
278
- CHAIN_EXCEPTION(tstate, *exception_value);
279
- #endif
211
+ FORMAT_TYPE_ERROR2(tstate, exception_state,
212
+ "calling %s() should have returned an instance of BaseException, not '%s'",
213
+ exception_type_type, exception_value_type);
280
214
 
281
- return;
282
- } else if (PyExceptionInstance_Check(*exception_type)) {
283
- #if PYTHON_VERSION >= 0x340
284
- CHAIN_EXCEPTION(tstate, *exception_value);
285
- #endif
215
+ return;
216
+ }
286
217
 
287
- // The type is rather a value, so we are overriding it here.
288
- *exception_value = *exception_type;
289
- *exception_type = PyExceptionInstance_Class(*exception_type);
290
- Py_INCREF(*exception_type);
218
+ Nuitka_Exception_SetCause(exception_state->exception_value, exception_cause);
219
+ CHAIN_EXCEPTION(tstate, exception_state->exception_value);
220
+ } else if (PyExceptionInstance_Check(exception_state->exception_type)) {
221
+ exception_state->exception_value = exception_state->exception_type;
222
+ exception_state->exception_type = PyExceptionInstance_Class(exception_state->exception_type);
223
+ Py_INCREF(exception_state->exception_type);
291
224
 
292
- return;
225
+ Nuitka_Exception_SetCause(exception_state->exception_value, exception_cause);
226
+ CHAIN_EXCEPTION(tstate, exception_state->exception_value);
293
227
  } else {
294
- PyObject *old_exception_type = *exception_type;
295
- Py_DECREF(*exception_value);
228
+ Py_XDECREF(exception_cause);
296
229
 
297
- FORMAT_TYPE_ERROR1(exception_type, exception_value, WRONG_EXCEPTION_TYPE_ERROR_MESSAGE,
298
- Py_TYPE(*exception_type)->tp_name);
230
+ char const *exception_type_type = Py_TYPE(exception_state->exception_type)->tp_name;
299
231
 
300
- Py_DECREF(old_exception_type);
232
+ RELEASE_ERROR_OCCURRED_STATE(exception_state);
301
233
 
302
- #if PYTHON_VERSION >= 0x340
303
- CHAIN_EXCEPTION(tstate, *exception_value);
304
- #endif
305
-
306
- return;
234
+ FORMAT_TYPE_ERROR1(tstate, exception_state, WRONG_EXCEPTION_TYPE_ERROR_MESSAGE, exception_type_type);
307
235
  }
308
- }
236
+ #else
237
+ ASSERT_NORMALIZED_EXCEPTION_VALUE(exception_state->exception_value);
309
238
 
310
- void RAISE_EXCEPTION_WITH_TRACEBACK(PyThreadState *tstate, PyObject **exception_type, PyObject **exception_value,
311
- PyTracebackObject **exception_tb) {
312
- CHECK_OBJECT(*exception_type);
313
- CHECK_OBJECT(*exception_value);
239
+ Nuitka_Exception_SetCause(exception_state->exception_value, exception_cause);
240
+ CHAIN_EXCEPTION(tstate, exception_state->exception_value);
241
+ #endif
242
+ }
243
+ #endif
314
244
 
315
- if (*exception_tb == (PyTracebackObject *)Py_None) {
316
- Py_DECREF_IMMORTAL(*exception_tb);
317
- *exception_tb = NULL;
245
+ #if PYTHON_VERSION < 0x300
246
+ void RAISE_EXCEPTION_WITH_TRACEBACK(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state) {
247
+ if (exception_state->exception_tb == (PyTracebackObject *)Py_None) {
248
+ Py_DECREF_IMMORTAL(exception_state->exception_tb);
249
+ exception_state->exception_tb = NULL;
318
250
  }
319
251
 
320
252
  // Non-empty tuple exceptions are the first element.
321
- while (unlikely(PyTuple_Check(*exception_type) && PyTuple_GET_SIZE(*exception_type) > 0)) {
322
- *exception_type = PyTuple_GET_ITEM(*exception_type, 0);
323
- }
253
+ UNPACK_TUPLE_EXCEPTION_TYPE(exception_state);
324
254
 
325
- if (PyExceptionClass_Check(*exception_type)) {
326
- NORMALIZE_EXCEPTION(tstate, exception_type, exception_value, exception_tb);
255
+ if (PyExceptionClass_Check(exception_state->exception_type)) {
256
+ NORMALIZE_EXCEPTION_STATE(tstate, exception_state);
327
257
  #if PYTHON_VERSION >= 0x270
328
- if (unlikely(!PyExceptionInstance_Check(*exception_value))) {
329
- PyObject *old_exception_type = *exception_type;
330
- PyObject *old_exception_value = *exception_value;
258
+ if (unlikely(!PyExceptionInstance_Check(exception_state->exception_value))) {
259
+ char const *exception_type_type = Py_TYPE(exception_state->exception_type)->tp_name;
260
+ char const *exception_value_type = Py_TYPE(exception_state->exception_value)->tp_name;
331
261
 
332
- FORMAT_TYPE_ERROR2(exception_type, exception_value,
333
- "calling %s() should have returned an instance of BaseException, not '%s'",
334
- Py_TYPE(*exception_type)->tp_name, Py_TYPE(*exception_value)->tp_name);
262
+ RELEASE_ERROR_OCCURRED_STATE(exception_state);
335
263
 
336
- Py_DECREF(old_exception_type);
337
- Py_DECREF(old_exception_value);
264
+ // TODO: It would be even more safe to create the format value
265
+ // before releasing the value.
266
+ FORMAT_TYPE_ERROR2(tstate, exception_state,
267
+ "calling %s() should have returned an instance of BaseException, not '%s'",
268
+ exception_type_type, exception_value_type);
338
269
  }
339
270
  #endif
340
271
 
341
272
  return;
342
- } else if (PyExceptionInstance_Check(*exception_type)) {
343
- if (unlikely(*exception_value != NULL && *exception_value != Py_None)) {
344
- Py_DECREF(*exception_type);
345
- Py_XDECREF(*exception_value);
346
- Py_XDECREF(*exception_tb);
347
-
348
- *exception_type = PyExc_TypeError;
349
- Py_INCREF(PyExc_TypeError);
350
- *exception_value = Nuitka_String_FromString("instance exception may not have a separate value");
273
+ } else if (PyExceptionInstance_Check(exception_state->exception_type)) {
274
+ if (unlikely(exception_state->exception_value != NULL && exception_state->exception_value != Py_None)) {
275
+ RELEASE_ERROR_OCCURRED_STATE(exception_state);
276
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_STR(tstate, exception_state, PyExc_TypeError,
277
+ "instance exception may not have a separate value");
351
278
 
352
279
  return;
353
280
  }
354
281
 
355
282
  // The type is rather a value, so we are overriding it here.
356
- *exception_value = *exception_type;
357
- *exception_type = PyExceptionInstance_Class(*exception_type);
358
- Py_INCREF(*exception_type);
283
+ exception_state->exception_value = exception_state->exception_type;
284
+ exception_state->exception_type = PyExceptionInstance_Class(exception_state->exception_type);
285
+ Py_INCREF(exception_state->exception_type);
359
286
 
360
287
  return;
361
288
  } else {
362
- PyObject *old_exception_type = *exception_type;
363
-
364
- FORMAT_TYPE_ERROR1(exception_type, exception_value, WRONG_EXCEPTION_TYPE_ERROR_MESSAGE,
365
- Py_TYPE(*exception_type)->tp_name);
366
-
367
- Py_DECREF(old_exception_type);
289
+ FORMAT_TYPE_ERROR1(tstate, exception_state, WRONG_EXCEPTION_TYPE_ERROR_MESSAGE,
290
+ Py_TYPE(exception_state->exception_type)->tp_name);
368
291
 
369
292
  return;
370
293
  }
371
294
  }
295
+ #endif
372
296
 
373
- bool RERAISE_EXCEPTION(PyObject **exception_type, PyObject **exception_value, PyTracebackObject **exception_tb) {
374
- PyThreadState *tstate = PyThreadState_GET();
375
- assert(tstate);
376
-
297
+ bool RERAISE_EXCEPTION(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state) {
377
298
  #if PYTHON_VERSION < 0x3b0
378
- *exception_type = EXC_TYPE(tstate) != NULL ? EXC_TYPE(tstate) : Py_None;
379
- Py_INCREF(*exception_type);
380
- *exception_value = EXC_VALUE(tstate);
381
- Py_XINCREF(*exception_value);
382
- *exception_tb = (PyTracebackObject *)EXC_TRACEBACK(tstate);
383
- Py_XINCREF(*exception_tb);
384
-
385
- if (unlikely(*exception_type == Py_None)) {
299
+ exception_state->exception_type = EXC_TYPE(tstate) != NULL ? EXC_TYPE(tstate) : Py_None;
300
+ Py_INCREF(exception_state->exception_type);
301
+ exception_state->exception_value = EXC_VALUE(tstate);
302
+ Py_XINCREF(exception_state->exception_value);
303
+ exception_state->exception_tb = (PyTracebackObject *)EXC_TRACEBACK(tstate);
304
+ Py_XINCREF(exception_state->exception_tb);
305
+
306
+ if (unlikely(exception_state->exception_type == Py_None)) {
386
307
  #if PYTHON_VERSION >= 0x300
387
- Py_DECREF(*exception_type);
308
+ RELEASE_ERROR_OCCURRED_STATE(exception_state);
388
309
 
389
- Py_INCREF(PyExc_RuntimeError);
390
- *exception_type = PyExc_RuntimeError;
391
- *exception_value = PyUnicode_FromString("No active exception to reraise");
392
- *exception_tb = NULL;
310
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_STR(tstate, exception_state, PyExc_RuntimeError,
311
+ "No active exception to reraise");
393
312
  #else
394
- PyObject *old_exception_type = *exception_type;
313
+ char const *exception_type_type = Py_TYPE(exception_state->exception_type)->tp_name;
395
314
 
396
- FORMAT_TYPE_ERROR1(exception_type, exception_value, WRONG_EXCEPTION_TYPE_ERROR_MESSAGE,
397
- Py_TYPE(*exception_type)->tp_name);
315
+ RELEASE_ERROR_OCCURRED_STATE(exception_state);
316
+
317
+ FORMAT_TYPE_ERROR1(tstate, exception_state, WRONG_EXCEPTION_TYPE_ERROR_MESSAGE, exception_type_type);
398
318
 
399
- Py_DECREF(old_exception_type);
400
319
  #endif
401
320
 
402
321
  return false;
403
322
  }
404
323
  #else
405
- *exception_value = EXC_VALUE(tstate);
324
+ exception_state->exception_value = EXC_VALUE(tstate);
406
325
 
407
- if (*exception_value == Py_None || *exception_value == NULL) {
408
- Py_INCREF(PyExc_RuntimeError);
409
- *exception_type = PyExc_RuntimeError;
410
- *exception_value = PyUnicode_FromString("No active exception to reraise");
411
- *exception_tb = NULL;
326
+ if (exception_state->exception_value == Py_None || exception_state->exception_value == NULL) {
327
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_STR(tstate, exception_state, PyExc_RuntimeError,
328
+ "No active exception to reraise");
412
329
 
413
330
  return false;
414
331
  } else {
415
- Py_INCREF(*exception_value);
332
+ Py_INCREF(exception_state->exception_value);
416
333
 
417
- *exception_type = PyExceptionInstance_Class(*exception_value);
418
- Py_INCREF(*exception_type);
419
- *exception_tb = GET_EXCEPTION_TRACEBACK(*exception_value);
420
- Py_XINCREF(*exception_tb);
334
+ #if PYTHON_VERSION < 0x3c0
335
+ exception_state->exception_type = PyExceptionInstance_Class(exception_state->exception_value);
336
+ Py_INCREF(exception_state->exception_type);
337
+ exception_state->exception_tb = GET_EXCEPTION_TRACEBACK(exception_state->exception_value);
338
+ Py_XINCREF(exception_state->exception_tb);
339
+ #endif
421
340
  }
422
341
  #endif
423
342
 
424
- CHECK_OBJECT(*exception_type);
425
- CHECK_OBJECT(*exception_value);
426
- CHECK_OBJECT_X(*exception_tb);
343
+ // Check for value to be present as well.
344
+ CHECK_EXCEPTION_STATE(exception_state);
345
+ CHECK_OBJECT(exception_state->exception_value);
427
346
 
428
347
  return true;
429
348
  }
430
349
 
431
350
  // Raise NameError for a given variable name.
432
- void RAISE_CURRENT_EXCEPTION_NAME_ERROR(PyThreadState *tstate, PyObject *variable_name, PyObject **exception_type,
433
- PyObject **exception_value) {
351
+ void RAISE_CURRENT_EXCEPTION_NAME_ERROR(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state,
352
+ PyObject *variable_name) {
434
353
  #if PYTHON_VERSION < 0x300
435
354
  PyObject *exception_value_str =
436
355
  Nuitka_String_FromFormat("name '%s' is not defined", Nuitka_String_AsString_Unchecked(variable_name));
@@ -438,56 +357,82 @@ void RAISE_CURRENT_EXCEPTION_NAME_ERROR(PyThreadState *tstate, PyObject *variabl
438
357
  PyObject *exception_value_str = Nuitka_String_FromFormat("name '%U' is not defined", variable_name);
439
358
  #endif
440
359
 
441
- *exception_value = MAKE_EXCEPTION_FROM_TYPE_ARG0(tstate, PyExc_NameError, exception_value_str);
360
+ PyObject *exception_value = MAKE_EXCEPTION_FROM_TYPE_ARG0(tstate, PyExc_NameError, exception_value_str);
442
361
  Py_DECREF(exception_value_str);
443
362
 
444
- *exception_type = PyExc_NameError;
445
- Py_INCREF(PyExc_NameError);
446
-
447
363
  #if PYTHON_VERSION >= 0x300
448
- CHAIN_EXCEPTION(tstate, *exception_value);
364
+ CHAIN_EXCEPTION(tstate, exception_value);
449
365
  #endif
366
+
367
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_VALUE1_NORMALIZED(tstate, exception_state, PyExc_NameError,
368
+ exception_value);
450
369
  }
451
370
 
452
- #if PYTHON_VERSION < 0x340
453
- void RAISE_CURRENT_EXCEPTION_GLOBAL_NAME_ERROR(PyThreadState *tstate, PyObject *variable_name,
454
- PyObject **exception_type, PyObject **exception_value) {
455
371
  #if PYTHON_VERSION < 0x300
372
+ void RAISE_CURRENT_EXCEPTION_GLOBAL_NAME_ERROR(PyThreadState *tstate,
373
+ struct Nuitka_ExceptionPreservationItem *exception_state,
374
+ PyObject *variable_name) {
456
375
  PyObject *exception_value_str =
457
376
  Nuitka_String_FromFormat("global name '%s' is not defined", Nuitka_String_AsString_Unchecked(variable_name));
458
- #else
459
- PyObject *exception_value_str = Nuitka_String_FromFormat("global name '%U' is not defined", variable_name);
460
- #endif
461
- *exception_value = MAKE_EXCEPTION_FROM_TYPE_ARG0(tstate, PyExc_NameError, exception_value_str);
377
+ PyObject *exception_value = MAKE_EXCEPTION_FROM_TYPE_ARG0(tstate, PyExc_NameError, exception_value_str);
462
378
  Py_DECREF(exception_value_str);
463
379
 
464
- *exception_type = PyExc_NameError;
465
- Py_INCREF(PyExc_NameError);
380
+ SET_EXCEPTION_PRESERVATION_STATE_FROM_TYPE0_VALUE1_NORMALIZED(tstate, exception_state, PyExc_NameError,
381
+ exception_value);
466
382
  }
467
383
  #endif
468
384
 
469
- #if PYTHON_VERSION >= 0x300
385
+ PyObject *NORMALIZE_EXCEPTION_VALUE_FOR_RAISE(PyThreadState *tstate, PyObject *exception_type) {
386
+ // Allow setting the value to NULL for time savings with quick type only errors
387
+ CHECK_OBJECT(exception_type);
470
388
 
471
- void RAISE_EXCEPTION_WITH_CAUSE_STATE(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state,
472
- PyObject *exception_cause) {
473
- #if PYTHON_VERSION < 0x3c0
474
- RAISE_EXCEPTION_WITH_CAUSE(tstate, &exception_state->exception_type, &exception_state->exception_value,
475
- &exception_state->exception_tb, exception_cause);
476
- #else
477
- PyObject *exception_type = (PyObject *)PyExceptionInstance_Class(exception_state->exception_value);
478
- Py_INCREF(exception_type);
479
- PyTracebackObject *exception_tb = NULL;
389
+ if (PyExceptionInstance_Check(exception_type)) {
390
+ return Py_NewRef(exception_type);
391
+ } else {
392
+ if (unlikely(!PyExceptionClass_Check(exception_type))) {
393
+ struct Nuitka_ExceptionPreservationItem exception_state;
394
+ FORMAT_TYPE_ERROR1(tstate, &exception_state, WRONG_EXCEPTION_TYPE_ERROR_MESSAGE,
395
+ Py_TYPE(exception_type)->tp_name);
396
+ RESTORE_ERROR_OCCURRED_STATE(tstate, &exception_state);
397
+ return NULL;
398
+ }
480
399
 
481
- // Python3.12: We are being a bit lazy there, by preparing the 3 things when
482
- // we shouldn't really need them.
483
- RAISE_EXCEPTION_WITH_CAUSE(tstate, &exception_type, &exception_state->exception_value, &exception_tb,
484
- exception_cause);
400
+ PyObject *exception_value = CALL_FUNCTION_NO_ARGS(tstate, exception_type);
485
401
 
486
- Py_DECREF(exception_type);
487
- #endif
402
+ if (unlikely(exception_value == NULL)) {
403
+ return NULL;
404
+ }
405
+
406
+ if (unlikely(!PyExceptionInstance_Check(exception_value))) {
407
+ struct Nuitka_ExceptionPreservationItem exception_state;
408
+ FORMAT_TYPE_ERROR2(tstate, &exception_state,
409
+ "calling %R should have returned an instance of BaseException, not %R",
410
+ (char const *)exception_type, (char const *)Py_TYPE(exception_value));
411
+ RESTORE_ERROR_OCCURRED_STATE(tstate, &exception_state);
412
+
413
+ Py_DECREF(exception_value);
414
+ return NULL;
415
+ }
416
+
417
+ return exception_value;
418
+ }
419
+ }
420
+
421
+ #if PYTHON_VERSION >= 0x300
422
+ PyObject *MAKE_STOP_ITERATION_EMPTY(void) {
423
+ // Fake tstate object is OK, no tuple will be needed.
424
+ return Nuitka_CreateStopIteration(NULL, NULL);
488
425
  }
489
- #endif
490
426
 
427
+ PyObject *MAKE_BASE_EXCEPTION_DERIVED_EMPTY(PyObject *exception_type) {
428
+ // Note: Fake tstate object is OK, no tuple will be needed to store anything
429
+ // in args.
430
+ PyBaseExceptionObject *result = Nuitka_BaseExceptionSingleArg_new(NULL, (PyTypeObject *)exception_type, NULL);
431
+
432
+ return (PyObject *)result;
433
+ }
434
+
435
+ #endif
491
436
  // Part of "Nuitka", an optimizing Python compiler that is compatible and
492
437
  // integrates with CPython, but also works on its own.
493
438
  //