anchor.diff:  ;; License along with this library; if not, write to the Free Software
   ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   
  -;; $Id: glib.lisp,v 1.6 2000-09-04 22:10:26 espen Exp $
  +;; $Id: glib.lisp,v 1.7 2000-10-05 17:17:41 espen Exp $
   
   
   (in-package "GLIB")
  
positive.code: 
  
  
  ;;;; Linked list
  
  (deftype glist () 'pointer)
  (deftype double-list (type) `(or (null (cons ,type list))))
  
  
  (define-foreign ("g_list_append" %glist-append) () glist
    (glist glist)
    (data unsigned))
  
  (defmacro glist-append (glist value type-spec)
    (ecase (first (mklist (translate-type-spec type-spec)))
      (unsigned `(%glist-append ,glist ,value))
  ;    (signed `(%glist-append ,glist (signed-to-unsigned ,value)))
      (system-area-pointer `(%glist-append ,glist (system:sap-int ,value)))))
  
  
  (defmacro glist-data (glist type-spec)
    (ecase (first (mklist (translate-type-spec type-spec)))
  
negative.code: 	   (dotimes (i ,(if (eq length '*) '(length vector) length) c-vector)
  	     (setf
  	      (,(sap-ref-fname element-type) c-vector (* i ,element-size))
  	      ,(translate-to-alien element-type '(aref vector i) :copy))))))))
  
  (deftype-method translate-from-alien
      vector (type-spec sap &optional (alloc :reference))
    (destructuring-bind (element-type &optional (length '*))
        (cdr (type-expand-to 'vector type-spec))
      (when (eq length '*)
        (error "Can't use vectors of variable length as return type"))
      (let ((element-size (size-of element-type)))
        `(let ((sap ,sap)
  	     (vector (make-array ,length :element-type ',element-type)))
  	 (dotimes (i ,length vector)
  	   (setf
  	    (aref vector i)
  	    ,(translate-to-alien
  	      element-type
  	      `(,(sap-ref-fname element-type) sap (* i ,element-size))
  	      alloc)))))))
  
  
  (deftype-method cleanup-alien vector (type-spec sap &optional copied)
    (declare (ignore type-spec copied))
  