chiark / gitweb /
Code moved from callback.c
[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
4d83a8a6 18;; $Id: glib.lisp,v 1.13 2004-10-27 14:58:59 espen Exp $
560af5c5 19
20
21(in-package "GLIB")
c4e9d221 22
560af5c5 23(use-prefix "g")
24
4d83a8a6 25;(load-shared-library "libglib-2.0")
560af5c5 26
27;;;; Memory management
28
dba0c446 29(defbinding (allocate-memory "g_malloc0") () pointer
560af5c5 30 (size unsigned-long))
31
dba0c446 32(defbinding (reallocate-memory "g_realloc") () pointer
560af5c5 33 (address pointer)
34 (size unsigned-long))
35
3c657c71 36(defbinding (deallocate-memory "g_free") () nil
37 (address pointer))
38;(defun deallocate-memory (address)
39; (declare (ignore address)))
560af5c5 40
41(defun copy-memory (from length &optional (to (allocate-memory length)))
42 (kernel:system-area-copy from 0 to 0 (* 8 length))
43 to)
44
45
c4e9d221 46;;;; User data mechanism
47
48(internal *user-data* *user-data-count*)
49
50(declaim (fixnum *user-data-count*))
51
52(defvar *destroy-notify* (system:foreign-symbol-address "destroy_notify"))
53(defvar *user-data* (make-hash-table))
54(defvar *user-data-count* 0)
55
56(defun register-user-data (object &optional destroy-function)
57 (check-type destroy-function (or null symbol function))
58 (incf *user-data-count*)
59 (setf
60 (gethash *user-data-count* *user-data*)
61 (cons object destroy-function))
62 *user-data-count*)
63
64(defun find-user-data (id)
65 (check-type id fixnum)
66 (multiple-value-bind (user-data p) (gethash id *user-data*)
67 (values (car user-data) p)))
68
69(defun destroy-user-data (id)
70 (check-type id fixnum)
71 (let ((user-data (gethash id *user-data*)))
72 (when (cdr user-data)
73 (funcall (cdr user-data) (car user-data))))
74 (remhash id *user-data*))
75
76
560af5c5 77
0aef1da8 78;;;; Quarks
79
c4e9d221 80(internal *quark-counter* *quark-from-object* *quark-to-object*)
81
0aef1da8 82(deftype quark () 'unsigned)
83
5cae32e1 84;(defbinding %quark-get-reserved () quark)
415444ae 85
5cae32e1 86(defbinding %quark-from-string () quark
415444ae 87 (string string))
88
c4e9d221 89(defvar *quark-counter* 0)
415444ae 90
91(defun %quark-get-reserved ()
c4e9d221 92 ;; The string is just a dummy
93