示例#1
0
文件: errors.c 项目: 10sr/cpython
PyObject *
PyErr_NoMemory(void)
{
    if (Py_TYPE(PyExc_MemoryError) == NULL) {
        /* PyErr_NoMemory() has been called before PyExc_MemoryError has been
           initialized by _PyExc_Init() */
        Py_FatalError("Out of memory and PyExc_MemoryError is not "
                      "initialized yet");
    }
    PyErr_SetNone(PyExc_MemoryError);
    return NULL;
}
static PyObject *bpy_bmeditseliter_next(BPy_BMEditSelIter *self)
{
	BMEditSelection *ese = self->ese;
	if (ese == NULL) {
		PyErr_SetNone(PyExc_StopIteration);
		return NULL;
	}
	else {
		self->ese = ese->next;
		return (PyObject *)BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head);
	}
}
static PyObject *orientedViewEdgeIterator_iternext(BPy_orientedViewEdgeIterator *self)
{
	ViewVertex::directedViewEdge *dve;

	if (self->reversed) {
		if (self->ove_it->isBegin()) {
			PyErr_SetNone(PyExc_StopIteration);
			return NULL;
		}
		self->ove_it->decrement();
		dve = self->ove_it->operator->();
	}
	else {
		if (self->ove_it->isEnd()) {
			PyErr_SetNone(PyExc_StopIteration);
			return NULL;
		}
		dve = self->ove_it->operator->();
		self->ove_it->increment();
	}
	return BPy_directedViewEdge_from_directedViewEdge(*dve);
}
static PyObject *StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self)
{
	StrokeVertex *sv;

	if (self->reversed) {
		if (self->sv_it->isBegin()) {
			PyErr_SetNone(PyExc_StopIteration);
			return NULL;
		}
		self->sv_it->decrement();
		sv = self->sv_it->operator->();
	}
	else {
		if (self->sv_it->isEnd()) {
			PyErr_SetNone(PyExc_StopIteration);
			return NULL;
		}
		sv = self->sv_it->operator->();
		self->sv_it->increment();
	}
	return BPy_StrokeVertex_from_StrokeVertex(*sv);
}
static PyObject *Interface0DIterator_iternext(BPy_Interface0DIterator *self)
{
	Interface0D *if0D;

	if (self->reversed) {
		if (self->if0D_it->isBegin()) {
			PyErr_SetNone(PyExc_StopIteration);
			return NULL;
		}
		self->if0D_it->decrement();
		if0D = self->if0D_it->operator->();
	}
	else {
		if (self->if0D_it->isEnd()) {
			PyErr_SetNone(PyExc_StopIteration);
			return NULL;
		}
		if0D = self->if0D_it->operator->();
		self->if0D_it->increment();
	}
	return Any_BPy_Interface0D_from_Interface0D(*if0D);
}
static PyObject *
channel_iternext(PyChannelObject *self)
{
    STACKLESS_GETARG();

    if (self->flags.closing && self->balance <= 0) {
        /* signal the end of the iteration */
        PyErr_SetNone(PyExc_StopIteration);
        return NULL;
    }
    STACKLESS_PROMOTE_ALL();
    return impl_channel_receive(self);
}
static PyObject* pyMessageWithCallbacks_delCallback(pyMessageWithCallbacks* self, PyObject* args) {
    Py_ssize_t idx;
    if (!PyArg_ParseTuple(args, "n", &idx)) {
        PyErr_SetString(PyExc_TypeError, "delCallback expects an int");
        return NULL;
    }
    if (size_t(idx) >= self->fThis->getCallbacks().size()) {
        PyErr_SetNone(PyExc_IndexError);
        return NULL;
    }
    self->fThis->delCallback((size_t)idx);
    Py_INCREF(Py_None);
    return Py_None;
}
示例#8
0
PyObject *uwsgi_Input_next(PyObject* self) {

	PyObject *line = uwsgi_Input_getline((uwsgi_Input *)self, 0);
	if (!line) return NULL;

	if (PyString_Size(line) == 0) {
		Py_DECREF(line);
		PyErr_SetNone(PyExc_StopIteration);
		return NULL;
	}

	return line;

}
static PyObject *t_collationelementiterator_iter_next(t_collationelementiterator *self)
{
    int n;

    STATUS_CALL(n = self->object->next(status));

    if (n == CollationElementIterator::NULLORDER)
    {
        PyErr_SetNone(PyExc_StopIteration);
        return NULL;
    }

    return PyInt_FromLong(n);
}
示例#10
0
static PyObject *
IO_iternext(Iobject *self)
{
    PyObject *next;
    next = IO_readline((IOobject *)self, NULL);
    if (!next)
        return NULL;
    if (!PyString_GET_SIZE(next)) {
        Py_DECREF(next);
        PyErr_SetNone(PyExc_StopIteration);
        return NULL;
    }
    return next;
}
示例#11
0
文件: search.cpp 项目: ezmiller/pyicu
static PyObject *t_searchiterator_iter_next(t_searchiterator *self)
{
    int32_t offset;

    STATUS_CALL(offset = self->object->next(status));

    if (offset == USEARCH_DONE)
    {
        PyErr_SetNone(PyExc_StopIteration);
        return NULL;
    }

    return PyInt_FromLong(offset);
}
示例#12
0
static PyObject* pySoftVolumeComplex_delSubVolume(pySoftVolumeComplex* self, PyObject* args) {
    Py_ssize_t idx;
    if (!PyArg_ParseTuple(args, "n", &idx)) {
        PyErr_SetString(PyExc_TypeError, "delSubVolume expects an int");
        return NULL;
    }
    if (size_t(idx) >= self->fThis->getSubVolumes().size()) {
        PyErr_SetNone(PyExc_IndexError);
        return NULL;
    }
    self->fThis->delSubVolume((size_t)idx);
    Py_INCREF(Py_None);
    return Py_None;
}
示例#13
0
JSBool
branch_cb(JSContext* jscx, JSScript* script)
{
    Context* pycx = (Context*) JS_GetContextPrivate(jscx);
    time_t now = time(NULL);

    if(pycx == NULL)
    {
        JS_ReportError(jscx, "Failed to find Python context.");
        return JS_FALSE;
    }

    // Get out quick if we don't have any quotas.
    if(pycx->max_time == 0 && pycx->max_heap == 0)
    {
        return JS_TRUE;
    }

    // Only check occasionally for resource usage.
    pycx->branch_count++;
    if((pycx->branch_count > 0x3FFF) != 1)
    {
        return JS_TRUE;
    }

    pycx->branch_count = 0;

    if(pycx->max_heap > 0 && jscx->runtime->gcBytes > pycx->max_heap)
    {
        // First see if garbage collection gets under the threshold.
        JS_GC(jscx);
        if(jscx->runtime->gcBytes > pycx->max_heap)
        {
            PyErr_NoMemory();
            return JS_FALSE;
        }
    }

    if(
        pycx->max_time > 0
        && pycx->start_time > 0
        && pycx->max_time < now - pycx->start_time
    )
    {
        PyErr_SetNone(PyExc_SystemError);
        return JS_FALSE;
    }

    return JS_TRUE;
}
static PyObject *StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self)
{
	/* Because Freestyle iterators for which it.isEnd() holds true have no valid object
	 * (referencing it.object in this case leads to a crash), we must check if it.object
	 * is valid after incrementing, to prevent crashes in Python.
	 * Additionally, the at_start attribute is used to keep Freestyle iterator objects
	 * and Python for loops in sync. */

	if (self->reversed) {
		if (self->sv_it->isBegin()) {
			PyErr_SetNone(PyExc_StopIteration);
			return NULL;
		}
		self->sv_it->decrement();
	}
	else {
		if (self->sv_it->isEnd()) {
			PyErr_SetNone(PyExc_StopIteration);
			return NULL;
		}
		/* if at the start of the iterator, only return the object
		 * and don't increment, to keep for-loops in sync */
		if (self->at_start)
			self->at_start = false;
		/* after incrementing, check if the iterator is at its end
		 * exit the loop if it is. not doing so will result in a crash */
		else {
			self->sv_it->increment();
			if (self->sv_it->isEnd()) {
				PyErr_SetNone(PyExc_StopIteration);
				return NULL;
			}
		}
	}
	StrokeVertex *sv = self->sv_it->operator->();
	return BPy_StrokeVertex_from_StrokeVertex(*sv);
}
示例#15
0
/*
 * Handle errors raised by BIO functions.
 *
 * Arguments: bio - The BIO object
 *            ret - The return value of the BIO_ function.
 * Returns: None, the calling function should return NULL;
 */
static void
handle_bio_errors(BIO* bio, int ret)
{
    if (BIO_should_retry(bio)) {
        if (BIO_should_read(bio)) {
            PyErr_SetNone(ssl_WantReadError);
        } else if (BIO_should_write(bio)) {
            PyErr_SetNone(ssl_WantWriteError);
        } else if (BIO_should_io_special(bio)) {
            /*
             * It's somewhat unclear what this means.  From the OpenSSL source,
             * it seems like it should not be triggered by the memory BIO, so
             * for the time being, this case shouldn't come up.  The SSL BIO
             * (which I think should be named the socket BIO) may trigger this
             * case if its socket is not yet connected or it is busy doing
             * something related to x509.
             */
            PyErr_SetString(PyExc_ValueError, "BIO_should_io_special");
        } else {
            /*
             * I hope this is dead code.  The BIO documentation suggests that
             * one of the above three checks should always be true.
             */
            PyErr_SetString(PyExc_ValueError, "unknown bio failure");
        }
    } else {
        /*
         * If we aren't to retry, it's really an error, so fall back to the
         * normal error reporting code.  However, the BIO interface does not
         * specify a uniform error reporting mechanism.  We can only hope that
         * the code which triggered the error also kindly pushed something onto
         * the error stack.
         */
        exception_from_error_queue(ssl_Error);
    }
}
示例#16
0
PyObject* PyUNFO_ObjListIter_iternext(PyObject *self) {
    PyObject *ret;
    if (((PyUNFO_ObjListIter*)self)->it) {
        ret = pyobjlist_getitem(((PyUNFO_ObjListIter*)self)->seq,
                                 ((PyUNFO_ObjListIter*)self)->pos);
    }
    if (((PyUNFO_ObjListIter*)self)->it) {
        ((PyUNFO_ObjListIter*)self)->it = ((PyUNFO_ObjListIter*)self)->it->next;
        ((PyUNFO_ObjListIter*)self)->pos += 1;
    } else {
        PyErr_SetNone(PyExc_StopIteration);
        return NULL;
    }
    return ret;
}
示例#17
0
static PyObject* possibilities_next(_PossibilitiesObject *self)
{
    HyPossibilities iter = self->possibilities;
    if (iter->type == TYPE_NEVRA) {
	HyNevra nevra;
	if (hy_possibilities_next_nevra(iter, &nevra) == 0)
	    return nevraToPyObject(nevra);
    } else {
	HyReldep reldep;
	if (hy_possibilities_next_reldep(iter, &reldep) == 0)
	    return reldepToPyObject(reldep);
    }
    PyErr_SetNone(PyExc_StopIteration);
    return NULL;
}
示例#18
0
static PyObject* pyOneShotMsg_delCallback(pyOneShotMsg* self, PyObject* args) {
    Py_ssize_t idx;
    if (!PyArg_ParseTuple(args, "n", &idx)) {
        PyErr_SetString(PyExc_TypeError, "delCallback expects an int");
        return NULL;
    }
    plOneShotCallbacks& cbs = self->fThis->getCallbacks();
    if (size_t(idx) >= cbs.getNumCallbacks()) {
        PyErr_SetNone(PyExc_IndexError);
        return NULL;
    }
    cbs.delCallback(idx);
    Py_INCREF(Py_None);
    return Py_None;
}
示例#19
0
static PyObject *Bitmap_iternext(BitmapObject *self)
{
	if (!Bitmap_Ready(self)) return NULL;

	if (++(self->point).x < self->bitmap->width) {
		return Py_BuildValue("(kk)", self->point.x, self->point.y);
	} else if (++(self->point).y < self->bitmap->height){
		self->point.x = 0;
		return Py_BuildValue("(kk)", self->point.x, self->point.y);
	} else {
		/* Raise standard StopIteration exception with empty value. */
		PyErr_SetNone(PyExc_StopIteration);
		return NULL;
	}
}
示例#20
0
文件: locale.cpp 项目: ezmiller/pyicu
static PyObject *t_resourcebundle_next(t_resourcebundle *self)
{
    if (self->object->hasNext())
    {
        UErrorCode status = U_ZERO_ERROR;
        ResourceBundle rb = self->object->getNext(status);

        if (U_FAILURE(status))
            return ICUException(status).reportError();

        return wrap_ResourceBundle(rb);
    }

    PyErr_SetNone(PyExc_StopIteration);
    return NULL;
}
示例#21
0
static PyObject *py_tevent_context_loop_until(TeventContext_Object *self, PyObject *args)
{
	PyObject *callback;
	if (!PyArg_ParseTuple(args, "O", &callback))
		return NULL;

	if (tevent_loop_until(self->ev, py_tevent_finished, callback) != 0) {
		PyErr_SetNone(PyExc_RuntimeError);
		return NULL;
	}

	if (PyErr_Occurred())
		return NULL;

	Py_RETURN_NONE;
}
示例#22
0
 // Returns next object.
 PyObject* bond_iterator_next(BondIterator* _self)
 {
   if(_self->N != _self->parent->bonds.size())
   {
     PYLADA_PYERROR(IndexError, "Bonds changed mid-iteration.");
     return NULL;
   }
   if(_self->i_first != _self->i_end) 
   {
     if(_self->is_first) _self->is_first = false; else ++_self->i_first;
     if(_self->i_first != _self->i_end)
       return edge_to_tuple(_self->parent, *_self->i_first);
   }
   PyErr_SetNone(PyExc_StopIteration);
   return NULL;
 }
示例#23
0
文件: error.c 项目: alex179ohm/pygit2
PyObject* Error_set(int err)
{
    assert(err < 0);

    if(err != GIT_ERROR) { //expected failure
        PyErr_SetNone(Error_type(err));
    } else { //critical failure
        const git_error* error = giterr_last();
        char* message = (error == NULL) ? 
                "(No error information given)" : error->message;
        
        PyErr_SetString(Error_type(err), message);
    }

    return NULL;
}
示例#24
0
文件: module.c 项目: rlutz/geda-gaf
static PyObject *eval_string(PyObject *self, PyObject *args, PyObject *kwds)
{
	PyObject *string_arg = NULL;
	static char *kwlist[] = { "string", NULL };

	if (!PyArg_ParseTupleAndKeywords(
		    args, kwds, "O!:eval_string", kwlist,
		    &PyString_Type, &string_arg))
		return NULL;

	PyObject *result = scm_with_guile(
		(void *(*)(void *))eval_string_wrapper, string_arg);
	if (result == NULL && !PyErr_Occurred())
		PyErr_SetNone(guile_error);
	return result;
}
示例#25
0
文件: module.c 项目: rlutz/geda-gaf
static PyObject *lookup(PyObject *self, PyObject *args, PyObject *kwds)
{
	const char *name_arg = NULL;
	static char *kwlist[] = { "name", NULL };

	if (!PyArg_ParseTupleAndKeywords(
		    args, kwds, "s:lookup", kwlist, &name_arg))
		return NULL;

	PyObject *result = scm_with_guile(
		(void *(*)(void *))lookup_wrapper, (void *)name_arg);
	if (result == NULL && !PyErr_Occurred()) {
		PyErr_SetNone(guile_error);
		return NULL;
	}
	return result;
}
示例#26
0
static int kill_greenlet(PyGreenlet* self)
{
	/* Cannot raise an exception to kill the greenlet if
	   it is not running in the same thread! */
	if (self->run_info == PyThreadState_GET()->dict) {
		/* The dying greenlet cannot be a parent of ts_current
		   because the 'parent' field chain would hold a
		   reference */
		PyObject* result;
		PyGreenlet* oldparent;
		PyGreenlet* tmp;
		if (!STATE_OK) {
			return -1;
		}
		oldparent = self->parent;
		self->parent = ts_current;
		Py_INCREF(self->parent);
		/* Send the greenlet a GreenletExit exception. */
		PyErr_SetNone(PyExc_GreenletExit);
		result = g_switch(self, NULL, NULL);
		tmp = self->parent;
		self->parent = oldparent;
		Py_XDECREF(tmp);
		if (result == NULL)
			return -1;
		Py_DECREF(result);
		return 0;
	}
	else {
		/* Not the same thread! Temporarily save the greenlet
		   into its thread's ts_delkey list. */
		PyObject* lst;
		lst = PyDict_GetItem(self->run_info, ts_delkey);
		if (lst == NULL) {
			lst = PyList_New(0);
			if (lst == NULL || PyDict_SetItem(self->run_info,
							  ts_delkey, lst) < 0)
				return -1;
		}
		if (PyList_Append(lst, (PyObject*) self) < 0)
			return -1;
		if (!STATE_OK)  /* to force ts_delkey to be reconsidered */
			return -1;
		return 0;
	}
}
示例#27
0
PyObject *
Billiard_SetError(PyObject *Type, int num)
{
    switch (num) {
    case MP_SUCCESS:
        break;
#ifdef MS_WINDOWS
    case MP_STANDARD_ERROR:
        if (Type == NULL)
            Type = PyExc_WindowsError;
        PyErr_SetExcFromWindowsErr(Type, 0);
        break;
    case MP_SOCKET_ERROR:
        if (Type == NULL)
            Type = PyExc_WindowsError;
        PyErr_SetExcFromWindowsErr(Type, WSAGetLastError());
        break;
#else /* !MS_WINDOWS */
    case MP_STANDARD_ERROR:
    case MP_SOCKET_ERROR:
        if (Type == NULL)
            Type = PyExc_OSError;
        PyErr_SetFromErrno(Type);
        break;
#endif /* !MS_WINDOWS */
    case MP_MEMORY_ERROR:
        PyErr_NoMemory();
        break;
    case MP_END_OF_FILE:
        PyErr_SetNone(PyExc_EOFError);
        break;
    case MP_EARLY_END_OF_FILE:
        PyErr_SetString(PyExc_IOError,
                        "got end of file during message");
        break;
    case MP_BAD_MESSAGE_LENGTH:
        PyErr_SetString(PyExc_IOError, "bad message length");
        break;
    case MP_EXCEPTION_HAS_BEEN_SET:
        break;
    default:
        PyErr_Format(PyExc_RuntimeError,
                     "unkown error number %d", num);
    }
    return NULL;
}
示例#28
0
文件: semaphore.c 项目: 10sr/cpython
static PyObject *
semlock_getvalue(SemLockObject *self)
{
#ifdef HAVE_BROKEN_SEM_GETVALUE
    PyErr_SetNone(PyExc_NotImplementedError);
    return NULL;
#else
    int sval;
    if (SEM_GETVALUE(self->handle, &sval) < 0)
        return _PyMp_SetError(NULL, MP_STANDARD_ERROR);
    /* some posix implementations use negative numbers to indicate
       the number of waiting threads */
    if (sval < 0)
        sval = 0;
    return PyLong_FromLong((long)sval);
#endif
}
示例#29
0
文件: revision.c 项目: SayCV/geda-gaf
static PyObject *Revision_get_object_data(
	Revision *self, PyObject *args, PyObject *kwds)
{
	PyObject *ob_arg = NULL;
	static char *kwlist[] = { "ob", NULL };

	if (!PyArg_ParseTupleAndKeywords(
		    args, kwds, "O!:Revision.get_object_data", kwlist,
		    &ObjectType, &ob_arg))
		return NULL;

	xorn_object_t ob = ((Object *)ob_arg)->ob;
	xorn_obtype_t type = xorn_get_object_type(self->rev, ob);

	switch (type) {
	case xorn_obtype_none:
		PyErr_SetNone(PyExc_KeyError);
		return NULL;
	case xornsch_obtype_arc:
		return construct_arc(xornsch_get_arc_data(self->rev, ob));
	case xornsch_obtype_box:
		return construct_box(xornsch_get_box_data(self->rev, ob));
	case xornsch_obtype_circle:
		return construct_circle(
			xornsch_get_circle_data(self->rev, ob));
	case xornsch_obtype_component:
		return construct_component(
			xornsch_get_component_data(self->rev, ob));
	case xornsch_obtype_line:
		return construct_line(xornsch_get_line_data(self->rev, ob));
	case xornsch_obtype_net:
		return construct_net(xornsch_get_net_data(self->rev, ob));
	case xornsch_obtype_path:
		return construct_path(xornsch_get_path_data(self->rev, ob));
	case xornsch_obtype_picture:
		return construct_picture(
			xornsch_get_picture_data(self->rev, ob));
	case xornsch_obtype_text:
		return construct_text(xornsch_get_text_data(self->rev, ob));
	}

	char buf[BUFSIZ];
	snprintf(buf, BUFSIZ, "Object type not supported (%d)", type);
	PyErr_SetString(PyExc_ValueError, buf);
	return NULL;
}
示例#30
0
static PyObject *
pygtk_tree_model_row_iter_next(PyGtkTreeModelRowIter *self)
{
    PyObject *row;

    if (!self->has_more) {
	PyErr_SetNone(PyExc_StopIteration);
	return NULL;
    }

    row = _pygtk_tree_model_row_new(self->model, &self->iter);

    /* move to next iter */
    self->has_more = gtk_tree_model_iter_next(self->model, &self->iter);

    return row;
}