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

C++ PyInt_AsSsize_t函数代码示例

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

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



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


示例16: PyInt_AsSsize_t

//Py Conversion Functions with overloads
int Pywrap::py_extractInt(PyObject *results) const
{
    if(PyInt_Check(results))
    {
        return PyInt_AsSsize_t(results);
    }
    std::cout << "Warning: PyObject is not Integer. Undefined behavior may occur! Warning in script: " << path
            << std::endl;
    return 0;
}
开发者ID:kiseitai2,项目名称:Engine_Eureka,代码行数:11,代码来源:pywrap.cpp


示例17: __Pyx_PyNumber_Int

static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static CYTHON_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:skipperkongen,项目名称:the_education_of,代码行数:54,代码来源:hello.c


示例18: Row_setattro

static int
Row_setattro(PyObject* o, PyObject *name, PyObject* v)
{
    Row* self = (Row*)o;

    PyObject* index = PyDict_GetItem(self->map_name_to_index, name);

    if (index)
        return Row_ass_item(self, PyInt_AsSsize_t(index), v);

    return PyObject_GenericSetAttr(o, name, v);
}
开发者ID:arvindchari88,项目名称:newGitTest,代码行数:12,代码来源:row.cpp


示例19: Image_new

/* Constructor */
PyObject *
Image_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
    ImageObject *self = (ImageObject*) type->tp_alloc(type, 0);
    if (self != NULL)
    {
        PyObject *input = NULL;

        if (PyArg_ParseTuple(args, "|O", &input))
        {
            if (input != NULL)
            {
                try
                {
                    PyObject *pyStr;
                    // If the input object is a tuple, consider it (index, filename)
                    if (PyTuple_Check(input))
                    {
                      // Get the index and filename from the Python tuple object
                      size_t index = PyInt_AsSsize_t(PyTuple_GetItem(input, 0));
                      const char * filename = PyString_AsString(PyTuple_GetItem(input, 1));
                      // Now read using both of index and filename
                      self->image = new ImageGeneric();
                      self->image->read(filename, DATA, index);

                    }
                    else if ((pyStr = PyObject_Str(input)) != NULL)
                    {
                        self->image = new ImageGeneric(PyString_AsString(pyStr));
                        //todo: add copy constructor
                    }
                    else
                    {
                        PyErr_SetString(PyExc_TypeError,
                                        "Image_new: Expected string, FileName or tuple as first argument");
                        return NULL;
                    }
                }
                catch (XmippError &xe)
                {
                    PyErr_SetString(PyXmippError, xe.msg.c_str());
                    return NULL;
                }
            }
            else
                self->image = new ImageGeneric();
        }
        else
            return NULL;
    }
    return (PyObject *) self;
}//function Image_new
开发者ID:juannavascalvente,项目名称:scipion,代码行数:53,代码来源:python_image.cpp


示例20: dealloc_cpt

PyObject *
dealloc_cpt(PyObject *self, PyObject *args) {
    PyObject *pycpt; // addr of cpt as a python int

    if (!PyArg_ParseTuple(args, "O", &pycpt)) {
        return NULL;
    }

    CPT *cpt = (CPT*) PyInt_AsSsize_t(pycpt);
    _dealloc_cpt(cpt);

    Py_RETURN_NONE;
}
开发者ID:Alwnikrotikz,项目名称:pebl-project,代码行数:13,代码来源:_cpd.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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