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.

663 lines
17 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
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) write(fd, str, strlen(str))
  12. #define MAX_STRING_LENGTH 100
  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. static PyObject *
  18. tb_dir(PyTracebackObject *self)
  19. {
  20. return Py_BuildValue("[ssss]", "tb_frame", "tb_next",
  21. "tb_lasti", "tb_lineno");
  22. }
  23. static PyMethodDef tb_methods[] = {
  24. {"__dir__", (PyCFunction)tb_dir, METH_NOARGS},
  25. {NULL, NULL, 0, NULL},
  26. };
  27. static PyMemberDef tb_memberlist[] = {
  28. {"tb_next", T_OBJECT, OFF(tb_next), READONLY},
  29. {"tb_frame", T_OBJECT, OFF(tb_frame), READONLY},
  30. {"tb_lasti", T_INT, OFF(tb_lasti), READONLY},
  31. {"tb_lineno", T_INT, OFF(tb_lineno), READONLY},
  32. {NULL} /* Sentinel */
  33. };
  34. static void
  35. tb_dealloc(PyTracebackObject *tb)
  36. {
  37. PyObject_GC_UnTrack(tb);
  38. Py_TRASHCAN_SAFE_BEGIN(tb)
  39. Py_XDECREF(tb->tb_next);
  40. Py_XDECREF(tb->tb_frame);
  41. PyObject_GC_Del(tb);
  42. Py_TRASHCAN_SAFE_END(tb)
  43. }
  44. static int
  45. tb_traverse(PyTracebackObject *tb, visitproc visit, void *arg)
  46. {
  47. Py_VISIT(tb->tb_next);
  48. Py_VISIT(tb->tb_frame);
  49. return 0;
  50. }
  51. static void
  52. tb_clear(PyTracebackObject *tb)
  53. {
  54. Py_CLEAR(tb->tb_next);
  55. Py_CLEAR(tb->tb_frame);
  56. }
  57. PyTypeObject PyTraceBack_Type = {
  58. PyVarObject_HEAD_INIT(&PyType_Type, 0)
  59. "traceback",
  60. sizeof(PyTracebackObject),
  61. 0,
  62. (destructor)tb_dealloc, /*tp_dealloc*/
  63. 0, /*tp_print*/
  64. 0, /*tp_getattr*/
  65. 0, /*tp_setattr*/
  66. 0, /*tp_reserved*/
  67. 0, /*tp_repr*/
  68. 0, /*tp_as_number*/
  69. 0, /*tp_as_sequence*/
  70. 0, /*tp_as_mapping*/
  71. 0, /* tp_hash */
  72. 0, /* tp_call */
  73. 0, /* tp_str */
  74. PyObject_GenericGetAttr, /* tp_getattro */
  75. 0, /* tp_setattro */
  76. 0, /* tp_as_buffer */
  77. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
  78. 0, /* tp_doc */
  79. (traverseproc)tb_traverse, /* tp_traverse */
  80. (inquiry)tb_clear, /* tp_clear */
  81. 0, /* tp_richcompare */
  82. 0, /* tp_weaklistoffset */
  83. 0, /* tp_iter */
  84. 0, /* tp_iternext */
  85. tb_methods, /* tp_methods */
  86. tb_memberlist, /* tp_members */
  87. 0, /* tp_getset */
  88. 0, /* tp_base */
  89. 0, /* tp_dict */
  90. };
  91. static PyTracebackObject *
  92. newtracebackobject(PyTracebackObject *next, PyFrameObject *frame)
  93. {
  94. PyTracebackObject *tb;
  95. if ((next != NULL && !PyTraceBack_Check(next)) ||
  96. frame == NULL || !PyFrame_Check(frame)) {
  97. PyErr_BadInternalCall();
  98. return NULL;
  99. }
  100. tb = PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type);
  101. if (tb != NULL) {
  102. Py_XINCREF(next);
  103. tb->tb_next = next;
  104. Py_XINCREF(frame);
  105. tb->tb_frame = frame;
  106. tb->tb_lasti = frame->f_lasti;
  107. tb->tb_lineno = PyFrame_GetLineNumber(frame);
  108. PyObject_GC_Track(tb);
  109. }
  110. return tb;
  111. }
  112. int
  113. PyTraceBack_Here(PyFrameObject *frame)
  114. {
  115. PyThreadState *tstate = PyThreadState_GET();
  116. PyTracebackObject *oldtb = (PyTracebackObject *) tstate->curexc_traceback;
  117. PyTracebackObject *tb = newtracebackobject(oldtb, frame);
  118. if (tb == NULL)
  119. return -1;
  120. tstate->curexc_traceback = (PyObject *)tb;
  121. Py_XDECREF(oldtb);
  122. return 0;
  123. }
  124. static PyObject *
  125. _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject *io)
  126. {
  127. Py_ssize_t i;
  128. PyObject *binary;
  129. PyObject *v;
  130. Py_ssize_t npath;
  131. size_t taillen;
  132. PyObject *syspath;
  133. PyObject *path;
  134. const char* tail;
  135. PyObject *filebytes;
  136. const char* filepath;
  137. Py_ssize_t len;
  138. PyObject* result;
  139. _Py_IDENTIFIER(open);
  140. filebytes = PyUnicode_EncodeFSDefault(filename);
  141. if (filebytes == NULL) {
  142. PyErr_Clear();
  143. return NULL;
  144. }
  145. filepath = PyBytes_AS_STRING(filebytes);
  146. /* Search tail of filename in sys.path before giving up */
  147. tail = strrchr(filepath, SEP);
  148. if (tail == NULL)
  149. tail = filepath;
  150. else
  151. tail++;
  152. taillen = strlen(tail);
  153. syspath = PySys_GetObject("path");
  154. if (syspath == NULL || !PyList_Check(syspath))
  155. goto error;
  156. npath = PyList_Size(syspath);
  157. for (i = 0; i < npath; i++) {
  158. v = PyList_GetItem(syspath, i);
  159. if (v == NULL) {
  160. PyErr_Clear();
  161. break;
  162. }
  163. if (!PyUnicode_Check(v))
  164. continue;
  165. path = PyUnicode_EncodeFSDefault(v);
  166. if (path == NULL) {
  167. PyErr_Clear();
  168. continue;
  169. }
  170. len = PyBytes_GET_SIZE(path);
  171. if (len + 1 + (Py_ssize_t)taillen >= (Py_ssize_t)namelen - 1) {
  172. Py_DECREF(path);
  173. continue; /* Too long */
  174. }
  175. strcpy(namebuf, PyBytes_AS_STRING(path));
  176. Py_DECREF(path);
  177. if (strlen(namebuf) != len)
  178. continue; /* v contains '\0' */
  179. if (len > 0 && namebuf[len-1] != SEP)
  180. namebuf[len++] = SEP;
  181. strcpy(namebuf+len, tail);
  182. binary = _PyObject_CallMethodId(io, &PyId_open, "ss", namebuf, "rb");
  183. if (binary != NULL) {
  184. result = binary;
  185. goto finally;
  186. }
  187. PyErr_Clear();
  188. }
  189. goto error;
  190. error:
  191. result = NULL;
  192. finally:
  193. Py_DECREF(filebytes);
  194. return result;
  195. }
  196. int
  197. _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
  198. {
  199. int err = 0;
  200. int fd;
  201. int i;
  202. char *found_encoding;
  203. char *encoding;
  204. PyObject *io;
  205. PyObject *binary;
  206. PyObject *fob = NULL;
  207. PyObject *lineobj = NULL;
  208. PyObject *res;
  209. char buf[MAXPATHLEN+1];
  210. int kind;
  211. void *data;
  212. _Py_IDENTIFIER(close);
  213. _Py_IDENTIFIER(open);
  214. _Py_IDENTIFIER(TextIOWrapper);
  215. /* open the file */
  216. if (filename == NULL)
  217. return 0;
  218. io = PyImport_ImportModuleNoBlock("io");
  219. if (io == NULL)
  220. return -1;
  221. binary = _PyObject_CallMethodId(io, &PyId_open, "Os", filename, "rb");
  222. if (binary == NULL) {
  223. binary = _Py_FindSourceFile(filename, buf, sizeof(buf), io);
  224. if (binary == NULL) {
  225. Py_DECREF(io);
  226. return 0;
  227. }
  228. }
  229. /* use the right encoding to decode the file as unicode */
  230. fd = PyObject_AsFileDescriptor(binary);
  231. found_encoding = PyTokenizer_FindEncodingFilename(fd, filename);
  232. encoding = (found_encoding != NULL) ? found_encoding : "utf-8";
  233. lseek(fd, 0, 0); /* Reset position */
  234. fob = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "Os", binary, encoding);
  235. Py_DECREF(io);
  236. Py_DECREF(binary);
  237. PyMem_FREE(found_encoding);
  238. if (fob == NULL) {
  239. PyErr_Clear();
  240. return 0;
  241. }
  242. /* get the line number lineno */
  243. for (i = 0; i < lineno; i++) {
  244. Py_XDECREF(lineobj);
  245. lineobj = PyFile_GetLine(fob, -1);
  246. if (!lineobj) {
  247. err = -1;
  248. break;
  249. }
  250. }
  251. res = _PyObject_CallMethodId(fob, &PyId_close, "");
  252. if (res)
  253. Py_DECREF(res);
  254. else
  255. PyErr_Clear();
  256. Py_DECREF(fob);
  257. if (!lineobj || !PyUnicode_Check(lineobj)) {
  258. Py_XDECREF(lineobj);
  259. return err;
  260. }
  261. /* remove the indentation of the line */
  262. kind = PyUnicode_KIND(lineobj);
  263. data = PyUnicode_DATA(lineobj);
  264. for (i=0; i < PyUnicode_GET_LENGTH(lineobj); i++) {
  265. Py_UCS4 ch = PyUnicode_READ(kind, data, i);
  266. if (ch != ' ' && ch != '\t' && ch != '\014')
  267. break;
  268. }
  269. if (i) {
  270. PyObject *truncated;
  271. truncated = PyUnicode_Substring(lineobj, i, PyUnicode_GET_LENGTH(lineobj));
  272. if (truncated) {
  273. Py_DECREF(lineobj);
  274. lineobj = truncated;
  275. } else {
  276. PyErr_Clear();
  277. }
  278. }
  279. /* Write some spaces before the line */
  280. strcpy(buf, " ");
  281. assert (strlen(buf) == 10);
  282. while (indent > 0) {
  283. if(indent < 10)
  284. buf[indent] = '\0';
  285. err = PyFile_WriteString(buf, f);
  286. if (err != 0)
  287. break;
  288. indent -= 10;
  289. }
  290. /* finally display the line */
  291. if (err == 0)
  292. err = PyFile_WriteObject(lineobj, f, Py_PRINT_RAW);
  293. Py_DECREF(lineobj);
  294. if (err == 0)
  295. err = PyFile_WriteString("\n", f);
  296. return err;
  297. }
  298. static int
  299. tb_displayline(PyObject *f, PyObject *filename, int lineno, PyObject *name)
  300. {
  301. int err;
  302. PyObject *line;
  303. if (filename == NULL || name == NULL)
  304. return -1;
  305. line = PyUnicode_FromFormat(" File \"%U\", line %d, in %U\n",
  306. filename, lineno, name);
  307. if (line == NULL)
  308. return -1;
  309. err = PyFile_WriteObject(line, f, Py_PRINT_RAW);
  310. Py_DECREF(line);
  311. if (err != 0)
  312. return err;
  313. return _Py_DisplaySourceLine(f, filename, lineno, 4);
  314. }
  315. static int
  316. tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit)
  317. {
  318. int err = 0;
  319. long depth = 0;
  320. PyTracebackObject *tb1 = tb;
  321. while (tb1 != NULL) {
  322. depth++;
  323. tb1 = tb1->tb_next;
  324. }
  325. while (tb != NULL && err == 0) {
  326. if (depth <= limit) {
  327. err = tb_displayline(f,
  328. tb->tb_frame->f_code->co_filename,
  329. tb->tb_lineno,
  330. tb->tb_frame->f_code->co_name);
  331. }
  332. depth--;
  333. tb = tb->tb_next;
  334. if (err == 0)
  335. err = PyErr_CheckSignals();
  336. }
  337. return err;
  338. }
  339. #define PyTraceBack_LIMIT 1000
  340. int
  341. PyTraceBack_Print(PyObject *v, PyObject *f)
  342. {
  343. int err;
  344. PyObject *limitv;
  345. long limit = PyTraceBack_LIMIT;
  346. if (v == NULL)
  347. return 0;
  348. if (!PyTraceBack_Check(v)) {
  349. PyErr_BadInternalCall();
  350. return -1;
  351. }
  352. limitv = PySys_GetObject("tracebacklimit");
  353. if (limitv) {
  354. PyObject *exc_type, *exc_value, *exc_tb;
  355. PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
  356. limit = PyLong_AsLong(limitv);
  357. if (limit == -1 && PyErr_Occurred()) {
  358. if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
  359. limit = PyTraceBack_LIMIT;
  360. }
  361. else {
  362. Py_XDECREF(exc_type);
  363. Py_XDECREF(exc_value);
  364. Py_XDECREF(exc_tb);
  365. return 0;
  366. }
  367. }
  368. else if (limit <= 0) {
  369. limit = PyTraceBack_LIMIT;
  370. }
  371. PyErr_Restore(exc_type, exc_value, exc_tb);
  372. }
  373. err = PyFile_WriteString("Traceback (most recent call last):\n", f);
  374. if (!err)
  375. err = tb_printinternal((PyTracebackObject *)v, f, limit);
  376. return err;
  377. }
  378. /* Reverse a string. For example, "abcd" becomes "dcba".
  379. This function is signal safe. */
  380. static void
  381. reverse_string(char *text, const size_t len)
  382. {
  383. char tmp;
  384. size_t i, j;
  385. if (len == 0)
  386. return;
  387. for (i=0, j=len-1; i < j; i++, j--) {
  388. tmp = text[i];
  389. text[i] = text[j];
  390. text[j] = tmp;
  391. }
  392. }
  393. /* Format an integer in range [0; 999999] to decimal,
  394. and write it into the file fd.
  395. This function is signal safe. */
  396. static void
  397. dump_decimal(int fd, int value)
  398. {
  399. char buffer[7];
  400. int len;
  401. if (value < 0 || 999999 < value)
  402. return;
  403. len = 0;
  404. do {
  405. buffer[len] = '0' + (value % 10);
  406. value /= 10;
  407. len++;
  408. } while (value);
  409. reverse_string(buffer, len);
  410. write(fd, buffer, len);
  411. }
  412. /* Format an integer in range [0; 0xffffffff] to hexdecimal of 'width' digits,
  413. and write it into the file fd.
  414. This function is signal safe. */
  415. static void
  416. dump_hexadecimal(int width, unsigned long value, int fd)
  417. {
  418. int len;
  419. char buffer[sizeof(unsigned long) * 2 + 1];
  420. len = 0;
  421. do {
  422. buffer[len] = Py_hexdigits[value & 15];
  423. value >>= 4;
  424. len++;
  425. } while (len < width || value);
  426. reverse_string(buffer, len);
  427. write(fd, buffer, len);
  428. }
  429. /* Write an unicode object into the file fd using ascii+backslashreplace.
  430. This function is signal safe. */
  431. static void
  432. dump_ascii(int fd, PyObject *text)
  433. {
  434. PyASCIIObject *ascii = (PyASCIIObject *)text;
  435. Py_ssize_t i, size;
  436. int truncated;
  437. int kind;
  438. void *data = NULL;
  439. wchar_t *wstr = NULL;
  440. Py_UCS4 ch;
  441. size = ascii->length;
  442. kind = ascii->state.kind;
  443. if (ascii->state.compact) {
  444. if (ascii->state.ascii)
  445. data = ((PyASCIIObject*)text) + 1;
  446. else
  447. data = ((PyCompactUnicodeObject*)text) + 1;
  448. }
  449. else if (kind != PyUnicode_WCHAR_KIND) {
  450. data = ((PyUnicodeObject *)text)->data.any;
  451. if (data == NULL)
  452. return;
  453. }
  454. else {
  455. wstr = ((PyASCIIObject *)text)->wstr;
  456. if (wstr == NULL)
  457. return;
  458. size = ((PyCompactUnicodeObject *)text)->wstr_length;
  459. }
  460. if (MAX_STRING_LENGTH < size) {
  461. size = MAX_STRING_LENGTH;
  462. truncated = 1;
  463. }
  464. else
  465. truncated = 0;
  466. for (i=0; i < size; i++) {
  467. if (kind != PyUnicode_WCHAR_KIND)
  468. ch = PyUnicode_READ(kind, data, i);
  469. else
  470. ch = wstr[i];
  471. if (ch < 128) {
  472. char c = (char)ch;
  473. write(fd, &c, 1);
  474. }
  475. else if (ch < 0xff) {
  476. PUTS(fd, "\\x");
  477. dump_hexadecimal(2, ch, fd);
  478. }
  479. else if (ch < 0xffff) {
  480. PUTS(fd, "\\u");
  481. dump_hexadecimal(4, ch, fd);
  482. }
  483. else {
  484. PUTS(fd, "\\U");
  485. dump_hexadecimal(8, ch, fd);
  486. }
  487. }
  488. if (truncated)
  489. PUTS(fd, "...");
  490. }
  491. /* Write a frame into the file fd: "File "xxx", line xxx in xxx".
  492. This function is signal safe. */
  493. static void
  494. dump_frame(int fd, PyFrameObject *frame)
  495. {
  496. PyCodeObject *code;
  497. int lineno;
  498. code = frame->f_code;
  499. PUTS(fd, " File ");
  500. if (code != NULL && code->co_filename != NULL
  501. && PyUnicode_Check(code->co_filename))
  502. {
  503. write(fd, "\"", 1);
  504. dump_ascii(fd, code->co_filename);
  505. write(fd, "\"", 1);
  506. } else {
  507. PUTS(fd, "???");
  508. }
  509. /* PyFrame_GetLineNumber() was introduced in Python 2.7.0 and 3.2.0 */
  510. lineno = PyCode_Addr2Line(code, frame->f_lasti);
  511. PUTS(fd, ", line ");
  512. dump_decimal(fd, lineno);
  513. PUTS(fd, " in ");
  514. if (code != NULL && code->co_name != NULL
  515. && PyUnicode_Check(code->co_name))
  516. dump_ascii(fd, code->co_name);
  517. else
  518. PUTS(fd, "???");
  519. write(fd, "\n", 1);
  520. }
  521. static void
  522. dump_traceback(int fd, PyThreadState *tstate, int write_header)
  523. {
  524. PyFrameObject *frame;
  525. unsigned int depth;
  526. if (write_header)
  527. PUTS(fd, "Traceback (most recent call first):\n");
  528. frame = _PyThreadState_GetFrame(tstate);
  529. if (frame == NULL)
  530. return;
  531. depth = 0;
  532. while (frame != NULL) {
  533. if (MAX_FRAME_DEPTH <= depth) {
  534. PUTS(fd, " ...\n");
  535. break;
  536. }
  537. if (!PyFrame_Check(frame))
  538. break;
  539. dump_frame(fd, frame);
  540. frame = frame->f_back;
  541. depth++;
  542. }
  543. }
  544. void
  545. _Py_DumpTraceback(int fd, PyThreadState *tstate)
  546. {
  547. dump_traceback(fd, tstate, 1);
  548. }
  549. /* Write the thread identifier into the file 'fd': "Current thread 0xHHHH:\" if
  550. is_current is true, "Thread 0xHHHH:\n" otherwise.
  551. This function is signal safe. */
  552. static void
  553. write_thread_id(int fd, PyThreadState *tstate, int is_current)
  554. {
  555. if (is_current)
  556. PUTS(fd, "Current thread 0x");
  557. else
  558. PUTS(fd, "Thread 0x");
  559. dump_hexadecimal(sizeof(long)*2, (unsigned long)tstate->thread_id, fd);
  560. PUTS(fd, ":\n");
  561. }
  562. const char*
  563. _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
  564. PyThreadState *current_thread)
  565. {
  566. PyThreadState *tstate;
  567. unsigned int nthreads;
  568. /* Get the current interpreter from the current thread */
  569. tstate = PyInterpreterState_ThreadHead(interp);
  570. if (tstate == NULL)
  571. return "unable to get the thread head state";
  572. /* Dump the traceback of each thread */
  573. tstate = PyInterpreterState_ThreadHead(interp);
  574. nthreads = 0;
  575. do
  576. {
  577. if (nthreads != 0)
  578. write(fd, "\n", 1);
  579. if (nthreads >= MAX_NTHREADS) {
  580. PUTS(fd, "...\n");
  581. break;
  582. }
  583. write_thread_id(fd, tstate, tstate == current_thread);
  584. dump_traceback(fd, tstate, 0);
  585. tstate = PyThreadState_Next(tstate);
  586. nthreads++;
  587. } while (tstate != NULL);
  588. return NULL;
  589. }