本文整理汇总了C++中PySequence_GetItem函数的典型用法代码示例。如果您正苦于以下问题:C++ PySequence_GetItem函数的具体用法?C++ PySequence_GetItem怎么用?C++ PySequence_GetItem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PySequence_GetItem函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: PyErr_Format
//-------------------------------------------------------------------------------------
PyObject* Entity::pyTeleport(PyObject* nearbyMBRef, PyObject* pyposition, PyObject* pydirection)
{
if(!PySequence_Check(pyposition) || PySequence_Size(pyposition) != 3)
{
PyErr_Format(PyExc_Exception, "%s::teleport: %d position not is Sequence!\n", getScriptName(), getID());
PyErr_PrintEx(0);
S_Return;
}
if(!PySequence_Check(pydirection) || PySequence_Size(pydirection) != 3)
{
PyErr_Format(PyExc_Exception, "%s::teleport: %d direction not is Sequence!\n", getScriptName(), getID());
PyErr_PrintEx(0);
S_Return;
}
Position3D pos;
Direction3D dir;
PyObject* pyitem = PySequence_GetItem(pyposition, 0);
pos.x = (float)PyFloat_AsDouble(pyitem);
Py_DECREF(pyitem);
pyitem = PySequence_GetItem(pyposition, 1);
pos.y = (float)PyFloat_AsDouble(pyitem);
Py_DECREF(pyitem);
pyitem = PySequence_GetItem(pyposition, 2);
pos.z = (float)PyFloat_AsDouble(pyitem);
Py_DECREF(pyitem);
pyitem = PySequence_GetItem(pydirection, 0);
dir.roll = (float)PyFloat_AsDouble(pyitem);
Py_DECREF(pyitem);
pyitem = PySequence_GetItem(pydirection, 1);
dir.pitch = (float)PyFloat_AsDouble(pyitem);
Py_DECREF(pyitem);
pyitem = PySequence_GetItem(pydirection, 2);
dir.yaw = (float)PyFloat_AsDouble(pyitem);
Py_DECREF(pyitem);
teleport(nearbyMBRef, pos, dir);
S_Return;
}
开发者ID:fengqk,项目名称:kbengine,代码行数:47,代码来源:entity.cpp
示例2: double_from_pyobj
static int double_from_pyobj(double* v,PyObject *obj,const char *errmess) {
PyObject* tmp = NULL;
if (PyFloat_Check(obj)) {
#ifdef __sgi
*v = PyFloat_AsDouble(obj);
#else
*v = PyFloat_AS_DOUBLE(obj);
#endif
return 1;
}
tmp = PyNumber_Float(obj);
if (tmp) {
#ifdef __sgi
*v = PyFloat_AsDouble(tmp);
#else
*v = PyFloat_AS_DOUBLE(tmp);
#endif
Py_DECREF(tmp);
return 1;
}
if (PyComplex_Check(obj))
tmp = PyObject_GetAttrString(obj,"real");
else if (PyString_Check(obj) || PyUnicode_Check(obj))
/*pass*/;
else if (PySequence_Check(obj))
tmp = PySequence_GetItem(obj,0);
if (tmp) {
PyErr_Clear();
if (double_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}
Py_DECREF(tmp);
}
{
PyObject* err = PyErr_Occurred();
if (err==NULL) err = uts_scsmfo_error;
PyErr_SetString(err,errmess);
}
return 0;
}
开发者ID:RebeccaWPerry,项目名称:holography-gpu,代码行数:38,代码来源:uts_scsmfomodule.c
示例3: sequence_to_arrays
/*
* Converts a Python sequence into 'count' PyArrayObjects
*
* seq - Input Python object, usually a tuple but any sequence works.
* op - Where the arrays are placed.
* count - How many arrays there should be (errors if it doesn't match).
* paramname - The name of the parameter that produced 'seq'.
*/
static int sequence_to_arrays(PyObject *seq,
PyArrayObject **op, int count,
char *paramname)
{
int i;
if (!PySequence_Check(seq) || PySequence_Size(seq) != count) {
PyErr_Format(PyExc_ValueError,
"parameter %s must be a sequence of length %d",
paramname, count);
return -1;
}
for (i = 0; i < count; ++i) {
PyObject *item = PySequence_GetItem(seq, i);
if (item == NULL) {
while (--i >= 0) {
Py_DECREF(op[i]);
op[i] = NULL;
}
return -1;
}
op[i] = (PyArrayObject *)PyArray_FromAny(item, NULL, 0, 0, 0, NULL);
if (op[i] == NULL) {
while (--i >= 0) {
Py_DECREF(op[i]);
op[i] = NULL;
}
Py_DECREF(item);
return -1;
}
Py_DECREF(item);
}
return 0;
}
开发者ID:Ethan-Yan,项目名称:numpy,代码行数:46,代码来源:compiled_base.c
示例4: PyADSIObject_AsADS_SEARCHPREF_INFOs
BOOL PyADSIObject_AsADS_SEARCHPREF_INFOs(PyObject *ob, ADS_SEARCHPREF_INFO **ppret, DWORD *pcinfos)
{
BOOL ret = FALSE;
if (!PySequence_Check(ob)) {
PyErr_SetString(PyExc_TypeError, "ADS_SEARCHPREF_INFOs must be a sequence");
return FALSE;
}
// Use C++ reference to make working with ppret more convenient.
ADS_SEARCHPREF_INFO *&pret = *ppret;
DWORD &nitems = *pcinfos;
nitems = PySequence_Length(ob);
pret = (ADS_SEARCHPREF_INFO *)malloc(sizeof(ADS_SEARCHPREF_INFO) * nitems);
if (!pret) {
PyErr_NoMemory();
return NULL;
}
memset(pret, 0, sizeof(ADS_SEARCHPREF_INFO) * nitems);
PyObject *sub = NULL;
PyObject *obValue; // no reference
DWORD i;
for (i=0;i<nitems;i++) {
PyObject *sub = PySequence_GetItem(ob, i);
if (!sub) goto done;
if (!PyArg_ParseTuple(sub, "iO:ADS_SEARCHPREF_INFO tuple", &pret[i].dwSearchPref, &obValue))
goto done;
if (!PyADSIObject_AsADSVALUE(obValue, pret[i].vValue))
goto done;
Py_DECREF(sub);
sub = NULL;
}
ret = TRUE;
done:
Py_XDECREF(sub);
if (!ret && pret)
PyADSIObject_FreeADS_SEARCHPREF_INFOs(pret, nitems);
return ret;
}
开发者ID:malrsrch,项目名称:pywin32,代码行数:38,代码来源:PyADSIUtil.cpp
示例5: assert
static GPtrArray *create_row(PyObject *item){
assert(item);
GPtrArray *row = g_ptr_array_new();
if(!row)
return NULL;
int i;
for(i = 0; i < PySequence_Size(item); i++){
PyObject *elem = PySequence_GetItem(item, i);
if(!elem)
goto failed;
PyObject *elem_str = PyObject_Str(elem);
Py_DECREF(elem);
if(!elem_str)
goto failed;
g_ptr_array_add(row, g_strdup(PyString_AsString(elem_str)));
Py_DECREF(elem_str);
}
return row;
failed:
g_ptr_array_clear(row);
return NULL;
}
开发者ID:akamajoris,项目名称:mysql-proxy-python,代码行数:23,代码来源:network-mysqld-python.c
示例6: listtoarray
double* listtoarray(PyObject* o,int *size)
{
int length;
double* result;
double tempval;
PyObject* tempObject;
int i;
//printf("Started List to Array\n");
length = PySequence_Size(o);
//printf("%d\n",length);
result=malloc(length*sizeof(double));
for(i=0;i<length;i++)
{
//printf("%d\n",i);
tempObject=PySequence_GetItem(o,i);
tempval=PyFloat_AsDouble(tempObject);
//printf("%g\n",tempval);
result[i]=tempval;
}
//printf("The length is: %d\n",length);
*size=length;
return result;
}
开发者ID:cjwiggins,项目名称:MagnetoShim,代码行数:23,代码来源:BiotSavart_LineSeg.c
示例7: save_mask
static PyObject*
save_mask(PyObject *self, PyObject *arg)
{
int idx, size;
PyObject *list, *item;
if (!PyArg_ParseTuple(arg, "O", &list)) {
return NULL;
}
sigemptyset(&newmask);
size = PySequence_Length(list);
for (idx = 0; idx < size; ++idx) {
item = PySequence_GetItem(list, idx);
sigaddset(&newmask, PyInt_AsLong(item));
}
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) != 0) {
Py_Exit(1);
}
Py_RETURN_NONE;
}
开发者ID:SoQoo,项目名称:dping,代码行数:23,代码来源:_sigpending.c
示例8: convert2_float_array
void convert2_float_array(float *result, PyObject *input, int size) {
int i;
if (!PySequence_Check(input)) {
printf("Expected a sequence\n");
exit(EXIT_FAILURE);
}
int length=PySequence_Length(input);
if (length > size) {
printf("Size mismatch.\n");
exit(EXIT_FAILURE);
}
for (i = 0; i < length; i++) {
PyObject *o = PySequence_GetItem(input,i);
if (PyNumber_Check(o)) {
result[i] = (float) PyFloat_AsDouble(o);
} else {
printf("Sequence elements must be numbers\n");
free(result);
exit(EXIT_FAILURE);
}
free(o);
}
}
开发者ID:kstovall,项目名称:psrfits_utils,代码行数:23,代码来源:swig_addedfunc.c
示例9: seqiterHasnext_capi
static Box* seqiterHasnext_capi(Box* s) noexcept {
RELEASE_ASSERT(s->cls == seqiter_cls || s->cls == seqreviter_cls, "");
BoxedSeqIter* self = static_cast<BoxedSeqIter*>(s);
if (!self->b) {
Py_RETURN_FALSE;
}
Box* next = PySequence_GetItem(self->b, self->idx);
if (!next) {
if (PyErr_ExceptionMatches(IndexError) || PyErr_ExceptionMatches(StopIteration)) {
PyErr_Clear();
Py_CLEAR(self->b);
Py_RETURN_FALSE;
}
return NULL;
}
self->idx++;
RELEASE_ASSERT(!self->next, "");
self->next = next;
Py_RETURN_TRUE;
}
开发者ID:ChinaQuants,项目名称:pyston,代码行数:23,代码来源:iterobject.cpp
示例10: PyErr_SetString
static PyObject *Playlist_remove_tracks(Playlist *self, PyObject *args) {
PyObject *py_tracks;
PyObject *item;
sp_error err;
int *tracks;
int num_tracks;
int playlist_length;
int i;
if(!PyArg_ParseTuple(args, "O", &py_tracks))
return NULL;
if (!PySequence_Check(py_tracks)) {
PyErr_SetString(PyExc_TypeError, "expected sequence");
return NULL;
}
num_tracks = PySequence_Size(py_tracks);
tracks = (int *) malloc(sizeof(tracks)*num_tracks);
playlist_length = sp_playlist_num_tracks(self->_playlist);
for (i = 0; i < num_tracks; i++) {
item = PySequence_GetItem(py_tracks, i);
if (!PyInt_Check(item)) {
free(tracks);
PyErr_SetString(PyExc_TypeError, "expected sequence of integers");
return NULL;
}
tracks[i] = (int)PyInt_AsLong(item);
if (tracks[i] > playlist_length) {
PyErr_SetString(PyExc_IndexError, "specified track does not exist");
return NULL;
}
Py_DECREF(item);
}
Py_BEGIN_ALLOW_THREADS
err = sp_playlist_remove_tracks(self->_playlist, tracks, num_tracks);
Py_END_ALLOW_THREADS
return handle_error(err);
}
开发者ID:aabilio,项目名称:pyspotify,代码行数:37,代码来源:playlist.c
示例11: PyErr_Clear
// ---------------------------------------------------
//
// Gateway Implementation
STDMETHODIMP PyGSpecifyPropertyPages::GetPages(
/* [out] */ CAUUID __RPC_FAR * pPages)
{
PY_GATEWAY_METHOD;
PyObject *result;
HRESULT hr=InvokeViaPolicy("GetPages", &result);
if (FAILED(hr)) return hr;
int length=PyObject_Length(result);
if(length<1 || !PySequence_Check(result) )
{
// Python implementation did not return a sequence
PyErr_Clear();
return E_NOTIMPL;
}
pPages->cElems=0;
pPages->pElems=(GUID *)CoTaskMemAlloc(length*sizeof(GUID)); // Not all may be used
for(int i=0;i<length;++i)
{
if(PyWinObject_AsIID(PySequence_GetItem(result,i),pPages->pElems+pPages->cElems))
{
// Sucessfully converted, so put the next GUID in the next slot
pPages->cElems++;
}
else
{
// Could not convert this GUID; ignore it and continue.
PyErr_Clear();
}
}
Py_DECREF(result);
return hr;
}
开发者ID:DavidGuben,项目名称:rcbplayspokemon,代码行数:40,代码来源:PyISpecifyPropertyPages.cpp
示例12: PyArray_ConvertClipmodeSequence
/*NUMPY_API
* Convert an object to an array of n NPY_CLIPMODE values.
* This is intended to be used in functions where a different mode
* could be applied to each axis, like in ravel_multi_index.
*/
NPY_NO_EXPORT int
PyArray_ConvertClipmodeSequence(PyObject *object, NPY_CLIPMODE *modes, int n)
{
int i;
/* Get the clip mode(s) */
if (object && (PyTuple_Check(object) || PyList_Check(object))) {
if (PySequence_Size(object) != n) {
PyErr_Format(PyExc_ValueError,
"list of clipmodes has wrong length (%d instead of %d)",
(int)PySequence_Size(object), n);
return NPY_FAIL;
}
for (i = 0; i < n; ++i) {
PyObject *item = PySequence_GetItem(object, i);
if(item == NULL) {
return NPY_FAIL;
}
if(PyArray_ClipmodeConverter(item, &modes[i]) != NPY_SUCCEED) {
Py_DECREF(item);
return NPY_FAIL;
}
Py_DECREF(item);
}
}
else if (PyArray_ClipmodeConverter(object, &modes[0]) == NPY_SUCCEED) {
for (i = 1; i < n; ++i) {
modes[i] = modes[0];
}
}
else {
return NPY_FAIL;
}
return NPY_SUCCEED;
}
开发者ID:alphaitis,项目名称:numpy,代码行数:42,代码来源:conversion_utils.c
示例13: read_list_float_attr
static double * read_list_float_attr(PyObject * record_obj, char * attr_name)
/* Read a list of floating point values from a Python record given the
* attribute name and return a C list of doubles. The C list has to be
* deallocated with free.
*/
{
/* new reference */
PyObject * item_list_obj = PyObject_GetAttrString(record_obj, attr_name);
int num_item = (int) PySequence_Length(item_list_obj);
double * retval = (double *) malloc(num_item * sizeof(double));
int idx;
for (idx = 0; idx < num_item; idx++)
{
/* new reference */
PyObject * item_obj = PySequence_GetItem(item_list_obj, (Py_ssize_t) idx);
retval[idx] = PyFloat_AsDouble(item_obj);
Py_DECREF(item_obj);
}
Py_DECREF(item_list_obj);
#ifdef VERYVERBOSE
printf(" %s = [", attr_name);
for (idx = 0; idx < num_item; idx++)
printf("%lf, ", retval[idx]);
printf("]\n");
#endif
return retval;
}
开发者ID:calonlay-hj,项目名称:ppaml-cp4,代码行数:36,代码来源:csolve.c
示例14: convertible
static void* convertible(PyObject* obj_ptr){
if(!PySequence_Check(obj_ptr)) return 0;
bool isFlat=!PySequence_Check(py::handle<>(PySequence_GetItem(obj_ptr,0)).get());
// mixed static/dynamic not handled (also not needed)
BOOST_STATIC_ASSERT(
(MT::RowsAtCompileTime!=Eigen::Dynamic && MT::ColsAtCompileTime!=Eigen::Dynamic)
||
(MT::RowsAtCompileTime==Eigen::Dynamic && MT::ColsAtCompileTime==Eigen::Dynamic)
);
int sz=PySequence_Size(obj_ptr);
if(MT::RowsAtCompileTime!=Eigen::Dynamic){
if(isFlat){
// flat sequence (first item not sub-sequence), must contain exactly all items
if(sz!=MT::RowsAtCompileTime*MT::ColsAtCompileTime) return 0;
} else {
// contains nested sequences, one per row
if(sz!=MT::RowsAtCompileTime) return 0;
}
};
return obj_ptr;
// other checks done in the construct function
// FIXME: it may be too late to do it there, as overloads are chosen based on *convertible*
// (at least a clear message should be given when py::extract fails there)
}
开发者ID:jbcolli2,项目名称:minieigen,代码行数:24,代码来源:converters.hpp
示例15: PySequence_GetItem
static PyObject *t_sequence_pop(t_sequence *self, PyObject *args)
{
int index = -1, setDirty = 1;
PyObject *value;
if (!PyArg_ParseTuple(args, "|ii", &index, &setDirty))
return NULL;
value = PySequence_GetItem(self->sequence, index);
if (!value)
return NULL;
if (!(self->itemvalue.flags & V_PURE))
{
PyObject *v = _restoreValue(self, value);
Py_DECREF(value);
if (!v)
return NULL;
value = v;
}
if (PySequence_DelItem(self->sequence, index) < 0)
{
Py_DECREF(value);
return NULL;
}
if (setDirty && _t_itemvalue__setDirty((t_itemvalue *) self, 0) < 0)
{
Py_DECREF(value);
return NULL;
}
return value;
}
开发者ID:HackLinux,项目名称:chandler,代码行数:36,代码来源:sequence.c
示例16: pyvar_walk_list
//-------------------------------------------------------------------------
Py_ssize_t pyvar_walk_list(
const ref_t &py_list,
int (idaapi *cb)(const ref_t &py_item, Py_ssize_t index, void *ud),
void *ud)
{
PYW_GIL_CHECK_LOCKED_SCOPE();
Py_ssize_t size = CIP_FAILED;
do
{
PyObject *o = py_list.o;
if ( !PyList_CheckExact(o) && !PyW_IsSequenceType(o) )
break;
bool is_seq = !PyList_CheckExact(o);
size = is_seq ? PySequence_Size(o) : PyList_Size(o);
if ( cb == NULL )
break;
Py_ssize_t i;
for ( i=0; i<size; i++ )
{
// Get the item
ref_t py_item;
if ( is_seq )
py_item = newref_t(PySequence_GetItem(o, i));
else
py_item = borref_t(PyList_GetItem(o, i));
if ( py_item == NULL || cb(py_item, i, ud) < CIP_OK )
break;
}
size = i;
} while ( false );
return size;
}
开发者ID:Hehouhua,项目名称:idapython,代码行数:37,代码来源:py_cvt.hpp
示例17: callMethod
Robot::Location Robot::getLocation() {
Robot::Location l;
PyObject *pValue = callMethod("getLocation");
/** pValue = ('locName', (x, y, orientation)) **/
if (pValue != NULL) {
PythonLock lock = PythonLock();
if (!PySequence_Check(pValue)) {
//problem!
} else {
l.name = std::string(PyString_AsString(PySequence_GetItem(pValue, 0)));
l.x = PyFloat_AsDouble(PySequence_GetItem(PySequence_GetItem(pValue, 1), 0));
l.y = PyFloat_AsDouble(PySequence_GetItem(PySequence_GetItem(pValue, 1), 1));
l.orientation = PyFloat_AsDouble(PySequence_GetItem(PySequence_GetItem(pValue, 1), 2));
}
Py_DECREF(pValue);
}
return l;
}
开发者ID:ipa-rmb,项目名称:accompany,代码行数:23,代码来源:robot.cpp
示例18: converttuple
static char *
converttuple(PyObject *arg, char **p_format, va_list *p_va, int *levels,
char *msgbuf, size_t bufsize, int toplevel, PyObject **freelist)
{
int level = 0;
int n = 0;
char *format = *p_format;
int i;
for (;;) {
int c = *format++;
if (c == '(') {
if (level == 0)
n++;
level++;
}
else if (c == ')') {
if (level == 0)
break;
level--;
}
else if (c == ':' || c == ';' || c == '\0')
break;
else if (level == 0 && isalpha(c))
n++;
}
if (!PySequence_Check(arg) || PyString_Check(arg)) {
levels[0] = 0;
PyOS_snprintf(msgbuf, bufsize,
toplevel ? "expected %d arguments, not %.50s" :
"must be %d-item sequence, not %.50s",
n,
arg == Py_None ? "None" : arg->ob_type->tp_name);
return msgbuf;
}
if ((i = PySequence_Size(arg)) != n) {
levels[0] = 0;
PyOS_snprintf(msgbuf, bufsize,
toplevel ? "expected %d arguments, not %d" :
"must be sequence of length %d, not %d",
n, i);
return msgbuf;
}
format = *p_format;
for (i = 0; i < n; i++) {
char *msg;
PyObject *item;
item = PySequence_GetItem(arg, i);
msg = convertitem(item, &format, p_va, levels+1, msgbuf,
bufsize, freelist);
/* PySequence_GetItem calls tp->sq_item, which INCREFs */
Py_XDECREF(item);
if (msg != NULL) {
levels[0] = i+1;
return msg;
}
}
*p_format = format;
return NULL;
}
开发者ID:MatiasNAmendola,项目名称:cleese,代码行数:64,代码来源:getargs.c
示例19: the
//.........这里部分代码省略.........
basedict->ffi_type_pointer.elements,
sizeof(ffi_type *) * (basedict->length));
ffi_ofs = basedict->length;
} else {
offset = 0;
size = 0;
align = 0;
union_size = 0;
total_align = 1;
stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT;
stgdict->ffi_type_pointer.elements = PyMem_Malloc(sizeof(ffi_type *) * (len + 1));
if (stgdict->ffi_type_pointer.elements == NULL) {
PyErr_NoMemory();
return -1;
}
memset(stgdict->ffi_type_pointer.elements, 0,
sizeof(ffi_type *) * (len + 1));
ffi_ofs = 0;
}
assert(stgdict->format == NULL);
if (isStruct && !isPacked) {
stgdict->format = alloc_format_string(NULL, "T{");
} else {
/* PEP3118 doesn't support union, or packed structures (well,
only standard packing, but we dont support the pep for
that). Use 'B' for bytes. */
stgdict->format = alloc_format_string(NULL, "B");
}
#define realdict ((PyObject *)&stgdict->dict)
for (i = 0; i < len; ++i) {
PyObject *name = NULL, *desc = NULL;
PyObject *pair = PySequence_GetItem(fields, i);
PyObject *prop;
StgDictObject *dict;
int bitsize = 0;
if (!pair || !PyArg_ParseTuple(pair, "OO|i", &name, &desc, &bitsize)) {
PyErr_SetString(PyExc_AttributeError,
"'_fields_' must be a sequence of pairs");
Py_XDECREF(pair);
return -1;
}
dict = PyType_stgdict(desc);
if (dict == NULL) {
Py_DECREF(pair);
PyErr_Format(PyExc_TypeError,
#if (PY_VERSION_HEX < 0x02050000)
"second item in _fields_ tuple (index %d) must be a C type",
#else
"second item in _fields_ tuple (index %zd) must be a C type",
#endif
i);
return -1;
}
stgdict->ffi_type_pointer.elements[ffi_ofs + i] = &dict->ffi_type_pointer;
if (dict->flags & (TYPEFLAG_ISPOINTER | TYPEFLAG_HASPOINTER))
stgdict->flags |= TYPEFLAG_HASPOINTER;
dict->flags |= DICTFLAG_FINAL; /* mark field type final */
if (PyTuple_Size(pair) == 3) { /* bits specified */
switch(dict->ffi_type_pointer.type) {
case FFI_TYPE_UINT8:
case FFI_TYPE_UINT16:
case FFI_TYPE_UINT32:
case FFI_TYPE_SINT64:
开发者ID:1310701102,项目名称:sl4a,代码行数:67,代码来源:stgdict.c
示例20: Process_func_spawn
static PyObject *
Process_func_spawn(Process *self, PyObject *args, PyObject *kwargs)
{
int err, flags, len, stdio_count;
unsigned int uid, gid;
char *cwd, *cwd2, *file, *file2, *arg_str, *tmp_str, *key_str, *value_str;
char **ptr, **process_args, **process_env;
Py_ssize_t i, n, pos;
PyObject *key, *value, *item, *tmp, *callback, *arguments, *env, *stdio, *ret;
uv_process_options_t options;
uv_stdio_container_t *stdio_container;
static char *kwlist[] = {"file", "exit_callback", "args", "env", "cwd", "uid", "gid", "flags", "stdio", NULL};
cwd = NULL;
ptr = process_args = process_env = NULL;
tmp = arguments = env = stdio = NULL;
stdio_container = NULL;
flags = uid = gid = stdio_count = 0;
RAISE_IF_SPAWNED(self, NULL);
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO!sIIiO:__init__", kwlist, &file, &callback, &arguments, &PyDict_Type, &env, &cwd, &uid, &gid, &flags, &stdio)) {
return NULL;
}
if (callback != Py_None && !PyCallable_Check(callback)) {
PyErr_SetString(PyExc_TypeError, "a callable is required");
return NULL;
}
if (arguments && !PySequence_Check(arguments)) {
PyErr_SetString(PyExc_TypeError, "only iterable objects are supported for 'args'");
return NULL;
}
if (stdio && !PySequence_Check(stdio)) {
PyErr_SetString(PyExc_TypeError, "only iterable objects are supported for 'stdio'");
return NULL;
}
memset(&options, 0, sizeof(uv_process_options_t));
options.uid = uid;
options.gid = gid;
options.flags = flags;
options.exit_cb = on_process_exit;
file2 = PyMem_Malloc(strlen(file) + 1);
if (!file2) {
PyErr_NoMemory();
ret = NULL;
goto cleanup;
}
strcpy(file2, file);
options.file = file2;
if (arguments) {
n = PySequence_Length(arguments);
process_args = PyMem_Malloc(sizeof *process_args * (n + 2));
if (!process_args) {
PyErr_NoMemory();
PyMem_Free(file2);
ret = NULL;
goto cleanup;
}
process_args[0] = file2;
i = 0;
while (i < n) {
item = PySequence_GetItem(arguments, i);
if (!item || !PyArg_Parse(item, "s;args contains a non-string value", &arg_str)) {
Py_XDECREF(item);
ret = NULL;
goto cleanup;
}
tmp_str = PyMem_Malloc(strlen(arg_str) + 1);
if (!tmp_str) {
Py_DECREF(item);
ret = NULL;
goto cleanup;
}
strcpy(tmp_str, arg_str);
process_args[i+1] = tmp_str;
Py_DECREF(item);
i++;
}
process_args[i+1] = NULL;
} else {
process_args = PyMem_Malloc(sizeof *process_args * 2);
if (!process_args) {
PyErr_NoMemory();
PyMem_Free(file2);
ret = NULL;
goto cleanup;
}
process_args[0] = file2;
process_args[1] = NULL;
}
options.args = process_args;
//.........这里部分代码省略.........
开发者ID:poupas,项目名称:pyuv,代码行数:101,代码来源:process.c
注:本文中的PySequence_GetItem函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论