• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PyObject_RichCompareBool函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PyObject_RichCompareBool函数的典型用法代码示例。如果您正苦于以下问题:C++ PyObject_RichCompareBool函数的具体用法?C++ PyObject_RichCompareBool怎么用?C++ PyObject_RichCompareBool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PyObject_RichCompareBool函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: compute_range_item

static PyObject *
compute_range_item(rangeobject *r, PyObject *arg)
{
    int cmp_result;
    PyObject *i, *result;

    /* PyLong equivalent to:
     *   if (arg < 0) {
     *     i = r->length + arg
     *   } else {
     *     i = arg
     *   }
     */
    cmp_result = PyObject_RichCompareBool(arg, _PyLong_Zero, Py_LT);
    if (cmp_result == -1) {
        return NULL;
    }
    if (cmp_result == 1) {
        i = PyNumber_Add(r->length, arg);
        if (!i) {
          return NULL;
        }
    } else {
        i = arg;
        Py_INCREF(i);
    }

    /* PyLong equivalent to:
     *   if (i < 0 || i >= r->length) {
     *     <report index out of bounds>
     *   }
     */
    cmp_result = PyObject_RichCompareBool(i, _PyLong_Zero, Py_LT);
    if (cmp_result == 0) {
        cmp_result = PyObject_RichCompareBool(i, r->length, Py_GE);
    }
    if (cmp_result == -1) {
       Py_DECREF(i);
       return NULL;
    }
    if (cmp_result == 1) {
        Py_DECREF(i);
        PyErr_SetString(PyExc_IndexError,
                        "range object index out of range");
        return NULL;
    }

    result = compute_item(r, i);
    Py_DECREF(i);
    return result;
}
开发者ID:Victor-Savu,项目名称:cpython,代码行数:51,代码来源:rangeobject.c


示例2: ct_compare

int
ct_compare(PyObject *key1, PyObject *key2)
{
	int res;

	res = PyObject_RichCompareBool(key1, key2, Py_LT);
	if (res > 0)
		return -1;
	else if (res < 0) {
		PyErr_SetString(PyExc_TypeError, "invalid type for key");
		return 0;
		}
	return PyObject_RichCompareBool(key1, key2, Py_GT);
}
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:14,代码来源:ctrees.c


示例3: _verify

/*
    def _verify(self):
        if ([r._generation for r in self._verify_ro]
            != self._verify_generations):
            self.changed(None)
*/
static int
_verify(verify *self)
{
  PyObject *changed_result;

  if (self->_verify_ro != NULL && self->_verify_generations != NULL)
    {
      PyObject *generations;
      int changed;

      generations = _generations_tuple(self->_verify_ro);
      if (generations == NULL)
        return -1;

      changed = PyObject_RichCompareBool(self->_verify_generations,
					 generations, Py_NE);
      Py_DECREF(generations);
      if (changed == -1)
        return -1;

      if (changed == 0)
        return 0;
    }

  changed_result = PyObject_CallMethodObjArgs(OBJECT(self), strchanged,
                                              Py_None, NULL);
  if (changed_result == NULL)
    return -1;

  Py_DECREF(changed_result);
  return 0;
}
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:38,代码来源:_zope_interface_coptimizations.c


示例4: instancemethod_richcompare

static PyObject *
instancemethod_richcompare(PyObject *self, PyObject *other, int op)
{
    PyInstanceMethodObject *a, *b;
    PyObject *res;
    int eq;

    if ((op != Py_EQ && op != Py_NE) ||
        !PyInstanceMethod_Check(self) ||
        !PyInstanceMethod_Check(other))
    {
        Py_RETURN_NOTIMPLEMENTED;
    }
    a = (PyInstanceMethodObject *)self;
    b = (PyInstanceMethodObject *)other;
    eq = PyObject_RichCompareBool(a->func, b->func, Py_EQ);
    if (eq < 0)
        return NULL;
    if (op == Py_EQ)
        res = eq ? Py_True : Py_False;
    else
        res = eq ? Py_False : Py_True;
    Py_INCREF(res);
    return res;
}
开发者ID:Illirgway,项目名称:cpython,代码行数:25,代码来源:classobject.c


示例5: tupleindex

static PyObject *
tupleindex(PyTupleObject *self, PyObject *args)
{
    Py_ssize_t i, start=0, stop=Py_SIZE(self);
    PyObject *v;

    if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
                                _PyEval_SliceIndex, &start,
                                _PyEval_SliceIndex, &stop))
        return NULL;
    if (start < 0) {
        start += Py_SIZE(self);
        if (start < 0)
            start = 0;
    }
    if (stop < 0) {
        stop += Py_SIZE(self);
        if (stop < 0)
            stop = 0;
    }
    for (i = start; i < stop && i < Py_SIZE(self); i++) {
        int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
        if (cmp > 0)
            return PyLong_FromSsize_t(i);
        else if (cmp < 0)
            return NULL;
    }
    PyErr_SetString(PyExc_ValueError, "tuple.index(x): x not in tuple");
    return NULL;
}
开发者ID:IgnusIndia,项目名称:pythonexperiment,代码行数:30,代码来源:tupleobject.c


示例6: atexit_unregister

    func - function to be unregistered");

static PyObject *
atexit_unregister(PyObject *self, PyObject *func)
{
    atexitmodule_state *modstate;
    atexit_callback *cb;
    int i, eq;

    modstate = GET_ATEXIT_STATE(self);

    for (i = 0; i < modstate->ncallbacks; i++)
    {
        cb = modstate->atexit_callbacks[i];
        if (cb == NULL)
            continue;

        eq = PyObject_RichCompareBool(cb->func, func, Py_EQ);
        if (eq < 0)
            return NULL;
        if (eq)
            atexit_delete_cb(modstate, i);
    }
    Py_RETURN_NONE;
}
开发者ID:1st1,项目名称:cpython,代码行数:25,代码来源:atexitmodule.c


示例7: calliter_iternext

static PyObject *
calliter_iternext(calliterobject *it)
{
    if (it->it_callable != NULL) {
        PyObject *args = PyTuple_New(0);
        PyObject *result;
        if (args == NULL)
            return NULL;
        result = PyObject_Call(it->it_callable, args, NULL);
        Py_DECREF(args);
        if (result != NULL) {
            int ok;
            ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);               
            if (ok == 0)
                return result; /* Common case, fast path */
            Py_DECREF(result);
            if (ok > 0) {
                Py_CLEAR(it->it_callable);
                Py_CLEAR(it->it_sentinel);
            }
        }
        else if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
            PyErr_Clear();
            Py_CLEAR(it->it_callable);
            Py_CLEAR(it->it_sentinel);
        }
    }
    return NULL;
}
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:29,代码来源:iterobject.c


示例8: modesreader_setmode

static int modesreader_setmode(modesreader *self, PyObject *mode, void *dummy)
{
    int i;

    if (mode == Py_None) {
        set_decoder_mode(self, DECODER_NONE);
        return 0;
    }

    for (i = 0; modetable[i].cstr != NULL; ++i) {
        int res = PyObject_RichCompareBool(modetable[i].pystr, mode, Py_EQ);
        if (res < 0)
            return -1;

        if (res == 1) {
            set_decoder_mode(self, modetable[i].mode);
            break;
        }
    }

    if (modetable[i].cstr == NULL) {
        PyErr_SetString(PyExc_ValueError, "unrecognized decoder mode");
        return -1;
    }

    return 0;
}
开发者ID:Sondermannolaf,项目名称:mlat-client,代码行数:27,代码来源:modes_reader.c


示例9: find_path_to_item

/*
 * trace a path to an item matching a given python value
 */
static int
find_path_to_item(btsort_pyobject *tree, PyObject *value, char first,
        char find, bt_path_t *path, char *found) {
    int i, index, cmp = 0;
    bt_node_t *node = (bt_node_t *)(tree->root);
    int (*bisector)(PyObject **, int, PyObject *);

    bisector = first ? bisect_left : bisect_right;
    if (find) *found = 0;
    path->tree = tree;

    for (i = 0; i <= tree->depth; ++i) {
        if (i) node = ((bt_branch_t *)node)->children[index];

        if ((index = bisector(node->values, node->filled, value)) < 0)
            return index;

        if (find && index < node->filled && (cmp = PyObject_RichCompareBool(
                node->values[index - (first ? 0 : 1)], value, Py_EQ)) < 0)
            return cmp;

        path->lineage[i] = node;
        path->indexes[i] = index;

        if (cmp) {
            *found = 1;
            break;
        }
    }

    path->depth = i;
    return 0;
}
开发者ID:donaq,项目名称:btree,代码行数:36,代码来源:sorted_btree.c


示例10: Per_set_jar

static int
Per_set_jar(cPersistentObject *self, PyObject *v)
{
    if (self->cache)
    {
        int result;

        if (v == NULL)
        {
            PyErr_SetString(PyExc_ValueError,
                            "can't delete _p_jar of cached object");
            return -1;
        }
        result = PyObject_RichCompareBool(self->jar, v, Py_NE);
        if (result < 0)
            return -1;
        if (result)
        {
            PyErr_SetString(PyExc_ValueError,
                            "can not change _p_jar of cached object");
            return -1;
        }
    }
    Py_XDECREF(self->jar);
    Py_XINCREF(v);
    self->jar = v;
    return 0;
}
开发者ID:zopefoundation,项目名称:persistent,代码行数:28,代码来源:cPersistence.c


示例11: longrangeiter_next

static PyObject *
longrangeiter_next(longrangeiterobject *r)
{
    PyObject *one, *product, *new_index, *result;
    if (PyObject_RichCompareBool(r->index, r->len, Py_LT) != 1)
        return NULL;

    one = PyLong_FromLong(1);
    if (!one)
        return NULL;

    new_index = PyNumber_Add(r->index, one);
    Py_DECREF(one);
    if (!new_index)
        return NULL;

    product = PyNumber_Multiply(r->index, r->step);
    if (!product) {
        Py_DECREF(new_index);
        return NULL;
    }

    result = PyNumber_Add(r->start, product);
    Py_DECREF(product);
    if (result) {
        Py_XSETREF(r->index, new_index);
    }
    else {
        Py_DECREF(new_index);
    }

    return result;
}
开发者ID:PiJoules,项目名称:cpython-modified,代码行数:33,代码来源:rangeobject.c


示例12: internal_bisect_right

static Py_ssize_t
internal_bisect_right(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t hi)
{
    PyObject *litem;
    Py_ssize_t mid, res;

    if (lo < 0) {
        PyErr_SetString(PyExc_ValueError, "lo must be non-negative");
        return -1;
    }
    if (hi == -1) {
        hi = PySequence_Size(list);
        if (hi < 0)
            return -1;
    }
    while (lo < hi) {
        /* The (size_t)cast ensures that the addition and subsequent division
           are performed as unsigned operations, avoiding difficulties from
           signed overflow.  (See issue 13496.) */
        mid = ((size_t)lo + hi) / 2;
        litem = PySequence_GetItem(list, mid);
        if (litem == NULL)
            return -1;
        res = PyObject_RichCompareBool(item, litem, Py_LT);
        Py_DECREF(litem);
        if (res < 0)
            return -1;
        if (res)
            hi = mid;
        else
            lo = mid + 1;
    }
    return lo;
}
开发者ID:524777134,项目名称:cpython,代码行数:34,代码来源:_bisectmodule.c


示例13: calliter_iternext

static PyObject *
calliter_iternext(calliterobject *it)
{
    PyObject *result;

    if (it->it_callable == NULL) {
        return NULL;
    }

    result = _PyObject_CallNoArg(it->it_callable);
    if (result != NULL) {
        int ok;

        ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);
        if (ok == 0) {
            return result; /* Common case, fast path */
        }

        Py_DECREF(result);
        if (ok > 0) {
            Py_CLEAR(it->it_callable);
            Py_CLEAR(it->it_sentinel);
        }
    }
    else if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
        PyErr_Clear();
        Py_CLEAR(it->it_callable);
        Py_CLEAR(it->it_sentinel);
    }
    return NULL;
}
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:31,代码来源:iterobject.c


示例14: internal_bisect_right

static Py_ssize_t
internal_bisect_right(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t hi)
{
    PyObject *litem;
    Py_ssize_t mid, res;

    if (lo < 0) {
        PyErr_SetString(PyExc_ValueError, "lo must be non-negative");
        return -1;
    }
    if (hi == -1) {
        hi = PySequence_Size(list);
        if (hi < 0)
            return -1;
    }
    while (lo < hi) {
        mid = (lo + hi) / 2;
        litem = PySequence_GetItem(list, mid);
        if (litem == NULL)
            return -1;
        res = PyObject_RichCompareBool(item, litem, Py_LT);
        Py_DECREF(litem);
        if (res < 0)
            return -1;
        if (res)
            hi = mid;
        else
            lo = mid + 1;
    }
    return lo;
}
开发者ID:AbnerChang,项目名称:edk2-staging,代码行数:31,代码来源:_bisectmodule.c


示例15: Compare

    int Compare(const leveldb::Slice& a, const leveldb::Slice& b) const
    {
        int ret;
        PyObject* bytes_a;
        PyObject* bytes_b;
        PyObject* compare_result;
        PyGILState_STATE gstate;

        gstate = PyGILState_Ensure();

        /* Create two Python byte strings */
        bytes_a = PyBytes_FromStringAndSize(a.data(), a.size());
        bytes_b = PyBytes_FromStringAndSize(b.data(), b.size());

        if ((bytes_a == NULL) || (bytes_b == NULL)) {
            this->bailout("Plyvel comparator could not allocate byte strings");
        }

        /* Invoke comparator callable */
        compare_result = PyObject_CallFunctionObjArgs(comparator, bytes_a, bytes_b, 0);

        if (compare_result == NULL) {
            this->bailout("Exception raised from custom Plyvel comparator");
        }

        /* The comparator callable can return any Python object. Compare it
         * to our "0" value to get a -1, 0, or 1 for LevelDB. */
        if (PyObject_RichCompareBool(compare_result, zero, Py_GT) == 1) {
            ret = 1;
        } else if (PyObject_RichCompareBool(compare_result, zero, Py_LT) == 1) {
            ret = -1;
        } else {
            ret = 0;
        }

        if (PyErr_Occurred()) {
            this->bailout("Exception raised while comparing custom Plyvel comparator result with 0");
        }

        Py_DECREF(compare_result);
        Py_DECREF(bytes_a);
        Py_DECREF(bytes_b);

        PyGILState_Release(gstate);

        return ret;
    }
开发者ID:EderSantana,项目名称:plyvel,代码行数:47,代码来源:comparator.cpp


示例16: code_richcompare

static PyObject *
code_richcompare(PyObject *self, PyObject *other, int op)
{
    PyCodeObject *co, *cp;
    int eq;
    PyObject *res;

    if ((op != Py_EQ && op != Py_NE) ||
        !PyCode_Check(self) ||
        !PyCode_Check(other)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    co = (PyCodeObject *)self;
    cp = (PyCodeObject *)other;

    eq = PyObject_RichCompareBool(co->co_name, cp->co_name, Py_EQ);
    if (eq <= 0) goto unequal;
    eq = co->co_argcount == cp->co_argcount;
    if (!eq) goto unequal;
    eq = co->co_kwonlyargcount == cp->co_kwonlyargcount;
    if (!eq) goto unequal;
    eq = co->co_nlocals == cp->co_nlocals;
    if (!eq) goto unequal;
    eq = co->co_flags == cp->co_flags;
    if (!eq) goto unequal;
    eq = co->co_firstlineno == cp->co_firstlineno;
    if (!eq) goto unequal;
    eq = PyObject_RichCompareBool(co->co_code, cp->co_code, Py_EQ);
    if (eq <= 0) goto unequal;
    eq = PyObject_RichCompareBool(co->co_consts, cp->co_consts, Py_EQ);
    if (eq <= 0) goto unequal;
    eq = PyObject_RichCompareBool(co->co_names, cp->co_names, Py_EQ);
    if (eq <= 0) goto unequal;
    eq = PyObject_RichCompareBool(co->co_varnames, cp->co_varnames, Py_EQ);
    if (eq <= 0) goto unequal;
    eq = PyObject_RichCompareBool(co->co_freevars, cp->co_freevars, Py_EQ);
    if (eq <= 0) goto unequal;
    eq = PyObject_RichCompareBool(co->co_cellvars, cp->co_cellvars, Py_EQ);
    if (eq <= 0) goto unequal;

    if (op == Py_EQ)
        res = Py_True;
    else
        res = Py_False;
    goto done;

  unequal:
    if (eq < 0)
        return NULL;
    if (op == Py_NE)
        res = Py_True;
    else
        res = Py_False;

  done:
    Py_INCREF(res);
    return res;
}
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:60,代码来源:codeobject.c


示例17: min

/* Older implementations of heapq used Py_LE for comparisons.  Now, it uses
   Py_LT so it will match min(), sorted(), and bisect().  Unfortunately, some
   client code (Twisted for example) relied on Py_LE, so this little function
   restores compatability by trying both.
*/
static int
cmp_lt(PyObject *x, PyObject *y)
{
    int cmp;
    static PyObject *lt = NULL;

    if (lt == NULL) {
        lt = PyString_FromString("__lt__");
        if (lt == NULL)
            return -1;
    }
    if (PyObject_HasAttr(x, lt))
        return PyObject_RichCompareBool(x, y, Py_LT);
    cmp = PyObject_RichCompareBool(y, x, Py_LE);
    if (cmp != -1)
        cmp = 1 - cmp;
    return cmp;
}
开发者ID:CSC-IT-Center-for-Science,项目名称:scalable-python,代码行数:23,代码来源:_heapqmodule.c


示例18: checkTypeIsExit

static inline bool checkTypeIsExit (PyObject *etype)
{
  PyObject *exceptions_module = PyImport_ImportModule("exceptions");
  PyObject *exceptions_module_dict = PyModule_GetDict (exceptions_module);
  PyObject *system_exit = PyDict_GetItemString (exceptions_module_dict,
						"SystemExit");
  bool result = (PyObject_RichCompareBool (system_exit, etype, Py_EQ) == 1);
  
  Py_XDECREF (exceptions_module);
  return result;
}
开发者ID:RealworldSystems,项目名称:rfgis,代码行数:11,代码来源:RFGisMain.cpp


示例19: tuplecontains

static int
tuplecontains(PyTupleObject *a, PyObject *el)
{
    Py_ssize_t i;
    int cmp;

    for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i)
        cmp = PyObject_RichCompareBool(el, PyTuple_GET_ITEM(a, i),
                                           Py_EQ);
    return cmp;
}
开发者ID:IgnusIndia,项目名称:pythonexperiment,代码行数:11,代码来源:tupleobject.c


示例20: tupleContains

Box* tupleContains(BoxedTuple* self, Box* elt) {
    int size = self->size();
    for (Box* e : *self) {
        int r = PyObject_RichCompareBool(elt, e, Py_EQ);
        if (r == -1)
            throwCAPIException();

        if (r)
            return True;
    }
    return False;
}
开发者ID:jmgc,项目名称:pyston,代码行数:12,代码来源:tuple.cpp



注:本文中的PyObject_RichCompareBool函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PyObject_SetAttr函数代码示例发布时间:2022-05-30
下一篇:
C++ PyObject_RichCompare函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap