本文整理汇总了C++中PyLong_FromSsize_t函数的典型用法代码示例。如果您正苦于以下问题:C++ PyLong_FromSsize_t函数的具体用法?C++ PyLong_FromSsize_t怎么用?C++ PyLong_FromSsize_t使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyLong_FromSsize_t函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Anugrahaa,项目名称:anagrammatic,代码行数:14,代码来源:newbuffer.c
示例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);
}
开发者ID:Illirgway,项目名称:cpython,代码行数:14,代码来源:frameobject.c
示例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);
}
}
开发者ID:Daetalus,项目名称:cpython,代码行数:50,代码来源:mmapmodule.c
示例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);
}
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:15,代码来源:iterobject.c
示例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);
}
开发者ID:IgnusIndia,项目名称:pythonexperiment,代码行数:15,代码来源:tupleobject.c
示例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);
}
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:15,代码来源:codeobject.c
示例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);
}
}
开发者ID:Victor-Savu,项目名称:cpython,代码行数:16,代码来源:rangeobject.c
示例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);
}
开发者ID:524777134,项目名称:cpython,代码行数:17,代码来源:_bisectmodule.c
示例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);
}
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:20,代码来源:iterobject.c
示例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;
}
开发者ID:vanangamudi,项目名称:blender-main,代码行数:21,代码来源:bpy_rna_array.c
示例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;
}
开发者ID:BeeRad-Johnson,项目名称:scipy-refactor,代码行数:40,代码来源:nd_image.c
示例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);
}
开发者ID:Jimlan,项目名称:kbengine,代码行数:39,代码来源:fileobject.c
示例13: PyCField_get_size
static PyObject *
PyCField_get_size(PyObject *self, void *data)
{
return PyLong_FromSsize_t(((CFieldObject *)self)->size);
}
开发者ID:pombredanne,项目名称:cpython,代码行数:5,代码来源:cfield.c
示例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;
}
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:101,代码来源:inspect.cpp
示例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);
}
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:5,代码来源:inspect.cpp
示例16: PyMember_GetOne
PyObject *
PyMember_GetOne(const char *addr, PyMemberDef *l)
{
PyObject *v;
addr += l->offset;
switch (l->type) {
case T_BOOL:
v = PyBool_FromLong(*(char*)addr);
break;
case T_BYTE:
v = PyLong_FromLong(*(char*)addr);
break;
case T_UBYTE:
v = PyLong_FromUnsignedLong(*(unsigned char*)addr);
break;
case T_SHORT:
v = PyLong_FromLong(*(short*)addr);
break;
case T_USHORT:
v = PyLong_FromUnsignedLong(*(unsigned short*)addr);
break;
case T_INT:
v = PyLong_FromLong(*(int*)addr);
break;
case T_UINT:
v = PyLong_FromUnsignedLong(*(unsigned int*)addr);
break;
case T_LONG:
v = PyLong_FromLong(*(long*)addr);
break;
case T_ULONG:
v = PyLong_FromUnsignedLong(*(unsigned long*)addr);
break;
case T_PYSSIZET:
v = PyLong_FromSsize_t(*(Py_ssize_t*)addr);
break;
case T_FLOAT:
v = PyFloat_FromDouble((double)*(float*)addr);
break;
case T_DOUBLE:
v = PyFloat_FromDouble(*(double*)addr);
break;
case T_STRING:
if (*(char**)addr == NULL) {
Py_INCREF(Py_None);
v = Py_None;
}
else
v = PyUnicode_FromString(*(char**)addr);
break;
case T_STRING_INPLACE:
v = PyUnicode_FromString((char*)addr);
break;
case T_CHAR:
v = PyUnicode_FromStringAndSize((char*)addr, 1);
break;
case T_OBJECT:
v = *(PyObject **)addr;
if (v == NULL)
v = Py_None;
Py_INCREF(v);
break;
case T_OBJECT_EX:
v = *(PyObject **)addr;
if (v == NULL)
PyErr_SetString(PyExc_AttributeError, l->name);
Py_XINCREF(v);
break;
#ifdef HAVE_LONG_LONG
case T_LONGLONG:
v = PyLong_FromLongLong(*(PY_LONG_LONG *)addr);
break;
case T_ULONGLONG:
v = PyLong_FromUnsignedLongLong(*(unsigned PY_LONG_LONG *)addr);
break;
#endif /* HAVE_LONG_LONG */
case T_NONE:
v = Py_None;
Py_INCREF(v);
break;
default:
PyErr_SetString(PyExc_SystemError, "bad memberdescr type");
v = NULL;
}
return v;
}
开发者ID:10sr,项目名称:cpython,代码行数:87,代码来源:structmember.c
示例17: memorysimpleview_itemsize_get
static PyObject *
memorysimpleview_itemsize_get(PyMemorySimpleViewObject *self)
{
return PyLong_FromSsize_t(self->view.itemsize);
}
开发者ID:Eothred,项目名称:jpype,代码行数:5,代码来源:jpype_memory_view.c
示例18: _new_long_object
static PyObject *
_new_long_object(_PyCrossInterpreterData *data)
{
return PyLong_FromSsize_t((Py_ssize_t)(data->data));
}
开发者ID:tiran,项目名称:cpython,代码行数:5,代码来源:pystate.c
注:本文中的PyLong_FromSsize_t函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论