Working with C object of python object (pycairo,ctypes)

AngelBlaZe gerdusvanzyl at gmail.com
Sun Feb 25 19:00:55 EST 2007


Can you access the c object of a python object directly? Can this be
done in ctypes or directly throught python functions without reverting
to forking the python module?

scanario:
I have pyctx object that i get in python like this:

pyctx = cairo.Context(surface)

defined in the python extension this:

typedef struct {
    PyObject_HEAD
    cairo_t *ctx;
    PyObject *base; /* base object used to create context, or NULL */
} PycairoContext;

PyObject *
PycairoContext_FromContext(cairo_t *ctx, PyTypeObject *type, PyObject
*base)
{
    PyObject *o;

    assert (ctx != NULL);

    if (Pycairo_Check_Status (cairo_status (ctx))) {
	cairo_destroy (ctx);
	return NULL;
    }

    if (type == NULL)
        type = &PycairoContext_Type;
    o = PycairoContext_Type.tp_alloc (type, 0);
    if (o) {
	((PycairoContext *)o)->ctx = ctx;
	Py_XINCREF(base);
	((PycairoContext *)o)->base = base;
    } else {
	cairo_destroy (ctx);
    }
    return o;
}

Now my question is:
Is there any way to access/get a pointer to PycairoContext->ctx from
python object (pyctx)?

A long shot i know :-)




More information about the Python-list mailing list