0d07716f |
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 | |
935a783c |
18 | ;; $Id: glib.lisp,v 1.13 2004/10/27 14:58:59 espen Exp $ |
0d07716f |
19 | |
20 | |
21 | (in-package "GLIB") |
b467f3d0 |
22 | |
0d07716f |
23 | (use-prefix "g") |
24 | |
935a783c |
25 | ;(load-shared-library "libglib-2.0") |
0d07716f |
26 | |
27 | ;;;; Memory management |
28 | |
1c99696e |
29 | (defbinding (allocate-memory "g_malloc0") () pointer |
0d07716f |
30 | (size unsigned-long)) |
31 | |
1c99696e |
32 | (defbinding (reallocate-memory "g_realloc") () pointer |
0d07716f |
33 | (address pointer) |
34 | (size unsigned-long)) |
35 | |
3fa4f6bd |
36 | (defbinding (deallocate-memory "g_free") () nil |
37 | (address pointer)) |
38 | ;(defun deallocate-memory (address) |
39 | ; (declare (ignore address))) |
0d07716f |
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 | |
b467f3d0 |
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 | |
0d07716f |
77 | |
6755fdad |
78 | ;;;; Quarks |
79 | |
b467f3d0 |
80 | (internal *quark-counter* *quark-from-object* *quark-to-object*) |
81 | |
6755fdad |
82 | (deftype quark () 'unsigned) |
83 | |
cb816364 |
84 | ;(defbinding %quark-get-reserved () quark) |
e5b6173a |
85 | |
cb816364 |
86 | (defbinding %quark-from-string () quark |
e5b6173a |
87 | (string string)) |
88 | |
b467f3d0 |
89 | (defvar *quark-counter* 0) |
e5b6173a |
90 | |
91 | (defun %quark-get-reserved () |
b467f3d0 |
92 | ;; The string is just a dummy |
93 |