本文整理汇总了C++中PySequence_Size函数的典型用法代码示例。如果您正苦于以下问题:C++ PySequence_Size函数的具体用法?C++ PySequence_Size怎么用?C++ PySequence_Size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PySequence_Size函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: convert_dashes
int convert_dashes(PyObject *dashobj, void *dashesp)
{
Dashes *dashes = (Dashes *)dashesp;
if (dashobj == NULL && dashobj == Py_None) {
return 1;
}
PyObject *dash_offset_obj = NULL;
double dash_offset = 0.0;
PyObject *dashes_seq = NULL;
Py_ssize_t nentries;
if (!PyArg_ParseTuple(dashobj, "OO:dashes", &dash_offset_obj, &dashes_seq)) {
return 0;
}
if (dash_offset_obj != Py_None) {
dash_offset = PyFloat_AsDouble(dash_offset_obj);
if (PyErr_Occurred()) {
return 0;
}
}
if (dashes_seq == Py_None) {
return 1;
}
if (!PySequence_Check(dashes_seq)) {
PyErr_SetString(PyExc_TypeError, "Invalid dashes sequence");
return 0;
}
nentries = PySequence_Size(dashes_seq);
if (nentries % 2 != 0) {
PyErr_Format(PyExc_ValueError, "dashes sequence must have an even number of elements");
return 0;
}
for (Py_ssize_t i = 0; i < nentries; ++i) {
PyObject *item;
double length;
double skip;
item = PySequence_GetItem(dashes_seq, i);
if (item == NULL) {
return 0;
}
length = PyFloat_AsDouble(item);
if (PyErr_Occurred()) {
Py_DECREF(item);
return 0;
}
Py_DECREF(item);
++i;
item = PySequence_GetItem(dashes_seq, i);
if (item == NULL) {
return 0;
}
skip = PyFloat_AsDouble(item);
if (PyErr_Occurred()) {
Py_DECREF(item);
return 0;
}
Py_DECREF(item);
dashes->add_dash_pair(length, skip);
}
dashes->set_dash_offset(dash_offset);
return 1;
}
开发者ID:earlhansen,项目名称:matplotlib,代码行数:75,代码来源:py_converters.cpp
示例2: Poly_create_new
static polypaths_planar_overridePolygonObject *
Poly_create_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
PyObject *verts_arg, *is_convex_arg = NULL, *is_simple_arg = NULL;
PyObject *verts_seq = NULL;
polypaths_planar_overridePolygonObject *poly = NULL;
Py_ssize_t size, i;
static char *kwlist[] = {"vertices", "is_convex", "is_simple", NULL};
if (!PyArg_ParseTupleAndKeywords(
args, kwargs, "O|OO:Polygon.__init__", kwlist,
&verts_arg, &is_convex_arg, &is_simple_arg)) {
return NULL;
}
if (!PySequence_Check(verts_arg)) {
verts_arg = verts_seq = PySequence_Fast(verts_arg,
"expected iterable of Vec2 objects");
if (verts_seq == NULL) {
goto error;
}
}
size = PySequence_Size(verts_arg);
if (size == -1) {
goto error;
}
poly = Poly_new(type, size);
if (poly == NULL) {
goto error;
}
if ((is_convex_arg != NULL && PyObject_IsTrue(is_convex_arg) > 0)
|| size == 3) {
poly->flags = (POLY_CONVEX_FLAG | POLY_CONVEX_KNOWN_FLAG
| POLY_SIMPLE_FLAG | POLY_SIMPLE_KNOWN_FLAG);
} else if (is_simple_arg != NULL && PyObject_IsTrue(is_simple_arg) > 0) {
poly->flags = POLY_SIMPLE_FLAG | POLY_SIMPLE_KNOWN_FLAG;
}
if (polypaths_planar_overrideSeq2_Check(verts_arg)) {
/* Copy existing Seq2 (optimized) */
memcpy(poly->vert, ((polypaths_planar_overrideSeq2Object *)verts_arg)->vec,
sizeof(polypaths_planar_override_vec2_t) * size);
} else {
/* Generic iterable of points */
for (i = 0; i < size; ++i) {
if (!polypaths_planar_overrideVec2_Parse(PySequence_Fast_GET_ITEM(verts_arg, i),
&poly->vert[i].x, &poly->vert[i].y)) {
PyErr_SetString(PyExc_TypeError,
"expected iterable of Vec2 objects");
goto error;
}
}
}
Py_XDECREF(verts_seq);
return poly;
error:
Py_XDECREF(verts_seq);
Py_XDECREF(poly);
return NULL;
}
开发者ID:apolcyn,项目名称:polypaths_planar_override,代码行数:61,代码来源:cpolygon.c
示例3: setTranslationAxis
void PyLink::setTranslationAxis(PyObject *v)
{
if (PySequence_Size(v) != 3) return;
PyListToVector(v, d);
}
开发者ID:Isaac-Gray,项目名称:hrpsys-base,代码行数:5,代码来源:PyLink.cpp
示例4: PyErr_SetString
void TileEngine::renderTilesLazy(
cairo_t *ctx,
PyObject *tileFunction,
PyObject *tileMap,
int tileSize,
int renderCol,
int renderRow,
int renderCols,
int renderRows,
double alpha,
PyObject *tileGenerator,
PyObject *tileCache,
PyObject *tileCacheSurfaces,
PyObject *tileState)
{
if ((tileFunction != Py_None) &&
!PyCallable_Check(tileFunction)) {
PyErr_SetString(
PyExc_TypeError,
"expected tileFunction to be a callable function or None");
return;
}
// The tileMap should be None, or an array of 4 byte integers,
// mapping virtual tiles indices to absolute tile numbers.
const int *tileMapData = NULL;
unsigned int tileMapCount = 0;
if (tileMap != Py_None) {
if (!PySequence_Check(tileMap)) {
PyErr_SetString(
PyExc_TypeError,
"expected tileMap to be an array "
"of 4 byte integers or None");
return;
}
tileMapCount = (unsigned int)PySequence_Size(tileMap);
Py_ssize_t tileMapLength = 0;
if (PyObject_AsReadBuffer(
tileMap,
(const void **)&tileMapData,
&tileMapLength) != 0) {
PyErr_SetString(
PyExc_TypeError,
"expected tileMap with read buffer");
return;
}
int tileMapDataCount =
(int)tileMapLength / sizeof(unsigned int);
if (tileMapDataCount != (int)tileMapCount) {
PyErr_SetString(
PyExc_TypeError,
"expected tileMap read buffer of 4 byte integers");
return;
}
}
// The tileGenerator should be a function that takes one integer
// tile parameter, and returns a tuple of three integers: a
// surface index, a tileX and a tileY position.
if (!PyCallable_Check(tileGenerator)) {
PyErr_SetString(
PyExc_TypeError,
"expected tileGenerator callable object");
return;
}
// The tileCache should be an array of integers, 4 integers per
// tile. The first is a "cached" flag, the second is a surface
// index, the 3rd and 4th are a tileX and tileY position.
int *tileCacheData = NULL;
Py_ssize_t tileCacheLength = 0;
if (PyObject_AsWriteBuffer(
tileCache,
(void **)&tileCacheData,
&tileCacheLength) != 0) {
PyErr_SetString(
PyExc_TypeError,
"expected tileCache array");
return;
}
// The tileCacheSurfaces parameters should be a list of Cairo
// surfaces.
if (!PySequence_Check(tileCacheSurfaces)) {
PyErr_SetString(
PyExc_TypeError,
"expected tileCacheSurfaces sequence");
return;
}
// The tileState parameters should be None or a list of tile state
// parameters.
//.........这里部分代码省略.........
开发者ID:DaveInKentucky,项目名称:micropolis,代码行数:101,代码来源:tileengine.cpp
示例5: set_str_list
int
set_str_list(
const char* propname,
PyObject* value,
Py_ssize_t len,
Py_ssize_t maxlen,
char (*dest)[72]) {
PyObject* str = NULL;
Py_ssize_t input_len;
Py_ssize_t i = 0;
if (check_delete(propname, value)) {
return -1;
}
if (maxlen == 0) {
maxlen = 68;
}
if (!PySequence_Check(value)) {
PyErr_Format(
PyExc_TypeError,
"'%s' must be a sequence of strings",
propname);
return -1;
}
if (PySequence_Size(value) != len) {
PyErr_Format(
PyExc_ValueError,
"len(%s) must be %u",
propname,
(unsigned int)len);
return -1;
}
/* We go through the list twice, once to verify that the list is
in the correct format, and then again to do the data copy. This
way, we won't partially copy the contents and then throw an
exception. */
for (i = 0; i < len; ++i) {
str = PySequence_GetItem(value, i);
if (str == NULL) {
return -1;
}
if (!(PyBytes_CheckExact(str) || PyUnicode_CheckExact(str))) {
PyErr_Format(
PyExc_TypeError,
"'%s' must be a sequence of bytes or strings",
propname);
Py_DECREF(str);
return -1;
}
input_len = PySequence_Size(str);
if (input_len > maxlen) {
PyErr_Format(
PyExc_TypeError,
"Each entry in '%s' must be less than %u characters",
propname, (unsigned int)maxlen);
Py_DECREF(str);
return -1;
} else if (input_len == -1) {
Py_DECREF(str);
return -1;
}
Py_DECREF(str);
}
for (i = 0; i < len; ++i) {
str = PySequence_GetItem(value, i);
if (str == NULL) {
/* Theoretically, something has gone really wrong here, since
we've already verified the list. */
PyErr_Clear();
PyErr_Format(
PyExc_RuntimeError,
"Input values have changed underneath us. Something is seriously wrong.");
return -1;
}
if (set_string(propname, str, dest[i], maxlen)) {
PyErr_Clear();
PyErr_Format(
PyExc_RuntimeError,
"Input values have changed underneath us. Something is seriously wrong.");
Py_DECREF(str);
return -1;
}
Py_DECREF(str);
}
return 0;
}
开发者ID:5Zhiyong,项目名称:astropy,代码行数:98,代码来源:pyutil.c
示例6: parse_calibration_data
/**
* Parses calibration data. The calibration data should be in the form of a
* sequence of sequences. eg:
* [
* [ xs, ys, zs, xi, yi ], ...
* ]
* where (xs, ys, zs) are the coordinates of a point in 3D space, and (xi, yi)
* are the coordinates of the corresponding point in an image.
*
* If the method fails, it returns NULL and raises an appropriate exception.
* On success, a flat array of doubles will be PyMem_Malloc()'d and filled
* with the calibration data:
* { xs1, ys1, zs1, xi1, yi1, xs2, ys2, zs2, xi2, yi2, ... }
* size will be populated with the number of calibration points.
*/
static double* parse_calibration_data(PyObject *pyobj, int *size)
{
PyObject *subseq = NULL, *sstuple = NULL;
int i = 0, ncoords = 0, index = 0;
double *array = NULL, xs, ys, zs, xi, yi;
/* check that pyobj is a sequence, and find out its size */
if (PySequence_Check(pyobj) == 0)
{
PyErr_SetString(PyExc_TypeError,
"First argument must be a sequence of coordinate " \
"sequences.");
return NULL;
}
ncoords = PySequence_Size(pyobj);
*size = ncoords;
/* allocate memory */
array = PyMem_Malloc(sizeof(double) * ncoords * 5);
if (array == NULL)
return NULL;
/* iterate over each sub-sequence within pyobj, performing appropriate
* checks and fetching data. */
for (i = 0; i < ncoords; i++)
{
subseq = PySequence_GetItem(pyobj, i);
if (PySequence_Check(subseq) == 0)
{
Py_DECREF(subseq);
PyMem_Free(array);
PyErr_SetString(PyExc_TypeError,
"First argument must be a sequence of " \
"coordinate sequences.");
return NULL;
}
sstuple = PySequence_Tuple(subseq);
Py_DECREF(subseq);
if (sstuple == NULL)
{
Py_DECREF(sstuple);
PyMem_Free(array);
PyErr_SetString(PyExc_TypeError,
"First argument must be a sequence of " \
"coordinate sequences.");
return NULL;
}
if (!PyArg_ParseTuple(sstuple, "ddddd", &xs, &ys, &zs,
&xi, &yi))
{
Py_DECREF(sstuple);
PyMem_Free(array);
PyErr_SetString(PyExc_TypeError,
"First argument's coordinate sequences must " \
"contain 5 elements each: [x,y,z,xi,yi]");
return NULL;
}
array[index++] = xs;
array[index++] = ys;
array[index++] = zs;
array[index++] = xi;
array[index++] = yi;
/* printf("xs = %f, ys = %f, zs = %f, xi = %f, yi = %f\n",
xs, ys, zs, xi, yi); */
Py_DECREF(sstuple);
}
return array;
}
开发者ID:Csega,项目名称:pyTsai,代码行数:88,代码来源:pytsai.c
示例7: MARS_88_run
static PyObject *
MARS_88_run(MARS_88 *self, PyObject *args, PyObject *kwds)
{
PyObject *warriors;
s32_t rounds = 1;
s32_t seed = time(0); /* some "random" value */
u32_t *result;
PyObject *res;
warrior_t *wlist;
/* Get and check arguments. */
static char *kwlist[] = {"warriors", "rounds", "seed", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ii", kwlist,
&warriors, &rounds, &seed)) {
return NULL;
}
if (PySequence_Check(warriors) == 0) {
PyErr_SetString(PyExc_ValueError, "List of warriors needed.");
return NULL;
}
if (PySequence_Size(warriors) != 2) {
PyErr_SetString(PyExc_ValueError,
"Exactly two warriors are needed "\
"to run a fight.");
return NULL;
}
if (rounds < 1) {
PyErr_SetString(PyExc_ValueError, "Invalid number of rounds.");
return NULL;
}
if (seed < 0) {
PyErr_SetString(PyExc_ValueError, "Invalid seed.");
return NULL;
}
if (seed < self->mindistance) {
PyErr_SetString(PyExc_ValueError, "Position of second "\
"warrior cannot be smaller than minimal "\
"warrior distance.");
return NULL;
}
/* Try to convert warriors into internal format. */
wlist = get_warriors88(warriors, 2, self->maxlength);
if (wlist == NULL) {
PyErr_SetString(PyExc_ValueError, "Couldn't load warriors.");
return NULL;
}
/* Run all fights. */
result = run_88(self->core, wlist, self->coresize, self->maxprocesses,
self->maxcycles, self->mindistance, rounds, seed);
/* Build results. */
res = Py_BuildValue("[[lll][lll]]", result[0], result[1], result[2],
result[1], result[0], result[2]);
if (res == NULL) {
free_warriors(wlist, 2);
free(result);
return NULL;
}
Py_INCREF(res);
/* Clean up. */
free_warriors(wlist, 2);
free(result);
return res;
}
开发者ID:ProgVal,项目名称:PyCorewar,代码行数:69,代码来源:Benchmarkingmodule.c
示例8: set_pvcards
int
set_pvcards(
/*@[email protected]*/ const char* propname,
PyObject* value,
struct pvcard** pv,
int *npv,
int *npvmax) {
PyObject* subvalue = NULL;
int i = 0;
Py_ssize_t size = 0;
int ival = 0;
int mval = 0;
double dblvalue = 0.0;
void* newmem = NULL;
if (!PySequence_Check(value)) {
return -1;
}
size = PySequence_Size(value);
if (size > 0x7fffffff) {
return -1;
}
if (size > (Py_ssize_t)*npvmax) {
newmem = malloc(sizeof(struct pvcard) * size);
if (newmem == NULL) {
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory.");
return -1;
}
free(*pv);
*pv = newmem;
*npvmax = (int)size;
}
/* Verify the entire list for correct types first, so we don't have
to undo anything copied into the canonical array. */
for (i = 0; i < size; ++i) {
subvalue = PySequence_GetItem(value, i);
if (subvalue == NULL) {
return -1;
}
if (!PyArg_ParseTuple(subvalue, "iid", &ival, &mval, &dblvalue)) {
Py_DECREF(subvalue);
return -1;
}
Py_DECREF(subvalue);
}
for (i = 0; i < size; ++i) {
subvalue = PySequence_GetItem(value, i);
if (subvalue == NULL) {
return -1;
}
if (!PyArg_ParseTuple(subvalue, "iid", &ival, &mval, &dblvalue)) {
Py_DECREF(subvalue);
return -1;
}
Py_DECREF(subvalue);
(*pv)[i].i = ival;
(*pv)[i].m = mval;
(*pv)[i].value = dblvalue;
(*npv) = i + 1;
}
return 0;
}
开发者ID:FairSky,项目名称:astropy,代码行数:68,代码来源:pyutil.c
示例9: pycbc_Connection__stats
PyObject *
pycbc_Connection__stats(pycbc_Connection *self,
PyObject *args,
PyObject *kwargs)
{
int rv;
int ii;
Py_ssize_t ncmds;
lcb_error_t err;
PyObject *keys = NULL;
PyObject *ret = NULL;
pycbc_MultiResult *mres = NULL;
struct pycbc_common_vars cv = PYCBC_COMMON_VARS_STATIC_INIT;
static char *kwlist[] = { "keys", NULL };
rv = PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, &keys);
if (!rv) {
PYCBC_EXCTHROW_ARGS();
return NULL;
}
if (keys == NULL || PyObject_IsTrue(keys) == 0) {
keys = NULL;
ncmds = 1;
} else {
if (!PySequence_Check(keys)) {
PYCBC_EXC_WRAP(PYCBC_EXC_ARGUMENTS, 0, "keys argument must be sequence");
return NULL;
}
ncmds = PySequence_Size(keys);
}
rv = pycbc_common_vars_init(&cv, ncmds, sizeof(lcb_server_stats_cmd_t), 0);
if (rv < 0) {
return NULL;
}
if (keys) {
for (ii =0; ii < ncmds; ii++) {
char *key;
Py_ssize_t nkey;
PyObject *newkey = NULL;
PyObject *curkey = PySequence_GetItem(keys, ii);
lcb_server_stats_cmd_t *cmd = cv.cmds.stats + ii;
rv = pycbc_BufFromString(curkey, &key, &nkey, &newkey);
if (rv < 0) {
PYCBC_EXC_WRAP_KEY(PYCBC_EXC_ARGUMENTS,
0,
"bad key type in stats",
curkey);
goto GT_DONE;
}
cmd->v.v0.name = key;
cmd->v.v0.nname = nkey;
cv.cmdlist.stats[ii] = cmd;
cv.enckeys[ii] = newkey;
}
} else {
cv.cmdlist.stats[0] = cv.cmds.stats;
}
mres = (pycbc_MultiResult*)pycbc_multiresult_new(self);
err = lcb_server_stats(self->instance, mres, ncmds, cv.cmdlist.stats);
if (err != LCB_SUCCESS) {
PYCBC_EXCTHROW_SCHED(err);
goto GT_DONE;
}
err = pycbc_oputil_wait_common(self);
if (err != LCB_SUCCESS) {
PYCBC_EXCTHROW_WAIT(err);
goto GT_DONE;
}
ret = (PyObject*)mres;
GT_DONE:
pycbc_common_vars_free(&cv);
/* Force multi, it's always a MultiResult */
pycbc_make_retval(PYCBC_ARGOPT_MULTI, &ret, &mres);
Py_XDECREF(mres);
return ret;
}
开发者ID:esplorio,项目名称:couchbase-python-client,代码行数:92,代码来源:miscops.c
示例10: set_str_list
int
set_str_list(
const char* propname,
PyObject* value,
Py_ssize_t len,
Py_ssize_t maxlen,
char (*dest)[72]) {
PyObject* str = NULL;
char* str_char = NULL;
Py_ssize_t str_len = 0;
Py_ssize_t i = 0;
if (check_delete(propname, value)) {
return -1;
}
if (maxlen == 0) {
maxlen = 68;
}
if (!PySequence_Check(value)) {
PyErr_Format(
PyExc_TypeError,
"'%s' must be a sequence of strings",
propname);
return -1;
}
if (PySequence_Size(value) != len) {
PyErr_Format(
PyExc_ValueError,
"len(%s) must be %u",
propname,
(unsigned int)len);
return -1;
}
/* We go through the list twice, once to verify that the list is
in the correct format, and then again to do the data copy. This
way, we won't partially copy the contents and then throw an
exception. */
for (i = 0; i < len; ++i) {
str = PySequence_GetItem(value, i);
if (str == NULL) {
return -1;
}
#if PY3K
if (!PyBytes_CheckExact(str)) {
#else
if (!PyString_CheckExact(str)) {
#endif
PyErr_Format(
PyExc_TypeError,
#if PY3K
"'%s' must be a sequence of bytes",
#else
"'%s' must be a sequence of strings",
#endif
propname);
Py_DECREF(str);
return -1;
}
#if PY3K
if (PyBytes_Size(str) > maxlen) {
#else
if (PyString_Size(str) > maxlen) {
#endif
PyErr_Format(
PyExc_TypeError,
#if PY3K
"Each bytes in '%s' must be less than %u characters",
#else
"Each string in '%s' must be less than %u characters",
#endif
propname, (unsigned int)maxlen);
Py_DECREF(str);
return -1;
}
Py_DECREF(str);
}
for (i = 0; i < len; ++i) {
str = PySequence_GetItem(value, i);
if (str == NULL) {
/* Theoretically, something has gone really wrong here, since
we've already verified the list. */
PyErr_Format(
PyExc_RuntimeError,
"Input values have changed underneath us. Something is seriously wrong.");
return -1;
}
/* We already know its a string of the correct length */
#if PY3K
if (PyBytes_AsStringAndSize(str, &str_char, &str_len)) {
#else
//.........这里部分代码省略.........
开发者ID:FairSky,项目名称:astropy,代码行数:101,代码来源:pyutil.c
示例11: convertTo_QList_0600QPair_0100QByteArray_0100QByteArray
static int convertTo_QList_0600QPair_0100QByteArray_0100QByteArray(PyObject *sipPy,void **sipCppPtrV,int *sipIsErr,PyObject *sipTransferObj)
{
QList<QPair<QByteArray,QByteArray> > **sipCppPtr = reinterpret_cast<QList<QPair<QByteArray,QByteArray> > **>(sipCppPtrV);
#line 286 "sip/QtCore/qpycore_qlist.sip"
PyObject *iter = PyObject_GetIter(sipPy);
if (!sipIsErr)
{
Py_XDECREF(iter);
return (iter
#if PY_MAJOR_VERSION < 3
&& !PyString_Check(sipPy)
#endif
&& !PyUnicode_Check(sipPy));
}
if (!iter)
{
*sipIsErr = 1;
return 0;
}
QList<QPair<QByteArray, QByteArray> > *ql = new QList<QPair<QByteArray, QByteArray> >;
for (SIP_SSIZE_T i = 0; ; ++i)
{
PyErr_Clear();
PyObject *seq = PyIter_Next(iter);
if (!seq)
{
if (PyErr_Occurred())
{
delete ql;
Py_DECREF(iter);
*sipIsErr = 1;
return 0;
}
break;
}
SIP_SSIZE_T sub_len;
if (PySequence_Check(seq)
#if PY_MAJOR_VERSION < 3
&& !PyString_Check(seq)
#endif
&& !PyUnicode_Check(seq))
sub_len = PySequence_Size(seq);
else
sub_len = -1;
if (sub_len != 2)
{
if (sub_len < 0)
PyErr_Format(PyExc_TypeError,
"index " SIP_SSIZE_T_FORMAT " has type '%s' but a 2 element non-string sequence is expected",
i, Py_TYPE(seq)->tp_name);
else
PyErr_Format(PyExc_TypeError,
"index " SIP_SSIZE_T_FORMAT " is a sequence of " SIP_SSIZE_T_FORMAT " sub-elements but 2 sub-elements are expected",
i, sub_len);
Py_DECREF(seq);
delete ql;
Py_DECREF(iter);
*sipIsErr = 1;
return 0;
}
PyObject *itm1 = PySequence_ITEM(seq, 0);
if (!itm1)
{
Py_DECREF(seq);
delete ql;
Py_DECREF(iter);
*sipIsErr = 1;
return 0;
}
int state1;
QByteArray *s1 = reinterpret_cast<QByteArray *>(
sipForceConvertToType(itm1, sipType_QByteArray, sipTransferObj,
SIP_NOT_NONE, &state1, sipIsErr));
if (*sipIsErr)
{
PyErr_Format(PyExc_TypeError,
"the first sub-element of index " SIP_SSIZE_T_FORMAT " has type '%s' but 'QByteArray' is expected",
i, Py_TYPE(itm1)->tp_name);
Py_DECREF(itm1);
//.........这里部分代码省略.........
开发者ID:rff255,项目名称:python-qt5,代码行数:101,代码来源:sipQtNetworkQList0600QPair0100QByteArray0100QByteArray.cpp
示例12: pyvslvm_file_objects_pool_initialize
/* Initializes the file objects IO pool
* Returns 1 if successful or -1 on error
*/
int pyvslvm_file_objects_pool_initialize(
libbfio_pool_t **pool,
PyObject *sequence_object,
int access_flags,
libcerror_error_t **error )
{
libbfio_handle_t *file_io_handle = NULL;
PyObject *file_object = NULL;
static char *function = "pyvslvm_file_objects_pool_initialize";
Py_ssize_t sequence_size = 0;
int element_index = 0;
int file_io_pool_entry = 0;
int number_of_elements = 0;
if( pool == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid pool.",
function );
return( -1 );
}
if( *pool != NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
"%s: invalid pool value already set.",
function );
return( -1 );
}
sequence_size = PySequence_Size(
sequence_object );
if( sequence_size > (Py_ssize_t) INT_MAX )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
"%s: invalid sequence size value exceeds maximum.",
function );
goto on_error;
}
number_of_elements = (int) sequence_size;
if( libbfio_pool_initialize(
pool,
0,
LIBBFIO_POOL_UNLIMITED_NUMBER_OF_OPEN_HANDLES,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to create pool.",
function );
goto on_error;
}
for( element_index = 0;
element_index < number_of_elements;
element_index++ )
{
file_object = PySequence_GetItem(
sequence_object,
element_index );
if( file_object == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: missing file object IO handle.",
function );
goto on_error;
}
if( pyvslvm_file_object_initialize(
&file_io_handle,
file_object,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to create file IO handle.",
function );
//.........这里部分代码省略.........
开发者ID:libyal,项目名称:libvslvm,代码行数:101,代码来源:pyvslvm_file_objects_io_pool.c
示例13: pycbc_Bucket__stats
PyObject *
pycbc_Bucket__stats(pycbc_Bucket *self, PyObject *args, PyObject *kwargs)
{
int rv;
int ii;
Py_ssize_t ncmds;
lcb_error_t err = LCB_ERROR;
PyObject *keys = NULL, *is_keystats = NULL;
struct pycbc_common_vars cv = PYCBC_COMMON_VARS_STATIC_INIT;
static char *kwlist[] = { "keys", "keystats", NULL };
lcb_CMDSTATS cmd = { 0 };
rv = PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", kwlist,
&keys, &is_keystats);
if (!rv) {
PYCBC_EXCTHROW_ARGS();
return NULL;
}
if (keys == NULL || PyObject_IsTrue(keys) == 0) {
keys = NULL;
ncmds = 1;
} else {
if (!PySequence_Check(keys)) {
PYCBC_EXC_WRAP(PYCBC_EXC_ARGUMENTS, 0, "keys argument must be sequence");
return NULL;
}
ncmds = PySequence_Size(keys);
}
rv = pycbc_common_vars_init(&cv, self, PYCBC_ARGOPT_MULTI, ncmds, 0);
if (rv < 0) {
return NULL;
}
if (keys) {
for (ii =0; ii < ncmds; ii++) {
char *key;
Py_ssize_t nkey;
PyObject *newkey = NULL;
PyObject *curkey = PySequence_GetItem(keys, ii);
rv = pycbc_BufFromString(curkey, &key, &nkey, &newkey);
if (rv < 0) {
PYCBC_EXC_WRAP_KEY(PYCBC_EXC_ARGUMENTS, 0, "bad key type in stats", curkey);
goto GT_DONE;
}
LCB_CMD_SET_KEY(&cmd, key, nkey);
if (is_keystats && PyObject_IsTrue(is_keystats)) {
cmd.cmdflags |= LCB_CMDSTATS_F_KV;
}
err = lcb_stats3(self->instance, cv.mres, &cmd);
Py_XDECREF(newkey);
}
} else {
err = lcb_stats3(self->instance, cv.mres, &cmd);
}
if (err != LCB_SUCCESS) {
PYCBC_EXCTHROW_SCHED(err);
goto GT_DONE;
}
if (-1 == pycbc_common_vars_wait(&cv, self)) {
goto GT_DONE;
}
GT_DONE:
pycbc_common_vars_finalize(&cv, self);
return cv.ret;
}
开发者ID:yonglehou,项目名称:couchbase-python-client,代码行数:75,代码来源:miscops.c
示例14: MARS_88_mw_run
static PyObject *
MARS_88_mw_run(MARS_88 *self, PyObject *args, PyObject *kwds)
{
PyObject *warriors;
s32_t rounds = 1;
s32_t seed = time(0); /* some "random" value */
u32_t *result;
PyObject *res;
u32_t numwarriors;
warrior_t *wlist;
PyObject *tmp;
PyObject *value;
u32_t i;
u32_t j;
/* Get and check arguments. */
static char *kwlist[] = {"warriors", "rounds", "seed", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ii", kwlist,
&warriors, &rounds, &seed)) {
return NULL;
}
if (PySequence_Check(warriors) == 0) {
PyErr_SetString(PyExc_ValueError, "List of warriors needed.");
return NULL;
}
numwarriors = PySequence_Size(warriors);
if (numwarriors < 2) {
PyErr_SetString(PyExc_ValueError,
"At least two warriors are needed "\
"to run a multiwarrior fight.");
return NULL;
}
if (self->coresize < numwarriors * self->mindistance) {
PyErr_SetString(PyExc_ValueError,
"All warriors do not fit into the core.");
return NULL;
}
if (rounds < 1) {
PyErr_SetString(PyExc_ValueError, "Invalid number of rounds.");
return NULL;
}
if (seed < 0) {
PyErr_SetString(PyExc_ValueError, "Invalid seed.");
return NULL;
}
if (seed < self->mindistance) {
PyErr_SetString(PyExc_ValueError, "Position of second "\
"warrior cannot be smaller than minimal "\
"warrior distance.");
return NULL;
}
/* Try to convert warriors into internal format. */
wlist = get_warriors88(warriors, numwarriors, self->maxlength);
if (wlist == NULL) {
PyErr_SetString(PyExc_ValueError, "Couldn't load warriors.");
return NULL;
}
/* Run all fights. */
result = mw_run_88(self->core, numwarriors, wlist, self->coresize,
self->maxprocesses, self->maxcycles,
self->mindistance, rounds, seed);
/* Partial cleanup. */
free_warriors(wlist, numwarriors);
/* Build results. */
res = PyList_New(numwarriors);
if (res == NULL) {
free(result);
return NULL;
}
for (i = 0; i < numwarriors; i++) {
tmp = PyList_New(numwarriors + 1);
if (tmp == NULL) {
/* Free already generated items. */
Py_DECREF(res);
free(result);
return NULL;
}
PyList_SetItem(res, i, tmp);
for (j = 0; j < numwarriors + 1; j++) {
value = py3long_or_py2int_from_long(result[i*(numwarriors+1)+j]);
PyList_SetItem(tmp, j, value);
}
}
/* Clean up. */
free(result);
return res;
}
开发者ID:ProgVal,项目名称:PyCorewar,代码行数:94,代码来源:Benchmarkingmodule.c
示例15: PySequence_Size
CThunkObject *_ctypes_alloc_callback(PyObject *callable,
PyObject *converters,
PyObject *restype,
int flags)
{
int result;
CThunkObject *p;
Py_ssize_t nArgs, i;
ffi_abi cc;
nArgs = PySequence_Size(converters);
p = CThunkObject_new(nArgs);
if (p == NULL)
return NULL;
assert(CThunk_CheckExact((PyObject *)p));
p->pcl = _ctypes_alloc_closure();
if (p->pcl == NULL) {
PyErr_NoMemory();
goto error;
}
p->flags = flags;
for (i = 0; i < nArgs; ++i) {
PyObject *cnv = PySequence_GetItem(converters, i);
if (cnv == NULL)
goto error;
p->atypes[i] = _ctypes_get_ffi_type(cnv);
Py_DECREF(cnv);
}
p->atypes[i] = NULL;
Py_INCREF(restype);
p->restype = restype;
if (restype == Py_None) {
p->setfunc = NULL;
p->ffi_restype = &ffi_type_void;
} else {
StgDictObject *dict = PyType_stgdict(restype);
if (dict == NULL || dict->setfunc == NULL) {
PyErr_SetString(PyExc_TypeError,
"invalid result type for callback function");
goto error;
}
p->setfunc = dict->setfunc;
p->ffi_restype = &dict->ffi_type_pointer;
}
cc = FFI_DEFAULT_ABI;
#if defined(MS_WIN32) && !defined(_WIN32_WCE) && !defined(MS_WIN64)
if ((flags & FUNCFLAG_CDECL) == 0)
cc = FFI_STDCALL;
#endif
result = ffi_prep_cif(&p->cif, cc,
Py_SAFE_DOWNCAST(nArgs, Py_ssize_t, int),
_ctypes_get_ffi_type(restype),
&p->atypes[0]);
if (result != FFI_OK) {
PyErr_Format(PyExc_RuntimeError,
"ffi_prep_cif failed with %d", result);
goto error;
}
result = ffi_prep_closure(p->pcl, &p->cif, closure_fcn, p);
if (result != FFI_OK) {
PyErr_Format(PyExc_RuntimeError,
"ffi_prep_closure failed with %d", result);
goto error;
}
Py_INCREF(converters);
p->converters = converters;
Py_INCREF(callable);
p->callable = callable;
return p;
error:
Py_XDECREF(p);
return NULL;
}
开发者ID:Kanma,项目名称:Athena-Dependencies-Python,代码行数:80,代码来源:callbacks.c
示例16: get_warrior94
/* Try to convert warrior into internal warrior format. Return 0 on success,
* 1 on error. */
u32_t
get_warrior94(PyObject *w, warrior_t *warrior, u32_t maxlength)
{
PyObject *tmp;
s32_t length;
s32_t start;
/* Get length of warrior. */
tmp = PyObject_GetAttrString(w, "length");
if (tmp == NULL) {
return 1;
}
if (!check_py3long_or_py2int(tmp)) {
Py_DECREF(tmp);
return 1;
}
length = py3long_or_py2int_as_long(tmp);
Py_DECREF(tmp);
if ((length < 1) | (length > maxlength)) {
return 1;
}
/* Get start instruction. */
tmp = PyObject_GetAttrString(w, "start");
if (tmp == NULL) {
return 1;
}
if (!check_py3long_or_py2int(tmp)) {
Py_DECREF(tmp);
return 1;
}
start = py3long_or_py2int_as_long(tmp);
Py_DECREF(tmp);
if ((start < 0) | (start >= length)) {
return 1;
}
/* Check for instructions. */
tmp = PyObject_GetAttrString(w, "instructions");
if (tmp == NULL) {
return 1;
}
if (!PySequence_Check(tmp)) {
Py_DECREF(tmp);
return 1;
}
if (PySequence_Size(tmp) != length) {
Py_DECREF(tmp);
return 1;
}
/* Get instructions. */
warrior->insns = get_instructions94(tmp, length);
Py_DECREF(tmp);
if (warrior->insns == NULL) {
return 1;
}
warrior->start = start;
warrior->length = length;
return 0;
}
开发者ID:ProgVal,项目名称:PyCorewar,代码行数:64,代码来源:Benchmarkingmodule.c
示例17: set_pscards
int
set_pscards(
/*@[email protected]*/ const char* propname,
PyObject* value,
struct pscard** ps,
int *nps,
int *npsmax) {
PyObject* subvalue = NULL;
Py_ssize_t i = 0;
Py_ssize_t size = 0;
int ival = 0;
int mval = 0;
const char* strvalue = 0;
void* newmem = NULL;
if (!PySequence_Check(value))
return -1;
size = PySequence_Size(value);
if (size > 0x7fffffff) {
/* Must be a 32-bit size */
return -1;
}
if (size > (Py_ssize_t)*npsmax) {
newmem = malloc(sizeof(struct pscard) * size);
if (newmem == NULL) {
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory.");
return -1;
}
free(*ps);
*ps = newmem;
*npsmax = (int)size;
}
/* Verify the entire list for correct types first, so we don't have
to undo anything copied into the canonical array. */
for (i = 0; i < size; ++i) {
subvalue = PySequence_GetItem(value, i);
if (subvalue == NULL) {
return -1;
}
if (!PyArg_ParseTuple(subvalue, "iis", &ival, &mval, &strvalue)) {
Py_DECREF(subvalue);
return -1;
}
Py_DECREF(subvalue);
}
for (i = 0; i < size; ++i) {
subvalue = PySequence_GetItem(value, i);
if (subvalue == NULL) {
return -1;
}
if (!PyArg_ParseTuple(subvalue, "iis", &ival, &mval, &strvalue)) {
Py_DECREF(subvalue);
return -1;
}
Py_DECREF(subvalue);
(*ps)[i].i = ival;
(*ps)[i].m = mval;
strncpy((*ps)[i].value, strvalue, 72);
(*ps)[i].value[71] = '\0';
(*nps) = (int)(i + 1);
}
return 0;
}
开发者ID:5Zhiyong,项目名称:astropy,代码行数:69,代码来源:pyutil.c
示例18: PySequence_Size
ffi_info *AllocFunctionCallback(PyObject *callable,
PyObject *converters,
PyObject *restype,
int is_cdecl)
{
int result;
ffi_info *p;
int nArgs, i;
ffi_abi cc;
nArgs = PySequence_Size(converters);
p = (ffi_info *)PyMem_Malloc(sizeof(ffi_info) + sizeof(ffi_type) * (nArgs + 1));
if (p == NULL) {
PyErr_NoMemory();
return NULL;
}
p->pcl = MallocClosure();
if (p->pcl == NULL) {
PyErr_NoMemory();
goto error;
}
for (i = 0; i < nArgs; ++i) {
PyObject *cnv = PySequence_GetItem(converters, i);
if (cnv == NULL)
goto error;
p->atypes[i] = GetType(cnv);
Py_DECREF(cnv);
}
p->atypes[i] = NULL;
if (restype == Py_None) {
p->setfunc = NULL;
p->restype = &ffi_type_void;
} else {
StgDictObject *dict = PyType_stgdict(restype);
if (dict == NULL || dict->setfunc == NULL) {
PyErr_SetString(PyExc_TypeError,
"invalid result type for callback function");
goto error;
}
p->setfunc = dict->setfunc;
p->restype = &dict->ffi_type_pointer;
}
cc = FFI_DEFAULT_ABI;
#if defined(MS_WIN32) && !defined(_WIN32_WCE)
if (is_cdecl == 0)
cc = FFI_STDCALL;
#endif
result = ffi_prep_cif(&p->cif, cc, nArgs,
GetType(restype),
&p->atypes[0]);
if (result != FFI_OK) {
PyErr_Format(PyExc_RuntimeError,
"ffi_prep_cif failed with %d", result);
goto error;
}
result = ffi_prep_closure(p->pcl, &p->cif, closure_fcn, p);
if (result != FFI_OK) {
PyErr_Format(PyExc_RuntimeError,
"ffi_prep_closure failed with %d", result);
goto error;
}
p->converters = converters;
p->callable = callable;
return p;
error:
if (p) {
if (p->pcl)
FreeClosure(p->pcl);
PyMem_Free(p);
}
return NULL;
}
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:77,代码来源:callbacks.c
示例19: if
static PyObject *Py_convert_to_string(PyObject *self,
|
请发表评论