[gtk-cffi-cvs] CVS gtk-cffi/g-lib

CVS User rklochkov rklochkov at common-lisp.net
Fri Sep 16 17:58:33 UTC 2011


Update of /project/gtk-cffi/cvsroot/gtk-cffi/g-lib
In directory tiger.common-lisp.net:/tmp/cvs-serv8326/g-lib

Modified Files:
	array.lisp 
Log Message:
Added PangoTabArray cffi foreign type
Fixed cffi-struct in array issues
Added pack of slots to GtkTextView


--- /project/gtk-cffi/cvsroot/gtk-cffi/g-lib/array.lisp	2011/09/10 16:26:10	1.3
+++ /project/gtk-cffi/cvsroot/gtk-cffi/g-lib/array.lisp	2011/09/16 17:58:33	1.4
@@ -9,11 +9,6 @@
 
 (defvar *array-length* (foreign-alloc :uint))
 
-;(defmacro with-array (&body body)
-;  `(with-foreign-object (*array-length* :uint)
-;     , at body)
-     
-
 (define-foreign-type cffi-array ()
   ((element-type :initarg :type :accessor element-type))
   (:actual-type :pointer))
@@ -25,32 +20,26 @@
 (defmethod translate-to-foreign (value (cffi-array cffi-array))
   (if (pointerp value)
       value
-      (let ((length (length value))
-            (type (element-type cffi-array)))
-        (let ((res (foreign-alloc type :count length)))
-                (dotimes (i length (values res t))
-                  (setf (mem-aref res type i) (elt value i)))))))
+      (let* ((length (length value))
+             (type (element-type cffi-array))
+             (res (foreign-alloc type :count length)))
+        (dotimes (i length (values res t))
+          (setf (mem-aref res type i) (elt value i)))
+        res)))
 
 (defmethod free-translated-object (value (cffi-array cffi-array) param)
-  (when param
-    (foreign-free value)))
+  (declare (ignore param))
+  (foreign-free value))
 
 (defcfun g-free :void (var :pointer))
 
 (defmethod translate-from-foreign (ptr (cffi-array cffi-array))
   (let ((array-length (mem-ref *array-length* :uint)))
     (let* ((res (make-array array-length))
-           (el-type (element-type cffi-array))
-           (struct (and (consp el-type) (eq (car el-type) 'struct))))
+           (el-type (element-type cffi-array)))
       (iter
         (for i from 0 below array-length)
         (setf (aref res i)
-              (if struct
-                  ;; if this is array of structs, we shouldn't think, that
-                  ;; elements are pointers to struct
-                  (convert-from-foreign 
-                   (inc-pointer ptr (* (foreign-type-size (second el-type)) i))
-                   el-type)
-                  (mem-aref ptr el-type i))))
+              (mem-aref ptr el-type i)))
       (g-free ptr)
       res)))





More information about the gtk-cffi-cvs mailing list