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

C++ PyNumber_AsSsize_t函数代码示例

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

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



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

示例1: memoryview_get_extents_info

static PyObject*
memoryview_get_extents_info(PyObject *self, PyObject *args)
{
    int i;
    Py_ssize_t *shape_ary = NULL;
    Py_ssize_t *strides_ary = NULL;
    PyObject *shape_tuple = NULL;
    PyObject *strides_tuple = NULL;
    PyObject *shape = NULL, *strides = NULL;
    Py_ssize_t itemsize = 0;
    int ndim = 0;
    PyObject* res = NULL;

    if (!PyArg_ParseTuple(args, "OOin", &shape, &strides, &ndim, &itemsize))
        goto cleanup;

    if (ndim < 0) {
        PyErr_SetString(PyExc_ValueError, "ndim is negative");
        goto cleanup;
    }

    if (itemsize <= 0) {
        PyErr_SetString(PyExc_ValueError, "ndim <= 0");
        goto cleanup;
    }

    shape_ary = malloc(sizeof(Py_ssize_t) * ndim + 1);
    strides_ary = malloc(sizeof(Py_ssize_t) * ndim + 1);

    shape_tuple = PySequence_Fast(shape, "shape is not a sequence");
    if (!shape_tuple) goto cleanup;

    for (i = 0; i < ndim; ++i) {
        shape_ary[i] = PyNumber_AsSsize_t(
                           PySequence_Fast_GET_ITEM(shape_tuple, i),
                           PyExc_OverflowError);
    }

    strides_tuple = PySequence_Fast(strides, "strides is not a sequence");
    if (!strides_tuple) goto cleanup;

    for (i = 0; i < ndim; ++i) {
        strides_ary[i] = PyNumber_AsSsize_t(
                           PySequence_Fast_GET_ITEM(strides_tuple, i),
                           PyExc_OverflowError);
    }

    res = get_extents(shape_ary, strides_ary, ndim, itemsize, 0);
cleanup:
    free(shape_ary);
    free(strides_ary);
    Py_XDECREF(shape_tuple);
    Py_XDECREF(strides_tuple);
    return res;
}
开发者ID:Alexhuszagh,项目名称:numba,代码行数:55,代码来源:mviewbuf.c


示例2: select_overload

PyObject*
select_overload(PyObject* self, PyObject* args)
{
    PyObject *tmcap, *sigtup, *ovsigstup;
    int allow_unsafe;

    if (!PyArg_ParseTuple(args, "OOOi", &tmcap, &sigtup, &ovsigstup,
                          &allow_unsafe)) {
        return NULL;
    }

    TypeManager *tm = unwrap_TypeManager(tmcap);
    if (!tm) {
        BAD_TM_ARGUMENT;
    }

    Py_ssize_t sigsz = PySequence_Size(sigtup);
    Py_ssize_t ovsz = PySequence_Size(ovsigstup);

    Type *sig = new Type[sigsz];
    Type *ovsigs = new Type[ovsz * sigsz];

    for (int i = 0; i < sigsz; ++i) {
        sig[i] = Type(PyNumber_AsSsize_t(PySequence_Fast_GET_ITEM(sigtup,
                                                                  i), NULL));
    }

    for (int i = 0; i < ovsz; ++i) {
        PyObject *cursig = PySequence_Fast_GET_ITEM(ovsigstup, i);
        for (int j = 0; j < sigsz; ++j) {
            long tid = PyNumber_AsSsize_t(PySequence_Fast_GET_ITEM(cursig,
                                                                   j), NULL);
            ovsigs[i * sigsz + j] = Type(tid);
        }
    }

    int selected = -42;
    int matches = tm->selectOverload(sig, ovsigs, selected, sigsz, ovsz,
                                     (bool) allow_unsafe);

    delete [] sig;
    delete [] ovsigs;

    if (matches > 1) {
        PyErr_SetString(PyExc_TypeError, "Ambigous overloading");
        return NULL;
    } else if (matches == 0) {
        PyErr_SetString(PyExc_TypeError, "No compatible overload");
        return NULL;
    }

    return PyLong_FromLong(selected);
}
开发者ID:Alexhuszagh,项目名称:numba,代码行数:53,代码来源:_typeconv.cpp


示例3: PYTHON_INIT_DEFINITION

PYTHON_INIT_DEFINITION(ptPlayer, args, keywords)
{
    // we have two sets of arguments we can use, hence the generic PyObject* pointers
    // argument set 1: pyKey, string, uint32_t, float
    // argument set 2: string, uint32_t
    PyObject* firstObj = NULL; // can be a pyKey or a string
    PyObject* secondObj = NULL; // can be a string or a uint32_t
    PyObject* thirdObj = NULL; // uint32_t
    PyObject* fourthObj = NULL; // float
    if (!PyArg_ParseTuple(args, "OO|OO", &firstObj, &secondObj, &thirdObj, &fourthObj))
    {
        PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
        PYTHON_RETURN_INIT_ERROR;
    }

    plKey key;
    plString name;
    uint32_t pid = -1;
    float distSeq = -1;

    if (pyKey::Check(firstObj))
    {
        if (!(PyString_CheckEx(secondObj) && PyNumber_Check(thirdObj) && PyFloat_Check(fourthObj)))
        {
            PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
            PYTHON_RETURN_INIT_ERROR;
        }

        key = pyKey::ConvertFrom(firstObj)->getKey();
        name = PyString_AsStringEx(secondObj);
        pid = PyNumber_AsSsize_t(thirdObj, NULL);
        distSeq = (float)PyFloat_AsDouble(fourthObj);
    } else if (PyString_CheckEx(firstObj)) {
        name = PyString_AsStringEx(firstObj);
        if (!PyNumber_Check(secondObj) || thirdObj  || fourthObj)
        {
            PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
            PYTHON_RETURN_INIT_ERROR;
        }

        pid = PyNumber_AsSsize_t(secondObj, NULL);
    } else {
        PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
        PYTHON_RETURN_INIT_ERROR;
    }

    self->fThis->Init(key, name.c_str(), pid, distSeq);
    PYTHON_RETURN_INIT_OK;
}
开发者ID:Michellacoste,项目名称:Plasma,代码行数:49,代码来源:pyPlayerGlue.cpp


示例4: CONVERT_TO_INDEX

NUITKA_MAY_BE_UNUSED static Py_ssize_t CONVERT_TO_INDEX( PyObject *value )
{
    assertObject( value );

#if PYTHON_VERSION < 300
    if ( PyInt_Check( value ) )
    {
        return PyInt_AS_LONG( value );
    }
    else
#endif
    if ( PyIndex_Check( value ) )
    {
        Py_ssize_t result = PyNumber_AsSsize_t( value, NULL );

        if (unlikely( result == -1 ))
        {
            THROW_IF_ERROR_OCCURED();
        }

        return result;
    }
    else
    {
        PyErr_Format( PyExc_TypeError, "slice indices must be integers or None or have an __index__ method" );
        throw PythonException();
    }
}
开发者ID:ballacky13,项目名称:Nuitka,代码行数:28,代码来源:indexes.hpp


示例5: assess_integer_base_input

/* Function to handle the conversion of base to integers.
 * 0 is success, 1 is failure.
 */
int
assess_integer_base_input(PyObject *pybase, int *base)
{
    Py_ssize_t longbase = 0;

    /* Default to INT_MIN.
     */
    if (pybase == NULL) {
        *base = INT_MIN;
        return 0;
    }

    /* Convert to int and check for overflow.
     */
    longbase = PyNumber_AsSsize_t(pybase, NULL);
    if (longbase == -1 && PyErr_Occurred()) {
        return 1;
    }

    /* Ensure valid integer in valid range.
     */
    if ((longbase != 0 && longbase < 2) || longbase > 36) {
        PyErr_SetString(PyExc_ValueError,
                        "int() base must be >= 2 and <= 36");
        return 1;
    }
    *base = (int) longbase;
    return 0;
}
开发者ID:SethMMorton,项目名称:fastnumbers,代码行数:32,代码来源:fastnumbers.c


示例6: _io__RawIOBase_read_impl

static PyObject *
_io__RawIOBase_read_impl(PyObject *self, Py_ssize_t n)
/*[clinic end generated code: output=6cdeb731e3c9f13c input=b6d0dcf6417d1374]*/
{
    PyObject *b, *res;

    if (n < 0) {
        _Py_IDENTIFIER(readall);

        return _PyObject_CallMethodId(self, &PyId_readall, NULL);
    }

    /* TODO: allocate a bytes object directly instead and manually construct
       a writable memoryview pointing to it. */
    b = PyByteArray_FromStringAndSize(NULL, n);
    if (b == NULL)
        return NULL;

    res = PyObject_CallMethodObjArgs(self, _PyIO_str_readinto, b, NULL);
    if (res == NULL || res == Py_None) {
        Py_DECREF(b);
        return res;
    }

    n = PyNumber_AsSsize_t(res, PyExc_ValueError);
    Py_DECREF(res);
    if (n == -1 && PyErr_Occurred()) {
        Py_DECREF(b);
        return NULL;
    }

    res = PyBytes_FromStringAndSize(PyByteArray_AsString(b), n);
    Py_DECREF(b);
    return res;
}
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:35,代码来源:iobase.c


示例7: tupleMul

Box* tupleMul(BoxedTuple* self, Box* rhs) {
    Py_ssize_t n;
    if (PyIndex_Check(rhs)) {
        n = PyNumber_AsSsize_t(rhs, PyExc_OverflowError);
        if (n == -1 && PyErr_Occurred())
            throwCAPIException();
    } else {
        raiseExcHelper(TypeError, "can't multiply sequence by non-int of type '%s'", getTypeName(rhs));
    }

    int s = self->size();

    if (n < 0)
        n = 0;

    if ((s == 0 || n == 1) && PyTuple_CheckExact(self)) {
        return self;
    } else {
        BoxedTuple* rtn = BoxedTuple::create(n * s);
        int rtn_i = 0;
        for (int i = 0; i < n; ++i) {
            memmove(&rtn->elts[rtn_i], &self->elts[0], sizeof(Box*) * s);
            rtn_i += s;
        }
        return rtn;
    }
}
开发者ID:jmgc,项目名称:pyston,代码行数:27,代码来源:tuple.cpp


示例8: PyErr_Format

static int PyBobSpIDCT1D_SetShape
(PyBobSpIDCT1DObject* self, PyObject* o, void* /*closure*/) {

  if (!PySequence_Check(o)) {
    PyErr_Format(PyExc_TypeError, "`%s' shape can only be set using tuples (or sequences), not `%s'", Py_TYPE(self)->tp_name, Py_TYPE(o)->tp_name);
    return -1;
  }

  PyObject* shape = PySequence_Tuple(o);
  auto shape_ = make_safe(shape);

  if (PyTuple_GET_SIZE(shape) != 1) {
    PyErr_Format(PyExc_RuntimeError, "`%s' shape can only be set using 1-position tuples (or sequences), not an %" PY_FORMAT_SIZE_T "d-position sequence", Py_TYPE(self)->tp_name, PyTuple_GET_SIZE(shape));
    return -1;
  }

  Py_ssize_t len = PyNumber_AsSsize_t(PyTuple_GET_ITEM(shape, 0), PyExc_OverflowError);
  if (PyErr_Occurred()) return -1;

  try {
    self->cxx->setLength(len);
  }
  catch (std::exception& ex) {
    PyErr_SetString(PyExc_RuntimeError, ex.what());
    return -1;
  }
  catch (...) {
    PyErr_Format(PyExc_RuntimeError, "cannot reset `shape' of %s: unknown exception caught", Py_TYPE(self)->tp_name);
    return -1;
  }

  return 0;

}
开发者ID:183amir,项目名称:bob.sp,代码行数:34,代码来源:idct1d.cpp


示例9: PyPointlessVector_check_index

static int PyPointlessVector_check_index(PyPointlessVector* self, PyObject* item, Py_ssize_t* i)
{
	// if this is not an index: throw an exception
	if (!PyIndex_Check(item)) {
		PyErr_Format(PyExc_TypeError, "PointlessVector: integer indexes please, got <%s>\n", item->ob_type->tp_name);
		return 0;
	}

	// if index value is not an integer: throw an exception
	*i = PyNumber_AsSsize_t(item, PyExc_IndexError);

	if (*i == -1 && PyErr_Occurred())
		return 0;

	// if index is negative, it is relative to vector end
	if (*i < 0)
		*i += PyPointlessVector_length(self);

	// if it is out of bounds: throw an exception
	if (!(0 <= *i && *i < PyPointlessVector_length(self))) {
		PyErr_SetString(PyExc_IndexError, "index is out of bounds");
		return 0;
	}

	return 1;
}
开发者ID:dohop,项目名称:py-pointless,代码行数:26,代码来源:pointless_vector.c


示例10: PyNumber_AsSsize_t

static PyObject *t_sequence_map_get(t_sequence* self, PyObject *item)
{
    PyObject *value;

    if (PyIndex_Check(item))
    {
        Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);

        if (i == -1 && PyErr_Occurred())
            return NULL;
        value = t_sequence_seq_get(self, i);
    }
    else if ((!(self->itemvalue.flags & V_PURE)) ||
             (!((self->sequence->ob_type->tp_as_mapping &&
                 self->sequence->ob_type->tp_as_mapping->mp_subscript) ||
                (PyObject_HasAttr(self->sequence, __getitem___NAME)))))
    {
        int size = PySequence_Size(self->sequence);
        PyObject *values;

        if (size < 0)
            return NULL;

        values = t_sequence_seq_getslice(self, 0, size);
        if (!values)
            return NULL;

        value = PyObject_GetItem(values, item);
        Py_DECREF(values);
    }
    else
        value = PyObject_GetItem(self->sequence, item);
    
    return value;
}
开发者ID:HackLinux,项目名称:chandler,代码行数:35,代码来源:sequence.c


示例11: PyNumber_AsSsize_t

static PyObject *bpy_bmdeformvert_subscript(BPy_BMDeformVert *self, PyObject *key)
{
	if (PyIndex_Check(key)) {
		int i;
		i = PyNumber_AsSsize_t(key, PyExc_IndexError);
		if (i == -1 && PyErr_Occurred()) {
			return NULL;
		}
		else {
			MDeformWeight *dw = defvert_find_index(self->data, i);

			if (dw == NULL) {
				PyErr_SetString(PyExc_KeyError, "BMDeformVert[key] = x: "
				                "key not found");
				return NULL;
			}
			else {
				return PyFloat_FromDouble(dw->weight);
			}
		}
	}
	else {
		PyErr_Format(PyExc_TypeError,
		             "BMDeformVert keys must be integers, not %.200s",
		             Py_TYPE(key)->tp_name);
		return NULL;
	}
}
开发者ID:wchargin,项目名称:blender,代码行数:28,代码来源:bmesh_py_types_meshdata.c


示例12: Affine_subscript

static PyObject *
Affine_subscript(polypaths_planar_overrideAffineObject *self, PyObject *item)
{
    Py_ssize_t i;
    PyObject *t, *s;

    assert(polypaths_planar_overrideAffine_Check(self));
    if (PyIndex_Check(item)) {
        i = PyNumber_AsSsize_t(item, PyExc_IndexError);
        if (i == -1 && PyErr_Occurred()) {
            return NULL;
        }
        if (i < 0) {
            i += Affine_len((PyObject *)self);
        }
        return Affine_getitem(self, i);
    } else if (PySlice_Check(item)) {
        /* We cheat a bit here by constructing a tuple from ourself and 
           slicing that, which is convenient since slicing a transform
           results in a tuple. Not the most efficient, but I don't expect
           transform slicing to be a common, performance sensitive operation
         */
        t = PySequence_Tuple((PyObject *)self);
        if (t == NULL) {
            return NULL;
        }
        s = PyObject_GetItem(t, item);
        Py_DECREF(t);
        return s;
    }
	PyErr_Format(PyExc_TypeError,
		 "Affine indices must be integers, not %.200s",
		 Py_TYPE(item)->tp_name);
	return NULL;
}
开发者ID:apolcyn,项目名称:polypaths_planar_override,代码行数:35,代码来源:ctransform.c


示例13: unpack_list_of_ssize_t

/**
  Helper routine to convert a PyList of integers to a c array of integers.
  */
static int unpack_list_of_ssize_t(PyObject * pylist, Py_ssize_t **dst, Py_ssize_t *len,
                                  const char* kwname)
{
  Py_ssize_t buflen, *buf;
  if (!PyList_Check(pylist))
    {
      PyErr_Format(PyExc_TypeError, "%s must be list", kwname);
      return -1;
    }
  assert (NULL == *dst);
  *len = buflen = PyList_Size(pylist);
  *dst = buf = (Py_ssize_t*)calloc(buflen, sizeof(Py_ssize_t));
  assert(buf);
  for (int ii = 0; ii < buflen; ++ii)
    {
      PyObject * el_i = PyList_GetItem(pylist, ii);
      Py_ssize_t n_i = PyNumber_AsSsize_t(el_i, PyExc_IndexError);
      if (PyErr_Occurred())
        {
          free(buf);
          *dst = NULL;
          return -1;
        }
      buf[ii] = n_i;
    }
  return 0;
}
开发者ID:Donghuan,项目名称:Theano,代码行数:30,代码来源:lazylinker_c.c


示例14: PyBlitzArray_getitem

static PyObject* PyBlitzArray_getitem(PyBlitzArrayObject* self,
    PyObject* item) {

  if (PyBob_NumberCheck(item)) {

    if (self->ndim != 1) {
      PyErr_Format(PyExc_TypeError, "expected tuple for accessing %" PY_FORMAT_SIZE_T "dD array", self->ndim);
      return 0;
    }

    // if you get to this point, the user has passed single number
    Py_ssize_t k = PyNumber_AsSsize_t(item, PyExc_IndexError);
    return PyBlitzArray_GetItem(self, &k);

  }

  if (PySequence_Check(item)) {

    if (self->ndim != PySequence_Fast_GET_SIZE(item)) {
      PyErr_Format(PyExc_TypeError, "expected tuple of size %" PY_FORMAT_SIZE_T "d for accessing %" PY_FORMAT_SIZE_T "dD array", self->ndim, self->ndim);
      return 0;
    }

    // if you get to this point, then the input tuple has the same size
    PyBlitzArrayObject shape;
    PyBlitzArrayObject* shape_p = &shape;
    if (!PyBlitzArray_IndexConverter(item, &shape_p)) return 0;
    return PyBlitzArray_GetItem(self, shape.shape);

  }

  PyErr_Format(PyExc_TypeError, "%s(@%" PY_FORMAT_SIZE_T "d,'%s') indexing requires a single integers (for 1D arrays) or sequences, for any rank size", Py_TYPE(self)->tp_name, self->ndim, PyBlitzArray_TypenumAsString(self->type_num));
  return 0;
}
开发者ID:183amir,项目名称:bob.blitz,代码行数:34,代码来源:array.cpp


示例15: igraphmodule_EdgeSeq_get_attribute_values_mapping

PyObject* igraphmodule_EdgeSeq_get_attribute_values_mapping(igraphmodule_EdgeSeqObject *self, PyObject *o) {
  Py_ssize_t index;

  /* Handle integer indices according to the sequence protocol */
  if (PyIndex_Check(o)) {
    index = PyNumber_AsSsize_t(o, 0);
    return igraphmodule_EdgeSeq_sq_item(self, index);
  }

  /* Handle strings according to the mapping protocol */
  if (PyBaseString_Check(o))
    return igraphmodule_EdgeSeq_get_attribute_values(self, o);

  /* Handle iterables and slices by calling the select() method */
  if (PySlice_Check(o) || PyObject_HasAttrString(o, "__iter__")) {
    PyObject *result, *args;
    args = Py_BuildValue("(O)", o);
    if (!args)
      return NULL;
    result = igraphmodule_EdgeSeq_select(self, args);
    Py_DECREF(args);
    return result;
  }

  /* Handle everything else according to the mapping protocol */
  return igraphmodule_EdgeSeq_get_attribute_values(self, o);
}
开发者ID:bravery,项目名称:python-igraph,代码行数:27,代码来源:edgeseqobject.c


示例16: Color_ass_subscript

static int Color_ass_subscript(ColorObject *self, PyObject *item, PyObject *value)
{
	if (PyIndex_Check(item)) {
		Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
		if (i == -1 && PyErr_Occurred())
			return -1;
		if (i < 0)
			i += COLOR_SIZE;
		return Color_ass_item(self, i, value);
	}
	else if (PySlice_Check(item)) {
		Py_ssize_t start, stop, step, slicelength;

		if (PySlice_GetIndicesEx((void *)item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0)
			return -1;

		if (step == 1)
			return Color_ass_slice(self, start, stop, value);
		else {
			PyErr_SetString(PyExc_IndexError,
			                "slice steps not supported with color");
			return -1;
		}
	}
	else {
		PyErr_Format(PyExc_TypeError,
		             "color indices must be integers, not %.200s",
		             Py_TYPE(item)->tp_name);
		return -1;
	}
}
开发者ID:mik0001,项目名称:Blender,代码行数:31,代码来源:mathutils_Color.c


示例17: PyNumber_AsSsize_t

static int PyBobLearnMLPTrainer_setBatchSize
(PyBobLearnMLPTrainerObject* self, PyObject* o, void* /*closure*/) {

  Py_ssize_t value = PyNumber_AsSsize_t(o, PyExc_OverflowError);
  if (PyErr_Occurred()) return -1;
  self->cxx->setBatchSize(value);
  return 0;

}
开发者ID:183amir,项目名称:bob.learn.mlp,代码行数:9,代码来源:trainer.cpp


示例18: bpy_bmlayercollection_subscript_str

static PyObject *bpy_bmlayercollection_subscript(BPy_BMLayerCollection *self, PyObject *key)
{
	/* don't need error check here */
	if (PyUnicode_Check(key)) {
		return bpy_bmlayercollection_subscript_str(self, _PyUnicode_AsString(key));
	}
	else if (PyIndex_Check(key)) {
		Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
		if (i == -1 && PyErr_Occurred())
			return NULL;
		return bpy_bmlayercollection_subscript_int(self, i);
	}
	else if (PySlice_Check(key)) {
		PySliceObject *key_slice = (PySliceObject *)key;
		Py_ssize_t step = 1;

		if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) {
			return NULL;
		}
		else if (step != 1) {
			PyErr_SetString(PyExc_TypeError,
			                "BMLayerCollection[slice]: slice steps not supported");
			return NULL;
		}
		else if (key_slice->start == Py_None && key_slice->stop == Py_None) {
			return bpy_bmlayercollection_subscript_slice(self, 0, PY_SSIZE_T_MAX);
		}
		else {
			Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;

			/* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
			if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) return NULL;
			if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop))    return NULL;

			if (start < 0 || stop < 0) {
				/* only get the length for negative values */
				Py_ssize_t len = bpy_bmlayercollection_length(self);
				if (start < 0) start += len;
				if (stop  < 0) stop  += len;
			}

			if (stop - start <= 0) {
				return PyTuple_New(0);
			}
			else {
				return bpy_bmlayercollection_subscript_slice(self, start, stop);
			}
		}
	}
	else {
		PyErr_SetString(PyExc_AttributeError,
		                "BMLayerCollection[key]: invalid key, key must be an int");
		return NULL;
	}
}
开发者ID:wchargin,项目名称:blender,代码行数:55,代码来源:bmesh_py_types_customdata.c


示例19: tuplesubscript

static PyObject*
tuplesubscript(PyTupleObject* self, PyObject* item)
{
    if (PyIndex_Check(item)) {
        Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
        if (i == -1 && PyErr_Occurred())
            return NULL;
        if (i < 0)
            i += PyTuple_GET_SIZE(self);
        return tupleitem(self, i);
    }
    else if (PySlice_Check(item)) {
        Py_ssize_t start, stop, step, slicelength, cur, i;
        PyObject* result;
        PyObject* it;
        PyObject **src, **dest;

        if (PySlice_GetIndicesEx(item,
                         PyTuple_GET_SIZE(self),
                         &start, &stop, &step, &slicelength) < 0) {
            return NULL;
        }

        if (slicelength <= 0) {
            return PyTuple_New(0);
        }
        else if (start == 0 && step == 1 &&
                 slicelength == PyTuple_GET_SIZE(self) &&
                 PyTuple_CheckExact(self)) {
            Py_INCREF(self);
            return (PyObject *)self;
        }
        else {
            result = PyTuple_New(slicelength);
            if (!result) return NULL;

            src = self->ob_item;
            dest = ((PyTupleObject *)result)->ob_item;
            for (cur = start, i = 0; i < slicelength;
                 cur += step, i++) {
                it = src[cur];
                Py_INCREF(it);
                dest[i] = it;
            }

            return result;
        }
    }
    else {
        PyErr_Format(PyExc_TypeError,
                     "tuple indices must be integers, not %.200s",
                     Py_TYPE(item)->tp_name);
        return NULL;
    }
}
开发者ID:IgnusIndia,项目名称:pythonexperiment,代码行数:55,代码来源:tupleobject.c


示例20: sipArray_ass_subscript

/*
 * Implement mapping assignment sub-script for the type.
 */
static int sipArray_ass_subscript(PyObject *self, PyObject *key,
        PyObject *value)
{
    sipArrayObject *array = (sipArrayObject *)self;
    SIP_SSIZE_T start, len;
    void *value_data;

    if (check_writable(array) < 0)
        return -1;

    if (PyIndex_Check(key))
    {
        start = PyNumber_AsSsize_t(key, PyExc_IndexError);

        if (start == -1 && PyErr_Occurred())
            return -1;

        if (start < 0)
            start += array->len;

        if (check_index(array, start) < 0)
            return -1;

        if ((value_data = get_value(array, value)) == NULL)
            return -1;

        len = 1;
    }
    else if (PySlice_Check(key))
    {
        Py_ssize_t stop, step;

        if (sipConvertFromSliceObject(key, array->len, &start, &stop, &step, &len) < 0)
            return -1;

        if (step != 1)
        {
            PyErr_SetNone(PyExc_NotImplementedError);
            return -1;
        }

        if ((value_data = get_slice(array, value, len)) == NULL)
            return -1;
    }
    else
    {
        bad_key(key);

        return -1;
    }

    memmove(element(array, start), value_data, len * array->stride);

    return 0;
}
开发者ID:Narengowda,项目名称:web-mouse,代码行数:58,代码来源:array.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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