This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2010-05-31.19:01:21
SpamBayes Score 0.00126299
Marked as misclassified No
Message-id <>
Attached patch implements an handler for the signal SIGSEGV. It uses its own stack to be able to allocate memory on the stack (eg. call a function), even on stack overflow.

The patch requires sigaction() and sigaltstack() functions, but I didn't patched script. These functions are available on Linux, but should be available on other UNIX OSes.

segfault() signal handler supposes that the thread state is consistent (interp->frame chained list). It calls indirectly PyUnicode_EncodeUTF8() and so call PyBytes_FromStringAndSize() which allocates memory on the heap. It clears PyUnicode "defenc" attribute (the result of PyUnicode_EncodeUTF8()) to free directly the memory.

To test it, try some scripts in Lib/test/crashers/.

One example:
$ ./python Lib/test/crashers/
Fatal Python error: segmentation fault

Traceback (most recent call first):
  File "Lib/test/crashers/", line 12, depth 15715
  File "Lib/test/crashers/", line 12, depth 15714
  File "Lib/test/crashers/", line 12, depth 15713
  File "Lib/test/crashers/", line 12, depth 3
  File "Lib/test/crashers/", line 12, depth 2
  File "Lib/test/crashers/", line 9, depth 1
Segmentation fault
Date User Action Args
2010-05-31 19:01:25vstinnersetrecipients: + vstinner
2010-05-31 19:01:25vstinnersetmessageid: <>
2010-05-31 19:01:23vstinnerlinkissue8863 messages
2010-05-31 19:01:23vstinnercreate