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"
31 #include "libguile/objprop.h"
34 /* {Object Properties}
37 static SCM object_whash
;
39 SCM_DEFINE (scm_object_properties
, "object-properties", 1, 0, 0,
41 "Return @var{obj}'s property list.")
42 #define FUNC_NAME s_scm_object_properties
44 return scm_weak_table_refq (object_whash
, obj
, SCM_EOL
);
49 SCM_DEFINE (scm_set_object_properties_x
, "set-object-properties!", 2, 0, 0,
51 "Set @var{obj}'s property list to @var{alist}.")
52 #define FUNC_NAME s_scm_set_object_properties_x
54 scm_weak_table_putq_x (object_whash
, obj
, alist
);
60 SCM_DEFINE (scm_object_property
, "object-property", 2, 0, 0,
62 "Return the property of @var{obj} with name @var{key}.")
63 #define FUNC_NAME s_scm_object_property
66 assoc
= scm_assq (key
, scm_object_properties (obj
));
67 return (scm_is_pair (assoc
) ? SCM_CDR (assoc
) : SCM_BOOL_F
);
71 SCM_DEFINE (scm_set_object_property_x
, "set-object-property!", 3, 0, 0,
72 (SCM obj
, SCM key
, SCM value
),
73 "In @var{obj}'s property list, set the property named @var{key}\n"
75 #define FUNC_NAME s_scm_set_object_property_x
80 scm_i_pthread_mutex_lock (&scm_i_misc_mutex
);
81 alist
= scm_weak_table_refq (object_whash
, obj
, SCM_EOL
);
82 assoc
= scm_assq (key
, alist
);
83 if (scm_is_pair (assoc
))
84 SCM_SETCDR (assoc
, value
);
86 scm_weak_table_putq_x (object_whash
, obj
, scm_acons (key
, value
, alist
));
87 scm_i_pthread_mutex_unlock (&scm_i_misc_mutex
);
97 object_whash
= scm_c_make_weak_table (0, SCM_WEAK_TABLE_KIND_KEY
);
98 #include "libguile/objprop.x"