# HG changeset patch
# User Robert Bradshaw <robertwb@math.washington.edu>
# Date 1300773512 25200
# Node ID 6d25566e4ad5847b615ccdaf9a2af0bedd3a563d
# Parent 9326be5cb9fac428116d39803e47b94376abafef
#10548 - stringify coercion tracebacks to avoid memory leaks
diff -r 9326be5cb9fa -r 6d25566e4ad5 sage/structure/coerce.pyx
|
a
|
b
|
|
| 88 | 88 | from parent import Set_PythonType |
| 89 | 89 | from coerce_exceptions import CoercionException |
| 90 | 90 | |
| 91 | | import sys |
| | 91 | import sys, traceback |
| 92 | 92 | |
| 93 | 93 | from coerce_actions import LeftModuleAction, RightModuleAction, IntegerMulAction |
| 94 | 94 | |
| … |
… |
|
| 295 | 295 | [] |
| 296 | 296 | sage: cm._test_exception_stack() |
| 297 | 297 | sage: cm.exception_stack() |
| 298 | | [(<type 'exceptions.TypeError'>, TypeError('just a test',), <traceback object at ...>)] |
| | 298 | ['Traceback (most recent call last):\n File "coerce.pyx", line ...TypeError: just a test'] |
| 299 | 299 | |
| 300 | | The function _test_exception_stack is executing the following code: |
| | 300 | The function _test_exception_stack is executing the following code:: |
| | 301 | |
| 301 | 302 | try: |
| 302 | 303 | raise TypeError, "just a test" |
| 303 | 304 | except: |
| … |
… |
|
| 306 | 307 | if not self._exceptions_cleared: |
| 307 | 308 | self._exception_stack = [] |
| 308 | 309 | self._exceptions_cleared = True |
| 309 | | self._exception_stack.append(sys.exc_info()) |
| | 310 | self._exception_stack.append(traceback.format_exc().strip()) |
| 310 | 311 | |
| 311 | 312 | def _test_exception_stack(self): |
| 312 | | """ |
| | 313 | r""" |
| 313 | 314 | A function to test the exception stack. |
| 314 | 315 | |
| 315 | 316 | EXAMPLES:: |
| … |
… |
|
| 321 | 322 | [] |
| 322 | 323 | sage: cm._test_exception_stack() |
| 323 | 324 | sage: cm.exception_stack() |
| 324 | | [(<type 'exceptions.TypeError'>, TypeError('just a test',), <traceback object at ...>)] |
| | 325 | ['Traceback (most recent call last):\n File "coerce.pyx", line ...TypeError: just a test'] |
| 325 | 326 | """ |
| 326 | 327 | try: |
| 327 | 328 | raise TypeError, "just a test" |
| … |
… |
|
| 355 | 356 | |
| 356 | 357 | sage: import traceback |
| 357 | 358 | sage: cm.exception_stack() |
| 358 | | [(<type 'exceptions.TypeError'>, TypeError('No coercion from Rational Field to pushout Ring of integers modulo 1',), <traceback object at ...>), (<type 'exceptions.TypeError'>, TypeError("no common canonical parent for objects with parents: 'Rational Field' and 'Finite Field of size 3'",), <traceback object at ...>)] |
| 359 | | sage: print ''.join(sum([traceback.format_exception(*info) for info in cm.exception_stack()], [])) |
| | 359 | ['Traceback (most recent call last):...', 'Traceback (most recent call last):...'] |
| | 360 | sage: print cm.exception_stack()[-1] |
| 360 | 361 | Traceback (most recent call last): |
| 361 | 362 | ... |
| 362 | 363 | TypeError: no common canonical parent for objects with parents: 'Rational Field' and 'Finite Field of size 3' |
diff -r 9326be5cb9fa -r 6d25566e4ad5 sage/structure/element.pyx
|
a
|
b
|
|
| 2684 | 2684 | TypeError: no common canonical parent for objects with parents: 'Rational Field' and 'Finite Field of size 5' |
| 2685 | 2685 | """ |
| 2686 | 2686 | if dump: |
| 2687 | | for exc_info in coercion_model.exception_stack(): |
| 2688 | | print ''.join(traceback.format_exception(*exc_info)) |
| | 2687 | for traceback in coercion_model.exception_stack(): |
| | 2688 | print traceback |
| 2689 | 2689 | else: |
| 2690 | 2690 | return coercion_model.exception_stack() |
| 2691 | 2691 | |