8000 gh-92536: PEP 623: Remove wstr from unicode by methane · Pull Request #92537 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-92536: PEP 623: Remove wstr from unicode #92537

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

Merged
merged 21 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Remove USE_UNICODE_WCHAR_CACHE
  • Loading branch information
methane committed May 9, 2022
commit 06fc65bc8bf27dce7a793e315725ef14d859403d
4 changes: 0 additions & 4 deletions Include/cpython/unicodeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@

/* --- Internal Unicode Operations ---------------------------------------- */

#ifndef USE_UNICODE_WCHAR_CACHE
# define USE_UNICODE_WCHAR_CACHE 1
#endif /* USE_UNICODE_WCHAR_CACHE */

/* Since splitting on whitespace is an important use case, and
whitespace in most situations is solely ASCII whitespace, we
optimize for the common case by using a quick look-up table
Expand Down
8 changes: 1 addition & 7 deletions Lib/test/clinic.test
Original file line number Diff line number Diff line change
Expand Up @@ -1819,17 +1819,11 @@ test_Py_UNICODE_converter(PyObject *module, PyObject *const *args, Py_ssize_t na

exit:
/* Cleanup for a */
#if !USE_UNICODE_WCHAR_CACHE
PyMem_Free((void *)a);
#endif /* USE_UNICODE_WCHAR_CACHE */
/* Cleanup for b */
#if !USE_UNICODE_WCHAR_CACHE
PyMem_Free((void *)b);
#endif /* USE_UNICODE_WCHAR_CACHE */
/* Cleanup for c */
#if !USE_UNICODE_WCHAR_CACHE
PyMem_Free((void *)c);
#endif /* USE_UNICODE_WCHAR_CACHE */

return return_value;
}
Expand All @@ -1839,7 +1833,7 @@ test_Py_UNICODE_converter_impl(PyObject *module, const Py_UNICODE *a,
const Py_UNICODE *b, const Py_UNICODE *c,
const Py_UNICODE *d, Py_ssize_t d_length,
const Py_UNICODE *e, Py_ssize_t e_length)
/*[clinic end generated code: output=45e92604de227552 input=064a3b68ad7f04b0]*/
/*[clinic end generated code: output=4d426808cdbb3ea3 input=064a3b68ad7f04b0]*/


/*[clinic input]
Expand Down
8000
8 changes: 0 additions & 8 deletions Lib/test/test_getargs2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,14 +1255,6 @@ class Test_testcapi(unittest.TestCase):
for name in dir(_testcapi)
if name.startswith('test_') and name.endswith('_code'))

@warnings_helper.ignore_warnings(category=DeprecationWarning)
def test_u_code(self):
_testcapi.test_u_code()

@warnings_helper.ignore_warnings(category=DeprecationWarning)
def test_Z_code(self):
_testcapi.test_Z_code()


if __name__ == "__main__":
unittest.main()
9 changes: 0 additions & 9 deletions Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,7 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
if (!PyUnicode_FSDecoder(nameobj, &stringobj)) {
return -1;
}
#if USE_UNICODE_WCHAR_CACHE
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
widename = PyUnicode_AsUnicode(stringobj);
_Py_COMP_DIAG_POP
#else /* USE_UNICODE_WCHAR_CACHE */
widename = PyUnicode_AsWideCharString(stringobj, NULL);
#endif /* USE_UNICODE_WCHAR_CACHE */
if (widename == NULL)
return -1;
#else
Expand Down Expand Up @@ -497,9 +490,7 @@ _Py_COMP_DIAG_POP

done:
#ifdef MS_WINDOWS
#if !USE_UNICODE_WCHAR_CACHE
PyMem_Free(widename);
#endif /* USE_UNICODE_WCHAR_CACHE */
#endif
Py_CLEAR(stringobj);
return ret;
Expand Down
175 changes: 0 additions & 175 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1991,116 +1991,6 @@ parse_tuple_and_keywords(PyObject *self, PyObject *args)
return return_value;
}

static volatile int x;

#if USE_UNICODE_WCHAR_CACHE
/* Ignore use of deprecated APIs */
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS

/* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case
of an error.
*/
static PyObject *
test_u_code(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *tuple, *obj;
Py_UNICODE *value;
Py_ssize_t len;

/* issue4122: Undefined reference to _Py_ascii_whitespace on Windows */
/* Just use the macro and check that it compiles */
x = Py_UNICODE_ISSPACE(25);

tuple = PyTuple_New(1);
if (tuple == NULL)
return NULL;

obj = PyUnicode_Decode("test", strlen("test"),
"ascii", NULL);
if (obj == NULL)
return NULL;

PyTuple_SET_ITEM(tuple, 0, obj);

value = 0;
if (!PyArg_ParseTuple(tuple, "u:test_u_code", &value)) {
return NULL;
}
if (value != PyUnicode_AS_UNICODE(obj))
return raiseTestError("te 9E88 st_u_code",
"u code returned wrong value for u'test'");
value = 0;
if (!PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len)) {
return NULL;
}
if (value != PyUnicode_AS_UNICODE(obj) ||
len != PyUnicode_GET_SIZE(obj))
return raiseTestError("test_u_code",
"u# code returned wrong values for u'test'");

Py_DECREF(tuple);
Py_RETURN_NONE;
}

/* Test Z and Z# codes for PyArg_ParseTuple */
static PyObject *
test_Z_code(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *tuple, *obj;
const Py_UNICODE *value1, *value2;
Py_ssize_t len1, len2;

tuple = PyTuple_New(2);
if (tuple == NULL)
return NULL;

obj = PyUnicode_FromString("test");
PyTuple_SET_ITEM(tuple, 0, obj);
Py_INCREF(Py_None);
PyTuple_SET_ITEM(tuple, 1, Py_None);

/* swap values on purpose */
value1 = NULL;
value2 = PyUnicode_AS_UNICODE(obj);

/* Test Z for both values */
if (!PyArg_ParseTuple(tuple, "ZZ:test_Z_code", &value1, &value2)) {
return NULL;
}
if (value1 != PyUnicode_AS_UNICODE(obj))
return raiseTestError("test_Z_code",
"Z code returned wrong value for 'test'");
if (value2 != NULL)
return raiseTestError("test_Z_code",
"Z code returned wrong value for None");

value1 = NULL;
value2 = PyUnicode_AS_UNICODE(obj);
len1 = -1;
len2 = -1;

/* Test Z# for both values */
if (!PyArg_ParseTuple(tuple, "Z#Z#:test_Z_code", &value1, &len1,
&value2, &len2))
{
return NULL;
}
if (value1 != PyUnicode_AS_UNICODE(obj) ||
len1 != PyUnicode_GET_SIZE(obj))
return raiseTestError("test_Z_code",
"Z# code returned wrong values for 'test'");
if (value2 != NULL ||
len2 != 0)
return raiseTestError("test_Z_code",
"Z# code returned wrong values for None'");

Py_DECREF(tuple);
Py_RETURN_NONE;
}
_Py_COMP_DIAG_POP
#endif /* USE_UNICODE_WCHAR_CACHE */

static PyObject *
test_widechar(PyObject *self, PyObject *Py_UNUSED(ignored))
{
Expand Down Expand Up @@ -2151,35 +2041,7 @@ test_widechar(PyObject *self, PyObject *Py_UNUSED(ignored))
else
return raiseTestError("test_widechar",
"PyUnicode_FromWideChar(L\"\\U00110000\", 1) didn't fail");

#if USE_UNICODE_WCHAR_CACHE
/* Ignore use of deprecated APIs */
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
wide = PyUnicode_FromUnicode(invalid, 1);
if (wide == NULL)
PyErr_Clear();
else
return raiseTestError("test_widechar",
"PyUnicode_FromUnicode(L\"\\U00110000\", 1) didn't fail");

wide = PyUnicode_FromUnicode(NULL, 1);
if (wide == NULL)
return NULL;
PyUnicode_AS_UNICODE(wide)[0] = invalid[0];
if (_PyUnicode_Ready(wide) < 0) {
Py_DECREF(wide);
PyErr_Clear();
}
else {
Py_DECREF(wide);
return raiseTestError("test_widechar",
"PyUnicode_Ready() didn't fail");
}
_Py_COMP_DIAG_POP
#endif /* USE_UNICODE_WCHAR_CACHE */
#endif

Py_RETURN_NONE;
}

Expand Down Expand Up @@ -2357,36 +2219,6 @@ unicode_copycharacters(PyObject *self, PyObject *args)
return Py_BuildValue("(Nn)", to_copy, copied);
}

#if USE_UNICODE_WCHAR_CACHE
/* Ignore use of deprecated APIs */
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS

static PyObject *
unicode_legacy_string(PyObject *self, PyObject *args)
{
Py_UNICODE *data;
Py_ssize_t len;
PyObject *u;

if (!PyArg_ParseTuple(args, "u#", &data, &len))
return NULL;

u = PyUnicode_FromUnicode(NULL, len);
if (u == NULL)
return NULL;

memcpy(PyUnicode_AS_UNICODE(u), data, len * sizeof(Py_UNICODE));

if (len > 0) { /* The empty string is always ready. */
assert(!PyUnicode_IS_READY(u));
}

return u;
}
_Py_COMP_DIAG_POP
#endif /* USE_UNICODE_WCHAR_CACHE */

static PyObject *
getargs_w_star(PyObject *self, PyObject *args)
{
Expand Down Expand Up @@ -6092,10 +5924,6 @@ static PyMethodDef TestMethods[] = {
{"codec_incrementaldecoder",
(PyCFunction)codec_incrementaldecoder, METH_VARARGS},
{"test_s_code", test_s_code, METH_NOARGS},
#if USE_UNICODE_WCHAR_CACHE
{"test_u_code", test_u_code, METH_NOARGS},
{"test_Z_code", test_Z_code, METH_NOARGS},
#endif /* USE_UNICODE_WCHAR_CACHE */
{"test_widechar", test_widechar, METH_NOARGS},
{"unicode_aswidechar", unicode_aswidechar, METH_VARARGS},
{"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS},
Expand All @@ -6104,9 +5932,6 @@ static PyMethodDef TestMethods[] = {
{"unicode_asutf8andsize", unicode_asutf8andsize, METH_VARARGS},
{"unicode_findchar", unicode_findchar, METH_VARARGS},
{"unicode_copycharacters", unicode_copycharacters, METH_VARARGS},
#if USE_UNICODE_WCHAR_CACHE
{"unicode_legacy_string", unicode_legacy_string, METH_VARARGS},
#endif /* USE_UNICODE_WCHAR_CACHE */
{"_test_thread_state", test_thread_state, METH_VARARGS},
{"_pending_threadfunc", pending_threadfunc, METH_VARARGS},
#ifdef HAVE_GETTIMEOFDAY
Expand Down
22 changes: 1 addition & 21 deletions Modules/clinic/_winapi.c.h

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

Loading
0