static PyObject *_tkinit(PyObject *self, PyObject *args) { Tcl_Interp *interp; TkappObject *app; PyObject *arg; int is_interp; if (!PyArg_ParseTuple(args, "Oi", &arg, &is_interp)) { return NULL; } if (is_interp) { interp = (Tcl_Interp *)PyLong_AsVoidPtr(arg); } else { /* Do it the hard way. This will break if the TkappObject layout changes */ app = (TkappObject *)PyLong_AsVoidPtr(arg); interp = app->interp; } /* This will bomb if interp is invalid... */ TCL_CREATE_COMMAND(interp, "PyAggImagePhoto", (Tcl_CmdProc *)PyAggImagePhoto, (ClientData)0, (Tcl_CmdDeleteProc *)NULL); Py_INCREF(Py_None); return Py_None; }
static PyObject * memsys_set_atomic_inc_dec(PyObject *self, PyObject *args) { PyObject *addr_inc_obj, *addr_dec_obj; void *addr_inc, *addr_dec; if (!PyArg_ParseTuple(args, "OO", &addr_inc_obj, &addr_dec_obj)) { return NULL; } addr_inc = PyLong_AsVoidPtr(addr_inc_obj); if(PyErr_Occurred()) return NULL; addr_dec = PyLong_AsVoidPtr(addr_dec_obj); if(PyErr_Occurred()) return NULL; NRT_MemSys_set_atomic_inc_dec(addr_inc, addr_dec); Py_RETURN_NONE; }
static int set_void_ptr(void **vpp, PyObject *o, const char *name) { void *vp = 0; if (check_value(o, name)) { return -1; } if (INT_CHECK(o)) { vp = PyLong_AsVoidPtr(o); if (PyErr_Occurred()) { return -1; } } else if (o == Py_None) { vp = 0; } else { PyErr_Format(PyExc_TypeError, "property %400s must be a Python integer, not '%400s'", name, Py_TYPE(o)->tp_name); return -1; } *vpp = vp; return 0; }
PyObject * SharedMemory_attach(SharedMemory *self, PyObject *args, PyObject *keywords) { PyObject *py_address = NULL; void *address = NULL; int flags = 0; static char *keyword_list[ ] = {"address", "flags", NULL}; DPRINTF("Inside SharedMemory_attach()\n"); if (!PyArg_ParseTupleAndKeywords(args, keywords, "|Oi", keyword_list, &py_address, &flags)) goto error_return; if ((!py_address) || (py_address == Py_None)) address = NULL; else { if (PyLong_Check(py_address)) address = PyLong_AsVoidPtr(py_address); else { PyErr_SetString(PyExc_TypeError, "address must be a long"); goto error_return; } } return shm_attach(self, address, flags); error_return: return NULL; }
static PyObject * PyBlosc_decompress_ptr(PyObject *self, PyObject *args) { PyObject * pointer, * return_int; void * input, * output; size_t cbytes, nbytes; /* require a compressed string and a pointer */ if (!PyArg_ParseTuple(args, "s#O:decompress", &input, &cbytes, &pointer)) return NULL; /* convert the int or long Python object to a void * */ output = PyLong_AsVoidPtr(pointer); if (output == NULL) return NULL; /* fetch the uncompressed size into nbytes */ if (!get_nbytes(input, cbytes, &nbytes)) return NULL; /* do decompression */ if (!decompress_helper(input, nbytes, output)) return NULL; /* Return nbytes as python integer. This is legitimate, because * decompress_helper above has checked that the number of bytes written * was indeed nbytes. * */ return_int = PyLong_FromSize_t(nbytes); Py_INCREF(return_int); return return_int; }
/* * A convenience function to convert a C/C++ void pointer from a Python object. */ void *sip_api_convert_to_void_ptr(PyObject *obj) { if (obj == NULL) { PyErr_SetString(PyExc_TypeError, "sip.voidptr is NULL"); return NULL; } if (obj == Py_None) return NULL; if (PyObject_TypeCheck(obj, &sipVoidPtr_Type)) return ((sipVoidPtrObject *)obj)->voidptr; #if defined(SIP_USE_PYCAPSULE) if (PyCapsule_CheckExact(obj)) return PyCapsule_GetPointer(obj, NULL); #endif #if defined(SIP_SUPPORT_PYCOBJECT) if (PyCObject_Check(obj)) return PyCObject_AsVoidPtr(obj); #endif return PyLong_AsVoidPtr(obj); }
static gboolean _pygi_marshal_from_py_void (PyGIInvokeState *state, PyGICallableCache *callable_cache, PyGIArgCache *arg_cache, PyObject *py_arg, GIArgument *arg, gpointer *cleanup_data) { g_warn_if_fail (arg_cache->transfer == GI_TRANSFER_NOTHING); if (py_arg == Py_None) { arg->v_pointer = NULL; } else if (PYGLIB_CPointer_Check(py_arg)) { arg->v_pointer = PYGLIB_CPointer_GetPointer (py_arg, NULL); } else if (PYGLIB_PyLong_Check(py_arg) || PyLong_Check(py_arg)) { arg->v_pointer = PyLong_AsVoidPtr (py_arg); } else { PyErr_SetString(PyExc_ValueError, "Pointer arguments are restricted to integers, capsules, and None. " "See: https://bugzilla.gnome.org/show_bug.cgi?id=683599"); return FALSE; } *cleanup_data = arg->v_pointer; return TRUE; }
static int Dispatcher_init(DispatcherObject *self, PyObject *args, PyObject *kwds) { PyObject *tmaddrobj; void *tmaddr; int argct; int can_fallback; int has_stararg = 0; int exact_match_required = 0; if (!PyArg_ParseTuple(args, "OiiO!O!i|ii", &tmaddrobj, &argct, &self->fold_args, &PyTuple_Type, &self->argnames, &PyTuple_Type, &self->defargs, &can_fallback, &has_stararg, &exact_match_required )) { return -1; } Py_INCREF(self->argnames); Py_INCREF(self->defargs); tmaddr = PyLong_AsVoidPtr(tmaddrobj); self->dispatcher = dispatcher_new(tmaddr, argct); self->can_compile = 1; self->can_fallback = can_fallback; self->firstdef = NULL; self->fallbackdef = NULL; self->interpdef = NULL; self->has_stararg = has_stararg; self->exact_match_required = exact_match_required; return 0; }
static Tcl_Interp *get_interpreter(PyObject *tkapp) { PyObject *interpaddrobj = PyObject_CallMethod(tkapp, "interpaddr", NULL); if(interpaddrobj == NULL) { return NULL; } void *interpaddr = PyLong_AsVoidPtr(interpaddrobj); Py_DECREF(interpaddrobj); if(interpaddr == -1) { return NULL; } return (Tcl_Interp*)interpaddr; }
// Get an array of OpenGL fundamental types from a sequence or an object that // implements a compatible buffer. Cache the array so that it persists until a // similar call. const GLvoid *qpyopengl_value_array_cached(sipErrorState *estate, PyObject *values, GLenum gl_type, PyObject *bindings, const char *pkey, GLuint skey) { // Handle the trivial byte offset case first. PyErr_Clear(); void *data = PyLong_AsVoidPtr(values); if (!PyErr_Occurred()) return data; PyErr_Clear(); qpyopengl_dataCache *data_cache = get_cache(bindings); if (!data_cache) { *estate = sipErrorFail; return 0; } if (!data_cache->pcache) data_cache->pcache = new PrimaryCache; // Get an empty wrapper for the array. PrimaryCacheEntry *pce = (*data_cache->pcache)[pkey]; if (!pce) { pce = new PrimaryCacheEntry; data_cache->pcache->insert(pkey, pce); } Array *array; if (skey == 0) { array = &pce->skey_0; } else { if (!pce->skey_n) pce->skey_n = new SecondaryCache; array = (*pce->skey_n)[skey]; if (!array) { array = new Array; pce->skey_n->insert(skey, array); } } array->clear(); return convert_values(array, values, gl_type, estate); }
static PyObject* send_action_python(PyObject* self, PyObject* args){ int action; PyObject* d; if (!PyArg_ParseTuple(args, "Oi", &d,&action)) return NULL; struct ms_control* data; data = (struct ms_control*)PyLong_AsVoidPtr(d); send_action(data,action); return Py_BuildValue("i",0); }
static PyObject* get_motor_rawValue_python(PyObject* self, PyObject* args){ int ret,motor,val; PyObject* d; if (!PyArg_ParseTuple(args, "Oi", &d,&motor)) return NULL; struct ms_control* data; data = (struct ms_control*)PyLong_AsVoidPtr(d); ret=get_motor_rawValue(data,motor); return Py_BuildValue("i", ret); }
static ach_channel_t *parse_channel_pointer( PyObject *i ) { if( PyInt_Check(i) ) { return (ach_channel_t*)PyInt_AsLong(i); } else if ( PyLong_Check(i) ) { return (ach_channel_t*)PyLong_AsVoidPtr(i); } else { PyErr_SetString( PyExc_TypeError, "invalid channel pointer" ); return NULL; } }
static PyObject* set_servo_value_python(PyObject* self, PyObject* args){ int ret,servo,val; PyObject* d; if (!PyArg_ParseTuple(args, "Oii", &d,&servo,&val)) return NULL; struct ms_control* data; data = (struct ms_control*)PyLong_AsVoidPtr(d); ret=set_servo_value(data,servo,val); return Py_BuildValue("i", ret); }
PyObject * read_memory_in(PyObject *self, PyObject *args) { PyObject *address_object; if (!PyArg_UnpackTuple(args, "read_memory_in", 1, 1, &address_object)) return NULL; void *address = PyLong_AsVoidPtr(address_object); return PyLong_FromUnsignedLong(*((unsigned char *)address)); }
static PyObject* dump_motor_python(PyObject* self, PyObject* args){ int motor; PyObject* d; if (!PyArg_ParseTuple(args, "Oi", &d,&motor)) return NULL; struct ms_control* data; data = (struct ms_control*)PyLong_AsVoidPtr(d); dump_motor(data,motor); return Py_BuildValue("i",0); }
void * Pythonize::runFunctionVoid (PyObject *object, PyObject *args) { if (!PyCallable_Check (object)) return NULL; PyObject *pyRes = PyObject_CallObject (object, args ? args : PyTuple_New (0)); void *res = PyLong_AsVoidPtr (pyRes); return res; }
static PyObject * memsys_set_atomic_cas(PyObject *self, PyObject *args) { PyObject *addr_cas_obj; void *addr_cas; if (!PyArg_ParseTuple(args, "O", &addr_cas_obj)) { return NULL; } addr_cas = PyLong_AsVoidPtr(addr_cas_obj); if(PyErr_Occurred()) return NULL; NRT_MemSys_set_atomic_cas(addr_cas); Py_RETURN_NONE; }
// Same as above, for an iterator handle. static int gpi_iterator_hdl_converter(PyObject *o, gpi_iterator_hdl *data) { void *p = PyLong_AsVoidPtr(o); if ((p == NULL) && PyErr_Occurred()) { return 0; } if (p == NULL) { PyErr_SetString(PyExc_ValueError, "handle cannot be 0"); return 0; } *data = (gpi_iterator_hdl)p; return 1; }
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { PyObject *m = NULL, *p = NULL; void *r = NULL; m = PyImport_ImportModule((char *)modname); if (!m) goto end; p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); if (!p) goto end; r = PyLong_AsVoidPtr(p); end: Py_XDECREF(p); Py_XDECREF(m); return (__Pyx_RefNannyAPIStruct *)r; }
static GeanyDocument * ZenEditor_get_context(ZenEditor *self) { GeanyDocument *doc; print_called(); if (self->context == NULL) return NULL; doc = (GeanyDocument *) PyLong_AsVoidPtr(self->context); return DOC_VALID(doc) ? doc : NULL; }
/* Get buffer info from the global dictionary */ static _buffer_info_t* _buffer_get_info(PyObject *arr) { PyObject *key, *item_list, *item; _buffer_info_t *info = NULL, *old_info = NULL; if (_buffer_info_cache == NULL) { _buffer_info_cache = PyDict_New(); if (_buffer_info_cache == NULL) { return NULL; } } /* Compute information */ info = _buffer_info_new((PyArrayObject*)arr); if (info == NULL) { return NULL; } /* Check if it is identical with an old one; reuse old one, if yes */ key = PyLong_FromVoidPtr((void*)arr); item_list = PyDict_GetItem(_buffer_info_cache, key); if (item_list != NULL) { Py_INCREF(item_list); if (PyList_GET_SIZE(item_list) > 0) { item = PyList_GetItem(item_list, PyList_GET_SIZE(item_list) - 1); old_info = (_buffer_info_t*)PyLong_AsVoidPtr(item); if (_buffer_info_cmp(info, old_info) == 0) { _buffer_info_free(info); info = old_info; } } } else { item_list = PyList_New(0); PyDict_SetItem(_buffer_info_cache, key, item_list); } if (info != old_info) { /* Needs insertion */ item = PyLong_FromVoidPtr((void*)info); PyList_Append(item_list, item); Py_DECREF(item); } Py_DECREF(item_list); Py_DECREF(key); return info; }
static int MemInfo_init(MemInfoObject *self, PyObject *args, PyObject *kwds) { static char *keywords[] = {"ptr", NULL}; PyObject *raw_ptr_obj; void *raw_ptr; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", keywords, &raw_ptr_obj)) { return -1; } raw_ptr = PyLong_AsVoidPtr(raw_ptr_obj); if(PyErr_Occurred()) return -1; self->meminfo = (NRT_MemInfo *)raw_ptr; assert (NRT_MemInfo_refcount(self->meminfo) > 0 && "0 refcount"); return 0; }
static int np_void_p(char *p, PyObject *v, const formatdef *f) { void *x = PyLong_AsVoidPtr(v); if (x == NULL && PyErr_Occurred()) { /* ### hrm. PyLong_AsVoidPtr raises SystemError */ if (PyErr_ExceptionMatches(PyExc_TypeError)) PyErr_SetString(StructError, "required argument is not an integer"); return -1; } memcpy(p, (char *)&x, sizeof x); return 0; }
PyObject * SharedMemory_attach(SharedMemory *self, PyObject *args) { PyObject *py_address = NULL; void *address = NULL; int flags = 0; if (!PyArg_ParseTuple(args, "|Oi", &py_address, &flags)) goto error_return; if ((!py_address) || (py_address == Py_None)) address = NULL; else { if (PyLong_Check(py_address)) address = PyLong_AsVoidPtr(py_address); else { PyErr_SetString(PyExc_TypeError, "address must be a long"); goto error_return; } } self->address = shmat(self->id, address, flags); if ((void *)-1 == self->address) { self->address = NULL; switch (errno) { case EACCES: PyErr_SetString(pPermissionsException, "No permission to attach"); break; case EINVAL: PyErr_SetString(PyExc_ValueError, "Invalid address or flags"); break; case ENOMEM: PyErr_SetString(PyExc_MemoryError, "Not enough memory"); break; default: PyErr_SetFromErrno(PyExc_OSError); break; } goto error_return; } Py_RETURN_NONE; error_return: return NULL; }
/* * Create a new MemInfo with a owner PyObject */ static PyObject * meminfo_new(PyObject *self, PyObject *args) { PyObject *addr_data_obj; void *addr_data; PyObject *ownerobj; NRT_MemInfo *mi; if (!PyArg_ParseTuple(args, "OO", &addr_data_obj, &ownerobj)) { return NULL; } addr_data = PyLong_AsVoidPtr(addr_data_obj); if (PyErr_Occurred()) return NULL; mi = meminfo_new_from_pyobject(addr_data, ownerobj); return PyLong_FromVoidPtr(mi); }
/* * A convenience function to convert a C/C++ void pointer from a Python object. */ void *sip_api_convert_to_void_ptr(PyObject *obj) { struct vp_values vp; if (obj == NULL) { PyErr_SetString(PyExc_TypeError, "sip.voidptr is NULL"); return NULL; } if (vp_convertor(obj, &vp)) return vp.voidptr; return PyLong_AsVoidPtr(obj); }
static int np_void_p(char *p, PyObject *v, const formatdef *f) { void *x; v = get_pylong(v); if (v == NULL) return -1; assert(PyLong_Check(v)); x = PyLong_AsVoidPtr(v); Py_DECREF(v); if (x == NULL && PyErr_Occurred()) return -1; memcpy(p, (char *)&x, sizeof x); return 0; }
PyObject * write_memory_in(PyObject *self, PyObject *args) { PyObject *address_object; PyObject *new_data_object; if (!PyArg_UnpackTuple(args, "write_memory_in", 2, 2, &address_object, &new_data_object)) return NULL; unsigned char *address = \ (unsigned char *)PyLong_AsVoidPtr(address_object); unsigned char new_data = \ (unsigned char)PyLong_AsUnsignedLong(new_data_object); *address = new_data; Py_RETURN_NONE; }
PyObject *CListValue::Pyfrom_id(PyObject *value) { uintptr_t id= (uintptr_t)PyLong_AsVoidPtr(value); if (PyErr_Occurred()) return NULL; int numelem = GetCount(); for (int i=0;i<numelem;i++) { if (reinterpret_cast<uintptr_t>(m_pValueArray[i]->m_proxy) == id) return GetValue(i)->GetProxy(); } PyErr_SetString(PyExc_IndexError, "from_id(#): id not found in CValueList"); return NULL; }