Example #1
0
static PyObject *t_set_discard(t_set *self, PyObject *args)
{
    PyObject *value;
    int setDirty = 1, result;

    if (!PyArg_ParseTuple(args, "O|i", &value, &setDirty))
        return NULL;

    if (self->itemvalue.flags & V_PURE)
        result = PySet_Discard(self->set, value);
    else
    {
        value = _useValue(self, value);
        if (!value)
            return NULL;
        result = PySet_Discard(self->set, value);
        Py_DECREF(value);
    }

    if (result < 0)
        return NULL;

    if (setDirty && _t_itemvalue__setDirty((t_itemvalue *) self, 0) < 0)
        return NULL;

    Py_RETURN_NONE;
}
Example #2
0
 /** remove an element if present
  * @throw index_err if not present
  * @throw err
  */
 void remove(const obj& o)
 {
     int r = PySet_Discard(_p, o.p());
     if(r == -1)
         throw err("set remove failed");
     else if(r == 0)
         throw index_err("set remove failed");
 }
Example #3
0
PyObject *WeakSet_remover(void *closure,PyObject *args,PyObject *kwargs){
    remover_closure *self = (remover_closure *)closure;
    PyObject *key = NULL;

    // The set we were created to update may not exist anymore.
    PyObject *set = PyWeakref_GET_OBJECT(self->setref);
    if (set == Py_None) Py_RETURN_NONE;
    
    if (!PyArg_ParseTuple(args, "O",&key)) return NULL;

    // Remove ourselves from the set
    int r = PySet_Discard(set,key);
    if (r == -1) return NULL; // Propegate errors from PySet_Discard
    if (r == 0){
        PyErr_Format(PyExc_RuntimeError,
                     "WeakSet_remover: PySet_Discard didn't find key in set");
        return NULL;
    }

    Py_RETURN_NONE;
}
Example #4
0
int
Context_rem_object(Context* cx, PyObject* val)
{
    return PySet_Discard((PyObject*) cx->objects, val);
}
Example #5
0
PyObject*
semaphore_acquire(SemaphoreObject *self, PyObject *blocking, long timeout)
{
    PyObject *res = NULL;
    PyObject *current = NULL;
    PyObject *timer = NULL;
    LoopObject *loop = NULL;

    DEBUG("self:%p timeout:%ld counter:%d", self, timeout, self->counter);

    if (self->counter > 0) {
        self->counter--;
        DEBUG("counter decr self:%p", self);
        Py_RETURN_TRUE;

    } else if(PyObject_Not(blocking)) {
        Py_RETURN_FALSE;
    }

    loop = get_event_loop();
    if (loop == NULL) {
        return NULL;
    }

    current = greenlet_getcurrent();
    Py_XDECREF(current);
    if (current == NULL) {
        return NULL;
    }

    timer = loop_set_timeout(loop, timeout, NULL);
    if (timer == NULL) {
        return NULL;
    }

    if (PySet_Add(self->waiters, current) == -1) {
        ((TimerObject*)timer)->cancelled = 1; 
        return NULL;
    }

    while (self->counter <= 0) {
        res = loop_switch(loop);
        Py_XDECREF(res);
        if (res == NULL) {
            if (PyErr_ExceptionMatches(TimeoutException)) {
                RDEBUG("catch TimeoutException self:%p", self);
                if (fetch_timer() == timer) {
                    PyErr_Clear();
                    res = Py_False;
                    goto fin;
                }
            }
            goto fin;
        }
    }

    self->counter--;
    res = Py_True;

fin:
    ((TimerObject*)timer)->cancelled = 1; 
    if (PySet_Discard(self->waiters, current) == -1) {
        res = NULL;
    }
    Py_DECREF(timer);
    Py_XINCREF(res);
    return res;
}
Example #6
0
 /** discard an element if present
  * @throw err
  */
 void discard(const obj& o)
 {
     int r = PySet_Discard(_p, o.p());
     if(r == -1)
         throw err("set discard failed");
 }