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.

738 lines
19 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. static void
  433. reverse_string(char *text, const size_t len)
  434. {
  435. char tmp;
  436. size_t i, j;
  437. if (len == 0)
  438. return;
  439. for (i=0, j=len-1; i < j; i++, j--) {
  440. tmp = text[i];
  441. text[i] = text[j];
  442. text[j] = tmp;
  443. }
  444. }
  445. /* Format an integer in range [0; 999999] to decimal,
  446. and write it into the file fd.
  447. This function is signal safe. */
  448. static void
  449. dump_decimal(int fd, int value)
  450. {
  451. char buffer[7];
  452. int len;
  453. if (value < 0 || 999999 < value)
  454. return;
  455. len = 0;
  456. do {
  457. buffer[len] = '0' + (value % 10);
  458. value /= 10;
  459. len++;
  460. } while (value);
  461. reverse_string(buffer, len);
  462. _Py_write_noraise(fd, buffer, len);
  463. }
  464. /* Format an integer in range [0; 0xffffffff] to hexadecimal of 'width' digits,
  465. and write it into the file fd.
  466. This function is signal safe. */
  467. static void
  468. dump_hexadecimal(int fd, unsigned long value, int width)
  469. {
  470. int len;
  471. char buffer[sizeof(unsigned long) * 2 + 1];
  472. len = 0;
  473. do {
  474. buffer[len] = Py_hexdigits[value & 15];
  475. value >>= 4;
  476. len++;
  477. } while (len < width || value);
  478. reverse_string(buffer, len);
  479. _Py_write_noraise(fd, buffer, len);
  480. }
  481. /* Write an unicode object into the file fd using ascii+backslashreplace.
  482. This function is signal safe. */
  483. static void
  484. dump_ascii(int fd, PyObject *text)
  485. {
  486. PyASCIIObject *ascii = (PyASCIIObject *)text;
  487. Py_ssize_t i, size;
  488. int truncated;
  489. int kind;
  490. void *data = NULL;
  491. wchar_t *wstr = NULL;
  492. Py_UCS4 ch;
  493. size = ascii->length;
  494. kind = ascii->state.kind;
  495. if (ascii->state.compact) {
  496. if (ascii->state.ascii)
  497. data = ((PyASCIIObject*)text) + 1;
  498. else
  499. data = ((PyCompactUnicodeObject*)text) + 1;
  500. }
  501. else if (kind != PyUnicode_WCHAR_KIND) {
  502. data = ((PyUnicodeObject *)text)->data.any;
  503. if (data == NULL)
  504. return;
  505. }
  506. else {
  507. wstr = ((PyASCIIObject *)text)->wstr;
  508. if (wstr == NULL)
  509. return;
  510. size = ((PyCompactUnicodeObject *)text)->wstr_length;
  511. }
  512. if (MAX_STRING_LENGTH < size) {
  513. size = MAX_STRING_LENGTH;
  514. truncated = 1;
  515. }
  516. else
  517. truncated = 0;
  518. for (i=0; i < size; i++) {
  519. if (kind != PyUnicode_WCHAR_KIND)
  520. ch = PyUnicode_READ(kind, data, i);
  521. else
  522. ch = wstr[i];
  523. if (' ' <= ch && ch <= 126) {
  524. /* printable ASCII character */
  525. char c = (char)ch;
  526. _Py_write_noraise(fd, &c, 1);
  527. }
  528. else if (ch <= 0xff) {
  529. PUTS(fd, "\\x");
  530. dump_hexadecimal(fd, ch, 2);
  531. }
  532. else if (ch <= 0xffff) {
  533. PUTS(fd, "\\u");
  534. dump_hexadecimal(fd, ch, 4);
  535. }
  536. else {
  537. PUTS(fd, "\\U");
  538. dump_hexadecimal(fd, ch, 8);
  539. }
  540. }
  541. if (truncated)
  542. PUTS(fd, "...");
  543. }
  544. /* Write a frame into the file fd: "File "xxx", line xxx in xxx".
  545. This function is signal safe. */
  546. static void
  547. dump_frame(int fd, PyFrameObject *frame)
  548. {
  549. PyCodeObject *code;
  550. int lineno;
  551. code = frame->f_code;
  552. PUTS(fd, " File ");
  553. if (code != NULL && code->co_filename != NULL
  554. && PyUnicode_Check(code->co_filename))
  555. {
  556. PUTS(fd, "\"");
  557. dump_ascii(fd, code->co_filename);
  558. PUTS(fd, "\"");
  559. } else {
  560. PUTS(fd, "???");
  561. }
  562. /* PyFrame_GetLineNumber() was introduced in Python 2.7.0 and 3.2.0 */
  563. lineno = PyCode_Addr2Line(code, frame->f_lasti);
  564. PUTS(fd, ", line ");
  565. dump_decimal(fd, lineno);
  566. PUTS(fd, " in ");
  567. if (code != NULL && code->co_name != NULL
  568. && PyUnicode_Check(code->co_name))
  569. dump_ascii(fd, code->co_name);
  570. else
  571. PUTS(fd, "???");
  572. PUTS(fd, "\n");
  573. }
  574. static void
  575. dump_traceback(int fd, PyThreadState *tstate, int write_header)
  576. {
  577. PyFrameObject *frame;
  578. unsigned int depth;
  579. if (write_header)
  580. PUTS(fd, "Stack (most recent call first):\n");
  581. frame = _PyThreadState_GetFrame(tstate);
  582. if (frame == NULL)
  583. return;
  584. depth = 0;
  585. while (frame != NULL) {
  586. if (MAX_FRAME_DEPTH <= depth) {
  587. PUTS(fd, " ...\n");
  588. break;
  589. }
  590. if (!PyFrame_Check(frame))
  591. break;
  592. dump_frame(fd, frame);
  593. frame = frame->f_back;
  594. depth++;
  595. }
  596. }
  597. /* Dump the traceback of a Python thread into fd. Use write() to write the
  598. traceback and retry if write() is interrupted by a signal (failed with
  599. EINTR), but don't call the Python signal handler.
  600. The caller is responsible to call PyErr_CheckSignals() to call Python signal
  601. handlers if signals were received. */
  602. void
  603. _Py_DumpTraceback(int fd, PyThreadState *tstate)
  604. {
  605. dump_traceback(fd, tstate, 1);
  606. }
  607. /* Write the thread identifier into the file 'fd': "Current thread 0xHHHH:\" if
  608. is_current is true, "Thread 0xHHHH:\n" otherwise.
  609. This function is signal safe. */
  610. static void
  611. write_thread_id(int fd, PyThreadState *tstate, int is_current)
  612. {
  613. if (is_current)
  614. PUTS(fd, "Current thread 0x");
  615. else
  616. PUTS(fd, "Thread 0x");
  617. dump_hexadecimal(fd, (unsigned long)tstate->thread_id, sizeof(unsigned long)*2);
  618. PUTS(fd, " (most recent call first):\n");
  619. }
  620. /* Dump the traceback of all Python threads into fd. Use write() to write the
  621. traceback and retry if write() is interrupted by a signal (failed with
  622. EINTR), but don't call the Python signal handler.
  623. The caller is responsible to call PyErr_CheckSignals() to call Python signal
  624. handlers if signals were received. */
  625. const char*
  626. _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
  627. PyThreadState *current_thread)
  628. {
  629. PyThreadState *tstate;
  630. unsigned int nthreads;
  631. /* Get the current interpreter from the current thread */
  632. tstate = PyInterpreterState_ThreadHead(interp);
  633. if (tstate == NULL)
  634. return "unable to get the thread head state";
  635. /* Dump the traceback of each thread */
  636. tstate = PyInterpreterState_ThreadHead(interp);
  637. nthreads = 0;
  638. _Py_BEGIN_SUPPRESS_IPH
  639. do
  640. {
  641. if (nthreads != 0)
  642. PUTS(fd, "\n");
  643. if (nthreads >= MAX_NTHREADS) {
  644. PUTS(fd, "...\n");
  645. break;
  646. }
  647. write_thread_id(fd, tstate, tstate == current_thread);
  648. dump_traceback(fd, tstate, 0);
  649. tstate = PyThreadState_Next(tstate);
  650. nthreads++;
  651. } while (tstate != NULL);
  652. _Py_END_SUPPRESS_IPH
  653. return NULL;
  654. }