dark-panda / ffi-geos

ffi-geos is an implementation of the GEOS Ruby bindings in Ruby via FFI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Geometry.dup should clone the geometry

dazuma opened this issue · comments

0.0.1.beta2

Geometry.clone performs a GEOSGeom_clone_r. Geometry.dup does not. As a result, if you dup a geometry (a shallow copy by default), the two copies share the same autopointer. Now if one of the copies gets collected, the autopointer will get released, which throws the other into a bad state. I suggest dup should also perform GEOSGeom_clone_r.

commented

I've written a patch that implements initialize_copy methods on Geometry and CoordinateSequence that I believe should take care of these situations rather than relying on an actual clone method, which was pretty bad form on my part to begin with.

The remaining classes (BufferParams, PreparedGeometry and STRTree) don't have cloning functions in the GEOS CAPI... what would you think about disabling those methods for those classes by raising exceptions for those classes on calls to clone and dup? BufferParams doesn't really need to be instantiated so much anyways as it really just acts as a wrapper for options, PreparedGeometry can't be instantiated directly anyways, and STRTree, well... that one I could clone by hand I suppose.

I've pushed a fix in 13889a5 if you'd like to try things out. Cheers.

Thanks. The patch looks good so far on my end. I agree on Buffer Params, PreparedGeometry, and STRTree: they can raise exceptions. We just need something better than segfaults. :-)

commented

Think we've closed the book on this one, so closing.