| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
PySequence_Check
Sorry, something went wrong.
There was a problem hiding this comment.
This class does not map well to the POSIX posix_spawn() API. It take an arbitrary ordered sequence of file_actions populated by the underlying posix_spawn_file_actions_add{dup2,open.close} C APIs.
What you really want is for the posix_spawn Python API to take a list of actions, each of which is an instance of a fileaction describing a dup2/open/close operation.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks @gpshead ! That makes a lot of sense. Should I create three different classes for dup2/open/close and pass a list of these of there is a better approach?
Sorry, something went wrong.
There was a problem hiding this comment.
The Python API name should be .posix_spawn to match the posix C API name.
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request. |
Sorry, something went wrong.
|
I suggest creating namedtuple instances for each of dup2, open, and close in the module and requiring this parameter to be a sequence of those. |
Sorry, something went wrong.
|
Is then ok to bring collections to the os module? I am asking this because is a big dependency. |
Sorry, something went wrong.
|
good point. given that, just define a trio of simple data classes of your own or some constants to indicate open/close/dup2 for use as the first element of a tuple? the "good" thing about os/posix module APIs is that they can be quite low level looking. This is the module providing a relatively raw wrapper of system calls. higher level abstrations to make using them easier often live in other modules. |
Sorry, something went wrong.
|
I have made the requested changes; please review again |
Sorry, something went wrong.
|
Thanks for making the requested changes! @gpshead: please review the changes made to this pull request. |
Sorry, something went wrong.
There was a problem hiding this comment.
Shouldn't this be hasattr(os, "posix_spawn"). Same for the other test
Sorry, something went wrong.
There was a problem hiding this comment.
News needs update to no longer mention FileActions class
Sorry, something went wrong.
|
@pppery Thanks! Corrected in b9db2c8 |
Sorry, something went wrong.
There was a problem hiding this comment.
you need to check for errors in all of these cases: The PyXXX_AsYYY APIs can cause TypeError or OverflowError. PyLong_As APIs return -1 on error, use PyErr_Occurred() to disambiguate. Check for NULL from PyUnicode_As.
Sorry, something went wrong.
There was a problem hiding this comment.
Done in cb440d5
Sorry, something went wrong.
There was a problem hiding this comment.
mention the name of the ifdef this pairs with.
Sorry, something went wrong.
There was a problem hiding this comment.
lack of indentation down here looks odd for everything but the "fail:" label.
Sorry, something went wrong.
There was a problem hiding this comment.
Done in cb440d5
Sorry, something went wrong.
|
I have made the requested changes; please review again |
Sorry, something went wrong.
|
Thanks for making the requested changes! @gpshead: please review the changes made to this pull request. |
Sorry, something went wrong.
| argv is a list or tuple of strings and env is a dictionary | ||
| like posix.environ. */ | ||
|
|
||
| if (!PySequence_Check(argv)){ |
There was a problem hiding this comment.
Why not (!PyList_Check(argv) && !PyTuple_Check(argv)) as in other places?
Sorry, something went wrong.
| Py_ssize_t argc, envc; | ||
|
|
||
| /* posix_spawn has three arguments: (path, argv, env), where | ||
| argv is a list or tuple of strings and env is a dictionary |
There was a problem hiding this comment.
Bad indentation.
Sorry, something went wrong.
| posix_spawn_file_actions_t *file_actionsp = NULL; | ||
| if (file_actions != NULL && file_actions != Py_None){ | ||
| posix_spawn_file_actions_t _file_actions; | ||
| if(posix_spawn_file_actions_init(&_file_actions) != 0){ |
There was a problem hiding this comment.
Doesn't conform PEP 7. Needed spaces after "if" and before "{".
Sorry, something went wrong.
| "Error initializing file actions"); | ||
| goto fail; | ||
| } | ||
|
|
There was a problem hiding this comment.
Too much empty lines.
Sorry, something went wrong.
| for (int i = 0; i < PySequence_Fast_GET_SIZE(seq); ++i) { | ||
| file_actions_obj = PySequence_Fast_GET_ITEM(seq, i); | ||
|
|
||
| if(!PySequence_Check(file_actions_obj) | !PySequence_Size(file_actions_obj)){ |
There was a problem hiding this comment.
PySequence_Size() can be called before PySequence_Check().
Use PySequence_Fast_GET_SIZE() instead of PySequence_Check().
Sorry, something went wrong.
| goto fail; | ||
| } | ||
|
|
||
| long open_fd = PyLong_AsLong(PySequence_GetItem(file_actions_obj, 1)); |
There was a problem hiding this comment.
PyLong_AsLong() can call arbitrary Python code. This can cause changing the size of file_actions_obj. Following PySequence_GetItem() can fail.
I would require file_actions_obj to be a tuple and use PyArg_ParseTuple() for parsing it.
Sorry, something went wrong.
| } | ||
|
|
||
| long open_fd = PyLong_AsLong(PySequence_GetItem(file_actions_obj, 1)); | ||
| if(PyErr_Occurred()) { |
There was a problem hiding this comment.
Use idiomatic code:
if (open_fd == -1 && PyErr_Occurred()) {
Sorry, something went wrong.
|
|
||
| _Py_BEGIN_SUPPRESS_IPH | ||
| posix_spawn(&pid, path->narrow, file_actionsp, NULL, argvlist, envlist); | ||
| return PyLong_FromPid(pid); |
There was a problem hiding this comment.
Return before _Py_END_SUPPRESS_IPH? This looks like a bug.
Sorry, something went wrong.
| } | ||
|
|
||
| _Py_BEGIN_SUPPRESS_IPH | ||
| posix_spawn(&pid, path->narrow, file_actionsp, NULL, argvlist, envlist); |
There was a problem hiding this comment.
The result of the call is not checked.
Sorry, something went wrong.
|
|
||
| path_error(path); | ||
|
|
||
| free_string_array(envlist, envc); |
There was a problem hiding this comment.
Isn't it leaked in error case?
Sorry, something went wrong.
| if(PyErr_Occurred()) { | ||
| goto fail; | ||
| } | ||
| const char* open_path = PyUnicode_AsUTF8(PySequence_GetItem(file_actions_obj, 2)); |
There was a problem hiding this comment.
Use filesystem encoding. PyUnicode_FSDecoder() or like.
Sorry, something went wrong.
| goto fail; | ||
| } | ||
|
|
||
| long open_fd = PyLong_AsLong(PySequence_GetItem(file_actions_obj, 1)); |
There was a problem hiding this comment.
open_fd should be of type int. Use _PyLong_AsInt().
Sorry, something went wrong.
| if(open_path == NULL){ | ||
| goto fail; | ||
| } | ||
| long open_oflag = PyLong_AsLong(PySequence_GetItem(file_actions_obj, 3)); |
There was a problem hiding this comment.
Should be int.
Sorry, something went wrong.
| if(PyErr_Occurred()) { | ||
| goto fail; | ||
| } | ||
| long open_mode = PyLong_AsLong(PySequence_GetItem(file_actions_obj, 4)); |
There was a problem hiding this comment.
Check integer overflow when cast to mode_t.
Sorry, something went wrong.
| goto fail; | ||
| } | ||
|
|
||
| long close_fd = PyLong_AsLong(PySequence_GetItem(file_actions_obj, 1)); |
There was a problem hiding this comment.
Should be int.
Sorry, something went wrong.
| goto fail; | ||
| } | ||
|
|
||
| long fd1 = PyLong_AsLong(PySequence_GetItem(file_actions_obj, 1)); |
There was a problem hiding this comment.
Should be int.
Sorry, something went wrong.
| break; | ||
|
|
||
| default: | ||
| PyErr_SetString(PyExc_TypeError,"Unknown file_actions identifier"); |
There was a problem hiding this comment.
Wouldn't ValueError more appropriate exception type?
Sorry, something went wrong.
|
|
||
|
|
||
| mode_obj = PySequence_Fast_GET_ITEM(file_actions_obj, 0); | ||
| int mode = PyLong_AsLong(mode_obj); |
There was a problem hiding this comment.
Should be checked for error.
Sorry, something went wrong.
|
Also there are trailing spaces added by this PR. |
Sorry, something went wrong.
| if (file_actions != NULL && file_actions != Py_None){ | ||
| posix_spawn_file_actions_t _file_actions; | ||
| if(posix_spawn_file_actions_init(&_file_actions) != 0){ | ||
| PyErr_SetString(PyExc_TypeError, |
There was a problem hiding this comment.
Shouldn't errno be included in the exception?
Sorry, something went wrong.
|
|
||
| pid_t pid; | ||
| posix_spawn_file_actions_t *file_actionsp = NULL; | ||
| if (file_actions != NULL && file_actions != Py_None){ |
There was a problem hiding this comment.
file_actions is never NULL.
Sorry, something went wrong.
|
@serhiy-storchaka I am trying to correct all these new issues in Corrected in #6331. Please, notice that some of them (like the result of posix_spawn not checked and the return before _Py_END_SUPPRESS_IPH) were already corrected as this is an outdated diff. Thanks for all the effort with this! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This PR exposes posix_spawn in the os module. This also adds a new class in said module to work with posix_spawn file_actions argument.
https://bugs.python.org/issue20104