@@ -648,8 +648,20 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_CopyCharacters(
648648 Py_ssize_t from_start,
649649 Py_ssize_t how_many
650650 );
651+
652+ /* Unsafe version of PyUnicode_CopyCharacters(): don't check arguments and so
653+ may crash if parameters are invalid (e.g. if the output string
654+ is too short). */
655+ PyAPI_FUNC (void ) _PyUnicode_FastCopyCharacters(
656+ PyObject *to,
657+ Py_ssize_t to_start,
658+ PyObject *from,
659+ Py_ssize_t from_start,
660+ Py_ssize_t how_many
661+ );
651662#endif
652663
664+ #ifndef Py_LIMITED_API
653665/* Fill a string with a character: write fill_char into
654666 unicode[start:start+length].
655667
@@ -658,13 +670,21 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_CopyCharacters(
658670
659671 Return the number of written character, or return -1 and raise an exception
660672 on error. */
661- #ifndef Py_LIMITED_API
662673PyAPI_FUNC (Py_ssize_t) PyUnicode_Fill(
663674 PyObject *unicode,
664675 Py_ssize_t start,
665676 Py_ssize_t length,
666677 Py_UCS4 fill_char
667678 );
679+
680+ /* Unsafe version of PyUnicode_Fill(): don't check arguments and so may crash
681+ if parameters are invalid (e.g. if length is longer than the string). */
682+ PyAPI_FUNC (void ) _PyUnicode_FastFill(
683+ PyObject *unicode,
684+ Py_ssize_t start,
685+ Py_ssize_t length,
686+ Py_UCS4 fill_char
687+ );
668688#endif
669689
670690/* Create a Unicode Object from the Py_UNICODE buffer u of the given
@@ -696,13 +716,19 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromString(
696716 const char *u /* UTF-8 encoded string */
697717 );
698718
719+ #ifndef Py_LIMITED_API
699720/* Create a new string from a buffer of Py_UCS1, Py_UCS2 or Py_UCS4 characters.
700721 Scan the string to find the maximum character. */
701- #ifndef Py_LIMITED_API
702722PyAPI_FUNC (PyObject*) PyUnicode_FromKindAndData(
703723 int kind,
704724 const void *buffer,
705725 Py_ssize_t size);
726+
727+ /* Create a new string from a buffer of ASCII characters.
728+ WARNING: Don't check if the string contains any non-ASCII character. */
729+ PyAPI_FUNC (PyObject*) _PyUnicode_FromASCII(
730+ const char *buffer,
731+ Py_ssize_t size);
706732#endif
707733
708734PyAPI_FUNC (PyObject*) PyUnicode_Substring(
@@ -864,13 +890,70 @@ PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(
864890 ...
865891 );
866892
893+ #ifndef Py_LIMITED_API
894+ typedef struct {
895+ PyObject *buffer;
896+ void *data;
897+ enum PyUnicode_Kind kind;
898+ Py_UCS4 maxchar;
899+ Py_ssize_t size;
900+ Py_ssize_t pos;
901+ /* minimum length of the buffer when overallocation is enabled,
902+ see _PyUnicodeWriter_Init() */
903+ Py_ssize_t min_length;
904+ struct {
905+ unsigned char overallocate:1 ;
906+ /* If readonly is 1, buffer is a shared string (cannot be modified)
907+ and size is set to 0. */
908+ unsigned char readonly:1 ;
909+ } flags;
910+ } _PyUnicodeWriter ;
911+
912+ /* Initialize a Unicode writer.
913+
914+ If min_length is greater than zero, _PyUnicodeWriter_Prepare()
915+ overallocates the buffer and min_length is the minimum length in characters
916+ of the buffer. */
917+ PyAPI_FUNC (void )
918+ _PyUnicodeWriter_Init(_PyUnicodeWriter *writer, Py_ssize_t min_length);
919+
920+ /* Prepare the buffer to write 'length' characters
921+ with the specified maximum character.
922+
923+ Return 0 on success, raise an exception and return -1 on error. */
924+ #define _PyUnicodeWriter_Prepare (WRITER, LENGTH, MAXCHAR ) \
925+ (((MAXCHAR) <= (WRITER)->maxchar \
926+ && (LENGTH) <= (WRITER)->size - (WRITER)->pos) \
927+ ? 0 \
928+ : (((LENGTH) == 0 ) \
929+ ? 0 \
930+ : _PyUnicodeWriter_PrepareInternal((WRITER), (LENGTH), (MAXCHAR))))
931+
932+ /* Don't call this function directly, use the _PyUnicodeWriter_Prepare() macro
933+ instead. */
934+ PyAPI_FUNC (int )
935+ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
936+ Py_ssize_t length, Py_UCS4 maxchar);
937+
938+ PyAPI_FUNC (int )
939+ _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str);
940+
941+ PyAPI_FUNC (PyObject *)
942+ _PyUnicodeWriter_Finish(_PyUnicodeWriter *writer);
943+
944+ PyAPI_FUNC (void )
945+ _PyUnicodeWriter_Dealloc(_PyUnicodeWriter *writer);
946+ #endif
947+
867948#ifndef Py_LIMITED_API
868949/* Format the object based on the format_spec, as defined in PEP 3101
869950 (Advanced String Formatting). */
870- PyAPI_FUNC (PyObject *) _PyUnicode_FormatAdvanced(PyObject *obj,
871- PyObject *format_spec,
872- Py_ssize_t start,
873- Py_ssize_t end);
951+ PyAPI_FUNC (int ) _PyUnicode_FormatAdvancedWriter(
952+ _PyUnicodeWriter *writer,
953+ PyObject *obj,
954+ PyObject *format_spec,
955+ Py_ssize_t start,
956+ Py_ssize_t end);
874957#endif
875958
876959PyAPI_FUNC (void ) PyUnicode_InternInPlace(PyObject **);
0 commit comments