PyObject *eStreamServer::getConnectedClients() { ePyObject ret; int idx = 0; int cnt = clients.size(); ret = PyList_New(cnt); for (eSmartPtrList<eStreamClient>::iterator it = clients.begin(); it != clients.end(); ++it) { ePyObject tuple = PyTuple_New(3); PyTuple_SET_ITEM(tuple, 0, PyString_FromString((char *)it->getRemoteHost().c_str())); PyTuple_SET_ITEM(tuple, 1, PyString_FromString((char *)it->getServiceref().c_str())); PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(it->isUsingEncoder())); PyList_SET_ITEM(ret, idx++, tuple); } return ret; }
static PyObject *t_locale_getISOLanguages(PyTypeObject *type) { const char *const *languages = Locale::getISOLanguages(); PyObject *list; int len = 0; while (languages[len] != NULL) len += 1; list = PyList_New(len); for (int i = 0; i < len; i++) { PyObject *str = PyString_FromString(languages[i]); PyList_SET_ITEM(list, i, str); } return list; }
static PyObject* pyDrawableSpans_getVerts(pyDrawableSpans* self, PyObject* args) { pyIcicle* ice; if (!PyArg_ParseTuple(args, "O", &ice)) { PyErr_SetString(PyExc_TypeError, "getVerts expects a plIcicle"); return NULL; } if (!pyIcicle_Check((PyObject*)ice)) { PyErr_SetString(PyExc_TypeError, "getVerts expects a plIcicle"); return NULL; } std::vector<plGBufferVertex> verts = self->fThis->getVerts(ice->fThis); PyObject* list = PyList_New(verts.size()); for (size_t i=0; i<verts.size(); i++) PyList_SET_ITEM(list, i, pyGBufferVertex_FromGBufferVertex(verts[i])); return list; }
static PyObject *pyop_dir(PyObject *UNUSED(self)) { GHashIterator iter; PyObject *list; int i; WM_operatortype_iter(&iter); list = PyList_New(BLI_ghash_size(iter.gh)); for (i = 0; !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter), i++) { wmOperatorType *ot = BLI_ghashIterator_getValue(&iter); PyList_SET_ITEM(list, i, PyUnicode_FromString(ot->idname)); } return list; }
static PyObject* pyDrawableSpans_getIndices(pyDrawableSpans* self, PyObject* args) { pyIcicle* ice; if (!PyArg_ParseTuple(args, "O", &ice)) { PyErr_SetString(PyExc_TypeError, "getIndices expects a plIcicle"); return NULL; } if (!pyIcicle_Check((PyObject*)ice)) { PyErr_SetString(PyExc_TypeError, "getIndices expects a plIcicle"); return NULL; } std::vector<unsigned short> indices = self->fThis->getIndices(ice->fThis); PyObject* list = PyList_New(indices.size()); for (size_t i=0; i<indices.size(); i++) PyList_SET_ITEM(list, i, PyInt_FromLong(indices[i])); return list; }
PyObject *eServiceEvent::getComponentData() const { ePyObject ret = PyList_New(m_component_data.size()); int cnt=0; for (std::list<eComponentData>::const_iterator it(m_component_data.begin()); it != m_component_data.end(); ++it) { ePyObject tuple = PyTuple_New(5); PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(it->m_componentTag)); PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(it->m_componentType)); PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(it->m_streamContent)); PyTuple_SET_ITEM(tuple, 3, PyString_FromString(it->m_iso639LanguageCode.c_str())); PyTuple_SET_ITEM(tuple, 4, PyString_FromString(it->m_text.c_str())); PyList_SET_ITEM(ret, cnt++, tuple); } return ret; }
PyObject *PyMAPIObject_FromSPropValueArray(SPropValue *pv, ULONG nvalues) { PyObject *ret = PyList_New(nvalues); if (!ret) return NULL; ULONG i; for (i=0;i<nvalues;i++) { PyObject *sub = PyMAPIObject_FromSPropValue(pv+i); if (!sub) { Py_DECREF(ret); return NULL; } PyList_SET_ITEM(ret, i, sub); } return ret; }
Py_LOCAL(PyObject *) avl_tree_repr(avl_tree_Object * self) { PyObject *result = NULL; avl_size_t len; int rc; len = avl_size(self->tree); rc = Py_ReprEnter((PyObject *) self); if (rc != 0) return rc > 0 ? PyString_FromString("[...]") : NULL; if (len == 0) { result = PyString_FromString("[]"); goto finish; } { avl_iterator iter; PyObject *list, *ob; Py_ssize_t i = 0; iter = avl_iterator_new(self->tree, AVL_ITERATOR_INI_PRE); if (iter == NULL) goto finish; list = PyList_New(len); if (list == NULL) goto finish; do { ob = objectAt(avl_iterator_next(iter)); Py_INCREF(ob); PyList_SET_ITEM(list, i, ob); ++i; } while (--len); avl_iterator_kill(iter); result = PyObject_Repr(list); list->ob_type->tp_dealloc(list); } finish: Py_ReprLeave((PyObject *) self); return result; }
static PyObject* pyGBufferGroup_getIndices(pyGBufferGroup* self, PyObject* args) { int idx, start = 0, len = -1; if (!PyArg_ParseTuple(args, "i|ii", &idx, &start, &len)) { PyErr_SetString(PyExc_TypeError, "getIndices expects an int"); return NULL; } std::vector<unsigned short> indices; if (start == 0 && len == -1) indices = self->fThis->getIndices(idx); else indices = self->fThis->getIndices(idx, start, len); PyObject* list = PyList_New(indices.size()); for (size_t i=0; i<indices.size(); i++) PyList_SET_ITEM(list, i, PyInt_FromLong(indices[i])); return list; }
static PyObject* pyGBufferGroup_getVerts(pyGBufferGroup* self, PyObject* args) { int idx, start = 0, len = -1; if (!PyArg_ParseTuple(args, "i|ii", &idx, &start, &len)) { PyErr_SetString(PyExc_TypeError, "getVertices expects an int"); return NULL; } std::vector<plGBufferVertex> verts; if (start == 0 && len == -1) verts = self->fThis->getVertices(idx); else verts = self->fThis->getVertices(start, len); PyObject* list = PyList_New(verts.size()); for (size_t i=0; i<verts.size(); i++) PyList_SET_ITEM(list, i, pyGBufferVertex_FromGBufferVertex(verts[i])); return list; }
PY_DEF(pyketama_Continuum_get_points, self, args) { PyObject *ret = NULL; pyketama_Continuum *pkc = (pyketama_Continuum *)self; if (pkc->cont->data->array) { int i; mcs (*mcsarr)[pkc->cont->data->numpoints] = &pkc->cont->data->array; ret = PyList_New(pkc->cont->data->numpoints); for (i = 0; i < pkc->cont->data->numpoints; i++) { PyList_SET_ITEM(ret, i, Py_BuildValue("Is", (*mcsarr)[i].point, (*mcsarr)[i].ip)); } } return ret; }
static PyObject * hash(PyObject * self, PyObject * args) { PyArrayObject * desc; PyObject * out_list; int cnt = 0; // get reference to the numpy.ndarray that OpenCV stores the descriptor matrix in if(!PyArg_ParseTuple(args, "O!", &PyArray_Type, &desc)) { PyErr_SetString(lsh_error, "Invalid arguments."); return NULL; } // get a pointer to the input matrix (must be contiguous!!!!!) unsigned char * arr = (unsigned char *)PyArray_DATA(desc); // get the dimensions of the input matrix npy_intp * dims = PyArray_DIMS(desc); // allocate output out_list = PyList_New(dims[0] * NUMBER_OF_TABLES); if(!out_list) { PyErr_SetString(lsh_error, "Failed to allocate list."); return NULL; } // for each feature... for(int i = 0; i < dims[0]; i++) { // for each table... for(int tb = 0; tb < NUMBER_OF_TABLES; tb++) { // hash the feature size_t key_raw = get_key(tb, arr); // store in the output PyObject * key = PyInt_FromSize_t(key_raw); PyList_SET_ITEM(out_list, cnt, key); cnt++; } // move to the next feature arr += FEATURE_SIZE; } return out_list; }
ULONG PyGMAPIAdviseSink::OnNotify(ULONG cNotif, LPNOTIFICATION lpNotifications ) { PY_GATEWAY_METHOD; PyObject *arg = PyList_New(cNotif); if (!arg) return MAKE_PYCOM_GATEWAY_FAILURE_CODE("OnNotify"); ULONG i; for (i=0;i<cNotif;i++) { PyObject *sub = PyObject_FromNOTIFICATION(lpNotifications+i); if (!sub) { Py_DECREF(arg); return MAKE_PYCOM_GATEWAY_FAILURE_CODE("OnNotify"); } PyList_SET_ITEM(arg, i, sub); } return InvokeViaPolicy("OnNotify", NULL, "(N)", arg); }
static void callback_dualtree2(void* v, int ind1, int ind2, double dist2) { struct dualtree_results2* dt = v; PyObject* lst; if (dt->permute) { ind1 = kdtree_permute(dt->kd1, ind1); ind2 = kdtree_permute(dt->kd2, ind2); } lst = PyList_GET_ITEM(dt->indlist, ind1); if (!lst) { lst = PyList_New(1); // SetItem steals a ref -- that's what we want. PyList_SetItem(dt->indlist, ind1, lst); PyList_SET_ITEM(lst, 0, PyInt_FromLong(ind2)); } else { PyList_Append(lst, PyInt_FromLong(ind2)); } }
static PyObject* launcharray2python(launch_data_t data) { size_t count = launch_data_array_get_count(data); size_t i; PyObject* result = PyList_New(count); for (i = 0; i < 0; i ++) { launch_data_t v = launch_data_array_get_index(data, i); PyList_SET_ITEM(result, i, launch2python(data)); } if (PyErr_Occurred()) { Py_DECREF(result); return NULL; } return result; }
static PyObject * Util_func_interface_addresses(PyObject *obj) { int i, count; char ip[INET6_ADDRSTRLEN]; uv_interface_address_t* interfaces; uv_err_t err; PyObject *result, *item, *exc_data; UNUSED_ARG(obj); err = uv_interface_addresses(&interfaces, &count); if (err.code == UV_OK) { result = PyList_New(count); if (!result) { uv_free_interface_addresses(interfaces, count); return NULL; } for (i = 0; i < count; i++) { item = PyStructSequence_New(&InterfaceAddressesResultType); if (!item) { Py_DECREF(result); uv_free_interface_addresses(interfaces, count); return NULL; } PyStructSequence_SET_ITEM(item, 0, Py_BuildValue("s", interfaces[i].name)); PyStructSequence_SET_ITEM(item, 1, PyBool_FromLong((long)interfaces[i].is_internal)); if (interfaces[i].address.address4.sin_family == AF_INET) { uv_ip4_name(&interfaces[i].address.address4, ip, INET_ADDRSTRLEN); } else if (interfaces[i].address.address4.sin_family == AF_INET6) { uv_ip6_name(&interfaces[i].address.address6, ip, INET6_ADDRSTRLEN); } PyStructSequence_SET_ITEM(item, 2, Py_BuildValue("s", ip)); PyList_SET_ITEM(result, i, item); } uv_free_interface_addresses(interfaces, count); return result; } else { exc_data = Py_BuildValue("(is)", err.code, uv_strerror(err)); if (exc_data != NULL) { PyErr_SetObject(PyExc_UVError, exc_data); Py_DECREF(exc_data); } return NULL; } }
// return Python list of values for this label. Return None if this label // has no values (e.g. Atom labels), or NULL on error. static PyObject *getvalues(GeometryMol *g) { if (!g->has_value()) { Py_INCREF(Py_None); return Py_None; } ResizeArray<float> gValues(1024); if (!g->calculate_all(gValues)) { PyErr_SetString(PyExc_ValueError, (char *)"Invalid label"); return NULL; } const int n = gValues.num(); PyObject *newlist = PyList_New(n); for (int i=0; i<n; i++) { PyList_SET_ITEM(newlist, i, PyFloat_FromDouble(gValues[i])); } return newlist; }
/** * Creates a Python list from a Mantid vector * @param values :: A reference to the MantidVec * @returns A standard Python list object */ PyObject * MantidVecHelper::createPythonList(const MantidVec & values) { const Py_ssize_t nVals = static_cast<Py_ssize_t>(values.size()); PyObject * pyValues = PyList_New(nVals); if( !pyValues ) { throw std::runtime_error("Cannot create Python list from Mantid vector."); } MantidVec::const_iterator iend = values.end(); Py_ssize_t index(0); for( MantidVec::const_iterator itr = values.begin(); itr != iend; ++itr ) { PyList_SET_ITEM(pyValues, index, PyFloat_FromDouble((*itr))); ++index; } return pyValues; }
/* * returns a Python list representing the arguments for the process * with given pid or NULL on error. */ PyObject * psutil_get_cmdline(long pid) { PyObject *ret = NULL; WCHAR *data = NULL; SIZE_T size; PyObject *py_retlist = NULL; PyObject *py_unicode = NULL; LPWSTR *szArglist = NULL; int nArgs, i; if (psutil_get_process_data(pid, KIND_CMDLINE, &data, &size) != 0) goto out; // attempt to parse the command line using Win32 API szArglist = CommandLineToArgvW(data, &nArgs); if (szArglist == NULL) { PyErr_SetFromWindowsErr(0); goto out; } // arglist parsed as array of UNICODE_STRING, so convert each to // Python string object and add to arg list py_retlist = PyList_New(nArgs); if (py_retlist == NULL) goto out; for (i = 0; i < nArgs; i++) { py_unicode = PyUnicode_FromWideChar(szArglist[i], wcslen(szArglist[i])); if (py_unicode == NULL) goto out; PyList_SET_ITEM(py_retlist, i, py_unicode); py_unicode = NULL; } ret = py_retlist; py_retlist = NULL; out: LocalFree(szArglist); free(data); Py_XDECREF(py_unicode); Py_XDECREF(py_retlist); return ret; }
PyObject* EntityGarbages<T>::pyValues() { ENTITYS_MAP& entities = getEntities(); PyObject* pyList = PyList_New(entities.size()); int i = 0; ENTITYS_MAP::const_iterator iter = entities.begin(); while (iter != entities.end()) { Py_INCREF(iter->second); PyList_SET_ITEM(pyList, i, iter->second); i++; iter++; } return pyList; }
PyObject* EntityGarbages<T>::pyKeys() { ENTITYS_MAP& entities = getEntities(); PyObject* pyList = PyList_New(entities.size()); int i = 0; ENTITYS_MAP::const_iterator iter = entities.begin(); while (iter != entities.end()) { PyObject* entityID = PyLong_FromLong(iter->first); PyList_SET_ITEM(pyList, i, entityID); i++; iter++; } return pyList; }
PyObject* CreatePyListFromStringVector(const std::vector<std::string> &data) { PyObject* returnlist = PyList_New( data.size() ); if(!returnlist) return 0; for(unsigned int i =0; i<data.size(); ++i) { PyObject *str = PyString_FromString(data[i].c_str()); if (str == NULL) { Py_DECREF(returnlist); return NULL; } PyList_SET_ITEM(returnlist, i, str); } return returnlist; }
static PyObject *bpy_bmdeformvert_items(BPy_BMDeformVert *self) { PyObject *ret; PyObject *item; int i; MDeformWeight *dw = self->data->dw; ret = PyList_New(self->data->totweight); for (i = 0; i < self->data->totweight; i++, dw++) { item = PyTuple_New(2); PyTuple_SET_ITEMS(item, PyLong_FromLong(dw->def_nr), PyFloat_FromDouble(dw->weight)); PyList_SET_ITEM(ret, i, item); } return ret; }
//------------------------------------------------------------------------------------- PyObject* PyBots::pyValues() { Bots::CLIENTS& refclients = Bots::getSingleton().clients(); PyObject* pyList = PyList_New(refclients.size()); int i = 0; Bots::CLIENTS::const_iterator iter = refclients.begin(); while (iter != refclients.end()) { Py_INCREF(iter->second); PyList_SET_ITEM(pyList, i, iter->second); i++; iter++; } return pyList; }
//------------------------------------------------------------------------------------- PyObject* PyBots::pyKeys() { Bots::CLIENTS& refclients = Bots::getSingleton().clients(); PyObject* pyList = PyList_New(refclients.size()); int i = 0; Bots::CLIENTS::const_iterator iter = refclients.begin(); while (iter != refclients.end()) { PyObject* clientID = PyLong_FromLong(iter->second->appID()); PyList_SET_ITEM(pyList, i, clientID); i++; iter++; } return pyList; }
static PyObject* pyResManager_getTypes(pyResManager* self, PyObject* args) { pyLocation* loc; char checkKeys = 0; if (!PyArg_ParseTuple(args, "O|b", &loc, &checkKeys)) { PyErr_SetString(PyExc_TypeError, "getTypes expects a plLocation"); return NULL; } if (!pyLocation_Check((PyObject*)loc)) { PyErr_SetString(PyExc_TypeError, "getTypes expects a plLocation"); return NULL; } std::vector<short> types = self->fThis->getTypes(*loc->fThis, (checkKeys != 0)); PyObject* list = PyList_New(types.size()); for (size_t i=0; i<types.size(); i++) PyList_SET_ITEM(list, i, PyInt_FromLong(types[i])); return list; }
/* http://docs.python.org/release/2.5.2/ext/callingPython.html */ static void py_guestfs_event_callback_wrapper (guestfs_h *g, void *callback, uint64_t event, int event_handle, int flags, const char *buf, size_t buf_len, const uint64_t *array, size_t array_len) { PyGILState_STATE py_save = PyGILState_UNLOCKED; PyObject *py_callback = callback; PyObject *py_array; PyObject *args; PyObject *a; size_t i; PyObject *py_r; py_array = PyList_New (array_len); for (i = 0; i < array_len; ++i) { a = PyLong_FromLongLong (array[i]); PyList_SET_ITEM (py_array, i, a); } /* XXX As with Perl we don't pass the guestfs_h handle here. */ args = Py_BuildValue ("(Kis#O)", (unsigned PY_LONG_LONG) event, event_handle, buf, buf_len, py_array); if (PyEval_ThreadsInitialized ()) py_save = PyGILState_Ensure (); py_r = PyEval_CallObject (py_callback, args); if (PyEval_ThreadsInitialized ()) PyGILState_Release (py_save); Py_DECREF (args); if (py_r != NULL) Py_DECREF (py_r); else /* Callback threw an exception: print it. */ PyErr_PrintEx (0); }
static PyObject* py_get_colorlist(PyObject *self, PyObject *args) { PyObject *newlist = NULL, *newtuple = NULL; int i, j, listlen; const char *name; float col[3]; VMDApp *app; if (!(app = get_vmdapp())) return NULL; listlen = app->num_regular_colors(); if (!(newlist = PyList_New(listlen))) goto failure; for (i = 0; i < listlen; i++) { name = app->color_name(i); if (!app->color_value(name, col, col+1, col+2)) goto failure; if (!(newtuple = PyTuple_New(3))) goto failure; for (j = 0; j < 3; j++) { PyTuple_SET_ITEM(newtuple, j, PyFloat_FromDouble(col[j])); if (PyErr_Occurred()) goto failure; } PyList_SET_ITEM(newlist, i, newtuple); if (PyErr_Occurred()) goto failure; } return newlist; failure: PyErr_SetString(PyExc_RuntimeError, "Problem getting color list"); Py_XDECREF(newlist); Py_XDECREF(newtuple); return NULL; }
static PyObject *py_kdtree_find_range(PyKDTree *self, PyObject *args, PyObject *kwargs) { PyObject *py_list; PyObject *py_co; float co[3]; KDTreeNearest *nearest = NULL; float radius; int i, found; const char *keywords[] = {"co", "radius", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "Of:find_range", (char **)keywords, &py_co, &radius)) { return NULL; } if (mathutils_array_parse(co, 3, 3, py_co, "find_range: invalid 'co' arg") == -1) return NULL; if (radius < 0.0f) { PyErr_SetString(PyExc_RuntimeError, "negative radius given"); return NULL; } if (self->count != self->count_balance) { PyErr_SetString(PyExc_RuntimeError, "KDTree must be balanced before calling find_range()"); return NULL; } found = BLI_kdtree_range_search(self->obj, co, &nearest, radius); py_list = PyList_New(found); for (i = 0; i < found; i++) { PyList_SET_ITEM(py_list, i, kdtree_nearest_to_py(&nearest[i])); } if (nearest) { MEM_freeN(nearest); } return py_list; }
static PyObject* spherematch_match2(PyObject* self, PyObject* args) { int i, N; long p1, p2; struct dualtree_results2 dtresults; kdtree_t *kd1, *kd2; double rad; PyObject* indlist; anbool notself; anbool permute; // So that ParseTuple("b") with a C "anbool" works assert(sizeof(anbool) == sizeof(unsigned char)); if (!PyArg_ParseTuple(args, "lldbb", &p1, &p2, &rad, ¬self, &permute)) { PyErr_SetString(PyExc_ValueError, "spherematch_c.match: need five args: two kdtree identifiers (ints), search radius (float), notself (boolean), permuted (boolean)"); return NULL; } // Nasty! kd1 = (kdtree_t*)p1; kd2 = (kdtree_t*)p2; N = kdtree_n(kd1); indlist = PyList_New(N); assert(indlist); dtresults.kd1 = kd1; dtresults.kd2 = kd2; dtresults.indlist = indlist; dtresults.permute = permute; dualtree_rangesearch(kd1, kd2, 0.0, rad, notself, NULL, callback_dualtree2, &dtresults, NULL, NULL); // set empty slots to None, not NULL. for (i=0; i<N; i++) { if (PyList_GET_ITEM(indlist, i)) continue; Py_INCREF(Py_None); PyList_SET_ITEM(indlist, i, Py_None); } return indlist; }