Skip to content

gh-116738: Make the array built in module safe for free threaded python #120103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Prev Previous commit
Next Next commit
gh-116738: correct Py_UCS4 access and mem allocation
  • Loading branch information
SonicField committed Jun 5, 2024
commit bc623ad3b15e06245a8c55ac0e91c20c5183a2b4
6 changes: 3 additions & 3 deletions Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@
if (array_get_item(ap, i, array_load_Py_UCS4, &x, sizeof(Py_UCS4))) {
return NULL;
}
return PyUnicode_FromOrdinal(((Py_UCS4 *) ap->ob_item)[i]);
return PyUnicode_FromOrdinal(x);
}

static int
Expand Down Expand Up @@ -1459,7 +1459,7 @@

void array_safe_memcpy(char* to, Py_ssize_t to_offset, char* from, Py_ssize_t from_offset, Py_ssize_t len)
{
int safe_len = len;

Check warning on line 1462 in Modules/arraymodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1462 in Modules/arraymodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1462 in Modules/arraymodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1462 in Modules/arraymodule.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
#ifdef Py_GIL_DISABLED
Py_ssize_t from_capacity = array_capacity(from);
Py_ssize_t to_capacity = array_capacity(to);
Expand All @@ -1471,14 +1471,14 @@
if (from_offset > from_capacity) {
return;
}
safe_len -= (total_len - from_capacity);

Check warning on line 1474 in Modules/arraymodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'-=': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1474 in Modules/arraymodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

'-=': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
}
total_len = to_offset + safe_len;
if (total_len > to_capacity) {
if (to_offset > to_capacity) {
return;
}
safe_len -= (total_len - to_capacity);

Check warning on line 1481 in Modules/arraymodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'-=': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1481 in Modules/arraymodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

'-=': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
}
#endif
memcpy(to + to_offset, from + from_offset, safe_len);
Expand Down Expand Up @@ -3541,11 +3541,11 @@

arrayobject *self = (arrayobject *)a;
#ifdef Py_GIL_DISABLED
if (array_resize(self, sizeof(wchar_t) * n, false)) {
if (array_resize(self, sizeof(Py_UCS4) * n, false)) {
Py_DECREF(a);
return NULL;
}
memcpy(self->ob_item, ustr, sizeof(wchar_t) * n);
memcpy(self->ob_item, ustr, sizeof(Py_UCS4) * n);
#else
// self->ob_item may be NULL but it is safe.
self->ob_item = (char *)ustr;
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy