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

C++ PyLong_AsSsize_t函数代码示例

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

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



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

示例1: PySlice_GetIndices

int
PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
                   Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)
{
	/* XXX support long ints */
	if (r->step == Py_None) {
		*step = 1;
	} else {
		if (!PyLong_Check(r->step)) return -1;
		*step = PyLong_AsSsize_t(r->step);
	}
	if (r->start == Py_None) {
		*start = *step < 0 ? length-1 : 0;
	} else {
		if (!PyLong_Check(r->start)) return -1;
		*start = PyLong_AsSsize_t(r->start);
		if (*start < 0) *start += length;
	}
	if (r->stop == Py_None) {
		*stop = *step < 0 ? -1 : length;
	} else {
		if (!PyLong_Check(r->stop)) return -1;
		*stop = PyLong_AsSsize_t(r->stop);
		if (*stop < 0) *stop += length;
	}
	if (*stop > length) return -1;
	if (*start >= length) return -1;
	if (*step == 0) return -1;
	return 0;
}
开发者ID:cocoatomo,项目名称:CTPython,代码行数:30,代码来源:sliceobject.c


示例2: SinglyLinkedList2_get

/* SinglyLinkedList2.get(index) */
static PyObject *
SinglyLinkedList2_get(SinglyLinkedList2 *self, PyObject *indexobj)
{
  SinglyLinkedListNode *n;
  PyObject *item;
  Py_ssize_t index = -1;
  int i;

  if (indexobj != NULL && indexobj != Py_None) {
  index = PyLong_AsSsize_t(indexobj);
  if (index == -1 && PyErr_Occurred())
    return NULL;
  }
  if (index < 0 || index > self->size - 1) {
  PyErr_SetString(PyExc_IndexError, "LinkedList index out of range");
  return NULL;
  }

  n = self->head;
  for (i = 0; i < index; ++i)
  n = n->next;
  item = n->data;
  Py_INCREF(item);
  return item;
}
开发者ID:nkraft,项目名称:educollections,代码行数:26,代码来源:_educollectionslists.c


示例3: em_list_setitem

/* Insert item in external memory list.
 *
 * XXX: Support slice objects and negative indices?
 */
static int em_list_setitem(em_list_t *self, PyObject *key, PyObject *value)
{
    Py_ssize_t index;

    int ret = -1;

    /* Python 3 supports only long integers. */
#if PY_MAJOR_VERSION < 3
    if(PyInt_CheckExact(key))
    {
        index = PyInt_AsSsize_t(key);
        ret = em_list_setitem_safe(self, index, value);
    }
    else if(PyLong_CheckExact(key))
#else
    if(PyLong_CheckExact(key))
#endif
    {
        index = PyLong_AsSsize_t(key);
        ret = em_list_setitem_safe(self, index, value);
    }
    else
        PyErr_SetString(PyExc_TypeError, "Invalid index type");

    return ret;
}
开发者ID:huku-,项目名称:pyrsistence,代码行数:30,代码来源:em_list.c


示例4: ArrayList_remove

/* ArrayList.remove(index) */
static PyObject *
ArrayList_remove(ArrayList *self, PyObject *indexobj)
{
  PyObject *old_item;
  Py_ssize_t index = -1;
  int j;

  if (indexobj != NULL && indexobj != Py_None) {
    index = PyLong_AsSsize_t(indexobj);
    if (index == -1 && PyErr_Occurred()) {
      PyErr_SetString(PyExc_RuntimeError, "WTF");
      return NULL;
    }
  }
  if (index < 0 || index >= self->capacity || index > self->size - 1) {
    PyErr_SetString(PyExc_IndexError, "ArrayList index out of range");
    return NULL;
  }

  old_item = self->data[index];
  for (j = index; j < self->size - 1; ++j) {
  self->data[j] = self->data[j+1];
  }
  Py_INCREF(Py_None);
  self->data[self->size-1] = Py_None;
  self->size -= 1;

  return old_item;
}
开发者ID:nkraft,项目名称:educollections,代码行数:30,代码来源:_educollectionslists.c


示例5: SinglyLinkedList2_set

/* SinglyLinkedList2.set(index, item) */
static PyObject *
SinglyLinkedList2_set(SinglyLinkedList2 *self, PyObject *args)
{
  SinglyLinkedListNode *n;
  PyObject *indexobj = NULL, *itemobj = NULL, *old_item = NULL;
  Py_ssize_t index = -1;
  int i;

  if (!PyArg_ParseTuple(args, "OO", &indexobj, &itemobj)) {
  return NULL;
  }
  if (indexobj != NULL && indexobj != Py_None) {
  index = PyLong_AsSsize_t(indexobj);
  if (index == -1 && PyErr_Occurred())
    return NULL;
  }
  if (index < 0 || index > self->size - 1) {
  PyErr_SetString(PyExc_IndexError, "SinglyLinkedList2 index out of range");
  return NULL;
  }
  if (itemobj == NULL) {
  PyErr_SetString(PyExc_ValueError, "item == NULL");
  return NULL;
  }

  n = self->head;
  for (i = 0; i < index; ++i)
  n = n->next;
  ++self->state;
  old_item = n->data;
  Py_XDECREF(old_item);
  Py_INCREF(itemobj);
  n->data = itemobj;
  Py_RETURN_NONE;
}
开发者ID:nkraft,项目名称:educollections,代码行数:36,代码来源:_educollectionslists.c


示例6: PyInt_AsSsize_t

/* Retrieve item from external memory list.
 *
 * XXX: Support slice objects and negative indices?
 */
static PyObject *em_list_getitem(em_list_t *self, PyObject *key)
{
    Py_ssize_t index;

    PyObject *r = NULL;

    /* Python 3 supports only long integers. */
#if PY_MAJOR_VERSION < 3
    if(PyInt_CheckExact(key))
    {
        index = PyInt_AsSsize_t(key);
        r = em_list_getitem_internal(self, index);
    }
    else if(PyLong_CheckExact(key))
#else
    if(PyLong_CheckExact(key))
#endif
    {
        index = PyLong_AsSsize_t(key);
        r = em_list_getitem_internal(self, index);
    }
    else
        PyErr_SetString(PyExc_TypeError, "Invalid key object type");

    return r;
}
开发者ID:huku-,项目名称:pyrsistence,代码行数:30,代码来源:em_list.c


示例7: PyErr_Format

static PyObject *SEQUENCE_REPEAT( ssizeargfunc repeatfunc, PyObject *seq, PyObject *n )
{
    if (unlikely( !PyIndex_Check( n ) ))
    {
        PyErr_Format(
            PyExc_TypeError,
            "can't multiply sequence by non-int of type '%s'",
            Py_TYPE( n )->tp_name
        );

        return NULL;
    }

    PyObject *index_value = PyNumber_Index( n );

    if (unlikely( index_value == NULL ))
    {
        return NULL;
    }

    /* We're done if PyInt_AsSsize_t() returns without error. */
#if PYTHON_VERSION < 300
    Py_ssize_t count = PyInt_AsSsize_t( index_value );
#else
    Py_ssize_t count = PyLong_AsSsize_t( index_value );
#endif

    Py_DECREF( index_value );

    if (unlikely( count == -1 )) // Note: -1 is an unlikely repetition count
    {
        PyObject *exception = GET_ERROR_OCCURRED();

        if (unlikely(  exception ))
        {
            if ( !EXCEPTION_MATCH_BOOL_SINGLE( exception, PyExc_OverflowError ) )
            {
                return NULL;
            }

            PyErr_Format(
                PyExc_OverflowError,
                "cannot fit '%s' into an index-sized integer",
                Py_TYPE( n )->tp_name
            );

            return NULL;
        }
    }

    PyObject *result = (*repeatfunc)( seq, count );

    if (unlikely( result == NULL ))
    {
        return NULL;
    }

    return result;
}
开发者ID:gitter-badger,项目名称:Nuitka,代码行数:59,代码来源:operations.hpp


示例8: ImageViewport_setCaptureSize

// set capture size
int ImageViewport_setCaptureSize (PyImage * self, PyObject * value, void * closure)
{
	// check validity of parameter
	if (value == NULL || !PySequence_Check(value) || PySequence_Length(value) != 2
		|| !PyLong_Check(PySequence_Fast_GET_ITEM(value, 0))
		|| !PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)))
	{
		PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 2 ints");
		return -1;
	}
	// set capture size
	short size [] = {
		short(PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, 0))),
			short(PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, 1)))
	};
	getImageViewport(self)->setCaptureSize(size);
	// success
	return 0;
}
开发者ID:jinjoh,项目名称:NOOR,代码行数:20,代码来源:ImageViewport.cpp


示例9: PyLong_AsSsize_t

void list_base::insert(object const& index, object_cref x)
{
#if PY_VERSION_HEX >= 0x03000000
    ssize_t index_ = PyLong_AsSsize_t(index.ptr());
#else
    long index_ = PyInt_AsLong(index.ptr());
#endif
    if (index_ == -1 && PyErr_Occurred())
        throw_error_already_set();
    this->insert(index_, x);
}
开发者ID:Faham,项目名称:bric-n-brac,代码行数:11,代码来源:list.cpp


示例10: bpy_bmdeformvert_contains

static int bpy_bmdeformvert_contains(BPy_BMDeformVert *self, PyObject *value)
{
	const int key = PyLong_AsSsize_t(value);

	if (key == -1 && PyErr_Occurred()) {
		PyErr_SetString(PyExc_TypeError,
		                "BMDeformVert.__contains__: expected an int");
		return -1;
	}

	return (defvert_find_index(self->data, key) != NULL) ? 1 : 0;
}
开发者ID:wchargin,项目名称:blender,代码行数:12,代码来源:bmesh_py_types_meshdata.c


示例11: result_obj

long list_base::index(object_cref value) const
{
    object result_obj(this->attr("index")(value));
#if PY_VERSION_HEX >= 0x03000000
    ssize_t result = PyLong_AsSsize_t(result_obj.ptr());
#else
    long result = PyInt_AsLong(result_obj.ptr());
#endif
    if (result == -1)
        throw_error_already_set();
    return result;
}
开发者ID:Faham,项目名称:bric-n-brac,代码行数:12,代码来源:list.cpp


示例12: iter_setstate

static PyObject *
iter_setstate(seqiterobject *it, PyObject *state)
{
    Py_ssize_t index = PyLong_AsSsize_t(state);
    if (index == -1 && PyErr_Occurred())
        return NULL;
    if (it->it_seq != NULL) {
        if (index < 0)
            index = 0;
        it->it_index = index;
    }
    Py_RETURN_NONE;
}
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:13,代码来源:iterobject.c


示例13: tupleiter_setstate

static PyObject *
tupleiter_setstate(tupleiterobject *it, PyObject *state)
{
    Py_ssize_t index = PyLong_AsSsize_t(state);
    if (index == -1 && PyErr_Occurred())
        return NULL;
    if (it->it_seq != NULL) {
        if (index < 0)
            index = 0;
        else if (it->it_seq != NULL && index > PyTuple_GET_SIZE(it->it_seq))
            index = PyTuple_GET_SIZE(it->it_seq);
        it->it_index = index;
    }
    Py_RETURN_NONE;
}
开发者ID:GuardianRG,项目名称:static-python,代码行数:15,代码来源:tupleobject.c


示例14: PyErr_SetString

static PyObject *listvalue_mapping_subscript(PyObject *self, PyObject *key)
{
	CListValue *list= static_cast<CListValue *>(BGE_PROXY_REF(self));
	if (list==NULL) {
		PyErr_SetString(PyExc_SystemError, "value = CList[i], "BGE_PROXY_ERROR_MSG);
		return NULL;
	}
	
	if (PyUnicode_Check(key)) {
		CValue *item = ((CListValue*) list)->FindValue(_PyUnicode_AsString(key));
		if (item) {
			PyObject *pyobj = item->ConvertValueToPython();
			if (pyobj)
				return pyobj;
			else
				return item->GetProxy();
		}
	}
	else if (PyIndex_Check(key)) {
		Py_ssize_t index = PyLong_AsSsize_t(key);
		return listvalue_buffer_item(self, index); /* wont add a ref */
	}
	else if (PySlice_Check(key)) {
		Py_ssize_t start, stop, step, slicelength;

		if (PySlice_GetIndicesEx(key, list->GetCount(), &start, &stop, &step, &slicelength) < 0)
			return NULL;

		if (slicelength <= 0) {
			return PyList_New(0);
		}
		else if (step == 1) {
			return listvalue_buffer_slice(list, start, stop);
		}
		else {
			PyErr_SetString(PyExc_TypeError, "CList[slice]: slice steps not supported");
			return NULL;
		}
	}

	PyErr_Format(PyExc_KeyError,
	             "CList[key]: '%R' key not in list", key);
	return NULL;
}
开发者ID:danielmarg,项目名称:blender-main,代码行数:44,代码来源:ListValue.cpp


示例15: skull_module_unpack

ssize_t skull_module_unpack (void* md, skull_txn_t* txn,
                         const void* data, size_t data_len)
{
    PyGILState_STATE state = PyGILState_Ensure();
    module_data_t* mdata = (module_data_t*)md;

    // Prepare args
    PyObject* pyArgs = PyTuple_New(4);
    PyObject* pyModuleName = PyString_FromString(mdata->name);
    PyObject* pyEntryName  = PyString_FromString(MODULE_UNPACK_FUNCNAME);
    PyObject* pyTxn        = PyCapsule_New(txn, "skull_txn", NULL);
    PyObject* pyData       = PyString_FromStringAndSize((const char*)data,
                                                        (Py_ssize_t)data_len);

    PyTuple_SetItem(pyArgs, 0, pyModuleName);
    PyTuple_SetItem(pyArgs, 1, pyEntryName);
    PyTuple_SetItem(pyArgs, 2, pyTxn);
    PyTuple_SetItem(pyArgs, 3, pyData);

    // Call user module_unpack
    PyObject* pyConsumed = PyObject_CallObject(mdata->pyExecutorFunc, pyArgs);

    // Set to -1 by default, so if error occurred, like un-handled excpetions,
    //  then the entity will be destroyed soon
    ssize_t consumed = -1;

    if (!pyConsumed) {
        if (PyErr_Occurred()) PyErr_Print();
    } else {
        if (PyInt_Check(pyConsumed)) {
            consumed = PyInt_AsSsize_t(pyConsumed);
        } else if (PyLong_Check(pyConsumed)) {
            consumed = PyLong_AsSsize_t(pyConsumed);
        } else {
            fprintf(stderr, "Error: Cannot parse the pyConsumed object");
            _PyObject_Dump(pyConsumed);
        }
    }

    Py_XDECREF(pyConsumed);
    Py_DECREF(pyArgs);
    PyGILState_Release(state);
    return consumed;
}
开发者ID:finaldie,项目名称:skull,代码行数:44,代码来源:module_executor.cpp


示例16: SinglyLinkedList1_insert

/* SinglyLinkedList1.insert(index, item) */
static PyObject *
SinglyLinkedList1_insert(SinglyLinkedList1 *self, PyObject *args)
{
  SinglyLinkedListNode *n, *tmp;
  PyObject *indexobj = NULL, *itemobj = NULL;
  Py_ssize_t index = -1;
  int i;

  if (!PyArg_ParseTuple(args, "OO", &indexobj, &itemobj)) {
  return NULL;
  }
  if (indexobj != NULL && indexobj != Py_None) {
  index = PyLong_AsSsize_t(indexobj);
  if (index == -1 && PyErr_Occurred())
    return NULL;
  }
  if (index < 0 || index > self->size - 1) {
  PyErr_SetString(PyExc_IndexError, "SinglyLinkedList1 index out of range");
  return NULL;
  }
  if (itemobj == NULL) {
  PyErr_SetString(PyExc_ValueError, "item == NULL");
  return NULL;
  }

  if (index == 0)
  return SinglyLinkedList1_prepend(self, itemobj);
  n = self->head;
  for (i = 0; i < index - 1; ++i)
  n = n->next;
  tmp = PyMem_Malloc(sizeof(SinglyLinkedListNode));
  if (tmp == NULL) {
    PyErr_NoMemory();
    return NULL;
  }
  ++self->state;
  ++self->size;
  Py_INCREF(itemobj);
  tmp->data = itemobj;
  tmp->next = n->next;
  n->next = tmp;
  Py_RETURN_NONE;
}
开发者ID:nkraft,项目名称:educollections,代码行数:44,代码来源:_educollectionslists.c


示例17: PyLong_AsSsize_t

/*
 * Implement setsize() for the type.
 */
static PyObject *sipVoidPtr_setsize(sipVoidPtrObject *v, PyObject *arg)
{
    SIP_SSIZE_T size;

#if PY_MAJOR_VERSION >= 3
    size = PyLong_AsSsize_t(arg);
#elif PY_VERSION_HEX >= 0x02050000
    size = PyInt_AsSsize_t(arg);
#else
    size = (int)PyInt_AsLong(arg);
#endif

    if (PyErr_Occurred())
        return NULL;

    v->size = size;

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:Werkov,项目名称:SIP,代码行数:23,代码来源:voidptr.c


示例18: get_ssize_t

static int
get_ssize_t(PyObject *v, Py_ssize_t *p)
{
    Py_ssize_t x;

    v = get_pylong(v);
    if (v == NULL)
        return -1;
    assert(PyLong_Check(v));
    x = PyLong_AsSsize_t(v);
    Py_DECREF(v);
    if (x == (Py_ssize_t)-1 && PyErr_Occurred()) {
        if (PyErr_ExceptionMatches(PyExc_OverflowError))
            PyErr_SetString(StructError,
                            "argument out of range");
        return -1;
    }
    *p = x;
    return 0;
}
开发者ID:sys-git,项目名称:pyopencl,代码行数:20,代码来源:_pvt_struct_v3.cpp


示例19: _long_shared

static int
_long_shared(PyObject *obj, _PyCrossInterpreterData *data)
{
    /* Note that this means the size of shareable ints is bounded by
     * sys.maxsize.  Hence on 32-bit architectures that is half the
     * size of maximum shareable ints on 64-bit.
     */
    Py_ssize_t value = PyLong_AsSsize_t(obj);
    if (value == -1 && PyErr_Occurred()) {
        if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
            PyErr_SetString(PyExc_OverflowError, "try sending as bytes");
        }
        return -1;
    }
    data->data = (void *)value;
    data->obj = NULL;
    data->new_object = _new_long_object;
    data->free = NULL;
    return 0;
}
开发者ID:tiran,项目名称:cpython,代码行数:20,代码来源:pystate.c


示例20: PyCapsule_New

bool KX_PolygonMaterial::Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const 
{
	bool dopass = false;

#ifdef WITH_PYTHON
	if (m_pymaterial)
	{
		PyObject *pyRasty = PyCapsule_New((void*)rasty, KX_POLYGONMATERIAL_CAPSULE_ID, NULL);	/* new reference */
		PyObject *pyCachingInfo = PyCapsule_New((void*) &cachingInfo, KX_POLYGONMATERIAL_CAPSULE_ID, NULL); /* new reference */
		PyObject *ret = PyObject_CallMethod(m_pymaterial, (char *)"activate", (char *)"(NNO)", pyRasty, pyCachingInfo, (PyObject*) this->m_proxy);
		if (ret)
		{
			bool value = PyLong_AsSsize_t(ret);
			Py_DECREF(ret);
			dopass = value;
		}
		else
		{
			PyErr_Print();
			PyErr_Clear();
			PySys_SetObject( (char *)"last_traceback", NULL);
		}
	}
	else
#endif // WITH_PYTHON
	{
		switch (m_pass++)
		{
			case 0:
				DefaultActivate(rasty, cachingInfo);
				dopass = true;
				break;
			default:
				m_pass = 0;
				dopass = false;
				break;
		}
	}
	
	return dopass;
}
开发者ID:BHCLL,项目名称:blendocv,代码行数:41,代码来源:KX_PolygonMaterial.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ PyLong_AsUnsignedLong函数代码示例发布时间:2022-05-30
下一篇:
C++ PyLong_AsLongLong函数代码示例发布时间: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