chiark / gitweb /
Updated for CMUCL 19a and glib-2.4
[clg] / glib / gboxed.lisp
CommitLineData
b44caf77 1;; Common Lisp bindings for GTK+ v2.0
2;; Copyright (C) 2001 Espen S. Johnsen <esj@stud.cs.uit.no>
3;;
4;; This library is free software; you can redistribute it and/or
5;; modify it under the terms of the GNU Lesser General Public
6;; License as published by the Free Software Foundation; either
7;; version 2 of the License, or (at your option) any later version.
8;;
9;; This library is distributed in the hope that it will be useful,
10;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12;; Lesser General Public License for more details.
13;;
14;; You should have received a copy of the GNU Lesser General Public
15;; License along with this library; if not, write to the Free Software
16;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
935a783c 18;; $Id: gboxed.lisp,v 1.10 2004/10/27 14:58:59 espen Exp $
b44caf77 19
20(in-package "GLIB")
21
22
23(eval-when (:compile-toplevel :load-toplevel :execute)
7bae2f98 24 (init-types-in-library "libgobject-2.0.so")
c1854b12 25 (defclass boxed (proxy)
b44caf77 26 ()
3a935dfa 27 (:metaclass proxy-class)
28 (:copy %boxed-copy)
29 (:free %boxed-free)))
30
31(defbinding %boxed-copy (type location) pointer
32 ((find-type-number type) type-number)
b44caf77 33 (location pointer))
34
3a935dfa 35(defbinding %boxed-free (type location) nil
36 ((find-type-number type) type-number)
b44caf77 37 (location pointer))
38
39
40;;;; Metaclass for boxed classes
41
42(eval-when (:compile-toplevel :load-toplevel :execute)
935a783c 43 (defclass boxed-class (proxy-class)
44 ())
b44caf77 45
46
f33ff27a 47 (defmethod shared-initialize ((class boxed-class) names
48 &rest initargs &key name alien-name)
49 (declare (ignore initargs names))
50 (call-next-method)
51
52 (let* ((class-name (or name (class-name class)))
53 (type-number
54 (find-type-number
55 (or (first alien-name) (default-alien-type-name class-name)))))
56 (register-type class-name type-number)))
b44caf77 57
b44caf77 58
f33ff27a 59 (defmethod validate-superclass
b44caf77 60 ((class boxed-class) (super pcl::standard-class))
f33ff27a 61 (subtypep (class-name super) 'boxed)))
b44caf77 62
63
3a935dfa 64;;;;
65
66(defun expand-boxed-type (type-number &optional slots)
67 `(defclass ,(type-from-number type-number) (boxed)
68 ,slots
69 (:metaclass boxed-class)
70 (:alien-name ,(find-type-name type-number))))
b44caf77 71
6895c081 72(register-derivable-type 'boxed "GBoxed" 'expand-boxed-type)
888d25fb 73
74;;;; Special boxed types
75
76(defclass gstring (boxed)
77 ()
78 (:metaclass boxed-class)
79 (:alien-name "GString"))
80
81(deftype-method translate-from-alien
82 gstring (type-spec location &optional weak-ref)
83 `(let ((location ,location))
84 (unless (null-pointer-p location)
85 (prog1
86 (c-call::%naturalize-c-string location)
87 ,(unless weak-ref
88 (unreference-alien type-spec location))))))
89
90(deftype-method translate-to-alien
91 gstring (type-spec string &optional weak-ref)
30279859 92 (declare (ignore weak-ref))
888d25fb 93 `(let ((string ,string))
94 ;; Always copy strings to prevent seg fault due to GC
95 (funcall
96 ',(proxy-class-copy (find-class type-spec))
97 ',type-spec
98 (make-pointer (1+ (kernel:get-lisp-obj-address string))))))
99
100(deftype-method cleanup-alien gstring (type-spec c-string &optional weak-ref)
101 (when weak-ref
102 (unreference-alien type-spec c-string)))
103