wx.lib.wxcairo in 64 bit environment segfaults

Dear all

I'm having problems using wx.lib.wxcairo in a 64 bit environment. Just
using it out of the box causes a segfault. After a litlle poking
around I found that the segfault is triggered inside pycairo because
it is not getting the correct 64 bit pointer, but only the lower 32
bits. To fix this I had to change wxcairo.py so that it now reads:

def ContextFromDC(dc):
(...)
        gdkLib.gdk_cairo_create.restype = ctypes.c_void_p
        ctxptr = gdkLib.gdk_cairo_create(drawable)
(...)

Now most examples in Cairo_Snippets.py work. Working with bitmaps
still causes segfaults, probably because of similar issues.

Any ideas?

Thanks in advance,
Ricardo

Dear all

I'm having problems using wx.lib.wxcairo in a 64 bit environment. Just
using it out of the box causes a segfault. After a litlle poking
around I found that the segfault is triggered inside pycairo because
it is not getting the correct 64 bit pointer, but only the lower 32
bits. To fix this I had to change wxcairo.py so that it now reads:

def ContextFromDC(dc):
(...)
         gdkLib.gdk_cairo_create.restype = ctypes.c_void_p
         ctxptr = gdkLib.gdk_cairo_create(drawable)
(...)

Thanks.

Now most examples in Cairo_Snippets.py work. Working with bitmaps
still causes segfaults, probably because of similar issues.

Any ideas?

If you can isolate the problem let me know, especially if you also have a fix. :wink:

···

On 1/4/10 3:27 AM, zamb wrote:

--
Robin Dunn
Software Craftsman

Hi

Well, the bitamp (actually PNG) issues were related to a separate
library issue on my side (two versions of the same library linked
against different packages), so no wxPython problems here. I did run
into problems with the FontFaceFromFont routine (which was breaking
demo/Cairo.py). The fix is similar to the previous one. The fixed code
now reads:

def FontFaceFromFont(font):
(...)
    elif 'wxGTK' in wx.PlatformInfo:
        gdkLib = _findGDKLib()
        pcLib = _findPangoCairoLib()

        # wow, this is a hell of a lot of steps...
        desc = voidp( font.GetPangoFontDescription() )

        pcLib.pango_cairo_font_map_get_default.restype =
ctypes.c_void_p
        pcfm = voidp(pcLib.pango_cairo_font_map_get_default())

        gdkLib.gdk_pango_context_get.restype = ctypes.c_void_p
        pctx = voidp(gdkLib.gdk_pango_context_get())

        pcLib.pango_font_map_load_font.restype = ctypes.c_void_p
        pfnt = voidp( pcLib.pango_font_map_load_font(pcfm, pctx,
desc) )

        pcLib.pango_cairo_font_get_scaled_font.restype =
ctypes.c_void_p
        scaledfontptr = voidp( pcLib.pango_cairo_font_get_scaled_font
(pfnt) )

        cairoLib.cairo_scaled_font_get_font_face.restype =
ctypes.c_void_p
        fontfaceptr = voidp(cairoLib.cairo_scaled_font_get_font_face
(scaledfontptr))

        fontface = pycairoAPI.FontFace_FromFontFace(fontfaceptr)

        gdkLib.g_object_unref(pctx)

    else:
(...)

So now all examples run fine. I'm sure some Python gurus will find a
better way of implementing this, so we don't set the function return
types every time we call it.

Cheers,
Ricardo

···

On Jan 5, 1:08 am, Robin Dunn <ro...@alldunn.com> wrote:

On 1/4/10 3:27 AM, zamb wrote:

> Dear all

> I'm having problems using wx.lib.wxcairo in a 64 bit environment. Just
> using it out of the box causes a segfault. After a litlle poking
> around I found that the segfault is triggered inside pycairo because
> it is not getting the correct 64 bit pointer, but only the lower 32
> bits. To fix this I had to change wxcairo.py so that it now reads:

> def ContextFromDC(dc):
> (...)
> gdkLib.gdk_cairo_create.restype = ctypes.c_void_p
> ctxptr = gdkLib.gdk_cairo_create(drawable)
> (...)

Thanks.

> Now most examples in Cairo_Snippets.py work. Working with bitmaps
> still causes segfaults, probably because of similar issues.

> Any ideas?

If you can isolate the problem let me know, especially if you also have
a fix. :wink:

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Could you please send this as a proper patch file (a unified diff between the original and your changed version) so I can more clearly see exactly what changed and where?

Thanks.

···

On 1/6/10 3:58 AM, zamb wrote:

Hi

Well, the bitamp (actually PNG) issues were related to a separate
library issue on my side (two versions of the same library linked
against different packages), so no wxPython problems here. I did run
into problems with the FontFaceFromFont routine (which was breaking
demo/Cairo.py). The fix is similar to the previous one. The fixed code
now reads:

--
Robin Dunn
Software Craftsman

Sure thing:

zamblap:lib zamb$ diff -u /tmp/wxcairo.py wxcairo.py
--- /tmp/wxcairo.py 2010-01-06 10:46:50.000000000 +0000
+++ wxcairo.py 2010-01-06 11:38:49.000000000 +0000
@@ -115,11 +115,12 @@
         drawable = voidp( dc.GetGdkDrawable() )

         # Call a GDK API to create a cairo context
+ gdkLib.gdk_cairo_create.restype = ctypes.c_void_p
         ctxptr = gdkLib.gdk_cairo_create(drawable)

         # Turn it into a pycairo context object
         ctx = pycairoAPI.Context_FromContext(ctxptr,
pycairoAPI.Context_Type, None)

···

-
+
     else:
         raise NotImplementedError, "Help me, I'm lost..."

@@ -156,12 +157,24 @@

         # wow, this is a hell of a lot of steps...
         desc = voidp( font.GetPangoFontDescription() )
- pcfm = voidp( pcLib.pango_cairo_font_map_get_default() )
- pctx = voidp( gdkLib.gdk_pango_context_get() )
+
+ pcLib.pango_cairo_font_map_get_default.restype =
ctypes.c_void_p
+ pcfm = voidp(pcLib.pango_cairo_font_map_get_default())
+
+ gdkLib.gdk_pango_context_get.restype = ctypes.c_void_p
+ pctx = voidp(gdkLib.gdk_pango_context_get())
+
+ pcLib.pango_font_map_load_font.restype = ctypes.c_void_p
         pfnt = voidp( pcLib.pango_font_map_load_font(pcfm, pctx,
desc) )
+
+ pcLib.pango_cairo_font_get_scaled_font.restype =
ctypes.c_void_p
         scaledfontptr = voidp( pcLib.pango_cairo_font_get_scaled_font
(pfnt) )
- fontfaceptr = cairoLib.cairo_scaled_font_get_font_face
(scaledfontptr)
- fontface = pycairoAPI.FontFace_FromFontFace(ctypes.c_void_p
(fontfaceptr))
+
+ cairoLib.cairo_scaled_font_get_font_face.restype =
ctypes.c_void_p
+ fontfaceptr = voidp(cairoLib.cairo_scaled_font_get_font_face
(scaledfontptr))
+
+ fontface = pycairoAPI.FontFace_FromFontFace(fontfaceptr)
+
         gdkLib.g_object_unref(pctx)

     else:
zamblap:lib zamb$

Cheers,
Ricardo

On Jan 6, 7:10 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 1/6/10 3:58 AM, zamb wrote:

> Hi

> Well, the bitamp (actually PNG) issues were related to a separate
> library issue on my side (two versions of the same library linked
> against different packages), so no wxPython problems here. I did run
> into problems with the FontFaceFromFont routine (which was breaking
> demo/Cairo.py). The fix is similar to the previous one. The fixed code
> now reads:

Could you please send this as a proper patch file (a unified diff
between the original and your changed version) so I can more clearly see
exactly what changed and where?

Thanks.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Next time please send it as a mail attachment, otherwise the lines get wrapped and mangled and the patch wont apply.

···

On 1/7/10 3:27 AM, Ricardo Fonseca wrote:

Sure thing:

--
Robin Dunn
Software Craftsman