本文整理汇总了C++中PyIter_Next函数的典型用法代码示例。如果您正苦于以下问题:C++ PyIter_Next函数的具体用法?C++ PyIter_Next怎么用?C++ PyIter_Next使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyIter_Next函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: python_sorted_btree_bulkload
/*
* python bulkload class method
*/
static PyObject *
python_sorted_btree_bulkload(PyObject *klass, PyObject *args) {
int i, result;
PyObject *item_list, *order, *iter, *item, *prev = NULL;
if (!PyArg_ParseTuple(args, "OO!", &item_list, &PyInt_Type, &order))
return NULL;
if ((iter = PyObject_GetIter(item_list)) == NULL)
return NULL;
for (i = 0, item = PyIter_Next(iter); item;
++i, item = PyIter_Next(iter)) {
if (i) {
result = PyObject_RichCompareBool(prev, item, Py_LT);
if (result <= 0) {
if (!result)
PyErr_SetString(PyExc_ValueError,
"the bulkloaded list must already be sorted");
Py_DECREF(prev);
Py_DECREF(item);
Py_DECREF(iter);
return NULL;
}
Py_DECREF(prev);
}
prev = item;
}
if (prev) Py_DECREF(prev);
Py_DECREF(iter);
if ((iter = PyObject_GetIter(item_list)) == NULL)
return NULL;
btsort_pyobject *tree = PyObject_GC_New(
btsort_pyobject, &btsort_pytypeobj);
if (bulkload(tree, iter, (int)PyInt_AsLong(order)))
return NULL;
return (PyObject *)tree;
}
开发者ID:donaq,项目名称:btree,代码行数:44,代码来源:sorted_btree.c
示例2: PyObject_GetIter
types::set<T> from_python<types::set<T>>::convert(PyObject *obj)
{
types::set<T> v = types::empty_set();
// may be useful to reserve more space ?
PyObject *iterator = PyObject_GetIter(obj);
while (PyObject *item = PyIter_Next(iterator)) {
v.add(::from_python<T>(item));
Py_DECREF(item);
}
Py_DECREF(iterator);
return v;
}
开发者ID:hainm,项目名称:pythran,代码行数:12,代码来源:set.hpp
示例3: udn_resolve_from_search_list
static PyObject *
udn_resolve_from_search_list(PyObject *self, PyObject *args, PyObject *keywds)
{
PyObject *name_space = NULL;
PyObject *return_value = NULL;
PyObject *iterator = NULL;
PyObject *search_list = NULL;
PyObject *name;
PyObject *default_value = NULL;
static char *kwlist[] = {"search_list", "name", "default", NULL};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "OO|O", kwlist,
&search_list, &name, &default_value)) {
return NULL;
}
if (!(PyUnicode_Check(name) || PyString_Check(name))) {
PyErr_SetString(PyExc_ValueError, "name must be string");
return NULL;
}
iterator = PyObject_GetIter(search_list);
if (iterator == NULL) {
return_value = NULL;
/* PyErr_SetString(PyExc_TypeError, "search_list is not iterable"); */
goto done;
}
while ((name_space = PyIter_Next(iterator))) {
return_value = _resolve_udn(name_space, name);
Py_DECREF(name_space);
if (return_value != NULL) {
goto done;
}
}
done:
if (return_value == NULL) {
if (default_value != NULL) {
return_value = default_value;
Py_INCREF(return_value);
} else {
return_value = UnresolvedPlaceholder;
Py_INCREF(return_value);
}
}
Py_XDECREF(iterator);
/* change the return value to be a bit more compatible with the way things
work in the python code.
*/
return return_value;
}
开发者ID:abraxasllc,项目名称:spitfire,代码行数:53,代码来源:_udn.c
示例4: __Pyx_EndUnpack
static int __Pyx_EndUnpack(PyObject *iter) {
PyObject *item;
if ((item = PyIter_Next(iter))) {
Py_DECREF(item);
__Pyx_UnpackError();
return -1;
}
else if (!PyErr_Occurred())
return 0;
else
return -1;
}
开发者ID:jwilk,项目名称:Pyrex,代码行数:12,代码来源:watts1.c
示例5: iobase_readlines
static PyObject *
iobase_readlines(PyObject *self, PyObject *args)
{
Py_ssize_t hint = -1, length = 0;
PyObject *result;
if (!PyArg_ParseTuple(args, "|O&:readlines", &_PyIO_ConvertSsize_t, &hint)) {
return NULL;
}
result = PyList_New(0);
if (result == NULL)
return NULL;
if (hint <= 0) {
/* XXX special-casing this made sense in the Python version in order
to remove the bytecode interpretation overhead, but it could
probably be removed here. */
_Py_IDENTIFIER(extend);
PyObject *ret = _PyObject_CallMethodId(result, &PyId_extend, "O", self);
if (ret == NULL) {
Py_DECREF(result);
return NULL;
}
Py_DECREF(ret);
return result;
}
while (1) {
PyObject *line = PyIter_Next(self);
if (line == NULL) {
if (PyErr_Occurred()) {
Py_DECREF(result);
return NULL;
}
else
break; /* StopIteration raised */
}
if (PyList_Append(result, line) < 0) {
Py_DECREF(line);
Py_DECREF(result);
return NULL;
}
length += PyObject_Size(line);
Py_DECREF(line);
if (length > hint)
break;
}
return result;
}
开发者ID:524777134,项目名称:cpython,代码行数:53,代码来源:iobase.c
示例6: PyErr_SetString
static PyObject *IOManager_submit(IOManager *self, PyObject *args) {
PyObject *req_s, *iter;
IORequest *item;
Py_ssize_t l;
int rc;
struct iocb **cb, **cb_l;
if (!PyArg_ParseTuple(args, "O", &req_s)) return NULL;
if ((l = PySequence_Size(req_s)) < 0) return NULL;
if (l > (self->nr_events - self->pending_events)) {
PyErr_SetString(PyExc_ValueError, "Queue length exceeded.");
return NULL;
}
cb = self->cbs;
cb_l = cb + (self->nr_events - self->pending_events);
if (!(iter = PyObject_GetIter(req_s))) return NULL;
for (; (item = (IORequest*) PyIter_Next(iter)); cb++) {
if (!PyObject_IsInstance((PyObject*) item, (PyObject*) &IORequestType)) {
Py_DECREF(item);
PyErr_SetString(PyExc_TypeError, "Elements of argument 0 must be of type IORequest.");
return IOM_iocb_cleanup(self, cb+1);
}
if (cb == cb_l) {
Py_DECREF(item);
PyErr_SetString(PyExc_ValueError, "Queue length exceeded (secondary check)");
return IOM_iocb_cleanup(self, cb+1);
}
if (item->submitted) {
Py_DECREF(item);
PyErr_SetString(PyExc_ValueError, "Element of argument 0 had already been submitted earlier.");
return IOM_iocb_cleanup(self, cb+1);
}
item->submitted = 1;
item->iocb.u.c.resfd = self->fd;
*cb = &item->iocb;
}
if (PyErr_Occurred()) return IOM_iocb_cleanup(self, cb);
l = cb - self->cbs;
rc = io_submit(self->ctx, l, self->cbs);
if (rc < 0) {
errno = -rc;
PyErr_SetFromErrno(PyExc_OSError);
return IOM_iocb_cleanup(self, cb);
}
/* Keep one reference to each element read from the iterable, to make sure
they aren't deallocated while we wait for their IO requests to complete
*/
self->pending_events += l;
Py_RETURN_NONE;
}
开发者ID:sh01,项目名称:gonium,代码行数:53,代码来源:_iomodule.c
示例7: cstuff_DirectionMap_set_walls
static PyObject* cstuff_DirectionMap_set_walls(cstuff_DirectionMap* self, PyObject *args) {
PyObject *list1, *list2, *iterator1, *iterator2, *value;
int whichwall;
int row, col, stride;
if (!PyArg_ParseTuple(args, "Oi", &list1, &whichwall)) {
return NULL;
}
row = 0;
if (!(iterator1 = PyObject_GetIter(list1))) {
return NULL;
}
while ((list2 = PyIter_Next(iterator1)) && row < g_rows) {
stride = row * g_cols;
if (!(iterator2 = PyObject_GetIter(list2))) {
Py_DECREF(list2);
break;
}
col = 0;
while ((value = PyIter_Next(iterator2)) && col < g_cols) {
if (PyLong_CheckExact(value) && PyLong_AsLong(value) == whichwall) {
self->walls->values[stride+col] = 1;
}
Py_DECREF(value);
col += 1;
}
Py_DECREF(iterator2);
Py_DECREF(list2);
row += 1;
}
Py_DECREF(iterator1);
if (PyErr_Occurred()) {
return NULL;
}
Py_RETURN_NONE;
}
开发者ID:fluxid,项目名称:flantob,代码行数:40,代码来源:cstuff.c
示例8: begin
DyND_PyWrapperIter<T> begin(PyObject *obj)
{
PyObject *iter = PyObject_GetIter(obj);
if (iter == NULL) {
std::cout << "not an iterator" << std::endl;
}
DyND_PyWrapperIter<T> it;
it.iter = iter;
it.item = PyIter_Next(it.iter);
return it;
}
开发者ID:mdboom,项目名称:dynd-python,代码行数:13,代码来源:wrapper.hpp
示例9: consume_iterator
/* Run an iterator to exhaustion. Shortcut for
the extend/extendleft methods when maxlen == 0. */
static PyObject*
consume_iterator(PyObject *it)
{
PyObject *item;
while ((item = PyIter_Next(it)) != NULL) {
Py_DECREF(item);
}
Py_DECREF(it);
if (PyErr_Occurred())
return NULL;
Py_RETURN_NONE;
}
开发者ID:pogigroo,项目名称:py3k-__format__,代码行数:15,代码来源:_collectionsmodule.c
示例10: _py_itermapping_cb
int _py_itermapping_cb(pgctx_t *ctx, int i, dbtype_t *key, dbtype_t *value, void *user)
{
PyObject *iter = (PyObject*)user;
PyObject *item = PyIter_Next(iter);
PyObject *k = PySequence_GetItem(item, 0);
PyObject *v = PySequence_GetItem(item, 1);
*key = from_python(ctx, k);
*value = from_python(ctx, v);
Py_DECREF(k); Py_DECREF(v);
Py_DECREF(item);
if (PyErr_Occurred()) return -1;
return 0;
}
开发者ID:cfrantz,项目名称:pongo,代码行数:13,代码来源:pongo.c
示例11: LDAPEntry_delete
static PyObject *
LDAPEntry_delete(LDAPEntry *self, PyObject *args, PyObject *kwds) {
char *dnstr;
PyObject *keys = PyMapping_Keys((PyObject *)self);
PyObject *iter, *key;
PyObject *tmp;
LDAPValueList *value;
/* Client must be set. */
if (self->client == NULL) {
PyErr_SetString(PyExc_AttributeError, "LDAPClient is not set.");
return NULL;
}
/* Get DN string. */
tmp = PyObject_Str(self->dn);
dnstr = PyObject2char(tmp);
Py_DECREF(tmp);
if (dnstr == NULL) return NULL;
if (LDAPClient_DelEntryStringDN(self->client, dnstr) != 0) return NULL;
if (keys == NULL) return NULL;
iter = PyObject_GetIter(keys);
Py_DECREF(keys);
if (iter == NULL) return NULL;
for (key = PyIter_Next(iter); key != NULL; key = PyIter_Next(iter)) {
/* Return value: New reference. */
value = (LDAPValueList *)LDAPEntry_GetItem(self, key);
if (value == NULL) {
Py_DECREF(iter);
Py_DECREF(key);
return NULL;
}
value->status = 2;
}
return Py_None;
}
开发者ID:KarapulYa,项目名称:pyLDAP,代码行数:39,代码来源:ldapentry.c
示例12: Dict_iterNext
static int Dict_iterNext(JSOBJ obj, JSONTypeContext *tc)
{
#if PY_MAJOR_VERSION >= 3
PyObject* itemNameTmp;
#endif
if (GET_TC(tc)->itemName)
{
Py_DECREF(GET_TC(tc)->itemName);
GET_TC(tc)->itemName = NULL;
}
if (!(GET_TC(tc)->itemName = PyIter_Next(GET_TC(tc)->iterator)))
{
PRINTMARK();
return 0;
}
if (!(GET_TC(tc)->itemValue = PyObject_GetItem(GET_TC(tc)->dictObj, GET_TC(tc)->itemName)))
{
PRINTMARK();
return 0;
}
if (PyUnicode_Check(GET_TC(tc)->itemName))
{
GET_TC(tc)->itemName = PyUnicode_AsUTF8String (GET_TC(tc)->itemName);
}
else
if (!PyString_Check(GET_TC(tc)->itemName))
{
if (UNLIKELY(GET_TC(tc)->itemName == Py_None))
{
GET_TC(tc)->itemName = PyString_FromString("null");
return 1;
}
GET_TC(tc)->itemName = PyObject_Str(GET_TC(tc)->itemName);
#if PY_MAJOR_VERSION >= 3
itemNameTmp = GET_TC(tc)->itemName;
GET_TC(tc)->itemName = PyUnicode_AsUTF8String (GET_TC(tc)->itemName);
Py_DECREF(itemNameTmp);
#endif
}
else
{
Py_INCREF(GET_TC(tc)->itemName);
}
PRINTMARK();
return 1;
}
开发者ID:esnme,项目名称:ultrajson,代码行数:51,代码来源:objToJSON.c
示例13: _io__IOBase_readlines_impl
static PyObject *
_io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
/*[clinic end generated code: output=2f50421677fa3dea input=9400c786ea9dc416]*/
{
Py_ssize_t length = 0;
PyObject *result;
result = PyList_New(0);
if (result == NULL)
return NULL;
if (hint <= 0) {
/* XXX special-casing this made sense in the Python version in order
to remove the bytecode interpretation overhead, but it could
probably be removed here. */
_Py_IDENTIFIER(extend);
PyObject *ret = _PyObject_CallMethodIdObjArgs(result, &PyId_extend,
self, NULL);
if (ret == NULL) {
Py_DECREF(result);
return NULL;
}
Py_DECREF(ret);
return result;
}
while (1) {
PyObject *line = PyIter_Next(self);
if (line == NULL) {
if (PyErr_Occurred()) {
Py_DECREF(result);
return NULL;
}
else
break; /* StopIteration raised */
}
if (PyList_Append(result, line) < 0) {
Py_DECREF(line);
Py_DECREF(result);
return NULL;
}
length += PyObject_Size(line);
Py_DECREF(line);
if (length > hint)
break;
}
return result;
}
开发者ID:Daetalus,项目名称:cpython,代码行数:51,代码来源:iobase.c
示例14: Reader_iternext
static PyObject *
Reader_iternext(ReaderObj *self)
{
PyObject *lineobj;
PyObject *fields = NULL;
char *line, c;
int linelen;
if (parse_reset(self) < 0)
return NULL;
do {
lineobj = PyIter_Next(self->input_iter);
if (lineobj == NULL) {
/* End of input OR exception */
if (!PyErr_Occurred() && self->field_len != 0)
PyErr_Format(error_obj,
"newline inside string");
return NULL;
}
++self->line_num;
line = PyString_AsString(lineobj);
linelen = PyString_Size(lineobj);
if (line == NULL || linelen < 0) {
Py_DECREF(lineobj);
return NULL;
}
while (linelen--) {
c = *line++;
if (c == '\0') {
Py_DECREF(lineobj);
PyErr_Format(error_obj,
"line contains NULL byte");
goto err;
}
if (parse_process_char(self, c) < 0) {
Py_DECREF(lineobj);
goto err;
}
}
Py_DECREF(lineobj);
if (parse_process_char(self, 0) < 0)
goto err;
} while (self->state != START_RECORD);
fields = self->fields;
self->fields = NULL;
err:
return fields;
}
开发者ID:Charlian,项目名称:python-cobra,代码行数:51,代码来源:_csv.c
示例15: pyAppendToRecord
static PyObject * pyAppendToRecord(PyObject *self, PyObject *args) {
PyObject* py_dict;
PyObject* py_iter;
PyObject* py_key;
PyObject* py_val;
int recid, rc;
char *allData;
unsigned size;
// retrieve record id and dictionary object
if (!PyArg_ParseTuple(args, "iO!", &recid, &PyDict_Type, &py_dict)) {
return Py_BuildValue("i", 1); // ERROR - PyArg_ParseTuple
}
// abort if record id does not exist
rc = MEgetAllFieldsById(dbhandle, recid, &allData, &size);
if (size == 0) {
return Py_BuildValue("i", 2); // ERROR - record ID not found
}
// retrieve iterator
py_iter = PyObject_GetIter(py_dict);
if (!py_iter) {
return Py_BuildValue("i", 3); // ERROR - Not an iterator
}
// loop through key-value pairs and append to record
int kvcount = 0;
while (py_key = PyIter_Next(py_iter)) {
py_val = PyDict_GetItem(py_dict, py_key);
char * key = PyString_AsString(py_key);
char * val = PyString_AsString(py_val);
if (debugMode) {
printf("pyAppendToRecord: %s - %s\n", key, val);
}
// add kv pair into meta engine
kvcount++;
MEaddKeyValue(dbhandle, recid, key, val);
Py_DECREF(py_key);
}
Py_DECREF(py_iter);
if (debugMode) {
printf("pyAppendToRecord: total kv count: %i\n", kvcount);
}
return Py_BuildValue("i", 0); // SUCCESS
}
开发者ID:cliffsze,项目名称:mda_ibm_metaengine,代码行数:51,代码来源:meta_api.c
示例16: iterwrapperHasnextUnboxed
llvm_compat_bool iterwrapperHasnextUnboxed(Box* s) {
RELEASE_ASSERT(s->cls == iterwrapper_cls, "");
BoxedIterWrapper* self = static_cast<BoxedIterWrapper*>(s);
Box* next = PyIter_Next(self->iter);
RELEASE_ASSERT(!self->next, "");
self->next = next;
if (!next) {
if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_StopIteration))
throwCAPIException();
PyErr_Clear();
}
return next != NULL;
}
开发者ID:ChinaQuants,项目名称:pyston,代码行数:14,代码来源:iterobject.cpp
示例17: statement_load_chunks
static PyObj
statement_load_chunks(PyObj self, PyObj args, PyObj kw)
{
char *words[] = {"chunks_iter", NULL};
PyObj chunk_iter, ob;
uint32 total = 0;
if (PyPgStatement_GetParameters(self) != Py_None)
{
PyErr_SetString(PyExc_TypeError,
"cannot use load_rows with constant parameters");
return(NULL);
}
if (!PyArg_ParseTupleAndKeywords(args, kw, "O:load_chunks", words, &chunk_iter))
return(NULL);
if (DB_IS_NOT_READY())
return(NULL);
chunk_iter = PyObject_GetIter(chunk_iter);
if (chunk_iter == NULL)
return(NULL);
while ((ob = PyIter_Next(chunk_iter)))
{
PyObj row_iter;
int r;
row_iter = PyObject_GetIter(ob);
Py_DECREF(ob);
if (row_iter == NULL)
{
Py_DECREF(chunk_iter);
return(NULL);
}
r = load_rows(self, row_iter, &total);
Py_DECREF(row_iter);
if (r)
{
Py_DECREF(chunk_iter);
return(NULL);
}
}
Py_DECREF(chunk_iter);
return(PyLong_FromUnsignedLong(total));
}
开发者ID:python-postgres,项目名称:be,代码行数:50,代码来源:statement.c
示例18: attr_dir_merge
static PyObject *
attr_dir_merge(PyObject *_self, PyObject *map)
{
PyObject *keys, *iter;
PyObject *key, *value;
int status;
keys = PyMapping_Keys(map);
if (!keys)
return NULL;
iter = PyObject_GetIter(keys);
Py_DECREF(keys);
if (!iter)
return NULL;
for (key = PyIter_Next(iter); key; key = PyIter_Next(iter)) {
value = PyObject_GetItem(map, key);
if (!value)
goto err;
status = attr_dir_ass_subscript(_self, key, value);
Py_DECREF(value);
if (status < 0)
goto err;
Py_DECREF(key);
}
Py_DECREF(iter);
if (PyErr_Occurred())
return NULL;
return Py_None;
err:
Py_DECREF(iter);
Py_DECREF(key);
return NULL;
}
开发者ID:jeffmahoney,项目名称:libkdumpfile,代码行数:37,代码来源:kdumpfile.c
示例19: PyImport_ImportModule
char *uwsgi_python_get_thread_name(PyObject *thread_id) {
PyObject *threading_module = PyImport_ImportModule("threading");
if (!threading_module) return NULL;
PyObject *threading_dict = PyModule_GetDict(threading_module);
if (!threading_dict) return NULL;
PyObject *threading_enumerate = PyDict_GetItemString(threading_dict, "enumerate");
if (!threading_enumerate) return NULL;
PyObject *threads_list = PyEval_CallObject(threading_enumerate, (PyObject *)NULL);
if (!threads_list) return NULL;
PyObject *threads_list_iter = PyObject_GetIter(threads_list);
if (!threads_list_iter) goto clear;
PyObject *threads_list_next = PyIter_Next(threads_list_iter);
while(threads_list_next) {
PyObject *thread_ident = PyObject_GetAttrString(threads_list_next, "ident");
if (!thread_ident) goto clear2;
if (PyInt_AsLong(thread_ident) == PyInt_AsLong(thread_id)) {
PyObject *thread_name = PyObject_GetAttrString(threads_list_next, "name");
if (!thread_name) goto clear2;
char *name = PyString_AsString(thread_name);
Py_DECREF(threads_list_iter);
Py_DECREF(threads_list);
return name;
}
threads_list_next = PyIter_Next(threads_list_iter);
}
clear2:
Py_DECREF(threads_list_iter);
clear:
Py_DECREF(threads_list);
return NULL;
}
开发者ID:20tab,项目名称:uwsgi,代码行数:37,代码来源:tracebacker.c
示例20: DiscoDBIter_format
static PyObject *
DiscoDBIter_format(DiscoDBIter *self, PyObject *format, int N)
{
PyObject
*iterator = PyObject_GetIter((PyObject *)self),
*string = PyString_FromString(""),
*item = NULL;
int i;
if (iterator == NULL)
goto Done;
if (string == NULL)
goto Done;
for (i = 0; i < N + 1; i++) {
item = PyIter_Next(iterator);
if (item == NULL) {
if (PyErr_Occurred())
goto Done;
else
break;
}
if (i > 0)
PyString_ConcatAndDel(&string, PyString_FromString(", "));
if (i < N)
PyString_ConcatAndDel(&string, PyString_Format(format, item));
else
PyString_ConcatAndDel(&string, PyString_FromString("..."));
if (string == NULL)
goto Done;
Py_CLEAR(item);
}
Done:
Py_CLEAR(iterator);
Py_CLEAR(item);
if (PyErr_Occurred()) {
Py_CLEAR(string);
return NULL;
}
return string;
}
开发者ID:christofd,项目名称:disco,代码行数:49,代码来源:discodbmodule.c
注:本文中的PyIter_Next函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论