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