当前位置: 首页>>代码示例>>C++>>正文


C++ PyInt_AsSsize_t函数代码示例

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


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

示例1: 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

示例2: SobolSampler_New

SobolSampler* SobolSampler_New(size_t dims, PyObject* size)
{
    size_t _size   = 0;
    size_t _is_inf = 0;

    if (size == Py_None)
    {
        _size   = 1;
        _is_inf = 1;
    }
    else if (PyInt_Check(size) || PyLong_Check(size))
    {
        _size   = PyInt_AsSsize_t(size);
        _is_inf = 0;
    }
    else
    {
        PyErr_SetString(PyExc_TypeError, "size must be an integer, or None");
        return NULL;
    }
    
    SobolSampler* s = PyObject_New(SobolSampler, &SobolSamplerType);
    if (!s) return NULL;

    s->_size   = _size;
    s->_is_inf = _is_inf;
    s->_dims   = dims;
    s->_rng    = gsl_qrng_alloc(gsl_qrng_sobol, dims);

    return s;
}
开发者ID:scriada,项目名称:pysobol,代码行数:31,代码来源:sobol_obj.c

示例3: python_write

static ssize_t python_write(vfs_handle_struct *handle, files_struct *fsp, const void *data, size_t n)
{
	struct pyfuncs *pf = handle->data;
	PyObject *pArgs, *pRet, *pValue;
	char *pydata;
	ssize_t s;

	if (!pf->pFuncWrite) {
		errno = ENOSYS;
		return -1;
	}

	PY_TUPLE_NEW(2);
	PY_ADD_TO_TUPLE(fsp->fh->fd, PyInt_FromSsize_t, 0);
	if (!(pValue = PyString_FromStringAndSize(data, n))) {
		Py_DECREF(pArgs);
		errno = E_INTERNAL;
		return -1;
	}
	PyTuple_SetItem(pArgs, 1, pValue);
	PY_CALL_WITH_ARGS(Write);

	s = PyInt_AsSsize_t(pRet);

	Py_DECREF(pRet);
	return s;
}
开发者ID:jeagle,项目名称:win_fuse_smb,代码行数:27,代码来源:vfs_python.c

示例4: transfer

static PyObject* transfer(PyObject* self, PyObject* arg)
{
	PyObject* transferTuple;

	if(!PyArg_ParseTuple(arg, "O", &transferTuple))		// "O" - Gets non-NULL borrowed reference to Python argument.
		return NULL;					// As far as I can tell, it's mostly just copying arg[0] into transferTuple
								// and making sure at least one arg has been passed (I think)

	if(!PyTuple_Check(transferTuple))			// The only argument we support is a single tuple.
		pabort("Only accepts a single tuple as an argument\n");


	uint32_t tupleSize = PyTuple_Size(transferTuple);

	uint8_t tx[tupleSize];
	uint8_t rx[tupleSize];
	PyObject* tempItem;

	uint16_t i=0;

	while(i < tupleSize)
	{
		tempItem = PyTuple_GetItem(transferTuple, i);		//
		if(!PyInt_Check(tempItem))
		{
			pabort("non-integer contained in tuple\n");
		}
		tx[i] = (uint8_t)PyInt_AsSsize_t(tempItem);

		i++;

	}

	struct spi_ioc_transfer tr = {
		.tx_buf = (unsigned long)tx,
		.rx_buf = (unsigned long)rx,
		.len = tupleSize,
		.delay_usecs = delay,
		.speed_hz = speed,
		.bits_per_word = bits,
                .cs_change = 1,
	};

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 1)
		pabort("can't send spi message");

	transferTuple = PyTuple_New(tupleSize);
	for(i=0;i<tupleSize;i++)
		PyTuple_SetItem(transferTuple, i, Py_BuildValue("i",rx[i]));

	return transferTuple;
}


static PyObject* closeSPI(PyObject* self,PyObject* args)
{
	close(fd);
	Py_RETURN_NONE;
}
开发者ID:DomAmato,项目名称:Laser_Engraver,代码行数:60,代码来源:spi.c

示例5: directWrite

static PyObject* directWrite(PyObject* self, PyObject* arg)
{
	PyObject* transferTuple;
	unsigned int offset, returnVal ;

	if(!PyArg_ParseTuple(arg, "lO", &offset, &transferTuple))		
		return NULL;					

	if(!PyTuple_Check(transferTuple))			
		pabort("Only accepts a single tuple as an argument\n");


	uint32_t tupleSize = PyTuple_Size(transferTuple);
	uint8_t tx[tupleSize];
	PyObject* tempItem;
	uint32_t i=0;
	while(i < tupleSize)
	{
		tempItem = PyTuple_GetItem(transferTuple, i);		//
		if(!PyInt_Check(tempItem))
		{
			pabort("non-integer contained in tuple\n");
		}
		tx[i] = (uint8_t)PyInt_AsSsize_t(tempItem);
		i++;

	}
	returnVal = direct_write(offset, tx, tupleSize);
	return Py_BuildValue("l", returnVal) ;
}
开发者ID:andygikling,项目名称:logi-tools,代码行数:30,代码来源:mark1-rpi.c

示例6: image_set_int

static int
image_set_int (zbarImage *self,
               PyObject *value,
               void *closure)
{
    unsigned int tmp, val = PyInt_AsSsize_t(value);
    if(val == -1 && PyErr_Occurred()) {
        PyErr_SetString(PyExc_TypeError, "expecting an integer");
        return(-1);
    }
    switch((int)closure) {
    case 0:
        tmp = zbar_image_get_height(self->zimg);
        zbar_image_set_size(self->zimg, val, tmp);
        break;
    case 1:
        tmp = zbar_image_get_width(self->zimg);
        zbar_image_set_size(self->zimg, tmp, val);
        break;
    case 2:
        zbar_image_set_sequence(self->zimg, val);
    default:
        assert(0);
    }
    return(0);
}
开发者ID:krunalsoni01,项目名称:yocto-zbar,代码行数:26,代码来源:image.c

示例7: do_pyfs_open

grub_err_t do_pyfs_open(const char *name, grub_off_t *size)
{
    PyObject *pyret;
    Py_ssize_t pysize;

    if (!pyfs_open_callable)
        return GRUB_ERR_FILE_NOT_FOUND;

    pyret = PyObject_CallFunction(pyfs_open_callable, "s", name);

    if (pyret == NULL) {
        PyErr_Print();
        return grub_error(GRUB_ERR_IO, "Internal error: Failed to call Python open callback, or it threw an exception");
    }

    if (pyret == Py_None) {
        Py_DECREF(pyret);
        return GRUB_ERR_BAD_FILE_TYPE;
    }

    pysize = PyInt_AsSsize_t(pyret);
    Py_DECREF(pyret);
    if (pysize < 0) {
        if (PyErr_Occurred())
            PyErr_Print();
        return grub_error(GRUB_ERR_IO, "Internal error: Python open callback returned a bad or negative size");
    }

    *size = (grub_off_t)pysize;
    return GRUB_ERR_NONE;
}
开发者ID:Tourountzis,项目名称:bits,代码行数:31,代码来源:pyfsmodule.c

示例8: 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

示例9: 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

示例10: __pyx_PyIndex_AsSsize_t

static INLINE Py_ssize_t __pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
开发者ID:liguow,项目名称:everseq,代码行数:8,代码来源:_core.c

示例11: Py_INCREF

/* Implementation of rowe_1 */

static PyObject *__pyx_f_6rowe_1_function(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rowe_1_function(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_data = 0;
  PyObject *__pyx_v_a;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  int __pyx_3;
  Py_ssize_t __pyx_4;
  Py_ssize_t __pyx_5;
  static char *__pyx_argnames[] = {"data",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_data)) return 0;
  Py_INCREF(__pyx_v_data);
  __pyx_v_a = Py_None; Py_INCREF(Py_None);

  /* "/Local/Projects/D/Pyrex/Source/Tests/Bugs/other/rowe_1.pyx":7 */
  __pyx_1 = PyInt_FromLong(4); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
  __pyx_2 = PyNumber_Multiply(__pyx_1, __pyx_v_a); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_3 = PyInt_AsLong(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  blarg(__pyx_3);

  /* "/Local/Projects/D/Pyrex/Source/Tests/Bugs/other/rowe_1.pyx":8 */
  __pyx_4 = PyInt_AsSsize_t(__pyx_v_a); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_b); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}
  __pyx_2 = PyNumber_Add(__pyx_v_a, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_5 = PyInt_AsSsize_t(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_1 = PySequence_GetSlice(__pyx_v_data, __pyx_4, __pyx_5); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("rowe_1.function");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_a);
  Py_DECREF(__pyx_v_data);
  return __pyx_r;
}
开发者ID:jwilk,项目名称:Pyrex,代码行数:49,代码来源:rowe_1.c

示例12: logiWrite

static PyObject* logiWrite(PyObject* self, PyObject* arg)
{
	PyObject* transferTuple;
	unsigned int offset, returnVal ;
	unsigned char type_size = 1 ;

	if(!PyArg_ParseTuple(arg, "lO|b", &offset, &transferTuple, &type_size))
		return NULL;

	if(!PyTuple_Check(transferTuple))
		pabort("Only accepts a single tuple as an argument\n");

	if(type_size != 1 && type_size != 2 && type_size != 4)
		pabort("type_size argument can only be 1, 2, 4\n");
	uint32_t tupleSize = PyTuple_Size(transferTuple);
	uint8_t tx[tupleSize*type_size];
	PyObject* tempItem;
	uint32_t i=0;
	while(i < tupleSize)
	{
		tempItem = PyTuple_GetItem(transferTuple, i);		//
		if(!PyInt_Check(tempItem))
		{
			pabort("non-integer contained in tuple\n");
		}
		switch(type_size){
			case 1:
				tx[i] = (uint8_t)PyInt_AsSsize_t(tempItem);
				break ;
			case 2:
				((uint16_t*)tx)[i] = (uint16_t)PyInt_AsSsize_t(tempItem);
				break ;
			case 4:
				((uint32_t*)tx)[i] = (uint32_t)PyInt_AsSsize_t(tempItem);
				break ;
			default:
				break ;

			
		}
		i++;

	}
	returnVal = logi_write(tx, tupleSize*type_size, offset);
	return Py_BuildValue("l", returnVal) ;
}
开发者ID:ddparker,项目名称:logi-tools,代码行数:46,代码来源:logi.c

示例13: _split_u_list

static PyObject*
_split_u_list(PyObject* self, PyObject* arg) {
	size_t sLen = 0, splitterLen = 1, maxsplit = 1, index = 0;
	Py_UNICODE *src = NULL, *s, *ss, *sEnd = NULL, *sPrev = NULL;
	Py_UNICODE defaultSplitter = ',', *splitter = &defaultSplitter, *sp, *spEnd = splitter + splitterLen;
	PyObject *list;
	PyTupleObject* argTuple = (PyTupleObject*) arg;

	if (PyUnicode_CheckExact(argTuple->ob_item[0])) {
		src = PyUnicode_AS_UNICODE(argTuple->ob_item[0]);
		sLen = PyUnicode_GET_SIZE(argTuple->ob_item[0]);
	} else {
		return NULL;
	}

	maxsplit = PyInt_AsSsize_t(argTuple->ob_item[1]);
	if (!maxsplit || maxsplit > 100) {
		return NULL;
	}

	if (argTuple->ob_size > 2) {
		if (PyUnicode_CheckExact(argTuple->ob_item[2])) {
			splitter = PyUnicode_AS_UNICODE(argTuple->ob_item[2]);
			splitterLen = PyUnicode_GET_SIZE(argTuple->ob_item[2]);
			spEnd = splitter + splitterLen;
		} else {
			return NULL;
		}
	}

	sPrev = s = src, sEnd = src + sLen;
	list = TYPE_NEW(maxsplit);
	while (s < sEnd) {
		if (*s == *splitter) {
			if (splitterLen > 1) {
				sp = splitter, ss = s;
				while (*++sp == *++ss);
				if (sp >= spEnd) {
					ADD_U;
					if (index >= maxsplit) return list;
					sPrev = s + splitterLen;
					s += splitterLen;
					continue;
				}
			} else {
				ADD_U;
				if (index >= maxsplit) return list;
				sPrev = s + 1;
			}
		}
		s++;
	}
	if (index < maxsplit) {
		ADD_U;
	}
	Py_SIZE(list) = index;
	return list;
}
开发者ID:S-YOU,项目名称:split,代码行数:58,代码来源:split.c

示例14: modena_model_outputs_argPos

size_t modena_model_outputs_argPos(const modena_model_t *m, const char *name)
{
    PyObject *pRet = PyObject_CallMethod(m->pModel, "outputs_argPos", NULL);
    if(!pRet){ Modena_PyErr_Print(); }
    size_t ret = PyInt_AsSsize_t(pRet);
    Py_DECREF(pRet);

    return ret;
}
开发者ID:mandarthombre,项目名称:MoDeNa,代码行数:9,代码来源:modena.c

示例15: PyTuple_GET_ITEM

void modena_substitute_model_calculate_maps
(
    modena_substitute_model_t *sm,
    modena_model_t *parent
)
{
    PyObject *pMaps = PyObject_CallMethod
    (
        parent->pModel, "calculate_maps", "(O)", sm->model->pModel
    );
    if(!pMaps){ Modena_PyErr_Print(); }

    PyObject *pMapOutputs = PyTuple_GET_ITEM(pMaps, 0); // Borrowed ref
    if(!pMapOutputs){ Modena_PyErr_Print(); }
    PyObject *pSeq = PySequence_Fast(pMapOutputs, "expected a sequence");
    sm->map_outputs_size = PySequence_Size(pMapOutputs);
    sm->map_outputs = malloc(sm->map_outputs_size*sizeof(double));
    size_t i;
    for(i = 0; i < sm->map_outputs_size; i++)
    {
        sm->map_outputs[i] = PyInt_AsSsize_t(PyList_GET_ITEM(pSeq, i));
        parent->argPos_used[sm->map_outputs[i]] = true;
    }
    sm->map_outputs_size /= 2;
    Py_DECREF(pSeq);
    Py_DECREF(pMapOutputs);
    if(PyErr_Occurred()){ Modena_PyErr_Print(); }

    PyObject *pMapInputs = PyTuple_GET_ITEM(pMaps, 1); // Borrowed ref
    if(!pMapInputs){ Modena_PyErr_Print(); }
    pSeq = PySequence_Fast(pMapInputs, "expected a sequence");
    sm->map_inputs_size = PySequence_Size(pMapInputs);
    sm->map_inputs = malloc(sm->map_inputs_size*sizeof(double));
    for(i = 0; i < sm->map_inputs_size; i++)
    {
        sm->map_inputs[i] = PyInt_AsSsize_t(PyList_GET_ITEM(pSeq, i));
    }
    sm->map_inputs_size /= 2;
    Py_DECREF(pSeq);
    Py_DECREF(pMapInputs);
    if(PyErr_Occurred()){ Modena_PyErr_Print(); }

    Py_DECREF(pMaps);
}
开发者ID:mandarthombre,项目名称:MoDeNa,代码行数:44,代码来源:modena.c


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