Cython 3.3.0__cp315-cp315-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. Cython/Build/BuildExecutable.py +156 -0
  2. Cython/Build/Cache.py +199 -0
  3. Cython/Build/Cythonize.py +349 -0
  4. Cython/Build/Dependencies.py +1281 -0
  5. Cython/Build/Distutils.py +1 -0
  6. Cython/Build/Inline.py +467 -0
  7. Cython/Build/IpythonMagic.py +559 -0
  8. Cython/Build/SharedModule.py +165 -0
  9. Cython/Build/Tests/TestCyCache.py +195 -0
  10. Cython/Build/Tests/TestCythonizeArgsParser.py +480 -0
  11. Cython/Build/Tests/TestDependencies.py +133 -0
  12. Cython/Build/Tests/TestInline.py +177 -0
  13. Cython/Build/Tests/TestIpythonMagic.py +303 -0
  14. Cython/Build/Tests/TestRecythonize.py +212 -0
  15. Cython/Build/Tests/TestStripLiterals.py +155 -0
  16. Cython/Build/Tests/__init__.py +1 -0
  17. Cython/Build/__init__.py +11 -0
  18. Cython/CodeWriter.py +825 -0
  19. Cython/Compiler/AnalysedTreeTransforms.py +97 -0
  20. Cython/Compiler/Annotate.py +328 -0
  21. Cython/Compiler/AutoDocTransforms.py +320 -0
  22. Cython/Compiler/Buffer.py +679 -0
  23. Cython/Compiler/Builtin.py +1102 -0
  24. Cython/Compiler/CmdLine.py +373 -0
  25. Cython/Compiler/Code.cp315-win_amd64.pyd +0 -0
  26. Cython/Compiler/Code.pxd +154 -0
  27. Cython/Compiler/Code.py +3760 -0
  28. Cython/Compiler/CodeGeneration.py +33 -0
  29. Cython/Compiler/CythonScope.py +208 -0
  30. Cython/Compiler/Dataclass.py +890 -0
  31. Cython/Compiler/DebugFlags.py +24 -0
  32. Cython/Compiler/Errors.py +310 -0
  33. Cython/Compiler/ExprNodes.py +16273 -0
  34. Cython/Compiler/FlowControl.cp315-win_amd64.pyd +0 -0
  35. Cython/Compiler/FlowControl.pxd +112 -0
  36. Cython/Compiler/FlowControl.py +1573 -0
  37. Cython/Compiler/FusedNode.cp315-win_amd64.pyd +0 -0
  38. Cython/Compiler/FusedNode.py +978 -0
  39. Cython/Compiler/Future.py +16 -0
  40. Cython/Compiler/Interpreter.py +57 -0
  41. Cython/Compiler/Lexicon.py +422 -0
  42. Cython/Compiler/LineTable.cp315-win_amd64.pyd +0 -0
  43. Cython/Compiler/LineTable.py +114 -0
  44. Cython/Compiler/Main.py +856 -0
  45. Cython/Compiler/MatchCaseNodes.py +2200 -0
  46. Cython/Compiler/MemoryView.py +930 -0
  47. Cython/Compiler/ModuleNode.py +4548 -0
  48. Cython/Compiler/Naming.py +370 -0
  49. Cython/Compiler/Nodes.py +11304 -0
  50. Cython/Compiler/Optimize.py +5564 -0
  51. Cython/Compiler/Options.py +840 -0
  52. Cython/Compiler/ParseTreeTransforms.pxd +80 -0
  53. Cython/Compiler/ParseTreeTransforms.py +4808 -0
  54. Cython/Compiler/Parsing.cp315-win_amd64.pyd +0 -0
  55. Cython/Compiler/Parsing.pxd +9 -0
  56. Cython/Compiler/Parsing.py +4809 -0
  57. Cython/Compiler/Pipeline.py +439 -0
  58. Cython/Compiler/PyrexTypes.py +6588 -0
  59. Cython/Compiler/Pythran.py +232 -0
  60. Cython/Compiler/Scanning.cp315-win_amd64.pyd +0 -0
  61. Cython/Compiler/Scanning.pxd +70 -0
  62. Cython/Compiler/Scanning.py +720 -0
  63. Cython/Compiler/StringEncoding.cp315-win_amd64.pyd +0 -0
  64. Cython/Compiler/StringEncoding.py +354 -0
  65. Cython/Compiler/Symtab.py +3121 -0
  66. Cython/Compiler/Tests/TestBuffer.py +105 -0
  67. Cython/Compiler/Tests/TestBuiltin.py +196 -0
  68. Cython/Compiler/Tests/TestCmdLine.py +652 -0
  69. Cython/Compiler/Tests/TestCode.py +145 -0
  70. Cython/Compiler/Tests/TestFlowControl.py +65 -0
  71. Cython/Compiler/Tests/TestGrammar.py +202 -0
  72. Cython/Compiler/Tests/TestMemView.py +71 -0
  73. Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
  74. Cython/Compiler/Tests/TestScanning.py +132 -0
  75. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  76. Cython/Compiler/Tests/TestStringEncoding.py +20 -0
  77. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  78. Cython/Compiler/Tests/TestTreePath.py +103 -0
  79. Cython/Compiler/Tests/TestTypes.py +119 -0
  80. Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
  81. Cython/Compiler/Tests/TestVisitor.py +119 -0
  82. Cython/Compiler/Tests/Utils.py +36 -0
  83. Cython/Compiler/Tests/__init__.py +1 -0
  84. Cython/Compiler/TreeFragment.py +279 -0
  85. Cython/Compiler/TreePath.py +303 -0
  86. Cython/Compiler/TypeInference.py +611 -0
  87. Cython/Compiler/TypeSlots.py +1329 -0
  88. Cython/Compiler/UFuncs.py +317 -0
  89. Cython/Compiler/UtilNodes.py +389 -0
  90. Cython/Compiler/UtilityCode.py +354 -0
  91. Cython/Compiler/Version.py +8 -0
  92. Cython/Compiler/Visitor.cp315-win_amd64.pyd +0 -0
  93. Cython/Compiler/Visitor.pxd +52 -0
  94. Cython/Compiler/Visitor.py +914 -0
  95. Cython/Compiler/__init__.py +1 -0
  96. Cython/Coverage.py +448 -0
  97. Cython/Debugger/Cygdb.py +214 -0
  98. Cython/Debugger/DebugWriter.py +82 -0
  99. Cython/Debugger/Tests/TestLibCython.py +280 -0
  100. Cython/Debugger/Tests/__init__.py +1 -0
  101. Cython/Debugger/Tests/cfuncs.c +8 -0
  102. Cython/Debugger/Tests/codefile +49 -0
  103. Cython/Debugger/Tests/test_libcython_in_gdb.py +580 -0
  104. Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
  105. Cython/Debugger/__init__.py +1 -0
  106. Cython/Debugger/libcython.py +1548 -0
  107. Cython/Debugger/libpython.py +2821 -0
  108. Cython/Debugging.py +20 -0
  109. Cython/Distutils/__init__.py +2 -0
  110. Cython/Distutils/build_ext.py +143 -0
  111. Cython/Distutils/extension.py +96 -0
  112. Cython/Distutils/old_build_ext.py +351 -0
  113. Cython/Includes/cpython/__init__.pxd +173 -0
  114. Cython/Includes/cpython/array.pxd +152 -0
  115. Cython/Includes/cpython/bool.pxd +37 -0
  116. Cython/Includes/cpython/buffer.pxd +112 -0
  117. Cython/Includes/cpython/bytearray.pxd +33 -0
  118. Cython/Includes/cpython/bytes.pxd +200 -0
  119. Cython/Includes/cpython/cellobject.pxd +35 -0
  120. Cython/Includes/cpython/ceval.pxd +8 -0
  121. Cython/Includes/cpython/codecs.pxd +121 -0
  122. Cython/Includes/cpython/complex.pxd +60 -0
  123. Cython/Includes/cpython/contextvars.pxd +145 -0
  124. Cython/Includes/cpython/conversion.pxd +36 -0
  125. Cython/Includes/cpython/datetime.pxd +395 -0
  126. Cython/Includes/cpython/descr.pxd +26 -0
  127. Cython/Includes/cpython/dict.pxd +268 -0
  128. Cython/Includes/cpython/exc.pxd +263 -0
  129. Cython/Includes/cpython/fileobject.pxd +57 -0
  130. Cython/Includes/cpython/float.pxd +56 -0
  131. Cython/Includes/cpython/frozendict.pxd +37 -0
  132. Cython/Includes/cpython/function.pxd +65 -0
  133. Cython/Includes/cpython/genobject.pxd +25 -0
  134. Cython/Includes/cpython/getargs.pxd +12 -0
  135. Cython/Includes/cpython/instance.pxd +25 -0
  136. Cython/Includes/cpython/iterator.pxd +36 -0
  137. Cython/Includes/cpython/iterobject.pxd +24 -0
  138. Cython/Includes/cpython/list.pxd +144 -0
  139. Cython/Includes/cpython/long.pxd +180 -0
  140. Cython/Includes/cpython/longintrepr.pxd +14 -0
  141. Cython/Includes/cpython/mapping.pxd +63 -0
  142. Cython/Includes/cpython/marshal.pxd +66 -0
  143. Cython/Includes/cpython/mem.pxd +120 -0
  144. Cython/Includes/cpython/memoryview.pxd +50 -0
  145. Cython/Includes/cpython/method.pxd +49 -0
  146. Cython/Includes/cpython/module.pxd +208 -0
  147. Cython/Includes/cpython/number.pxd +258 -0
  148. Cython/Includes/cpython/object.pxd +430 -0
  149. Cython/Includes/cpython/pycapsule.pxd +143 -0
  150. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  151. Cython/Includes/cpython/pyport.pxd +8 -0
  152. Cython/Includes/cpython/pystate.pxd +95 -0
  153. Cython/Includes/cpython/pythread.pxd +53 -0
  154. Cython/Includes/cpython/ref.pxd +141 -0
  155. Cython/Includes/cpython/sentinel.pxd +17 -0
  156. Cython/Includes/cpython/sequence.pxd +134 -0
  157. Cython/Includes/cpython/set.pxd +119 -0
  158. Cython/Includes/cpython/slice.pxd +70 -0
  159. Cython/Includes/cpython/time.pxd +129 -0
  160. Cython/Includes/cpython/tuple.pxd +72 -0
  161. Cython/Includes/cpython/type.pxd +146 -0
  162. Cython/Includes/cpython/unicode.pxd +639 -0
  163. Cython/Includes/cpython/version.pxd +32 -0
  164. Cython/Includes/cpython/weakref.pxd +78 -0
  165. Cython/Includes/libc/__init__.pxd +1 -0
  166. Cython/Includes/libc/complex.pxd +35 -0
  167. Cython/Includes/libc/errno.pxd +127 -0
  168. Cython/Includes/libc/float.pxd +43 -0
  169. Cython/Includes/libc/limits.pxd +28 -0
  170. Cython/Includes/libc/locale.pxd +46 -0
  171. Cython/Includes/libc/math.pxd +209 -0
  172. Cython/Includes/libc/setjmp.pxd +10 -0
  173. Cython/Includes/libc/signal.pxd +64 -0
  174. Cython/Includes/libc/stddef.pxd +9 -0
  175. Cython/Includes/libc/stdint.pxd +105 -0
  176. Cython/Includes/libc/stdio.pxd +80 -0
  177. Cython/Includes/libc/stdlib.pxd +72 -0
  178. Cython/Includes/libc/string.pxd +50 -0
  179. Cython/Includes/libc/threads.pxd +234 -0
  180. Cython/Includes/libc/time.pxd +52 -0
  181. Cython/Includes/libcpp/__init__.pxd +4 -0
  182. Cython/Includes/libcpp/algorithm.pxd +320 -0
  183. Cython/Includes/libcpp/any.pxd +16 -0
  184. Cython/Includes/libcpp/atomic.pxd +59 -0
  185. Cython/Includes/libcpp/barrier.pxd +22 -0
  186. Cython/Includes/libcpp/bit.pxd +29 -0
  187. Cython/Includes/libcpp/cast.pxd +12 -0
  188. Cython/Includes/libcpp/cmath.pxd +518 -0
  189. Cython/Includes/libcpp/complex.pxd +106 -0
  190. Cython/Includes/libcpp/condition_variable.pxd +322 -0
  191. Cython/Includes/libcpp/deque.pxd +165 -0
  192. Cython/Includes/libcpp/exception.pxd +216 -0
  193. Cython/Includes/libcpp/execution.pxd +15 -0
  194. Cython/Includes/libcpp/forward_list.pxd +63 -0
  195. Cython/Includes/libcpp/functional.pxd +26 -0
  196. Cython/Includes/libcpp/future.pxd +103 -0
  197. Cython/Includes/libcpp/iterator.pxd +34 -0
  198. Cython/Includes/libcpp/latch.pxd +17 -0
  199. Cython/Includes/libcpp/limits.pxd +61 -0
  200. Cython/Includes/libcpp/list.pxd +117 -0
  201. Cython/Includes/libcpp/map.pxd +252 -0
  202. Cython/Includes/libcpp/memory.pxd +115 -0
  203. Cython/Includes/libcpp/mutex.pxd +387 -0
  204. Cython/Includes/libcpp/numbers.pxd +15 -0
  205. Cython/Includes/libcpp/numeric.pxd +131 -0
  206. Cython/Includes/libcpp/optional.pxd +34 -0
  207. Cython/Includes/libcpp/pair.pxd +1 -0
  208. Cython/Includes/libcpp/queue.pxd +25 -0
  209. Cython/Includes/libcpp/random.pxd +166 -0
  210. Cython/Includes/libcpp/semaphore.pxd +43 -0
  211. Cython/Includes/libcpp/set.pxd +228 -0
  212. Cython/Includes/libcpp/shared_mutex.pxd +96 -0
  213. Cython/Includes/libcpp/span.pxd +87 -0
  214. Cython/Includes/libcpp/stack.pxd +11 -0
  215. Cython/Includes/libcpp/stop_token.pxd +117 -0
  216. Cython/Includes/libcpp/string.pxd +355 -0
  217. Cython/Includes/libcpp/string_view.pxd +183 -0
  218. Cython/Includes/libcpp/typeindex.pxd +15 -0
  219. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  220. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  221. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  222. Cython/Includes/libcpp/utility.pxd +30 -0
  223. Cython/Includes/libcpp/vector.pxd +186 -0
  224. Cython/Includes/numpy/math.pxd +150 -0
  225. Cython/Includes/openmp.pxd +50 -0
  226. Cython/Includes/posix/__init__.pxd +1 -0
  227. Cython/Includes/posix/dlfcn.pxd +14 -0
  228. Cython/Includes/posix/fcntl.pxd +86 -0
  229. Cython/Includes/posix/ioctl.pxd +4 -0
  230. Cython/Includes/posix/mman.pxd +101 -0
  231. Cython/Includes/posix/resource.pxd +57 -0
  232. Cython/Includes/posix/select.pxd +21 -0
  233. Cython/Includes/posix/signal.pxd +73 -0
  234. Cython/Includes/posix/stat.pxd +98 -0
  235. Cython/Includes/posix/stdio.pxd +37 -0
  236. Cython/Includes/posix/stdlib.pxd +29 -0
  237. Cython/Includes/posix/strings.pxd +9 -0
  238. Cython/Includes/posix/time.pxd +71 -0
  239. Cython/Includes/posix/types.pxd +30 -0
  240. Cython/Includes/posix/uio.pxd +26 -0
  241. Cython/Includes/posix/unistd.pxd +271 -0
  242. Cython/Includes/posix/wait.pxd +38 -0
  243. Cython/LZSS.cp315-win_amd64.pyd +0 -0
  244. Cython/LZSS.py +184 -0
  245. Cython/Plex/Actions.cp315-win_amd64.pyd +0 -0
  246. Cython/Plex/Actions.pxd +24 -0
  247. Cython/Plex/Actions.py +119 -0
  248. Cython/Plex/DFA.cp315-win_amd64.pyd +0 -0
  249. Cython/Plex/DFA.pxd +14 -0
  250. Cython/Plex/DFA.py +164 -0
  251. Cython/Plex/Errors.py +48 -0
  252. Cython/Plex/Lexicons.py +178 -0
  253. Cython/Plex/Machines.cp315-win_amd64.pyd +0 -0
  254. Cython/Plex/Machines.pxd +36 -0
  255. Cython/Plex/Machines.py +238 -0
  256. Cython/Plex/Regexps.py +535 -0
  257. Cython/Plex/Scanners.cp315-win_amd64.pyd +0 -0
  258. Cython/Plex/Scanners.pxd +45 -0
  259. Cython/Plex/Scanners.py +328 -0
  260. Cython/Plex/Transitions.cp315-win_amd64.pyd +0 -0
  261. Cython/Plex/Transitions.pxd +14 -0
  262. Cython/Plex/Transitions.py +239 -0
  263. Cython/Plex/__init__.py +34 -0
  264. Cython/Runtime/__init__.py +1 -0
  265. Cython/Runtime/refnanny.cp315-win_amd64.pyd +0 -0
  266. Cython/Runtime/refnanny.pyx +237 -0
  267. Cython/Shadow.py +1174 -0
  268. Cython/StringIOTree.cp315-win_amd64.pyd +0 -0
  269. Cython/StringIOTree.py +169 -0
  270. Cython/Tempita/__init__.py +4 -0
  271. Cython/Tempita/_looper.py +154 -0
  272. Cython/Tempita/_tempita.cp315-win_amd64.pyd +0 -0
  273. Cython/Tempita/_tempita.py +1087 -0
  274. Cython/TestUtils.py +472 -0
  275. Cython/Tests/TestCodeWriter.py +128 -0
  276. Cython/Tests/TestCythonUtils.py +202 -0
  277. Cython/Tests/TestJediTyper.py +223 -0
  278. Cython/Tests/TestShadow.py +125 -0
  279. Cython/Tests/TestStringIOTree.py +68 -0
  280. Cython/Tests/TestTestUtils.py +89 -0
  281. Cython/Tests/__init__.py +1 -0
  282. Cython/Tests/xmlrunner.py +390 -0
  283. Cython/Utility/AsyncGen.c +1152 -0
  284. Cython/Utility/Buffer.c +866 -0
  285. Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
  286. Cython/Utility/Builtins.c +1068 -0
  287. Cython/Utility/CConvert.pyx +153 -0
  288. Cython/Utility/CMath.c +104 -0
  289. Cython/Utility/CommonStructures.c +244 -0
  290. Cython/Utility/Complex.c +378 -0
  291. Cython/Utility/Coroutine.c +2344 -0
  292. Cython/Utility/CpdefEnums.pyx +119 -0
  293. Cython/Utility/CppConvert.pyx +282 -0
  294. Cython/Utility/CppSupport.cpp +151 -0
  295. Cython/Utility/CythonFunction.c +2185 -0
  296. Cython/Utility/Dataclasses.c +101 -0
  297. Cython/Utility/Embed.c +129 -0
  298. Cython/Utility/Exceptions.c +1331 -0
  299. Cython/Utility/Exceptions_Cy.pyx +109 -0
  300. Cython/Utility/ExtensionTypes.c +1199 -0
  301. Cython/Utility/FunctionArguments.c +1052 -0
  302. Cython/Utility/FusedFunction.pyx +44 -0
  303. Cython/Utility/ImportExport.c +972 -0
  304. Cython/Utility/MatchCase.c +981 -0
  305. Cython/Utility/MatchCase_Cy.pyx +12 -0
  306. Cython/Utility/MemoryView.pxd +108 -0
  307. Cython/Utility/MemoryView.pyx +1499 -0
  308. Cython/Utility/MemoryView_C.c +1056 -0
  309. Cython/Utility/ModuleSetupCode.c +3319 -0
  310. Cython/Utility/NumpyImportArray.c +46 -0
  311. Cython/Utility/ObjectHandling.c +3404 -0
  312. Cython/Utility/Optimize.c +2564 -0
  313. Cython/Utility/Overflow.c +378 -0
  314. Cython/Utility/Profile.c +736 -0
  315. Cython/Utility/StringTools.c +1534 -0
  316. Cython/Utility/Synchronization.c +438 -0
  317. Cython/Utility/TString.c +369 -0
  318. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  319. Cython/Utility/TestCythonScope.pyx +75 -0
  320. Cython/Utility/TestUtilityLoader.c +12 -0
  321. Cython/Utility/TypeConversion.c +1588 -0
  322. Cython/Utility/UFuncs.pyx +50 -0
  323. Cython/Utility/UFuncs_C.c +89 -0
  324. Cython/Utility/__init__.py +28 -0
  325. Cython/Utility/arrayarray.h +172 -0
  326. Cython/Utils.cp315-win_amd64.pyd +0 -0
  327. Cython/Utils.py +680 -0
  328. Cython/__init__.py +12 -0
  329. Cython/_shared.cp315-win_amd64.pyd +0 -0
  330. Cython/py.typed +0 -0
  331. cython-3.3.0.dist-info/METADATA +555 -0
  332. cython-3.3.0.dist-info/RECORD +339 -0
  333. cython-3.3.0.dist-info/WHEEL +5 -0
  334. cython-3.3.0.dist-info/entry_points.txt +4 -0
  335. cython-3.3.0.dist-info/top_level.txt +3 -0
  336. cython.py +29 -0
  337. pyximport/__init__.py +4 -0
  338. pyximport/pyxbuild.py +160 -0
  339. pyximport/pyximport.py +482 -0
@@ -0,0 +1,580 @@
1
+ """
2
+ Tests that run inside GDB.
3
+
4
+ Note: debug information is already imported by the file generated by
5
+ Cython.Debugger.Cygdb.make_command_file()
6
+ """
7
+
8
+
9
+ import os
10
+ import re
11
+ import sys
12
+ import trace
13
+ import pickle
14
+ import random
15
+ import inspect
16
+ import warnings
17
+ import unittest
18
+ import textwrap
19
+ import tempfile
20
+ import functools
21
+ import traceback
22
+ import itertools
23
+ #from test import test_support
24
+
25
+ import gdb
26
+
27
+ from .. import libcython
28
+ from .. import libpython
29
+ from . import TestLibCython as test_libcython
30
+ from ...TestUtils import TimedTest
31
+
32
+ # for some reason sys.argv is missing in gdb
33
+ sys.argv = ['gdb']
34
+
35
+
36
+ def print_on_call_decorator(func):
37
+ @functools.wraps(func)
38
+ def wrapper(self, *args, **kwargs):
39
+ _debug(type(self).__name__, func.__name__)
40
+
41
+ try:
42
+ return func(self, *args, **kwargs)
43
+ except Exception:
44
+ _debug("An exception occurred:", traceback.format_exc())
45
+ raise
46
+
47
+ return wrapper
48
+
49
+ class TraceMethodCallMeta(type):
50
+
51
+ def __init__(self, name, bases, dict):
52
+ for func_name, func in dict.items():
53
+ if inspect.isfunction(func):
54
+ setattr(self, func_name, print_on_call_decorator(func))
55
+
56
+
57
+ class DebugTestCase(TimedTest, metaclass=TraceMethodCallMeta):
58
+ """
59
+ Base class for test cases. On teardown it kills the inferior and unsets
60
+ all breakpoints.
61
+ """
62
+
63
+ def __init__(self, name):
64
+ super().__init__(name)
65
+ self.cy = libcython.cy
66
+ self.module = libcython.cy.cython_namespace['codefile']
67
+ self.spam_func, self.spam_meth = libcython.cy.functions_by_name['spam']
68
+ self.ham_func = libcython.cy.functions_by_qualified_name[
69
+ 'codefile.ham']
70
+ self.eggs_func = libcython.cy.functions_by_qualified_name[
71
+ 'codefile.eggs']
72
+
73
+ def read_var(self, varname, cast_to=None):
74
+ result = gdb.parse_and_eval('$cy_cvalue("%s")' % varname)
75
+ if cast_to:
76
+ result = cast_to(result)
77
+
78
+ return result
79
+
80
+ def local_info(self):
81
+ return gdb.execute('info locals', to_string=True)
82
+
83
+ def lineno_equals(self, source_line=None, lineno=None):
84
+ if source_line is not None:
85
+ lineno = test_libcython.source_to_lineno[source_line]
86
+ frame = gdb.selected_frame()
87
+ self.assertEqual(libcython.cython_info.lineno(frame), lineno)
88
+
89
+ def break_and_run(self, source_line):
90
+ break_lineno = test_libcython.source_to_lineno[source_line]
91
+ gdb.execute('cy break codefile:%d' % break_lineno, to_string=True)
92
+ gdb.execute('run', to_string=True)
93
+
94
+ def tearDown(self):
95
+ super().tearDown()
96
+ gdb.execute('delete breakpoints', to_string=True)
97
+ try:
98
+ gdb.execute('kill inferior 1', to_string=True)
99
+ except RuntimeError:
100
+ pass
101
+
102
+ gdb.execute('set args -c "import codefile"')
103
+
104
+
105
+ class TestDebugInformationClasses(DebugTestCase):
106
+
107
+ def test_CythonModule(self):
108
+ "test that debug information was parsed properly into data structures"
109
+ self.assertEqual(self.module.name, 'codefile')
110
+ global_vars = ('c_var', 'python_var', '__name__',
111
+ '__builtins__', '__doc__', '__file__')
112
+ assert set(global_vars).issubset(self.module.globals)
113
+
114
+ def test_CythonVariable(self):
115
+ module_globals = self.module.globals
116
+ c_var = module_globals['c_var']
117
+ python_var = module_globals['python_var']
118
+ self.assertEqual(c_var.type, libcython.CObject)
119
+ self.assertEqual(python_var.type, libcython.PythonObject)
120
+ self.assertEqual(c_var.qualified_name, 'codefile.c_var')
121
+
122
+ def test_CythonFunction(self):
123
+ self.assertEqual(self.spam_func.qualified_name, 'codefile.spam')
124
+ self.assertEqual(self.spam_meth.qualified_name,
125
+ 'codefile.SomeClass.spam')
126
+ self.assertEqual(self.spam_func.module, self.module)
127
+
128
+ assert self.eggs_func.pf_cname, (self.eggs_func, self.eggs_func.pf_cname)
129
+ assert not self.ham_func.pf_cname
130
+ assert not self.spam_func.pf_cname
131
+ assert not self.spam_meth.pf_cname
132
+
133
+ self.assertEqual(self.spam_func.type, libcython.CObject)
134
+ self.assertEqual(self.ham_func.type, libcython.CObject)
135
+
136
+ self.assertEqual(self.spam_func.arguments, ['a'])
137
+ self.assertEqual(self.spam_func.step_into_functions,
138
+ {'puts', 'some_c_function'})
139
+
140
+ expected_lineno = test_libcython.source_to_lineno['def spam(a=0):']
141
+ self.assertEqual(self.spam_func.lineno, expected_lineno)
142
+ self.assertEqual(sorted(self.spam_func.locals), list('abcd'))
143
+
144
+
145
+ class TestReprMethods(DebugTestCase):
146
+
147
+ def test_simple_repr(self):
148
+ test_class = libcython.CythonModule
149
+ num_args = len(inspect.signature(test_class).parameters)
150
+ lorem_ipsum = random.Random(0)
151
+ filler_args = (lorem_ipsum.randbytes(8) for _ in range(num_args))
152
+ instance = test_class(*filler_args)
153
+ recreated = eval("libcython." + repr(instance))
154
+ self.assertEqual(pickle.dumps(instance), pickle.dumps(recreated))
155
+
156
+ def test_frame_repr(self):
157
+ # check that frame_repr's function expansion is idempotent
158
+ beginline = 'import os'
159
+
160
+ self.break_and_run(beginline)
161
+ frame = gdb.selected_frame()
162
+ self.assertEqual(libcython.frame_repr(frame),
163
+ libcython.frame_repr(frame))
164
+
165
+
166
+ class TestParameters(TimedTest):
167
+
168
+ def test_parameters(self):
169
+ gdb.execute('set cy_colorize_code on')
170
+ assert libcython.parameters.colorize_code
171
+ gdb.execute('set cy_colorize_code off')
172
+ assert not libcython.parameters.colorize_code
173
+
174
+
175
+ class TestBreak(DebugTestCase):
176
+
177
+ def test_break(self):
178
+ breakpoint_amount = len(gdb.breakpoints() or ())
179
+ gdb.execute('cy break codefile.spam')
180
+
181
+ self.assertEqual(len(gdb.breakpoints()), breakpoint_amount + 1)
182
+ bp = gdb.breakpoints()[-1]
183
+ self.assertEqual(bp.type, gdb.BP_BREAKPOINT)
184
+ assert self.spam_func.cname in bp.location
185
+ assert bp.enabled
186
+
187
+ def test_python_break(self):
188
+ gdb.execute('cy break -p join')
189
+ assert 'def join(' in gdb.execute('cy run', to_string=True)
190
+
191
+ def test_break_lineno(self):
192
+ beginline = 'import os'
193
+ nextline = 'cdef int c_var = 12'
194
+
195
+ self.break_and_run(beginline)
196
+ self.lineno_equals(beginline)
197
+ step_result = gdb.execute('cy step', to_string=True)
198
+ self.lineno_equals(nextline)
199
+ assert step_result.rstrip().endswith(nextline)
200
+
201
+ def test_break_completion(self):
202
+ completer = libcython.cy.break_.complete
203
+ self.assertIn('spam', completer("codefile.SomeClass.s", "s"))
204
+ self.assertIn('spam', completer("codefile.SomeClass.", None))
205
+ self.assertIn('pam', completer("codefile.s", None))
206
+
207
+
208
+ # I removed this testcase, because it will never work, because
209
+ # gdb.execute(..., to_string=True) does not capture stdout and stderr of python.
210
+ # class TestKilled(DebugTestCase):
211
+ # def test_abort(self):
212
+ # gdb.execute("set args -c 'import os;print(123456789);os.abort()'")
213
+ # output = gdb.execute('cy run', to_string=True)
214
+ # assert 'abort' in output.lower()
215
+
216
+
217
+ class DebugStepperTestCase(DebugTestCase):
218
+
219
+ def step(self, varnames_and_values, source_line=None, lineno=None):
220
+ gdb.execute(self.command)
221
+ for varname, value in varnames_and_values:
222
+ self.assertEqual(self.read_var(varname), value, self.local_info())
223
+
224
+ self.lineno_equals(source_line, lineno)
225
+
226
+
227
+ class TestStep(DebugStepperTestCase):
228
+ """
229
+ Test stepping. Stepping happens in the code found in
230
+ Cython/Debugger/Tests/codefile.
231
+ """
232
+
233
+ def test_cython_step(self):
234
+ gdb.execute('cy break codefile.spam')
235
+
236
+ gdb.execute('run', to_string=True)
237
+ self.lineno_equals('def spam(a=0):')
238
+
239
+ gdb.execute('cy step', to_string=True)
240
+ self.lineno_equals('b = c = d = 0')
241
+
242
+ self.command = 'cy step'
243
+ self.step([('b', 0)], source_line='b = 1')
244
+ self.step([('b', 1), ('c', 0)], source_line='c = 2')
245
+ self.step([('c', 2)], source_line='int(10)')
246
+ self.step([], source_line='puts("spam")')
247
+
248
+ gdb.execute('cont', to_string=True)
249
+ self.assertEqual(len(gdb.inferiors()), 1)
250
+ self.assertEqual(gdb.inferiors()[0].pid, 0)
251
+
252
+ def test_c_step(self):
253
+ self.break_and_run('some_c_function()')
254
+ gdb.execute('cy step', to_string=True)
255
+ self.assertEqual(gdb.selected_frame().name(), 'some_c_function')
256
+
257
+ def test_python_step(self):
258
+ self.break_and_run('os.path.join("foo", "bar")')
259
+
260
+ result = gdb.execute('cy step', to_string=True)
261
+
262
+ curframe = gdb.selected_frame()
263
+ self.assertEqual(curframe.name(), 'PyEval_EvalFrameEx')
264
+
265
+ pyframe = libpython.Frame(curframe).get_pyop()
266
+ # With Python 3 inferiors, pyframe.co_name will return a PyUnicodePtr,
267
+ # be compatible
268
+ frame_name = pyframe.co_name.proxyval(set())
269
+ self.assertEqual(frame_name, 'join')
270
+ assert re.match(r'\d+ def join\(', result), result
271
+
272
+
273
+ class TestNext(DebugStepperTestCase):
274
+
275
+ def test_cython_next(self):
276
+ self.break_and_run('c = 2')
277
+
278
+ lines = (
279
+ 'int(10)',
280
+ 'puts("spam")',
281
+ 'os.path.join("foo", "bar")',
282
+ 'some_c_function()',
283
+ )
284
+
285
+ for line in lines:
286
+ gdb.execute('cy next')
287
+ self.lineno_equals(line)
288
+
289
+
290
+ class TestLocalsGlobals(DebugTestCase):
291
+
292
+ def test_locals(self):
293
+ self.break_and_run('int(10)')
294
+
295
+ result = gdb.execute('cy locals', to_string=True)
296
+ assert 'a = 0', repr(result)
297
+ assert 'b = (int) 1', result
298
+ assert 'c = (int) 2' in result, repr(result)
299
+
300
+ def test_globals(self):
301
+ self.break_and_run('int(10)')
302
+
303
+ result = gdb.execute('cy globals', to_string=True)
304
+ assert '__name__ ' in result, repr(result)
305
+ assert '__doc__ ' in result, repr(result)
306
+ assert 'os ' in result, repr(result)
307
+ assert 'c_var ' in result, repr(result)
308
+ assert 'python_var ' in result, repr(result)
309
+
310
+
311
+ class TestBacktrace(DebugTestCase):
312
+
313
+ def test_backtrace(self):
314
+ libcython.parameters.colorize_code.value = False
315
+
316
+ self.break_and_run('os.path.join("foo", "bar")')
317
+
318
+ def match_backtrace_output(result):
319
+ assert re.search(r'\#\d+ *0x.* in spam\(\) at .*codefile\.pyx:22',
320
+ result), result
321
+ assert 'os.path.join("foo", "bar")' in result, result
322
+
323
+ result = gdb.execute('cy bt', to_string=True)
324
+ match_backtrace_output(result)
325
+
326
+ result = gdb.execute('cy bt -a', to_string=True)
327
+ match_backtrace_output(result)
328
+
329
+ # Apparently not everyone has main()
330
+ # assert re.search(r'\#0 *0x.* in main\(\)', result), result
331
+
332
+
333
+ class TestFunctions(DebugTestCase):
334
+
335
+ def test_functions(self):
336
+ self.break_and_run('c = 2')
337
+ result = gdb.execute('print $cy_cname("b")', to_string=True)
338
+ assert re.search('__pyx_.*b', result), result
339
+
340
+ result = gdb.execute('print $cy_lineno()', to_string=True)
341
+ supposed_lineno = test_libcython.source_to_lineno['c = 2']
342
+ assert str(supposed_lineno) in result, (supposed_lineno, result)
343
+
344
+ result = gdb.execute('print $cy_cvalue("b")', to_string=True)
345
+ assert '= 1' in result
346
+
347
+
348
+ class TestPrint(DebugTestCase):
349
+
350
+ def test_print(self):
351
+ self.break_and_run('c = 2')
352
+ result = gdb.execute('cy print b', to_string=True)
353
+ self.assertEqual('b = (int) 1\n', result)
354
+ result = gdb.execute('cy print python_var', to_string=True)
355
+ self.assertEqual('python_var = 13\n', result)
356
+ result = gdb.execute('cy print c_var', to_string=True)
357
+ self.assertEqual('c_var = (int) 12\n', result)
358
+
359
+ correct_result_test_list_inside_func = '''\
360
+ 14 int b, c
361
+ 15
362
+ 16 b = c = d = 0
363
+ 17
364
+ 18 b = 1
365
+ > 19 c = 2
366
+ 20 int(10)
367
+ 21 puts("spam")
368
+ 22 os.path.join("foo", "bar")
369
+ 23 some_c_function()
370
+ '''
371
+ correct_result_test_list_outside_func = '''\
372
+ 5 void some_c_function()
373
+ 6
374
+ 7 import os
375
+ 8
376
+ 9 cdef int c_var = 12
377
+ > 10 python_var = 13
378
+ 11
379
+ 12 def spam(a=0):
380
+ 13 cdef:
381
+ 14 int b, c
382
+ '''
383
+
384
+
385
+ class TestList(DebugTestCase):
386
+ def workaround_for_coding_style_checker(self, correct_result_wrong_whitespace):
387
+ correct_result = ""
388
+ for line in correct_result_test_list_inside_func.split("\n"):
389
+ if len(line) < 10 and len(line) > 0:
390
+ line += " "*4
391
+ correct_result += line + "\n"
392
+ correct_result = correct_result[:-1]
393
+
394
+ def test_list_inside_func(self):
395
+ self.break_and_run('c = 2')
396
+ result = gdb.execute('cy list', to_string=True)
397
+ # We don't want to fail because of some trailing whitespace,
398
+ # so we remove trailing whitespaces with the following line
399
+ result = "\n".join([line.rstrip() for line in result.split("\n")])
400
+ self.assertEqual(correct_result_test_list_inside_func, result)
401
+
402
+ def test_list_outside_func(self):
403
+ self.break_and_run('python_var = 13')
404
+ result = gdb.execute('cy list', to_string=True)
405
+ # We don't want to fail because of some trailing whitespace,
406
+ # so we remove trailing whitespaces with the following line
407
+ result = "\n".join([line.rstrip() for line in result.split("\n")])
408
+ self.assertEqual(correct_result_test_list_outside_func, result)
409
+
410
+
411
+ class TestUpDown(DebugTestCase):
412
+
413
+ def test_updown(self):
414
+ self.break_and_run('os.path.join("foo", "bar")')
415
+ gdb.execute('cy step')
416
+ self.assertRaises(RuntimeError, gdb.execute, 'cy down')
417
+
418
+ result = gdb.execute('cy up', to_string=True)
419
+ assert 'spam()' in result
420
+ assert 'os.path.join("foo", "bar")' in result
421
+
422
+
423
+ class TestExec(DebugTestCase):
424
+
425
+ def setUp(self):
426
+ super().setUp()
427
+ self.fd, self.tmpfilename = tempfile.mkstemp()
428
+ self.tmpfile = os.fdopen(self.fd, 'r+')
429
+
430
+ def tearDown(self):
431
+ super().tearDown()
432
+
433
+ try:
434
+ self.tmpfile.close()
435
+ finally:
436
+ os.remove(self.tmpfilename)
437
+
438
+ def eval_command(self, command):
439
+ gdb.execute('cy exec open(%r, "w").write(str(%s))' %
440
+ (self.tmpfilename, command))
441
+ return self.tmpfile.read().strip()
442
+
443
+ def test_cython_exec(self):
444
+ self.break_and_run('os.path.join("foo", "bar")')
445
+
446
+ # test normal behaviour
447
+ self.assertEqual("[0]", self.eval_command('[a]'))
448
+
449
+ return #The test after this return freezes gdb, so I temporarily removed it.
450
+ # test multiline code
451
+ result = gdb.execute(textwrap.dedent('''\
452
+ cy exec
453
+ pass
454
+
455
+ "nothing"
456
+ end
457
+ '''))
458
+ result = self.tmpfile.read().rstrip()
459
+ self.assertEqual('', result)
460
+
461
+ def test_python_exec(self):
462
+ self.break_and_run('os.path.join("foo", "bar")')
463
+ gdb.execute('cy step')
464
+
465
+ gdb.execute('cy exec some_random_var = 14')
466
+ self.assertEqual('14', self.eval_command('some_random_var'))
467
+
468
+
469
+ class CySet(DebugTestCase):
470
+
471
+ def test_cyset(self):
472
+ self.break_and_run('os.path.join("foo", "bar")')
473
+
474
+ gdb.execute('cy set a = $cy_eval("{None: []}")')
475
+ stringvalue = self.read_var("a", cast_to=str)
476
+ self.assertEqual(stringvalue, "{None: []}")
477
+
478
+
479
+ class TestCyEval(DebugTestCase):
480
+ "Test the $cy_eval() gdb function."
481
+
482
+ def test_cy_eval(self):
483
+ # This function leaks a few objects in the GDB python process. This
484
+ # is no biggie
485
+ self.break_and_run('os.path.join("foo", "bar")')
486
+
487
+ result = gdb.execute('print $cy_eval("None")', to_string=True)
488
+ assert re.match(r'\$\d+ = None\n', result), result
489
+
490
+ result = gdb.execute('print $cy_eval("[a]")', to_string=True)
491
+ assert re.match(r'\$\d+ = \[0\]', result), result
492
+
493
+
494
+ class TestClosure(DebugTestCase):
495
+
496
+ def break_and_run_func(self, funcname):
497
+ gdb.execute('cy break ' + funcname)
498
+ gdb.execute('cy run')
499
+
500
+ def test_inner(self):
501
+ self.break_and_run_func('inner')
502
+ self.assertEqual('', gdb.execute('cy locals', to_string=True))
503
+
504
+ # Allow the Cython-generated code to initialize the scope variable
505
+ gdb.execute('cy step')
506
+
507
+ self.assertEqual(str(self.read_var('a')), "'an object'")
508
+ print_result = gdb.execute('cy print a', to_string=True).strip()
509
+ self.assertEqual(print_result, "a = 'an object'")
510
+
511
+ def test_outer(self):
512
+ self.break_and_run_func('outer')
513
+ self.assertEqual('', gdb.execute('cy locals', to_string=True))
514
+
515
+ # Initialize scope with 'a' uninitialized
516
+ gdb.execute('cy step')
517
+ self.assertEqual('', gdb.execute('cy locals', to_string=True))
518
+
519
+ # Initialize 'a' to 1
520
+ gdb.execute('cy step')
521
+ print_result = gdb.execute('cy print a', to_string=True).strip()
522
+ self.assertEqual(print_result, "a = 'an object'")
523
+
524
+
525
+ _do_debug = os.environ.get('GDB_DEBUG')
526
+ if _do_debug:
527
+ _debug_file = open('/dev/tty', 'w')
528
+
529
+ def _debug(*messages):
530
+ if _do_debug:
531
+ messages = itertools.chain([sys._getframe(1).f_code.co_name, ':'],
532
+ messages)
533
+ _debug_file.write(' '.join(str(msg) for msg in messages) + '\n')
534
+
535
+
536
+ def run_unittest_in_module(modulename):
537
+ # Check if the Python executable provides a symbol table.
538
+ if not hasattr(gdb.selected_inferior().progspace, "symbol_file"):
539
+ msg = ("Unable to run tests, Python was not compiled with "
540
+ "debugging information. Either compile python with "
541
+ "-g or get a debug build (configure with --with-pydebug).")
542
+ warnings.warn(msg)
543
+ os._exit(1)
544
+ else:
545
+ m = __import__(modulename, fromlist=[''])
546
+ tests = inspect.getmembers(m, inspect.isclass)
547
+
548
+ # test_support.run_unittest(tests)
549
+
550
+ test_loader = unittest.TestLoader()
551
+ suite = unittest.TestSuite(
552
+ [test_loader.loadTestsFromTestCase(cls) for name, cls in tests])
553
+
554
+ result = unittest.TextTestRunner(verbosity=1).run(suite)
555
+ return result.wasSuccessful()
556
+
557
+ def runtests():
558
+ """
559
+ Run the libcython and libpython tests. Ensure that an appropriate status is
560
+ returned to the parent test process.
561
+ """
562
+ from Cython.Debugger.Tests import test_libpython_in_gdb
563
+
564
+ success_libcython = run_unittest_in_module(__name__)
565
+ success_libpython = run_unittest_in_module(test_libpython_in_gdb.__name__)
566
+
567
+ if not success_libcython or not success_libpython:
568
+ sys.exit(2)
569
+
570
+ def main(version, trace_code=False):
571
+ global inferior_python_version
572
+
573
+ inferior_python_version = version
574
+
575
+ if trace_code:
576
+ tracer = trace.Trace(count=False, trace=True, outfile=sys.stderr,
577
+ ignoredirs=[sys.prefix, sys.exec_prefix])
578
+ tracer.runfunc(runtests)
579
+ else:
580
+ runtests()
@@ -0,0 +1,90 @@
1
+ """
2
+ Test libpython.py. This is already partly tested by test_libcython_in_gdb and
3
+ Lib/test/test_gdb.py in the Python source. These tests are run in gdb and
4
+ called from test_libcython_in_gdb.main()
5
+ """
6
+
7
+ import gdb
8
+
9
+ from Cython.Debugger import libcython
10
+ from Cython.Debugger import libpython
11
+
12
+ from . import test_libcython_in_gdb
13
+
14
+
15
+ class TestPrettyPrinters(test_libcython_in_gdb.DebugTestCase):
16
+ """
17
+ Test whether types of Python objects are correctly inferred and that
18
+ the right libpython.PySomeTypeObjectPtr classes are instantiated.
19
+
20
+ Also test whether values are appropriately formatted (don't be too
21
+ laborious as Lib/test/test_gdb.py already covers this extensively).
22
+
23
+ Don't take care of decreffing newly allocated objects as a new
24
+ interpreter is started for every test anyway.
25
+ """
26
+
27
+ def setUp(self):
28
+ self.break_and_run('b = c = d = 0')
29
+ super().setUp()
30
+
31
+ def get_pyobject(self, code):
32
+ value = gdb.parse_and_eval(code)
33
+ assert libpython.pointervalue(value) != 0
34
+ return value
35
+
36
+ def pyobject_fromcode(self, code, gdbvar=None):
37
+ if gdbvar is not None:
38
+ d = {'varname':gdbvar, 'code':code}
39
+ gdb.execute('set $%(varname)s = %(code)s' % d)
40
+ code = '$' + gdbvar
41
+
42
+ return libpython.PyObjectPtr.from_pyobject_ptr(self.get_pyobject(code))
43
+
44
+ def get_repr(self, pyobject):
45
+ return pyobject.get_truncated_repr(libpython.MAX_OUTPUT_LEN)
46
+
47
+ def alloc_bytestring(self, string, gdbvar=None):
48
+ assert b'"' not in string
49
+
50
+ # ensure double quotes
51
+ code = '(PyObject *) PyBytes_FromStringAndSize("%s", %d)' % (string.decode('iso8859-1'), len(string))
52
+ return self.pyobject_fromcode(code, gdbvar=gdbvar)
53
+
54
+ def alloc_unicodestring(self, string, gdbvar=None):
55
+ postfix = libpython.get_inferior_unicode_postfix()
56
+ funcname = 'PyUnicode%s_DecodeUnicodeEscape' % (postfix,)
57
+
58
+ data = string.encode("unicode_escape").decode('iso8859-1')
59
+ return self.pyobject_fromcode(
60
+ '(PyObject *) %s("%s", %d, "strict")' % (
61
+ funcname, data.replace('"', r'\"').replace('\\', r'\\'), len(data)),
62
+ gdbvar=gdbvar)
63
+
64
+ def test_bytestring(self):
65
+ bytestring = self.alloc_bytestring(b"spam")
66
+
67
+ bytestring_class = libpython.PyBytesObjectPtr
68
+ expected = "b'spam'"
69
+
70
+ self.assertEqual(type(bytestring), bytestring_class)
71
+ self.assertEqual(self.get_repr(bytestring), expected)
72
+
73
+ def test_unicode(self):
74
+ unicode_string = self.alloc_unicodestring("spam ἄλφα")
75
+
76
+ self.assertEqual(type(unicode_string), libpython.PyUnicodeObjectPtr)
77
+ self.assertEqual(self.get_repr(unicode_string), "'spam ἄλφα'")
78
+
79
+ def test_long(self):
80
+ longval = self.pyobject_fromcode('PyLong_FromLong(200)',
81
+ gdbvar='longval')
82
+ assert gdb.parse_and_eval('$longval->ob_type == &PyLong_Type')
83
+
84
+ self.assertEqual(type(longval), libpython.PyLongObjectPtr)
85
+ self.assertEqual(self.get_repr(longval), '200')
86
+
87
+ def test_frame_type(self):
88
+ frame = self.pyobject_fromcode('PyEval_GetFrame()')
89
+
90
+ self.assertEqual(type(frame), libpython.PyFrameObjectPtr)
@@ -0,0 +1 @@
1
+ # empty file