本文整理汇总了C++中PyLong_FromSsize_t函数的典型用法代码示例。如果您正苦于以下问题:C++ PyLong_FromSsize_t函数的具体用法?C++ PyLong_FromSsize_t怎么用?C++ PyLong_FromSsize_t使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyLong_FromSsize_t函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Module_AddSsize_tConstant
static int
Module_AddSsize_tConstant(PyObject *module, const char *name, Py_ssize_t value)
{
PyObject *py_value = PyLong_FromSsize_t(value);
if (!py_value) {
return -1;
}
if (PyModule_AddObject(module, name, py_value)) {
Py_DECREF(py_value);
return -1;
}
return 0;
}
示例2: frame_sizeof
static PyObject *
frame_sizeof(PyFrameObject *f)
{
Py_ssize_t res, extras, ncells, nfrees;
ncells = PyTuple_GET_SIZE(f->f_code->co_cellvars);
nfrees = PyTuple_GET_SIZE(f->f_code->co_freevars);
extras = f->f_code->co_stacksize + f->f_code->co_nlocals +
ncells + nfrees;
/* subtract one as it is already included in PyFrameObject */
res = sizeof(PyFrameObject) + (extras-1) * sizeof(PyObject *);
return PyLong_FromSsize_t(res);
}
示例3: mmap_gfind
static PyObject *
mmap_gfind(mmap_object *self,
PyObject *args,
int reverse)
{
Py_ssize_t start = self->pos;
Py_ssize_t end = self->size;
Py_buffer view;
CHECK_VALID(NULL);
if (!PyArg_ParseTuple(args, reverse ? "y*|nn:rfind" : "y*|nn:find",
&view, &start, &end)) {
return NULL;
} else {
const char *p, *start_p, *end_p;
int sign = reverse ? -1 : 1;
const char *needle = view.buf;
Py_ssize_t len = view.len;
if (start < 0)
start += self->size;
if (start < 0)
start = 0;
else if (start > self->size)
start = self->size;
if (end < 0)
end += self->size;
if (end < 0)
end = 0;
else if (end > self->size)
end = self->size;
start_p = self->data + start;
end_p = self->data + end;
for (p = (reverse ? end_p - len : start_p);
(p >= start_p) && (p + len <= end_p); p += sign) {
Py_ssize_t i;
for (i = 0; i < len && needle[i] == p[i]; ++i)
/* nothing */;
if (i == len) {
PyBuffer_Release(&view);
return PyLong_FromSsize_t(p - self->data);
}
}
PyBuffer_Release(&view);
return PyLong_FromLong(-1);
}
}
示例4: iter_len
static PyObject *
iter_len(seqiterobject *it)
{
Py_ssize_t seqsize, len;
if (it->it_seq) {
seqsize = PySequence_Size(it->it_seq);
if (seqsize == -1)
return NULL;
len = seqsize - it->it_index;
if (len >= 0)
return PyLong_FromSsize_t(len);
}
return PyLong_FromLong(0);
}
示例5: tuplecount
static PyObject *
tuplecount(PyTupleObject *self, PyObject *v)
{
Py_ssize_t count = 0;
Py_ssize_t i;
for (i = 0; i < Py_SIZE(self); i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0)
count++;
else if (cmp < 0)
return NULL;
}
return PyLong_FromSsize_t(count);
}
示例6: code_sizeof
static PyObject *
code_sizeof(PyCodeObject *co, void *unused)
{
Py_ssize_t res = _PyObject_SIZE(Py_TYPE(co));
_PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra*) co->co_extra;
if (co->co_cell2arg != NULL && co->co_cellvars != NULL) {
res += PyTuple_GET_SIZE(co->co_cellvars) * sizeof(Py_ssize_t);
}
if (co_extra != NULL) {
res += sizeof(_PyCodeObjectExtra) +
(co_extra->ce_size-1) * sizeof(co_extra->ce_extras[0]);
}
return PyLong_FromSsize_t(res);
}
示例7: range_count
static PyObject *
range_count(rangeobject *r, PyObject *ob)
{
if (PyLong_CheckExact(ob) || PyBool_Check(ob)) {
int result = range_contains_long(r, ob);
if (result == -1)
return NULL;
return PyLong_FromLong(result);
} else {
Py_ssize_t count;
count = _PySequence_IterSearch((PyObject*)r, ob, PY_ITERSEARCH_COUNT);
if (count == -1)
return NULL;
return PyLong_FromSsize_t(count);
}
}
示例8: bisect_right
static PyObject *
bisect_right(PyObject *self, PyObject *args, PyObject *kw)
{
PyObject *list, *item;
Py_ssize_t lo = 0;
Py_ssize_t hi = -1;
Py_ssize_t index;
static char *keywords[] = {"a", "x", "lo", "hi", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kw, "OO|nn:bisect_right",
keywords, &list, &item, &lo, &hi))
return NULL;
index = internal_bisect_right(list, item, lo, hi);
if (index < 0)
return NULL;
return PyLong_FromSsize_t(index);
}
示例9: iter_len
static PyObject *
iter_len(seqiterobject *it, PyObject *Py_UNUSED(ignored))
{
Py_ssize_t seqsize, len;
if (it->it_seq) {
if (_PyObject_HasLen(it->it_seq)) {
seqsize = PySequence_Size(it->it_seq);
if (seqsize == -1)
return NULL;
}
else {
Py_RETURN_NOTIMPLEMENTED;
}
len = seqsize - it->it_index;
if (len >= 0)
return PyLong_FromSsize_t(len);
}
return PyLong_FromLong(0);
}
示例10: switch
PyObject *pyrna_array_index(PointerRNA *ptr, PropertyRNA *prop, int index)
{
PyObject *item;
switch (RNA_property_type(prop)) {
case PROP_FLOAT:
item = PyFloat_FromDouble(RNA_property_float_get_index(ptr, prop, index));
break;
case PROP_BOOLEAN:
item = PyBool_FromLong(RNA_property_boolean_get_index(ptr, prop, index));
break;
case PROP_INT:
item = PyLong_FromSsize_t(RNA_property_int_get_index(ptr, prop, index));
break;
default:
PyErr_SetString(PyExc_TypeError, "not an array type");
item = NULL;
}
return item;
}
示例11: Py_Map
static int Py_Map(npy_intp *ocoor, double* icoor, int orank, int irank,
void *data)
{
PyObject *coors = NULL, *rets = NULL, *args = NULL, *tmp = NULL;
npy_intp ii;
NI_PythonCallbackData *cbdata = (NI_PythonCallbackData*)data;
coors = PyTuple_New(orank);
if (!coors)
goto exit;
for(ii = 0; ii < orank; ii++) {
#if PY_VERSION_HEX < 0x02060000
PyTuple_SetItem(coors, ii, PyLong_FromLong(ocoor[ii]));
#else
PyTuple_SetItem(coors, ii, PyLong_FromSsize_t(ocoor[ii]));
#endif
if (PyErr_Occurred())
goto exit;
}
tmp = Py_BuildValue("(O)", coors);
if (!tmp)
goto exit;
args = PySequence_Concat(tmp, cbdata->extra_arguments);
if (!args)
goto exit;
rets = PyObject_Call(cbdata->function, args, cbdata->extra_keywords);
if (!rets)
goto exit;
for(ii = 0; ii < irank; ii++) {
icoor[ii] = PyFloat_AsDouble(PyTuple_GetItem(rets, ii));
if (PyErr_Occurred())
goto exit;
}
exit:
Py_XDECREF(coors);
Py_XDECREF(tmp);
Py_XDECREF(rets);
Py_XDECREF(args);
return PyErr_Occurred() ? 0 : 1;
}
示例12: stdprinter_write
static PyObject *
stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
{
char *c;
Py_ssize_t n;
if (self->fd < 0) {
/* fd might be invalid on Windows
* I can't raise an exception here. It may lead to an
* unlimited recursion in the case stderr is invalid.
*/
Py_RETURN_NONE;
}
if (!PyArg_ParseTuple(args, "s", &c)) {
return NULL;
}
n = strlen(c);
Py_BEGIN_ALLOW_THREADS
errno = 0;
#if defined(MS_WIN64) || defined(MS_WINDOWS)
if (n > INT_MAX)
n = INT_MAX;
n = write(self->fd, c, (int)n);
#else
n = write(self->fd, c, n);
#endif
Py_END_ALLOW_THREADS
if (n < 0) {
if (errno == EAGAIN)
Py_RETURN_NONE;
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
return PyLong_FromSsize_t(n);
}
示例13: PyCField_get_size
static PyObject *
PyCField_get_size(PyObject *self, void *data)
{
return PyLong_FromSsize_t(((CFieldObject *)self)->size);
}
示例14: meth_inspect
//.........这里部分代码省略.........
dict_add_obj(res, "self", obj);
dict_add_obj(res, "wrapper", renderbuffer->wrapper);
dict_add_obj(res, "context", (PyObject *)renderbuffer->context);
dict_add_int(res, "renderbuffer_obj", renderbuffer->renderbuffer_obj);
dict_add_int(res, "width", renderbuffer->width);
dict_add_int(res, "height", renderbuffer->height);
dict_add_int(res, "depth", renderbuffer->depth);
dict_add_int(res, "components", renderbuffer->components);
dict_add_int(res, "levels", renderbuffer->levels);
dict_add_int(res, "samples", renderbuffer->samples);
return res;
}
if (Py_TYPE(mglo) == mglo->context->MGLSampler_class) {
MGLSampler * sampler = (MGLSampler *)obj;
PyObject * res = PyDict_New();
dict_add_obj(res, "self", obj);
dict_add_obj(res, "wrapper", sampler->wrapper);
dict_add_obj(res, "context", (PyObject *)sampler->context);
dict_add_int(res, "sampler_obj", sampler->sampler_obj);
return res;
}
if (Py_TYPE(mglo) == mglo->context->MGLScope_class) {
MGLScope * scope = (MGLScope *)obj;
PyObject * res = PyDict_New();
dict_add_obj(res, "self", obj);
dict_add_obj(res, "wrapper", scope->wrapper);
dict_add_obj(res, "context", (PyObject *)scope->context);
dict_add_obj(res, "framebuffer", (PyObject *)scope->framebuffer);
dict_add_obj(res, "old_framebuffer", (PyObject *)scope->old_framebuffer);
dict_add_int(res, "num_samplers", scope->num_samplers);
dict_add_int(res, "num_buffers", scope->num_buffers);
dict_add_int(res, "enable_only", scope->enable_only);
dict_add_int(res, "old_enable_only", scope->old_enable_only);
PyObject * bindings = PyTuple_New(2);
PyObject * bindings_samplers = PyTuple_New(scope->num_samplers);
PyObject * bindings_buffers = PyTuple_New(scope->num_buffers);
for (int i = 0; i < scope->num_samplers; ++i) {
PyObject * obj = PyDict_New();
PyTuple_SET_ITEM(bindings_samplers, 0, obj);
PyDict_SetItemString(obj, "sampler", scope->samplers[i].object);
PyObject * binding = PyLong_FromLong(scope->samplers[i].binding);
PyDict_SetItemString(obj, "binding", binding);
Py_DECREF(binding);
}
for (int i = 0; i < scope->num_buffers; ++i) {
PyObject * obj = PyDict_New();
PyDict_SetItemString(obj, "buffer", scope->buffers[i].object);
PyObject * target = PyLong_FromLong(scope->buffers[i].target);
PyDict_SetItemString(obj, "target", target);
Py_DECREF(target);
PyObject * binding = PyLong_FromLong(scope->buffers[i].binding);
PyDict_SetItemString(obj, "binding", binding);
Py_DECREF(binding);
PyObject * offset = PyLong_FromSsize_t(scope->buffers[i].offset);
PyDict_SetItemString(obj, "offset", offset);
Py_DECREF(offset);
PyObject * size = PyLong_FromSsize_t(scope->buffers[i].size);
PyDict_SetItemString(obj, "size", size);
Py_DECREF(size);
}
PyTuple_SET_ITEM(bindings, 0, bindings_samplers);
PyTuple_SET_ITEM(bindings, 1, bindings_buffers);
dict_add_obj_decref(res, "bindings", bindings);
return res;
}
if (Py_TYPE(mglo) == mglo->context->MGLTexture_class) {
MGLTexture * texture = (MGLTexture *)obj;
PyObject * res = PyDict_New();
dict_add_obj(res, "self", obj);
dict_add_obj(res, "wrapper", texture->wrapper);
dict_add_obj(res, "context", (PyObject *)texture->context);
dict_add_int(res, "texture_obj", texture->texture_obj);
dict_add_int(res, "texture_target", texture->texture_target);
dict_add_int(res, "width", texture->width);
dict_add_int(res, "height", texture->height);
dict_add_int(res, "depth", texture->depth);
dict_add_int(res, "components", texture->components);
dict_add_int(res, "levels", texture->levels);
dict_add_int(res, "samples", texture->samples);
return res;
}
if (Py_TYPE(mglo) == mglo->context->MGLVertexArray_class) {
MGLVertexArray * vertex_array = (MGLVertexArray *)obj;
PyObject * res = PyDict_New();
dict_add_obj(res, "self", obj);
dict_add_obj(res, "wrapper", vertex_array->wrapper);
dict_add_obj(res, "context", (PyObject *)vertex_array->context);
dict_add_int(res, "vertex_array_obj", vertex_array->vertex_array_obj);
dict_add_int(res, "max_vertices", vertex_array->max_vertices);
return res;
}
}
return 0;
}
示例15: dict_add_ssizet
inline void dict_add_ssizet(PyObject * dict, const char * key, Py_ssize_t value) {
PyObject * item = PyLong_FromSsize_t(value);
PyDict_SetItemString(dict, key, item);
Py_DECREF(item);
}