Ferada / cl-cffi-gtk

#cl-cffi-gtk on Freenode. A Lisp binding to GTK+3. SBCL/CCL/ABCL (ECL/CLISP unstable)
http://www.crategus.com/books/cl-cffi-gtk
41 stars 8 forks source link

Register object type implementation after defining class #1

Closed glv2 closed 7 years ago

glv2 commented 7 years ago

I got a strange issue when trying to compile the gtk/gtk.array-list-store.lisp file. The compilation failed because it couldn't find the array-list-store and tree-lisp-store classes.

However, this error only occured when compiling with SBCL from a Roswell script. Everything worked fine when compiling directly with SBCL.

Anyway, by moving the register-object-type-implementation calls after the class definitions, compilation works in all cases.

Ferada commented 7 years ago

Thanks for taking a look and I apologise for not pushing some more local commits earlier, but could you try running again now from the same branch fixes?

glv2 commented 7 years ago

The new commits fixed the original issue, and everything works well with SBCL.

However, CCL and ECL refuse to compile the gobject/gobject.base.lisp file because they don't accept the :synchronized keyword in the make-weak-hash-table and make-hash-table calls.

Ferada commented 7 years ago

Updated. Right, only available on SBCL (and maybe others), I put a lock around it instead (might be overkill but I'm not going to special case this).

Note that I'm not sure this is completely correct but I didn't see any more corrupted hash table warnings after. YMMV.

glv2 commented 7 years ago

In one of my apps which loads images using several threads, SBCL and ECL complain because they try to lock a mutex twice. Using make-recursive-lock and with-recursive-lock-held instead of make-lock and with-lock-held solves the problem.

My app still doesn't work with CCL and ECL because my function loading and resizing images throws a "null-pointer in parse-g-param-spec" error. I've not yet determined what causes this.

However, SBCL works fine (with the recursive lock).

Ferada commented 7 years ago

Thanks. If you have a minimal example I could take a look.

Edit: In case you're running via gtk-application I get the same from the GTK demo application too:

? (GTK-DEMO::DEMO-APPLICATION)
Bloatpad
> Error: null-pointer in parse-g-param-spec
> While executing: GOBJECT:PARSE-G-PARAM-SPEC, in process listener(1).

(7F77E200E280) : 0 (PARSE-G-PARAM-SPEC #<A Null Foreign Pointer>) 77
(7F77E200E298) : 1 (CLASS-PROPERTY-INFO #<GTYPE :name "GtkSettings" :id 140152769409360> "gtk-settings-gtk-recent-files-enabled") 213
(7F77E200E300) : 2 (CLASS-PROPERTY-TYPE #<GTYPE :name "GtkSettings" :id 140152769409360> "gtk-settings-gtk-recent-files-enabled" :ASSERT-READABLE T :ASSERT-WRITABLE NIL) 101
(7F77E200E340) : 3 (FUNCALL #'#<#<COMMON-LISP:STANDARD-METHOD SLOT-BOUNDP-USING-CLASS (GOBJECT-CLASS T GOBJECT::GOBJECT-PROPERTY-EFFECTIVE-SLOT-DEFINITION)>> #<GOBJECT-CLASS GTK-SETTINGS> #<GTK-SETTINGS #x3020043E9D7D> #<GOBJECT-PROPERTY-EFFECTIVE-SLOT-DEFINITION for gobject-property slot GTK::GTK-RECENT-FILES-ENABLED #x302001D20DED>) 421
(7F77E200E390) : 4 (%SHARED-INITIALIZE #<GTK-SETTINGS #x3020043E9D7D> T (:POINTER #<A Foreign Pointer #x7F77DC1076E0>)) 941
(7F77E200E408) : 5 (FUNCALL #'#<#<CCL::STANDARD-KERNEL-METHOD SHARED-INITIALIZE (STANDARD-OBJECT T)>> #<GTK-SETTINGS #x3020043E9D7D> T :POINTER #<A Foreign Pointer #x7F77DC1076E0>) 125
(7F77E200E438) : 6 (FUNCALL #'#<#<CCL::STANDARD-KERNEL-METHOD INITIALIZE-INSTANCE (STANDARD-OBJECT)>> #<GTK-SETTINGS #x3020043E9D7D> :POINTER #<A Foreign Pointer #x7F77DC1076E0>) 149
(7F77E200E460) : 7 (%%CNM-WITH-ARGS-COMBINED-METHOD-DCODE #(#<COMMON-LISP:STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE #x302000021C3F> (#<#> #<#> #<#> #<#>) (#<COMMON-LISP:STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE #x302000021C3F> #) #<Compiled-function CCL::%%CNM-WITH-ARGS-CHECK-INITARGS #x30000020DEEF> (#<#> NIL # #<#> #<#>)) (#<GTK-SETTINGS #x3020043E9D7D> :POINTER #<A Foreign Pointer #x7F77DC1076E0>) (#(#<
COMMON-LISP:STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE #x302000021C3F> # # # #) (#<#>) . 17519108693209)) 997
(7F77E200E4B8) : 8 (%CALL-NEXT-METHOD-WITH-ARGS (#(#<COMMON-LISP:STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE #x302000021C3F> # # # #) (#<#>) . 17519108693209) #<GTK-SETTINGS #x3020043E9D7D> :POINTER #<A Foreign Pointer #x7F77DC1076E0>) 381
(7F77E200E4F8) : 9 (FUNCALL #'#<#<COMMON-LISP:STANDARD-METHOD INITIALIZE-INSTANCE (G-OBJECT)>> #<GTK-SETTINGS #x3020043E9D7D> :POINTER #<A Foreign Pointer #x7F77DC1076E0>) 245
(7F77E200E530) : 10 (%%BEFORE-AND-AFTER-COMBINED-METHOD-DCODE (#(#<COMMON-LISP:STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE #x302000021C3F> # # # #) (#<#>) . 17519108693209)) 845
(7F77E200E5A0) : 11 (%CALL-NEXT-METHOD (#(#<COMMON-LISP:STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE #x302000021C3F> # # # #) (#<#>) . 17519108693209)) 509
(7F77E200E618) : 12 (FUNCALL #'#<#<COMMON-LISP:STANDARD-METHOD INITIALIZE-INSTANCE :AROUND (G-OBJECT)>> #<GTK-SETTINGS #x3020043E9D7D>) 309
(7F77E200E660) : 13 (%%CNM-WITH-ARGS-COMBINED-METHOD-DCODE #(#<COMMON-LISP:STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE #x302000021C3F> (#<#> #<#> #<#> #<#>) (#<COMMON-LISP:STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE #x302000021C3F> #) #<Compiled-function CCL::%%CNM-WITH-ARGS-CHECK-INITARGS #x30000020DEEF> (#<#> NIL # #<#> #<#>)) 17519108693209 NIL) 1133
(7F77E200E6E8) : 14 (%MAKE-STD-INSTANCE #<GOBJECT-CLASS GTK-SETTINGS> (:POINTER #<A Foreign Pointer #x7F77DC1076E0>)) 317
(7F77E200E710) : 15 (FUNCALL #'#<#<CCL::STANDARD-KERNEL-METHOD MAKE-INSTANCE (COMMON-LISP:STANDARD-CLASS)>> #<GOBJECT-CLASS GTK-SETTINGS> :POINTER #<A Foreign Pointer #x7F77DC1076E0>) 157
(7F77E200E738) : 16 (%CALL-NEXT-METHOD (#(#<COMMON-LISP:STANDARD-GENERIC-FUNCTION MAKE-INSTANCE #x30200002BCFF> # NIL NIL #) #<CCL::STANDARD-KERNEL-METHOD MAKE-INSTANCE #> . 17519108693265)) 1061
(7F77E200E7B8) : 17 (FUNCALL #'#<#<COMMON-LISP:STANDARD-METHOD MAKE-INSTANCE (GOBJECT-CLASS)>> #<GOBJECT-CLASS GTK-SETTINGS> :POINTER #<A Foreign Pointer #x7F77DC1076E0>) 445
(7F77E200E818) : 18 (%%CNM-WITH-ARGS-COMBINED-METHOD-DCODE #(#<COMMON-LISP:STANDARD-GENERIC-FUNCTION MAKE-INSTANCE #x30200002BCFF> (#<#> #<#> #<#>) NIL NIL (#<#> #<#>)) 17519108693265 NIL) 1133
(7F77E200E8E0) : 19 (FUNCALL #'#<#<CCL::STANDARD-KERNEL-METHOD MAKE-INSTANCE (SYMBOL)>> GTK-SETTINGS :POINTER #<A Foreign Pointer #x7F77DC1076E0>) 165
(7F77E200E908) : 20 (CREATE-GOBJECT-FROM-POINTER #<A Foreign Pointer #x7F77DC1076E0>) 309
(7F77E200E958) : 21 (GET-G-OBJECT-FOR-POINTER #<A Foreign Pointer #x7F77DC1076E0>) 589
(7F77E200E9B8) : 22 (FUNCALL #'#<#<COMMON-LISP:STANDARD-METHOD TRANSLATE-FROM-FOREIGN (T GOBJECT::FOREIGN-G-OBJECT-TYPE)>> #<A Foreign Pointer #x7F77DC1076E0> #<GOBJECT::FOREIGN-G-OBJECT-TYPE #x302001D2739D>) 45
(7F77E200E9D8) : 23 (GTK-SETTINGS-GET-DEFAULT) 197

The exact same call, (gobject::class-property-info (gobject::gtype "GtkSettings") "gtk-settings-gtk-recent-files-enabled") fails in SBCL as well though, so I think it's just not being called there.

Ferada commented 7 years ago

Updated, @glv2 try again please, I believe this was a spelling error for the property name.

glv2 commented 7 years ago

Here's a small example that works in SBCL and fails because of a null-pointer in CCL and ECL:

(require 'cl-cffi-gtk)

(defpackage load-img
  (:use cl gdk gdk-pixbuf glib gobject gtk)
  (:export test))

(in-package load-img)

(defun load-img (pathspec)
  (gdk-pixbuf-animation-new-from-file (namestring pathspec)))

(defun test ()
  (within-main-loop
    (load-img "test.jpg")
    (leave-gtk-main))
  (join-gtk-main))

(load-img:test)
Ferada commented 7 years ago

Seems like CCL is more eagerly accessing slots, so all of these so far were slots misspelled or on the wrong classes. Good to know to check with that implementation then.

Updated again and I can run that example now on CCL too.

glv2 commented 7 years ago

I confirm that with the last update everything works fine with SBCL, CCL and ECL. Thanks!