Skip to content

Commit c29e29b

Browse files
committed
Relax _PyBytesWriter API
Don't require _PyBytesWriter pointer to be a "char *". Same change for _PyBytesWriter_WriteBytes() parameter. For example, binascii uses "unsigned char*".
1 parent b031eae commit c29e29b

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

Include/bytesobject.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,30 +156,30 @@ PyAPI_FUNC(void) _PyBytesWriter_Init(_PyBytesWriter *writer);
156156
Return a bytes object.
157157
Raise an exception and return NULL on error. */
158158
PyAPI_FUNC(PyObject *) _PyBytesWriter_Finish(_PyBytesWriter *writer,
159-
char *str);
159+
void *str);
160160

161161
/* Deallocate memory of a writer (clear its internal buffer). */
162162
PyAPI_FUNC(void) _PyBytesWriter_Dealloc(_PyBytesWriter *writer);
163163

164164
/* Allocate the buffer to write size bytes.
165165
Return the pointer to the beginning of buffer data.
166166
Raise an exception and return NULL on error. */
167-
PyAPI_FUNC(char*) _PyBytesWriter_Alloc(_PyBytesWriter *writer,
167+
PyAPI_FUNC(void*) _PyBytesWriter_Alloc(_PyBytesWriter *writer,
168168
Py_ssize_t size);
169169

170170
/* Add *size* bytes to the buffer.
171171
str is the current pointer inside the buffer.
172172
Return the updated current pointer inside the buffer.
173173
Raise an exception and return NULL on error. */
174-
PyAPI_FUNC(char*) _PyBytesWriter_Prepare(_PyBytesWriter *writer,
175-
char *str,
174+
PyAPI_FUNC(void*) _PyBytesWriter_Prepare(_PyBytesWriter *writer,
175+
void *str,
176176
Py_ssize_t size);
177177

178178
/* Write bytes.
179179
Raise an exception and return NULL on error. */
180-
PyAPI_FUNC(char*) _PyBytesWriter_WriteBytes(_PyBytesWriter *writer,
181-
char *str,
182-
char *bytes,
180+
PyAPI_FUNC(void*) _PyBytesWriter_WriteBytes(_PyBytesWriter *writer,
181+
void *str,
182+
const void *bytes,
183183
Py_ssize_t size);
184184
#endif /* Py_LIMITED_API */
185185

Objects/bytesobject.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,8 +3923,8 @@ _PyBytesWriter_CheckConsistency(_PyBytesWriter *writer, char *str)
39233923
#endif
39243924
}
39253925

3926-
char*
3927-
_PyBytesWriter_Prepare(_PyBytesWriter *writer, char *str, Py_ssize_t size)
3926+
void*
3927+
_PyBytesWriter_Prepare(_PyBytesWriter *writer, void *str, Py_ssize_t size)
39283928
{
39293929
Py_ssize_t allocated, pos;
39303930

@@ -3992,7 +3992,7 @@ _PyBytesWriter_Prepare(_PyBytesWriter *writer, char *str, Py_ssize_t size)
39923992
/* Allocate the buffer to write size bytes.
39933993
Return the pointer to the beginning of buffer data.
39943994
Raise an exception and return NULL on error. */
3995-
char*
3995+
void*
39963996
_PyBytesWriter_Alloc(_PyBytesWriter *writer, Py_ssize_t size)
39973997
{
39983998
/* ensure that _PyBytesWriter_Alloc() is only called once */
@@ -4011,7 +4011,7 @@ _PyBytesWriter_Alloc(_PyBytesWriter *writer, Py_ssize_t size)
40114011
}
40124012

40134013
PyObject *
4014-
_PyBytesWriter_Finish(_PyBytesWriter *writer, char *str)
4014+
_PyBytesWriter_Finish(_PyBytesWriter *writer, void *str)
40154015
{
40164016
Py_ssize_t pos;
40174017
PyObject *result;
@@ -4033,13 +4033,12 @@ _PyBytesWriter_Finish(_PyBytesWriter *writer, char *str)
40334033
else {
40344034
result = PyBytes_FromStringAndSize(writer->small_buffer, pos);
40354035
}
4036-
40374036
return result;
40384037
}
40394038

4040-
char*
4041-
_PyBytesWriter_WriteBytes(_PyBytesWriter *writer, char *str,
4042-
char *bytes, Py_ssize_t size)
4039+
void*
4040+
_PyBytesWriter_WriteBytes(_PyBytesWriter *writer, void *str,
4041+
const void *bytes, Py_ssize_t size)
40434042
{
40444043
str = _PyBytesWriter_Prepare(writer, str, size);
40454044
if (str == NULL)

0 commit comments

Comments
 (0)