[geos-devel] Ruby, FFI and ERROR_/NOTICE_MESSAGE

J Smith dark.panda+lists at gmail.com
Thu Dec 9 17:45:00 EST 2010


On Thu, Dec 9, 2010 at 12:32 PM, Sean Gillies <sean.gillies at gmail.com> wrote:
> FWIW, here's the GeoDjango approach:
>
>  http://code.djangoproject.com/browser/django/trunk/django/contrib/gis/geos/libgeos.py#L53
>
> and the Shapely approach:
>
>  https://github.com/sgillies/shapely/blob/master/shapely/geos.py#L148
>
> Shapely by default takes the error messages and sends them to
> /dev/null because I didn't find them super useful. Each of the above
> use a callback factory from ctypes
>
>  http://docs.python.org/library/ctypes.html#callback-functions

I was poking around those projects last night and gave a similar
approach a try by tossing the errors out and relying on return values
from GEOS functions instead, but the problem remains.

I pared everything down to a minimal script to reproduce the problem.
Here's where it gets weird... this is the definition of the
initialization with the notice and error handlers:

def error_handler(*args)
  #print "anything"
  raise args[0] % args[1]
end

This will cause the segfault/weirdness to occur. However, when you
uncomment the print line, you get no segfault or weirdness. The print
line can even output an empty string so long as you NULL terminate it,
so outputting with 'print "\0"' will still eliminate the segfaults.

I'll drop a line to the FFI groups when I get a chance and we'll see
how that goes.

Cheers


More information about the geos-devel mailing list