Skip to content

Commit

Permalink
Use uint32_t for the format
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Jun 14, 2024
1 parent fa0ff6d commit 11b9f43
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Include/unicodeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,23 +261,23 @@ PyAPI_FUNC(PyObject *) PyUnicode_InternFromString(
// The export must be released by PyUnicode_ReleaseExport().
PyAPI_FUNC(const void*) PyUnicode_Export(
PyObject *unicode,
unsigned int supported_formats,
uint32_t supported_formats,
Py_ssize_t *size,
unsigned int *format);
uint32_t *format);

// Release an export created by PyUnicode_Export().
PyAPI_FUNC(void) PyUnicode_ReleaseExport(
PyObject *unicode,
const void* data,
unsigned int format);
uint32_t format);

// Create a string object from a string in the format 'format'.
// - Return a reference to a new string object on success.
// - Set an exception and return NULL on error.
PyAPI_FUNC(PyObject*) PyUnicode_Import(
const void *data,
Py_ssize_t size,
unsigned int format);
uint32_t format);

/* --- wchar_t support for platforms which support it --------------------- */

Expand Down
6 changes: 3 additions & 3 deletions Modules/_testlimitedcapi/unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1849,13 +1849,13 @@ unicode_export(PyObject *self, PyObject *args)
}

Py_ssize_t size;
unsigned int format;
uint32_t format;
const void *data = PyUnicode_Export(obj, supported_formats, &size, &format);
if (data == NULL) {
return NULL;
}

PyObject *res = Py_BuildValue("y#i", data, size, format);
PyObject *res = Py_BuildValue("y#I", data, size, (unsigned int)format);
PyUnicode_ReleaseExport(obj, data, format);
return res;
}
Expand All @@ -1868,7 +1868,7 @@ unicode_import(PyObject *self, PyObject *args)
const void *data;
Py_ssize_t size;
unsigned int format;
if (!PyArg_ParseTuple(args, "y#i", &data, &size, &format)) {
if (!PyArg_ParseTuple(args, "y#I", &data, &size, &format)) {
return NULL;
}
return PyUnicode_Import(data, size, format);
Expand Down
8 changes: 4 additions & 4 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2098,8 +2098,8 @@ _PyUnicode_FromUCS4(const Py_UCS4 *u, Py_ssize_t size)
}

const void*
PyUnicode_Export(PyObject *unicode, unsigned int supported_formats,
Py_ssize_t *size, unsigned int *format)
PyUnicode_Export(PyObject *unicode, uint32_t supported_formats,
Py_ssize_t *size, uint32_t *format)
{
if (!PyUnicode_Check(unicode)) {
PyErr_Format(PyExc_TypeError, "must be str, not %T", unicode);
Expand Down Expand Up @@ -2173,7 +2173,7 @@ PyUnicode_Export(PyObject *unicode, unsigned int supported_formats,

void
PyUnicode_ReleaseExport(PyObject *unicode, const void* data,
unsigned int format)
uint32_t format)
{
switch (format)
{
Expand All @@ -2198,7 +2198,7 @@ PyUnicode_ReleaseExport(PyObject *unicode, const void* data,

PyObject*
PyUnicode_Import(const void *data, Py_ssize_t size,
unsigned int format)
uint32_t format)
{
if (size < 0) {
PyErr_SetString(PyExc_ValueError, "Negative size");
Expand Down

0 comments on commit 11b9f43

Please sign in to comment.