本文整理汇总了C++中PyTuple_GetItem函数的典型用法代码示例。如果您正苦于以下问题:C++ PyTuple_GetItem函数的具体用法?C++ PyTuple_GetItem怎么用?C++ PyTuple_GetItem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyTuple_GetItem函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: _pygi_closure_convert_arguments
static gboolean
_pygi_closure_convert_arguments (PyGIInvokeState *state,
PyGIClosureCache *closure_cache)
{
PyGICallableCache *cache = (PyGICallableCache *) closure_cache;
gssize n_in_args = 0;
gssize i;
for (i = 0; i < _pygi_callable_cache_args_len (cache); i++) {
PyGIArgCache *arg_cache;
arg_cache = g_ptr_array_index (cache->args_cache, i);
if (arg_cache->direction & PYGI_DIRECTION_TO_PYTHON) {
PyObject *value;
if (cache->user_data_index == i) {
if (state->user_data == NULL) {
/* user_data can be NULL for connect functions which don't accept
* user_data or as the default for user_data in the middle of function
* arguments.
*/
Py_INCREF (Py_None);
value = Py_None;
} else {
/* Extend the callbacks args with user_data as variable args. */
gssize j, user_data_len;
PyObject *py_user_data = state->user_data;
if (!PyTuple_Check (py_user_data)) {
PyErr_SetString (PyExc_TypeError, "expected tuple for callback user_data");
return FALSE;
}
user_data_len = PyTuple_Size (py_user_data);
_PyTuple_Resize (&state->py_in_args,
state->n_py_in_args + user_data_len - 1);
for (j = 0; j < user_data_len; j++, n_in_args++) {
value = PyTuple_GetItem (py_user_data, j);
Py_INCREF (value);
PyTuple_SET_ITEM (state->py_in_args, n_in_args, value);
}
/* We can assume user_data args are never going to be inout,
* so just continue here.
*/
continue;
}
} else if (arg_cache->meta_type != PYGI_META_ARG_TYPE_PARENT) {
continue;
} else {
value = arg_cache->to_py_marshaller (state,
cache,
arg_cache,
&state->args[i].arg_value);
if (value == NULL) {
pygi_marshal_cleanup_args_to_py_parameter_fail (state,
cache,
i);
return FALSE;
}
}
PyTuple_SET_ITEM (state->py_in_args, n_in_args, value);
n_in_args++;
}
}
if (_PyTuple_Resize (&state->py_in_args, n_in_args) == -1)
return FALSE;
return TRUE;
}
开发者ID:Distrotech,项目名称:pygobject,代码行数:74,代码来源:pygi-closure.c
示例2: pysqlite_row_item
PyObject* pysqlite_row_item(pysqlite_Row* self, Py_ssize_t idx)
{
PyObject* item = PyTuple_GetItem(self->data, idx);
Py_XINCREF(item);
return item;
}
开发者ID:corona10,项目名称:pyston,代码行数:6,代码来源:row.c
示例3: PyTuple_GetItem
PyObject *py_uwsgi_gevent_request(PyObject * self, PyObject * args) {
PyObject *ret;
PyObject *py_wsgi_req = PyTuple_GetItem(args, 0);
struct wsgi_request *wsgi_req = (struct wsgi_request *) PyLong_AsLong(py_wsgi_req);
int status ;
PyObject *current_greenlet = GET_CURRENT_GREENLET;
PyObject *greenlet_switch = PyObject_GetAttrString(current_greenlet, "switch");
uwsgi.wsgi_req = wsgi_req;
// create a watcher for request socket
PyObject *watcher = PyObject_CallMethod(ugevent.hub_loop, "io", "ii", wsgi_req->poll.fd, 1);
if (!watcher) goto clear1;
// a timer to implement timeoit (thanks Denis)
PyObject *timer = PyObject_CallMethod(ugevent.hub_loop, "timer", "i", uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
if (!timer) goto clear0;
for(;;) {
// wait for data in the socket
PyObject *ret = uwsgi_gevent_wait(watcher, timer, greenlet_switch);
if (!ret) goto clear_and_stop;
// do not forget to overwrite this pointer each time !!!
uwsgi.wsgi_req = wsgi_req;
// we can safely decref here as watcher and timer has got a +1 for start() method
Py_DECREF(ret);
if (ret == timer) {
uwsgi_log( "timeout. skip request.\n");
goto clear_and_stop;
}
else if (ret == watcher) {
status = wsgi_req->socket->proto(wsgi_req);
if (status < 0) {
goto clear_and_stop;
}
else if (status == 0) {
stop_the_watchers;
break;
}
}
else {
uwsgi_log("unrecognized gevent event !!!\n");
goto clear_and_stop;
}
stop_the_watchers;
}
for(;;) {
uwsgi.wsgi_req = wsgi_req;
wsgi_req->async_status = uwsgi.p[wsgi_req->uh.modifier1]->request(wsgi_req);
if (wsgi_req->async_status <= UWSGI_OK) {
goto clear;
}
// switch after each yield
GEVENT_SWITCH;
}
goto clear;
clear_and_stop:
stop_the_watchers;
clear:
Py_DECREF(timer);
clear0:
Py_DECREF(watcher);
clear1:
Py_DECREF(greenlet_switch);
Py_DECREF(current_greenlet);
uwsgi_close_request(wsgi_req);
uwsgi.wsgi_req = wsgi_req;
free_req_queue;
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:sashka,项目名称:uwsgi,代码行数:87,代码来源:gevent.c
示例4: image_init
static int image_init(PyImage *self,
PyObject *args,
PyObject *kwargs)
{
PyObject *initial;
int location = OSL_IN_VRAM;
int pf = OSL_PF_8888;
if (!PyArg_ParseTuple(args, "O|ii:__init__", &initial, &location, &pf))
return -1;
self->location = location;
if (PyString_Check(initial))
{
// Load from file
char *filename = PyString_AsString(initial);
self->pImg = oslLoadImageFile(filename, location, pf);
if (!self->pImg)
{
PyErr_SetString(osl_Error, "Could not load image.");
return -1;
}
}
else if (PyTuple_Check(initial))
{
int w, h;
if (PyTuple_Size(initial) != 2)
{
PyErr_SetString(PyExc_TypeError, "Image dimension must be a 2-tuple");
return -1;
}
if (!PyInt_Check(PyTuple_GetItem(initial, 0)))
{
PyErr_SetString(PyExc_TypeError, "Image width must be an integer");
return -1;
}
if (!PyInt_Check(PyTuple_GetItem(initial, 1)))
{
PyErr_SetString(PyExc_TypeError, "Image height must be an integer");
return -1;
}
w = PyInt_AsLong(PyTuple_GetItem(initial, 0));
h = PyInt_AsLong(PyTuple_GetItem(initial, 1));
self->pImg = oslCreateImage(w, h, location, pf);
if (!self->pImg)
{
PyErr_SetString(osl_Error, "Could not create image");
return -1;
}
}
else
{
PyErr_SetString(PyExc_TypeError, "First argument must be a filename or a 2-tuple");
return -1;
}
if (location == OSL_IN_VRAM)
{
FREEIMG *pFree = (FREEIMG*)malloc(sizeof(FREEIMG));
pFree->bDelete = 0;
pFree->pImg = self->pImg;
pFree->next = (void*)pCurrent;
pCurrent = pFree;
}
return 0;
}
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:78,代码来源:image.c
示例5: uwsgi_response_subhandler_web3
int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) {
PyObject *pychunk;
// ok its a yield
if (!wsgi_req->async_placeholder) {
if (PyTuple_Check((PyObject *)wsgi_req->async_result)) {
if (PyTuple_Size((PyObject *)wsgi_req->async_result) != 3) {
uwsgi_log("invalid Web3 response.\n");
goto clear;
}
wsgi_req->async_placeholder = PyTuple_GetItem((PyObject *)wsgi_req->async_result, 0);
Py_INCREF((PyObject *)wsgi_req->async_placeholder);
PyObject *spit_args = PyTuple_New(2);
PyObject *status = PyTuple_GetItem((PyObject *)wsgi_req->async_result, 1);
Py_INCREF(status);
PyTuple_SetItem(spit_args, 0, status);
PyObject *headers = PyTuple_GetItem((PyObject *)wsgi_req->async_result, 2);
Py_INCREF(headers);
PyTuple_SetItem(spit_args, 1, headers);
if (py_uwsgi_spit(Py_None, spit_args) == NULL) {
PyErr_Print();
Py_DECREF(spit_args);
goto clear;
}
// send the headers if not already sent
if (!wsgi_req->headers_sent && wsgi_req->headers_hvec > 0) {
uwsgi_python_do_send_headers(wsgi_req);
}
Py_DECREF(spit_args);
if (PyString_Check((PyObject *)wsgi_req->async_placeholder)) {
char *content = PyString_AsString(wsgi_req->async_placeholder);
size_t content_len = PyString_Size(wsgi_req->async_placeholder);
UWSGI_RELEASE_GIL
wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len);
UWSGI_GET_GIL
uwsgi_py_check_write_errors {
uwsgi_py_write_exception(wsgi_req);
}
goto clear;
}
PyObject *tmp = (PyObject *)wsgi_req->async_placeholder;
wsgi_req->async_placeholder = PyObject_GetIter( (PyObject *)wsgi_req->async_placeholder );
Py_DECREF(tmp);
if (!wsgi_req->async_placeholder) {
goto clear;
}
#ifdef UWSGI_ASYNC
if (uwsgi.async > 1) {
return UWSGI_AGAIN;
}
#endif
}
else {
开发者ID:theflockers,项目名称:file-uploader,代码行数:68,代码来源:web3_subhandler.c
示例6: PyTuple_Size
// Register signal change callback
// First argument should be the signal handle
// Second argument is the function to call
// Remaining arguments and keyword arguments are to be passed to the callback
static PyObject *register_value_change_callback(PyObject *self, PyObject *args) //, PyObject *keywds)
{
FENTER
PyObject *fArgs;
PyObject *function;
gpi_sim_hdl sig_hdl;
gpi_sim_hdl hdl;
unsigned int edge;
p_callback_data callback_data_p;
Py_ssize_t numargs = PyTuple_Size(args);
if (numargs < 3) {
fprintf(stderr, "Attempt to register value change callback without enough arguments!\n");
return NULL;
}
PyObject *pSihHdl = PyTuple_GetItem(args, 0);
if (!gpi_sim_hdl_converter(pSihHdl, &sig_hdl)) {
return NULL;
}
// Extract the callback function
function = PyTuple_GetItem(args, 1);
if (!PyCallable_Check(function)) {
fprintf(stderr, "Attempt to register value change callback without passing a callable callback!\n");
return NULL;
}
Py_INCREF(function);
PyObject *pedge = PyTuple_GetItem(args, 2);
edge = (unsigned int)PyLong_AsLong(pedge);
// Remaining args for function
fArgs = PyTuple_GetSlice(args, 3, numargs); // New reference
if (fArgs == NULL) {
return NULL;
}
callback_data_p = (p_callback_data)malloc(sizeof(s_callback_data));
if (callback_data_p == NULL) {
return PyErr_NoMemory();
}
// Set up the user data (no more python API calls after this!)
// Causes segfault?
callback_data_p->_saved_thread_state = PyThreadState_Get();//PyThreadState_Get();
callback_data_p->id_value = COCOTB_ACTIVE_ID;
callback_data_p->function = function;
callback_data_p->args = fArgs;
callback_data_p->kwargs = NULL;
hdl = gpi_register_value_change_callback((gpi_function_t)handle_gpi_callback,
callback_data_p,
sig_hdl,
edge);
// Check success
PyObject *rv = PyLong_FromVoidPtr(hdl);
FEXIT
return rv;
}
开发者ID:TC01,项目名称:cocotb,代码行数:70,代码来源:simulatormodule.c
示例7: pyobj_send
void pyobj_send(t_outlet*const outlet,PyObject*const value)
{
if(!value);
else if(value==Py_True)
outlet_bang(outlet);
else if(value==Py_False)
outlet_symbol(outlet,&s_);
else if(PyInt_Check(value))
outlet_float(outlet,PyInt_AsLong(value));
else if(PyFloat_Check(value))
outlet_float(outlet,PyFloat_AsDouble(value));
else if(PyString_Check(value))
outlet_symbol(outlet,gensym(PyString_AsString(value)));
else if(PyDict_Check(value))
{
}
else if(PyList_Check(value))
{
register int k,K;
Py_ssize_t size=PyList_Size(value);
t_atom*atom=(t_atom*)calloc(sizeof(t_atom),size);
for(k=0,K=size;k<K;++k)
{
PyObject*obj=PyList_GetItem(value,k);
if(!obj)
SETSYMBOL(atom+k,&s_);
else if(obj==Py_True)
SETFLOAT(atom+k,1);
else if(obj==Py_False)
SETSYMBOL(atom+k,&s_);
else if(PyInt_Check(obj))
SETFLOAT(atom+k,PyInt_AsLong(obj));
else if(PyFloat_Check(obj))
SETFLOAT(atom+k,PyFloat_AsDouble(obj));
else
SETSYMBOL(atom+k,&s_);
}
outlet_list(outlet,gensym("list"),size,atom);
}
else if(PyTuple_Check(value))
{
register int k,K;
Py_ssize_t size=PyTuple_Size(value);
t_atom*atom=(t_atom*)calloc(sizeof(t_atom),size);
for(k=0,K=size;k<K;++k)
{
PyObject*obj=PyTuple_GetItem(value,k);
if(!obj)
SETSYMBOL(atom+k,&s_);
else if(obj==Py_True)
SETFLOAT(atom+k,1);
else if(obj==Py_False)
SETSYMBOL(atom+k,&s_);
else if(PyInt_Check(obj))
SETFLOAT(atom+k,PyInt_AsLong(obj));
else if(PyFloat_Check(obj))
SETFLOAT(atom+k,PyFloat_AsDouble(obj));
else
SETSYMBOL(atom+k,&s_);
}
outlet_list(outlet,gensym("list"),size,atom);
}
}
开发者ID:kotan-kn,项目名称:pdvms,代码行数:63,代码来源:send.c
示例8: AerospikeClient_InfoNode_Invoke
/**
******************************************************************************************************
* Returns data for a particular request string to AerospikeClient_InfoNode
*
* @param self AerospikeClient object
* @param request_str_p Request string sent from the python client
* @param py_host Optional host sent from the python client
* @param py_policy The policy sent from the python client
*
* Returns information about a host.
********************************************************************************************************/
static PyObject * AerospikeClient_InfoNode_Invoke(
AerospikeClient * self,
PyObject * py_request_str, PyObject * py_host, PyObject * py_policy) {
PyObject * py_response = NULL;
PyObject * py_ustr = NULL;
PyObject * py_ustr1 = NULL;
as_policy_info info_policy;
as_policy_info* info_policy_p = NULL;
char* address = (char *) self->as->config.hosts[0].addr;
long port_no = self->as->config.hosts[0].port;
char* response_p = NULL;
as_status status = AEROSPIKE_OK;
as_error err;
as_error_init(&err);
if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster");
goto CLEANUP;
}
if (py_policy) {
if( PyDict_Check(py_policy) ) {
pyobject_to_policy_info(&err, py_policy, &info_policy, &info_policy_p,
&self->as->config.policies.info);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
} else {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Policy should be a dictionary");
goto CLEANUP;
}
}
if ( py_host ) {
if ( PyTuple_Check(py_host) && PyTuple_Size(py_host) == 2) {
PyObject * py_addr = PyTuple_GetItem(py_host,0);
PyObject * py_port = PyTuple_GetItem(py_host,1);
if ( PyString_Check(py_addr) ) {
address = PyString_AsString(py_addr);
} else if (PyUnicode_Check(py_addr)) {
py_ustr = PyUnicode_AsUTF8String(py_addr);
address = PyString_AsString(py_ustr);
}
if ( PyInt_Check(py_port) ) {
port_no = (uint16_t) PyInt_AsLong(py_port);
}
else if ( PyLong_Check(py_port) ) {
port_no = (uint16_t) PyLong_AsLong(py_port);
}
} else if ( !PyTuple_Check(py_host)){
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Host should be a specified in form of Tuple.");
goto CLEANUP;
}
}
char * request_str_p = NULL;
if (PyUnicode_Check(py_request_str)) {
py_ustr1 = PyUnicode_AsUTF8String(py_request_str);
request_str_p = PyString_AsString(py_ustr1);
} else if (PyString_Check(py_request_str)) {
request_str_p = PyString_AsString(py_request_str);
} else {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Request should be of string type");
goto CLEANUP;
}
status = aerospike_info_host(self->as, &err, info_policy_p,
(const char *) address, (uint16_t) port_no, request_str_p,
&response_p);
if( err.code == AEROSPIKE_OK ) {
if (response_p && status == AEROSPIKE_OK){
py_response = PyString_FromString(response_p);
free(response_p);
} else if ( response_p == NULL){
as_error_update(&err, AEROSPIKE_ERR_CLIENT, "Invalid info operation");
goto CLEANUP;
} else if ( status != AEROSPIKE_OK ){
as_error_update(&err, status, "Info operation failed");
goto CLEANUP;
}
} else {
//.........这里部分代码省略.........
开发者ID:Kavec,项目名称:aerospike-client-python,代码行数:101,代码来源:info_node.c
示例9: Merge
static char *
Merge(PyObject *args)
{
PyObject *tmp = NULL;
char *argvStore[ARGSZ];
char **argv = NULL;
int fvStore[ARGSZ];
int *fv = NULL;
int argc = 0, fvc = 0, i;
char *res = NULL;
if (!(tmp = PyList_New(0)))
return NULL;
argv = argvStore;
fv = fvStore;
if (args == NULL)
argc = 0;
else if (!PyTuple_Check(args)) {
argc = 1;
fv[0] = 0;
if (!(argv[0] = AsString(args, tmp)))
goto finally;
}
else {
argc = PyTuple_Size(args);
if (argc > ARGSZ) {
argv = (char **)ckalloc(argc * sizeof(char *));
fv = (int *)ckalloc(argc * sizeof(int));
if (argv == NULL || fv == NULL) {
PyErr_NoMemory();
goto finally;
}
}
for (i = 0; i < argc; i++) {
PyObject *v = PyTuple_GetItem(args, i);
if (PyTuple_Check(v)) {
fv[i] = 1;
if (!(argv[i] = Merge(v)))
goto finally;
fvc++;
}
else if (v == Py_None) {
argc = i;
break;
}
else {
fv[i] = 0;
if (!(argv[i] = AsString(v, tmp)))
goto finally;
fvc++;
}
}
}
res = Tcl_Merge(argc, argv);
if (res == NULL)
PyErr_SetString(Tkinter_TclError, "merge failed");
finally:
for (i = 0; i < fvc; i++)
if (fv[i]) {
ckfree(argv[i]);
}
if (argv != argvStore)
ckfree(FREECAST argv);
if (fv != fvStore)
ckfree(FREECAST fv);
Py_DECREF(tmp);
return res;
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:75,代码来源:_tkinter.c
示例10: _buffer_format_string
static int
_buffer_format_string(PyArray_Descr *descr, _tmp_string_t *str,
PyArrayObject* arr, Py_ssize_t *offset,
char *active_byteorder)
{
int k;
char _active_byteorder = '@';
Py_ssize_t _offset = 0;
if (active_byteorder == NULL) {
active_byteorder = &_active_byteorder;
}
if (offset == NULL) {
offset = &_offset;
}
if (descr->subarray) {
PyObject *item, *subarray_tuple;
Py_ssize_t total_count = 1;
Py_ssize_t dim_size;
char buf[128];
int old_offset;
int ret;
if (PyTuple_Check(descr->subarray->shape)) {
subarray_tuple = descr->subarray->shape;
Py_INCREF(subarray_tuple);
}
else {
subarray_tuple = Py_BuildValue("(O)", descr->subarray->shape);
}
_append_char(str, '(');
for (k = 0; k < PyTuple_GET_SIZE(subarray_tuple); ++k) {
if (k > 0) {
_append_char(str, ',');
}
item = PyTuple_GET_ITEM(subarray_tuple, k);
dim_size = PyNumber_AsSsize_t(item, NULL);
PyOS_snprintf(buf, sizeof(buf), "%ld", (long)dim_size);
_append_str(str, buf);
total_count *= dim_size;
}
_append_char(str, ')');
Py_DECREF(subarray_tuple);
old_offset = *offset;
ret = _buffer_format_string(descr->subarray->base, str, arr, offset,
active_byteorder);
*offset = old_offset + (*offset - old_offset) * total_count;
return ret;
}
else if (PyDataType_HASFIELDS(descr)) {
int base_offset = *offset;
_append_str(str, "T{");
for (k = 0; k < PyTuple_GET_SIZE(descr->names); ++k) {
PyObject *name, *item, *offset_obj, *tmp;
PyArray_Descr *child;
char *p;
Py_ssize_t len;
int new_offset;
name = PyTuple_GET_ITEM(descr->names, k);
item = PyDict_GetItem(descr->fields, name);
child = (PyArray_Descr*)PyTuple_GetItem(item, 0);
offset_obj = PyTuple_GetItem(item, 1);
new_offset = base_offset + PyInt_AsLong(offset_obj);
/* Insert padding manually */
if (*offset > new_offset) {
PyErr_SetString(PyExc_RuntimeError,
"This should never happen: Invalid offset in "
"buffer format string generation. Please "
"report a bug to the Numpy developers.");
return -1;
}
while (*offset < new_offset) {
_append_char(str, 'x');
++*offset;
}
/* Insert child item */
_buffer_format_string(child, str, arr, offset,
active_byteorder);
/* Insert field name */
#if defined(NPY_PY3K)
/* FIXME: XXX -- should it use UTF-8 here? */
tmp = PyUnicode_AsUTF8String(name);
#else
tmp = name;
#endif
if (tmp == NULL || PyBytes_AsStringAndSize(tmp, &p, &len) < 0) {
PyErr_SetString(PyExc_ValueError, "invalid field name");
return -1;
}
//.........这里部分代码省略.........
开发者ID:87,项目名称:numpy,代码行数:101,代码来源:buffer.c
示例11: addType
bool addType(const char *name, PyObject *klass) {
bool singleton = false;
std::string desc;
PyObject *sg = PyObject_GetAttrString(klass, "Singleton");
if (!sg) {
PyErr_Clear();
} else {
if (PyBool_Check(sg)) {
singleton = (sg == Py_True);
}
Py_DECREF(sg);
}
PyObject *de = PyObject_GetAttrString(klass, "Description");
if (!de) {
PyErr_Clear();
} else {
if (PyString_Check(de)) {
desc = PyString_AsString(de);
}
Py_DECREF(de);
}
PyObject *mt = PyObject_GetAttrString(klass, "Methods");
if (!mt || !PyDict_Check(mt)) {
std::cout << "pyloader: Missing \"Methods\" class member" << std::endl;
Py_XDECREF(mt);
return false;
}
if (PyDict_Size(mt) == 0) {
std::cout << "pyloader: No keys in \"Methods\" dict" << std::endl;
Py_DECREF(mt);
return false;
}
lwc::MethodsTable *typeMethods = 0;
PyObject *key;
PyObject *value;
Py_ssize_t pos = 0;
while (PyDict_Next(mt, &pos, &key, &value)) {
if (!PyString_Check(key) || !PyTuple_Check(value)) {
std::cout << "pyloader: \"Methods\" must be a dict of tuples" << std::endl;
continue;
}
bool add = true;
char *mname = PyString_AsString(key);
char *mdesc = NULL;
long n = PyTuple_Size(value);
if (n < 1 || n > 2) {
std::cout << "pyloader: \"Methods\" dict values must be tuples with 1 to 2 elements" << std::endl;
continue;
}
PyObject *args = PyTuple_GetItem(value, 0);
if (!PyList_Check(args)) {
std::cout << "pyloader: \"Methods\" dict values' tuple first element must be a list" << std::endl;
continue;
}
if (n == 2) {
PyObject *pdesc = PyTuple_GetItem(value, 1);
if (!PyString_Check(pdesc)) {
std::cout << "pyloader: \"Methods\" dict values' tuple second element must be a string" << std::endl;
continue;
}
mdesc = PyString_AsString(pdesc);
}
lwc::Method meth;
if (mdesc) {
meth.setDescription(mdesc);
}
n = PyList_Size(args);
for (long i=0; i<n; ++i) {
PyObject *arg = PyList_GetItem(args, i);
Py_ssize_t ts = PyTuple_Size(arg);
if (!PyTuple_Check(arg) || ts < 2 || ts > 6) {
std::cout << "pyloader: Arguments must be tuples with 2 to 6 elements" << std::endl;
add = false;
break;
}
lwc::Argument a;
a.setDir(lwc::Direction(PyInt_AsLong(PyTuple_GetItem(arg, 0))));
a.setType(lwc::Type(PyInt_AsLong(PyTuple_GetItem(arg, 1))));
if (ts >= 3) {
a.setArraySizeArg(PyInt_AsLong(PyTuple_GetItem(arg, 2)));
}
if (ts >= 4) {
//.........这里部分代码省略.........
开发者ID:gatgui,项目名称:lwc,代码行数:101,代码来源:pyloader.cpp
示例12: get_module_code
/* Get the code object associated with the module specified by
'fullname'. */
static PyObject *
get_module_code(ZipImporter *self, PyObject *fullname,
int *p_ispackage, PyObject **p_modpath)
{
PyObject *code = NULL, *toc_entry, *subname;
PyObject *path, *fullpath = NULL;
struct st_zip_searchorder *zso;
subname = get_subname(fullname);
if (subname == NULL)
return NULL;
path = make_filename(self->prefix, subname);
Py_DECREF(subname);
if (path == NULL)
return NULL;
for (zso = zip_searchorder; *zso->suffix; zso++) {
code = NULL;
fullpath = PyUnicode_FromFormat("%U%s", path, zso->suffix);
if (fullpath == NULL)
goto exit;
if (Py_VerboseFlag > 1)
PySys_FormatStderr("# trying %U%c%U\n",
self->archive, (int)SEP, fullpath);
toc_entry = PyDict_GetItem(self->files, fullpath);
if (toc_entry != NULL) {
time_t mtime = 0;
int ispackage = zso->type & IS_PACKAGE;
int isbytecode = zso->type & IS_BYTECODE;
if (isbytecode) {
mtime = get_mtime_of_source(self, fullpath);
if (mtime == (time_t)-1 && PyErr_Occurred()) {
goto exit;
}
}
Py_CLEAR(fullpath);
if (p_ispackage != NULL)
*p_ispackage = ispackage;
code = get_code_from_data(self, ispackage,
isbytecode, mtime,
toc_entry);
if (code == Py_None) {
/* bad magic number or non-matching mtime
in byte code, try next */
Py_DECREF(code);
continue;
}
if (code != NULL && p_modpath != NULL) {
*p_modpath = PyTuple_GetItem(toc_entry, 0);
Py_INCREF(*p_modpath);
}
goto exit;
}
else
Py_CLEAR(fullpath);
}
PyErr_Format(ZipImportError, "can't find module %R", fullname);
exit:
Py_DECREF(path);
Py_XDECREF(fullpath);
return code;
}
开发者ID:cpcloud,项目名称:cpython,代码行数:68,代码来源:zipimport.c
示例13: oXformProperty_setValues
static PyObject * oXformProperty_setValues(PyObject * self, PyObject * args)
{
ALEMBIC_TRY_STATEMENT
oXformProperty * prop = (oXformProperty*)self;
if(prop->mArchive == NULL)
{
PyErr_SetString(getError(), "Archive already closed!");
return NULL;
}
PyObject * tuple = NULL;
if(!PyArg_ParseTuple(args, "O", &tuple))
{
PyErr_SetString(getError(), "No sample tuple specified!");
return NULL;
}
if(!PyTuple_Check(tuple) && !PyList_Check(tuple))
{
PyErr_SetString(getError(), "Sample tuple argument is not a tuple!");
return NULL;
}
/*if(prop->mMembers->mXformSchema.getNumSamples() >= prop->mMaxNbSamples)
{
PyErr_SetString(getError(), "Already stored the maximum number of samples!");
return NULL;
}*/
size_t nbItems = 0;
if(PyTuple_Check(tuple))
nbItems = PyTuple_Size(tuple);
else
nbItems = PyList_Size(tuple);
if(nbItems != 16)
{
PyErr_SetString(getError(), "Sample tuple should contain 16 items!");
return NULL;
}
std::vector<double> values(16);
for(size_t i=0;i<16;i++)
{
PyObject * item = NULL;
if(PyTuple_Check(tuple))
item = PyTuple_GetItem(tuple,i);
else
item = PyList_GetItem(tuple,i);
if(!PyArg_Parse(item,"d",&values[i]))
{
PyErr_SetString(getError(), "Some item of the sample tuple is not a floating point number!");
return NULL;
}
}
Imath::M44d matrix(values[0],values[1],values[2],values[3],values[4],values[5],values[6],values[7],
values[8],values[9],values[10],values[11],values[12],values[13],values[14],values[15]);
prop->mMembers->mSample.setInheritsXforms(true);
prop->mMembers->mSample.setMatrix(matrix);
prop->mMembers->mXformSchema.set(prop->mMembers->mSample);
return Py_BuildValue("I",prop->mMembers->mXformSchema.getNumSamples());
ALEMBIC_PYOBJECT_CATCH_STATEMENT
}
开发者ID:EriLee,项目名称:ExocortexCrate,代码行数:65,代码来源:oxformproperty.cpp
示例14: _pygi_marshal_from_py_interface_callback
static gboolean
_pygi_marshal_from_py_interface_callback (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
PyObject *py_arg,
GIArgument *arg,
gpointer *cleanup_data)
{
GICallableInfo *callable_info;
PyGICClosure *closure;
PyGIArgCache *user_data_cache = NULL;
PyGIArgCache *destroy_cache = NULL;
PyGICallbackCache *callback_cache;
PyObject *py_user_data = NULL;
callback_cache = (PyGICallbackCache *)arg_cache;
if (callback_cache->user_data_index > 0) {
user_data_cache = _pygi_callable_cache_get_arg (callable_cache, callback_cache->user_data_index);
if (user_data_cache->py_arg_index < state->n_py_in_args) {
/* py_user_data is a borrowed reference. */
py_user_data = PyTuple_GetItem (state->py_in_args, user_data_cache->py_arg_index);
if (!py_user_data)
return FALSE;
/* NULL out user_data if it was not supplied and the default arg placeholder
* was used instead.
*/
if (py_user_data == _PyGIDefaultArgPlaceholder) {
py_user_data = NULL;
} else if (callable_cache->user_data_varargs_index < 0) {
/* For non-variable length user data, place the user data in a
* single item tuple which is concatenated to the callbacks arguments.
* This allows callback input arg marshaling to always expect a
* tuple for user data. Note the
*/
py_user_data = Py_BuildValue("(O)", py_user_data, NULL);
} else {
/* increment the ref borrowed from PyTuple_GetItem above */
Py_INCREF (py_user_data);
}
}
}
if (py_arg == Py_None) {
return TRUE;
}
if (!PyCallable_Check (py_arg)) {
PyErr_Format (PyExc_TypeError,
"Callback needs to be a function or method not %s",
py_arg->ob_type->tp_name);
return FALSE;
}
callable_info = (GICallableInfo *)callback_cache->interface_info;
closure = _pygi_make_native_closure (callable_info, callback_cache->scope, py_arg, py_user_data);
arg->v_pointer = closure->closure;
/* always decref the user data as _pygi_make_native_closure adds its own ref */
Py_XDECREF (py_user_data);
/* The PyGICClosure instance is used as user data passed into the C function.
* The return trip to python will marshal this back and pull the python user data out.
*/
if (user_data_cache != NULL) {
state->args[user_data_cache->c_arg_index].arg_value.v_pointer = closure;
}
/* Setup a GDestroyNotify callback if this method supports it along with
* a user data field. The user data field is a requirement in order
* free resources and ref counts associated with this arguments closure.
* In case a user data field is not available, show a warning giving
* explicit information and setup a dummy notification to avoid a crash
* later on in _pygi_destroy_notify_callback_closure.
*/
if (callback_cache->destroy_notify_index > 0) {
destroy_cache = _pygi_callable_cache_get_arg (callable_cache, callback_cache->destroy_notify_index);
}
if (destroy_cache) {
if (user_data_cache != NULL) {
state->args[destroy_cache->c_arg_index].arg_value.v_pointer = _pygi_invoke_closure_free;
} else {
char *full_name = pygi_callable_cache_get_full_name (callable_cache);
gchar *msg = g_strdup_printf("Callables passed to %s will leak references because "
"the method does not support a user_data argument. "
"See: https://bugzilla.gnome.org/show_bug.cgi?id=685598",
full_name);
g_free (full_name);
if (PyErr_WarnEx(PyExc_RuntimeWarning, msg, 2)) {
g_free(msg);
_pygi_invoke_closure_free(closure);
return FALSE;
}
g_free(msg);
state->args[destroy_cache->c_arg_index].arg_value.v_pointer = _pygi_destroy_notify_dummy;
}
}
//.........这里部分代码省略.........
开发者ID:Distrotech,项目名称:pygobject,代码行数:101,代码来源:pygi-closure.c
示例15: cpmaximum
static PyObject *
cpmaximum(PyObject *self, PyObject *args)
{
PyObject *image = NULL; /* the image ndarray */
PyObject *cimage = NULL; /* a contiguous version of the array */
PyObject *structure = NULL; /* the structure ndarray */
PyObject *cstructure= NULL; /* a contiguous version of the structure */
PyObject *im_shape = NULL; /* the image shape sequence */
PyObject *str_shape = NULL; /* the structure shape sequence */
PyObject *offset = NULL; /* 2-tuple giving the x and y offset of the origin of the structuring element */
long height = 0; /* the image height */
long width = 0; /* the image width */
long strheight = 0; /* the structuring element height */
long strwidth = 0; /* the structuring element width */
PyObject *output = NULL; /* the output ndarray */
double *imdata = NULL; /* the image data */
char *strdata = NULL; /* the structure data (really boolean) */
double *out_data = NULL; /* the output data */
const char *error = NULL;
PyObject **shapes[] = { &im_shape, &im_shape, &str_shape, &str_shape };
long *slots[] = { &width, &height, &strwidth, &strheight };
int indices[] = { 0,1,0,1 };
int i = 0;
int j = 0;
int k = 0;
int l = 0;
npy_intp dims[2];
long xoff = 0;
long yoff = 0;
image = PySequence_GetItem(args,0);
if (! image) {
error = "Failed to get image from arguments";
goto exit;
}
cimage = PyArray_ContiguousFromAny(image, NPY_DOUBLE,2,2);
if (! cimage) {
error = "Failed to make a contiguous array from first argument";
goto exit;
}
structure = PySequence_GetItem(args,1);
if (! structure) {
error = "Failed to get structuring element from arguments";
goto exit;
}
cstructure = PyArray_ContiguousFromAny(structure, NPY_BOOL,2,2);
if (! cstructure) {
error = "Failed to make a contiguous array from second argument";
goto exit;
}
im_shape = PyObject_GetAttrString(cimage,"shape");
if (! im_shape) {
error = "Failed to get image.shape";
goto exit;
}
if (! PyTuple_Check(im_shape)) {
error = "image.shape not a tuple";
goto exit;
}
if (PyTuple_Size(im_shape) != 2) {
error = "image is not 2D";
goto exit;
}
str_shape = PyObject_GetAttrString(cstructure,"shape");
if (! str_shape) {
error = "Failed to get structure.shape";
goto exit;
}
if (! PyTuple_Check(str_shape)) {
error = "structure.shape not a tuple";
goto exit;
}
if (PyTuple_Size(str_shape) != 2) {
error = "structure is not 2D";
goto exit;
}
for (i=0;i<4;i++) {
PyObject *obDim = PyTuple_GetItem(*shapes[i],indices[i]);
*(slots[i]) = PyInt_AsLong(obDim);
if (PyErr_Occurred()) {
error = "Array shape is not a tuple of integers";
goto exit;
}
}
imdata = (double *)PyArray_DATA(cimage);
if (! imdata) {
error = "Failed to get image data";
goto exit;
}
strdata = (char *)PyArray_DATA(cstructure);
if (! strdata) {
error = "Failed to get structure data";
goto exit;
}
offset = PySequence_GetItem(args,2);
if (! offset) {
error = "Failed to get offset into structure from args";
goto exit;
}
//.........这里部分代码省略.........
开发者ID:simone-codeluppi,项目名称:CellProfiler,代码行数:101,代码来源:cpmorphology.c
示例16: Tkapp_Call
static PyObject *
Tkapp_Call(PyObject *self, PyObject *args)
{
Tcl_Obj *objStore[ARGSZ];
Tcl_Obj **objv = NULL;
int objc = 0, i;
PyObject *res = NULL;
Tcl_Interp *interp = Tkapp_Interp(self);
/* Could add TCL_EVAL_GLOBAL if wrapped by GlobalCall... */
int flags = TCL_EVAL_DIRECT;
objv = objStore;
if (args == NULL)
objc = 0;
else if (!PyTuple_Check(args)) {
objc = 1;
objv[0] = AsObj(args);
if (objv[0] == 0)
goto finally;
Tcl_IncrRefCount(objv[0]);
}
else {
objc = PyTuple_Size(args);
if (objc > ARGSZ) {
objv = (Tcl_Obj **)ckalloc(objc * sizeof(char *));
if (objv == NULL) {
PyErr_NoMemory();
goto finally;
}
}
for (i = 0; i < objc; i++) {
PyObject *v = PyTuple_GetItem(args, i);
if (v == Py_None) {
objc = i;
break;
}
objv[i] = AsObj(v);
if (!objv[i])
goto finally;
Tcl_IncrRefCount(objv[i]);
}
}
ENTER_TCL
i = Tcl_EvalObjv(interp, objc, objv, flags);
ENTER_OVERLAP
if (i == TCL_ERROR)
Tkinter_Error(self);
else {
/* We could request the object result here, but doing
so would confuse applications that expect a string. */
char *s = Tcl_GetStringResult(interp);
char *p = s;
/* If the result contains any bytes with the top bit set,
it's UTF-8 and we should decode it to Unicode */
while (*p != '\0') {
if (*p & 0x80)
break;
p++;
}
if (*p == '\0')
res = PyString_FromStringAndSize(s, (int)(p-s));
else {
/* Convert UTF-8 to Unicode string */
p = strchr(p, '\0');
res = PyUnicode_DecodeUTF8(s, (int)(p-s), "strict");
if (res == NULL) {
PyErr_Clear();
res = PyString_FromStringAndSize(s, (int)(p-s));
}
}
}
LEAVE_OVERLAP_TCL
finally:
for (i = 0; i < objc; i++)
Tcl_DecrRefCount(objv[i]);
if (objv != objStore)
ckfree(FREECAST objv);
return res;
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:88,代码来源:_tkinter.c
示例17: pygi_collect_attributes
/* Hall of shame, wasted time debugging the code below
* 20min - Johan 2009-02-19
*/
static PyObject *
pygi_collect_attributes (PyObject *self,
PyObject *args)
{
char *tag_name;
PyObject *attributes;
int indent, indent_len, i, j, self_indent;
char *indent_char;
gboolean first;
GString *attr_value = NULL;
int len;
PyObject *result = NULL;
if (!PyArg_ParseTuple(args, "sO!isi",
&tag_name, &PyList_Type, &attributes,
&self_indent, &indent_char,
&indent))
return NULL;
if (attributes == Py_None || !PyList_Size(attributes))
return PyUnicode_DecodeUTF8("", 0, "strict");
len = calc_attrs_length(attributes, indent, self_indent);
if (len < 0)
return NULL;
if (len > 79)
indent_len = self_indent + strlen(tag_name) + 1;
else
indent_len = 0;
first = TRUE;
attr_value = g_string_new ("");
for (i = 0; i < PyList_Size (attributes); ++i)
{
PyObject *tuple, *pyvalue;
char *attr, *value, *escaped;
tuple = Py
|
请发表评论