Zero-offset branches are backward branches; fix "br" backward branches
[bpt/guile.git] / libguile / objprop.c
... / ...
CommitLineData
1/* Copyright (C) 1995,1996, 2000, 2001, 2003, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
2 *
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.
7 *
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.
12 *
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
16 * 02110-1301 USA
17 */
18
19
20\f
21#ifdef HAVE_CONFIG_H
22# include <config.h>
23#endif
24
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
31#include "libguile/objprop.h"
32\f
33
34/* {Object Properties}
35 */
36
37static SCM object_whash;
38
39SCM_DEFINE (scm_object_properties, "object-properties", 1, 0, 0,
40 (SCM obj),
41 "Return @var{obj}'s property list.")
42#define FUNC_NAME s_scm_object_properties
43{
44 return scm_weak_table_refq (object_whash, obj, SCM_EOL);
45}
46#undef FUNC_NAME
47
48
49SCM_DEFINE (scm_set_object_properties_x, "set-object-properties!", 2, 0, 0,
50 (SCM obj, SCM alist),
51 "Set @var{obj}'s property list to @var{alist}.")
52#define FUNC_NAME s_scm_set_object_properties_x
53{
54 scm_weak_table_putq_x (object_whash, obj, alist);
55
56 return alist;
57}
58#undef FUNC_NAME
59
60SCM_DEFINE (scm_object_property, "object-property", 2, 0, 0,
61 (SCM obj, SCM key),
62 "Return the property of @var{obj} with name @var{key}.")
63#define FUNC_NAME s_scm_object_property
64{
65 SCM assoc;
66 assoc = scm_assq (key, scm_object_properties (obj));
67 return (scm_is_pair (assoc) ? SCM_CDR (assoc) : SCM_BOOL_F);
68}
69#undef FUNC_NAME
70
71SCM_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"
74 "to @var{value}.")
75#define FUNC_NAME s_scm_set_object_property_x
76{
77 SCM alist;
78 SCM assoc;
79
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);
85 else
86 scm_weak_table_putq_x (object_whash, obj, scm_acons (key, value, alist));
87 scm_i_pthread_mutex_unlock (&scm_i_misc_mutex);
88
89 return value;
90}
91#undef FUNC_NAME
92
93
94void
95scm_init_objprop ()
96{
97 object_whash = scm_c_make_weak_table (0, SCM_WEAK_TABLE_KIND_KEY);
98#include "libguile/objprop.x"
99}
100
101
102/*
103 Local Variables:
104 c-file-style: "gnu"
105 End:
106*/