Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
699e616
bpo-36346: Prepare for removing the legacy Unicode C API.
serhiy-storchaka Oct 26, 2018
60b89c9
Fix winreg.SetValue().
serhiy-storchaka Mar 19, 2019
f386b63
Clean up some ifdefs in _testcapimodule.
serhiy-storchaka Mar 19, 2019
11e0e0c
Make path_cleanup() paranoidally safer.
serhiy-storchaka Mar 19, 2019
236f608
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Mar 19, 2019
8750d48
Fix os.scandir().
serhiy-storchaka Mar 20, 2019
431e71f
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Mar 20, 2019
545c7a9
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Mar 28, 2019
3c1ab31
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Mar 13, 2020
54b0561
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Jun 15, 2020
2c62d96
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Jun 29, 2020
6d89775
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Jun 30, 2020
3b5294a
Silence compiler warnings.
serhiy-storchaka Jun 30, 2020
e7898fa
Fix PyUnicode_IsIdentifier for the cache-less build.
serhiy-storchaka Jun 30, 2020
fd641c6
Silence compiler warnings on Windows.
serhiy-storchaka Jun 30, 2020
a79d935
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Jun 30, 2020
ed14aa9
Fix compiler warning in _testcapi.
serhiy-storchaka Jun 30, 2020
c5eb102
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Jul 1, 2020
d529224
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Jul 1, 2020
6102b4b
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Jul 5, 2020
74695b3
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Jul 5, 2020
97b5228
Use HAVE_UNICODE_WCHAR_CACHE instead of USE_UNICODE_WCHAR_CACHE in _P…
serhiy-storchaka Jul 5, 2020
d6ba6b7
Set HAVE_UNICODE_WCHAR_CACHE and USE_UNICODE_WCHAR_CACHE only if they…
serhiy-storchaka Jul 9, 2020
0da4146
Remove Py_UNICODE_MATCH.
serhiy-storchaka Jul 9, 2020
51365fb
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Jul 10, 2020
e425908
Fix unterminated #if.
serhiy-storchaka Jul 10, 2020
8a9259b
Reset arraymodule.c.
serhiy-storchaka Jul 10, 2020
76ba4b6
Merge branch 'master' into disable-wchar-cache
serhiy-storchaka Jul 10, 2020
16ac7fd
Temporary disable the wchar_t cache by default.
serhiy-storchaka Jul 10, 2020
5950b5c
Remove HAVE_UNICODE_WCHAR_CACHE.
serhiy-storchaka Jul 10, 2020
065fc2d
Merge branch 'master' into do-not-use-wchar-cache
serhiy-storchaka Jul 10, 2020
672b8d7
Fix possible leaks.
serhiy-storchaka Jul 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into disable-wchar-cache
  • Loading branch information
serhiy-storchaka committed Mar 13, 2020
commit 3c1ab31a8b8eb889de7790047f4b05caba20aaaf
5 changes: 5 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
except ImportError:
resource = None

try:
import _hashlib
except ImportError:
_hashlib = None

try:
from _testcapi import unicode_legacy_string
except ImportError:
Expand Down
37 changes: 10 additions & 27 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1366,9 +1366,6 @@ WCharArray_get_value(CDataObject *self, void *Py_UNUSED(ignored))
static int
WCharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored))
{
Py_ssize_t result = 0;
Py_ssize_t len;

if (value == NULL) {
PyErr_SetString(PyExc_TypeError,
"can't delete attribute");
Expand All @@ -1379,38 +1376,24 @@ WCharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored
"unicode string expected instead of %s instance",
Py_TYPE(value)->tp_name);
return -1;
} else
Py_INCREF(value);
}

#if USE_UNICODE_WCHAR_CACHE
len = PyUnicode_GetSize(value);
Py_ssize_t size = self->b_size / sizeof(wchar_t);
Py_ssize_t len = PyUnicode_AsWideChar(value, NULL, 0);
if (len < 0) {
Py_DECREF(value);
return -1;
}
#else /* USE_UNICODE_WCHAR_CACHE */
len = PyUnicode_AsWideChar(value, NULL, 0);
if (len < 0) {
Py_DECREF(value);
// PyUnicode_AsWideChar() returns number of wchars including trailing null byte,
// when it is called with NULL.
assert(len > 0);
if (len - 1 > size) {
PyErr_SetString(PyExc_ValueError, "string too long");
return -1;
}
assert(len > 0);
len--;
#endif /* USE_UNICODE_WCHAR_CACHE */
if ((size_t)len > self->b_size/sizeof(wchar_t)) {
PyErr_SetString(PyExc_ValueError,
"string too long");
Py_DECREF(value);
if (PyUnicode_AsWideChar(value, (wchar_t *)self->b_ptr, size) < 0) {
return -1;
}
result = PyUnicode_AsWideChar(value,
(wchar_t *)self->b_ptr,
self->b_size/sizeof(wchar_t));
if (result >= 0 && (size_t)result < self->b_size/sizeof(wchar_t))
((wchar_t *)self->b_ptr)[result] = (wchar_t)0;
Py_DECREF(value);

return result >= 0 ? 0 : -1;
return 0;
}

static PyGetSetDef WCharArray_getsets[] = {
Expand Down
12 changes: 10 additions & 2 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,8 +1315,16 @@ static PyObject *load_library(PyObject *self, PyObject *args)
#if !USE_UNICODE_WCHAR_CACHE
PyMem_Free(name);
#endif /* USE_UNICODE_WCHAR_CACHE */
if (!hMod)
return PyErr_SetFromWindowsErr(GetLastError());
if (err == ERROR_MOD_NOT_FOUND) {
PyErr_Format(PyExc_FileNotFoundError,
("Could not find module '%.500S' (or one of its "
"dependencies). Try using the full path with "
"constructor syntax."),
nameobj);
return NULL;
} else if (err) {
return PyErr_SetFromWindowsErr(err);
}
#ifdef _WIN64
return PyLong_FromVoidPtr(hMod);
#else
Expand Down
26 changes: 8 additions & 18 deletions Modules/_ctypes/cfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -1228,8 +1228,6 @@ U_get(void *ptr, Py_ssize_t size)
static PyObject *
U_set(void *ptr, PyObject *value, Py_ssize_t length)
{
Py_ssize_t size;

/* It's easier to calculate in characters than in bytes */
length /= sizeof(wchar_t);

Expand All @@ -1240,16 +1238,14 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
return NULL;
}

#if USE_UNICODE_WCHAR_CACHE
size = PyUnicode_GetSize(value);
if (size < 0)
return NULL;
#else /* USE_UNICODE_WCHAR_CACHE */
size = PyUnicode_AsWideChar(value, NULL, 0);
if (size < 0)
Py_ssize_t size = PyUnicode_AsWideChar(value, NULL, 0);
if (size < 0) {
return NULL;
}
// PyUnicode_AsWideChar() returns number of wchars including trailing null byte,
// when it is called with NULL.
size--;
#endif /* USE_UNICODE_WCHAR_CACHE */
assert(size >= 0);
if (size > length) {
PyErr_Format(PyExc_ValueError,
"string too long (%zd, maximum length %zd)",
Expand Down Expand Up @@ -1424,12 +1420,8 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
/* create a BSTR from value */
if (value) {
Py_ssize_t wsize;
#if USE_UNICODE_WCHAR_CACHE
wvalue = PyUnicode_AsUnicodeAndSize(value, &wsize);
#else /* USE_UNICODE_WCHAR_CACHE */
wvalue = PyUnicode_AsWideCharString(value, &wsize);
#endif /* USE_UNICODE_WCHAR_CACHE */
if (wvalue == NULL)
wchar_t *wvalue = PyUnicode_AsWideCharString(value, &wsize);
if (wvalue == NULL) {
return NULL;
}
if ((unsigned) wsize != wsize) {
Expand All @@ -1438,9 +1430,7 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
return NULL;
}
bstr = SysAllocStringLen(wvalue, (unsigned)wsize);
#if !USE_UNICODE_WCHAR_CACHE
PyMem_Free(wvalue);
#endif /* USE_UNICODE_WCHAR_CACHE */
} else
bstr = NULL;

Expand Down
6 changes: 3 additions & 3 deletions Modules/clinic/_winapi.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Modules/clinic/arraymodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 2 additions & 57 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -10255,65 +10255,10 @@ static PyObject *
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value)
/*[clinic end generated code: output=d29a567d6b2327d2 input=ba586581c2e6105f]*/
{
Py_ssize_t size;

/* Search from index 1 because on Windows starting '=' is allowed for
defining hidden environment variables. */
if (PyUnicode_GET_LENGTH(name) == 0 ||
PyUnicode_FindChar(name, '=', 1, PyUnicode_GET_LENGTH(name), 1) != -1)
{
PyErr_SetString(PyExc_ValueError, "illegal environment variable name");
return NULL;
}
PyObject *buffer = PyUnicode_FromFormat("%U=%U", name, value);
if (buffer == NULL) {
return NULL;
}

#if USE_UNICODE_WCHAR_CACHE
const wchar_t *env = PyUnicode_AsUnicodeAndSize(buffer, &size);
if (env == NULL)
goto error;
#else /* USE_UNICODE_WCHAR_CACHE */
size = PyUnicode_AsWideChar(buffer, NULL, 0);
if (size < 0) {
if (PySys_Audit("os.putenv", "OO", name, value) < 0) {
return NULL;
}
if ((size_t)size > (size_t)PY_SSIZE_T_MAX / sizeof(wchar_t)) {
return PyErr_NoMemory();
}
PyObject *bytes = PyBytes_FromStringAndSize(NULL, size * sizeof(wchar_t));
if (bytes == NULL) {
goto error;
}
wchar_t *env = (wchar_t *)PyBytes_AS_STRING(bytes);
size = PyUnicode_AsWideChar(buffer, env, size);
assert(size >= 0);
Py_DECREF(buffer);
buffer = bytes;
#endif /* USE_UNICODE_WCHAR_CACHE */
if (size > _MAX_ENV) {
PyErr_Format(PyExc_ValueError,
"the environment variable is longer than %u characters",
_MAX_ENV);
goto error;
}
if (wcslen(env) != (size_t)size) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto error;
}

if (_wputenv(env)) {
posix_error();
goto error;
}

posix_putenv_garbage_setitem(name, buffer);
Py_RETURN_NONE;

error:
Py_DECREF(buffer);
return NULL;
return win32_putenv(name, value);
}
#else
/*[clinic input]
Expand Down
23 changes: 12 additions & 11 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,12 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
else
#endif /* HAVE_UNICODE_WCHAR_CACHE */
{
ASSERT(kind == PyUnicode_1BYTE_KIND
|| kind == PyUnicode_2BYTE_KIND
|| kind == PyUnicode_4BYTE_KIND);
ASSERT(ascii->state.compact == 0);
ASSERT(ascii->state.ready == 1);
ASSERT(data != NULL);
CHECK(kind == PyUnicode_1BYTE_KIND
|| kind == PyUnicode_2BYTE_KIND
|| kind == PyUnicode_4BYTE_KIND);
CHECK(ascii->state.compact == 0);
CHECK(ascii->state.ready == 1);
CHECK(data != NULL);
if (ascii->state.ascii) {
CHECK(compact->utf8 == data);
CHECK(compact->utf8_length == ascii->length);
Expand All @@ -573,10 +573,10 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
#endif /* HAVE_UNICODE_WCHAR_CACHE */

if (compact->utf8 == NULL)
ASSERT(compact->utf8_length == 0);
CHECK(compact->utf8_length == 0);
#if HAVE_UNICODE_WCHAR_CACHE
if (ascii->wstr == NULL)
ASSERT(compact->wstr_length == 0);
CHECK(compact->wstr_length == 0);
#endif /* HAVE_UNICODE_WCHAR_CACHE */
}

Expand Down Expand Up @@ -1369,7 +1369,7 @@ _PyUnicode_Dump(PyObject *op)
printf(", ");
if (ascii->wstr == data)
printf("shared ");
printf("wstr=%p", ascii->wstr);
printf("wstr=%p", (void *)ascii->wstr);
#endif /* HAVE_UNICODE_WCHAR_CACHE */

if (!(ascii->state.ascii == 1 && ascii->state.compact == 1)) {
Expand Down Expand Up @@ -1962,10 +1962,11 @@ unicode_dealloc(PyObject *unicode)
}

#if HAVE_UNICODE_WCHAR_CACHE
if (_PyUnicode_HAS_WSTR_MEMORY(unicode))
if (_PyUnicode_HAS_WSTR_MEMORY(unicode)) {
PyObject_DEL(_PyUnicode_WSTR(unicode));
}
#endif /* HAVE_UNICODE_WCHAR_CACHE */
if (_PyUnicode_HAS_UTF8_MEMORY(unicode))
if (_PyUnicode_HAS_UTF8_MEMORY(unicode)) {
PyObject_DEL(_PyUnicode_UTF8(unicode));
}
if (!PyUnicode_IS_COMPACT(unicode) && _PyUnicode_DATA_ANY(unicode)) {
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.