| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Not in working condition, things need to be moved around to work with generation of AC code in a separate file.
This is required to be able to include the generated AC code from clinic/selectmodule.c.h, which must appear before these definitions but after all typedefs and type declarations.
The converter was copied from Modules/posixmodule.c, but changed to check whether fd == -1 rather than fd < 0 as an error condition from calling PyOjbect_AsFileDescriptor(). Note: AC output in Modules/clinic/selectmodule.c.h was manually modified in this commit to get the build working. This may be due to an AC bug.
Note: AC output in Modules/clinic/selectmodule.c.h was manually modified in this commit to get the build working. This may be due to an AC bug.
Also change the doc-string of epoll.poll: * use AC's per-argument docs to describe the arguments * revert an addition describing the return value Note: AC output in Modules/clinic/selectmodule.c.h was manually modified in this commit to get the build working. This may be due to an AC bug.
|
|
||
| fd: fildes | ||
| either an integer, or an object with a fileno() method returning an int | ||
| eventmask: object(converter="ushort_converter", type="unsigned short", c_default="POLLIN | POLLOUT | POLLPRI") = POLLIN | POLLOUT | POLLPRI |
There was a problem hiding this comment.
Good opportunity to register the ushort converter.
Sorry, something went wrong.
There was a problem hiding this comment.
Please keep flags in this order: POLLIN | POLLPRI | POLLOUT. It seems like POLLPRI is more related to POLLIN, than POLLOUT. See https://bugs.python.org/issue30844 :-)
Sorry, something went wrong.
| return NULL; | ||
| } | ||
|
|
||
| if (timeout_obj != NULL && timeout_obj != Py_None) { |
There was a problem hiding this comment.
timeout_obj can't be NULL.
Sorry, something went wrong.
| } | ||
|
|
||
| /* Check values for timeout */ | ||
| if (timeout_obj == NULL || timeout_obj == Py_None) { |
There was a problem hiding this comment.
timeout_obj can't be NULL.
Sorry, something went wrong.
| @classmethod | ||
| select.epoll.__new__ | ||
|
|
||
| sizehint: int(c_default="FD_SETSIZE - 1") = -1 |
There was a problem hiding this comment.
Negative sizehint is an error.
Sorry, something went wrong.
There was a problem hiding this comment.
Should it be an error? The tests only check that -2 should raise ValueError, not -1. The existing doc-string mentions that -1 should mean the default size, though it currently doesn't.
Perhaps we should fix the code to special-case -1? Currently the only way to get the default is to not specify sizehint, but that's one type of inconsistency AC aims to remove.
Sorry, something went wrong.
There was a problem hiding this comment.
See the check at line 1304. The current code treats -1 as invalid value. Argument Clinic conversion shouldn't change semantic (too much). If there is a bug in the current code, fix it in a separate issue, so that the fix can be backported.
Sorry, something went wrong.
There was a problem hiding this comment.
This may not actually matter much. From the docs: "sizehint and flags are deprecated and completely ignored." Looking at the code, this is true for flags, but sizehint is actually passed to epoll_create if HAVE_EPOLL_CREATE1 isn't defined.
So there are two problems right now:
Fixing the doc-string to describe the actual behavior seems like the way to go. I'm just not sure what that is regarding sizehint: is it actually ignored? I.e. are the docs wrong on this?
I'm really unsure what to do regarding the default value for sizehint shown in the doc-string.
Sorry, something went wrong.
There was a problem hiding this comment.
@serhiy-storchaka Could you help decide how to resolve this point?
Sorry, something went wrong.
There was a problem hiding this comment.
I'm summarizing in hope to move forward with this.
The default for sizehint should ideally be FD_SETSIZE - 1, but FD_SETSIZE isn't exposed at the Python level. The current behavior sets sizehint to FD_SETSIZE - 1 if not supplied, but that's a type of inconsistency that AC aims to remove.
-1 is an invalid value, therefore it should probably not be used as a default value since that would change the existing semantics too much.
The docs say that sizehint is deprecated and ignored, in which case this discussion would be moot. However in the code sizehint is still passed to epoll_create() if epoll_create1() is not available:
#ifdef HAVE_EPOLL_CREATE1
self->epfd = epoll_create1(EPOLL_CLOEXEC);
#else
self->epfd = epoll_create(sizehint);
#endif
Sorry, something went wrong.
There was a problem hiding this comment.
-1 was valid before 2fb9ae9 (but 0 was not valid). I'm not sure this change is intentional. It is better to open a separate issue for this.
Sorry, something went wrong.
There was a problem hiding this comment.
@serhiy-storchaka, I'll open a new issue. In the meantime, what do we do with the default value of sizehint in this branch?
Sorry, something went wrong.
There was a problem hiding this comment.
Depending on the results of that issue. Likely -1 will be the default value.
Sorry, something went wrong.
There was a problem hiding this comment.
Created bpo-32568.
Sorry, something went wrong.
|
|
||
| return pyepoll_internal_ctl(self->epfd, EPOLL_CTL_DEL, pfd, 0); | ||
| } | ||
| timeout as timeout_obj: object(c_default="Py_None") = -1.0 |
There was a problem hiding this comment.
Why not use None as a default?
Sorry, something went wrong.
There was a problem hiding this comment.
The doc-string mentions, regarding timeout, "-1 makes poll wait indefinitely" but doesn't mention None, though None actually does the same. Given this, I thought documenting the default as -1 was clearer.
Perhaps we should improve the doc-string, mentioning that either None or -1 mean "wait indefinitely", and then change the default to None?
Sorry, something went wrong.
There was a problem hiding this comment.
Do what looks better to you.
Sorry, something went wrong.
There was a problem hiding this comment.
I'll improve the doc-string and change the default to None.
Sorry, something went wrong.
|
|
||
| if (ch != NULL && ch != Py_None) { | ||
| seq = PySequence_Fast(ch, "changelist is not iterable"); | ||
| if (changelist != NULL && changelist != Py_None) { |
There was a problem hiding this comment.
otimeout and changelist can't be NULL.
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you for this nice PR. While I may have other comments later, and @serhiy-storchaka already added comments, I like how the new code looks like ;-)
Sorry, something went wrong.
| PyObject_Del(self); | ||
| } | ||
|
|
||
| static PyTypeObject poll_Type = { |
There was a problem hiding this comment.
Would it be possible to not move this code, to group all code related to poll at the same place, as done currently.
Sorry, something went wrong.
There was a problem hiding this comment.
Currently we must either move all method and type definitions towards the end of the file, or move all typedefs and type declarations to the beginning. This is because #include "clinic/selectmodule.c.h" must come between them.
On bpo-20180 (msg304976), regarding itertools, @serhiy-storchaka mentioned preference for moving the method and type definitions to the end rather than the alternative. Therefore I did the same here.
Sorry, something went wrong.
There was a problem hiding this comment.
This is not a preference, this is just an option. Since methods lists and type object initializers could be generated by Argument Clinic in future, I think it is easier to move them.
Sorry, something went wrong.
|
|
||
| fd: fildes | ||
| either an integer, or an object with a fileno() method returning an int | ||
| eventmask: object(converter="ushort_converter", type="unsigned short", c_default="POLLIN | POLLOUT | POLLPRI") = POLLIN | POLLOUT | POLLPRI |
There was a problem hiding this comment.
Please keep flags in this order: POLLIN | POLLPRI | POLLOUT. It seems like POLLPRI is more related to POLLIN, than POLLOUT. See https://bugs.python.org/issue30844 :-)
Sorry, something went wrong.
| int.\n\ | ||
| events -- an optional bitmask describing the type of events to check for"); | ||
| /*[clinic input] | ||
| select.poll.register |
There was a problem hiding this comment.
Please use "-> NoneType". Even if currently it seems like it has no effect, it will be used in signature once https://bugs.python.org/issue31939 will be implemented.
Sorry, something went wrong.
There was a problem hiding this comment.
That syntax is for defining AC return converters, not return type annotations, so it could have unwanted effects.
Specifically, the Argument Clinic How-To currently states:
(There’s also an experimental NoneType converter, which lets you return Py_None on success or NULL on failure, without having to increment the reference count on Py_None. I’m not sure it adds enough clarity to be worth using.)
Sorry, something went wrong.
| static PyObject* | ||
| devpoll_fileno(devpollObject *self) | ||
| /*[clinic input] | ||
| select.devpoll.fileno |
There was a problem hiding this comment.
Please try to use "-> int" return converter. Same comment for other fileno() methods.
Sorry, something went wrong.
There was a problem hiding this comment.
Regarding devpoll.fileno(), due to the use of devpoll_err_closed() internally, using -> int or -> long actually complicates the code. The same goes for epoll.fileno() and kqueue.fileno() as well.
Sorry, something went wrong.
There was a problem hiding this comment.
This will complicate the code. select_devpoll_fileno_impl would be need to convert NULL returned by devpoll_err_closed() to -1. I think it is better to keep the current code and add the converter in a separate issue if you with.
Sorry, something went wrong.
There was a problem hiding this comment.
This PR is just giant. I would suggest to split it into multiple smaller PRs. For example, why not starting by converting only select()?
Sorry, something went wrong.
| int fd; | ||
| int *pointer = (int *)p; | ||
| fd = PyObject_AsFileDescriptor(o); | ||
| if (fd == -1) |
There was a problem hiding this comment.
PEP 7: add { ... }.
Sorry, something went wrong.
| { | ||
| int fd; | ||
| int *pointer = (int *)p; | ||
| fd = PyObject_AsFileDescriptor(o); |
There was a problem hiding this comment.
nitpick: you can write "int fd = ...;" (single line)
Sorry, something went wrong.
|
|
||
| *** IMPORTANT NOTICE *** | ||
| On Windows, only sockets are supported; on Unix, all file | ||
| descriptors can be used. |
There was a problem hiding this comment.
used => supported or acceptd.
Sorry, something went wrong.
| Wait until one or more file descriptors are ready for some kind of I/O. | ||
|
|
||
| The first three arguments are sequences of file descriptors to be waited for: | ||
| rlist -- wait until ready for reading |
There was a problem hiding this comment.
I would remove "wait until" since select is non-blocking when using a timeout of 0.
Sorry, something went wrong.
| The first three arguments are sequences of file descriptors to be waited for: | ||
| rlist -- wait until ready for reading | ||
| wlist -- wait until ready for writing | ||
| xlist -- wait for an ``exceptional condition'' |
There was a problem hiding this comment.
the prevent encoding issues on legacy terminals, I suggest to use more common and ASCII quote: '...'
Sorry, something went wrong.
There was a problem hiding this comment.
See also https://bugs.python.org/issue28710 .
Sorry, something went wrong.
| xlist -- wait for an ``exceptional condition'' | ||
| If only one kind of condition is required, pass [] for the other lists. | ||
| A file descriptor is either a socket or file object, or a small integer | ||
| gotten from a fileno() method call on one of those. |
There was a problem hiding this comment.
I'm not sure if it's worth it to mention it, but on Windows, technically select() expects a list of socket handles, not file descriptors. On Windows, socket handles and file descriptors are two distinct namespaces.
Sorry, something went wrong.
| efdlist = set2list(&efdset, efd2obj); | ||
| rlist = set2list(&ifdset, rfd2obj); | ||
| wlist = set2list(&ofdset, wfd2obj); | ||
| xlist = set2list(&efdset, efd2obj); |
There was a problem hiding this comment.
I would prefer "elist" to be consisten with "efdset" and "efd2obj".
Sorry, something went wrong.
I can understand why you suggest this. I'm discouraged by the amount of work required in addition to that already invested here. I'm further discouraged since I've done exactly what you suggest for the AC conversion of itertools, beginning with converting only groupby(), but that has been completely ignored so far (PR #4170). |
Sorry, something went wrong.
I like AC and want to convert everything to AC, but I have limited bandwidth to review such AC. Please don't hesitate to ping me frequently until I reviewed all of them :-) |
Sorry, something went wrong.
|
Making all changes with a single PR LGTM. This is unavoidable when convert to AC such module. Let me to recall where we stopped last time. I guess there were just minor problems which should be resolved. |
Sorry, something went wrong.
I've got a patch ready which addresses nearly all of those issues. If you're interested I'll get it done and push it to this branch. I suggest that you wait until that's done before reviewing again. |
Sorry, something went wrong.
I greatly appreciate your bandwidth, it's obvious you spend a lot of time and effort to address so many different issues! I realize that AC is lower priority than most things and accept that. I'll work on moving my AC patches one at a time, in hopes of getting things moving in smaller steps will require less ongoing commitment from other core devs. |
Sorry, something went wrong.
|
@vstinner, AFAICT all of your comments in the last batch are regarding code and comments which I mostly moved around rather than actually wrote or edited. I'd rather make such changes after the AC conversion if you don't mind. I'd gladly collect your comments here and prepare another PR with just those improvements, after this is done with. |
Sorry, something went wrong.
# Conflicts: # Modules/selectmodule.c
|
@serhiy-storchaka, I've fixed all of the outstanding issues brought up here that it was clear should be fixed. I think this is ready for another review! I've left the epoll sizehint behavior as-is, i.e. this patch doesn't change the existing behavior, questionable though it may be. We are addressing that on the dedicated issue bpo-32568. I've also not addressed the comments from @vstinner's latest review, since they are all about things I haven't actually changed here. |
Sorry, something went wrong.
| } | ||
|
|
||
| PyDoc_STRVAR(devpoll_poll_doc, | ||
| "poll( [timeout] ) -> list of (fd, event) 2-tuples\n\n\ |
There was a problem hiding this comment.
The hint about the structure of the return value is lost. Same for epoll.poll.
Sorry, something went wrong.
There was a problem hiding this comment.
Good catch! I'd addressed this for poll.poll() but not devpoll.poll() and epoll.poll(). Fixed!
Sorry, something went wrong.
| The first three arguments are sequences of file descriptors to be waited for: | ||
| rlist -- wait until ready for reading | ||
| wlist -- wait until ready for writing | ||
| xlist -- wait for an ``exceptional condition'' |
There was a problem hiding this comment.
See also https://bugs.python.org/issue28710 .
Sorry, something went wrong.
| /*[clinic input] | ||
| select.devpoll.poll | ||
|
|
||
| timeout as timeout_obj: object = None |
There was a problem hiding this comment.
Should be positional-only.
Sorry, something went wrong.
|
@serhiy-storchaka, I think this is ready for another review! I've addressed your latest two comments and fixed a couple of bugs related to select.kqueue (now all tests are passing). |
Sorry, something went wrong.
# Conflicts: # Modules/selectmodule.c
| Back | FazBrowse Home | New Git URL |
This is a complete Argument Clinic conversion of Modules/selectmodule.c.
The initial commit on this branch is the mostly fixed application of the latest patch on bpo-20182. Later changes were each done in a separate commit to facilitate review.
Minor note: Some of the early commits on the branch don't compile successfully.
https://bugs.python.org/issue31938