[Ecls-list] tiny problem with in-package - maybe...

Teunis Peters teunis at wintersgift.com
Fri Aug 29 08:56:50 UTC 2008


this worked in SBCL, just to let you know.   It also worked fine when 
NOT using 'in-package'.  I've been having some issues with my packages 
and thought it was due to my code so I 'whipped' up this test:
(note: rather linux-specific or at least specific to platforms that have 
dbus.  Also : uses cffi as I find it easier)

I'm also not sure why cffi can't do load-foreign-library...   maybe a 
CFFI issue though.   I really like packages for organization... but I'm 
not 100% attached to continuing with them.   They do look so very handy 
though.

resulting error from the code below is:  (with :name)
;;; Compiling (DEFVAR DBERROR ...).
;;; Compiling (DEFVAR CONN ...).
An error occurred during initialization:
Error: in file test-ffi.lisp, position 16, and form
  (IF (NULL-POINTER-P CONN) (PROGN # # ...))
;;; The macro form (CFFI:FOREIGN-SLOT-VALUE COMMON-LISP::DBERROR 
'DBUS:DBUSERROR :NAME) was not expanded successfully.
;;; You are recommended to compile again.

and with 'name:
;;; Compiling (DEFVAR CONN ...).
An error occurred during initialization:
Error: in file test-ffi.lisp, position 16, and form
  (IF (NULL-POINTER-P CONN) (PROGN # # ...))
;;; The macro form (CFFI:FOREIGN-SLOT-VALUE COMMON-LISP::DBERROR
                         'DBUS:DBUSERROR
                         'COMMON-LISP::NAME) was not expanded successfully.
;;; You are recommended to compile again

... while it MAY be a CFFI issue - this code works just fine in sbcl and 
the error code is hardly helpful.  dbus:dbuserror 'name - should work.  
(or :name - I've tried both)

; test-ffi.lisp
(require 'cffi)
(defpackage #:dbus
  (:use #:common-lisp)
  (:export :DBusError :BusType :BUS_SESSION BUS_SYSTEM BUS_STARTER
            :error_init :bus_get
  )
)

(in-package :dbus)

#-ecl
(cffi:load-foreign-library "libdbus-1.so")
#-ecl
(cffi:load-foreign-library "libdbus-glib-1.so")

#+ecl
(ffi:load-foreign-library "/lib/libdbus-1.so")
#+ecl
(ffi:load-foreign-library "/usr/lib/libdbus-glib-1.so")

(cffi:defcstruct DBusError
    (name :string)
    (message :string)
    (dummy1 :unsigned-int)
    (dummy2 :unsigned-int)
    (dummy3 :unsigned-int)
    (dummy4 :unsigned-int)
    (dummy5 :unsigned-int)
    (padding1 :pointer))

; alternative to enum: more portable
(cffi:defctype BusType :long)
(defparameter BUS_SESSION 0 "DBus bus type: session")
(defparameter BUS_SYSTEM  1 "DBus bus type: system")
(defparameter BUS_STARTER 2 "DBus bus type: starter")

(cffi:defcfun ("dbus_error_init" error_init) :void
  (error :pointer))

(cffi:defcfun ("dbus_bus_get" bus_get) :pointer
  (type BusType)
  (error :pointer))

(in-package :cl)

(defvar dberror (cffi:foreign-alloc 'dbus:DBusError) "DBus error")
(dbus:error_init dberror)
(defvar conn (dbus:bus_get dbus:BUS_SYSTEM dberror) "DBus connection")
(if (cffi:null-pointer-p conn)
   (progn (error "dbus_bus_get: ~a~ ~a~%"
         (cffi:foreign-slot-value dberror 'dbus:DBusError :name)
         (cffi:foreign-slot-value dberror 'dbus:DBusError :message))
      (cffi:foreign-free dberror)
      (quit)
      ; (LIBHAL_FREE_DBUS_ERROR &error)
      )
   )
(cffi:foreign-free conn)





More information about the ecl-devel mailing list