diff options
author | Inada Naoki <songofacandy@gmail.com> | 2022-05-12 05:48:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-12 05:48:38 (GMT) |
commit | f9c9354a7a173eaca2aa19e667b5cf12167b7fed (patch) | |
tree | eb0fdd3219f53c973f1a7dbbcb9f8b0e0babdf36 /PC | |
parent | 68fec31364e96d122aae0571c14683b4ddb0ebd0 (diff) | |
download | cpython-f9c9354a7a173eaca2aa19e667b5cf12167b7fed.zip cpython-f9c9354a7a173eaca2aa19e667b5cf12167b7fed.tar.gz cpython-f9c9354a7a173eaca2aa19e667b5cf12167b7fed.tar.bz2 |
gh-92536: PEP 623: Remove wstr and legacy APIs from Unicode (GH-92537)
Diffstat (limited to 'PC')
-rw-r--r-- | PC/_msi.c | 6 | ||||
-rw-r--r-- | PC/clinic/_msi.c.h | 26 | ||||
-rw-r--r-- | PC/clinic/winreg.c.h | 74 | ||||
-rw-r--r-- | PC/winreg.c | 23 |
4 files changed, 2 insertions, 127 deletions
@@ -757,19 +757,13 @@ _msi_SummaryInformation_SetProperty_impl(msiobj *self, int field, int status; if (PyUnicode_Check(data)) { -#if USE_UNICODE_WCHAR_CACHE - const WCHAR *value = _PyUnicode_AsUnicode(data); -#else /* USE_UNICODE_WCHAR_CACHE */ WCHAR *value = PyUnicode_AsWideCharString(data, NULL); -#endif /* USE_UNICODE_WCHAR_CACHE */ if (value == NULL) { return NULL; } status = MsiSummaryInfoSetPropertyW(self->h, field, VT_LPSTR, 0, NULL, value); -#if !USE_UNICODE_WCHAR_CACHE PyMem_Free(value); -#endif /* USE_UNICODE_WCHAR_CACHE */ } else if (PyLong_CheckExact(data)) { long value = PyLong_AsLong(data); if (value == -1 && PyErr_Occurred()) { diff --git a/PC/clinic/_msi.c.h b/PC/clinic/_msi.c.h index fd21142..ca1f8ad 100644 --- a/PC/clinic/_msi.c.h +++ b/PC/clinic/_msi.c.h @@ -208,11 +208,7 @@ _msi_Record_SetString(msiobj *self, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("SetString", "argument 2", "str", args[1]); goto exit; } - #if USE_UNICODE_WCHAR_CACHE - value = _PyUnicode_AsUnicode(args[1]); - #else /* USE_UNICODE_WCHAR_CACHE */ value = PyUnicode_AsWideCharString(args[1], NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (value == NULL) { goto exit; } @@ -220,9 +216,7 @@ _msi_Record_SetString(msiobj *self, PyObject *const *args, Py_ssize_t nargs) exit: /* Cleanup for value */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)value); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -257,11 +251,7 @@ _msi_Record_SetStream(msiobj *self, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("SetStream", "argument 2", "str", args[1]); goto exit; } - #if USE_UNICODE_WCHAR_CACHE - value = _PyUnicode_AsUnicode(args[1]); - #else /* USE_UNICODE_WCHAR_CACHE */ value = PyUnicode_AsWideCharString(args[1], NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (value == NULL) { goto exit; } @@ -269,9 +259,7 @@ _msi_Record_SetStream(msiobj *self, PyObject *const *args, Py_ssize_t nargs) exit: /* Cleanup for value */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)value); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -561,11 +549,7 @@ _msi_Database_OpenView(msiobj *self, PyObject *arg) _PyArg_BadArgument("OpenView", "argument", "str", arg); goto exit; } - #if USE_UNICODE_WCHAR_CACHE - sql = _PyUnicode_AsUnicode(arg); - #else /* USE_UNICODE_WCHAR_CACHE */ sql = PyUnicode_AsWideCharString(arg, NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (sql == NULL) { goto exit; } @@ -573,9 +557,7 @@ _msi_Database_OpenView(msiobj *self, PyObject *arg) exit: /* Cleanup for sql */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)sql); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -660,11 +642,7 @@ _msi_OpenDatabase(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("OpenDatabase", "argument 1", "str", args[0]); goto exit; } - #if USE_UNICODE_WCHAR_CACHE - path = _PyUnicode_AsUnicode(args[0]); - #else /* USE_UNICODE_WCHAR_CACHE */ path = PyUnicode_AsWideCharString(args[0], NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (path == NULL) { goto exit; } @@ -676,9 +654,7 @@ _msi_OpenDatabase(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: /* Cleanup for path */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)path); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -713,4 +689,4 @@ _msi_CreateRecord(PyObject *module, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=d7eb07e6bfcdc13f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a592695c4315db22 input=a9049054013a1b77]*/ diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h index 8bcb290..6af24af 100644 --- a/PC/clinic/winreg.c.h +++ b/PC/clinic/winreg.c.h @@ -159,11 +159,7 @@ winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs computer_name = NULL; } else if (PyUnicode_Check(args[0])) { - #if USE_UNICODE_WCHAR_CACHE - computer_name = _PyUnicode_AsUnicode(args[0]); - #else /* USE_UNICODE_WCHAR_CACHE */ computer_name = PyUnicode_AsWideCharString(args[0], NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (computer_name == NULL) { goto exit; } @@ -183,9 +179,7 @@ winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs exit: /* Cleanup for computer_name */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)computer_name); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -233,11 +227,7 @@ winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) sub_key = NULL; } else if (PyUnicode_Check(args[1])) { - #if USE_UNICODE_WCHAR_CACHE - sub_key = _PyUnicode_AsUnicode(args[1]); - #else /* USE_UNICODE_WCHAR_CACHE */ sub_key = PyUnicode_AsWideCharString(args[1], NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (sub_key == NULL) { goto exit; } @@ -254,9 +244,7 @@ winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: /* Cleanup for sub_key */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)sub_key); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -318,9 +306,7 @@ winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py exit: /* Cleanup for sub_key */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)sub_key); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -366,11 +352,7 @@ winreg_DeleteKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("DeleteKey", "argument 2", "str", args[1]); goto exit; } - #if USE_UNICODE_WCHAR_CACHE - sub_key = _PyUnicode_AsUnicode(args[1]); - #else /* USE_UNICODE_WCHAR_CACHE */ sub_key = PyUnicode_AsWideCharString(args[1], NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (sub_key == NULL) { goto exit; } @@ -378,9 +360,7 @@ winreg_DeleteKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: /* Cleanup for sub_key */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)sub_key); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -437,9 +417,7 @@ winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py exit: /* Cleanup for sub_key */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)sub_key); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -478,11 +456,7 @@ winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) value = NULL; } else if (PyUnicode_Check(args[1])) { - #if USE_UNICODE_WCHAR_CACHE - value = _PyUnicode_AsUnicode(args[1]); - #else /* USE_UNICODE_WCHAR_CACHE */ value = PyUnicode_AsWideCharString(args[1], NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (value == NULL) { goto exit; } @@ -495,9 +469,7 @@ winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: /* Cleanup for value */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)value); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -622,11 +594,7 @@ winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg) _PyArg_BadArgument("ExpandEnvironmentStrings", "argument", "str", arg); goto exit; } - #if USE_UNICODE_WCHAR_CACHE - string = _PyUnicode_AsUnicode(arg); - #else /* USE_UNICODE_WCHAR_CACHE */ string = PyUnicode_AsWideCharString(arg, NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (string == NULL) { goto exit; } @@ -634,9 +602,7 @@ winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg) exit: /* Cleanup for string */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)string); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -734,11 +700,7 @@ winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("LoadKey", "argument 2", "str", args[1]); goto exit; } - #if USE_UNICODE_WCHAR_CACHE - sub_key = _PyUnicode_AsUnicode(args[1]); - #else /* USE_UNICODE_WCHAR_CACHE */ sub_key = PyUnicode_AsWideCharString(args[1], NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (sub_key == NULL) { goto exit; } @@ -746,11 +708,7 @@ winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("LoadKey", "argument 3", "str", args[2]); goto exit; } - #if USE_UNICODE_WCHAR_CACHE - file_name = _PyUnicode_AsUnicode(args[2]); - #else /* USE_UNICODE_WCHAR_CACHE */ file_name = PyUnicode_AsWideCharString(args[2], NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (file_name == NULL) { goto exit; } @@ -758,13 +716,9 @@ winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: /* Cleanup for sub_key */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)sub_key); - #endif /* USE_UNICODE_WCHAR_CACHE */ /* Cleanup for file_name */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)file_name); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -819,9 +773,7 @@ winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje exit: /* Cleanup for sub_key */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)sub_key); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -876,9 +828,7 @@ winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb exit: /* Cleanup for sub_key */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)sub_key); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -962,11 +912,7 @@ winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) sub_key = NULL; } else if (PyUnicode_Check(args[1])) { - #if USE_UNICODE_WCHAR_CACHE - sub_key = _PyUnicode_AsUnicode(args[1]); - #else /* USE_UNICODE_WCHAR_CACHE */ sub_key = PyUnicode_AsWideCharString(args[1], NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (sub_key == NULL) { goto exit; } @@ -979,9 +925,7 @@ winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: /* Cleanup for sub_key */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)sub_key); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -1025,11 +969,7 @@ winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) name = NULL; } else if (PyUnicode_Check(args[1])) { - #if USE_UNICODE_WCHAR_CACHE - name = _PyUnicode_AsUnicode(args[1]); - #else /* USE_UNICODE_WCHAR_CACHE */ name = PyUnicode_AsWideCharString(args[1], NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (name == NULL) { goto exit; } @@ -1042,9 +982,7 @@ winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: /* Cleanup for name */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)name); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -1093,11 +1031,7 @@ winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("SaveKey", "argument 2", "str", args[1]); goto exit; } - #if USE_UNICODE_WCHAR_CACHE - file_name = _PyUnicode_AsUnicode(args[1]); - #else /* USE_UNICODE_WCHAR_CACHE */ file_name = PyUnicode_AsWideCharString(args[1], NULL); - #endif /* USE_UNICODE_WCHAR_CACHE */ if (file_name == NULL) { goto exit; } @@ -1105,9 +1039,7 @@ winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: /* Cleanup for file_name */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)file_name); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -1162,9 +1094,7 @@ winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: /* Cleanup for sub_key */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)sub_key); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -1238,9 +1168,7 @@ winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: /* Cleanup for value_name */ - #if !USE_UNICODE_WCHAR_CACHE PyMem_Free((void *)value_name); - #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -1346,4 +1274,4 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=c3454803528f6e97 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9782b1630b59e201 input=a9049054013a1b77]*/ diff --git a/PC/winreg.c b/PC/winreg.c index 2d44c82..92d05f5 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -645,19 +645,9 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize) t = PyList_GET_ITEM(value, j); if (!PyUnicode_Check(t)) return FALSE; -#if USE_UNICODE_WCHAR_CACHE -_Py_COMP_DIAG_PUSH -_Py_COMP_DIAG_IGNORE_DEPR_DECLS - len = PyUnicode_GetSize(t); - if (len < 0) - return FALSE; - len++; -_Py_COMP_DIAG_POP -#else /* USE_UNICODE_WCHAR_CACHE */ len = PyUnicode_AsWideChar(t, NULL, 0); if (len < 0) return FALSE; -#endif /* USE_UNICODE_WCHAR_CACHE */ size += Py_SAFE_DOWNCAST(len * sizeof(wchar_t), size_t, DWORD); } @@ -1709,40 +1699,27 @@ winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, return NULL; } -#if USE_UNICODE_WCHAR_CACHE -_Py_COMP_DIAG_PUSH -_Py_COMP_DIAG_IGNORE_DEPR_DECLS - const wchar_t *value = PyUnicode_AsUnicodeAndSize(value_obj, &value_length); -_Py_COMP_DIAG_POP -#else /* USE_UNICODE_WCHAR_CACHE */ wchar_t *value = PyUnicode_AsWideCharString(value_obj, &value_length); -#endif /* USE_UNICODE_WCHAR_CACHE */ if (value == NULL) { return NULL; } if ((Py_ssize_t)(DWORD)value_length != value_length) { PyErr_SetString(PyExc_OverflowError, "value is too long"); -#if !USE_UNICODE_WCHAR_CACHE PyMem_Free(value); -#endif /* USE_UNICODE_WCHAR_CACHE */ return NULL; } if (PySys_Audit("winreg.SetValue", "nunu#", (Py_ssize_t)key, sub_key, (Py_ssize_t)type, value, value_length) < 0) { -#if !USE_UNICODE_WCHAR_CACHE PyMem_Free(value); -#endif /* USE_UNICODE_WCHAR_CACHE */ return NULL; } Py_BEGIN_ALLOW_THREADS rc = RegSetValueW(key, sub_key, REG_SZ, value, (DWORD)(value_length + 1)); Py_END_ALLOW_THREADS -#if !USE_UNICODE_WCHAR_CACHE PyMem_Free(value); -#endif /* USE_UNICODE_WCHAR_CACHE */ if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue"); Py_RETURN_NONE; |