You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

787 lines
21 KiB

29 years ago
Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62260 | gregory.p.smith | 2008-04-10 01:11:56 +0200 (Thu, 10 Apr 2008) | 2 lines better diagnostics ........ r62261 | gregory.p.smith | 2008-04-10 01:16:37 +0200 (Thu, 10 Apr 2008) | 3 lines Raise SystemError when size < 0 is passed into PyString_FromStringAndSize, PyBytes_FromStringAndSize or PyUnicode_FromStringAndSize. [issue2587] ........ r62266 | neal.norwitz | 2008-04-10 07:46:39 +0200 (Thu, 10 Apr 2008) | 5 lines Remove the test file before writing it in case there is no write permission. This might help fix some of the failures on Windows box(es). It doesn't hurt either way and ensure the tests are a little more self contained (ie have less assumptions). ........ r62271 | gregory.p.smith | 2008-04-10 21:50:36 +0200 (Thu, 10 Apr 2008) | 2 lines get rid of assert (size >= 0) now that an explicit if (size < 0) is in the code. ........ r62277 | andrew.kuchling | 2008-04-10 23:27:10 +0200 (Thu, 10 Apr 2008) | 1 line Remove forward-looking statement ........ r62278 | andrew.kuchling | 2008-04-10 23:28:51 +0200 (Thu, 10 Apr 2008) | 1 line Add punctuation ........ r62279 | andrew.kuchling | 2008-04-10 23:29:01 +0200 (Thu, 10 Apr 2008) | 1 line Use issue directive ........ r62289 | thomas.heller | 2008-04-11 15:05:38 +0200 (Fri, 11 Apr 2008) | 3 lines Move backwards compatibility macro to the correct place; PyIndex_Check() was introduced in Python 2.5. ........ r62290 | thomas.heller | 2008-04-11 16:20:26 +0200 (Fri, 11 Apr 2008) | 2 lines Performance improvements. ........ r62293 | christian.heimes | 2008-04-12 15:03:03 +0200 (Sat, 12 Apr 2008) | 2 lines Applied patch #2617 from Frank Wierzbicki wit some extras from me -J and -X are now reserved for Jython and non-standard arguments (e.g. IronPython). I've added some extra comments to make sure the reservation don't get missed in the future. ........ r62294 | georg.brandl | 2008-04-12 20:11:18 +0200 (Sat, 12 Apr 2008) | 2 lines Use absolute path in sys.path. ........ r62295 | georg.brandl | 2008-04-12 20:36:09 +0200 (Sat, 12 Apr 2008) | 2 lines #2615: small consistency update by Jeroen Ruigrok van der Werven. ........ r62296 | georg.brandl | 2008-04-12 21:00:20 +0200 (Sat, 12 Apr 2008) | 2 lines Add Jeroen. ........ r62297 | georg.brandl | 2008-04-12 21:05:37 +0200 (Sat, 12 Apr 2008) | 2 lines Don't offend snake lovers. ........ r62298 | gregory.p.smith | 2008-04-12 22:37:48 +0200 (Sat, 12 Apr 2008) | 2 lines fix compiler warnings ........ r62302 | gregory.p.smith | 2008-04-13 00:24:04 +0200 (Sun, 13 Apr 2008) | 3 lines socket.error inherits from IOError, it no longer needs listing in the all_errors tuple. ........ r62303 | brett.cannon | 2008-04-13 01:44:07 +0200 (Sun, 13 Apr 2008) | 8 lines Re-implement the 'warnings' module in C. This allows for usage of the 'warnings' code in places where it was previously not possible (e.g., the parser). It could also potentially lead to a speed-up in interpreter start-up if the C version of the code (_warnings) is imported over the use of the Python version in key places. Closes issue #1631171. ........ r62304 | gregory.p.smith | 2008-04-13 02:03:25 +0200 (Sun, 13 Apr 2008) | 3 lines Adds a profile-opt target for easy compilation of a python binary using gcc's profile guided optimization. ........ r62305 | brett.cannon | 2008-04-13 02:18:44 +0200 (Sun, 13 Apr 2008) | 3 lines Fix a bug in PySys_HasWarnOption() where it was not properly checking the length of the list storing the warning options. ........ r62306 | brett.cannon | 2008-04-13 02:25:15 +0200 (Sun, 13 Apr 2008) | 2 lines Fix an accidental bug of an non-existent init function. ........ r62308 | andrew.kuchling | 2008-04-13 03:05:59 +0200 (Sun, 13 Apr 2008) | 1 line Mention -J, -X ........ r62311 | benjamin.peterson | 2008-04-13 04:20:05 +0200 (Sun, 13 Apr 2008) | 2 lines Give the "Interactive Interpreter Changes" section in 2.6 whatsnew a unique link name ........ r62313 | brett.cannon | 2008-04-13 04:42:36 +0200 (Sun, 13 Apr 2008) | 3 lines Fix test_warnings by making the state of things more consistent for each test when it is run. ........ r62314 | skip.montanaro | 2008-04-13 05:17:30 +0200 (Sun, 13 Apr 2008) | 2 lines spelling ........ r62315 | georg.brandl | 2008-04-13 09:07:44 +0200 (Sun, 13 Apr 2008) | 2 lines Fix markup. ........ r62319 | christian.heimes | 2008-04-13 11:30:17 +0200 (Sun, 13 Apr 2008) | 1 line Fix compiler warning Include/warnings.h:19:28: warning: no newline at end of file ........ r62320 | christian.heimes | 2008-04-13 11:33:24 +0200 (Sun, 13 Apr 2008) | 1 line Use PyString_InternFromString instead of PyString_FromString for static vars ........ r62321 | christian.heimes | 2008-04-13 11:37:05 +0200 (Sun, 13 Apr 2008) | 1 line Added new files to the pcbuild files ........
18 years ago
13 years ago
Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62260 | gregory.p.smith | 2008-04-10 01:11:56 +0200 (Thu, 10 Apr 2008) | 2 lines better diagnostics ........ r62261 | gregory.p.smith | 2008-04-10 01:16:37 +0200 (Thu, 10 Apr 2008) | 3 lines Raise SystemError when size < 0 is passed into PyString_FromStringAndSize, PyBytes_FromStringAndSize or PyUnicode_FromStringAndSize. [issue2587] ........ r62266 | neal.norwitz | 2008-04-10 07:46:39 +0200 (Thu, 10 Apr 2008) | 5 lines Remove the test file before writing it in case there is no write permission. This might help fix some of the failures on Windows box(es). It doesn't hurt either way and ensure the tests are a little more self contained (ie have less assumptions). ........ r62271 | gregory.p.smith | 2008-04-10 21:50:36 +0200 (Thu, 10 Apr 2008) | 2 lines get rid of assert (size >= 0) now that an explicit if (size < 0) is in the code. ........ r62277 | andrew.kuchling | 2008-04-10 23:27:10 +0200 (Thu, 10 Apr 2008) | 1 line Remove forward-looking statement ........ r62278 | andrew.kuchling | 2008-04-10 23:28:51 +0200 (Thu, 10 Apr 2008) | 1 line Add punctuation ........ r62279 | andrew.kuchling | 2008-04-10 23:29:01 +0200 (Thu, 10 Apr 2008) | 1 line Use issue directive ........ r62289 | thomas.heller | 2008-04-11 15:05:38 +0200 (Fri, 11 Apr 2008) | 3 lines Move backwards compatibility macro to the correct place; PyIndex_Check() was introduced in Python 2.5. ........ r62290 | thomas.heller | 2008-04-11 16:20:26 +0200 (Fri, 11 Apr 2008) | 2 lines Performance improvements. ........ r62293 | christian.heimes | 2008-04-12 15:03:03 +0200 (Sat, 12 Apr 2008) | 2 lines Applied patch #2617 from Frank Wierzbicki wit some extras from me -J and -X are now reserved for Jython and non-standard arguments (e.g. IronPython). I've added some extra comments to make sure the reservation don't get missed in the future. ........ r62294 | georg.brandl | 2008-04-12 20:11:18 +0200 (Sat, 12 Apr 2008) | 2 lines Use absolute path in sys.path. ........ r62295 | georg.brandl | 2008-04-12 20:36:09 +0200 (Sat, 12 Apr 2008) | 2 lines #2615: small consistency update by Jeroen Ruigrok van der Werven. ........ r62296 | georg.brandl | 2008-04-12 21:00:20 +0200 (Sat, 12 Apr 2008) | 2 lines Add Jeroen. ........ r62297 | georg.brandl | 2008-04-12 21:05:37 +0200 (Sat, 12 Apr 2008) | 2 lines Don't offend snake lovers. ........ r62298 | gregory.p.smith | 2008-04-12 22:37:48 +0200 (Sat, 12 Apr 2008) | 2 lines fix compiler warnings ........ r62302 | gregory.p.smith | 2008-04-13 00:24:04 +0200 (Sun, 13 Apr 2008) | 3 lines socket.error inherits from IOError, it no longer needs listing in the all_errors tuple. ........ r62303 | brett.cannon | 2008-04-13 01:44:07 +0200 (Sun, 13 Apr 2008) | 8 lines Re-implement the 'warnings' module in C. This allows for usage of the 'warnings' code in places where it was previously not possible (e.g., the parser). It could also potentially lead to a speed-up in interpreter start-up if the C version of the code (_warnings) is imported over the use of the Python version in key places. Closes issue #1631171. ........ r62304 | gregory.p.smith | 2008-04-13 02:03:25 +0200 (Sun, 13 Apr 2008) | 3 lines Adds a profile-opt target for easy compilation of a python binary using gcc's profile guided optimization. ........ r62305 | brett.cannon | 2008-04-13 02:18:44 +0200 (Sun, 13 Apr 2008) | 3 lines Fix a bug in PySys_HasWarnOption() where it was not properly checking the length of the list storing the warning options. ........ r62306 | brett.cannon | 2008-04-13 02:25:15 +0200 (Sun, 13 Apr 2008) | 2 lines Fix an accidental bug of an non-existent init function. ........ r62308 | andrew.kuchling | 2008-04-13 03:05:59 +0200 (Sun, 13 Apr 2008) | 1 line Mention -J, -X ........ r62311 | benjamin.peterson | 2008-04-13 04:20:05 +0200 (Sun, 13 Apr 2008) | 2 lines Give the "Interactive Interpreter Changes" section in 2.6 whatsnew a unique link name ........ r62313 | brett.cannon | 2008-04-13 04:42:36 +0200 (Sun, 13 Apr 2008) | 3 lines Fix test_warnings by making the state of things more consistent for each test when it is run. ........ r62314 | skip.montanaro | 2008-04-13 05:17:30 +0200 (Sun, 13 Apr 2008) | 2 lines spelling ........ r62315 | georg.brandl | 2008-04-13 09:07:44 +0200 (Sun, 13 Apr 2008) | 2 lines Fix markup. ........ r62319 | christian.heimes | 2008-04-13 11:30:17 +0200 (Sun, 13 Apr 2008) | 1 line Fix compiler warning Include/warnings.h:19:28: warning: no newline at end of file ........ r62320 | christian.heimes | 2008-04-13 11:33:24 +0200 (Sun, 13 Apr 2008) | 1 line Use PyString_InternFromString instead of PyString_FromString for static vars ........ r62321 | christian.heimes | 2008-04-13 11:37:05 +0200 (Sun, 13 Apr 2008) | 1 line Added new files to the pcbuild files ........
18 years ago
Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62260 | gregory.p.smith | 2008-04-10 01:11:56 +0200 (Thu, 10 Apr 2008) | 2 lines better diagnostics ........ r62261 | gregory.p.smith | 2008-04-10 01:16:37 +0200 (Thu, 10 Apr 2008) | 3 lines Raise SystemError when size < 0 is passed into PyString_FromStringAndSize, PyBytes_FromStringAndSize or PyUnicode_FromStringAndSize. [issue2587] ........ r62266 | neal.norwitz | 2008-04-10 07:46:39 +0200 (Thu, 10 Apr 2008) | 5 lines Remove the test file before writing it in case there is no write permission. This might help fix some of the failures on Windows box(es). It doesn't hurt either way and ensure the tests are a little more self contained (ie have less assumptions). ........ r62271 | gregory.p.smith | 2008-04-10 21:50:36 +0200 (Thu, 10 Apr 2008) | 2 lines get rid of assert (size >= 0) now that an explicit if (size < 0) is in the code. ........ r62277 | andrew.kuchling | 2008-04-10 23:27:10 +0200 (Thu, 10 Apr 2008) | 1 line Remove forward-looking statement ........ r62278 | andrew.kuchling | 2008-04-10 23:28:51 +0200 (Thu, 10 Apr 2008) | 1 line Add punctuation ........ r62279 | andrew.kuchling | 2008-04-10 23:29:01 +0200 (Thu, 10 Apr 2008) | 1 line Use issue directive ........ r62289 | thomas.heller | 2008-04-11 15:05:38 +0200 (Fri, 11 Apr 2008) | 3 lines Move backwards compatibility macro to the correct place; PyIndex_Check() was introduced in Python 2.5. ........ r62290 | thomas.heller | 2008-04-11 16:20:26 +0200 (Fri, 11 Apr 2008) | 2 lines Performance improvements. ........ r62293 | christian.heimes | 2008-04-12 15:03:03 +0200 (Sat, 12 Apr 2008) | 2 lines Applied patch #2617 from Frank Wierzbicki wit some extras from me -J and -X are now reserved for Jython and non-standard arguments (e.g. IronPython). I've added some extra comments to make sure the reservation don't get missed in the future. ........ r62294 | georg.brandl | 2008-04-12 20:11:18 +0200 (Sat, 12 Apr 2008) | 2 lines Use absolute path in sys.path. ........ r62295 | georg.brandl | 2008-04-12 20:36:09 +0200 (Sat, 12 Apr 2008) | 2 lines #2615: small consistency update by Jeroen Ruigrok van der Werven. ........ r62296 | georg.brandl | 2008-04-12 21:00:20 +0200 (Sat, 12 Apr 2008) | 2 lines Add Jeroen. ........ r62297 | georg.brandl | 2008-04-12 21:05:37 +0200 (Sat, 12 Apr 2008) | 2 lines Don't offend snake lovers. ........ r62298 | gregory.p.smith | 2008-04-12 22:37:48 +0200 (Sat, 12 Apr 2008) | 2 lines fix compiler warnings ........ r62302 | gregory.p.smith | 2008-04-13 00:24:04 +0200 (Sun, 13 Apr 2008) | 3 lines socket.error inherits from IOError, it no longer needs listing in the all_errors tuple. ........ r62303 | brett.cannon | 2008-04-13 01:44:07 +0200 (Sun, 13 Apr 2008) | 8 lines Re-implement the 'warnings' module in C. This allows for usage of the 'warnings' code in places where it was previously not possible (e.g., the parser). It could also potentially lead to a speed-up in interpreter start-up if the C version of the code (_warnings) is imported over the use of the Python version in key places. Closes issue #1631171. ........ r62304 | gregory.p.smith | 2008-04-13 02:03:25 +0200 (Sun, 13 Apr 2008) | 3 lines Adds a profile-opt target for easy compilation of a python binary using gcc's profile guided optimization. ........ r62305 | brett.cannon | 2008-04-13 02:18:44 +0200 (Sun, 13 Apr 2008) | 3 lines Fix a bug in PySys_HasWarnOption() where it was not properly checking the length of the list storing the warning options. ........ r62306 | brett.cannon | 2008-04-13 02:25:15 +0200 (Sun, 13 Apr 2008) | 2 lines Fix an accidental bug of an non-existent init function. ........ r62308 | andrew.kuchling | 2008-04-13 03:05:59 +0200 (Sun, 13 Apr 2008) | 1 line Mention -J, -X ........ r62311 | benjamin.peterson | 2008-04-13 04:20:05 +0200 (Sun, 13 Apr 2008) | 2 lines Give the "Interactive Interpreter Changes" section in 2.6 whatsnew a unique link name ........ r62313 | brett.cannon | 2008-04-13 04:42:36 +0200 (Sun, 13 Apr 2008) | 3 lines Fix test_warnings by making the state of things more consistent for each test when it is run. ........ r62314 | skip.montanaro | 2008-04-13 05:17:30 +0200 (Sun, 13 Apr 2008) | 2 lines spelling ........ r62315 | georg.brandl | 2008-04-13 09:07:44 +0200 (Sun, 13 Apr 2008) | 2 lines Fix markup. ........ r62319 | christian.heimes | 2008-04-13 11:30:17 +0200 (Sun, 13 Apr 2008) | 1 line Fix compiler warning Include/warnings.h:19:28: warning: no newline at end of file ........ r62320 | christian.heimes | 2008-04-13 11:33:24 +0200 (Sun, 13 Apr 2008) | 1 line Use PyString_InternFromString instead of PyString_FromString for static vars ........ r62321 | christian.heimes | 2008-04-13 11:37:05 +0200 (Sun, 13 Apr 2008) | 1 line Added new files to the pcbuild files ........
18 years ago
Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62260 | gregory.p.smith | 2008-04-10 01:11:56 +0200 (Thu, 10 Apr 2008) | 2 lines better diagnostics ........ r62261 | gregory.p.smith | 2008-04-10 01:16:37 +0200 (Thu, 10 Apr 2008) | 3 lines Raise SystemError when size < 0 is passed into PyString_FromStringAndSize, PyBytes_FromStringAndSize or PyUnicode_FromStringAndSize. [issue2587] ........ r62266 | neal.norwitz | 2008-04-10 07:46:39 +0200 (Thu, 10 Apr 2008) | 5 lines Remove the test file before writing it in case there is no write permission. This might help fix some of the failures on Windows box(es). It doesn't hurt either way and ensure the tests are a little more self contained (ie have less assumptions). ........ r62271 | gregory.p.smith | 2008-04-10 21:50:36 +0200 (Thu, 10 Apr 2008) | 2 lines get rid of assert (size >= 0) now that an explicit if (size < 0) is in the code. ........ r62277 | andrew.kuchling | 2008-04-10 23:27:10 +0200 (Thu, 10 Apr 2008) | 1 line Remove forward-looking statement ........ r62278 | andrew.kuchling | 2008-04-10 23:28:51 +0200 (Thu, 10 Apr 2008) | 1 line Add punctuation ........ r62279 | andrew.kuchling | 2008-04-10 23:29:01 +0200 (Thu, 10 Apr 2008) | 1 line Use issue directive ........ r62289 | thomas.heller | 2008-04-11 15:05:38 +0200 (Fri, 11 Apr 2008) | 3 lines Move backwards compatibility macro to the correct place; PyIndex_Check() was introduced in Python 2.5. ........ r62290 | thomas.heller | 2008-04-11 16:20:26 +0200 (Fri, 11 Apr 2008) | 2 lines Performance improvements. ........ r62293 | christian.heimes | 2008-04-12 15:03:03 +0200 (Sat, 12 Apr 2008) | 2 lines Applied patch #2617 from Frank Wierzbicki wit some extras from me -J and -X are now reserved for Jython and non-standard arguments (e.g. IronPython). I've added some extra comments to make sure the reservation don't get missed in the future. ........ r62294 | georg.brandl | 2008-04-12 20:11:18 +0200 (Sat, 12 Apr 2008) | 2 lines Use absolute path in sys.path. ........ r62295 | georg.brandl | 2008-04-12 20:36:09 +0200 (Sat, 12 Apr 2008) | 2 lines #2615: small consistency update by Jeroen Ruigrok van der Werven. ........ r62296 | georg.brandl | 2008-04-12 21:00:20 +0200 (Sat, 12 Apr 2008) | 2 lines Add Jeroen. ........ r62297 | georg.brandl | 2008-04-12 21:05:37 +0200 (Sat, 12 Apr 2008) | 2 lines Don't offend snake lovers. ........ r62298 | gregory.p.smith | 2008-04-12 22:37:48 +0200 (Sat, 12 Apr 2008) | 2 lines fix compiler warnings ........ r62302 | gregory.p.smith | 2008-04-13 00:24:04 +0200 (Sun, 13 Apr 2008) | 3 lines socket.error inherits from IOError, it no longer needs listing in the all_errors tuple. ........ r62303 | brett.cannon | 2008-04-13 01:44:07 +0200 (Sun, 13 Apr 2008) | 8 lines Re-implement the 'warnings' module in C. This allows for usage of the 'warnings' code in places where it was previously not possible (e.g., the parser). It could also potentially lead to a speed-up in interpreter start-up if the C version of the code (_warnings) is imported over the use of the Python version in key places. Closes issue #1631171. ........ r62304 | gregory.p.smith | 2008-04-13 02:03:25 +0200 (Sun, 13 Apr 2008) | 3 lines Adds a profile-opt target for easy compilation of a python binary using gcc's profile guided optimization. ........ r62305 | brett.cannon | 2008-04-13 02:18:44 +0200 (Sun, 13 Apr 2008) | 3 lines Fix a bug in PySys_HasWarnOption() where it was not properly checking the length of the list storing the warning options. ........ r62306 | brett.cannon | 2008-04-13 02:25:15 +0200 (Sun, 13 Apr 2008) | 2 lines Fix an accidental bug of an non-existent init function. ........ r62308 | andrew.kuchling | 2008-04-13 03:05:59 +0200 (Sun, 13 Apr 2008) | 1 line Mention -J, -X ........ r62311 | benjamin.peterson | 2008-04-13 04:20:05 +0200 (Sun, 13 Apr 2008) | 2 lines Give the "Interactive Interpreter Changes" section in 2.6 whatsnew a unique link name ........ r62313 | brett.cannon | 2008-04-13 04:42:36 +0200 (Sun, 13 Apr 2008) | 3 lines Fix test_warnings by making the state of things more consistent for each test when it is run. ........ r62314 | skip.montanaro | 2008-04-13 05:17:30 +0200 (Sun, 13 Apr 2008) | 2 lines spelling ........ r62315 | georg.brandl | 2008-04-13 09:07:44 +0200 (Sun, 13 Apr 2008) | 2 lines Fix markup. ........ r62319 | christian.heimes | 2008-04-13 11:30:17 +0200 (Sun, 13 Apr 2008) | 1 line Fix compiler warning Include/warnings.h:19:28: warning: no newline at end of file ........ r62320 | christian.heimes | 2008-04-13 11:33:24 +0200 (Sun, 13 Apr 2008) | 1 line Use PyString_InternFromString instead of PyString_FromString for static vars ........ r62321 | christian.heimes | 2008-04-13 11:37:05 +0200 (Sun, 13 Apr 2008) | 1 line Added new files to the pcbuild files ........
18 years ago
  1. /* Traceback implementation */
  2. #include "Python.h"
  3. #include "code.h"
  4. #include "frameobject.h"
  5. #include "structmember.h"
  6. #include "osdefs.h"
  7. #ifdef HAVE_FCNTL_H
  8. #include <fcntl.h>
  9. #endif
  10. #define OFF(x) offsetof(PyTracebackObject, x)
  11. #define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str))
  12. #define MAX_STRING_LENGTH 500
  13. #define MAX_FRAME_DEPTH 100
  14. #define MAX_NTHREADS 100
  15. /* Function from Parser/tokenizer.c */
  16. extern char * PyTokenizer_FindEncodingFilename(int, PyObject *);
  17. _Py_IDENTIFIER(TextIOWrapper);
  18. _Py_IDENTIFIER(close);
  19. _Py_IDENTIFIER(open);
  20. _Py_IDENTIFIER(path);
  21. static PyObject *
  22. tb_dir(PyTracebackObject *self)
  23. {
  24. return Py_BuildValue("[ssss]", "tb_frame", "tb_next",
  25. "tb_lasti", "tb_lineno");
  26. }
  27. static PyMethodDef tb_methods[] = {
  28. {"__dir__", (PyCFunction)tb_dir, METH_NOARGS},
  29. {NULL, NULL, 0, NULL},
  30. };
  31. static PyMemberDef tb_memberlist[] = {
  32. {"tb_next", T_OBJECT, OFF(tb_next), READONLY},
  33. {"tb_frame", T_OBJECT, OFF(tb_frame), READONLY},
  34. {"tb_lasti", T_INT, OFF(tb_lasti), READONLY},
  35. {"tb_lineno", T_INT, OFF(tb_lineno), READONLY},
  36. {NULL} /* Sentinel */
  37. };
  38. static void
  39. tb_dealloc(PyTracebackObject *tb)
  40. {
  41. PyObject_GC_UnTrack(tb);
  42. Py_TRASHCAN_SAFE_BEGIN(tb)
  43. Py_XDECREF(tb->tb_next);
  44. Py_XDECREF(tb->tb_frame);
  45. PyObject_GC_Del(tb);
  46. Py_TRASHCAN_SAFE_END(tb)
  47. }
  48. static int
  49. tb_traverse(PyTracebackObject *tb, visitproc visit, void *arg)
  50. {
  51. Py_VISIT(tb->tb_next);
  52. Py_VISIT(tb->tb_frame);
  53. return 0;
  54. }
  55. static void
  56. tb_clear(PyTracebackObject *tb)
  57. {
  58. Py_CLEAR(tb->tb_next);
  59. Py_CLEAR(tb->tb_frame);
  60. }
  61. PyTypeObject PyTraceBack_Type = {
  62. PyVarObject_HEAD_INIT(&PyType_Type, 0)
  63. "traceback",
  64. sizeof(PyTracebackObject),
  65. 0,
  66. (destructor)tb_dealloc, /*tp_dealloc*/
  67. 0, /*tp_print*/
  68. 0, /*tp_getattr*/
  69. 0, /*tp_setattr*/
  70. 0, /*tp_reserved*/
  71. 0, /*tp_repr*/
  72. 0, /*tp_as_number*/
  73. 0, /*tp_as_sequence*/
  74. 0, /*tp_as_mapping*/
  75. 0, /* tp_hash */
  76. 0, /* tp_call */
  77. 0, /* tp_str */
  78. PyObject_GenericGetAttr, /* tp_getattro */
  79. 0, /* tp_setattro */
  80. 0, /* tp_as_buffer */
  81. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
  82. 0, /* tp_doc */
  83. (traverseproc)tb_traverse, /* tp_traverse */
  84. (inquiry)tb_clear, /* tp_clear */
  85. 0, /* tp_richcompare */
  86. 0, /* tp_weaklistoffset */
  87. 0, /* tp_iter */
  88. 0, /* tp_iternext */
  89. tb_methods, /* tp_methods */
  90. tb_memberlist, /* tp_members */
  91. 0, /* tp_getset */
  92. 0, /* tp_base */
  93. 0, /* tp_dict */
  94. };
  95. static PyTracebackObject *
  96. newtracebackobject(PyTracebackObject *next, PyFrameObject *frame)
  97. {
  98. PyTracebackObject *tb;
  99. if ((next != NULL && !PyTraceBack_Check(next)) ||
  100. frame == NULL || !PyFrame_Check(frame)) {
  101. PyErr_BadInternalCall();
  102. return NULL;
  103. }
  104. tb = PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type);
  105. if (tb != NULL) {
  106. Py_XINCREF(next);
  107. tb->tb_next = next;
  108. Py_XINCREF(frame);
  109. tb->tb_frame = frame;
  110. tb->tb_lasti = frame->f_lasti;
  111. tb->tb_lineno = PyFrame_GetLineNumber(frame);
  112. PyObject_GC_Track(tb);
  113. }
  114. return tb;
  115. }
  116. int
  117. PyTraceBack_Here(PyFrameObject *frame)
  118. {
  119. PyThreadState *tstate = PyThreadState_GET();
  120. PyTracebackObject *oldtb = (PyTracebackObject *) tstate->curexc_traceback;
  121. PyTracebackObject *tb = newtracebackobject(oldtb, frame);
  122. if (tb == NULL)
  123. return -1;
  124. tstate->curexc_traceback = (PyObject *)tb;
  125. Py_XDECREF(oldtb);
  126. return 0;
  127. }
  128. /* Insert a frame into the traceback for (funcname, filename, lineno). */
  129. void _PyTraceback_Add(const char *funcname, const char *filename, int lineno)
  130. {
  131. PyObject *globals = NULL;
  132. PyCodeObject *code = NULL;
  133. PyFrameObject *frame = NULL;
  134. PyObject *exception, *value, *tb;
  135. /* Save and clear the current exception. Python functions must not be
  136. called with an exception set. Calling Python functions happens when
  137. the codec of the filesystem encoding is implemented in pure Python. */
  138. PyErr_Fetch(&exception, &value, &tb);
  139. globals = PyDict_New();
  140. if (!globals)
  141. goto done;
  142. code = PyCode_NewEmpty(filename, funcname, lineno);
  143. if (!code)
  144. goto done;
  145. frame = PyFrame_New(PyThreadState_Get(), code, globals, NULL);
  146. if (!frame)
  147. goto done;
  148. frame->f_lineno = lineno;
  149. PyErr_Restore(exception, value, tb);
  150. PyTraceBack_Here(frame);
  151. done:
  152. Py_XDECREF(globals);
  153. Py_XDECREF(code);
  154. Py_XDECREF(frame);
  155. }
  156. static PyObject *
  157. _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject *io)
  158. {
  159. Py_ssize_t i;
  160. PyObject *binary;
  161. PyObject *v;
  162. Py_ssize_t npath;
  163. size_t taillen;
  164. PyObject *syspath;
  165. PyObject *path;
  166. const char* tail;
  167. PyObject *filebytes;
  168. const char* filepath;
  169. Py_ssize_t len;
  170. PyObject* result;
  171. filebytes = PyUnicode_EncodeFSDefault(filename);
  172. if (filebytes == NULL) {
  173. PyErr_Clear();
  174. return NULL;
  175. }
  176. filepath = PyBytes_AS_STRING(filebytes);
  177. /* Search tail of filename in sys.path before giving up */
  178. tail = strrchr(filepath, SEP);
  179. if (tail == NULL)
  180. tail = filepath;
  181. else
  182. tail++;
  183. taillen = strlen(tail);
  184. syspath = _PySys_GetObjectId(&PyId_path);
  185. if (syspath == NULL || !PyList_Check(syspath))
  186. goto error;
  187. npath = PyList_Size(syspath);
  188. for (i = 0; i < npath; i++) {
  189. v = PyList_GetItem(syspath, i);
  190. if (v == NULL) {
  191. PyErr_Clear();
  192. break;
  193. }
  194. if (!PyUnicode_Check(v))
  195. continue;
  196. path = PyUnicode_EncodeFSDefault(v);
  197. if (path == NULL) {
  198. PyErr_Clear();
  199. continue;
  200. }
  201. len = PyBytes_GET_SIZE(path);
  202. if (len + 1 + (Py_ssize_t)taillen >= (Py_ssize_t)namelen - 1) {
  203. Py_DECREF(path);
  204. continue; /* Too long */
  205. }
  206. strcpy(namebuf, PyBytes_AS_STRING(path));
  207. Py_DECREF(path);
  208. if (strlen(namebuf) != (size_t)len)
  209. continue; /* v contains '\0' */
  210. if (len > 0 && namebuf[len-1] != SEP)
  211. namebuf[len++] = SEP;
  212. strcpy(namebuf+len, tail);
  213. binary = _PyObject_CallMethodId(io, &PyId_open, "ss", namebuf, "rb");
  214. if (binary != NULL) {
  215. result = binary;
  216. goto finally;
  217. }
  218. PyErr_Clear();
  219. }
  220. goto error;
  221. error:
  222. result = NULL;
  223. finally:
  224. Py_DECREF(filebytes);
  225. return result;
  226. }
  227. int
  228. _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
  229. {
  230. int err = 0;
  231. int fd;
  232. int i;
  233. char *found_encoding;
  234. char *encoding;
  235. PyObject *io;
  236. PyObject *binary;
  237. PyObject *fob = NULL;
  238. PyObject *lineobj = NULL;
  239. PyObject *res;
  240. char buf[MAXPATHLEN+1];
  241. int kind;
  242. void *data;
  243. /* open the file */
  244. if (filename == NULL)
  245. return 0;
  246. io = PyImport_ImportModuleNoBlock("io");
  247. if (io == NULL)
  248. return -1;
  249. binary = _PyObject_CallMethodId(io, &PyId_open, "Os", filename, "rb");
  250. if (binary == NULL) {
  251. PyErr_Clear();
  252. binary = _Py_FindSourceFile(filename, buf, sizeof(buf), io);
  253. if (binary == NULL) {
  254. Py_DECREF(io);
  255. return -1;
  256. }
  257. }
  258. /* use the right encoding to decode the file as unicode */
  259. fd = PyObject_AsFileDescriptor(binary);
  260. if (fd < 0) {
  261. Py_DECREF(io);
  262. Py_DECREF(binary);
  263. return 0;
  264. }
  265. found_encoding = PyTokenizer_FindEncodingFilename(fd, filename);
  266. if (found_encoding == NULL)
  267. PyErr_Clear();
  268. encoding = (found_encoding != NULL) ? found_encoding : "utf-8";
  269. /* Reset position */
  270. if (lseek(fd, 0, SEEK_SET) == (off_t)-1) {
  271. Py_DECREF(io);
  272. Py_DECREF(binary);
  273. PyMem_FREE(found_encoding);
  274. return 0;
  275. }
  276. fob = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "Os", binary, encoding);
  277. Py_DECREF(io);
  278. PyMem_FREE(found_encoding);
  279. if (fob == NULL) {
  280. PyErr_Clear();
  281. res = _PyObject_CallMethodId(binary, &PyId_close, "");
  282. Py_DECREF(binary);
  283. if (res)
  284. Py_DECREF(res);
  285. else
  286. PyErr_Clear();
  287. return 0;
  288. }
  289. Py_DECREF(binary);
  290. /* get the line number lineno */
  291. for (i = 0; i < lineno; i++) {
  292. Py_XDECREF(lineobj);
  293. lineobj = PyFile_GetLine(fob, -1);
  294. if (!lineobj) {
  295. PyErr_Clear();
  296. err = -1;
  297. break;
  298. }
  299. }
  300. res = _PyObject_CallMethodId(fob, &PyId_close, "");
  301. if (res)
  302. Py_DECREF(res);
  303. else
  304. PyErr_Clear();
  305. Py_DECREF(fob);
  306. if (!lineobj || !PyUnicode_Check(lineobj)) {
  307. Py_XDECREF(lineobj);
  308. return err;
  309. }
  310. /* remove the indentation of the line */
  311. kind = PyUnicode_KIND(lineobj);
  312. data = PyUnicode_DATA(lineobj);
  313. for (i=0; i < PyUnicode_GET_LENGTH(lineobj); i++) {
  314. Py_UCS4 ch = PyUnicode_READ(kind, data, i);
  315. if (ch != ' ' && ch != '\t' && ch != '\014')
  316. break;
  317. }
  318. if (i) {
  319. PyObject *truncated;
  320. truncated = PyUnicode_Substring(lineobj, i, PyUnicode_GET_LENGTH(lineobj));
  321. if (truncated) {
  322. Py_DECREF(lineobj);
  323. lineobj = truncated;
  324. } else {
  325. PyErr_Clear();
  326. }
  327. }
  328. /* Write some spaces before the line */
  329. strcpy(buf, " ");
  330. assert (strlen(buf) == 10);
  331. while (indent > 0) {
  332. if (indent < 10)
  333. buf[indent] = '\0';
  334. err = PyFile_WriteString(buf, f);
  335. if (err != 0)
  336. break;
  337. indent -= 10;
  338. }
  339. /* finally display the line */
  340. if (err == 0)
  341. err = PyFile_WriteObject(lineobj, f, Py_PRINT_RAW);
  342. Py_DECREF(lineobj);
  343. if (err == 0)
  344. err = PyFile_WriteString("\n", f);
  345. return err;
  346. }
  347. static int
  348. tb_displayline(PyObject *f, PyObject *filename, int lineno, PyObject *name)
  349. {
  350. int err;
  351. PyObject *line;
  352. if (filename == NULL || name == NULL)
  353. return -1;
  354. line = PyUnicode_FromFormat(" File \"%U\", line %d, in %U\n",
  355. filename, lineno, name);
  356. if (line == NULL)
  357. return -1;
  358. err = PyFile_WriteObject(line, f, Py_PRINT_RAW);
  359. Py_DECREF(line);
  360. if (err != 0)
  361. return err;
  362. /* ignore errors since we can't report them, can we? */
  363. if (_Py_DisplaySourceLine(f, filename, lineno, 4))
  364. PyErr_Clear();
  365. return err;
  366. }
  367. static int
  368. tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit)
  369. {
  370. int err = 0;
  371. long depth = 0;
  372. PyTracebackObject *tb1 = tb;
  373. while (tb1 != NULL) {
  374. depth++;
  375. tb1 = tb1->tb_next;
  376. }
  377. while (tb != NULL && err == 0) {
  378. if (depth <= limit) {
  379. err = tb_displayline(f,
  380. tb->tb_frame->f_code->co_filename,
  381. tb->tb_lineno,
  382. tb->tb_frame->f_code->co_name);
  383. }
  384. depth--;
  385. tb = tb->tb_next;
  386. if (err == 0)
  387. err = PyErr_CheckSignals();
  388. }
  389. return err;
  390. }
  391. #define PyTraceBack_LIMIT 1000
  392. int
  393. PyTraceBack_Print(PyObject *v, PyObject *f)
  394. {
  395. int err;
  396. PyObject *limitv;
  397. long limit = PyTraceBack_LIMIT;
  398. if (v == NULL)
  399. return 0;
  400. if (!PyTraceBack_Check(v)) {
  401. PyErr_BadInternalCall();
  402. return -1;
  403. }
  404. limitv = PySys_GetObject("tracebacklimit");
  405. if (limitv) {
  406. PyObject *exc_type, *exc_value, *exc_tb;
  407. PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
  408. limit = PyLong_AsLong(limitv);
  409. if (limit == -1 && PyErr_Occurred()) {
  410. if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
  411. limit = PyTraceBack_LIMIT;
  412. }
  413. else {
  414. Py_XDECREF(exc_type);
  415. Py_XDECREF(exc_value);
  416. Py_XDECREF(exc_tb);
  417. return 0;
  418. }
  419. }
  420. else if (limit <= 0) {
  421. limit = PyTraceBack_LIMIT;
  422. }
  423. PyErr_Restore(exc_type, exc_value, exc_tb);
  424. }
  425. err = PyFile_WriteString("Traceback (most recent call last):\n", f);
  426. if (!err)
  427. err = tb_printinternal((PyTracebackObject *)v, f, limit);
  428. return err;
  429. }
  430. /* Reverse a string. For example, "abcd" becomes "dcba".
  431. This function is signal safe. */
  432. void
  433. _Py_DumpDecimal(int fd, unsigned long value)
  434. {
  435. /* maximum number of characters required for output of %lld or %p.
  436. We need at most ceil(log10(256)*SIZEOF_LONG_LONG) digits,
  437. plus 1 for the null byte. 53/22 is an upper bound for log10(256). */
  438. char buffer[1 + (sizeof(unsigned long)*53-1) / 22 + 1];
  439. char *ptr, *end;
  440. end = &buffer[Py_ARRAY_LENGTH(buffer) - 1];
  441. ptr = end;
  442. *ptr = '\0';
  443. do {
  444. --ptr;
  445. assert(ptr >= buffer);
  446. *ptr = '0' + (value % 10);
  447. value /= 10;
  448. } while (value);
  449. _Py_write_noraise(fd, ptr, end - ptr);
  450. }
  451. /* Format an integer in range [0; 0xffffffff] to hexadecimal of 'width' digits,
  452. and write it into the file fd.
  453. This function is signal safe. */
  454. void
  455. _Py_DumpHexadecimal(int fd, unsigned long value, Py_ssize_t width)
  456. {
  457. char buffer[sizeof(unsigned long) * 2 + 1], *ptr, *end;
  458. const Py_ssize_t size = Py_ARRAY_LENGTH(buffer) - 1;
  459. if (width > size)
  460. width = size;
  461. /* it's ok if width is negative */
  462. end = &buffer[size];
  463. ptr = end;
  464. *ptr = '\0';
  465. do {
  466. --ptr;
  467. assert(ptr >= buffer);
  468. *ptr = Py_hexdigits[value & 15];
  469. value >>= 4;
  470. } while ((end - ptr) < width || value);
  471. _Py_write_noraise(fd, ptr, end - ptr);
  472. }
  473. void
  474. _Py_DumpASCII(int fd, PyObject *text)
  475. {
  476. PyASCIIObject *ascii = (PyASCIIObject *)text;
  477. Py_ssize_t i, size;
  478. int truncated;
  479. int kind;
  480. void *data = NULL;
  481. wchar_t *wstr = NULL;
  482. Py_UCS4 ch;
  483. if (!PyUnicode_Check(text))
  484. return;
  485. size = ascii->length;
  486. kind = ascii->state.kind;
  487. if (kind == PyUnicode_WCHAR_KIND) {
  488. wstr = ((PyASCIIObject *)text)->wstr;
  489. if (wstr == NULL)
  490. return;
  491. size = ((PyCompactUnicodeObject *)text)->wstr_length;
  492. }
  493. else if (ascii->state.compact) {
  494. if (ascii->state.ascii)
  495. data = ((PyASCIIObject*)text) + 1;
  496. else
  497. data = ((PyCompactUnicodeObject*)text) + 1;
  498. }
  499. else {
  500. data = ((PyUnicodeObject *)text)->data.any;
  501. if (data == NULL)
  502. return;
  503. }
  504. if (MAX_STRING_LENGTH < size) {
  505. size = MAX_STRING_LENGTH;
  506. truncated = 1;
  507. }
  508. else {
  509. truncated = 0;
  510. }
  511. for (i=0; i < size; i++) {
  512. if (kind != PyUnicode_WCHAR_KIND)
  513. ch = PyUnicode_READ(kind, data, i);
  514. else
  515. ch = wstr[i];
  516. if (' ' <= ch && ch <= 126) {
  517. /* printable ASCII character */
  518. char c = (char)ch;
  519. _Py_write_noraise(fd, &c, 1);
  520. }
  521. else if (ch <= 0xff) {
  522. PUTS(fd, "\\x");
  523. _Py_DumpHexadecimal(fd, ch, 2);
  524. }
  525. else if (ch <= 0xffff) {
  526. PUTS(fd, "\\u");
  527. _Py_DumpHexadecimal(fd, ch, 4);
  528. }
  529. else {
  530. PUTS(fd, "\\U");
  531. _Py_DumpHexadecimal(fd, ch, 8);
  532. }
  533. }
  534. if (truncated) {
  535. PUTS(fd, "...");
  536. }
  537. }
  538. /* Write a frame into the file fd: "File "xxx", line xxx in xxx".
  539. This function is signal safe. */
  540. static void
  541. dump_frame(int fd, PyFrameObject *frame)
  542. {
  543. PyCodeObject *code;
  544. int lineno;
  545. code = frame->f_code;
  546. PUTS(fd, " File ");
  547. if (code != NULL && code->co_filename != NULL
  548. && PyUnicode_Check(code->co_filename))
  549. {
  550. PUTS(fd, "\"");
  551. _Py_DumpASCII(fd, code->co_filename);
  552. PUTS(fd, "\"");
  553. } else {
  554. PUTS(fd, "???");
  555. }
  556. /* PyFrame_GetLineNumber() was introduced in Python 2.7.0 and 3.2.0 */
  557. lineno = PyCode_Addr2Line(code, frame->f_lasti);
  558. PUTS(fd, ", line ");
  559. if (lineno >= 0) {
  560. _Py_DumpDecimal(fd, (unsigned long)lineno);
  561. }
  562. else {
  563. PUTS(fd, "???");
  564. }
  565. PUTS(fd, " in ");
  566. if (code != NULL && code->co_name != NULL
  567. && PyUnicode_Check(code->co_name)) {
  568. _Py_DumpASCII(fd, code->co_name);
  569. }
  570. else {
  571. PUTS(fd, "???");
  572. }
  573. PUTS(fd, "\n");
  574. }
  575. static void
  576. dump_traceback(int fd, PyThreadState *tstate, int write_header)
  577. {
  578. PyFrameObject *frame;
  579. unsigned int depth;
  580. if (write_header)
  581. PUTS(fd, "Stack (most recent call first):\n");
  582. frame = _PyThreadState_GetFrame(tstate);
  583. if (frame == NULL)
  584. return;
  585. depth = 0;
  586. while (frame != NULL) {
  587. if (MAX_FRAME_DEPTH <= depth) {
  588. PUTS(fd, " ...\n");
  589. break;
  590. }
  591. if (!PyFrame_Check(frame))
  592. break;
  593. dump_frame(fd, frame);
  594. frame = frame->f_back;
  595. depth++;
  596. }
  597. }
  598. /* Dump the traceback of a Python thread into fd. Use write() to write the
  599. traceback and retry if write() is interrupted by a signal (failed with
  600. EINTR), but don't call the Python signal handler.
  601. The caller is responsible to call PyErr_CheckSignals() to call Python signal
  602. handlers if signals were received. */
  603. void
  604. _Py_DumpTraceback(int fd, PyThreadState *tstate)
  605. {
  606. dump_traceback(fd, tstate, 1);
  607. }
  608. /* Write the thread identifier into the file 'fd': "Current thread 0xHHHH:\" if
  609. is_current is true, "Thread 0xHHHH:\n" otherwise.
  610. This function is signal safe. */
  611. static void
  612. write_thread_id(int fd, PyThreadState *tstate, int is_current)
  613. {
  614. if (is_current)
  615. PUTS(fd, "Current thread 0x");
  616. else
  617. PUTS(fd, "Thread 0x");
  618. _Py_DumpHexadecimal(fd,
  619. (unsigned long)tstate->thread_id,
  620. sizeof(unsigned long) * 2);
  621. PUTS(fd, " (most recent call first):\n");
  622. }
  623. /* Dump the traceback of all Python threads into fd. Use write() to write the
  624. traceback and retry if write() is interrupted by a signal (failed with
  625. EINTR), but don't call the Python signal handler.
  626. The caller is responsible to call PyErr_CheckSignals() to call Python signal
  627. handlers if signals were received. */
  628. const char*
  629. _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
  630. PyThreadState *current_tstate)
  631. {
  632. PyThreadState *tstate;
  633. unsigned int nthreads;
  634. #ifdef WITH_THREAD
  635. if (current_tstate == NULL) {
  636. /* _Py_DumpTracebackThreads() is called from signal handlers by
  637. faulthandler.
  638. SIGSEGV, SIGFPE, SIGABRT, SIGBUS and SIGILL are synchronous signals
  639. and are thus delivered to the thread that caused the fault. Get the
  640. Python thread state of the current thread.
  641. PyThreadState_Get() doesn't give the state of the thread that caused
  642. the fault if the thread released the GIL, and so this function
  643. cannot be used. Read the thread local storage (TLS) instead: call
  644. PyGILState_GetThisThreadState(). */
  645. current_tstate = PyGILState_GetThisThreadState();
  646. }
  647. if (interp == NULL) {
  648. if (current_tstate == NULL) {
  649. interp = _PyGILState_GetInterpreterStateUnsafe();
  650. if (interp == NULL) {
  651. /* We need the interpreter state to get Python threads */
  652. return "unable to get the interpreter state";
  653. }
  654. }
  655. else {
  656. interp = current_tstate->interp;
  657. }
  658. }
  659. #else
  660. if (current_tstate == NULL) {
  661. /* Call _PyThreadState_UncheckedGet() instead of PyThreadState_Get()
  662. to not fail with a fatal error if the thread state is NULL. */
  663. current_thread = _PyThreadState_UncheckedGet();
  664. }
  665. if (interp == NULL) {
  666. if (current_tstate == NULL) {
  667. /* We need the interpreter state to get Python threads */
  668. return "unable to get the interpreter state";
  669. }
  670. interp = current_tstate->interp;
  671. }
  672. #endif
  673. assert(interp != NULL);
  674. /* Get the current interpreter from the current thread */
  675. tstate = PyInterpreterState_ThreadHead(interp);
  676. if (tstate == NULL)
  677. return "unable to get the thread head state";
  678. /* Dump the traceback of each thread */
  679. tstate = PyInterpreterState_ThreadHead(interp);
  680. nthreads = 0;
  681. _Py_BEGIN_SUPPRESS_IPH
  682. do
  683. {
  684. if (nthreads != 0)
  685. PUTS(fd, "\n");
  686. if (nthreads >= MAX_NTHREADS) {
  687. PUTS(fd, "...\n");
  688. break;
  689. }
  690. write_thread_id(fd, tstate, tstate == current_tstate);
  691. dump_traceback(fd, tstate, 0);
  692. tstate = PyThreadState_Next(tstate);
  693. nthreads++;
  694. } while (tstate != NULL);
  695. _Py_END_SUPPRESS_IPH
  696. return NULL;
  697. }