Kaydet (Commit) c29e29be authored tarafından Victor Stinner's avatar Victor Stinner

Relax _PyBytesWriter API

Don't require _PyBytesWriter pointer to be a "char *". Same change for
_PyBytesWriter_WriteBytes() parameter.

For example, binascii uses "unsigned char*".
üst b031eaee
...@@ -156,7 +156,7 @@ PyAPI_FUNC(void) _PyBytesWriter_Init(_PyBytesWriter *writer); ...@@ -156,7 +156,7 @@ PyAPI_FUNC(void) _PyBytesWriter_Init(_PyBytesWriter *writer);
Return a bytes object. Return a bytes object.
Raise an exception and return NULL on error. */ Raise an exception and return NULL on error. */
PyAPI_FUNC(PyObject *) _PyBytesWriter_Finish(_PyBytesWriter *writer, PyAPI_FUNC(PyObject *) _PyBytesWriter_Finish(_PyBytesWriter *writer,
char *str); void *str);
/* Deallocate memory of a writer (clear its internal buffer). */ /* Deallocate memory of a writer (clear its internal buffer). */
PyAPI_FUNC(void) _PyBytesWriter_Dealloc(_PyBytesWriter *writer); PyAPI_FUNC(void) _PyBytesWriter_Dealloc(_PyBytesWriter *writer);
...@@ -164,22 +164,22 @@ PyAPI_FUNC(void) _PyBytesWriter_Dealloc(_PyBytesWriter *writer); ...@@ -164,22 +164,22 @@ PyAPI_FUNC(void) _PyBytesWriter_Dealloc(_PyBytesWriter *writer);
/* Allocate the buffer to write size bytes. /* Allocate the buffer to write size bytes.
Return the pointer to the beginning of buffer data. Return the pointer to the beginning of buffer data.
Raise an exception and return NULL on error. */ Raise an exception and return NULL on error. */
PyAPI_FUNC(char*) _PyBytesWriter_Alloc(_PyBytesWriter *writer, PyAPI_FUNC(void*) _PyBytesWriter_Alloc(_PyBytesWriter *writer,
Py_ssize_t size); Py_ssize_t size);
/* Add *size* bytes to the buffer. /* Add *size* bytes to the buffer.
str is the current pointer inside the buffer. str is the current pointer inside the buffer.
Return the updated current pointer inside the buffer. Return the updated current pointer inside the buffer.
Raise an exception and return NULL on error. */ Raise an exception and return NULL on error. */
PyAPI_FUNC(char*) _PyBytesWriter_Prepare(_PyBytesWriter *writer, PyAPI_FUNC(void*) _PyBytesWriter_Prepare(_PyBytesWriter *writer,
char *str, void *str,
Py_ssize_t size); Py_ssize_t size);
/* Write bytes. /* Write bytes.
Raise an exception and return NULL on error. */ Raise an exception and return NULL on error. */
PyAPI_FUNC(char*) _PyBytesWriter_WriteBytes(_PyBytesWriter *writer, PyAPI_FUNC(void*) _PyBytesWriter_WriteBytes(_PyBytesWriter *writer,
char *str, void *str,
char *bytes, const void *bytes,
Py_ssize_t size); Py_ssize_t size);
#endif /* Py_LIMITED_API */ #endif /* Py_LIMITED_API */
......
...@@ -3923,8 +3923,8 @@ _PyBytesWriter_CheckConsistency(_PyBytesWriter *writer, char *str) ...@@ -3923,8 +3923,8 @@ _PyBytesWriter_CheckConsistency(_PyBytesWriter *writer, char *str)
#endif #endif
} }
char* void*
_PyBytesWriter_Prepare(_PyBytesWriter *writer, char *str, Py_ssize_t size) _PyBytesWriter_Prepare(_PyBytesWriter *writer, void *str, Py_ssize_t size)
{ {
Py_ssize_t allocated, pos; Py_ssize_t allocated, pos;
...@@ -3992,7 +3992,7 @@ _PyBytesWriter_Prepare(_PyBytesWriter *writer, char *str, Py_ssize_t size) ...@@ -3992,7 +3992,7 @@ _PyBytesWriter_Prepare(_PyBytesWriter *writer, char *str, Py_ssize_t size)
/* Allocate the buffer to write size bytes. /* Allocate the buffer to write size bytes.
Return the pointer to the beginning of buffer data. Return the pointer to the beginning of buffer data.
Raise an exception and return NULL on error. */ Raise an exception and return NULL on error. */
char* void*
_PyBytesWriter_Alloc(_PyBytesWriter *writer, Py_ssize_t size) _PyBytesWriter_Alloc(_PyBytesWriter *writer, Py_ssize_t size)
{ {
/* ensure that _PyBytesWriter_Alloc() is only called once */ /* ensure that _PyBytesWriter_Alloc() is only called once */
...@@ -4011,7 +4011,7 @@ _PyBytesWriter_Alloc(_PyBytesWriter *writer, Py_ssize_t size) ...@@ -4011,7 +4011,7 @@ _PyBytesWriter_Alloc(_PyBytesWriter *writer, Py_ssize_t size)
} }
PyObject * PyObject *
_PyBytesWriter_Finish(_PyBytesWriter *writer, char *str) _PyBytesWriter_Finish(_PyBytesWriter *writer, void *str)
{ {
Py_ssize_t pos; Py_ssize_t pos;
PyObject *result; PyObject *result;
...@@ -4033,13 +4033,12 @@ _PyBytesWriter_Finish(_PyBytesWriter *writer, char *str) ...@@ -4033,13 +4033,12 @@ _PyBytesWriter_Finish(_PyBytesWriter *writer, char *str)
else { else {
result = PyBytes_FromStringAndSize(writer->small_buffer, pos); result = PyBytes_FromStringAndSize(writer->small_buffer, pos);
} }
return result; return result;
} }
char* void*
_PyBytesWriter_WriteBytes(_PyBytesWriter *writer, char *str, _PyBytesWriter_WriteBytes(_PyBytesWriter *writer, void *str,
char *bytes, Py_ssize_t size) const void *bytes, Py_ssize_t size)
{ {
str = _PyBytesWriter_Prepare(writer, str, size); str = _PyBytesWriter_Prepare(writer, str, size);
if (str == NULL) if (str == NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment