本文整理汇总了C++中PyIter_Next函数的典型用法代码示例。如果您正苦于以下问题:C++ PyIter_Next函数的具体用法?C++ PyIter_Next怎么用?C++ PyIter_Next使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyIter_Next函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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
}