本文整理汇总了C++中PySequence_Fast_GET_SIZE函数的典型用法代码示例。如果您正苦于以下问题:C++ PySequence_Fast_GET_SIZE函数的具体用法?C++ PySequence_Fast_GET_SIZE怎么用?C++ PySequence_Fast_GET_SIZE使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PySequence_Fast_GET_SIZE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _NonPyObjectUniqueSorterIncer
_NonPyObjectUniqueSorterIncer(PyObject * fast_seq)
{
if (fast_seq == Py_None)
return;
vals.reserve(PySequence_Fast_GET_SIZE(fast_seq));
for (size_t i = 0; i < static_cast<size_t>(PySequence_Fast_GET_SIZE(fast_seq)); ++i) {
PyObject * const val = PySequence_Fast_GET_ITEM(fast_seq, i);
DBG_ASSERT(PyTuple_Check(val));
DBG_ASSERT(PyTuple_Size(val) == 2);
PyObject * const key = PyTuple_GET_ITEM(val, 0);
BANYAN_PYOBJECT_INCREF(key);
vals.push_back(std::make_pair(
std::make_pair(
_KeyFactory<Key_Type>::convert(key),
key),
PyTuple_GET_ITEM(val, 1)));
}
_FirstLT<_FirstLT<std::less<Key_Type> > > lt;
std::sort(vals.begin(), vals.end(), lt);
vals.erase(unique(vals.begin(), vals.end(), not2(lt)), vals.end());
for (size_t i = 0; i < vals.size(); ++i)
BANYAN_PYOBJECT_INCREF(vals[i].second);
}
示例2: references
/*
This symbol filters its children through a python function... where anything is possible.
functions are generated differently than other symbols:
- each arg is generated into the output, but the start/end of each arg is recorded for later
- after references (@symbols) are resolved, then all the functions can be called
- function output replaces the args in the output (may be bigger or smaller than arg length)
- function args may contain other function calls, so when function return replaces it's args,
need to check if this falls within the range of another function arg, and if so repair the range
*/
static int
_generate_function(PyObject *s, void *g)
{
PyObject *res, *l;
int status, i, func_cookie, has_ref, defer_depth;
int *args, nargs;
// generate arg values
l = PySequence_Fast(SYMOBJ(s)->data.func.args, "Error enumerating function args");
if (!l)
return -1;
nargs = PySequence_Fast_GET_SIZE(l);
args = (int *)malloc(sizeof(int) * (nargs + 1));
if (!args) {
Py_DECREF(l);
PyErr_NoMemory();
return -1;
}
args[0] = gen_state_tell(g);
func_cookie = gen_state_enter_function(g);
defer_depth = ((gen_state_t *)g)->nfuncs;
for (i = 0; i < PySequence_Fast_GET_SIZE(l); i++) {
status = _generate(SYMOBJ(PySequence_Fast_GET_ITEM(l, i)), g);
if (status) {
Py_DECREF(l);
free(args);
return -1;
}
args[i+1] = gen_state_tell(g); // mark end of this arg
}
Py_DECREF(l);
has_ref = gen_state_leave_function(g, func_cookie);
if (has_ref) {
// function call must be deferred until after references are generated
return gen_state_defer_function(g, s, nargs, args, defer_depth);
} else {
// call function now
const char *strres;
res = call_func_now(s, g, nargs, args);
gen_state_backtrack(g, args[0]);
free(args);
if (!res)
return -1;
strres = PyBytes_AsString(res);
if (!strres) {
Py_DECREF(res);
return -1;
}
status = gen_state_write((gen_state_t *)g, strres, PyBytes_GET_SIZE(res));
Py_DECREF(res);
return status;
}
}
示例3: pycairo_set_dash
static PyObject *
pycairo_set_dash (PycairoContext *o, PyObject *args) {
double *dashes, offset = 0;
int num_dashes, i;
PyObject *py_dashes;
if (!PyArg_ParseTuple (args, "O|d:Context.set_dash", &py_dashes, &offset))
return NULL;
py_dashes = PySequence_Fast (py_dashes,
"first argument must be a sequence");
if (py_dashes == NULL)
return NULL;
num_dashes = PySequence_Fast_GET_SIZE(py_dashes);
dashes = PyMem_Malloc (num_dashes * sizeof(double));
if (dashes == NULL) {
Py_DECREF(py_dashes);
return PyErr_NoMemory();
}
for (i = 0; i < num_dashes; i++) {
dashes[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(py_dashes, i));
if (PyErr_Occurred()) {
PyMem_Free (dashes);
Py_DECREF(py_dashes);
return NULL;
}
}
cairo_set_dash (o->ctx, dashes, num_dashes, offset);
PyMem_Free (dashes);
Py_DECREF(py_dashes);
RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
Py_RETURN_NONE;
}
示例4: PositionWeightMatrix_scoreAll
static PyObject* PositionWeightMatrix_scoreAll( PositionWeightMatrix* self, PyObject* args )
{
PyObject* seq = parseTupleToFastSequence( args );
if( !seq ) return NULL;
double** matrix = self -> matrix;
int n = self -> n;
int m = self -> m;
int len = PySequence_Fast_GET_SIZE( seq );
//check that length is correct
if( n > len )
{
//TODO raise error
return NULL;
}
PyObject** elems = PySequence_Fast_ITEMS( seq );
//create new python list and fill it with the scores at each position
int end = len - n + 1;
PyObject* list = PyList_New( end );
int i;
for( i = 0 ; i < end ; ++i )
{
PyList_SetItem( list, i, PyFloat_FromDouble( scoreFromIndex( matrix, n, m, elems, i ) ) );
}
return list;
}
示例5: PySequence_Fast
/*
* Callback function which is exposed as a part of the additional methods which allow
* a Python plugin to issue a Register Event to register additional events it wants
* to receive.
*/
static PyObject *PyBareosRegisterEvents(PyObject *self, PyObject *args)
{
int len, event;
bpContext *ctx;
PyObject *pyCtx, *pyEvents, *pySeq, *pyEvent;
if (!PyArg_ParseTuple(args, "OO:BareosRegisterEvents", &pyCtx, &pyEvents)) {
return NULL;
}
pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events");
if (!pySeq) {
return NULL;
}
len = PySequence_Fast_GET_SIZE(pySeq);
ctx = PyGetbpContext(pyCtx);
for (int i = 0; i < len; i++) {
pyEvent = PySequence_Fast_GET_ITEM(pySeq, i);
event = PyInt_AsLong(pyEvent);
if (event >= bDirEventJobStart && event <= bDirEventGetScratch) {
Dmsg(ctx, dbglvl, "PyBareosRegisterEvents: registering event %d\n", event);
bfuncs->registerBareosEvents(ctx, 1, event);
}
}
Py_DECREF(pySeq);
Py_INCREF(Py_None);
return Py_None;
}
示例6: pathlist_new
static PyObject* pathlist_new(PyTypeObject* pytype, PyObject* args,
PyObject* kwds) {
PyObject* py_arg = 0;
if (PyArg_ParseTuple(args, "|O", &py_arg) <= 0)
return 0;
boost::shared_ptr<PathList> p(new PathList());
if (py_arg != 0) {
PyObject* seq = PySequence_Fast(py_arg, "Argument must be a sequence of Path objects.");
if (seq == 0)
return 0;
int size = PySequence_Fast_GET_SIZE(seq);
for (int i = 0; i < size; ++i) {
PyObject* py_path = PySequence_Fast_GET_ITEM(seq, i);
if (!is_PathObject(py_path)) {
PyErr_SetString(PyExc_TypeError, "Argument must be a sequence of Path objects.");
Py_DECREF(seq);
return 0;
}
p->push_back(((PathObject*)py_path)->m_x);
}
}
PathListObject* so;
so = (PathListObject*)pytype->tp_alloc(pytype, 0);
so->m_x = p;
return (PyObject*)so;
}
示例7: pygdk_atom_vector_from_sequence
GdkAtom*
pygdk_atom_vector_from_sequence(PyObject *py_targets, gint *n_targets)
{
gint i;
GdkAtom *targets;
if (!(py_targets = PySequence_Fast(py_targets,
"targets must be a sequence")))
return NULL;
*n_targets = PySequence_Fast_GET_SIZE(py_targets);
targets = g_new(GdkAtom, *n_targets);
for (i = 0; i < *n_targets; i++) {
PyObject *trgt = PySequence_Fast_GET_ITEM(py_targets, i);
targets[i] = pygdk_atom_from_pyobject(trgt);
if (PyErr_Occurred()) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,
"each 'targets' item must be a GdkAtom or string");
g_free(targets);
Py_DECREF(py_targets);
return NULL;
}
}
Py_DECREF(py_targets);
return targets;
}
示例8: pygtk_target_list_from_sequence
GtkTargetList *
pygtk_target_list_from_sequence(PyObject *py_targets)
{
gint n_targets, i;
GtkTargetEntry *targets;
GtkTargetList *target_list;
if (!(py_targets = PySequence_Fast(py_targets,
"target list must be a sequence")))
return NULL;
n_targets = PySequence_Fast_GET_SIZE(py_targets);
targets = g_new(GtkTargetEntry, n_targets);
for (i = 0; i < n_targets; i++) {
PyObject *item = PySequence_Fast_GET_ITEM(py_targets, i);
if (!PyArg_ParseTuple(item, "sii", &targets[i].target,
&targets[i].flags, &targets[i].info)) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,
"target list items should be of form (string,int,int)");
g_free(targets);
Py_DECREF(py_targets);
return NULL;
}
}
target_list = gtk_target_list_new(targets, n_targets);
g_free(targets);
Py_DECREF(py_targets);
return target_list;
}
示例9: py_array_from_obj
int py_array_from_obj(PyObject *obj, float *arr) {
PyObject *seqdata = NULL;
PyObject *elem;
int i;
if (!(seqdata = PySequence_Fast(obj, "Coordinate argument must be a sequence")))
goto failure;
if (PySequence_Fast_GET_SIZE(seqdata) != 3) {
PyErr_SetString(PyExc_ValueError, "Coordinate must have length 3");
goto failure;
}
for (i = 0; i < 3; i++) {
elem = PySequence_Fast_GET_ITEM(seqdata, i);
arr[i] = PyFloat_AsDouble(elem);
if (PyErr_Occurred()) {
PyErr_SetString(PyExc_ValueError, "Problem unpacking coordinate");
goto failure;
}
}
return 1; // successful return
failure:
Py_XDECREF(seqdata);
return 0;
}
示例10: pycairo_set_dash
static PyObject *
pycairo_set_dash (PycairoContext *o, PyObject *args)
{
double *dashes, offset = 0;
int ndash, i;
PyObject *py_dashes;
if (!PyArg_ParseTuple (args, "O|d:Context.set_dash", &py_dashes, &offset))
return NULL;
py_dashes = PySequence_Fast (py_dashes,
"first argument must be a sequence");
if (!py_dashes)
return NULL;
ndash = PySequence_Fast_GET_SIZE(py_dashes);
dashes = malloc (ndash * sizeof(double));
for (i = 0; i < ndash; i++) {
PyObject *item = PySequence_Fast_GET_ITEM(py_dashes, i);
dashes[i] = PyFloat_AsDouble(item);
if (PyErr_Occurred()) {
free (dashes);
Py_DECREF(py_dashes);
return NULL;
}
}
Py_DECREF(py_dashes);
cairo_set_dash (o->ctx, dashes, ndash, offset);
free (dashes);
if (Pycairo_Check_Status (cairo_status (o->ctx)))
return NULL;
Py_RETURN_NONE;
}
示例11: ImageViewport_setCaptureSize
// set capture size
int ImageViewport_setCaptureSize(PyImage *self, PyObject *value, void *closure)
{
// check validity of parameter
if (value == NULL ||
!(PyTuple_Check(value) || PyList_Check(value)) ||
PySequence_Fast_GET_SIZE(value) != 2 ||
!PyLong_Check(PySequence_Fast_GET_ITEM(value, 0)) ||
!PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)))
{
PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 2 ints");
return -1;
}
// set capture size
short size[2] = {
short(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 0))),
short(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 1)))
};
try
{
// can throw in case of resize and buffer exports
getImageViewport(self)->setCaptureSize(size);
}
catch (Exception & exp)
{
exp.report();
return -1;
}
// success
return 0;
}
示例12: mathutils_array_parse_alloc_v
/* parse an array of vectors */
int mathutils_array_parse_alloc_v(float **array, int array_dim, PyObject *value, const char *error_prefix)
{
PyObject *value_fast = NULL;
int i, size;
/* non list/tuple cases */
if (!(value_fast = PySequence_Fast(value, error_prefix))) {
/* PySequence_Fast sets the error */
return -1;
}
size = PySequence_Fast_GET_SIZE(value_fast);
if (size != 0) {
float *fp;
fp = *array = PyMem_Malloc(size * array_dim * sizeof(float));
for (i = 0; i < size; i++, fp += array_dim) {
PyObject *item = PySequence_Fast_GET_ITEM(value, i);
if (mathutils_array_parse(fp, array_dim, array_dim, item, error_prefix) == -1) {
PyMem_Free(*array);
*array = NULL;
size = -1;
break;
}
}
}
Py_DECREF(value_fast);
return size;
}
示例13: sequenceToIntArray
int* sequenceToIntArray(PyObject* obj, bool zeroTerminated)
{
AutoDecRef seq(PySequence_Fast(obj, "Sequence of ints expected"));
if (seq.isNull())
return 0;
Py_ssize_t size = PySequence_Fast_GET_SIZE(seq.object());
int* array = new int[size + (zeroTerminated ? 1 : 0)];
for (int i = 0; i < size; i++) {
PyObject* item = PySequence_Fast_GET_ITEM(seq.object(), i);
if (!PyInt_Check(item)) {
PyErr_SetString(PyExc_TypeError, "Sequence of ints expected");
delete[] array;
return 0;
} else {
array[i] = PyInt_AsLong(item);
}
}
if (zeroTerminated)
array[size] = 0;
return array;
}
示例14: IntVector_from_python
inline IntVector* IntVector_from_python(PyObject* py) {
PyObject* seq = PySequence_Fast(py, "Argument must be a sequence of ints.");
if (seq == NULL)
return 0;
int size = PySequence_Fast_GET_SIZE(seq);
IntVector* cpp = new IntVector(size);
try {
for (int i = 0; i < size; ++i) {
PyObject* number = PySequence_Fast_GET_ITEM(seq, i);
if (!PyInt_Check(number)) {
PyErr_SetString(PyExc_TypeError,
"Argument must be a sequence of ints.");
delete cpp;
Py_DECREF(seq);
return 0;
}
(*cpp)[i] = (int)PyInt_AsLong(number);
}
} catch (std::exception e) {
delete cpp;
Py_DECREF(seq);
PyErr_SetString(PyExc_RuntimeError, e.what());
return 0;
}
Py_DECREF(seq);
return cpp;
}
示例15: convert_seq
static PyObject*
convert_seq(PyObject *ob, convert_func convert_string)
{
PyObject *seq = PySequence_Fast(ob, "ob is not a sequence");
if (seq == NULL) {
return NULL;
}
Py_ssize_t i = 0;
Py_ssize_t seq_len = PySequence_Fast_GET_SIZE(seq);
PyObject **items = PySequence_Fast_ITEMS(seq);
for (i=0; i < seq_len; ++i) {
PyObject *old_item = items[i];
PyObject *new_item = convert_nested(old_item, convert_string);
if (new_item == NULL) {
Py_DECREF(seq);
return NULL;
}
items[i] = new_item;
Py_DECREF(old_item);
}
return seq;
}