ich wollte gerade die librsvg mittels ctypes binden und erhalte leider Segmentation Faults. Hier die entsprechenden C-Header (aus pycairo und librsvg):
Code: Alles auswählen
typedef struct {
PyObject_HEAD
cairo_t *ctx;
PyObject *base; /* base object used to create context, or NULL */
} PycairoContext;
struct _RsvgHandle {
GObject parent;
RsvgHandlePrivate *priv;
gpointer _abi_padding[15];
};
RsvgHandle *rsvg_handle_new_from_file (const gchar * file_name, GError ** error);
gboolean rsvg_handle_render_cairo (RsvgHandle * handle, cairo_t * cr);
Code: Alles auswählen
from ctypes import *
from ctypes import util
librsvg = cdll.LoadLibrary('/usr/local/lib/librsvg-2.2.dylib')
libgobject = cdll.LoadLibrary('/usr/local/lib/libgobject-2.0.dylib')
libgobject.g_type_init()
class RSVGDimensionData(Structure):
_fields_ = [
('width', c_int),
('height', c_int),
('em', c_double),
('ex', c_double)
]
class PycairoContext(Structure):
_fields_ = [
('PyObject_HEAD', c_byte * object.__basicsize__),
('ctx', c_void_p),
('base', c_void_p)
]
#class GObject(Structure):
#
# _fields_ = [
# ('g_type_instance', c_void_p),
# ('ref_count', c_uint),
# ('qdata', c_void_p),
# ]
#
#
#class RsvgHandle(Structure):
#
# _fields_ = [
# ('parent', GObject),
# ('priv', c_void_p),
# ('_abi_padding', c_void_p),
# ]
class Handle(object):
def __init__(self, path):
self.path = path
self.error = ''
#librsvg.rsvg_handle_new_from_file.restype = RsvgHandle
self.handle = librsvg.rsvg_handle_new_from_file(self.path, self.error)
def render_cairo(self, context):
context.save()
c_context = PycairoContext.from_address(id(context)).ctx
# segmentation fault...
librsvg.rsvg_handle_render_cairo(self.handle, c_context)
context.restore()
import cairo
handle = Handle('test.svg')
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 400)
context = cairo.Context(surface)
# segmentation fault...
handle.render_cairo(context)
Ich habe noch nicht allzu viel mit ctypes gemacht. Gibt es also irgendeine Möglichkeit den Segmentation Fault zu debuggen oder könnt mir sagen, wo der Fehler liegt?
Vielen Dank!