[cl-pdf-devel] CMUCL compatibility fixes and new color handlingcode

Edi Weitz edi at agharta.de
Tue Apr 13 20:13:07 UTC 2004


On Tue, 13 Apr 2004 14:28:51 +0200, "Marc Battyani" <marc.battyani at fractalconcept.com> wrote:

> BTW as you are the latest one who changed the zlib FFI ;-), have you
> some ideas on the CMUCL FFI problem?

IIRC the problem is that CMUCL can't compile an
ALIEN:DEF-ALIEN-ROUTINE (which is what UFFI:DEF-FUNCTION translates
to) unless the corresponding library is already loaded, so the
LOAD-ZLIB approach won't work. I think you need to split it into two
files, something like this:

--------------------------- init.lisp ---------------------------

(in-package pdf)

(defvar *zlib-loaded* nil)

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defun find-zlib-path ()
    (uffi:find-foreign-library
     "libz"
     *zlib-search-paths*
     :drive-letters '("C" "D" "E")
     :types '("so" "a" "dll" "dylib"))))

#+:cmu
(eval-when (:compile-toplevel :load-toplevel :execute)
  (let ((zlib-path (find-zlib-path)))
    (when zlib-path
      (format t "~&;;; Loading ~s" zlib-path)
      (uffi:load-foreign-library zlib-path
                                 :module "zlib" 
                                 :supporting-libraries '("c"))
      (pushnew :zlib-found *features*))))

--------------------------- init.lisp ---------------------------

--------------------------- init2.lisp ---------------------------

(in-package pdf)

(defun load-zlib (&optional force)
  (when force (setf *zlib-loaded* nil))
  (unless *zlib-loaded*
    (let ((zlib-path (find-zlib-path)))
      (if zlib-path
	  (progn
	    (format t "~&;;; Loading ~s" zlib-path)
	    (uffi:load-foreign-library zlib-path
				       :module "zlib" 
				       :supporting-libraries '("c"))
            #+(or (not :cmu) :zlib-found)
	    (uffi:def-function ("compress" c-compress)
		((dest (* :unsigned-char))
		 (destlen (* :long))
		 (source :cstring)
		 (source-len :long))
	      :returning :int
	      :module "zlib")
	    (setf *zlib-loaded* t *compress-streams* t))
	  (progn
	    (warn "Unable to load zlib. Disabling compression.")
	    (setf *compress-streams* nil))))))

(load-zlib)

--------------------------- init2.lisp ---------------------------

Disclaimer: I'm not a CMUCL expert. You should ask on their mailing
list.

BTW, UFFI already keeps track of loaded foreign libraries and won't
load the same library twice unless you force it to do so. So
*ZLIB-LOADED* is actually not needed. Or, from a different angle, the
FORCE argument to LOAD-ZLIB is bogus unless you call UFFI like
  
  (UFFI:LOAD-FOREIGN-LIBRARY ... :FORCE-LOAD FORCE)

HTH,
Edi.




More information about the cl-pdf-devel mailing list