Ticket #31: cygwin-poll.diff

File cygwin-poll.diff, 1.0 KB (added by warner, at 2007-07-25T01:16:38Z)

patch for python-2.5.1's Modules/selectmodule.c to work around cygwin bug

  • Modules/selectmodule.c

    old new  
    452452poll_poll(pollObject *self, PyObject *args)
    453453{
    454454        PyObject *result_list = NULL, *tout = NULL;
    455         int timeout = 0, poll_result, i, j;
     455        int timeout = 0, poll_result, i, j, num_descriptors;
    456456        PyObject *value = NULL, *num = NULL;
    457457
    458458        if (!PyArg_UnpackTuple(args, "poll", 0, 1, &tout)) {
     
    491491                PyErr_SetFromErrno(SelectError);
    492492                return NULL;
    493493        }
    494        
     494
     495        /* count the number of fired descriptors */
     496        num_descriptors = 0;
     497        for (i = 0; i < self->ufd_len; i++) {
     498                if (self->ufds[i].revents)
     499                        num_descriptors++;
     500        }
     501
    495502        /* build the result list */
    496503 
    497         result_list = PyList_New(poll_result);
     504        result_list = PyList_New(num_descriptors);
    498505        if (!result_list)
    499506                return NULL;
    500507        else {
    501                 for (i = 0, j = 0; j < poll_result; j++) {
     508                for (i = 0, j = 0; j < num_descriptors; j++) {
    502509                        /* skip to the next fired descriptor */
    503510                        while (!self->ufds[i].revents) {
    504511                                i++;