chiark / gitweb /
Cleanups
[clg] / glib / glib.lisp
CommitLineData
560af5c5 1;; Common Lisp bindings for GTK+ v1.2.x
2;; Copyright (C) 1999 Espen S. Johnsen <espejohn@online.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
5cae32e1 18;; $Id: glib.lisp,v 1.9 2001-04-29 20:07:17 espen Exp $
560af5c5 19
20
21(in-package "GLIB")
c4e9d221 22
560af5c5 23(use-prefix "g")
24
25
26;;;; Memory management
27
5cae32e1 28(defbinding ("g_malloc0" allocate-memory) () pointer
560af5c5 29 (size unsigned-long))
30
5cae32e1 31(defbinding ("g_realloc" reallocate-memory) () pointer
560af5c5 32 (address pointer)
33 (size unsigned-long))
34
5cae32e1 35(defbinding ("g_free" deallocate-memory) () nil
560af5c5 36 (address pointer))
37
38(defun copy-memory (from length &optional (to (allocate-memory length)))
39 (kernel:system-area-copy from 0 to 0 (* 8 length))
40 to)
41
42
c4e9d221 43;;;; User data mechanism
44
45(internal *user-data* *user-data-count*)
46
47(declaim (fixnum *user-data-count*))
48
49(defvar *destroy-notify* (system:foreign-symbol-address "destroy_notify"))
50(defvar *user-data* (make-hash-table))
51(defvar *user-data-count* 0)
52
53(defun register-user-data (object &optional destroy-function)
54 (check-type destroy-function (or null symbol function))
55 (incf *user-data-count*)
56 (setf
57 (gethash *user-data-count* *user-data*)
58 (cons object destroy-function))
59 *user-data-count*)
60
61(defun find-user-data (id)
62 (check-type id fixnum)
63 (multiple-value-bind (user-data p) (gethash id *user-data*)
64 (values (car user-data) p)))
65
66(defun destroy-user-data (id)
67 (check-type id fixnum)
68 (let ((user-data (gethash id *user-data*)))
69 (when (cdr user-data)
70 (funcall (cdr user-data) (car user-data))))
71 (remhash id *user-data*))
72
73
560af5c5 74
0aef1da8 75;;;; Quarks
76
c4e9d221 77(internal *quark-counter* *quark-from-object* *quark-to-object*)
78
0aef1da8 79(deftype quark () 'unsigned)
80
5cae32e1 81;(defbinding %quark-get-reserved () quark)
415444ae 82
5cae32e1 83(defbinding %quark-from-string () quark
415444ae 84 (string string))
85
c4e9d221 86(defvar *quark-counter* 0)
415444ae 87
88(defun %quark-get-reserved ()
c4e9d221 89 ;; The string is just a dummy
90