Enhance and rewrite traceback dump C functions

Issue #26564:

* Expose _Py_DumpASCII() and _Py_DumpDecimal() in traceback.h
* Change the type of the second _Py_DumpASCII() parameter from int to unsigned
  long
* Rewrite _Py_DumpDecimal() and dump_hexadecimal() to write directly characters
  in the expected order, avoid the need of reversing the string.
* dump_hexadecimal() limits width to the size of the buffer
* _Py_DumpASCII() does nothing if the object is not a Unicode string
* dump_frame() wrtites "???" as the line number if the line number is negative
This commit is contained in:
Victor Stinner 2016-03-15 21:49:37 +01:00
parent b380010782
commit 89e7cdcb9c
2 changed files with 73 additions and 52 deletions

View file

@ -67,6 +67,24 @@ PyAPI_DATA(const char*) _Py_DumpTracebackThreads(
PyThreadState *current_thread);
#ifndef Py_LIMITED_API
/* Write a Unicode object into the file descriptor fd. Encode the string to
ASCII using the backslashreplace error handler.
Do nothing if text is not a Unicode object. The function accepts Unicode
string which is not ready (PyUnicode_WCHAR_KIND).
This function is signal safe. */
PyAPI_FUNC(void) _Py_DumpASCII(int fd, PyObject *text);
/* Format an integer as decimal into the file descriptor fd.
This function is signal safe. */
PyAPI_FUNC(void) _Py_DumpDecimal(int fd, unsigned long value);
#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
#endif