summaryrefslogtreecommitdiffstats
path: root/Modules/clinic
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-06-30 06:03:15 (GMT)
committerGitHub <noreply@github.com>2020-06-30 06:03:15 (GMT)
commit349f76c6aace5a4a2b57f6b442a532faf0027d6b (patch)
treec9d8fe1e3062e51e65cd7b2a763822908cb7a1cb /Modules/clinic
parentb3332660adb02babb7e66e45310c66dc9a9a94da (diff)
downloadcpython-349f76c6aace5a4a2b57f6b442a532faf0027d6b.zip
cpython-349f76c6aace5a4a2b57f6b442a532faf0027d6b.tar.gz
cpython-349f76c6aace5a4a2b57f6b442a532faf0027d6b.tar.bz2
bpo-36346: Prepare for removing the legacy Unicode C API (AC only). (GH-21223)
Diffstat (limited to 'Modules/clinic')
-rw-r--r--Modules/clinic/_winapi.c.h15
-rw-r--r--Modules/clinic/posixmodule.c.h63
2 files changed, 68 insertions, 10 deletions
diff --git a/Modules/clinic/_winapi.c.h b/Modules/clinic/_winapi.c.h
index e21f2bc..6022dfe 100644
--- a/Modules/clinic/_winapi.c.h
+++ b/Modules/clinic/_winapi.c.h
@@ -367,13 +367,22 @@ _winapi_CreateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
const Py_UNICODE *current_directory;
PyObject *startup_info;
- if (!_PyArg_ParseStack(args, nargs, "ZOOOikOZO:CreateProcess",
- &application_name, &command_line, &proc_attrs, &thread_attrs, &inherit_handles, &creation_flags, &env_mapping, &current_directory, &startup_info)) {
+ if (!_PyArg_ParseStack(args, nargs, "O&OOOikOO&O:CreateProcess",
+ _PyUnicode_WideCharString_Opt_Converter, &application_name, &command_line, &proc_attrs, &thread_attrs, &inherit_handles, &creation_flags, &env_mapping, _PyUnicode_WideCharString_Opt_Converter, &current_directory, &startup_info)) {
goto exit;
}
return_value = _winapi_CreateProcess_impl(module, application_name, command_line, proc_attrs, thread_attrs, inherit_handles, creation_flags, env_mapping, current_directory, startup_info);
exit:
+ /* Cleanup for application_name */
+ #if !USE_UNICODE_WCHAR_CACHE
+ PyMem_Free((void *)application_name);
+ #endif /* USE_UNICODE_WCHAR_CACHE */
+ /* Cleanup for current_directory */
+ #if !USE_UNICODE_WCHAR_CACHE
+ PyMem_Free((void *)current_directory);
+ #endif /* USE_UNICODE_WCHAR_CACHE */
+
return return_value;
}
@@ -1097,4 +1106,4 @@ _winapi_GetFileType(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P
exit:
return return_value;
}
-/*[clinic end generated code: output=f3897898ea1da99d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=db87076a32fa7abe input=a9049054013a1b77]*/
diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h
index b691cfb..6533edf 100644
--- a/Modules/clinic/posixmodule.c.h
+++ b/Modules/clinic/posixmodule.c.h
@@ -1674,12 +1674,28 @@ os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k
{
PyObject *return_value = NULL;
static const char * const _keywords[] = {"command", NULL};
- static _PyArg_Parser _parser = {"u:system", _keywords, 0};
+ static _PyArg_Parser _parser = {NULL, _keywords, "system", 0};
+ PyObject *argsbuf[1];
const Py_UNICODE *command;
long _return_value;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- &command)) {
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[0])) {
+ _PyArg_BadArgument("system", "argument 'command'", "str", args[0]);
+ goto exit;
+ }
+ #if USE_UNICODE_WCHAR_CACHE
+ _Py_COMP_DIAG_PUSH
+ _Py_COMP_DIAG_IGNORE_DEPR_DECLS
+ command = _PyUnicode_AsUnicode(args[0]);
+ _Py_COMP_DIAG_POP
+ #else /* USE_UNICODE_WCHAR_CACHE */
+ command = PyUnicode_AsWideCharString(args[0], NULL);
+ #endif /* USE_UNICODE_WCHAR_CACHE */
+ if (command == NULL) {
goto exit;
}
_return_value = os_system_impl(module, command);
@@ -1689,6 +1705,11 @@ os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k
return_value = PyLong_FromLong(_return_value);
exit:
+ /* Cleanup for command */
+ #if !USE_UNICODE_WCHAR_CACHE
+ PyMem_Free((void *)command);
+ #endif /* USE_UNICODE_WCHAR_CACHE */
+
return return_value;
}
@@ -6998,19 +7019,47 @@ os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
{
PyObject *return_value = NULL;
static const char * const _keywords[] = {"filepath", "operation", NULL};
- static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
+ static _PyArg_Parser _parser = {NULL, _keywords, "startfile", 0};
+ PyObject *argsbuf[2];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
const Py_UNICODE *operation = NULL;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- path_converter, &filepath, &operation)) {
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!path_converter(args[0], &filepath)) {
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (!PyUnicode_Check(args[1])) {
+ _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]);
goto exit;
}
+ #if USE_UNICODE_WCHAR_CACHE
+ _Py_COMP_DIAG_PUSH
+ _Py_COMP_DIAG_IGNORE_DEPR_DECLS
+ operation = _PyUnicode_AsUnicode(args[1]);
+ _Py_COMP_DIAG_POP
+ #else /* USE_UNICODE_WCHAR_CACHE */
+ operation = PyUnicode_AsWideCharString(args[1], NULL);
+ #endif /* USE_UNICODE_WCHAR_CACHE */
+ if (operation == NULL) {
+ goto exit;
+ }
+skip_optional_pos:
return_value = os_startfile_impl(module, &filepath, operation);
exit:
/* Cleanup for filepath */
path_cleanup(&filepath);
+ /* Cleanup for operation */
+ #if !USE_UNICODE_WCHAR_CACHE
+ PyMem_Free((void *)operation);
+ #endif /* USE_UNICODE_WCHAR_CACHE */
return return_value;
}
@@ -8876,4 +8925,4 @@ exit:
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
-/*[clinic end generated code: output=d7c1212a94613496 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ba3d4b35fda2c208 input=a9049054013a1b77]*/