@@ -60,93 +60,7 @@ PyAPI_FUNC(void)
60
60
_PyBytes_Repeat (char * dest , Py_ssize_t len_dest ,
61
61
const char * src , Py_ssize_t len_src );
62
62
63
- /* --- _PyBytesWriter ----------------------------------------------------- */
64
-
65
- /* The _PyBytesWriter structure is big: it contains an embedded "stack buffer".
66
- A _PyBytesWriter variable must be declared at the end of variables in a
67
- function to optimize the memory allocation on the stack. */
68
- typedef struct {
69
- /* bytes, bytearray or NULL (when the small buffer is used) */
70
- PyObject * buffer ;
71
-
72
- /* Number of allocated size. */
73
- Py_ssize_t allocated ;
74
-
75
- /* Minimum number of allocated bytes,
76
- incremented by _PyBytesWriter_Prepare() */
77
- Py_ssize_t min_size ;
78
-
79
- /* If non-zero, use a bytearray instead of a bytes object for buffer. */
80
- int use_bytearray ;
81
-
82
- /* If non-zero, overallocate the buffer (default: 0).
83
- This flag must be zero if use_bytearray is non-zero. */
84
- int overallocate ;
85
-
86
- /* Stack buffer */
87
- int use_small_buffer ;
88
- char small_buffer [512 ];
89
- } _PyBytesWriter ;
90
-
91
- /* Initialize a bytes writer
92
-
93
- By default, the overallocation is disabled. Set the overallocate attribute
94
- to control the allocation of the buffer.
95
-
96
- Export _PyBytesWriter API for '_pickle' shared extension. */
97
- PyAPI_FUNC (void ) _PyBytesWriter_Init (_PyBytesWriter * writer );
98
-
99
- /* Get the buffer content and reset the writer.
100
- Return a bytes object, or a bytearray object if use_bytearray is non-zero.
101
- Raise an exception and return NULL on error. */
102
- PyAPI_FUNC (PyObject * ) _PyBytesWriter_Finish (_PyBytesWriter * writer ,
103
- void * str );
104
-
105
- /* Deallocate memory of a writer (clear its internal buffer). */
106
- PyAPI_FUNC (void ) _PyBytesWriter_Dealloc (_PyBytesWriter * writer );
107
-
108
- /* Allocate the buffer to write size bytes.
109
- Return the pointer to the beginning of buffer data.
110
- Raise an exception and return NULL on error. */
111
- PyAPI_FUNC (void * ) _PyBytesWriter_Alloc (_PyBytesWriter * writer ,
112
- Py_ssize_t size );
113
-
114
- /* Ensure that the buffer is large enough to write *size* bytes.
115
- Add size to the writer minimum size (min_size attribute).
116
-
117
- str is the current pointer inside the buffer.
118
- Return the updated current pointer inside the buffer.
119
- Raise an exception and return NULL on error. */
120
- PyAPI_FUNC (void * ) _PyBytesWriter_Prepare (_PyBytesWriter * writer ,
121
- void * str ,
122
- Py_ssize_t size );
123
-
124
- /* Resize the buffer to make it larger.
125
- The new buffer may be larger than size bytes because of overallocation.
126
- Return the updated current pointer inside the buffer.
127
- Raise an exception and return NULL on error.
128
-
129
- Note: size must be greater than the number of allocated bytes in the writer.
130
-
131
- This function doesn't use the writer minimum size (min_size attribute).
132
-
133
- See also _PyBytesWriter_Prepare().
134
- */
135
- PyAPI_FUNC (void * ) _PyBytesWriter_Resize (_PyBytesWriter * writer ,
136
- void * str ,
137
- Py_ssize_t size );
138
-
139
- /* Write bytes.
140
- Raise an exception and return NULL on error. */
141
- PyAPI_FUNC (void * ) _PyBytesWriter_WriteBytes (_PyBytesWriter * writer ,
142
- void * str ,
143
- const void * bytes ,
144
- Py_ssize_t size );
145
-
146
- // Export for '_testcapi' shared extension.
147
- PyAPI_FUNC (PyBytesWriter * ) _PyBytesWriter_CreateByteArray (
148
- Py_ssize_t size );
149
-
63
+ /* --- PyBytesWriter ------------------------------------------------------ */
150
64
151
65
struct PyBytesWriter {
152
66
char small_buffer [256 ];
@@ -156,6 +70,9 @@ struct PyBytesWriter {
156
70
int overallocate ;
157
71
};
158
72
73
+ // Export for '_testcapi' shared extension
74
+ PyAPI_FUNC (PyBytesWriter * ) _PyBytesWriter_CreateByteArray (Py_ssize_t size );
75
+
159
76
#ifdef __cplusplus
160
77
}
161
78
#endif
0 commit comments