Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
/*
 * 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);
}
Exemplo n.º 6
0
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();
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
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;
}
Exemplo n.º 10
0
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;
}
Exemplo n.º 11
0
// 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);
}
Exemplo n.º 12
0
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);
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
0
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
}
Exemplo n.º 16
0
static PyObject *
Struct_tp_repr(PyObject *self)
{
    PyObject *parent_repr = (PyTuple_Type.tp_repr)((PyObject *)self);
    PyObject *sig;
    PyObject *sig_repr = NULL;
    PyObject *key;
    long variant_level;
    PyObject *my_repr = NULL;

    if (!parent_repr) goto finally;
    key = PyLong_FromVoidPtr(self);
    if (!key) goto finally;
    sig = PyDict_GetItem(struct_signatures, key);
    Py_CLEAR(key);
    if (!sig) sig = Py_None;
    sig_repr = PyObject_Repr(sig);
    if (!sig_repr) goto finally;

    variant_level = dbus_py_variant_level_get(self);
    if (variant_level < 0)
        goto finally;

    if (variant_level > 0) {
        my_repr = PyUnicode_FromFormat("%s(%V, signature=%V, "
                                       "variant_level=%ld)",
                                       Py_TYPE(self)->tp_name,
                                       REPRV(parent_repr),
                                       REPRV(sig_repr),
                                       variant_level);
    }
    else {
        my_repr = PyUnicode_FromFormat("%s(%V, signature=%V)",
                                       Py_TYPE(self)->tp_name,
                                       REPRV(parent_repr),
                                       REPRV(sig_repr));
    }

finally:
    Py_CLEAR(parent_repr);
    Py_CLEAR(sig_repr);
    return my_repr;
}
Exemplo n.º 17
0
static int
register_npymath_exports(PyObject *dct)
{
    size_t count = sizeof(npymath_exports) / sizeof(npymath_exports[0]);
    size_t i;

    for (i = 0; i < count; ++i) {
        PyObject *ptr = PyLong_FromVoidPtr(npymath_exports[i].func);
        if (ptr == NULL)
            return -1;
        if (PyDict_SetItemString(dct, npymath_exports[i].name, ptr) < 0) {
            Py_DECREF(ptr);
            return -1;
        }
        Py_DECREF(ptr);
    }

    return 0;
}
Exemplo n.º 18
0
bool CPythonEngine::InitMainInterp(void)
{
	// ensure only 1 engine/thread initialises this only
	CSLock l(m_initLock);
	if (!m_haveInit) {
		PyGILState_STATE old_state;
		if (Py_IsInitialized())
			old_state = PyGILState_Ensure();
		else {
			Py_Initialize();
			old_state = PyGILState_UNLOCKED;
		}
		PyEval_InitThreads();
	
		if (!g_IsFrozen) {
			TCHAR *dll_path = GetModulePath();
			AddToPythonPath(dll_path);
			free(dll_path);
			PyErr_Clear();
			}
	
		// isapidllhandle to match dllhandle, frozendllhandle, etc :)  Also a 
		// nice way for a program to know they are in an ISAPI context.
		PyObject *obh = PyLong_FromVoidPtr(g_hInstance);
		PySys_SetObject("isapidllhandle", obh);
		Py_XDECREF(obh);
		// Locate the special exception we use to trigger a reload.
		PyObject *isapi_package = PyImport_ImportModule("isapi");
		if (isapi_package)
			m_reload_exception = PyObject_GetAttrString(isapi_package,
			                             "InternalReloadException");
		Py_XDECREF(isapi_package);

		// ready our types.
		InitExtensionTypes();
		InitFilterTypes();

		PyGILState_Release(old_state);
		FindModuleName();
		m_haveInit = true;
	}
	return true;
}
Exemplo n.º 19
0
static PyObject *get_root_handle(PyObject *self, PyObject *args)
{
    const char *name;
    gpi_sim_hdl result;
    PyObject *value;

    if (!PyArg_ParseTuple(args, "z", &name)) {
        return NULL;
    }

    result = gpi_get_root_handle(name);
    if (NULL == result) {
       Py_RETURN_NONE;
    }


    value = PyLong_FromVoidPtr(result);

    return value;
}
Exemplo n.º 20
0
PyObject *
dbus_py_variant_level_getattro(PyObject *obj, PyObject *name)
{
    PyObject *key, *value;

    if (PyString_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(PyString_AS_STRING(name), "variant_level")) {
        value = PyObject_GenericGetAttr(obj, name);
        Py_DECREF(name);
        return value;
    }

    Py_DECREF(name);

    key = PyLong_FromVoidPtr(obj);

    if (!key) {
        return NULL;
    }

    value = PyDict_GetItem(_dbus_py_variant_levels, key);
    Py_DECREF(key);

    if (!value)
        return PyInt_FromLong(0);
    Py_INCREF(value);
    return value;
}
Exemplo n.º 21
0
PyObject *PythonImport_GetKeys( PyObject *self, PyObject *args )
{
	// if a key wasn't pressed then return NULL
	if( Keys_HasChanged() )
	{
		SKeyInfo *pKeys = Keys_GetKeyData();

		PyObject* pObject = PyLong_FromVoidPtr( (void*)pKeys );
		if( pObject )
		{
			// increment the reference count?
			Py_INCREF( pObject );
			return pObject;
		}

		// throw exception
		return PyErr_NoMemory();
	}

	return PyLong_FromLong(0);
}
Exemplo n.º 22
0
PyObject*
create_symbol_list(void)
{
    /*
     * note: reference stealing at its best
     * returns a PyList with a tuple for each symbol. The PyList has one reference.
     */
    size_t count = sizeof(exports) / sizeof(exports[0]);
    PyObject* pylist = PyList_New(count);
    size_t i;

    for (i = 0; i < count; ++i) {
        /* create the tuple */
        PyObject* ptr = PyLong_FromVoidPtr(exports[i].func);
        PyObject* tuple = Py_BuildValue("(s,O)", exports[i].name, ptr);
        PyList_SET_ITEM(pylist, i, tuple);
        Py_XDECREF(ptr);
    }

    return pylist;
}
Exemplo n.º 23
0
PyObject *PythonImport_GetPlayer( PyObject *self, PyObject *args )
{
	VisInstancePtr* pPlayer = &gp_GameObject->m_PlayerObject;

	// if the player pointer is NULL return NULL
	if( pPlayer )
	{
		PyObject* pObject = PyLong_FromVoidPtr( (void*)pPlayer );
		if( pObject )
		{
			// increment the reference count?
			Py_INCREF( pObject );
			return pObject;
		}

		// throw exception
		return PyErr_NoMemory();
	}

	return PyLong_FromLong(0);
}
Exemplo n.º 24
0
long
_Py_HashPointer(void *p)
{
#if SIZEOF_LONG >= SIZEOF_VOID_P
	return (long)p;
#else
	/* convert to a Python long and hash that */
	PyObject* longobj;
	long x;
	
	if ((longobj = PyLong_FromVoidPtr(p)) == NULL) {
		x = -1;
		goto finally;
	}
	x = PyObject_Hash(longobj);
	
finally:
	Py_XDECREF(longobj);
	return x;
#endif
}
Exemplo n.º 25
0
PySTEntryObject *
PySymtable_Lookup(struct symtable *st, void *key)
{
    PyObject *k, *v;

    k = PyLong_FromVoidPtr(key);
    if (k == NULL)
        return NULL;
    v = PyDict_GetItem(st->st_symbols, k);
    if (v) {
        assert(PySTEntry_Check(v));
        Py_INCREF(v);
    }
    else {
        PyErr_SetString(PyExc_KeyError,
                        "unknown symbol table entry");
    }

    Py_DECREF(k);
    return (PySTEntryObject *)v;
}
Exemplo n.º 26
0
static PyObject *
dl_dlsym(PyObject *self, PyObject *args)
{
  PyObject *arg0 = NULL;
  void *handle = NULL;
  char *symbol = NULL;
  void *symval = NULL;
  (void)self; /* unused */
  if (!PyArg_ParseTuple(args, (char *)"Os:dlsym",
                        &arg0, &symbol)) return NULL;
#ifdef RTLD_DEFAULT
  handle = (void *)RTLD_DEFAULT;
#endif
  if (arg0 != Py_None) {
    handle = PyLong_AsVoidPtr(arg0);
    if (!handle && PyErr_Occurred())
      return NULL;
  }
  symval = dlsym(handle, symbol);
  return PyLong_FromVoidPtr(symval);
}
Exemplo n.º 27
0
void superlu_python_module_free(void *ptr)
{
    PyObject *key;
    PyObject *ptype, *pvalue, *ptraceback;

    if (ptr == NULL)
	return;
    PyErr_Fetch(&ptype, &pvalue, &ptraceback);
    key = PyLong_FromVoidPtr(ptr);
    /* This will only free the pointer if it could find it in the dictionary
     * of already allocated pointers --- thus after abort, the module can free all
     * the memory that "might" have been allocated to avoid memory leaks on abort
     * calls.
     */
    if (_superlumodule_memory_dict &&
	!(PyDict_DelItem(_superlumodule_memory_dict, key))) {
	free(ptr);
    }
    Py_DECREF(key);
    PyErr_Restore(ptype, pvalue, ptraceback);
    return;
}
Exemplo n.º 28
0
/* Clear buffer info from the global dictionary */
static void
_buffer_clear_info(PyObject *arr)
{
    PyObject *key, *item_list, *item;
    _buffer_info_t *info;
    int k;

    if (_buffer_info_cache == NULL) {
        return;
    }

    key = PyLong_FromVoidPtr((void*)arr);
    item_list = PyDict_GetItem(_buffer_info_cache, key);
    if (item_list != NULL) {
        for (k = 0; k < PyList_GET_SIZE(item_list); ++k) {
            item = PyList_GET_ITEM(item_list, k);
            info = (_buffer_info_t*)PyLong_AsVoidPtr(item);
            _buffer_info_free(info);
        }
        PyDict_DelItem(_buffer_info_cache, key);
    }

    Py_DECREF(key);
}
Exemplo n.º 29
0
static
PyObject* GetPointer(PyObject* obj){
    void *pointer = PyCapsule_GetPointer(obj, PyCapsule_GetName(obj));
    if (!pointer) return NULL;
    return PyLong_FromVoidPtr(pointer);
}
Exemplo n.º 30
0
Arquivo: voidptr.c Projeto: Werkov/SIP
/*
 * Implement int() for the type.
 */
static PyObject *sipVoidPtr_int(PyObject *self)
{
    return PyLong_FromVoidPtr(((sipVoidPtrObject *)self)->voidptr);
}