Add support for saving images with Clozure
[cl-gtk2.git] / glib / glib.gstrv.lisp
blob810fc39a56c11e6aae1ae1ac89a6e5c38e051db6
1 (in-package :glib)
3 (define-foreign-type gstrv-type ()
4 ((free-from-foreign :initarg :free-from-foreign :initform t :reader gstrv-type-fff)
5 (free-to-foreign :initarg :free-to-foreign :initform t :reader gstrv-type-ftf))
6 (:actual-type :pointer))
8 (define-parse-method gstrv (&key (free-from-foreign t) (free-to-foreign t))
9 (make-instance 'gstrv-type :free-from-foreign free-from-foreign :free-to-foreign free-to-foreign))
11 (defmethod translate-from-foreign (value (type gstrv-type))
12 (unless (null-pointer-p value)
13 (prog1
14 (iter (for i from 0)
15 (for str-ptr = (mem-aref value :pointer i))
16 (until (null-pointer-p str-ptr))
17 (collect (convert-from-foreign str-ptr '(:string :free-from-foreign nil)))
18 (when (gstrv-type-fff type)
19 (g-free str-ptr)))
20 (when (gstrv-type-fff type)
21 (g-free value)))))
23 (defmethod translate-to-foreign (str-list (type gstrv-type))
24 (let* ((n (length str-list))
25 (result (g-malloc (* (1+ n) (foreign-type-size :pointer)))))
26 (iter (for i from 0)
27 (for str in str-list)
28 (setf (mem-aref result :pointer i) (g-strdup str)))
29 (setf (mem-aref result :pointer n) (null-pointer))
30 result))