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


C++ PyInt_FromSsize_t函数代码示例

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


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

示例1: __pyx_f_13extinheritset_9Norwegian___setitem__

/* Implementation of extinheritset */

static int __pyx_f_13extinheritset_9Norwegian___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_x); /*proto*/
static int __pyx_f_13extinheritset_9Norwegian___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_x) {
    int __pyx_r;
    Py_INCREF((PyObject *)__pyx_v_self);
    Py_INCREF(__pyx_v_i);
    Py_INCREF(__pyx_v_x);

    __pyx_r = 0;
    Py_DECREF((PyObject *)__pyx_v_self);
    Py_DECREF(__pyx_v_i);
    Py_DECREF(__pyx_v_x);
    return __pyx_r;
}

static int __pyx_f_13extinheritset_9Norwegian___setslice__(PyObject *__pyx_v_self, Py_ssize_t __pyx_arg_i, Py_ssize_t __pyx_arg_j, PyObject *__pyx_v_x); /*proto*/
static int __pyx_f_13extinheritset_9Norwegian___setslice__(PyObject *__pyx_v_self, Py_ssize_t __pyx_arg_i, Py_ssize_t __pyx_arg_j, PyObject *__pyx_v_x) {
    PyObject *__pyx_v_i = 0;
    PyObject *__pyx_v_j = 0;
    int __pyx_r;
    Py_INCREF((PyObject *)__pyx_v_self);
    Py_INCREF(__pyx_v_x);
    __pyx_v_i = PyInt_FromSsize_t(__pyx_arg_i);
    if (!__pyx_v_i) {
        __pyx_filename = __pyx_f[0];
        __pyx_lineno = 9;
        goto __pyx_L1;
    }
    __pyx_v_j = PyInt_FromSsize_t(__pyx_arg_j);
    if (!__pyx_v_j) {
        __pyx_filename = __pyx_f[0];
        __pyx_lineno = 9;
        goto __pyx_L1;
    }

    __pyx_r = 0;
    goto __pyx_L0;
__pyx_L1:
    ;
    __Pyx_AddTraceback("extinheritset.Norwegian.__setslice__");
    __pyx_r = -1;
__pyx_L0:
    ;
    Py_DECREF(__pyx_v_i);
    Py_DECREF(__pyx_v_j);
    Py_DECREF((PyObject *)__pyx_v_self);
    Py_DECREF(__pyx_v_x);
    return __pyx_r;
}
开发者ID:jwilk,项目名称:Pyrex,代码行数:50,代码来源:extinheritset.c

示例2: string_count

PyObject *
string_count(PyStringObject *self, PyObject *args)
{
    PyObject *sub_obj;
    const char *str = PyString_AS_STRING(self), *sub;
    Py_ssize_t sub_len;
    Py_ssize_t start = 0, end = PY_SSIZE_T_MAX;

    if (!stringlib_parse_args_finds("count", args, &sub_obj, &start, &end))
        return NULL;

    if (PyString_Check(sub_obj)) {
        sub = PyString_AS_STRING(sub_obj);
        sub_len = PyString_GET_SIZE(sub_obj);
    }
#ifdef Py_USING_UNICODE
    else if (PyUnicode_Check(sub_obj)) {
        Py_ssize_t count;
        count = PyUnicode_Count((PyObject *)self, sub_obj, start, end);
        if (count == -1)
            return NULL;
        else
            return PyInt_FromSsize_t(count);
    }
#endif
    else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len))
        return NULL;

    ADJUST_INDICES(start, end, PyString_GET_SIZE(self));

    return PyInt_FromSsize_t(
        stringlib_count(str + start, end - start, sub, sub_len, PY_SSIZE_T_MAX)
        );
}
开发者ID:guangwong,项目名称:pyston,代码行数:34,代码来源:stringobject.c

示例3: thread_stack_size

static PyObject *
thread_stack_size(PyObject *self, PyObject *args)
{
    size_t old_size;
    Py_ssize_t new_size = 0;
    int rc;

    if (!PyArg_ParseTuple(args, "|n:stack_size", &new_size))
        return NULL;

    if (new_size < 0) {
        PyErr_SetString(PyExc_ValueError,
                        "size must be 0 or a positive value");
        return NULL;
    }

    old_size = PyThread_get_stacksize();

    rc = PyThread_set_stacksize((size_t) new_size);
    if (rc == -1) {
        PyErr_Format(PyExc_ValueError,
                     "size not valid: %zd bytes",
                     new_size);
        return NULL;
    }
    if (rc == -2) {
        PyErr_SetString(ThreadError,
                        "setting stack size not supported");
        return NULL;
    }

    return PyInt_FromSsize_t((Py_ssize_t) old_size);
}
开发者ID:CSC-IT-Center-for-Science,项目名称:scalable-python,代码行数:33,代码来源:threadmodule.c

示例4: java_number_to_pythonintlong

static PyObject* java_number_to_pythonintlong(JNIEnv *env, PyObject* n)
{
    jlong      value;
    PyJObject *jnumber  = (PyJObject*) n;

    if (longValue == 0) {
        longValue = (*env)->GetMethodID(env, JNUMBER_TYPE, "longValue", "()J");

        if (process_java_exception(env)) {
            return NULL;
        }
    }

#if PY_MAJOR_VERSION < 3
    if (intValue == 0) {
        intValue = (*env)->GetMethodID(env, JNUMBER_TYPE, "intValue", "()I");

        if (process_java_exception(env)) {
            return NULL;
        }
    }

    if ((*env)->IsInstanceOf(env, jnumber->object, JBYTE_OBJ_TYPE) ||
            (*env)->IsInstanceOf(env, jnumber->object, JSHORT_OBJ_TYPE) ||
            (*env)->IsInstanceOf(env, jnumber->object, JINT_OBJ_TYPE)) {
        jint result = (*env)->CallIntMethod(env, jnumber->object, intValue);
        return PyInt_FromSsize_t(result);
    }
#endif

    value = (*env)->CallLongMethod(env, jnumber->object, longValue);
    return PyLong_FromLongLong(value);
}
开发者ID:codeApeFromChina,项目名称:jep,代码行数:33,代码来源:pyjnumber.c

示例5: gc_collect

static PyObject *
gc_collect(PyObject *self, PyObject *args, PyObject *kws)
{
	static char *keywords[] = {"generation", NULL};
	int genarg = NUM_GENERATIONS - 1;
	Py_ssize_t n;

	if (!PyArg_ParseTupleAndKeywords(args, kws, "|i", keywords, &genarg))
		return NULL;

	else if (genarg < 0 || genarg >= NUM_GENERATIONS) {
		PyErr_SetString(PyExc_ValueError, "invalid generation");
		return NULL;
	}

	if (collecting)
		n = 0; /* already collecting, don't do anything */
	else {
		collecting = 1;
		n = collect(genarg);
		collecting = 0;
	}

	return PyInt_FromSsize_t(n);
}
开发者ID:moon2l,项目名称:Python-2.5.6,代码行数:25,代码来源:gcmodule.c

示例6: mmap_find_method

static PyObject *
mmap_find_method(mmap_object *self,
		 PyObject *args)
{
	Py_ssize_t start = self->pos;
	char *needle;
	Py_ssize_t len;

	CHECK_VALID(NULL);
	if (!PyArg_ParseTuple(args, "s#|n:find", &needle, &len, &start)) {
		return NULL;
	} else {
		char *p;
		char *e = self->data + self->size;

                if (start < 0)
			start += self->size;
                if (start < 0)
			start = 0;
                else if ((size_t)start > self->size)
			start = self->size;

		for (p = self->data + start; p + len <= e; ++p) {
			Py_ssize_t i;
			for (i = 0; i < len && needle[i] == p[i]; ++i)
				/* nothing */;
			if (i == len) {
				return PyInt_FromSsize_t(p - self->data);
			}
		}
		return PyInt_FromLong(-1);
	}
}
开发者ID:BIT66COM,项目名称:python-multiprocessing,代码行数:33,代码来源:mmapmodule.c

示例7: IO_tell

static PyObject *
IO_tell(IOobject *self, PyObject *unused) {

        if (!IO__opencheck(self)) return NULL;

        return PyInt_FromSsize_t(self->pos);
}
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:7,代码来源:cStringIO.c

示例8: logger

struct matcher_entry *matchers_get_response(u_char *data, u_int datalen, struct ctx *ctx, u_int type, u_int src_port, u_int dst_port)
{

    struct matcher_entry *matcher;

#ifdef HAVE_PYTHON
    PyObject *args;
    PyObject *value;
    Py_ssize_t rdatalen;
    char *rdata;
#endif

    if(!(matcher = matchers_match((const char *)data, datalen, ctx, type, src_port, dst_port))) {
        logger(DBG, "No matchers found for data");
        return NULL;
    }

#ifdef HAVE_PYTHON
    if(matcher->pyfunc) {
        logger(DBG, "We have a Python code to construct response");
        args = PyTuple_New(2);
        PyTuple_SetItem(args,0,PyString_FromStringAndSize((const char *)data, datalen)); // here is data
        PyTuple_SetItem(args,1,PyInt_FromSsize_t(datalen));

        value = PyObject_CallObject(matcher->pyfunc, args);
        if(value == NULL) {
            PyErr_Print();
            logger(WARN, "Python function returns no data!");
            return NULL;
        }

        rdata = PyString_AsString(value);
        rdatalen = PyString_Size(value);

        if(rdata != NULL && rdatalen > 0) {
            matcher->response_len = (u_int) rdatalen;
            if(matcher->response) {
                // We already have previous response, free it
                free(matcher->response);
            }
            matcher->response = malloc(matcher->response_len);
            memcpy(matcher->response, (u_char *) rdata, rdatalen);
        } else {
            PyErr_Print();
            logger(WARN, "Python cannot convert return string");
            return NULL;
        }
        return matcher;
    }
#endif

    if(matcher->response) {
        logger(DBG, "We have a plain text response");
        return matcher;
    }

    logger(WARN, "There is no response data!");
    return NULL;

}
开发者ID:DINKIN,项目名称:lrc,代码行数:60,代码来源:matchers.c

示例9: PyErr_SetString

static PyObject *ffi_offsetof(FFIObject *self, PyObject *args)
{
    PyObject *arg;
    CTypeDescrObject *ct;
    Py_ssize_t i, offset;

    if (PyTuple_Size(args) < 2) {
        PyErr_SetString(PyExc_TypeError,
                        "offsetof() expects at least 2 arguments");
        return NULL;
    }

    arg = PyTuple_GET_ITEM(args, 0);
    ct = _ffi_type(self, arg, ACCEPT_STRING|ACCEPT_CTYPE);
    if (ct == NULL)
        return NULL;

    offset = 0;
    for (i = 1; i < PyTuple_GET_SIZE(args); i++) {
        Py_ssize_t ofs1;
        ct = direct_typeoffsetof(ct, PyTuple_GET_ITEM(args, i), i > 1, &ofs1);
        if (ct == NULL)
            return NULL;
        offset += ofs1;
    }
    return PyInt_FromSsize_t(offset);
}
开发者ID:RBPI,项目名称:real-python-test,代码行数:27,代码来源:ffi_obj.c

示例10: PyInt_FromSsize_t

static PyObject *__pyx_sq_item_9ishimoto1_A(PyObject *o, Py_ssize_t i) {
  PyObject *r;
  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
  r = o->ob_type->tp_as_mapping->mp_subscript(o, x);
  Py_DECREF(x);
  return r;
}
开发者ID:jwilk,项目名称:Pyrex,代码行数:7,代码来源:ishimoto1.c

示例11: install

static void
install(PyObject *d, char* name, void* value)
{
    PyObject *v = PyInt_FromSsize_t((Py_ssize_t) value);
    if (!v || PyDict_SetItemString(d, name, v))
        PyErr_Clear();
    Py_XDECREF(v);
}
开发者ID:Bouke,项目名称:Pillow,代码行数:8,代码来源:_imagingmath.c

示例12: string_find

PyObject *
string_find(PyStringObject *self, PyObject *args)
{
    Py_ssize_t result = string_find_internal(self, args, +1);
    if (result == -2)
        return NULL;
    return PyInt_FromSsize_t(result);
}
开发者ID:guangwong,项目名称:pyston,代码行数:8,代码来源:stringobject.c

示例13: ip_store_size

static PyObject *
ip_store_size(PyObject *self){
#ifdef IS_PY3K
    return PyLong_FromSsize_t(ipdb_size);
#else
    return PyInt_FromSsize_t(ipdb_size);
#endif
}
开发者ID:huxt2014,项目名称:python-examples,代码行数:8,代码来源:ip_store.c

示例14: getargs_n

static PyObject *
getargs_n(PyObject *self, PyObject *args)
{
	Py_ssize_t value;
	if (!PyArg_ParseTuple(args, "n", &value))
	return NULL;
	return PyInt_FromSsize_t(value);
}
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:8,代码来源:_testcapimodule.c

示例15: tupleiter_len

static PyObject *
tupleiter_len(tupleiterobject *it)
{
	Py_ssize_t len = 0;
	if (it->it_seq)
		len = PyTuple_GET_SIZE(it->it_seq) - it->it_index;
	return PyInt_FromSsize_t(len);
}
开发者ID:moon2l,项目名称:Python-2.5.6,代码行数:8,代码来源:tupleobject.c


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