crategus / cl-cffi-gtk

cl-cffi-gtk is a Lisp binding to the GTK+ 3 library.
http://www.crategus.com/books/cl-cffi-gtk
145 stars 33 forks source link

wrong uses of with-foreign-object #87

Open aymeric-nb opened 3 years ago

aymeric-nb commented 3 years ago

Hi,

cairo-font-extents in cairo/cairo.text.lisp returns a (:struct cairo-font-extents-t) obtained from with-foreign-object.

However, according to with-foreign-object's documentation, the object created by it is not valid outside the scope of with-foreign-object, if I understand correctly.

Indeed, accessing a field of the returned structure leads to a crash at least under ECL on NetBSD/amd64.

Sorry for not providing any patch, but I don't see a way around this bug without changing the lisp API. A workaround is to use directly cairo::%cairo-font-extents but as the name implies, this is suboptimal.

A quick look around shows there are other such uses in other functions, so if you confirm my analysis, I think you should audit all uses of with-foreign-object and similar macros.

Regards

stacksmith commented 3 years ago

There are many terrible things hidden here, due to the author's misunderstanding of GTK objects and their lifespan. Beware.