Add bug 494246 to NEWS
[valgrind.git] / helgrind / hg_wordset.h
blobc7264b8d36405a729b6aa396fd6753a9ea0fce28
2 /*--------------------------------------------------------------------*/
3 /*--- Sets of words, with unique set identifiers. ---*/
4 /*--- hg_wordset.h ---*/
5 /*--------------------------------------------------------------------*/
7 /*
8 This file is part of Helgrind, a Valgrind tool for detecting errors
9 in threaded programs.
11 Copyright (C) 2007-2017 OpenWorks LLP
12 info@open-works.co.uk
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, see <http://www.gnu.org/licenses/>.
27 The GNU General Public License is contained in the file COPYING.
29 Neither the names of the U.S. Department of Energy nor the
30 University of California nor the names of its contributors may be
31 used to endorse or promote products derived from this software
32 without prior written permission.
35 #ifndef __HG_WORDSET_H
36 #define __HG_WORDSET_H
38 //------------------------------------------------------------------//
39 //--- WordSet ---//
40 //--- Public Interface ---//
41 //------------------------------------------------------------------//
43 typedef struct _WordSetU WordSetU; /* opaque */
45 typedef UInt WordSet; /* opaque, small int index */
47 /* Allocate and initialise a WordSetU */
48 WordSetU* HG_(newWordSetU) ( void* (*alloc_nofail)( const HChar*, SizeT ),
49 const HChar* cc,
50 void (*dealloc)(void*),
51 Word cacheSize );
53 /* Free up the WordSetU. */
54 void HG_(deleteWordSetU) ( WordSetU* );
56 /* Get the number of elements in this WordSetU. Note that the dead
57 WordSet are included in the WordSetU number of elements. */
58 UWord HG_(cardinalityWSU) ( WordSetU* );
60 /* Show performance stats for this WordSetU. */
61 void HG_(ppWSUstats) ( WordSetU* wsu, const HChar* name );
64 /* Element-level operations on WordSets. Note that the WordSet
65 numbers given out are 0, 1, 2, 3, etc, and as it happens 0 always
66 represents the empty set. */
68 WordSet HG_(emptyWS) ( WordSetU* );
69 WordSet HG_(addToWS) ( WordSetU*, WordSet, UWord );
70 WordSet HG_(delFromWS) ( WordSetU*, WordSet, UWord );
71 WordSet HG_(unionWS) ( WordSetU*, WordSet, WordSet );
72 WordSet HG_(intersectWS) ( WordSetU*, WordSet, WordSet );
73 WordSet HG_(minusWS) ( WordSetU*, WordSet, WordSet );
74 Bool HG_(isEmptyWS) ( WordSetU*, WordSet );
75 Bool HG_(isSingletonWS) ( WordSetU*, WordSet, UWord );
76 UWord HG_(anyElementOfWS) ( WordSetU*, WordSet );
77 UWord HG_(cardinalityWS) ( WordSetU*, WordSet );
78 Bool HG_(elemWS) ( WordSetU*, WordSet, UWord );
79 WordSet HG_(doubletonWS) ( WordSetU*, UWord, UWord );
80 WordSet HG_(singletonWS) ( WordSetU*, UWord );
81 WordSet HG_(isSubsetOf) ( WordSetU*, WordSet, WordSet );
83 Bool HG_(plausibleWS) ( WordSetU*, WordSet );
86 Bool HG_(saneWS_SLOW) ( WordSetU*, WordSet );
88 void HG_(ppWS) ( WordSetU*, WordSet );
90 void HG_(getPayloadWS) ( /*OUT*/UWord** words, /*OUT*/UWord* nWords,
91 WordSetU*, WordSet );
93 /* HG_(dieWS) indicates WordSet is not used/not referenced anymore,
94 and its memory can be reclaimed.
95 If ever a WordSet with the same content would be needed again,
96 a new WordSet will be reallocated.
98 BUG ALERT: !!! Using HG_(dieWS) on a WSU introduces a risk of
99 dangling references. Dangling references can be created by keeping
100 a ws after having marked it dead. This ws (just an index in
101 reality) will be re-cycled : a newly created wv can get the same
102 index. This implies that the wrong wv will be used if the
103 "old" ws has been kept.
104 Re-using a "dead" ws will be detected if the index has not been
105 re-cycled yet.
107 Another possibility of bug is to ask for the payload of a ws, and
108 then have this ws marked dead while the payload is still being
109 examined. This is a real dangling reference in free or re-allocated
110 memory. */
111 void HG_(dieWS) ( WordSetU*, WordSet );
115 //------------------------------------------------------------------//
116 //--- end WordSet ---//
117 //--- Public Interface ---//
118 //------------------------------------------------------------------//
120 #endif /* ! __HG_WORDSET_H */
122 /*--------------------------------------------------------------------*/
123 /*--- end hg_wordset.h ---*/
124 /*--------------------------------------------------------------------*/