This file is indexed.

/usr/include/Field3D/RefCount.h is in libfield3d-dev 1.6.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//----------------------------------------------------------------------------//

/*
 * Copyright (c) 2009 Sony Pictures Imageworks Inc
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the
 * distribution.  Neither the name of Sony Pictures Imageworks nor the
 * names of its contributors may be used to endorse or promote
 * products derived from this software without specific prior written
 * permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

//----------------------------------------------------------------------------//

/*! \file RefCount.h
  \brief Contains base class for reference counting with Mutex
*/

//----------------------------------------------------------------------------//

#ifndef _INCLUDED_Field3D_REF_COUNT_H_
#define _INCLUDED_Field3D_REF_COUNT_H_

#define FIELD3D_USE_ATOMIC_COUNT

//----------------------------------------------------------------------------//
#include <boost/intrusive_ptr.hpp> 

#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

#ifdef FIELD3D_USE_ATOMIC_COUNT
#include <boost/detail/atomic_count.hpp>
#else
#include <boost/thread/mutex.hpp>
#endif

#include <string.h>
#include "Traits.h"
#include "ns.h"

FIELD3D_NAMESPACE_OPEN

//----------------------------------------------------------------------------//
// Field RTTI Replacement
//----------------------------------------------------------------------------//

#define DEFINE_CHECK_RTTI_CALL                    \
  virtual bool checkRTTI(const char *typenameStr) \
  { return matchRTTI(typenameStr); }              \
  
#define DEFINE_MATCH_RTTI_CALL                        \
  bool matchRTTI(const char *typenameStr)             \
  {                                                   \
    if (strcmp(typenameStr,staticClassType()) == 0) {       \
      return true;                                    \
    }                                                 \
    return base::matchRTTI(typenameStr);              \
  }                                                   \

#define DEFINE_FIELD_RTTI_CONCRETE_CLASS        \
  DEFINE_CHECK_RTTI_CALL                        \
  DEFINE_MATCH_RTTI_CALL                        \

#define DEFINE_FIELD_RTTI_ABSTRACT_CLASS        \
  DEFINE_MATCH_RTTI_CALL                        \

//----------------------------------------------------------------------------//
// null_deleter (for shared_ptr)
//----------------------------------------------------------------------------//

//! Used to let a shared pointer exist that doesn't delete anything.
//! This is used by RefBase to hold a shared pointer to *this without
//! actually deleting twice when the object goes out of scope.
struct null_deleter
{
  void operator()(void const *) const
  { }
};

//----------------------------------------------------------------------------//

class FIELD3D_API RefBase 
{
public:

  // Typedefs ------------------------------------------------------------------

  typedef boost::intrusive_ptr<RefBase> Ptr;
  typedef boost::weak_ptr<RefBase>      WeakPtr;

  // Constructors --------------------------------------------------------------

  //! \name Constructors, destructors, copying
  //! \{

  RefBase() 
    : m_counter(0), 
      m_sharedPtr(this, null_deleter()) 
  { }

  //! Copy constructor
  //! \note The null_deleter ensures we never try to actually delete this
  //! object using the shared pointer.
  RefBase(const RefBase&) 
    : m_counter(0),
      m_sharedPtr(this, null_deleter()) 
  { }

  //! Assignment operator
  RefBase& operator= (const RefBase&)
  { return *this; }

  //! Destructor
  virtual ~RefBase() 
  {}

  //! \}

  // Reference counting --------------------------------------------------------

  //! Used by boost::intrusive_pointer
  size_t refcnt() 
  { return m_counter; }
    
  //! Used by boost::intrusive_pointer
  void ref() const
  { 
#ifndef FIELD3D_USE_ATOMIC_COUNT
    boost::mutex::scoped_lock lock(m_refMutex);
#endif
    ++m_counter; 
  }

  //! Used by boost::intrusive_pointer
  void unref() const
  {
#ifndef FIELD3D_USE_ATOMIC_COUNT
    boost::mutex::scoped_lock lock(m_refMutex);
#endif
    --m_counter; 
    // since we use intrusive_pointer no need
    // to delete the object ourselves.
  }
  
  // Cache handling ------------------------------------------------------------

  WeakPtr weakPtr() const
  { return m_sharedPtr; }

  // RTTI replacement ----------------------------------------------------------

  /*! \note A note on why the RTTI replacement is needed:
     RTTI calls fail once the object crosses the dso boundary. We revert
     to using simple string checks which is more expensive but at least works
     once the dso is used in Houdini, etc.
     Use field_dynamic_cast<> for any RefBase subclass instead of 
     dynamic_cast<>.
  */

  //! \name RTTI replacement
  //! \{

  //! This function is only implemented by concrete classes and triggers
  //! the actual RTTI check through matchRTTI();
  virtual bool checkRTTI(const char *typenameStr) = 0;
  
  //! Performs a check to see if the given typename string matches this class'
  //! This needs to be implemented in -all- subclasses, even abstract ones.
  bool matchRTTI(const char *typenameStr)
  {
    if (strcmp(staticClassType(), typenameStr) == 0)
      return true;
    return false;
  }

  static const char *staticClassType()
  {
    return "RefBase";
  }

  //! \}

private:

  //! For boost intrusive pointer
#ifdef FIELD3D_USE_ATOMIC_COUNT
  mutable boost::detail::atomic_count m_counter;
#else
  mutable long m_counter;
  //! Mutex for ref counting
  mutable boost::mutex m_refMutex;     
#endif

  //! For use by the FieldCache only:
  //! The shared pointer lets us see if this object is still alive.
  boost::shared_ptr<RefBase> m_sharedPtr;

};

//----------------------------------------------------------------------------//
// Intrusive Pointer reference counting 
//----------------------------------------------------------------------------//

inline void 
intrusive_ptr_add_ref(RefBase* r)
{
  r->ref();
}

//----------------------------------------------------------------------------//

//! \todo Communicate with the FieldCache to prevent any cache updates from
//! happening while this releases its count.
inline void
intrusive_ptr_release(RefBase* r)
{
  r->unref();

  if (r->refcnt() == 0)
    delete r;
}

//----------------------------------------------------------------------------//
// field_dynamic_cast
//----------------------------------------------------------------------------//

//! Dynamic cast that uses string-comparison in order to be safe even
//! after an object crosses a shared library boundary.
//! \ingroup field
template <class Field_T>
typename Field_T::Ptr
field_dynamic_cast(RefBase::Ptr field)
{
  if (!field) 
    return NULL;

  const char *tgtTypeString =  Field_T::staticClassType();
  
  if (field->checkRTTI(tgtTypeString)) {
    return static_cast<Field_T*>(field.get());
  } else {
    return NULL;
  }
}

//#define FIELD_DYNAMIC_CAST boost::dynamic_pointer_cast
#define FIELD_DYNAMIC_CAST field_dynamic_cast

//----------------------------------------------------------------------------//

FIELD3D_NAMESPACE_HEADER_CLOSE

//----------------------------------------------------------------------------//

#endif // Include guard