3 (define-foreign-type g-boxed-foreign-type ()
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
10 (:actual-type :pointer))
12 (eval-when (:compile-toplevel :load-toplevel :execute)
13 (defstruct g-boxed-info
17 (eval-when (:compile-toplevel :load-toplevel :execute)
18 (defun get-g-boxed-foreign-info (name)
19 (get name 'g-boxed-foreign-info)))
21 (defvar *g-type-name->g-boxed-foreign-info* (make-hash-table :test 'equal))
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))))
27 (defgeneric make-foreign-type (info &key return-p))
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))))
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)))
38 (defmethod boxed-copy-fn :before (type-info native)
39 (format t "(boxed-copy-fn ~A ~A)~%" (g-boxed-info-name type-info) native))
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)))
45 (defmethod boxed-free-fn :before (type-info native)
46 (format t "(boxed-free-fn ~A ~A)~%" (g-boxed-info-name type-info) native))
48 (defmethod has-callback-cleanup ((type g-boxed-foreign-type))
51 (eval-when (:load-toplevel :compile-toplevel :execute)
52 (defstruct (g-boxed-cstruct-wrapper-info (:include g-boxed-info))
55 (defclass boxed-cstruct-foreign-type (g-boxed-foreign-type) ())
57 (defstruct cstruct-slot-description
64 (defstruct (cstruct-inline-slot-description (:include cstruct-slot-description))
67 (defmethod make-load-form ((object cstruct-slot-description) &optional environment)
68 (make-load-form-saving-slots object :environment environment))
70 (defmethod make-load-form ((object cstruct-inline-slot-description) &optional environment)
71 (make-load-form-saving-slots object :environment environment))
73 (defstruct cstruct-description
77 (defmethod make-load-form ((object cstruct-description) &optional environment)
78 (make-load-form-saving-slots object :environment environment))
80 (defun parse-cstruct-slot (slot)
81 (destructuring-bind (name type &key count initform inline) slot
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))))
89 (defun parse-cstruct-definition (name slots)
90 (make-cstruct-description :name name
91 :slots (mapcar #'parse-cstruct-slot slots)))
93 (defmacro define-g-boxed-cstruct (name g-type-name &body slots)
94 (let ((cstruct-description (parse-cstruct-definition name slots)))
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
113 :cstruct-description ,cstruct-description)
114 (gethash ,g-type-name *g-type-name->g-boxed-foreign-info*)
115 (get ',name 'g-boxed-foreign-info))))))
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))
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))))
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))))
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)))
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))
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)
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))))
154 (setf (foreign-slot-value native cstruct-type slot-name)
155 (slot-value proxy slot-name))))))
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))
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))
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))))))
177 (defmethod translate-to-foreign (proxy (type boxed-cstruct-foreign-type))
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)))))
186 (defmethod free-translated-object (native-structure (type boxed-cstruct-foreign-type) 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))))
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))
202 (defmethod cleanup-translated-object-for-callback ((type boxed-cstruct-foreign-type) proxy native-structure)
204 (let ((info (g-boxed-foreign-info type)))
205 (copy-slots-to-native proxy native-structure (g-boxed-cstruct-wrapper-info-cstruct-description info)))))
207 (eval-when (:compile-toplevel :load-toplevel :execute)
208 (defstruct (g-boxed-opaque-wrapper-info (:include g-boxed-info))
211 (define-foreign-type boxed-opaque-foreign-type (g-boxed-foreign-type) ())
213 (defclass g-boxed-opaque ()
214 ((pointer :initarg :pointer
216 :accessor g-boxed-opaque-pointer)))
218 (defmethod pointer ((object g-boxed-opaque))
219 (g-boxed-opaque-pointer object))
221 (defmethod make-foreign-type ((info g-boxed-opaque-wrapper-info) &key return-p)
222 (make-instance 'boxed-opaque-foreign-type :info info :return-p return-p))
224 (defmethod translate-to-foreign (proxy (type boxed-opaque-foreign-type))
225 (prog1 (g-boxed-opaque-pointer proxy)
226 (when (g-boxed-foreign-return-p type)
227 (tg:cancel-finalization proxy)
228 (setf (g-boxed-opaque-pointer proxy) nil))))
230 (defmethod free-translated-object (native (type boxed-opaque-foreign-type) param)
231 (declare (ignore native type param)))
233 (defun make-boxed-free-finalizer (type pointer)
234 (lambda () (boxed-free-fn type pointer)))
236 (defmethod translate-from-foreign (native (foreign-type boxed-opaque-foreign-type))
237 (let* ((type (g-boxed-foreign-info foreign-type))
238 (proxy (make-instance (g-boxed-info-name type) :pointer native)))
239 (tg:finalize proxy (make-boxed-free-finalizer type native))))
241 (defmethod cleanup-translated-object-for-callback ((type boxed-opaque-foreign-type) proxy native)
242 (tg:cancel-finalization proxy)
243 (setf (g-boxed-opaque-pointer proxy) nil))
245 (defmacro define-g-boxed-opaque (name g-type-name &key
246 (alloc (error "Alloc must be specified")))
247 (let ((native-copy (gensym "NATIVE-COPY-"))
248 (instance (gensym "INSTANCE-")))
249 `(progn (defclass ,name (g-boxed-opaque) ())
250 (defmethod initialize-instance :after ((,instance ,name) &key &allow-other-keys)
251 (unless (g-boxed-opaque-pointer ,instance)
252 (let ((,native-copy ,alloc))
253 (setf (g-boxed-opaque-pointer ,instance) ,native-copy)
254 (finalize ,instance (make-boxed-free-finalizer (get ',name 'g-boxed-foreign-info) ,native-copy)))))
255 (eval-when (:compile-toplevel :load-toplevel :execute)
256 (setf (get ',name 'g-boxed-foreign-info)
257 (make-g-boxed-opaque-wrapper-info :name ',name
258 :g-type ,g-type-name)
259 (gethash ,g-type-name *g-type-name->g-boxed-foreign-info*)
260 (get ',name 'g-boxed-foreign-info))))))
262 (defstruct var-structure
268 resulting-cstruct-description)
270 (defstruct var-structure-variant
271 discriminating-values
274 (defmethod make-load-form ((object var-structure) &optional env)
275 (make-load-form-saving-slots object :environment env))
277 (defmethod make-load-form ((object var-structure-variant) &optional env)
278 (make-load-form-saving-slots object :environment env))
280 (defun var-struct-all-slots (struct)
282 (append (var-struct-all-slots (var-structure-parent struct))
283 (var-structure-slots struct))))
285 (defun all-structures (structure)
286 (append (iter (for variant in (var-structure-variants structure))
287 (appending (all-structures (var-structure-variant-structure variant))))
290 (defun parse-variant-structure-definition (name slots &optional parent)
291 (iter (with result = (make-var-structure :name name
294 :discriminator-slot nil
297 (if (eq :variant (first slot))
299 (when (var-structure-discriminator-slot result)
300 (error "Structure has more than one discriminator slot"))
301 (setf (var-structure-discriminator-slot result) (second slot)
302 (var-structure-variants result) (parse-variants result (nthcdr 2 slot))))
303 (push (parse-cstruct-slot slot) (var-structure-slots result)))
304 (finally (setf (var-structure-slots result)
305 (reverse (var-structure-slots result)))
307 (set-variant-result-structure result))
310 (defun set-variant-result-structure (var-structure)
311 (setf (var-structure-resulting-cstruct-description var-structure)
312 (make-cstruct-description
314 (var-structure-name var-structure)
317 (when (var-structure-parent var-structure)
318 (cstruct-description-slots (var-structure-resulting-cstruct-description (var-structure-parent var-structure))))
319 (var-structure-slots var-structure))))
320 (iter (for variant in (var-structure-variants var-structure))
321 (for child-var-structure = (var-structure-variant-structure variant))
322 (set-variant-result-structure child-var-structure)))
324 (defun ensure-list (thing)
329 (defun parse-variants (parent variants)
330 (iter (for var-descr in variants)
331 (for (options variant-name . slots) in variants)
333 (make-var-structure-variant
334 :discriminating-values (ensure-list options)
335 :structure (parse-variant-structure-definition variant-name slots parent)))
338 (defpackage :gobject.boxed.generated-names)
340 (defun generated-cstruct-name (symbol)
341 (or (get symbol 'generated-cstruct-name)
342 (setf (get symbol 'generated-cstruct-name) (gentemp (format nil "CSTRUCT-~A" (symbol-name symbol)) (find-package :gobject.boxed.generated-names)))))
344 (defun generated-cunion-name (symbol)
345 (or (get symbol 'generated-cunion-name)
346 (setf (get symbol 'generated-cunion-name) (gentemp (format nil "CUNION-~A" (symbol-name symbol)) (find-package :gobject.boxed.generated-names)))))
348 (defun generated-fn-name (symbol)
349 (or (get symbol 'generated-fn-name)
350 (setf (get symbol 'generated-fn-name) (gentemp (format nil "FN~A" (symbol-name symbol)) (find-package :gobject.boxed.generated-names)))))
352 (defun generate-cstruct-1 (struct)
353 `(defcstruct ,(generated-cstruct-name (cstruct-description-name struct))
354 ,@(iter (for slot in (cstruct-description-slots struct))
355 (collect `(,(cstruct-slot-description-name slot) ,(cstruct-slot-description-type slot)
356 ,@(when (cstruct-slot-description-count slot)
357 `(:count ,(cstruct-slot-description-count slot))))))))
359 (defun generate-c-structures (structure)
360 (iter (for str in (all-structures structure))
361 (for cstruct = (var-structure-resulting-cstruct-description str))
362 (collect (generate-cstruct-1 cstruct))))
364 (defun generate-variant-union (struct)
365 `(defcunion ,(generated-cunion-name (var-structure-name struct))
366 ,@(iter (for str in (all-structures struct))
367 (collect `(,(var-structure-name str)
368 ,(generated-cstruct-name (var-structure-name str)))))))
370 (defun generate-structure-1 (str)
371 `(defstruct ,(if (var-structure-parent str)
372 `(,(var-structure-name str) (:include ,(var-structure-name (var-structure-parent str))
373 (,(var-structure-discriminator-slot (var-structure-parent str))
374 ,(first (var-structure-variant-discriminating-values
376 (var-structure-variants
377 (var-structure-parent str))
378 :key #'var-structure-variant-structure))))))
379 `,(var-structure-name str))
380 ,@(iter (for slot in (var-structure-slots str))
381 (collect `(,(cstruct-slot-description-name slot)
382 ,(cstruct-slot-description-initform slot))))))
384 (defun generate-structures (str)
385 (iter (for variant in (reverse (all-structures str)))
386 (collect (generate-structure-1 variant))))
388 (defun generate-native-type-decision-procedure-1 (str proxy-var)
389 (if (null (var-structure-discriminator-slot str))
390 `(values ',(var-structure-resulting-cstruct-description str))
391 `(typecase ,proxy-var
392 ,@(iter (for variant in (var-structure-variants str))
393 (for v-str = (var-structure-variant-structure variant))
394 (collect `(,(var-structure-name v-str)
395 ,(generate-native-type-decision-procedure-1 v-str proxy-var))))
396 (,(var-structure-name str)
397 (values ',(var-structure-resulting-cstruct-description str))))))
399 (defun generate-proxy-type-decision-procedure-1 (str native-var)
400 (if (null (var-structure-discriminator-slot str))
401 `(values ',(var-structure-name str)
402 ',(var-structure-resulting-cstruct-description str))
403 `(case (foreign-slot-value ,native-var
404 ',(generated-cstruct-name (var-structure-name str))
405 ',(var-structure-discriminator-slot str))
406 ,@(iter (for variant in (var-structure-variants str))
407 (for v-str = (var-structure-variant-structure variant))
408 (collect `(,(var-structure-variant-discriminating-values variant)
409 ,(generate-proxy-type-decision-procedure-1
412 (t (values ',(var-structure-name str)
413 ',(var-structure-resulting-cstruct-description str))))))
415 (defun generate-proxy-type-decision-procedure (str)
416 (let ((native (gensym "NATIVE-")))
418 (declare (ignorable ,native))
419 ,(generate-proxy-type-decision-procedure-1 str native))))
421 (defun generate-native-type-decision-procedure (str)
422 (let ((proxy (gensym "PROXY-")))
424 (declare (ignorable ,proxy))
425 ,(generate-native-type-decision-procedure-1 str proxy))))
427 (defun compile-proxy-type-decision-procedure (str)
428 (compile nil (generate-proxy-type-decision-procedure str)))
430 (defun compile-native-type-decision-procedure (str)
431 (compile nil (generate-native-type-decision-procedure str)))
433 (defstruct (g-boxed-variant-cstruct-info (:include g-boxed-info))
435 native-type-decision-procedure
436 proxy-type-decision-procedure)
438 (defmethod make-load-form ((object g-boxed-variant-cstruct-info) &optional env)
439 (make-load-form-saving-slots object :environment env))
441 (define-foreign-type boxed-variant-cstruct-foreign-type (g-boxed-foreign-type) ())
443 (defmethod make-foreign-type ((info g-boxed-variant-cstruct-info) &key return-p)
444 (make-instance 'boxed-variant-cstruct-foreign-type :info info :return-p return-p))
446 (defmacro define-g-boxed-variant-cstruct (name g-type-name &body slots)
447 (let* ((structure (parse-variant-structure-definition name slots)))
448 `(progn ,@(generate-c-structures structure)
449 ,(generate-variant-union structure)
450 ,@(generate-structures structure)
451 (eval-when (:compile-toplevel :load-toplevel :execute)
452 (setf (get ',name 'g-boxed-foreign-info)
453 (make-g-boxed-variant-cstruct-info :name ',name
456 :native-type-decision-procedure
457 ,(generate-native-type-decision-procedure structure)
458 :proxy-type-decision-procedure
459 ,(generate-proxy-type-decision-procedure structure))
460 (gethash ,g-type-name *g-type-name->g-boxed-foreign-info*)
461 (get ',name 'g-boxed-foreign-info))))))
463 (defun decide-native-type (info proxy)
464 (funcall (g-boxed-variant-cstruct-info-native-type-decision-procedure info) proxy))
466 (defmethod boxed-copy-fn ((info g-boxed-variant-cstruct-info) native)
467 (if (g-boxed-info-g-type info)
468 (g-boxed-copy (g-boxed-info-g-type info) native)
469 (let ((copy (foreign-alloc (generated-cunion-name (g-boxed-info-name info)))))
470 (memcpy copy native (foreign-type-size (generated-cunion-name (g-boxed-info-name info))))
473 (defmethod boxed-free-fn ((info g-boxed-variant-cstruct-info) native)
474 (if (g-boxed-info-g-type info)
475 (g-boxed-free (g-boxed-info-g-type info) native)
476 (foreign-free native)))
478 (defmethod translate-to-foreign (proxy (foreign-type boxed-variant-cstruct-foreign-type))
481 (let* ((type (g-boxed-foreign-info foreign-type))
482 (cstruct-description (decide-native-type type proxy)))
483 (with-foreign-object (native-structure (generated-cunion-name
485 (g-boxed-variant-cstruct-info-root type))))
486 (copy-slots-to-native proxy native-structure cstruct-description)
487 (values (boxed-copy-fn type native-structure) proxy)))))
489 (defun decide-proxy-type (info native-structure)
490 (funcall (g-boxed-variant-cstruct-info-proxy-type-decision-procedure info) native-structure))
492 (defmethod free-translated-object (native (foreign-type boxed-variant-cstruct-foreign-type) proxy)
494 (let ((type (g-boxed-foreign-info foreign-type)))
495 (multiple-value-bind (actual-struct cstruct-description) (decide-proxy-type type native)
496 (unless (eq (type-of proxy) actual-struct)
498 (error "Expected type of boxed variant structure ~A and actual type ~A do not match"
499 (type-of proxy) actual-struct)
500 (skip-parsing-values () (return-from free-translated-object))))
501 (copy-slots-to-proxy proxy native cstruct-description)
502 (boxed-free-fn type native)))))
504 (defmethod translate-from-foreign (native (foreign-type boxed-variant-cstruct-foreign-type))
505 (unless (null-pointer-p native)
506 (let ((type (g-boxed-foreign-info foreign-type)))
507 (multiple-value-bind (actual-struct cstruct-description) (decide-proxy-type type native)
508 (let ((proxy (make-instance actual-struct)))
509 (copy-slots-to-proxy proxy native cstruct-description)
510 (when (g-boxed-foreign-return-p foreign-type)
511 (boxed-free-fn type native))
514 (defmethod cleanup-translated-object-for-callback ((foreign-type boxed-variant-cstruct-foreign-type) proxy native)
516 (let ((type (g-boxed-foreign-info foreign-type)))
517 (let ((cstruct-description (decide-native-type type proxy)))
518 (copy-slots-to-native proxy native cstruct-description)))))
520 (defgeneric boxed-parse-g-value (gvalue-ptr info))
522 (defgeneric boxed-set-g-value (gvalue-ptr info proxy))
524 (defmethod parse-g-value-for-type (gvalue-ptr (type-numeric (eql +g-type-boxed+)) parse-kind)
525 (declare (ignore parse-kind))
526 (if (g-type= (g-value-type gvalue-ptr) (g-strv-get-type))
527 (convert-from-foreign (g-value-get-boxed gvalue-ptr) '(glib:gstrv :free-from-foreign nil))
528 (let ((boxed-type (get-g-boxed-foreign-info-for-gtype (g-value-type gvalue-ptr))))
529 (boxed-parse-g-value gvalue-ptr boxed-type))))
531 (defmethod set-gvalue-for-type (gvalue-ptr (type-numeric (eql +g-type-boxed+)) value)
532 (if (g-type= (g-value-type gvalue-ptr) (g-strv-get-type))
533 (g-value-set-boxed gvalue-ptr (convert-to-foreign value '(glib:gstrv :free-from-foreign nil)))
534 (let ((boxed-type (get-g-boxed-foreign-info-for-gtype (g-value-type gvalue-ptr))))
535 (boxed-set-g-value gvalue-ptr boxed-type value))))
537 (defmethod boxed-parse-g-value (gvalue-ptr (info g-boxed-cstruct-wrapper-info))
538 (translate-from-foreign (g-value-get-boxed gvalue-ptr) (make-foreign-type info :return-p nil)))
540 (defmethod boxed-set-g-value (gvalue-ptr (info g-boxed-cstruct-wrapper-info) proxy)
541 (g-value-take-boxed gvalue-ptr (translate-to-foreign proxy (make-foreign-type info :return-p nil))))
543 (defmethod boxed-parse-g-value (gvalue-ptr (info g-boxed-variant-cstruct-info))
544 (translate-from-foreign (g-value-get-boxed gvalue-ptr) (make-foreign-type info :return-p nil)))
546 (defmethod boxed-set-g-value (gvalue-ptr (info g-boxed-variant-cstruct-info) proxy)
547 (g-value-take-boxed gvalue-ptr (translate-to-foreign proxy (make-foreign-type info :return-p nil))))
549 (defmethod boxed-parse-g-value (gvalue-ptr (info g-boxed-opaque-wrapper-info))
550 (translate-from-foreign (boxed-copy-fn info (g-value-get-boxed gvalue-ptr)) (make-foreign-type info :return-p nil)))
552 (defmethod boxed-set-g-value (gvalue-ptr (info g-boxed-opaque-wrapper-info) proxy)
553 (g-value-set-boxed gvalue-ptr (translate-to-foreign proxy (make-foreign-type info :return-p nil))))
555 (defun boxed-related-symbols (name)
556 (let ((info (get-g-boxed-foreign-info name)))
558 (g-boxed-cstruct-wrapper-info
560 (intern (format nil "MAKE-~A" (symbol-name name)))
561 (intern (format nil "COPY-~A" (symbol-name name))))
562 (iter (for slot in (cstruct-description-slots (g-boxed-cstruct-wrapper-info-cstruct-description info)))
563 (for slot-name = (cstruct-slot-description-name slot))
564 (collect (intern (format nil "~A-~A" (symbol-name name) (symbol-name slot-name)))))))
565 (g-boxed-opaque-wrapper-info
567 (g-boxed-variant-cstruct-info
569 (iter (for var-struct in (all-structures (g-boxed-variant-cstruct-info-root info)))
570 (for s-name = (var-structure-name var-struct))
571 (for cstruct-description = (var-structure-resulting-cstruct-description var-struct))
572 (appending (append (list (intern (format nil "MAKE-~A" (symbol-name s-name)))
573 (intern (format nil "COPY-~A" (symbol-name s-name))))
574 (iter (for slot in (cstruct-description-slots cstruct-description))
575 (for slot-name = (cstruct-slot-description-name slot))
576 (collect (intern (format nil "~A-~A" (symbol-name s-name)
577 (symbol-name slot-name)))))))))))))
579 (defmacro define-boxed-opaque-accessor (boxed-name accessor-name &key type reader writer)
582 `(progn ,@(when reader
583 (list (etypecase reader
584 (symbol `(defun ,accessor-name (,var)
585 (funcall ,reader ,var)))
586 (string `(defcfun (,accessor-name ,reader) ,type
587 (,var (g-boxed-foreign ,boxed-name)))))))
589 (list (etypecase reader
590 (symbol `(defun (setf ,accessor-name) (,n-var ,var)
591 (funcall ,reader ,n-var ,var)))
592 (string `(defun (setf ,accessor-name) (,n-var ,var)
593 (foreign-funcall ,writer (g-boxed-foreign ,boxed-name) ,var ,type ,n-var :void)))))))))