本文整理汇总了C++中PyLong_FromVoidPtr函数的典型用法代码示例。如果您正苦于以下问题:C++ PyLong_FromVoidPtr函数的具体用法?C++ PyLong_FromVoidPtr怎么用?C++ PyLong_FromVoidPtr使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyLong_FromVoidPtr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: multiprocessing_address_of_buffer
static PyObject*
multiprocessing_address_of_buffer(PyObject *self, PyObject *obj)
{
void *buffer;
Py_ssize_t buffer_len;
if (PyObject_AsWriteBuffer(obj, &buffer, &buffer_len) < 0)
return NULL;
return Py_BuildValue("N" F_PY_SSIZE_T,
PyLong_FromVoidPtr(buffer), buffer_len);
}
示例2: py_newterm
static PyObject* py_newterm(PyObject *self, PyObject *args){
int fd;
SCREEN *screen;
if (!PyArg_ParseTuple(args, "i", &fd))
return NULL;
Py_BEGIN_ALLOW_THREADS
FILE *fp = fdopen(fd, "w+");
screen = newterm(NULL, fp, fp);
Py_END_ALLOW_THREADS
return PyLong_FromVoidPtr(screen);
}
示例3: EnumVisibleWindowsProc
BOOL CALLBACK
EnumVisibleWindowsProc(HWND hwnd, LPARAM lParam)
{
if (IsWindowVisible(hwnd))
{
PyObject *item;
item = PyLong_FromVoidPtr(hwnd);
PyList_Append((PyObject *) lParam, item);
Py_DECREF(item);
}
return TRUE;
}
示例4: PyTuple_Size
static PyObject *register_nextstep_callback(PyObject *self, PyObject *args)
{
FENTER
PyObject *fArgs;
PyObject *function;
gpi_sim_hdl hdl;
p_callback_data callback_data_p;
Py_ssize_t numargs = PyTuple_Size(args);
if (numargs < 1) {
fprintf(stderr, "Attempt to register ReadOnly callback with!\n");
return NULL;
}
// Extract the callback function
function = PyTuple_GetItem(args, 0);
if (!PyCallable_Check(function)) {
fprintf(stderr, "Attempt to register ReadOnly without supplying a callback!\n");
return NULL;
}
Py_INCREF(function);
// Remaining args for function
fArgs = PyTuple_GetSlice(args, 1, 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!)
callback_data_p->_saved_thread_state = 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_nexttime_callback((gpi_function_t)handle_gpi_callback, callback_data_p);
PyObject *rv = PyLong_FromVoidPtr(hdl);
FEXIT
return rv;
}
示例5: meminfo_new
/*
* 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);
}
示例6: Mouse_GetMouseData
PyObject *PythonImport_GetMouse( PyObject *self, PyObject *args )
{
SMouseInfo *pMouse = Mouse_GetMouseData();
// mouse always needs to be returned
PyObject* pObject = PyLong_FromVoidPtr( (void*)pMouse );
if( pObject )
{
// increment the reference count?
Py_INCREF( pObject );
return pObject;
}
// throw exception
return PyErr_NoMemory();
}
示例7: zen_controller_run_action
void zen_controller_run_action(ZenController *zen, const char *action_name)
{
PyObject *addr, *result;
GeanyDocument *doc;
g_return_if_fail(zen != NULL);
g_return_if_fail(action_name != NULL);
ui_set_statusbar(FALSE, _("Zen Coding: Running '%s' action"), action_name);
doc = document_get_current();
if (!DOC_VALID(doc))
{
g_warning("No valid document detected.");
return;
}
addr = PyLong_FromVoidPtr((void *) doc);
if (addr == NULL)
{
if (PyErr_Occurred())
PyErr_Print();
g_warning("Unable to convert document pointer to Python object.");
return;
}
result = PyObject_CallMethod(zen->editor, "set_context", "O", addr);
Py_DECREF(addr);
if (result == NULL)
{
if (PyErr_Occurred())
PyErr_Print();
g_warning("Unable to call set_context() function.");
return;
}
Py_XDECREF(result);
result = PyObject_CallFunction(zen->run_action, "sO", action_name, zen->editor);
if (result == NULL)
{
if (PyErr_Occurred())
PyErr_Print();
g_warning("Call to run_action() failed.");
return;
}
Py_XDECREF(result);
}
示例8: gpi_get_handle_by_index
static PyObject *get_handle_by_index(PyObject *self, PyObject *args)
{
int32_t index;
gpi_sim_hdl hdl;
gpi_sim_hdl result;
PyObject *value;
if (!PyArg_ParseTuple(args, "O&i", gpi_sim_hdl_converter, &hdl, &index)) {
return NULL;
}
result = gpi_get_handle_by_index((gpi_sim_hdl)hdl, index);
value = PyLong_FromVoidPtr(result);
return value;
}
示例9: gpi_get_handle_by_name
static PyObject *get_handle_by_name(PyObject *self, PyObject *args)
{
const char *name;
gpi_sim_hdl hdl;
gpi_sim_hdl result;
PyObject *res;
if (!PyArg_ParseTuple(args, "O&s", gpi_sim_hdl_converter, &hdl, &name)) {
return NULL;
}
result = gpi_get_handle_by_name((gpi_sim_hdl)hdl, name);
res = PyLong_FromVoidPtr(result);
return res;
}
示例10: gpi_iterate
static PyObject *iterate(PyObject *self, PyObject *args)
{
gpi_sim_hdl hdl;
int type;
gpi_iterator_hdl result;
PyObject *res;
if (!PyArg_ParseTuple(args, "O&i", gpi_sim_hdl_converter, &hdl, &type)) {
return NULL;
}
result = gpi_iterate(hdl, (gpi_iterator_sel_t)type);
res = PyLong_FromVoidPtr(result);
return res;
}
示例11: _get_osfhandle
// Convert a C runtime file descriptor to an OS file handle.
static PyObject *msvcrt_get_osfhandle(PyObject *self, PyObject *args)
{
int fd;
intptr_t handle;
if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
return NULL;
handle = _get_osfhandle(fd);
if (handle == -1)
return PyErr_SetFromErrno(PyExc_IOError);
/* technically 'handle' is not a pointer, but a integer as
large as a pointer, Python's *VoidPtr interface is the
most appropriate here */
return PyLong_FromVoidPtr((void*)handle);
}
示例12: dbus_py_variant_level_get
long
dbus_py_variant_level_get(PyObject *obj)
{
PyObject *vl_obj;
PyObject *key = PyLong_FromVoidPtr(obj);
if (!key) {
return 0;
}
vl_obj = PyDict_GetItem(_dbus_py_variant_levels, key);
Py_DECREF(key);
if (!vl_obj)
return 0;
return PyInt_AsLong(vl_obj);
}
示例13: dbus_py_variant_level_getattro
PyObject *
dbus_py_variant_level_getattro(PyObject *obj, PyObject *name)
{
PyObject *key, *value;
#ifdef PY3
if (PyUnicode_CompareWithASCIIString(name, "variant_level"))
return PyObject_GenericGetAttr(obj, name);
#else
if (PyBytes_Check(name)) {
Py_INCREF(name);
}
else if (PyUnicode_Check(name)) {
name = PyUnicode_AsEncodedString(name, NULL, NULL);
if (!name) {
return NULL;
}
}
else {
PyErr_SetString(PyExc_TypeError, "attribute name must be string");
return NULL;
}
if (strcmp(PyBytes_AS_STRING(name), "variant_level")) {
value = PyObject_GenericGetAttr(obj, name);
Py_CLEAR(name);
return value;
}
Py_CLEAR(name);
#endif /* PY3 */
key = PyLong_FromVoidPtr(obj);
if (!key) {
return NULL;
}
value = PyDict_GetItem(_dbus_py_variant_levels, key);
Py_CLEAR(key);
if (!value)
return NATIVEINT_FROMLONG(0);
Py_INCREF(value);
return value;
}
示例14: call_getnewargs
static PyObject *node_deepcopy(PyObject *self, PyObject *memo)
{
PyObject *args, *state, *temp;
PyObject *result=NULL;
args = call_getnewargs(self);
if (args == NULL)
return NULL;
args = PyObject_CallFunction(deepcopy_function, "NO", args, memo);
if (args == NULL)
return NULL;
result = self->ob_type->tp_new(self->ob_type, args, NULL);
Py_DECREF(args);
if (result == NULL)
return NULL;
temp = PyLong_FromVoidPtr(self);
if (temp == NULL) {
Py_DECREF(result);
return NULL;
}
if (PyDict_SetItem(memo, temp, result) < 0) {
Py_DECREF(temp);
Py_DECREF(result);
return NULL;
}
Py_DECREF(temp);
/* __getstate__(deep=True) is our extension for deepcopying nodes */
state = PyObject_CallMethod(self, "__getstate__", "O", Py_True);
if (state == NULL) {
Py_DECREF(result);
return NULL;
}
state = PyObject_CallFunction(deepcopy_function, "NO", state, memo);
if (state == NULL) {
Py_DECREF(result);
return NULL;
}
temp = PyObject_CallMethod(result, "__setstate__", "(N)", state);
if (temp == NULL) {
Py_DECREF(result);
return NULL;
}
return result;
}
示例15: node_hash
static long node_hash(NodeObject *self)
{
#if SIZEOF_LONG >= SIZEOF_VOID_P
return (long)self;
#else
/* convert to a Python long and hash that */
PyObject *longobj;
long hash;
if ((longobj = PyLong_FromVoidPtr(self)) == NULL) {
return -1;
}
hash = PyObject_Hash(longobj);
Py_DECREF(longobj);
return hash;
#endif
}