1 /* Copyright (C) 1995,1996, 2000, 2001, 2003, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
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.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
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
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "libguile/_scm.h"
26 #include "libguile/async.h"
27 #include "libguile/hashtab.h"
28 #include "libguile/alist.h"
29 #include "libguile/root.h"
30 #include "libguile/weaks.h"
32 #include "libguile/objprop.h"
35 /* {Object Properties}
38 static SCM object_whash
;
39 static scm_i_pthread_mutex_t whash_mutex
= SCM_I_PTHREAD_MUTEX_INITIALIZER
;
41 SCM_DEFINE (scm_object_properties
, "object-properties", 1, 0, 0,
43 "Return @var{obj}'s property list.")
44 #define FUNC_NAME s_scm_object_properties
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
);
57 SCM_DEFINE (scm_set_object_properties_x
, "set-object-properties!", 2, 0, 0,
59 "Set @var{obj}'s property list to @var{alist}.")
60 #define FUNC_NAME s_scm_set_object_properties_x
62 scm_i_pthread_mutex_lock (&whash_mutex
);
63 scm_hashq_set_x (object_whash
, obj
, alist
);
64 scm_i_pthread_mutex_unlock (&whash_mutex
);
70 SCM_DEFINE (scm_object_property
, "object-property", 2, 0, 0,
72 "Return the property of @var{obj} with name @var{key}.")
73 #define FUNC_NAME s_scm_object_property
76 assoc
= scm_assq (key
, scm_object_properties (obj
));
77 return (SCM_NIMP (assoc
) ? SCM_CDR (assoc
) : SCM_BOOL_F
);
81 SCM_DEFINE (scm_set_object_property_x
, "set-object-property!", 3, 0, 0,
82 (SCM obj
, SCM key
, SCM value
),
83 "In @var{obj}'s property list, set the property named @var{key}\n"
85 #define FUNC_NAME s_scm_set_object_property_x
90 scm_i_pthread_mutex_lock (&whash_mutex
);
91 alist
= scm_hashq_ref (object_whash
, obj
, SCM_EOL
);
92 assoc
= scm_assq (key
, alist
);
94 SCM_SETCDR (assoc
, value
);
96 scm_hashq_set_x (object_whash
, obj
, scm_acons (key
, value
, alist
));
97 scm_i_pthread_mutex_unlock (&whash_mutex
);
107 object_whash
= scm_make_weak_key_hash_table (SCM_UNDEFINED
);
108 #include "libguile/objprop.x"