diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2018-01-29 01:56:10 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2018-01-29 01:56:10 (GMT) |
commit | 6c6ddf97c402709713d668d0ed53836a7749ba99 (patch) | |
tree | e403bfbc134daea26026db43b207bbdb203019fa /Modules/clinic | |
parent | f5b04a360e44aa9733f7a92dd66d2292d6c52955 (diff) | |
download | cpython-6c6ddf97c402709713d668d0ed53836a7749ba99.zip cpython-6c6ddf97c402709713d668d0ed53836a7749ba99.tar.gz cpython-6c6ddf97c402709713d668d0ed53836a7749ba99.tar.bz2 |
bpo-20104: Expose `posix_spawn` in the os module (GH-5109)
Add os.posix_spawn to wrap the low level POSIX API of the same name.
Contributed by Pablo Galindo.
Diffstat (limited to 'Modules/clinic')
-rw-r--r-- | Modules/clinic/posixmodule.c.h | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index f432437..d6af15f 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -1721,6 +1721,54 @@ exit: #endif /* defined(HAVE_EXECV) */ +#if defined(HAVE_POSIX_SPAWN) + +PyDoc_STRVAR(os_posix_spawn__doc__, +"posix_spawn($module, path, argv, env, file_actions=None, /)\n" +"--\n" +"\n" +"Execute the program specified by path in a new process.\n" +"\n" +" path\n" +" Path of executable file.\n" +" argv\n" +" Tuple or list of strings.\n" +" env\n" +" Dictionary of strings mapping to strings.\n" +" file_actions\n" +" FileActions object."); + +#define OS_POSIX_SPAWN_METHODDEF \ + {"posix_spawn", (PyCFunction)os_posix_spawn, METH_FASTCALL, os_posix_spawn__doc__}, + +static PyObject * +os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv, + PyObject *env, PyObject *file_actions); + +static PyObject * +os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0); + PyObject *argv; + PyObject *env; + PyObject *file_actions = Py_None; + + if (!_PyArg_ParseStack(args, nargs, "O&OO|O:posix_spawn", + path_converter, &path, &argv, &env, &file_actions)) { + goto exit; + } + return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions); + +exit: + /* Cleanup for path */ + path_cleanup(&path); + + return return_value; +} + +#endif /* defined(HAVE_POSIX_SPAWN) */ + #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) PyDoc_STRVAR(os_spawnv__doc__, @@ -6137,6 +6185,10 @@ exit: #define OS_EXECVE_METHODDEF #endif /* !defined(OS_EXECVE_METHODDEF) */ +#ifndef OS_POSIX_SPAWN_METHODDEF + #define OS_POSIX_SPAWN_METHODDEF +#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */ + #ifndef OS_SPAWNV_METHODDEF #define OS_SPAWNV_METHODDEF #endif /* !defined(OS_SPAWNV_METHODDEF) */ @@ -6528,4 +6580,4 @@ exit: #ifndef OS_GETRANDOM_METHODDEF #define OS_GETRANDOM_METHODDEF #endif /* !defined(OS_GETRANDOM_METHODDEF) */ -/*[clinic end generated code: output=06ace805893aa10c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8e5d4a01257b6292 input=a9049054013a1b77]*/ |