Commit | Line | Data |
---|---|---|
f5e85438 | 1 | /* Copyright (C) 1995,1996, 2000, 2001, 2003, 2006, 2008, 2009, 2010 Free Software Foundation, Inc. |
0f2d19dd | 2 | * |
73be1d9e | 3 | * This library is free software; you can redistribute it and/or |
53befeb7 NJ |
4 | * modify it under the terms of the GNU Lesser General Public License |
5 | * as published by the Free Software Foundation; either version 3 of | |
6 | * the License, or (at your option) any later version. | |
0f2d19dd | 7 | * |
53befeb7 NJ |
8 | * This library is distributed in the hope that it will be useful, but |
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
73be1d9e MV |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | * Lesser General Public License for more details. | |
0f2d19dd | 12 | * |
73be1d9e MV |
13 | * You should have received a copy of the GNU Lesser General Public |
14 | * License along with this library; if not, write to the Free Software | |
53befeb7 NJ |
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
16 | * 02110-1301 USA | |
73be1d9e | 17 | */ |
1bbd0b84 | 18 | |
1bbd0b84 | 19 | |
0f2d19dd | 20 | \f |
dbb605f5 LC |
21 | #ifdef HAVE_CONFIG_H |
22 | # include <config.h> | |
23 | #endif | |
0f2d19dd | 24 | |
a0599745 | 25 | #include "libguile/_scm.h" |
4e047c3e | 26 | #include "libguile/async.h" |
a0599745 MD |
27 | #include "libguile/hashtab.h" |
28 | #include "libguile/alist.h" | |
29 | #include "libguile/root.h" | |
30 | #include "libguile/weaks.h" | |
0f2d19dd | 31 | |
a0599745 | 32 | #include "libguile/objprop.h" |
0f2d19dd JB |
33 | \f |
34 | ||
35 | /* {Object Properties} | |
36 | */ | |
37 | ||
e7efe8e7 | 38 | static SCM object_whash; |
f5e85438 | 39 | static scm_i_pthread_mutex_t whash_mutex = SCM_I_PTHREAD_MUTEX_INITIALIZER; |
e7efe8e7 | 40 | |
3b3b36dd | 41 | SCM_DEFINE (scm_object_properties, "object-properties", 1, 0, 0, |
1bbd0b84 | 42 | (SCM obj), |
b380b885 | 43 | "Return @var{obj}'s property list.") |
1bbd0b84 | 44 | #define FUNC_NAME s_scm_object_properties |
0f2d19dd | 45 | { |
f5e85438 AW |
46 | SCM ret; |
47 | ||
48 | scm_i_pthread_mutex_lock (&whash_mutex); | |
49 | ret = scm_hashq_ref (object_whash, obj, SCM_EOL); | |
50 | scm_i_pthread_mutex_unlock (&whash_mutex); | |
51 | ||
52 | return ret; | |
0f2d19dd | 53 | } |
1bbd0b84 | 54 | #undef FUNC_NAME |
0f2d19dd JB |
55 | |
56 | ||
3b3b36dd | 57 | SCM_DEFINE (scm_set_object_properties_x, "set-object-properties!", 2, 0, 0, |
1e6808ea | 58 | (SCM obj, SCM alist), |
b380b885 | 59 | "Set @var{obj}'s property list to @var{alist}.") |
1bbd0b84 | 60 | #define FUNC_NAME s_scm_set_object_properties_x |
0f2d19dd | 61 | { |
f5e85438 AW |
62 | SCM handle; |
63 | ||
64 | scm_i_pthread_mutex_lock (&whash_mutex); | |
65 | handle = scm_hashq_create_handle_x (object_whash, obj, alist); | |
1e6808ea | 66 | SCM_SETCDR (handle, alist); |
f5e85438 AW |
67 | scm_i_pthread_mutex_unlock (&whash_mutex); |
68 | ||
1e6808ea | 69 | return alist; |
0f2d19dd | 70 | } |
1bbd0b84 | 71 | #undef FUNC_NAME |
0f2d19dd | 72 | |
3b3b36dd | 73 | SCM_DEFINE (scm_object_property, "object-property", 2, 0, 0, |
1bbd0b84 | 74 | (SCM obj, SCM key), |
b380b885 | 75 | "Return the property of @var{obj} with name @var{key}.") |
1bbd0b84 | 76 | #define FUNC_NAME s_scm_object_property |
0f2d19dd JB |
77 | { |
78 | SCM assoc; | |
332ab360 | 79 | assoc = scm_assq (key, scm_object_properties (obj)); |
0f2d19dd JB |
80 | return (SCM_NIMP (assoc) ? SCM_CDR (assoc) : SCM_BOOL_F); |
81 | } | |
1bbd0b84 | 82 | #undef FUNC_NAME |
0f2d19dd | 83 | |
3b3b36dd | 84 | SCM_DEFINE (scm_set_object_property_x, "set-object-property!", 3, 0, 0, |
1e6808ea | 85 | (SCM obj, SCM key, SCM value), |
1e6808ea MG |
86 | "In @var{obj}'s property list, set the property named @var{key}\n" |
87 | "to @var{value}.") | |
1bbd0b84 | 88 | #define FUNC_NAME s_scm_set_object_property_x |
0f2d19dd JB |
89 | { |
90 | SCM h; | |
91 | SCM assoc; | |
f5e85438 AW |
92 | |
93 | scm_i_pthread_mutex_lock (&whash_mutex); | |
e7efe8e7 | 94 | h = scm_hashq_create_handle_x (object_whash, obj, SCM_EOL); |
e869585c | 95 | assoc = scm_assq (key, SCM_CDR (h)); |
0f2d19dd | 96 | if (SCM_NIMP (assoc)) |
1e6808ea | 97 | SCM_SETCDR (assoc, value); |
0f2d19dd JB |
98 | else |
99 | { | |
1e6808ea | 100 | assoc = scm_acons (key, value, SCM_CDR (h)); |
0f2d19dd JB |
101 | SCM_SETCDR (h, assoc); |
102 | } | |
f5e85438 AW |
103 | scm_i_pthread_mutex_unlock (&whash_mutex); |
104 | ||
1e6808ea | 105 | return value; |
0f2d19dd | 106 | } |
1bbd0b84 | 107 | #undef FUNC_NAME |
0f2d19dd | 108 | |
1cc91f1b | 109 | |
0f2d19dd JB |
110 | void |
111 | scm_init_objprop () | |
0f2d19dd | 112 | { |
e7efe8e7 | 113 | object_whash = scm_make_weak_key_hash_table (SCM_UNDEFINED); |
a0599745 | 114 | #include "libguile/objprop.x" |
0f2d19dd JB |
115 | } |
116 | ||
89e00824 ML |
117 | |
118 | /* | |
119 | Local Variables: | |
120 | c-file-style: "gnu" | |
121 | End: | |
122 | */ |