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.

919 lines
25 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
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" // PyMemberDef
  6. #include "osdefs.h" // SEP
  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. /*[clinic input]
  22. class TracebackType "PyTracebackObject *" "&PyTraceback_Type"
  23. [clinic start generated code]*/
  24. /*[clinic end generated code: output=da39a3ee5e6b4b0d input=928fa06c10151120]*/
  25. #include "clinic/traceback.c.h"
  26. static PyObject *
  27. tb_create_raw(PyTracebackObject *next, PyFrameObject *frame, int lasti,
  28. int lineno)
  29. {
  30. PyTracebackObject *tb;
  31. if ((next != NULL && !PyTraceBack_Check(next)) ||
  32. frame == NULL || !PyFrame_Check(frame)) {
  33. PyErr_BadInternalCall();
  34. return NULL;
  35. }
  36. tb = PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type);
  37. if (tb != NULL) {
  38. Py_XINCREF(next);
  39. tb->tb_next = next;
  40. Py_XINCREF(frame);
  41. tb->tb_frame = frame;
  42. tb->tb_lasti = lasti;
  43. tb->tb_lineno = lineno;
  44. PyObject_GC_Track(tb);
  45. }
  46. return (PyObject *)tb;
  47. }
  48. /*[clinic input]
  49. @classmethod
  50. TracebackType.__new__ as tb_new
  51. tb_next: object
  52. tb_frame: object(type='PyFrameObject *', subclass_of='&PyFrame_Type')
  53. tb_lasti: int
  54. tb_lineno: int
  55. Create a new traceback object.
  56. [clinic start generated code]*/
  57. static PyObject *
  58. tb_new_impl(PyTypeObject *type, PyObject *tb_next, PyFrameObject *tb_frame,
  59. int tb_lasti, int tb_lineno)
  60. /*[clinic end generated code: output=fa077debd72d861a input=01cbe8ec8783fca7]*/
  61. {
  62. if (tb_next == Py_None) {
  63. tb_next = NULL;
  64. } else if (!PyTraceBack_Check(tb_next)) {
  65. return PyErr_Format(PyExc_TypeError,
  66. "expected traceback object or None, got '%s'",
  67. Py_TYPE(tb_next)->tp_name);
  68. }
  69. return tb_create_raw((PyTracebackObject *)tb_next, tb_frame, tb_lasti,
  70. tb_lineno);
  71. }
  72. static PyObject *
  73. tb_dir(PyTracebackObject *self, PyObject *Py_UNUSED(ignored))
  74. {
  75. return Py_BuildValue("[ssss]", "tb_frame", "tb_next",
  76. "tb_lasti", "tb_lineno");
  77. }
  78. static PyObject *
  79. tb_next_get(PyTracebackObject *self, void *Py_UNUSED(_))
  80. {
  81. PyObject* ret = (PyObject*)self->tb_next;
  82. if (!ret) {
  83. ret = Py_None;
  84. }
  85. Py_INCREF(ret);
  86. return ret;
  87. }
  88. static int
  89. tb_next_set(PyTracebackObject *self, PyObject *new_next, void *Py_UNUSED(_))
  90. {
  91. if (!new_next) {
  92. PyErr_Format(PyExc_TypeError, "can't delete tb_next attribute");
  93. return -1;
  94. }
  95. /* We accept None or a traceback object, and map None -> NULL (inverse of
  96. tb_next_get) */
  97. if (new_next == Py_None) {
  98. new_next = NULL;
  99. } else if (!PyTraceBack_Check(new_next)) {
  100. PyErr_Format(PyExc_TypeError,
  101. "expected traceback object, got '%s'",
  102. Py_TYPE(new_next)->tp_name);
  103. return -1;
  104. }
  105. /* Check for loops */
  106. PyTracebackObject *cursor = (PyTracebackObject *)new_next;
  107. while (cursor) {
  108. if (cursor == self) {
  109. PyErr_Format(PyExc_ValueError, "traceback loop detected");
  110. return -1;
  111. }
  112. cursor = cursor->tb_next;
  113. }
  114. PyObject *old_next = (PyObject*)self->tb_next;
  115. Py_XINCREF(new_next);
  116. self->tb_next = (PyTracebackObject *)new_next;
  117. Py_XDECREF(old_next);
  118. return 0;
  119. }
  120. static PyMethodDef tb_methods[] = {
  121. {"__dir__", (PyCFunction)tb_dir, METH_NOARGS},
  122. {NULL, NULL, 0, NULL},
  123. };
  124. static PyMemberDef tb_memberlist[] = {
  125. {"tb_frame", T_OBJECT, OFF(tb_frame), READONLY},
  126. {"tb_lasti", T_INT, OFF(tb_lasti), READONLY},
  127. {"tb_lineno", T_INT, OFF(tb_lineno), READONLY},
  128. {NULL} /* Sentinel */
  129. };
  130. static PyGetSetDef tb_getsetters[] = {
  131. {"tb_next", (getter)tb_next_get, (setter)tb_next_set, NULL, NULL},
  132. {NULL} /* Sentinel */
  133. };
  134. static void
  135. tb_dealloc(PyTracebackObject *tb)
  136. {
  137. PyObject_GC_UnTrack(tb);
  138. Py_TRASHCAN_BEGIN(tb, tb_dealloc)
  139. Py_XDECREF(tb->tb_next);
  140. Py_XDECREF(tb->tb_frame);
  141. PyObject_GC_Del(tb);
  142. Py_TRASHCAN_END
  143. }
  144. static int
  145. tb_traverse(PyTracebackObject *tb, visitproc visit, void *arg)
  146. {
  147. Py_VISIT(tb->tb_next);
  148. Py_VISIT(tb->tb_frame);
  149. return 0;
  150. }
  151. static int
  152. tb_clear(PyTracebackObject *tb)
  153. {
  154. Py_CLEAR(tb->tb_next);
  155. Py_CLEAR(tb->tb_frame);
  156. return 0;
  157. }
  158. PyTypeObject PyTraceBack_Type = {
  159. PyVarObject_HEAD_INIT(&PyType_Type, 0)
  160. "traceback",
  161. sizeof(PyTracebackObject),
  162. 0,
  163. (destructor)tb_dealloc, /*tp_dealloc*/
  164. 0, /*tp_vectorcall_offset*/
  165. 0, /*tp_getattr*/
  166. 0, /*tp_setattr*/
  167. 0, /*tp_as_async*/
  168. 0, /*tp_repr*/
  169. 0, /*tp_as_number*/
  170. 0, /*tp_as_sequence*/
  171. 0, /*tp_as_mapping*/
  172. 0, /* tp_hash */
  173. 0, /* tp_call */
  174. 0, /* tp_str */
  175. PyObject_GenericGetAttr, /* tp_getattro */
  176. 0, /* tp_setattro */
  177. 0, /* tp_as_buffer */
  178. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
  179. tb_new__doc__, /* tp_doc */
  180. (traverseproc)tb_traverse, /* tp_traverse */
  181. (inquiry)tb_clear, /* tp_clear */
  182. 0, /* tp_richcompare */
  183. 0, /* tp_weaklistoffset */
  184. 0, /* tp_iter */
  185. 0, /* tp_iternext */
  186. tb_methods, /* tp_methods */
  187. tb_memberlist, /* tp_members */
  188. tb_getsetters, /* tp_getset */
  189. 0, /* tp_base */
  190. 0, /* tp_dict */
  191. 0, /* tp_descr_get */
  192. 0, /* tp_descr_set */
  193. 0, /* tp_dictoffset */
  194. 0, /* tp_init */
  195. 0, /* tp_alloc */
  196. tb_new, /* tp_new */
  197. };
  198. PyObject*
  199. _PyTraceBack_FromFrame(PyObject *tb_next, PyFrameObject *frame)
  200. {
  201. assert(tb_next == NULL || PyTraceBack_Check(tb_next));
  202. assert(frame != NULL);
  203. return tb_create_raw((PyTracebackObject *)tb_next, frame, frame->f_lasti,
  204. PyFrame_GetLineNumber(frame));
  205. }
  206. int
  207. PyTraceBack_Here(PyFrameObject *frame)
  208. {
  209. PyObject *exc, *val, *tb, *newtb;
  210. PyErr_Fetch(&exc, &val, &tb);
  211. newtb = _PyTraceBack_FromFrame(tb, frame);
  212. if (newtb == NULL) {
  213. _PyErr_ChainExceptions(exc, val, tb);
  214. return -1;
  215. }
  216. PyErr_Restore(exc, val, newtb);
  217. Py_XDECREF(tb);
  218. return 0;
  219. }
  220. /* Insert a frame into the traceback for (funcname, filename, lineno). */
  221. void _PyTraceback_Add(const char *funcname, const char *filename, int lineno)
  222. {
  223. PyObject *globals;
  224. PyCodeObject *code;
  225. PyFrameObject *frame;
  226. PyObject *exc, *val, *tb;
  227. /* Save and clear the current exception. Python functions must not be
  228. called with an exception set. Calling Python functions happens when
  229. the codec of the filesystem encoding is implemented in pure Python. */
  230. PyErr_Fetch(&exc, &val, &tb);
  231. globals = PyDict_New();
  232. if (!globals)
  233. goto error;
  234. code = PyCode_NewEmpty(filename, funcname, lineno);
  235. if (!code) {
  236. Py_DECREF(globals);
  237. goto error;
  238. }
  239. frame = PyFrame_New(PyThreadState_Get(), code, globals, NULL);
  240. Py_DECREF(globals);
  241. Py_DECREF(code);
  242. if (!frame)
  243. goto error;
  244. frame->f_lineno = lineno;
  245. PyErr_Restore(exc, val, tb);
  246. PyTraceBack_Here(frame);
  247. Py_DECREF(frame);
  248. return;
  249. error:
  250. _PyErr_ChainExceptions(exc, val, tb);
  251. }
  252. static PyObject *
  253. _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject *io)
  254. {
  255. Py_ssize_t i;
  256. PyObject *binary;
  257. PyObject *v;
  258. Py_ssize_t npath;
  259. size_t taillen;
  260. PyObject *syspath;
  261. PyObject *path;
  262. const char* tail;
  263. PyObject *filebytes;
  264. const char* filepath;
  265. Py_ssize_t len;
  266. PyObject* result;
  267. filebytes = PyUnicode_EncodeFSDefault(filename);
  268. if (filebytes == NULL) {
  269. PyErr_Clear();
  270. return NULL;
  271. }
  272. filepath = PyBytes_AS_STRING(filebytes);
  273. /* Search tail of filename in sys.path before giving up */
  274. tail = strrchr(filepath, SEP);
  275. if (tail == NULL)
  276. tail = filepath;
  277. else
  278. tail++;
  279. taillen = strlen(tail);
  280. syspath = _PySys_GetObjectId(&PyId_path);
  281. if (syspath == NULL || !PyList_Check(syspath))
  282. goto error;
  283. npath = PyList_Size(syspath);
  284. for (i = 0; i < npath; i++) {
  285. v = PyList_GetItem(syspath, i);
  286. if (v == NULL) {
  287. PyErr_Clear();
  288. break;
  289. }
  290. if (!PyUnicode_Check(v))
  291. continue;
  292. path = PyUnicode_EncodeFSDefault(v);
  293. if (path == NULL) {
  294. PyErr_Clear();
  295. continue;
  296. }
  297. len = PyBytes_GET_SIZE(path);
  298. if (len + 1 + (Py_ssize_t)taillen >= (Py_ssize_t)namelen - 1) {
  299. Py_DECREF(path);
  300. continue; /* Too long */
  301. }
  302. strcpy(namebuf, PyBytes_AS_STRING(path));
  303. Py_DECREF(path);
  304. if (strlen(namebuf) != (size_t)len)
  305. continue; /* v contains '\0' */
  306. if (len > 0 && namebuf[len-1] != SEP)
  307. namebuf[len++] = SEP;
  308. strcpy(namebuf+len, tail);
  309. binary = _PyObject_CallMethodId(io, &PyId_open, "ss", namebuf, "rb");
  310. if (binary != NULL) {
  311. result = binary;
  312. goto finally;
  313. }
  314. PyErr_Clear();
  315. }
  316. goto error;
  317. error:
  318. result = NULL;
  319. finally:
  320. Py_DECREF(filebytes);
  321. return result;
  322. }
  323. int
  324. _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
  325. {
  326. int err = 0;
  327. int fd;
  328. int i;
  329. char *found_encoding;
  330. const char *encoding;
  331. PyObject *io;
  332. PyObject *binary;
  333. PyObject *fob = NULL;
  334. PyObject *lineobj = NULL;
  335. PyObject *res;
  336. char buf[MAXPATHLEN+1];
  337. int kind;
  338. const void *data;
  339. /* open the file */
  340. if (filename == NULL)
  341. return 0;
  342. io = PyImport_ImportModuleNoBlock("io");
  343. if (io == NULL)
  344. return -1;
  345. binary = _PyObject_CallMethodId(io, &PyId_open, "Os", filename, "rb");
  346. if (binary == NULL) {
  347. PyErr_Clear();
  348. binary = _Py_FindSourceFile(filename, buf, sizeof(buf), io);
  349. if (binary == NULL) {
  350. Py_DECREF(io);
  351. return -1;
  352. }
  353. }
  354. /* use the right encoding to decode the file as unicode */
  355. fd = PyObject_AsFileDescriptor(binary);
  356. if (fd < 0) {
  357. Py_DECREF(io);
  358. Py_DECREF(binary);
  359. return 0;
  360. }
  361. found_encoding = PyTokenizer_FindEncodingFilename(fd, filename);
  362. if (found_encoding == NULL)
  363. PyErr_Clear();
  364. encoding = (found_encoding != NULL) ? found_encoding : "utf-8";
  365. /* Reset position */
  366. if (lseek(fd, 0, SEEK_SET) == (off_t)-1) {
  367. Py_DECREF(io);
  368. Py_DECREF(binary);
  369. PyMem_FREE(found_encoding);
  370. return 0;
  371. }
  372. fob = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "Os", binary, encoding);
  373. Py_DECREF(io);
  374. PyMem_FREE(found_encoding);
  375. if (fob == NULL) {
  376. PyErr_Clear();
  377. res = _PyObject_CallMethodIdNoArgs(binary, &PyId_close);
  378. Py_DECREF(binary);
  379. if (res)
  380. Py_DECREF(res);
  381. else
  382. PyErr_Clear();
  383. return 0;
  384. }
  385. Py_DECREF(binary);
  386. /* get the line number lineno */
  387. for (i = 0; i < lineno; i++) {
  388. Py_XDECREF(lineobj);
  389. lineobj = PyFile_GetLine(fob, -1);
  390. if (!lineobj) {
  391. PyErr_Clear();
  392. err = -1;
  393. break;
  394. }
  395. }
  396. res = _PyObject_CallMethodIdNoArgs(fob, &PyId_close);
  397. if (res)
  398. Py_DECREF(res);
  399. else
  400. PyErr_Clear();
  401. Py_DECREF(fob);
  402. if (!lineobj || !PyUnicode_Check(lineobj)) {
  403. Py_XDECREF(lineobj);
  404. return err;
  405. }
  406. /* remove the indentation of the line */
  407. kind = PyUnicode_KIND(lineobj);
  408. data = PyUnicode_DATA(lineobj);
  409. for (i=0; i < PyUnicode_GET_LENGTH(lineobj); i++) {
  410. Py_UCS4 ch = PyUnicode_READ(kind, data, i);
  411. if (ch != ' ' && ch != '\t' && ch != '\014')
  412. break;
  413. }
  414. if (i) {
  415. PyObject *truncated;
  416. truncated = PyUnicode_Substring(lineobj, i, PyUnicode_GET_LENGTH(lineobj));
  417. if (truncated) {
  418. Py_DECREF(lineobj);
  419. lineobj = truncated;
  420. } else {
  421. PyErr_Clear();
  422. }
  423. }
  424. /* Write some spaces before the line */
  425. strcpy(buf, " ");
  426. assert (strlen(buf) == 10);
  427. while (indent > 0) {
  428. if (indent < 10)
  429. buf[indent] = '\0';
  430. err = PyFile_WriteString(buf, f);
  431. if (err != 0)
  432. break;
  433. indent -= 10;
  434. }
  435. /* finally display the line */
  436. if (err == 0)
  437. err = PyFile_WriteObject(lineobj, f, Py_PRINT_RAW);
  438. Py_DECREF(lineobj);
  439. if (err == 0)
  440. err = PyFile_WriteString("\n", f);
  441. return err;
  442. }
  443. static int
  444. tb_displayline(PyObject *f, PyObject *filename, int lineno, PyObject *name)
  445. {
  446. int err;
  447. PyObject *line;
  448. if (filename == NULL || name == NULL)
  449. return -1;
  450. line = PyUnicode_FromFormat(" File \"%U\", line %d, in %U\n",
  451. filename, lineno, name);
  452. if (line == NULL)
  453. return -1;
  454. err = PyFile_WriteObject(line, f, Py_PRINT_RAW);
  455. Py_DECREF(line);
  456. if (err != 0)
  457. return err;
  458. /* ignore errors since we can't report them, can we? */
  459. if (_Py_DisplaySourceLine(f, filename, lineno, 4))
  460. PyErr_Clear();
  461. return err;
  462. }
  463. static const int TB_RECURSIVE_CUTOFF = 3; // Also hardcoded in traceback.py.
  464. static int
  465. tb_print_line_repeated(PyObject *f, long cnt)
  466. {
  467. cnt -= TB_RECURSIVE_CUTOFF;
  468. PyObject *line = PyUnicode_FromFormat(
  469. (cnt > 1)
  470. ? " [Previous line repeated %ld more times]\n"
  471. : " [Previous line repeated %ld more time]\n",
  472. cnt);
  473. if (line == NULL) {
  474. return -1;
  475. }
  476. int err = PyFile_WriteObject(line, f, Py_PRINT_RAW);
  477. Py_DECREF(line);
  478. return err;
  479. }
  480. static int
  481. tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit)
  482. {
  483. int err = 0;
  484. Py_ssize_t depth = 0;
  485. PyObject *last_file = NULL;
  486. int last_line = -1;
  487. PyObject *last_name = NULL;
  488. long cnt = 0;
  489. PyTracebackObject *tb1 = tb;
  490. while (tb1 != NULL) {
  491. depth++;
  492. tb1 = tb1->tb_next;
  493. }
  494. while (tb != NULL && depth > limit) {
  495. depth--;
  496. tb = tb->tb_next;
  497. }
  498. while (tb != NULL && err == 0) {
  499. PyCodeObject *code = PyFrame_GetCode(tb->tb_frame);
  500. if (last_file == NULL ||
  501. code->co_filename != last_file ||
  502. last_line == -1 || tb->tb_lineno != last_line ||
  503. last_name == NULL || code->co_name != last_name) {
  504. if (cnt > TB_RECURSIVE_CUTOFF) {
  505. err = tb_print_line_repeated(f, cnt);
  506. }
  507. last_file = code->co_filename;
  508. last_line = tb->tb_lineno;
  509. last_name = code->co_name;
  510. cnt = 0;
  511. }
  512. cnt++;
  513. if (err == 0 && cnt <= TB_RECURSIVE_CUTOFF) {
  514. err = tb_displayline(f, code->co_filename, tb->tb_lineno,
  515. code->co_name);
  516. if (err == 0) {
  517. err = PyErr_CheckSignals();
  518. }
  519. }
  520. Py_DECREF(code);
  521. tb = tb->tb_next;
  522. }
  523. if (err == 0 && cnt > TB_RECURSIVE_CUTOFF) {
  524. err = tb_print_line_repeated(f, cnt);
  525. }
  526. return err;
  527. }
  528. #define PyTraceBack_LIMIT 1000
  529. int
  530. PyTraceBack_Print(PyObject *v, PyObject *f)
  531. {
  532. int err;
  533. PyObject *limitv;
  534. long limit = PyTraceBack_LIMIT;
  535. if (v == NULL)
  536. return 0;
  537. if (!PyTraceBack_Check(v)) {
  538. PyErr_BadInternalCall();
  539. return -1;
  540. }
  541. limitv = PySys_GetObject("tracebacklimit");
  542. if (limitv && PyLong_Check(limitv)) {
  543. int overflow;
  544. limit = PyLong_AsLongAndOverflow(limitv, &overflow);
  545. if (overflow > 0) {
  546. limit = LONG_MAX;
  547. }
  548. else if (limit <= 0) {
  549. return 0;
  550. }
  551. }
  552. err = PyFile_WriteString("Traceback (most recent call last):\n", f);
  553. if (!err)
  554. err = tb_printinternal((PyTracebackObject *)v, f, limit);
  555. return err;
  556. }
  557. /* Reverse a string. For example, "abcd" becomes "dcba".
  558. This function is signal safe. */
  559. void
  560. _Py_DumpDecimal(int fd, unsigned long value)
  561. {
  562. /* maximum number of characters required for output of %lld or %p.
  563. We need at most ceil(log10(256)*SIZEOF_LONG_LONG) digits,
  564. plus 1 for the null byte. 53/22 is an upper bound for log10(256). */
  565. char buffer[1 + (sizeof(unsigned long)*53-1) / 22 + 1];
  566. char *ptr, *end;
  567. end = &buffer[Py_ARRAY_LENGTH(buffer) - 1];
  568. ptr = end;
  569. *ptr = '\0';
  570. do {
  571. --ptr;
  572. assert(ptr >= buffer);
  573. *ptr = '0' + (value % 10);
  574. value /= 10;
  575. } while (value);
  576. _Py_write_noraise(fd, ptr, end - ptr);
  577. }
  578. /* Format an integer in range [0; 0xffffffff] to hexadecimal of 'width' digits,
  579. and write it into the file fd.
  580. This function is signal safe. */
  581. void
  582. _Py_DumpHexadecimal(int fd, unsigned long value, Py_ssize_t width)
  583. {
  584. char buffer[sizeof(unsigned long) * 2 + 1], *ptr, *end;
  585. const Py_ssize_t size = Py_ARRAY_LENGTH(buffer) - 1;
  586. if (width > size)
  587. width = size;
  588. /* it's ok if width is negative */
  589. end = &buffer[size];
  590. ptr = end;
  591. *ptr = '\0';
  592. do {
  593. --ptr;
  594. assert(ptr >= buffer);
  595. *ptr = Py_hexdigits[value & 15];
  596. value >>= 4;
  597. } while ((end - ptr) < width || value);
  598. _Py_write_noraise(fd, ptr, end - ptr);
  599. }
  600. void
  601. _Py_DumpASCII(int fd, PyObject *text)
  602. {
  603. PyASCIIObject *ascii = (PyASCIIObject *)text;
  604. Py_ssize_t i, size;
  605. int truncated;
  606. int kind;
  607. void *data = NULL;
  608. wchar_t *wstr = NULL;
  609. Py_UCS4 ch;
  610. if (!PyUnicode_Check(text))
  611. return;
  612. size = ascii->length;
  613. kind = ascii->state.kind;
  614. if (kind == PyUnicode_WCHAR_KIND) {
  615. wstr = ((PyASCIIObject *)text)->wstr;
  616. if (wstr == NULL)
  617. return;
  618. size = ((PyCompactUnicodeObject *)text)->wstr_length;
  619. }
  620. else if (ascii->state.compact) {
  621. if (ascii->state.ascii)
  622. data = ((PyASCIIObject*)text) + 1;
  623. else
  624. data = ((PyCompactUnicodeObject*)text) + 1;
  625. }
  626. else {
  627. data = ((PyUnicodeObject *)text)->data.any;
  628. if (data == NULL)
  629. return;
  630. }
  631. if (MAX_STRING_LENGTH < size) {
  632. size = MAX_STRING_LENGTH;
  633. truncated = 1;
  634. }
  635. else {
  636. truncated = 0;
  637. }
  638. for (i=0; i < size; i++) {
  639. if (kind != PyUnicode_WCHAR_KIND)
  640. ch = PyUnicode_READ(kind, data, i);
  641. else
  642. ch = wstr[i];
  643. if (' ' <= ch && ch <= 126) {
  644. /* printable ASCII character */
  645. char c = (char)ch;
  646. _Py_write_noraise(fd, &c, 1);
  647. }
  648. else if (ch <= 0xff) {
  649. PUTS(fd, "\\x");
  650. _Py_DumpHexadecimal(fd, ch, 2);
  651. }
  652. else if (ch <= 0xffff) {
  653. PUTS(fd, "\\u");
  654. _Py_DumpHexadecimal(fd, ch, 4);
  655. }
  656. else {
  657. PUTS(fd, "\\U");
  658. _Py_DumpHexadecimal(fd, ch, 8);
  659. }
  660. }
  661. if (truncated) {
  662. PUTS(fd, "...");
  663. }
  664. }
  665. /* Write a frame into the file fd: "File "xxx", line xxx in xxx".
  666. This function is signal safe. */
  667. static void
  668. dump_frame(int fd, PyFrameObject *frame)
  669. {
  670. PyCodeObject *code = PyFrame_GetCode(frame);
  671. PUTS(fd, " File ");
  672. if (code->co_filename != NULL
  673. && PyUnicode_Check(code->co_filename))
  674. {
  675. PUTS(fd, "\"");
  676. _Py_DumpASCII(fd, code->co_filename);
  677. PUTS(fd, "\"");
  678. } else {
  679. PUTS(fd, "???");
  680. }
  681. /* PyFrame_GetLineNumber() was introduced in Python 2.7.0 and 3.2.0 */
  682. int lineno = PyCode_Addr2Line(code, frame->f_lasti);
  683. PUTS(fd, ", line ");
  684. if (lineno >= 0) {
  685. _Py_DumpDecimal(fd, (unsigned long)lineno);
  686. }
  687. else {
  688. PUTS(fd, "???");
  689. }
  690. PUTS(fd, " in ");
  691. if (code->co_name != NULL
  692. && PyUnicode_Check(code->co_name)) {
  693. _Py_DumpASCII(fd, code->co_name);
  694. }
  695. else {
  696. PUTS(fd, "???");
  697. }
  698. PUTS(fd, "\n");
  699. Py_DECREF(code);
  700. }
  701. static void
  702. dump_traceback(int fd, PyThreadState *tstate, int write_header)
  703. {
  704. PyFrameObject *frame;
  705. unsigned int depth;
  706. if (write_header) {
  707. PUTS(fd, "Stack (most recent call first):\n");
  708. }
  709. frame = tstate->frame;
  710. if (frame == NULL) {
  711. PUTS(fd, "<no Python frame>\n");
  712. return;
  713. }
  714. depth = 0;
  715. while (frame != NULL) {
  716. if (MAX_FRAME_DEPTH <= depth) {
  717. PUTS(fd, " ...\n");
  718. break;
  719. }
  720. if (!PyFrame_Check(frame))
  721. break;
  722. dump_frame(fd, frame);
  723. frame = frame->f_back;
  724. depth++;
  725. }
  726. }
  727. /* Dump the traceback of a Python thread into fd. Use write() to write the
  728. traceback and retry if write() is interrupted by a signal (failed with
  729. EINTR), but don't call the Python signal handler.
  730. The caller is responsible to call PyErr_CheckSignals() to call Python signal
  731. handlers if signals were received. */
  732. void
  733. _Py_DumpTraceback(int fd, PyThreadState *tstate)
  734. {
  735. dump_traceback(fd, tstate, 1);
  736. }
  737. /* Write the thread identifier into the file 'fd': "Current thread 0xHHHH:\" if
  738. is_current is true, "Thread 0xHHHH:\n" otherwise.
  739. This function is signal safe. */
  740. static void
  741. write_thread_id(int fd, PyThreadState *tstate, int is_current)
  742. {
  743. if (is_current)
  744. PUTS(fd, "Current thread 0x");
  745. else
  746. PUTS(fd, "Thread 0x");
  747. _Py_DumpHexadecimal(fd,
  748. tstate->thread_id,
  749. sizeof(unsigned long) * 2);
  750. PUTS(fd, " (most recent call first):\n");
  751. }
  752. /* Dump the traceback of all Python threads into fd. Use write() to write the
  753. traceback and retry if write() is interrupted by a signal (failed with
  754. EINTR), but don't call the Python signal handler.
  755. The caller is responsible to call PyErr_CheckSignals() to call Python signal
  756. handlers if signals were received. */
  757. const char*
  758. _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
  759. PyThreadState *current_tstate)
  760. {
  761. PyThreadState *tstate;
  762. unsigned int nthreads;
  763. if (current_tstate == NULL) {
  764. /* _Py_DumpTracebackThreads() is called from signal handlers by
  765. faulthandler.
  766. SIGSEGV, SIGFPE, SIGABRT, SIGBUS and SIGILL are synchronous signals
  767. and are thus delivered to the thread that caused the fault. Get the
  768. Python thread state of the current thread.
  769. PyThreadState_Get() doesn't give the state of the thread that caused
  770. the fault if the thread released the GIL, and so
  771. _PyThreadState_GET() cannot be used. Read the thread specific
  772. storage (TSS) instead: call PyGILState_GetThisThreadState(). */
  773. current_tstate = PyGILState_GetThisThreadState();
  774. }
  775. if (interp == NULL) {
  776. if (current_tstate == NULL) {
  777. interp = _PyGILState_GetInterpreterStateUnsafe();
  778. if (interp == NULL) {
  779. /* We need the interpreter state to get Python threads */
  780. return "unable to get the interpreter state";
  781. }
  782. }
  783. else {
  784. interp = current_tstate->interp;
  785. }
  786. }
  787. assert(interp != NULL);
  788. /* Get the current interpreter from the current thread */
  789. tstate = PyInterpreterState_ThreadHead(interp);
  790. if (tstate == NULL)
  791. return "unable to get the thread head state";
  792. /* Dump the traceback of each thread */
  793. tstate = PyInterpreterState_ThreadHead(interp);
  794. nthreads = 0;
  795. _Py_BEGIN_SUPPRESS_IPH
  796. do
  797. {
  798. if (nthreads != 0)
  799. PUTS(fd, "\n");
  800. if (nthreads >= MAX_NTHREADS) {
  801. PUTS(fd, "...\n");
  802. break;
  803. }
  804. write_thread_id(fd, tstate, tstate == current_tstate);
  805. dump_traceback(fd, tstate, 0);
  806. tstate = PyThreadState_Next(tstate);
  807. nthreads++;
  808. } while (tstate != NULL);
  809. _Py_END_SUPPRESS_IPH
  810. return NULL;
  811. }