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