Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2235)

Side by Side Diff: Include/unicodeobject.h

Issue 14744: Use _PyUnicodeWriter API in str.format() internals
Patch Set: Created 1 year ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Include/longobject.h ('k') | Objects/complexobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #ifndef Py_UNICODEOBJECT_H 1 #ifndef Py_UNICODEOBJECT_H
2 #define Py_UNICODEOBJECT_H 2 #define Py_UNICODEOBJECT_H
3 3
4 #include <stdarg.h> 4 #include <stdarg.h>
5 5
6 /* 6 /*
7 7
8 Unicode implementation based on original code by Fredrik Lundh, 8 Unicode implementation based on original code by Fredrik Lundh,
9 modified by Marc-Andre Lemburg (mal@lemburg.com) according to the 9 modified by Marc-Andre Lemburg (mal@lemburg.com) according to the
10 Unicode Integration Proposal. (See 10 Unicode Integration Proposal. (See
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 to[to_start:to_start+how_many] = from[from_start:from_start+how_many] 638 to[to_start:to_start+how_many] = from[from_start:from_start+how_many]
639 return how_many 639 return how_many
640 640
641 Note: The function doesn't write a terminating null character. 641 Note: The function doesn't write a terminating null character.
642 */ 642 */
643 #ifndef Py_LIMITED_API 643 #ifndef Py_LIMITED_API
644 PyAPI_FUNC(Py_ssize_t) PyUnicode_CopyCharacters( 644 PyAPI_FUNC(Py_ssize_t) PyUnicode_CopyCharacters(
645 PyObject *to, 645 PyObject *to,
646 Py_ssize_t to_start, 646 Py_ssize_t to_start,
647 PyObject *from, 647 PyObject *from,
648 Py_ssize_t from_start,
649 Py_ssize_t how_many
650 );
651
652 /* Unsafe version of PyUnicode_CopyCharacters(): don't check
653 arguments and so may crash parameters are invalid (e.g. if the output
654 string is too short). */
655 PyAPI_FUNC(void) _PyUnicode_FastCopyCharacters(
656 PyObject *to,
657 Py_ssize_t to_start,
658 PyObject *from,
648 Py_ssize_t from_start, 659 Py_ssize_t from_start,
649 Py_ssize_t how_many 660 Py_ssize_t how_many
650 ); 661 );
651 #endif 662 #endif
652 663
653 /* Fill a string with a character: write fill_char into 664 /* Fill a string with a character: write fill_char into
654 unicode[start:start+length]. 665 unicode[start:start+length].
655 666
656 Fail if fill_char is bigger than the string maximum character, or if the 667 Fail if fill_char is bigger than the string maximum character, or if the
657 string has more than 1 reference. 668 string has more than 1 reference.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 ); 867 );
857 868
858 PyAPI_FUNC(PyObject *) PyUnicode_FromFormatV( 869 PyAPI_FUNC(PyObject *) PyUnicode_FromFormatV(
859 const char *format, /* ASCII-encoded string */ 870 const char *format, /* ASCII-encoded string */
860 va_list vargs 871 va_list vargs
861 ); 872 );
862 PyAPI_FUNC(PyObject *) PyUnicode_FromFormat( 873 PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(
863 const char *format, /* ASCII-encoded string */ 874 const char *format, /* ASCII-encoded string */
864 ... 875 ...
865 ); 876 );
877
878 #ifndef Py_LIMITED_API
879 typedef struct {
880 PyObject *buffer;
881 void *data;
882 enum PyUnicode_Kind kind;
883 Py_UCS4 maxchar;
884 Py_ssize_t size;
885 Py_ssize_t pos;
886 /* minimum length of the buffer when overallocation is enabled,
887 see _PyUnicodeWriter_Init() */
888 Py_ssize_t min_length;
889 struct {
890 unsigned char overallocate:1;
891 /* If readonly is 1, buffer is a shared string (cannot be modified)
892 and size is set to 0. */
893 unsigned char readonly:1;
894 } flags;
895 } _PyUnicodeWriter ;
896
897 /* Initialize a Unicode writer.
898
899 min_length is used by _PyUnicodeWriter_Prepare() as the minimum length of
900 the buffer when overallocation is enabled (overallocate=1) */
901 PyAPI_FUNC(void)
902 _PyUnicodeWriter_Init(_PyUnicodeWriter *writer, Py_ssize_t min_length);
903
904 /* Prepare the buffer for to write 'length' characters
905 with the specified maximum character.
906
907 Return 0 on success, raise an exception and return -1 on error. */
908 #define _PyUnicodeWriter_Prepare(WRITER, LENGTH, MAXCHAR) \
909 (((MAXCHAR) <= (WRITER)->maxchar \
910 && (LENGTH) <= (WRITER)->size - (WRITER)->pos) \
911 ? 0 \
912 : (((LENGTH) == 0) \
913 ? 0 \
914 : _PyUnicodeWriter_PrepareInternal((WRITER), (LENGTH), (MAXCHAR))))
915
916 /* Don't call this function directly, use the _PyUnicodeWriter_Prepare() macro
917 instead. */
918 PyAPI_FUNC(int)
919 _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
920 Py_ssize_t length, Py_UCS4 maxchar);
921
922 PyAPI_FUNC(int)
923 _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str);
924
925 PyAPI_FUNC(PyObject *)
926 _PyUnicodeWriter_Finish(_PyUnicodeWriter *writer);
927
928 PyAPI_FUNC(void)
929 _PyUnicodeWriter_Dealloc(_PyUnicodeWriter *writer);
930 #endif
866 931
867 #ifndef Py_LIMITED_API 932 #ifndef Py_LIMITED_API
868 /* Format the object based on the format_spec, as defined in PEP 3101 933 /* Format the object based on the format_spec, as defined in PEP 3101
869 (Advanced String Formatting). */ 934 (Advanced String Formatting). */
870 PyAPI_FUNC(PyObject *) _PyUnicode_FormatAdvanced(PyObject *obj, 935 PyAPI_FUNC(int) _PyUnicode_FormatAdvancedWriter(
871 PyObject *format_spec, 936 PyObject *obj,
872 Py_ssize_t start, 937 PyObject *format_spec,
873 Py_ssize_t end); 938 Py_ssize_t start,
939 Py_ssize_t end,
940 _PyUnicodeWriter *writer);
874 #endif 941 #endif
875 942
876 PyAPI_FUNC(void) PyUnicode_InternInPlace(PyObject **); 943 PyAPI_FUNC(void) PyUnicode_InternInPlace(PyObject **);
877 PyAPI_FUNC(void) PyUnicode_InternImmortal(PyObject **); 944 PyAPI_FUNC(void) PyUnicode_InternImmortal(PyObject **);
878 PyAPI_FUNC(PyObject *) PyUnicode_InternFromString( 945 PyAPI_FUNC(PyObject *) PyUnicode_InternFromString(
879 const char *u /* UTF-8 encoded string */ 946 const char *u /* UTF-8 encoded string */
880 ); 947 );
881 #ifndef Py_LIMITED_API 948 #ifndef Py_LIMITED_API
882 PyAPI_FUNC(void) _Py_ReleaseInternedUnicodeStrings(void); 949 PyAPI_FUNC(void) _Py_ReleaseInternedUnicodeStrings(void);
883 #endif 950 #endif
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2125 2192
2126 /* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/ 2193 /* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/
2127 PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*); 2194 PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
2128 /* Clear all static strings. */ 2195 /* Clear all static strings. */
2129 PyAPI_FUNC(void) _PyUnicode_ClearStaticStrings(void); 2196 PyAPI_FUNC(void) _PyUnicode_ClearStaticStrings(void);
2130 2197
2131 #ifdef __cplusplus 2198 #ifdef __cplusplus
2132 } 2199 }
2133 #endif 2200 #endif
2134 #endif /* !Py_UNICODEOBJECT_H */ 2201 #endif /* !Py_UNICODEOBJECT_H */
OLDNEW
« no previous file with comments | « Include/longobject.h ('k') | Objects/complexobject.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7