Nuitka-winsvc 2.1.5__cp311-cp311-win_amd64.whl → 2.2.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 (234) hide show
  1. {Nuitka_winsvc-2.1.5.dist-info → Nuitka_winsvc-2.2.1.dist-info}/METADATA +1 -1
  2. {Nuitka_winsvc-2.1.5.dist-info → Nuitka_winsvc-2.2.1.dist-info}/RECORD +234 -225
  3. nuitka/Errors.py +4 -0
  4. nuitka/HardImportRegistry.py +18 -1
  5. nuitka/MainControl.py +27 -30
  6. nuitka/OptionParsing.py +32 -30
  7. nuitka/Options.py +26 -13
  8. nuitka/OutputDirectories.py +7 -4
  9. nuitka/PostProcessing.py +9 -7
  10. nuitka/Progress.py +3 -3
  11. nuitka/PythonVersions.py +2 -2
  12. nuitka/TreeXML.py +1 -1
  13. nuitka/Version.py +1 -1
  14. nuitka/build/Backend.scons +2 -1
  15. nuitka/build/DataComposerInterface.py +1 -0
  16. nuitka/build/Onefile.scons +2 -1
  17. nuitka/build/SconsCaching.py +64 -46
  18. nuitka/build/SconsCompilerSettings.py +19 -6
  19. nuitka/build/SconsHacks.py +0 -1
  20. nuitka/build/SconsInterface.py +84 -5
  21. nuitka/build/SconsProgress.py +0 -1
  22. nuitka/build/SconsUtils.py +9 -5
  23. nuitka/build/include/nuitka/allocator.h +8 -3
  24. nuitka/build/include/nuitka/compiled_cell.h +8 -0
  25. nuitka/build/include/nuitka/constants.h +2 -0
  26. nuitka/build/include/nuitka/exceptions.h +554 -179
  27. nuitka/build/include/nuitka/helper/dictionaries.h +1 -1
  28. nuitka/build/include/nuitka/helper/import_hard.h +3 -0
  29. nuitka/build/include/nuitka/helper/ints.h +15 -2
  30. nuitka/build/include/nuitka/helper/lists.h +4 -1
  31. nuitka/build/include/nuitka/helper/raising.h +12 -0
  32. nuitka/build/include/nuitka/helper/tuples.h +5 -1
  33. nuitka/build/include/nuitka/helpers.h +5 -0
  34. nuitka/build/include/nuitka/importing.h +3 -4
  35. nuitka/build/include/nuitka/jit_sources.h +25 -0
  36. nuitka/build/include/nuitka/prelude.h +38 -11
  37. nuitka/build/include/nuitka/printing.h +3 -0
  38. nuitka/build/include/nuitka/threading.h +2 -6
  39. nuitka/build/include/nuitka/type_aliases.h +27 -0
  40. nuitka/build/inline_copy/pkg_resources/pkg_resources/__init__.py +0 -3
  41. nuitka/build/inline_copy/tqdm/tqdm/version.py +1 -4
  42. nuitka/build/static_src/CompiledAsyncgenType.c +99 -114
  43. nuitka/build/static_src/CompiledCodeHelpers.c +24 -14
  44. nuitka/build/static_src/CompiledCoroutineType.c +96 -114
  45. nuitka/build/static_src/CompiledFrameType.c +14 -11
  46. nuitka/build/static_src/CompiledFunctionType.c +34 -7
  47. nuitka/build/static_src/CompiledGeneratorType.c +248 -142
  48. nuitka/build/static_src/CompiledGeneratorTypeUncompiledIntegration.c +60 -70
  49. nuitka/build/static_src/CompiledMethodType.c +8 -7
  50. nuitka/build/static_src/HelpersAttributes.c +2 -19
  51. nuitka/build/static_src/HelpersBuiltin.c +2 -1
  52. nuitka/build/static_src/HelpersComparisonEq.c +32 -18
  53. nuitka/build/static_src/HelpersComparisonGe.c +50 -36
  54. nuitka/build/static_src/HelpersComparisonGt.c +50 -36
  55. nuitka/build/static_src/HelpersComparisonLe.c +50 -36
  56. nuitka/build/static_src/HelpersComparisonLt.c +50 -36
  57. nuitka/build/static_src/HelpersComparisonNe.c +32 -18
  58. nuitka/build/static_src/HelpersDeepcopy.c +6 -8
  59. nuitka/build/static_src/HelpersDictionaries.c +8 -3
  60. nuitka/build/static_src/HelpersExceptions.c +36 -22
  61. nuitka/build/static_src/HelpersFiles.c +9 -0
  62. nuitka/build/static_src/HelpersFilesystemPaths.c +7 -7
  63. nuitka/build/static_src/HelpersImportHard.c +15 -0
  64. nuitka/build/static_src/HelpersJitSources.c +46 -0
  65. nuitka/build/static_src/HelpersLists.c +40 -0
  66. nuitka/build/static_src/HelpersOperationBinaryAdd.c +66 -66
  67. nuitka/build/static_src/HelpersOperationBinaryAddUtils.c +80 -33
  68. nuitka/build/static_src/HelpersOperationBinaryMultUtils.c +16 -13
  69. nuitka/build/static_src/HelpersOperationBinarySub.c +39 -39
  70. nuitka/build/static_src/HelpersOperationInplaceAdd.c +54 -54
  71. nuitka/build/static_src/HelpersOperationInplaceAddUtils.c +1 -1
  72. nuitka/build/static_src/HelpersOperationInplaceSub.c +50 -50
  73. nuitka/build/static_src/HelpersProfiling.c +3 -4
  74. nuitka/build/static_src/HelpersRaising.c +62 -1
  75. nuitka/build/static_src/HelpersStrings.c +203 -8
  76. nuitka/build/static_src/HelpersTypes.c +42 -0
  77. nuitka/build/static_src/MainProgram.c +1 -1
  78. nuitka/build/static_src/MetaPathBasedLoader.c +2 -1
  79. nuitka/build/static_src/OnefileBootstrap.c +3 -3
  80. nuitka/code_generation/BinaryOperationHelperDefinitions.py +5 -3
  81. nuitka/code_generation/BuiltinCodes.py +1 -0
  82. nuitka/code_generation/CodeGeneration.py +11 -0
  83. nuitka/code_generation/CodeHelpers.py +5 -3
  84. nuitka/code_generation/CodeObjectCodes.py +10 -6
  85. nuitka/code_generation/ComparisonCodes.py +19 -3
  86. nuitka/code_generation/ConstantCodes.py +5 -0
  87. nuitka/code_generation/Contexts.py +22 -6
  88. nuitka/code_generation/Emission.py +1 -0
  89. nuitka/code_generation/ErrorCodes.py +8 -16
  90. nuitka/code_generation/EvalCodes.py +5 -3
  91. nuitka/code_generation/ExceptionCodes.py +8 -1
  92. nuitka/code_generation/ExpressionCTypeSelectionHelpers.py +1 -0
  93. nuitka/code_generation/FrameCodes.py +5 -3
  94. nuitka/code_generation/FunctionCodes.py +0 -1
  95. nuitka/code_generation/GeneratorCodes.py +3 -3
  96. nuitka/code_generation/GlobalConstants.py +1 -2
  97. nuitka/code_generation/ImportCodes.py +2 -0
  98. nuitka/code_generation/JitCodes.py +44 -0
  99. nuitka/code_generation/ListCodes.py +11 -17
  100. nuitka/code_generation/MatchCodes.py +0 -1
  101. nuitka/code_generation/ModuleCodes.py +2 -1
  102. nuitka/code_generation/Namify.py +0 -1
  103. nuitka/code_generation/NetworkxCodes.py +51 -0
  104. nuitka/code_generation/OperationCodes.py +8 -6
  105. nuitka/code_generation/PackageResourceCodes.py +7 -5
  106. nuitka/code_generation/TensorflowCodes.py +54 -0
  107. nuitka/code_generation/TypeAliasCodes.py +71 -0
  108. nuitka/code_generation/VariableCodes.py +7 -5
  109. nuitka/code_generation/VariableDeclarations.py +1 -0
  110. nuitka/code_generation/c_types/CTypeCLongs.py +0 -1
  111. nuitka/code_generation/c_types/CTypeNuitkaInts.py +0 -1
  112. nuitka/code_generation/c_types/CTypeVoids.py +1 -0
  113. nuitka/code_generation/templates/CodeTemplatesConstants.py +15 -0
  114. nuitka/code_generation/templates/CodeTemplatesExceptions.py +1 -1
  115. nuitka/code_generation/templates/CodeTemplatesIterators.py +0 -1
  116. nuitka/code_generation/templates/CodeTemplatesLoader.py +0 -1
  117. nuitka/code_generation/templates/CodeTemplatesModules.py +4 -1
  118. nuitka/code_generation/templates/CodeTemplatesVariables.py +8 -8
  119. nuitka/code_generation/templates/TemplateDebugWrapper.py +0 -1
  120. nuitka/code_generation/templates_c/HelperOperationComparisonUnicode.c.j2 +4 -0
  121. nuitka/code_generation/templates_c/HelperSlotsLong.c.j2 +9 -7
  122. nuitka/containers/Namedtuples.py +0 -1
  123. nuitka/finalizations/Finalization.py +1 -0
  124. nuitka/finalizations/FinalizeMarkups.py +0 -1
  125. nuitka/freezer/DllDependenciesMacOS.py +60 -13
  126. nuitka/freezer/DllDependenciesPosix.py +0 -1
  127. nuitka/freezer/IncludedDataFiles.py +46 -15
  128. nuitka/freezer/IncludedEntryPoints.py +5 -3
  129. nuitka/freezer/Standalone.py +6 -1
  130. nuitka/importing/ImportCache.py +2 -2
  131. nuitka/importing/ImportResolving.py +80 -78
  132. nuitka/importing/Importing.py +34 -1
  133. nuitka/nodes/AttributeNodesGenerated.py +21 -6
  134. nuitka/nodes/BuiltinComplexNodes.py +1 -0
  135. nuitka/nodes/BuiltinFormatNodes.py +1 -0
  136. nuitka/nodes/BuiltinIteratorNodes.py +5 -3
  137. nuitka/nodes/BuiltinOperationNodeBasesGenerated.py +21 -6
  138. nuitka/nodes/BuiltinRefNodes.py +8 -1
  139. nuitka/nodes/BuiltinVarsNodes.py +0 -1
  140. nuitka/nodes/ChildrenHavingMixins.py +906 -186
  141. nuitka/nodes/CodeObjectSpecs.py +1 -1
  142. nuitka/nodes/ConstantRefNodes.py +38 -0
  143. nuitka/nodes/CtypesNodes.py +0 -1
  144. nuitka/nodes/DictionaryNodes.py +0 -1
  145. nuitka/nodes/ExceptionNodes.py +10 -0
  146. nuitka/nodes/ExpressionBases.py +15 -9
  147. nuitka/nodes/ExpressionBasesGenerated.py +32 -15
  148. nuitka/nodes/FunctionNodes.py +50 -5
  149. nuitka/nodes/HardImportNodesGenerated.py +245 -60
  150. nuitka/nodes/ImportHardNodes.py +27 -13
  151. nuitka/nodes/ImportNodes.py +90 -70
  152. nuitka/nodes/InjectCNodes.py +0 -1
  153. nuitka/nodes/ModuleNodes.py +10 -5
  154. nuitka/nodes/NetworkxNodes.py +45 -0
  155. nuitka/nodes/OperatorNodesUnary.py +1 -0
  156. nuitka/nodes/OsSysNodes.py +0 -1
  157. nuitka/nodes/PackageMetadataNodes.py +0 -1
  158. nuitka/nodes/PackageResourceNodes.py +10 -6
  159. nuitka/nodes/StatementBasesGenerated.py +107 -60
  160. nuitka/nodes/StringConcatenationNodes.py +1 -0
  161. nuitka/nodes/TensorflowNodes.py +38 -0
  162. nuitka/nodes/TypeNodes.py +21 -0
  163. nuitka/nodes/VariableRefNodes.py +1 -0
  164. nuitka/nodes/shapes/BuiltinTypeShapes.py +25 -15
  165. nuitka/optimizations/Optimization.py +7 -6
  166. nuitka/optimizations/OptimizeBuiltinCalls.py +11 -9
  167. nuitka/optimizations/Tags.py +0 -1
  168. nuitka/optimizations/TraceCollections.py +6 -55
  169. nuitka/optimizations/ValueTraces.py +49 -1
  170. nuitka/plugins/PluginBase.py +26 -4
  171. nuitka/plugins/Plugins.py +49 -12
  172. nuitka/plugins/standard/AntiBloatPlugin.py +12 -2
  173. nuitka/plugins/standard/ConsiderPyLintAnnotationsPlugin.py +0 -1
  174. nuitka/plugins/standard/DataFilesPlugin.py +2 -6
  175. nuitka/plugins/standard/DillPlugin.py +3 -3
  176. nuitka/plugins/standard/DllFilesPlugin.py +29 -23
  177. nuitka/plugins/standard/GiPlugin.py +1 -0
  178. nuitka/plugins/standard/ImplicitImports.py +9 -7
  179. nuitka/plugins/standard/MatplotlibPlugin.py +1 -0
  180. nuitka/plugins/standard/OptionsNannyPlugin.py +3 -7
  181. nuitka/plugins/standard/PkgResourcesPlugin.py +0 -1
  182. nuitka/plugins/standard/PmwPlugin.py +10 -9
  183. nuitka/plugins/standard/PySidePyQtPlugin.py +0 -28
  184. nuitka/plugins/standard/TensorflowPlugin.py +1 -0
  185. nuitka/plugins/standard/TorchPlugin.py +1 -0
  186. nuitka/plugins/standard/TrioPlugin.py +1 -0
  187. nuitka/plugins/standard/standard.nuitka-package.config.yml +242 -54
  188. nuitka/reports/CompilationReportReader.py +0 -1
  189. nuitka/reports/Reports.py +49 -5
  190. nuitka/specs/BuiltinParameterSpecs.py +10 -2
  191. nuitka/specs/BuiltinStrOperationSpecs.py +1 -1
  192. nuitka/specs/BuiltinTypeOperationSpecs.py +0 -1
  193. nuitka/specs/HardImportSpecs.py +34 -1
  194. nuitka/specs/ParameterSpecs.py +11 -9
  195. nuitka/tools/environments/Virtualenv.py +0 -1
  196. nuitka/tools/specialize/CTypeDescriptions.py +15 -11
  197. nuitka/tools/specialize/SpecializeC.py +11 -9
  198. nuitka/tools/specialize/SpecializePython.py +57 -30
  199. nuitka/tools/testing/Common.py +24 -7
  200. nuitka/tools/testing/OutputComparison.py +4 -0
  201. nuitka/tools/testing/Pythons.py +0 -1
  202. nuitka/tools/testing/compare_with_cpython/__main__.py +0 -4
  203. nuitka/tools/watch/GitHub.py +4 -1
  204. nuitka/tools/watch/__main__.py +22 -1
  205. nuitka/tree/Building.py +3 -0
  206. nuitka/tree/InternalModule.py +0 -1
  207. nuitka/tree/ReformulationAssertStatements.py +1 -0
  208. nuitka/tree/ReformulationAssignmentStatements.py +26 -3
  209. nuitka/tree/ReformulationClasses3.py +23 -26
  210. nuitka/tree/ReformulationContractionExpressions.py +5 -3
  211. nuitka/tree/ReformulationDictionaryCreation.py +6 -5
  212. nuitka/tree/ReformulationExecStatements.py +8 -6
  213. nuitka/tree/ReformulationFunctionStatements.py +10 -6
  214. nuitka/tree/SourceHandling.py +8 -0
  215. nuitka/tree/TreeHelpers.py +6 -3
  216. nuitka/utils/AppDirs.py +6 -2
  217. nuitka/utils/CStrings.py +1 -1
  218. nuitka/utils/CommandLineOptions.py +0 -1
  219. nuitka/utils/Distributions.py +3 -3
  220. nuitka/utils/Download.py +5 -1
  221. nuitka/utils/Execution.py +6 -3
  222. nuitka/utils/FileOperations.py +62 -35
  223. nuitka/utils/Importing.py +4 -4
  224. nuitka/utils/InstanceCounters.py +1 -0
  225. nuitka/utils/MacOSApp.py +1 -0
  226. nuitka/utils/Shebang.py +1 -0
  227. nuitka/utils/Utils.py +39 -1
  228. nuitka/utils/WindowsFileUsage.py +4 -3
  229. {Nuitka_winsvc-2.1.5.data → Nuitka_winsvc-2.2.1.data}/scripts/nuitka-run.bat +0 -0
  230. {Nuitka_winsvc-2.1.5.data → Nuitka_winsvc-2.2.1.data}/scripts/nuitka.bat +0 -0
  231. {Nuitka_winsvc-2.1.5.dist-info → Nuitka_winsvc-2.2.1.dist-info}/LICENSE.txt +0 -0
  232. {Nuitka_winsvc-2.1.5.dist-info → Nuitka_winsvc-2.2.1.dist-info}/WHEEL +0 -0
  233. {Nuitka_winsvc-2.1.5.dist-info → Nuitka_winsvc-2.2.1.dist-info}/entry_points.txt +0 -0
  234. {Nuitka_winsvc-2.1.5.dist-info → Nuitka_winsvc-2.2.1.dist-info}/top_level.txt +0 -0
@@ -607,8 +607,8 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_LONG(PyObject **operand1, PyObjec
607
607
 
608
608
  PyLongObject *operand2_long_object = (PyLongObject *)operand2;
609
609
 
610
- if (Py_ABS(Py_SIZE(operand1_long_object)) <= 1 && Py_ABS(Py_SIZE(operand2_long_object)) <= 1) {
611
- long r = MEDIUM_VALUE(operand1_long_object) - MEDIUM_VALUE(operand2_long_object);
610
+ if (Nuitka_LongGetDigitSize(operand1_long_object) <= 1 && Nuitka_LongGetDigitSize(operand2_long_object) <= 1) {
611
+ long r = (long)(MEDIUM_VALUE(operand1_long_object) - MEDIUM_VALUE(operand2_long_object));
612
612
 
613
613
  if (Py_REFCNT(*operand1) == 1) {
614
614
  Nuitka_LongUpdateFromCLong(&*operand1, r);
@@ -624,18 +624,18 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_LONG(PyObject **operand1, PyObjec
624
624
  }
625
625
 
626
626
  if (Py_REFCNT(*operand1) == 1) {
627
- digit const *b_digits = operand2_long_object->ob_digit;
628
- Py_ssize_t b_digit_count = Py_ABS(Py_SIZE(operand2_long_object));
627
+ digit const *b_digits = Nuitka_LongGetDigitPointer(operand2_long_object);
628
+ Py_ssize_t b_digit_count = Nuitka_LongGetDigitSize(operand2_long_object);
629
629
 
630
- bool a_negative = Py_SIZE(operand1_long_object) < 0;
631
- bool b_negative = Py_SIZE(operand2_long_object) < 0;
630
+ bool a_negative = Nuitka_LongIsNegative(operand1_long_object);
631
+ bool b_negative = Nuitka_LongIsNegative(operand2_long_object);
632
632
 
633
633
  if (a_negative) {
634
634
  if (b_negative) {
635
635
  *operand1 = _Nuitka_LongSubInplaceDigits(*operand1, b_digits, b_digit_count, -1);
636
636
  } else {
637
637
  *operand1 = _Nuitka_LongAddInplaceDigits(*operand1, b_digits, b_digit_count);
638
- Py_SET_SIZE(*operand1, -Py_ABS(Py_SIZE(*operand1)));
638
+ Nuitka_LongSetSignNegative(*operand1);
639
639
  }
640
640
  } else {
641
641
  if (b_negative) {
@@ -650,12 +650,12 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_LONG(PyObject **operand1, PyObjec
650
650
  {
651
651
  PyLongObject *z;
652
652
 
653
- digit const *a_digits = operand1_long_object->ob_digit;
654
- Py_ssize_t a_digit_count = Py_ABS(Py_SIZE(operand1_long_object));
655
- bool a_negative = Py_SIZE(operand1_long_object) < 0;
656
- digit const *b_digits = operand2_long_object->ob_digit;
657
- Py_ssize_t b_digit_count = Py_ABS(Py_SIZE(operand2_long_object));
658
- bool b_negative = Py_SIZE(operand2_long_object) < 0;
653
+ digit const *a_digits = Nuitka_LongGetDigitPointer(operand1_long_object);
654
+ Py_ssize_t a_digit_count = Nuitka_LongGetDigitSize(operand1_long_object);
655
+ bool a_negative = Nuitka_LongIsNegative(operand1_long_object);
656
+ digit const *b_digits = Nuitka_LongGetDigitPointer(operand2_long_object);
657
+ Py_ssize_t b_digit_count = Nuitka_LongGetDigitSize(operand2_long_object);
658
+ bool b_negative = Nuitka_LongIsNegative(operand2_long_object);
659
659
 
660
660
  if (a_negative) {
661
661
  if (b_negative) {
@@ -664,7 +664,7 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_LONG(PyObject **operand1, PyObjec
664
664
  z = _Nuitka_LongAddDigits(a_digits, a_digit_count, b_digits, b_digit_count);
665
665
  }
666
666
 
667
- Py_SET_SIZE(z, -(Py_SIZE(z)));
667
+ Nuitka_LongFlipSign(z);
668
668
  } else {
669
669
  if (b_negative) {
670
670
  z = _Nuitka_LongAddDigits(a_digits, a_digit_count, b_digits, b_digit_count);
@@ -898,8 +898,8 @@ static inline bool _INPLACE_OPERATION_SUB_OBJECT_LONG(PyObject **operand1, PyObj
898
898
 
899
899
  PyLongObject *operand2_long_object = (PyLongObject *)operand2;
900
900
 
901
- if (Py_ABS(Py_SIZE(operand1_long_object)) <= 1 && Py_ABS(Py_SIZE(operand2_long_object)) <= 1) {
902
- long r = MEDIUM_VALUE(operand1_long_object) - MEDIUM_VALUE(operand2_long_object);
901
+ if (Nuitka_LongGetDigitSize(operand1_long_object) <= 1 && Nuitka_LongGetDigitSize(operand2_long_object) <= 1) {
902
+ long r = (long)(MEDIUM_VALUE(operand1_long_object) - MEDIUM_VALUE(operand2_long_object));
903
903
 
904
904
  if (Py_REFCNT(*operand1) == 1) {
905
905
  Nuitka_LongUpdateFromCLong(&*operand1, r);
@@ -915,18 +915,18 @@ static inline bool _INPLACE_OPERATION_SUB_OBJECT_LONG(PyObject **operand1, PyObj
915
915
  }
916
916
 
917
917
  if (Py_REFCNT(*operand1) == 1) {
918
- digit const *b_digits = operand2_long_object->ob_digit;
919
- Py_ssize_t b_digit_count = Py_ABS(Py_SIZE(operand2_long_object));
918
+ digit const *b_digits = Nuitka_LongGetDigitPointer(operand2_long_object);
919
+ Py_ssize_t b_digit_count = Nuitka_LongGetDigitSize(operand2_long_object);
920
920
 
921
- bool a_negative = Py_SIZE(operand1_long_object) < 0;
922
- bool b_negative = Py_SIZE(operand2_long_object) < 0;
921
+ bool a_negative = Nuitka_LongIsNegative(operand1_long_object);
922
+ bool b_negative = Nuitka_LongIsNegative(operand2_long_object);
923
923
 
924
924
  if (a_negative) {
925
925
  if (b_negative) {
926
926
  *operand1 = _Nuitka_LongSubInplaceDigits(*operand1, b_digits, b_digit_count, -1);
927
927
  } else {
928
928
  *operand1 = _Nuitka_LongAddInplaceDigits(*operand1, b_digits, b_digit_count);
929
- Py_SET_SIZE(*operand1, -Py_ABS(Py_SIZE(*operand1)));
929
+ Nuitka_LongSetSignNegative(*operand1);
930
930
  }
931
931
  } else {
932
932
  if (b_negative) {
@@ -941,12 +941,12 @@ static inline bool _INPLACE_OPERATION_SUB_OBJECT_LONG(PyObject **operand1, PyObj
941
941
  {
942
942
  PyLongObject *z;
943
943
 
944
- digit const *a_digits = operand1_long_object->ob_digit;
945
- Py_ssize_t a_digit_count = Py_ABS(Py_SIZE(operand1_long_object));
946
- bool a_negative = Py_SIZE(operand1_long_object) < 0;
947
- digit const *b_digits = operand2_long_object->ob_digit;
948
- Py_ssize_t b_digit_count = Py_ABS(Py_SIZE(operand2_long_object));
949
- bool b_negative = Py_SIZE(operand2_long_object) < 0;
944
+ digit const *a_digits = Nuitka_LongGetDigitPointer(operand1_long_object);
945
+ Py_ssize_t a_digit_count = Nuitka_LongGetDigitSize(operand1_long_object);
946
+ bool a_negative = Nuitka_LongIsNegative(operand1_long_object);
947
+ digit const *b_digits = Nuitka_LongGetDigitPointer(operand2_long_object);
948
+ Py_ssize_t b_digit_count = Nuitka_LongGetDigitSize(operand2_long_object);
949
+ bool b_negative = Nuitka_LongIsNegative(operand2_long_object);
950
950
 
951
951
  if (a_negative) {
952
952
  if (b_negative) {
@@ -955,7 +955,7 @@ static inline bool _INPLACE_OPERATION_SUB_OBJECT_LONG(PyObject **operand1, PyObj
955
955
  z = _Nuitka_LongAddDigits(a_digits, a_digit_count, b_digits, b_digit_count);
956
956
  }
957
957
 
958
- Py_SET_SIZE(z, -(Py_SIZE(z)));
958
+ Nuitka_LongFlipSign(z);
959
959
  } else {
960
960
  if (b_negative) {
961
961
  z = _Nuitka_LongAddDigits(a_digits, a_digit_count, b_digits, b_digit_count);
@@ -1194,8 +1194,8 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_OBJECT(PyObject **operand1, PyObj
1194
1194
 
1195
1195
  PyLongObject *operand2_long_object = (PyLongObject *)operand2;
1196
1196
 
1197
- if (Py_ABS(Py_SIZE(operand1_long_object)) <= 1 && Py_ABS(Py_SIZE(operand2_long_object)) <= 1) {
1198
- long r = MEDIUM_VALUE(operand1_long_object) - MEDIUM_VALUE(operand2_long_object);
1197
+ if (Nuitka_LongGetDigitSize(operand1_long_object) <= 1 && Nuitka_LongGetDigitSize(operand2_long_object) <= 1) {
1198
+ long r = (long)(MEDIUM_VALUE(operand1_long_object) - MEDIUM_VALUE(operand2_long_object));
1199
1199
 
1200
1200
  if (Py_REFCNT(*operand1) == 1) {
1201
1201
  Nuitka_LongUpdateFromCLong(&*operand1, r);
@@ -1211,18 +1211,18 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_OBJECT(PyObject **operand1, PyObj
1211
1211
  }
1212
1212
 
1213
1213
  if (Py_REFCNT(*operand1) == 1) {
1214
- digit const *b_digits = operand2_long_object->ob_digit;
1215
- Py_ssize_t b_digit_count = Py_ABS(Py_SIZE(operand2_long_object));
1214
+ digit const *b_digits = Nuitka_LongGetDigitPointer(operand2_long_object);
1215
+ Py_ssize_t b_digit_count = Nuitka_LongGetDigitSize(operand2_long_object);
1216
1216
 
1217
- bool a_negative = Py_SIZE(operand1_long_object) < 0;
1218
- bool b_negative = Py_SIZE(operand2_long_object) < 0;
1217
+ bool a_negative = Nuitka_LongIsNegative(operand1_long_object);
1218
+ bool b_negative = Nuitka_LongIsNegative(operand2_long_object);
1219
1219
 
1220
1220
  if (a_negative) {
1221
1221
  if (b_negative) {
1222
1222
  *operand1 = _Nuitka_LongSubInplaceDigits(*operand1, b_digits, b_digit_count, -1);
1223
1223
  } else {
1224
1224
  *operand1 = _Nuitka_LongAddInplaceDigits(*operand1, b_digits, b_digit_count);
1225
- Py_SET_SIZE(*operand1, -Py_ABS(Py_SIZE(*operand1)));
1225
+ Nuitka_LongSetSignNegative(*operand1);
1226
1226
  }
1227
1227
  } else {
1228
1228
  if (b_negative) {
@@ -1237,12 +1237,12 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_OBJECT(PyObject **operand1, PyObj
1237
1237
  {
1238
1238
  PyLongObject *z;
1239
1239
 
1240
- digit const *a_digits = operand1_long_object->ob_digit;
1241
- Py_ssize_t a_digit_count = Py_ABS(Py_SIZE(operand1_long_object));
1242
- bool a_negative = Py_SIZE(operand1_long_object) < 0;
1243
- digit const *b_digits = operand2_long_object->ob_digit;
1244
- Py_ssize_t b_digit_count = Py_ABS(Py_SIZE(operand2_long_object));
1245
- bool b_negative = Py_SIZE(operand2_long_object) < 0;
1240
+ digit const *a_digits = Nuitka_LongGetDigitPointer(operand1_long_object);
1241
+ Py_ssize_t a_digit_count = Nuitka_LongGetDigitSize(operand1_long_object);
1242
+ bool a_negative = Nuitka_LongIsNegative(operand1_long_object);
1243
+ digit const *b_digits = Nuitka_LongGetDigitPointer(operand2_long_object);
1244
+ Py_ssize_t b_digit_count = Nuitka_LongGetDigitSize(operand2_long_object);
1245
+ bool b_negative = Nuitka_LongIsNegative(operand2_long_object);
1246
1246
 
1247
1247
  if (a_negative) {
1248
1248
  if (b_negative) {
@@ -1251,7 +1251,7 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_OBJECT(PyObject **operand1, PyObj
1251
1251
  z = _Nuitka_LongAddDigits(a_digits, a_digit_count, b_digits, b_digit_count);
1252
1252
  }
1253
1253
 
1254
- Py_SET_SIZE(z, -(Py_SIZE(z)));
1254
+ Nuitka_LongFlipSign(z);
1255
1255
  } else {
1256
1256
  if (b_negative) {
1257
1257
  z = _Nuitka_LongAddDigits(a_digits, a_digit_count, b_digits, b_digit_count);
@@ -2308,8 +2308,8 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_DIGIT(PyObject **operand1, long o
2308
2308
 
2309
2309
  PyLongObject *operand1_long_object = (PyLongObject *)*operand1;
2310
2310
 
2311
- if (Py_ABS(Py_SIZE(operand1_long_object)) <= 1 && (operand2 == 0 ? 0 : 1) <= 1) {
2312
- long r = MEDIUM_VALUE(operand1_long_object) - (sdigit)operand2;
2311
+ if (Nuitka_LongGetDigitSize(operand1_long_object) <= 1 && (operand2 == 0 ? 0 : 1) <= 1) {
2312
+ long r = (long)(MEDIUM_VALUE(operand1_long_object) - (sdigit)operand2);
2313
2313
 
2314
2314
  if (Py_REFCNT(*operand1) == 1) {
2315
2315
  Nuitka_LongUpdateFromCLong(&*operand1, r);
@@ -2328,7 +2328,7 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_DIGIT(PyObject **operand1, long o
2328
2328
  digit const *b_digits = (digit *)&operand2;
2329
2329
  Py_ssize_t b_digit_count = (operand2 == 0 ? 0 : 1);
2330
2330
 
2331
- bool a_negative = Py_SIZE(operand1_long_object) < 0;
2331
+ bool a_negative = Nuitka_LongIsNegative(operand1_long_object);
2332
2332
  bool b_negative = operand2 < 0;
2333
2333
 
2334
2334
  if (a_negative) {
@@ -2336,7 +2336,7 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_DIGIT(PyObject **operand1, long o
2336
2336
  *operand1 = _Nuitka_LongSubInplaceDigits(*operand1, b_digits, b_digit_count, -1);
2337
2337
  } else {
2338
2338
  *operand1 = _Nuitka_LongAddInplaceDigits(*operand1, b_digits, b_digit_count);
2339
- Py_SET_SIZE(*operand1, -Py_ABS(Py_SIZE(*operand1)));
2339
+ Nuitka_LongSetSignNegative(*operand1);
2340
2340
  }
2341
2341
  } else {
2342
2342
  if (b_negative) {
@@ -2351,9 +2351,9 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_DIGIT(PyObject **operand1, long o
2351
2351
  {
2352
2352
  PyLongObject *z;
2353
2353
 
2354
- digit const *a_digits = operand1_long_object->ob_digit;
2355
- Py_ssize_t a_digit_count = Py_ABS(Py_SIZE(operand1_long_object));
2356
- bool a_negative = Py_SIZE(operand1_long_object) < 0;
2354
+ digit const *a_digits = Nuitka_LongGetDigitPointer(operand1_long_object);
2355
+ Py_ssize_t a_digit_count = Nuitka_LongGetDigitSize(operand1_long_object);
2356
+ bool a_negative = Nuitka_LongIsNegative(operand1_long_object);
2357
2357
  digit const *b_digits = (digit *)&operand2;
2358
2358
  Py_ssize_t b_digit_count = (operand2 == 0 ? 0 : 1);
2359
2359
  bool b_negative = operand2 < 0;
@@ -2365,7 +2365,7 @@ static inline bool _INPLACE_OPERATION_SUB_LONG_DIGIT(PyObject **operand1, long o
2365
2365
  z = _Nuitka_LongAddDigits(a_digits, a_digit_count, b_digits, b_digit_count);
2366
2366
  }
2367
2367
 
2368
- Py_SET_SIZE(z, -(Py_SIZE(z)));
2368
+ Nuitka_LongFlipSign(z);
2369
2369
  } else {
2370
2370
  if (b_negative) {
2371
2371
  z = _Nuitka_LongAddDigits(a_digits, a_digit_count, b_digits, b_digit_count);
@@ -63,9 +63,8 @@ void stopProfiling(void) {
63
63
  // Save the current exception, if any, we must preserve it.
64
64
  PyThreadState *tstate = PyThreadState_GET();
65
65
 
66
- PyObject *save_exception_type, *save_exception_value;
67
- PyTracebackObject *save_exception_tb;
68
- FETCH_ERROR_OCCURRED(tstate, &save_exception_type, &save_exception_value, &save_exception_tb);
66
+ struct Nuitka_ExceptionPreservationItem saved_exception_state;
67
+ FETCH_ERROR_OCCURRED_STATE(tstate, &saved_exception_state);
69
68
 
70
69
  PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, PyObject_GetAttrString(vmprof_module, "disable"));
71
70
 
@@ -84,7 +83,7 @@ void stopProfiling(void) {
84
83
 
85
84
  fclose(tempfile_times);
86
85
 
87
- RESTORE_ERROR_OCCURRED(tstate, save_exception_type, save_exception_value, save_exception_tb);
86
+ RESTORE_ERROR_OCCURRED_STATE(tstate, &saved_exception_state);
88
87
  }
89
88
 
90
89
  #endif
@@ -56,7 +56,10 @@ void RAISE_EXCEPTION_WITH_TYPE(PyThreadState *tstate, PyObject **exception_type,
56
56
  if (PyExceptionClass_Check(*exception_type)) {
57
57
  NORMALIZE_EXCEPTION(tstate, exception_type, exception_value, exception_tb);
58
58
  #if PYTHON_VERSION >= 0x270
59
+ // TODO: It seems NORMALIZE_EXCEPTION already does this?
59
60
  if (unlikely(!PyExceptionInstance_Check(*exception_value))) {
61
+ assert(false);
62
+
60
63
  PyObject *old_exception_type = *exception_type;
61
64
  PyObject *old_exception_value = *exception_value;
62
65
 
@@ -122,7 +125,12 @@ void RAISE_EXCEPTION_WITH_CAUSE(PyThreadState *tstate, PyObject **exception_type
122
125
  Py_DECREF(*exception_type);
123
126
  Py_XDECREF(*exception_tb);
124
127
 
125
- FETCH_ERROR_OCCURRED(tstate, exception_type, exception_value, exception_tb);
128
+ struct Nuitka_ExceptionPreservationItem exception_state;
129
+ FETCH_ERROR_OCCURRED_STATE(tstate, &exception_state);
130
+
131
+ ASSIGN_ARGS_FROM_EXCEPTION_PRESERVATION_STATE(&exception_state, exception_type, exception_value,
132
+ exception_tb);
133
+ RELEASE_ERROR_OCCURRED_STATE(&exception_state);
126
134
 
127
135
  return;
128
136
  }
@@ -420,6 +428,59 @@ bool RERAISE_EXCEPTION(PyObject **exception_type, PyObject **exception_value, Py
420
428
  return true;
421
429
  }
422
430
 
431
+ // 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) {
434
+ PyObject *exception_value_str =
435
+ Nuitka_String_FromFormat("name '%s' is not defined", Nuitka_String_AsString_Unchecked(variable_name));
436
+
437
+ *exception_value = MAKE_EXCEPTION_FROM_TYPE_ARG0(tstate, PyExc_NameError, exception_value_str);
438
+ Py_DECREF(exception_value_str);
439
+
440
+ *exception_type = PyExc_NameError;
441
+ Py_INCREF(PyExc_NameError);
442
+
443
+ #if PYTHON_VERSION >= 0x300
444
+ CHAIN_EXCEPTION(tstate, *exception_value);
445
+ #endif
446
+ }
447
+
448
+ #if PYTHON_VERSION < 0x340
449
+ void RAISE_CURRENT_EXCEPTION_GLOBAL_NAME_ERROR(PyThreadState *tstate, PyObject *variable_name,
450
+ PyObject **exception_type, PyObject **exception_value) {
451
+ PyObject *exception_value_str =
452
+ Nuitka_String_FromFormat("global name '%s' is not defined", Nuitka_String_AsString_Unchecked(variable_name));
453
+
454
+ *exception_value = MAKE_EXCEPTION_FROM_TYPE_ARG0(tstate, PyExc_NameError, exception_value_str);
455
+ Py_DECREF(exception_value_str);
456
+
457
+ *exception_type = PyExc_NameError;
458
+ Py_INCREF(PyExc_NameError);
459
+ }
460
+ #endif
461
+
462
+ #if PYTHON_VERSION >= 0x300
463
+
464
+ void RAISE_EXCEPTION_WITH_CAUSE_STATE(PyThreadState *tstate, struct Nuitka_ExceptionPreservationItem *exception_state,
465
+ PyObject *exception_cause) {
466
+ #if PYTHON_VERSION < 0x3c0
467
+ RAISE_EXCEPTION_WITH_CAUSE(tstate, &exception_state->exception_type, &exception_state->exception_value,
468
+ &exception_state->exception_tb, exception_cause);
469
+ #else
470
+ PyObject *exception_type = (PyObject *)PyExceptionInstance_Class(exception_state->exception_value);
471
+ Py_INCREF(exception_type);
472
+ PyTracebackObject *exception_tb = NULL;
473
+
474
+ // Python3.12: We are being a bit lazy there, by preparing the 3 things when
475
+ // we shouldn't really need them.
476
+ RAISE_EXCEPTION_WITH_CAUSE(tstate, &exception_type, &exception_state->exception_value, &exception_tb,
477
+ exception_cause);
478
+
479
+ Py_DECREF(exception_type);
480
+ #endif
481
+ }
482
+ #endif
483
+
423
484
  // Part of "Nuitka", an optimizing Python compiler that is compatible and
424
485
  // integrates with CPython, but also works on its own.
425
486
  //
@@ -140,8 +140,10 @@ PyObject *BUILTIN_ORD(PyObject *value) {
140
140
  #define _PyUnicode_KIND(op) (((PyASCIIObject *)(op))->state.kind)
141
141
  #define _PyUnicode_DATA_ANY(op) (((PyUnicodeObject *)(op))->data.any)
142
142
 
143
+ #if PYTHON_VERSION < 0x3c0
143
144
  #undef PyUnicode_READY
144
145
  #define PyUnicode_READY(op) ((PyUnicode_IS_READY(op) ? 0 : _PyUnicode_Ready(op)))
146
+ #endif
145
147
 
146
148
  #define _PyUnicode_SHARE_UTF8(op) (assert(!PyUnicode_IS_COMPACT_ASCII(op)), (_PyUnicode_UTF8(op) == PyUnicode_DATA(op)))
147
149
  #define _PyUnicode_SHARE_WSTR(op) ((_PyUnicode_WSTR(unicode) == PyUnicode_DATA(op)))
@@ -232,6 +234,7 @@ static int _NuitkaUnicode_modifiable(PyObject *unicode) {
232
234
  return 1;
233
235
  }
234
236
 
237
+ #if PYTHON_VERSION < 0x3c0
235
238
  static PyObject *_NuitkaUnicode_New(Py_ssize_t length) {
236
239
  assert(length != 0);
237
240
 
@@ -294,6 +297,24 @@ static PyObject *_NuitkaUnicode_resize_copy(PyObject *unicode, Py_ssize_t length
294
297
  }
295
298
  }
296
299
 
300
+ #else
301
+
302
+ static PyObject *_NuitkaUnicode_resize_copy(PyObject *unicode, Py_ssize_t length) {
303
+ // TODO: We should inline this one as well, it's doable and would save a bunch
304
+ // for the copying case as well.
305
+ PyObject *copy = PyUnicode_New(length, PyUnicode_MAX_CHAR_VALUE(unicode));
306
+
307
+ if (unlikely(copy == NULL)) {
308
+ return NULL;
309
+ }
310
+
311
+ Py_ssize_t copy_length = Py_MIN(length, PyUnicode_GET_LENGTH(unicode));
312
+ _NuitkaUnicode_FastCopyCharacters(copy, 0, unicode, 0, copy_length);
313
+ return copy;
314
+ }
315
+
316
+ #endif
317
+
297
318
  // We use older form code, make some backward compatible defines available.
298
319
  #if PYTHON_VERSION >= 0x390
299
320
 
@@ -311,6 +332,7 @@ static PyObject *_NuitkaUnicode_resize_copy(PyObject *unicode, Py_ssize_t length
311
332
 
312
333
  #endif
313
334
 
335
+ #if PYTHON_VERSION < 0x3c0
314
336
  static PyObject *_NuitkaUnicode_resize_compact(PyObject *unicode, Py_ssize_t length) {
315
337
  assert(PyUnicode_IS_COMPACT(unicode));
316
338
 
@@ -325,7 +347,7 @@ static PyObject *_NuitkaUnicode_resize_compact(PyObject *unicode, Py_ssize_t len
325
347
 
326
348
  int share_wstr = _PyUnicode_SHARE_WSTR(unicode);
327
349
 
328
- if (length > ((PY_SSIZE_T_MAX - struct_size) / char_size - 1)) {
350
+ if (unlikely(length > ((PY_SSIZE_T_MAX - struct_size) / char_size - 1))) {
329
351
  PyErr_NoMemory();
330
352
  return NULL;
331
353
  }
@@ -336,6 +358,7 @@ static PyObject *_NuitkaUnicode_resize_compact(PyObject *unicode, Py_ssize_t len
336
358
  _PyUnicode_UTF8(unicode) = NULL;
337
359
  _PyUnicode_UTF8_LENGTH(unicode) = 0;
338
360
  }
361
+
339
362
  _Py_DEC_REFTOTAL;
340
363
  _Py_ForgetReference(unicode);
341
364
 
@@ -346,10 +369,12 @@ static PyObject *_NuitkaUnicode_resize_compact(PyObject *unicode, Py_ssize_t len
346
369
  PyErr_NoMemory();
347
370
  return NULL;
348
371
  }
372
+
349
373
  unicode = new_unicode;
350
374
  Nuitka_Py_NewReference(unicode);
351
375
 
352
376
  _PyUnicode_LENGTH(unicode) = length;
377
+
353
378
  if (share_wstr) {
354
379
  _PyUnicode_WSTR(unicode) = (wchar_t *)PyUnicode_DATA(unicode);
355
380
  if (!PyUnicode_IS_ASCII(unicode)) {
@@ -378,10 +403,11 @@ static int _NuitkaUnicode_resize_inplace(PyObject *unicode, Py_ssize_t length) {
378
403
  int share_wstr = _PyUnicode_SHARE_WSTR(unicode);
379
404
  int share_utf8 = _PyUnicode_SHARE_UTF8(unicode);
380
405
 
381
- if (length > (PY_SSIZE_T_MAX / char_size - 1)) {
406
+ if (unlikely(length > (PY_SSIZE_T_MAX / char_size - 1))) {
382
407
  PyErr_NoMemory();
383
408
  return -1;
384
409
  }
410
+
385
411
  Py_ssize_t new_size = (length + 1) * char_size;
386
412
 
387
413
  if (!share_utf8 && _PyUnicode_HAS_UTF8_MEMORY(unicode)) {
@@ -395,6 +421,7 @@ static int _NuitkaUnicode_resize_inplace(PyObject *unicode, Py_ssize_t length) {
395
421
  PyErr_NoMemory();
396
422
  return -1;
397
423
  }
424
+
398
425
  _PyUnicode_DATA_ANY(unicode) = data;
399
426
  if (share_wstr) {
400
427
  _PyUnicode_WSTR(unicode) = (wchar_t *)data;
@@ -433,15 +460,17 @@ static int _NuitkaUnicode_resize_inplace(PyObject *unicode, Py_ssize_t length) {
433
460
  }
434
461
 
435
462
  static int _NuitkaUnicode_resize(PyObject **p_unicode, Py_ssize_t length) {
463
+ assert(p_unicode != NULL);
464
+ assert(*p_unicode != NULL);
465
+ assert(0 <= length);
466
+
436
467
  PyObject *unicode = *p_unicode;
468
+ assert(PyUnicode_Check(unicode));
437
469
  Py_ssize_t old_length;
438
470
 
439
- #if PYTHON_VERSION < 0x3c0
440
471
  if (_PyUnicode_KIND(unicode) == PyUnicode_WCHAR_KIND) {
441
472
  old_length = PyUnicode_WSTR_LENGTH(unicode);
442
- } else
443
- #endif
444
- {
473
+ } else {
445
474
  old_length = PyUnicode_GET_LENGTH(unicode);
446
475
  }
447
476
 
@@ -457,23 +486,189 @@ static int _NuitkaUnicode_resize(PyObject **p_unicode, Py_ssize_t length) {
457
486
 
458
487
  if (!_NuitkaUnicode_modifiable(unicode)) {
459
488
  PyObject *copy = _NuitkaUnicode_resize_copy(unicode, length);
460
- if (copy == NULL)
489
+ if (unlikely(copy == NULL)) {
461
490
  return -1;
491
+ }
462
492
  Py_DECREF(*p_unicode);
463
493
  *p_unicode = copy;
494
+
464
495
  return 0;
465
496
  }
466
497
 
467
498
  if (PyUnicode_IS_COMPACT(unicode)) {
468
499
  PyObject *new_unicode = _NuitkaUnicode_resize_compact(unicode, length);
469
- if (new_unicode == NULL)
500
+
501
+ if (unlikely(new_unicode == NULL)) {
470
502
  return -1;
503
+ }
504
+
471
505
  *p_unicode = new_unicode;
472
506
  return 0;
473
507
  }
474
508
 
475
509
  return _NuitkaUnicode_resize_inplace(unicode, length);
476
510
  }
511
+ #else
512
+
513
+ #ifndef __NUITKA_NO_ASSERT__
514
+ static void _Nuitka_unicode_fill_invalid(PyObject *unicode, Py_ssize_t old_length) {
515
+ int kind = PyUnicode_KIND(unicode);
516
+ Py_UCS1 *data = PyUnicode_1BYTE_DATA(unicode);
517
+ Py_ssize_t length = _PyUnicode_LENGTH(unicode);
518
+ if (length <= old_length)
519
+ return;
520
+ memset(data + old_length * kind, 0xff, (length - old_length) * kind);
521
+ }
522
+ #endif
523
+
524
+ static PyObject *_NuitkaUnicode_resize_compact(PyObject *unicode, Py_ssize_t length) {
525
+ assert(PyUnicode_IS_COMPACT(unicode));
526
+
527
+ Py_ssize_t char_size = PyUnicode_KIND(unicode);
528
+ Py_ssize_t struct_size;
529
+
530
+ if (PyUnicode_IS_ASCII(unicode)) {
531
+ struct_size = sizeof(PyASCIIObject);
532
+ } else {
533
+ struct_size = sizeof(PyCompactUnicodeObject);
534
+ }
535
+
536
+ #ifndef __NUITKA_NO_ASSERT__
537
+ Py_ssize_t old_length = _PyUnicode_LENGTH(unicode);
538
+ #endif
539
+
540
+ // assert(_Nuitka_unicode_modifiable(unicode));
541
+
542
+ if (unlikely(length > ((PY_SSIZE_T_MAX - struct_size) / char_size - 1))) {
543
+ PyErr_NoMemory();
544
+ return NULL;
545
+ }
546
+ Py_ssize_t new_size = (struct_size + (length + 1) * char_size);
547
+
548
+ if (_PyUnicode_HAS_UTF8_MEMORY(unicode)) {
549
+ PyObject_DEL(_PyUnicode_UTF8(unicode));
550
+ _PyUnicode_UTF8(unicode) = NULL;
551
+ _PyUnicode_UTF8_LENGTH(unicode) = 0;
552
+ }
553
+ _Py_ForgetReference(unicode);
554
+
555
+ PyObject *new_unicode = (PyObject *)PyObject_Realloc(unicode, new_size);
556
+ if (unlikely(new_unicode == NULL)) {
557
+ Nuitka_Py_NewReferenceNoTotal(unicode);
558
+
559
+ PyErr_NoMemory();
560
+ return NULL;
561
+ }
562
+
563
+ unicode = new_unicode;
564
+ Nuitka_Py_NewReferenceNoTotal(unicode);
565
+
566
+ _PyUnicode_LENGTH(unicode) = length;
567
+
568
+ #ifndef __NUITKA_NO_ASSERT__
569
+ _Nuitka_unicode_fill_invalid(unicode, old_length);
570
+ #endif
571
+
572
+ PyUnicode_WRITE(PyUnicode_KIND(unicode), PyUnicode_DATA(unicode), length, 0);
573
+ assert(_PyUnicode_CheckConsistency(unicode, 0));
574
+
575
+ return unicode;
576
+ }
577
+
578
+ static int _NuitkaUnicode_resize_inplace(PyObject *unicode, Py_ssize_t length) {
579
+ assert(!PyUnicode_IS_COMPACT(unicode));
580
+ assert(Py_REFCNT(unicode) == 1);
581
+
582
+ #ifndef __NUITKA_NO_ASSERT__
583
+ Py_ssize_t old_length = _PyUnicode_LENGTH(unicode);
584
+ #endif
585
+
586
+ void *data = _PyUnicode_DATA_ANY(unicode);
587
+ Py_ssize_t char_size = PyUnicode_KIND(unicode);
588
+ int share_utf8 = _PyUnicode_SHARE_UTF8(unicode);
589
+
590
+ if (unlikely(length > (PY_SSIZE_T_MAX / char_size - 1))) {
591
+ PyErr_NoMemory();
592
+ return -1;
593
+ }
594
+
595
+ Py_ssize_t new_size = (length + 1) * char_size;
596
+
597
+ if (!share_utf8 && _PyUnicode_HAS_UTF8_MEMORY(unicode)) {
598
+ PyObject_DEL(_PyUnicode_UTF8(unicode));
599
+ _PyUnicode_UTF8(unicode) = NULL;
600
+ _PyUnicode_UTF8_LENGTH(unicode) = 0;
601
+ }
602
+
603
+ data = (PyObject *)PyObject_REALLOC(data, new_size);
604
+ if (data == NULL) {
605
+ PyErr_NoMemory();
606
+ return -1;
607
+ }
608
+
609
+ _PyUnicode_DATA_ANY(unicode) = data;
610
+ if (share_utf8) {
611
+ _PyUnicode_UTF8(unicode) = data;
612
+ _PyUnicode_UTF8_LENGTH(unicode) = length;
613
+ }
614
+ _PyUnicode_LENGTH(unicode) = length;
615
+ PyUnicode_WRITE(PyUnicode_KIND(unicode), data, length, 0);
616
+ #ifndef __NUITKA_NO_ASSERT__
617
+ _Nuitka_unicode_fill_invalid(unicode, old_length);
618
+ #endif
619
+
620
+ /* check for integer overflow */
621
+ if (length > PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(wchar_t) - 1) {
622
+ PyErr_NoMemory();
623
+ return -1;
624
+ }
625
+ assert(_PyUnicode_CheckConsistency(unicode, 0));
626
+ return 0;
627
+ }
628
+
629
+ static int _NuitkaUnicode_resize(PyObject **p_unicode, Py_ssize_t length) {
630
+ assert(p_unicode != NULL);
631
+ assert(*p_unicode != NULL);
632
+ assert(0 <= length);
633
+
634
+ PyObject *unicode = *p_unicode;
635
+ assert(PyUnicode_Check(unicode));
636
+ Py_ssize_t old_length;
637
+
638
+ old_length = PyUnicode_GET_LENGTH(unicode);
639
+ if (old_length == length) {
640
+ return 0;
641
+ }
642
+
643
+ if (length == 0) {
644
+ Py_SETREF(*p_unicode, const_str_empty);
645
+ return 0;
646
+ }
647
+
648
+ if (!_NuitkaUnicode_modifiable(unicode)) {
649
+ PyObject *copy = _NuitkaUnicode_resize_copy(unicode, length);
650
+ if (unlikely(copy == NULL)) {
651
+ return -1;
652
+ }
653
+ Py_SETREF(*p_unicode, copy);
654
+
655
+ return 0;
656
+ }
657
+
658
+ if (PyUnicode_IS_COMPACT(unicode)) {
659
+ PyObject *new_unicode = _NuitkaUnicode_resize_compact(unicode, length);
660
+
661
+ if (unlikely(new_unicode == NULL)) {
662
+ return -1;
663
+ }
664
+
665
+ *p_unicode = new_unicode;
666
+ return 0;
667
+ }
668
+
669
+ return _NuitkaUnicode_resize_inplace(unicode, length);
670
+ }
671
+ #endif
477
672
 
478
673
  PyObject *UNICODE_CONCAT(PyThreadState *tstate, PyObject *left, PyObject *right) {
479
674
  if (left == const_str_empty) {