8c93a35e682f07ee888832418a6653e767011464
[cl-gtk2.git] / glib / gobject.boxed.lisp
1 (in-package :gobject)
2
3 (define-foreign-type g-boxed-foreign-type ()
4   ((info :initarg :info
5          :accessor g-boxed-foreign-info
6          :initform (error "info must be specified"))
7    (return-p :initarg :return-p
8              :accessor g-boxed-foreign-return-p
9              :initform nil))
10   (:actual-type :pointer))
11
12 (eval-when (:compile-toplevel :load-toplevel :execute)
13   (defstruct g-boxed-info
14     name
15     g-type))
16
17 (eval-when (:compile-toplevel :load-toplevel :execute)
18   (defun get-g-boxed-foreign-info (name)
19     (get name 'g-boxed-foreign-info)))
20
21 (defvar *g-type-name->g-boxed-foreign-info* (make-hash-table :test 'equal))
22
23 (defun get-g-boxed-foreign-info-for-gtype (g-type-designator)
24   (or (gethash (g-type-string g-type-designator) *g-type-name->g-boxed-foreign-info*)
25       (error "Unknown GBoxed type '~A'" (g-type-string g-type-designator))))
26
27 (defgeneric make-foreign-type (info &key return-p))
28
29 (define-parse-method g-boxed-foreign (name &rest options)
30   (let ((info (get-g-boxed-foreign-info name)))
31     (assert info nil "Unknown foreign GBoxed type ~A" name)
32     (make-foreign-type info :return-p (member :return options))))
33
34 (defgeneric boxed-copy-fn (type-info native)
35   (:method (type-info native)
36     (g-boxed-copy (g-boxed-info-g-type type-info) native)))
37
38 (defmethod boxed-copy-fn :before (type-info native)
39   (format t "(boxed-copy-fn ~A ~A)~%" (g-boxed-info-name type-info) native))
40
41 (defgeneric boxed-free-fn (type-info native)
42   (:method (type-info native)
43     (g-boxed-free (g-boxed-info-g-type type-info) native)))
44
45 (defmethod boxed-free-fn :before (type-info native)
46   (format t "(boxed-free-fn ~A ~A)~%" (g-boxed-info-name type-info) native))
47
48 (defmethod has-callback-cleanup ((type g-boxed-foreign-type))
49   t)
50
51 (eval-when (:load-toplevel :compile-toplevel :execute)
52   (defstruct (g-boxed-cstruct-wrapper-info (:include g-boxed-info))
53     cstruct-description))
54
55 (defclass boxed-cstruct-foreign-type (g-boxed-foreign-type) ())
56
57 (defstruct cstruct-slot-description
58   name
59   type
60   count
61   initform
62   inline-p)
63
64 (defstruct (cstruct-inline-slot-description (:include cstruct-slot-description))
65   boxed-type-name)
66
67 (defmethod make-load-form ((object cstruct-slot-description) &optional environment)
68   (make-load-form-saving-slots object :environment environment))
69
70 (defmethod make-load-form ((object cstruct-inline-slot-description) &optional environment)
71   (make-load-form-saving-slots object :environment environment))
72
73 (defstruct cstruct-description
74   name
75   slots)
76
77 (defmethod make-load-form ((object cstruct-description) &optional environment)
78   (make-load-form-saving-slots object :environment environment))
79
80 (defun parse-cstruct-slot (slot)
81   (destructuring-bind (name type &key count initform inline) slot
82     (if inline
83         (make-cstruct-inline-slot-description :name name :type (generated-cunion-name type)
84                                        :count count :initform initform :inline-p inline
85                                        :boxed-type-name type)
86         (make-cstruct-inline-slot-description :name name :type type
87                                               :count count :initform initform :inline-p inline))))
88
89 (defun parse-cstruct-definition (name slots)
90   (make-cstruct-description :name name
91                             :slots (mapcar #'parse-cstruct-slot slots)))
92
93 (defmacro define-g-boxed-cstruct (name g-type-name &body slots)
94   (let ((cstruct-description (parse-cstruct-definition name slots)))
95     `(progn
96        (defstruct ,name
97          ,@(iter (for slot in (cstruct-description-slots cstruct-description))
98                  (for name = (cstruct-slot-description-name slot))
99                  (for initform = (cstruct-slot-description-initform slot))
100                  (collect (list name initform))))
101        (defcstruct ,(generated-cstruct-name name)
102          ,@(iter (for slot in (cstruct-description-slots cstruct-description))
103                  (for name = (cstruct-slot-description-name slot))
104                  (for type = (cstruct-slot-description-type slot))
105                  (for count = (cstruct-slot-description-count slot))
106                  (collect `(,name ,type ,@(when count `(:count ,count))))))
107        (defcunion ,(generated-cunion-name name)
108          (,name ,(generated-cstruct-name name)))
109        (eval-when (:compile-toplevel :load-toplevel :execute)
110          (setf (get ',name 'g-boxed-foreign-info)
111                (make-g-boxed-cstruct-wrapper-info :name ',name
112                                                   :g-type ,g-type-name
113                                                   :cstruct-description ,cstruct-description)
114                (gethash ,g-type-name *g-type-name->g-boxed-foreign-info*)
115                (get ',name 'g-boxed-foreign-info))))))
116
117 (defmethod make-foreign-type ((info g-boxed-cstruct-wrapper-info) &key return-p)
118   (make-instance 'boxed-cstruct-foreign-type :info info :return-p return-p))
119
120 (defun memcpy (target source bytes)
121   (iter (for i from 0 below bytes)
122         (setf (mem-aref target :uchar i)
123               (mem-aref source :uchar i))))
124
125 (defmethod boxed-copy-fn ((info g-boxed-cstruct-wrapper-info) native)
126   (if (g-boxed-info-g-type info)
127       (g-boxed-copy (g-boxed-info-g-type info) native)
128       (let ((copy (foreign-alloc (generated-cstruct-name (g-boxed-info-name info)))))
129         (memcpy copy native (foreign-type-size (generated-cstruct-name (g-boxed-info-name info))))
130         copy)))
131
132 (defmethod boxed-free-fn ((info g-boxed-cstruct-wrapper-info) native)
133   (if (g-boxed-info-g-type info)
134       (g-boxed-free (g-boxed-info-g-type info) native)
135       (foreign-free native)))
136
137 (defun copy-slots-to-native (proxy native cstruct-description)
138   (iter (with cstruct-type = (generated-cstruct-name (cstruct-description-name cstruct-description)))
139         (for slot in (cstruct-description-slots cstruct-description))
140         (for slot-name = (cstruct-slot-description-name slot))
141         (cond
142           ((cstruct-slot-description-count slot)
143            (iter (with ptr = (foreign-slot-pointer native cstruct-type slot-name))
144                  (with array = (slot-value proxy slot-name))
145                  (for i from 0 below (cstruct-slot-description-count slot))
146                  (setf (mem-aref ptr (cstruct-slot-description-type slot) i)
147                        (aref array i))))
148           ((cstruct-slot-description-inline-p slot)
149            (let ((info (get-g-boxed-foreign-info (cstruct-inline-slot-description-boxed-type-name slot))))
150              (copy-slots-to-native (slot-value proxy slot-name)
151                                    (foreign-slot-pointer native cstruct-type slot-name)
152                                    (g-boxed-cstruct-wrapper-info-cstruct-description info))))
153           (t
154            (setf (foreign-slot-value native cstruct-type slot-name)
155                  (slot-value proxy slot-name))))))
156
157 (defun copy-slots-to-proxy (proxy native cstruct-description)
158   (iter (with cstruct-type = (generated-cstruct-name (cstruct-description-name cstruct-description)))
159         (for slot in (cstruct-description-slots cstruct-description))
160         (for slot-name = (cstruct-slot-description-name slot))
161         (cond
162           ((cstruct-slot-description-count slot)
163            (setf (slot-value proxy slot-name) (make-array (list (cstruct-slot-description-count slot))))
164            (iter (with ptr = (foreign-slot-pointer native cstruct-type slot-name))
165                  (with array = (slot-value proxy slot-name))
166                  (for i from 0 below (cstruct-slot-description-count slot))
167                  (setf (aref array i)
168                        (mem-aref ptr (cstruct-slot-description-type slot) i))))
169           ((cstruct-slot-description-inline-p slot)
170            (let ((info (get-g-boxed-foreign-info (cstruct-inline-slot-description-boxed-type-name slot))))
171              (copy-slots-to-proxy (slot-value proxy slot-name)
172                                   (foreign-slot-pointer native cstruct-type slot-name)
173                                   (g-boxed-cstruct-wrapper-info-cstruct-description info))))
174           (t (setf (slot-value proxy slot-name)
175                    (foreign-slot-value native cstruct-type slot-name))))))
176
177 (defmethod translate-to-foreign (proxy (type boxed-cstruct-foreign-type))
178   (if (null proxy)
179       (null-pointer)
180       (let* ((info (g-boxed-foreign-info type))
181              (native-structure-type (generated-cstruct-name (g-boxed-info-name info))))
182         (with-foreign-object (native-structure native-structure-type)
183           (copy-slots-to-native proxy native-structure (g-boxed-cstruct-wrapper-info-cstruct-description info))
184           (values (boxed-copy-fn info native-structure) proxy)))))
185
186 (defmethod free-translated-object (native-structure (type boxed-cstruct-foreign-type) proxy)
187   (when proxy
188     (let ((info (g-boxed-foreign-info type)))
189       (copy-slots-to-proxy proxy native-structure (g-boxed-cstruct-wrapper-info-cstruct-description info))
190       (boxed-free-fn info native-structure))))
191
192 (defmethod translate-from-foreign (native-structure (type boxed-cstruct-foreign-type))
193   (unless (null-pointer-p native-structure)
194     (let* ((info (g-boxed-foreign-info type))
195            (proxy-structure-type (g-boxed-info-name info))
196            (proxy (make-instance proxy-structure-type)))
197       (copy-slots-to-proxy proxy native-structure (g-boxed-cstruct-wrapper-info-cstruct-description info))
198       (when (g-boxed-foreign-return-p type)
199         (boxed-free-fn info native-structure))
200       proxy)))
201
202 (defmethod cleanup-translated-object-for-callback ((type boxed-cstruct-foreign-type) proxy native-structure)
203   (when proxy
204     (let ((info (g-boxed-foreign-info type)))
205       (copy-slots-to-native proxy native-structure (g-boxed-cstruct-wrapper-info-cstruct-description info)))))
206
207 (eval-when (:compile-toplevel :load-toplevel :execute)
208   (defstruct (g-boxed-opaque-wrapper-info (:include g-boxed-info))
209     alloc free))
210
211 (define-foreign-type boxed-opaque-foreign-type (g-boxed-foreign-type) ())
212
213 (defclass g-boxed-opaque ()
214   ((pointer :initarg :pointer
215             :initform nil
216             :accessor g-boxed-opaque-pointer)))
217
218 (defmethod make-foreign-type ((info g-boxed-opaque-wrapper-info) &key return-p)
219   (make-instance 'boxed-opaque-foreign-type :info info :return-p return-p))
220
221 (defmethod translate-to-foreign (proxy (type boxed-opaque-foreign-type))
222   (prog1 (g-boxed-opaque-pointer proxy)
223     (when (g-boxed-foreign-return-p type)
224       (tg:cancel-finalization proxy)
225       (setf (g-boxed-opaque-pointer proxy) nil))))
226
227 (defmethod free-translated-object (native (type boxed-opaque-foreign-type) param)
228   (declare (ignore native type param)))
229
230 (defun make-boxed-free-finalizer (type pointer)
231   (lambda () (boxed-free-fn type pointer)))
232
233 (defmethod translate-from-foreign (native (foreign-type boxed-opaque-foreign-type))
234   (let* ((type (g-boxed-foreign-info foreign-type))
235          (proxy (make-instance (g-boxed-info-name type) :pointer native)))
236     (tg:finalize proxy (make-boxed-free-finalizer type native))))
237
238 (defmethod cleanup-translated-object-for-callback ((type boxed-opaque-foreign-type) proxy native)
239   (tg:cancel-finalization proxy)
240   (setf (g-boxed-opaque-pointer proxy) nil))
241
242 (defmacro define-g-boxed-opaque (name g-type-name &key
243                                  (alloc (error "Alloc must be specified")))
244   (let ((native-copy (gensym "NATIVE-COPY-"))
245         (instance (gensym "INSTANCE-"))
246         (finalizer (gensym "FINALIZER-")))
247     `(progn (defclass ,name (g-boxed-opaque) ())
248             (defmethod initialize-instance :after ((,instance ,name) &key &allow-other-keys)
249               (unless (g-boxed-opaque-pointer ,instance)
250                 (let ((,native-copy ,alloc))
251                   (flet ((,finalizer () (boxed-free-fn ,g-type-name ,native-copy)))
252                     (setf (g-boxed-opaque-pointer ,instance) ,native-copy)
253                     (finalize ,instance (make-boxed-free-finalizer (get ',name 'g-boxed-foreign-info) ,native-copy))))))
254             (eval-when (:compile-toplevel :load-toplevel :execute)
255               (setf (get ',name 'g-boxed-foreign-info)
256                     (make-g-boxed-opaque-wrapper-info :name ',name
257                                                       :g-type ,g-type-name)
258                     (gethash ,g-type-name *g-type-name->g-boxed-foreign-info*)
259                     (get ',name 'g-boxed-foreign-info))))))
260
261 (defstruct var-structure
262   name
263   parent
264   slots
265   discriminator-slot
266   variants
267   resulting-cstruct-description)
268
269 (defstruct var-structure-variant
270   discriminating-values
271   structure)
272
273 (defmethod make-load-form ((object var-structure) &optional env)
274   (make-load-form-saving-slots object :environment env))
275
276 (defmethod make-load-form ((object var-structure-variant) &optional env)
277   (make-load-form-saving-slots object :environment env))
278
279 (defun var-struct-all-slots (struct)
280   (when struct
281     (append (var-struct-all-slots (var-structure-parent struct))
282             (var-structure-slots struct))))
283
284 (defun all-structures (structure)
285   (append (iter (for variant in (var-structure-variants structure))
286                 (appending (all-structures (var-structure-variant-structure variant))))
287           (list structure)))
288
289 (defun parse-variant-structure-definition (name slots &optional parent)
290   (iter (with result = (make-var-structure :name name
291                                            :parent parent
292                                            :slots nil
293                                            :discriminator-slot nil
294                                            :variants nil))
295         (for slot in slots)
296         (if (eq :variant (first slot))
297             (progn
298               (when (var-structure-discriminator-slot result)
299                 (error "Structure has more than one discriminator slot"))
300               (setf (var-structure-discriminator-slot result) (second slot)
301                     (var-structure-variants result) (parse-variants result (nthcdr 2 slot))))
302             (push (parse-cstruct-slot slot) (var-structure-slots result)))
303         (finally (setf (var-structure-slots result)
304                        (reverse (var-structure-slots result)))
305                  (unless parent
306                    (set-variant-result-structure result))
307                  (return result))))
308
309 (defun set-variant-result-structure (var-structure)
310   (setf (var-structure-resulting-cstruct-description var-structure)
311         (make-cstruct-description
312          :name
313          (var-structure-name var-structure)
314          :slots
315          (append
316           (when (var-structure-parent var-structure)
317             (cstruct-description-slots (var-structure-resulting-cstruct-description (var-structure-parent var-structure))))
318           (var-structure-slots var-structure))))
319   (iter (for variant in (var-structure-variants var-structure))
320         (for child-var-structure = (var-structure-variant-structure variant))
321         (set-variant-result-structure child-var-structure)))
322
323 (defun ensure-list (thing)
324   (if (listp thing)
325       thing
326       (list thing)))
327
328 (defun parse-variants (parent variants)
329   (iter (for var-descr in variants)
330         (for (options variant-name . slots) in variants)
331         (for variant =
332              (make-var-structure-variant
333               :discriminating-values (ensure-list options)
334               :structure (parse-variant-structure-definition variant-name slots parent)))
335         (collect variant)))
336
337 (defpackage :gobject.boxed.generated-names)
338
339 (defun generated-cstruct-name (symbol)
340   (or (get symbol 'generated-cstruct-name)
341       (setf (get symbol 'generated-cstruct-name) (gentemp (format nil "CSTRUCT-~A" (symbol-name symbol)) (find-package :gobject.boxed.generated-names)))))
342
343 (defun generated-cunion-name (symbol)
344   (or (get symbol 'generated-cunion-name)
345       (setf (get symbol 'generated-cunion-name) (gentemp (format nil "CUNION-~A" (symbol-name symbol)) (find-package :gobject.boxed.generated-names)))))
346
347 (defun generate-cstruct-1 (struct)
348   `(defcstruct ,(generated-cstruct-name (cstruct-description-name struct))
349      ,@(iter (for slot in (cstruct-description-slots struct))
350              (collect `(,(cstruct-slot-description-name slot) ,(cstruct-slot-description-type slot)
351                          ,@(when (cstruct-slot-description-count slot)
352                                  `(:count ,(cstruct-slot-description-count slot))))))))
353
354 (defun generate-c-structures (structure)
355   (iter (for str in (all-structures structure))
356         (for cstruct = (var-structure-resulting-cstruct-description str))
357         (collect (generate-cstruct-1 cstruct))))
358
359 (defun generate-variant-union (struct)
360   `(defcunion ,(generated-cunion-name (var-structure-name struct))
361      ,@(iter (for str in (all-structures struct))
362              (collect `(,(var-structure-name str)
363                          ,(generated-cstruct-name (var-structure-name str)))))))
364
365 (defun generate-structure-1 (str)
366   `(defstruct ,(if (var-structure-parent str)
367                    `(,(var-structure-name str) (:include ,(var-structure-name (var-structure-parent str))
368                                                          (,(var-structure-discriminator-slot (var-structure-parent str))
369                                                            ,(first (var-structure-variant-discriminating-values
370                                                                     (find str
371                                                                           (var-structure-variants
372                                                                            (var-structure-parent str))
373                                                                           :key #'var-structure-variant-structure))))))
374                    `,(var-structure-name str))
375      ,@(iter (for slot in (var-structure-slots str))
376              (collect `(,(cstruct-slot-description-name slot)
377                          ,(cstruct-slot-description-initform slot))))))
378
379 (defun generate-structures (str)
380   (iter (for variant in (reverse (all-structures str)))
381         (collect (generate-structure-1 variant))))
382
383 (defun generate-native-type-decision-procedure-1 (str proxy-var)
384   (if (null (var-structure-discriminator-slot str))
385       `(values ',(var-structure-resulting-cstruct-description str))
386       `(typecase ,proxy-var
387          ,@(iter (for variant in (var-structure-variants str))
388                  (for v-str = (var-structure-variant-structure variant))
389                  (collect `(,(var-structure-name v-str)
390                              ,(generate-native-type-decision-procedure-1 v-str proxy-var))))
391          (,(var-structure-name str)
392           (values ',(var-structure-resulting-cstruct-description str))))))
393
394 (defun generate-proxy-type-decision-procedure-1 (str native-var)
395   (if (null (var-structure-discriminator-slot str))
396       `(values ',(var-structure-name str)
397                ',(var-structure-resulting-cstruct-description str))
398       `(case (foreign-slot-value ,native-var
399                                  ',(generated-cstruct-name (var-structure-name str))
400                                  ',(var-structure-discriminator-slot str))
401          ,@(iter (for variant in (var-structure-variants str))
402                  (for v-str = (var-structure-variant-structure variant))
403                  (collect `(,(var-structure-variant-discriminating-values variant)
404                              ,(generate-proxy-type-decision-procedure-1
405                                v-str
406                                native-var))))
407          (t (values ',(var-structure-name str)
408                     ',(var-structure-resulting-cstruct-description str))))))
409
410 (defun generate-proxy-type-decision-procedure (str)
411   (let ((native (gensym "NATIVE-")))
412     `(lambda (,native)
413        (declare (ignorable ,native))
414        ,(generate-proxy-type-decision-procedure-1 str native))))
415
416 (defun generate-native-type-decision-procedure (str)
417   (let ((proxy (gensym "PROXY-")))
418     `(lambda (,proxy)
419        (declare (ignorable ,proxy))
420        ,(generate-native-type-decision-procedure-1 str proxy))))
421
422 (defun compile-proxy-type-decision-procedure (str)
423   (compile nil (generate-proxy-type-decision-procedure str)))
424
425 (defun compile-native-type-decision-procedure (str)
426   (compile nil (generate-native-type-decision-procedure str)))
427
428 (defstruct (g-boxed-variant-cstruct-info (:include g-boxed-info))
429   root
430   native-type-decision-procedure
431   proxy-type-decision-procedure)
432
433 (defmethod make-load-form ((object g-boxed-variant-cstruct-info) &optional env)
434   (make-load-form-saving-slots object :environment env))
435
436 (define-foreign-type boxed-variant-cstruct-foreign-type (g-boxed-foreign-type) ())
437
438 (defmethod make-foreign-type ((info g-boxed-variant-cstruct-info) &key return-p)
439   (make-instance 'boxed-variant-cstruct-foreign-type :info info :return-p return-p))
440
441 (defmacro define-g-boxed-variant-cstruct (name g-type-name &body slots)
442   (let* ((structure (parse-variant-structure-definition name slots)))
443     `(progn ,@(generate-c-structures structure)
444             ,(generate-variant-union structure)
445             ,@(generate-structures structure)
446             (eval-when (:compile-toplevel :load-toplevel :execute)
447               (setf (get ',name 'g-boxed-foreign-info)
448                     (make-g-boxed-variant-cstruct-info :name ',name
449                                                        :g-type ,g-type-name
450                                                        :root ,structure
451                                                        :native-type-decision-procedure
452                                                        ,(generate-native-type-decision-procedure structure)
453                                                        :proxy-type-decision-procedure
454                                                        ,(generate-proxy-type-decision-procedure structure))
455                     (gethash ,g-type-name *g-type-name->g-boxed-foreign-info*)
456                     (get ',name 'g-boxed-foreign-info))))))
457
458 (defun decide-native-type (info proxy)
459   (funcall (g-boxed-variant-cstruct-info-native-type-decision-procedure info) proxy))
460
461 (defmethod boxed-copy-fn ((info g-boxed-variant-cstruct-info) native)
462   (if (g-boxed-info-g-type info)
463       (g-boxed-copy (g-boxed-info-g-type info) native)
464       (let ((copy (foreign-alloc (generated-cunion-name (g-boxed-info-name info)))))
465         (memcpy copy native (foreign-type-size (generated-cunion-name (g-boxed-info-name info))))
466         copy)))
467
468 (defmethod boxed-free-fn ((info g-boxed-variant-cstruct-info) native)
469   (if (g-boxed-info-g-type info)
470       (g-boxed-free (g-boxed-info-g-type info) native)
471       (foreign-free native)))
472
473 (defmethod translate-to-foreign (proxy (foreign-type boxed-variant-cstruct-foreign-type))
474   (if (null proxy)
475       (null-pointer)
476       (let* ((type (g-boxed-foreign-info foreign-type))
477              (cstruct-description (decide-native-type type proxy)))
478         (with-foreign-object (native-structure (generated-cunion-name
479                                                 (var-structure-name
480                                                  (g-boxed-variant-cstruct-info-root type))))
481           (copy-slots-to-native proxy native-structure cstruct-description)
482           (values (boxed-copy-fn type native-structure) proxy)))))
483
484 (defun decide-proxy-type (info native-structure)
485   (funcall (g-boxed-variant-cstruct-info-proxy-type-decision-procedure info) native-structure))
486
487 (defmethod free-translated-object (native (foreign-type boxed-variant-cstruct-foreign-type) proxy)
488   (when proxy
489     (let ((type (g-boxed-foreign-info foreign-type)))
490       (multiple-value-bind (actual-struct cstruct-description) (decide-proxy-type type native)
491         (unless (eq (type-of proxy) actual-struct)
492           (restart-case
493               (error "Expected type of boxed variant structure ~A and actual type ~A do not match"
494                      (type-of proxy) actual-struct)
495             (skip-parsing-values () (return-from free-translated-object))))
496         (copy-slots-to-proxy proxy native cstruct-description)
497         (boxed-free-fn type native)))))
498
499 (defmethod translate-from-foreign (native (foreign-type boxed-variant-cstruct-foreign-type))
500   (unless (null-pointer-p native)
501     (let ((type (g-boxed-foreign-info foreign-type)))
502       (multiple-value-bind (actual-struct cstruct-description) (decide-proxy-type type native)
503         (let ((proxy (make-instance actual-struct)))
504           (copy-slots-to-proxy proxy native cstruct-description)
505           (when (g-boxed-foreign-return-p foreign-type)
506             (boxed-free-fn type native))
507           proxy)))))
508
509 (defmethod cleanup-translated-object-for-callback ((foreign-type boxed-variant-cstruct-foreign-type) proxy native)
510   (when proxy
511     (let ((type (g-boxed-foreign-info foreign-type)))
512       (let ((cstruct-description (decide-native-type type proxy)))
513         (copy-slots-to-native proxy native cstruct-description)))))
514
515 (defgeneric boxed-parse-g-value (gvalue-ptr info))
516
517 (defgeneric boxed-set-g-value (gvalue-ptr info proxy))
518
519 (defmethod parse-g-value-for-type (gvalue-ptr (type-numeric (eql +g-type-boxed+)) parse-kind)
520   (declare (ignore parse-kind))
521   (if (g-type= (g-value-type gvalue-ptr) (g-strv-get-type))
522       (convert-from-foreign (g-value-get-boxed gvalue-ptr) '(glib:gstrv :free-from-foreign nil))
523       (let ((boxed-type (get-g-boxed-foreign-info-for-gtype type-numeric)))
524         (boxed-parse-g-value gvalue-ptr boxed-type))))
525
526 (defmethod set-gvalue-for-type (gvalue-ptr (type-numeric (eql +g-type-boxed+)) value)
527   (if (g-type= (g-value-type gvalue-ptr) (g-strv-get-type))
528       (g-value-set-boxed gvalue-ptr (convert-to-foreign value '(glib:gstrv :free-from-foreign nil)))
529       (let ((boxed-type (get-g-boxed-foreign-info-for-gtype type-numeric)))
530         (boxed-set-g-value gvalue-ptr boxed-type value))))
531
532 (defmethod boxed-parse-g-value (gvalue-ptr (info g-boxed-cstruct-wrapper-info))
533   (translate-from-foreign (g-value-get-boxed gvalue-ptr) (make-foreign-type info :return-p nil)))
534
535 (defmethod boxed-set-g-value (gvalue-ptr (info g-boxed-cstruct-wrapper-info) proxy)
536   (g-value-take-boxed gvalue-ptr (translate-to-foreign proxy (make-foreign-type info :return-p nil))))
537
538 (defmethod boxed-parse-g-value (gvalue-ptr (info g-boxed-variant-cstruct-info))
539   (translate-from-foreign (g-value-get-boxed gvalue-ptr) (make-foreign-type info :return-p nil)))
540
541 (defmethod boxed-set-g-value (gvalue-ptr (info g-boxed-variant-cstruct-info) proxy)
542   (g-value-take-boxed gvalue-ptr (translate-to-foreign proxy (make-foreign-type info :return-p nil))))
543
544 (defmethod boxed-parse-g-value (gvalue-ptr (info g-boxed-opaque-wrapper-info))
545   (translate-from-foreign (boxed-copy-fn info (g-value-get-boxed gvalue-ptr)) (make-foreign-type info :return-p nil)))
546
547 (defmethod boxed-set-g-value (gvalue-ptr (info g-boxed-opaque-wrapper-info) proxy)
548   (g-value-set-boxed gvalue-ptr (translate-to-foreign proxy (make-foreign-type info :return-p nil))))