This file is indexed.

/usr/include/roboptim/core/solver-factory.hxx is in libroboptim-core-dev 2.0-7.

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
// Copyright (C) 2009 by Thomas Moulard, AIST, CNRS, INRIA.
//
// This file is part of the roboptim.
//
// roboptim is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// roboptim is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with roboptim.  If not, see <http://www.gnu.org/licenses/>.

#ifndef ROBOPTIM_CORE_SOLVER_FACTORY_HXX
# define ROBOPTIM_CORE_SOLVER_FACTORY_HXX
# include <cstddef>
# include <sstream>

namespace roboptim
{
  // This union is here to workaround a limitation of the C++
  // standard. There is *no* way to cast a pointer to object into a
  // pointer to function.
  //
  // Unfortunately lt_dlsym is giving us a void* so we have to use
  // this kind of trick to transform it into a pointer to function.
  template <typename T>
  T* unionCast(void* ptr)
  {
    union
    {
      void* ptr;
      T* real_ptr;
    } u;
    u.ptr = ptr;
    return u.real_ptr;
  }

  template <typename T>
  SolverFactory<T>::SolverFactory (std::string plugin, const problem_t& pb)
  throw (std::runtime_error)
    : handle_ (),
      solver_ ()
  {
    typedef std::size_t getsizeofproblem_t ();
    typedef solver_t* create_t (const problem_t&);

    if (lt_dlinit () > 0)
      throw std::runtime_error ("failed to initialize libltdl.");

    std::stringstream ss;
    ss << "roboptim-core-plugin-" << plugin;
    handle_ = lt_dlopenext (ss.str ().c_str ());
    if (!handle_)
      {
	std::stringstream sserror;
	sserror << "libltdl failed to load plug-in ``"
		<< ss.str () << "'': " << lt_dlerror ();
	lt_dlexit ();
	throw std::runtime_error (sserror.str ().c_str ());
      }

    getsizeofproblem_t* getSizeOfProblem =
      unionCast<getsizeofproblem_t> (lt_dlsym (handle_, "getSizeOfProblem"));
    if (!getSizeOfProblem)
      {
	std::stringstream sserror;
	sserror << "libltdl failed to find symbol ``getSizeOfProblem'': "
		<< lt_dlerror ();

	lt_dlclose (handle_);
	lt_dlexit ();
	throw std::runtime_error (sserror.str ().c_str ());
      }

    std::size_t sizeOfProblem = getSizeOfProblem ();
    if (sizeOfProblem != sizeof (typename solver_t::problem_t))
      {
	std::stringstream sserror;
	sserror
	  << "``Problem'' type size does not match in application and plug-in"
	  << " (size is " << sizeOfProblem
	  << " byte(s) but " << sizeof (typename solver_t::problem_t)
	  << " byte(s) was expected by application)";

	lt_dlclose (handle_);
	lt_dlexit ();
	throw std::runtime_error (sserror.str ().c_str ());
      }


    create_t* c =
      unionCast<create_t> (lt_dlsym (handle_, "create"));
    if (!c)
      {
	std::stringstream sserror;
	sserror << "libltdl failed to find symbol ``create'': "
		<< lt_dlerror ();

	lt_dlclose (handle_);
	lt_dlexit ();
	throw std::runtime_error (sserror.str ().c_str ());
      }

    solver_ = c (pb);

    if (!solver_)
      {
	std::stringstream sserror;
	sserror << "libltdl failed to call ``create'': "
		<< lt_dlerror ();

	lt_dlclose (handle_);
	lt_dlexit ();
	throw std::runtime_error (sserror.str ().c_str ());
      }
  }

  template <typename T>
  SolverFactory<T>::~SolverFactory () throw ()
  {
    typedef void destroy_t (solver_t*);

    destroy_t* destructor =
      unionCast<destroy_t> (lt_dlsym (handle_, "destroy"));
    if (destructor)
      {
        destructor (solver_);
        solver_ = 0;
      }
    else
      {
	std::stringstream sserror;
	sserror << "libltdl failed to call ``destroy'': "
		<< lt_dlerror ();
      }

    if (lt_dlclose (handle_))
      {
	std::stringstream sserror;
	sserror << "libltdl failed to close plug-in: "
		<< lt_dlerror ();
	std::cerr << sserror << std::endl;
      }

    if (lt_dlexit ())
      {
	std::stringstream sserror;
	sserror << "libltdl failed to call ``create'': "
		<< lt_dlerror ();
	std::cerr << sserror << std::endl;
      }
  }

  template <typename T>
  typename SolverFactory<T>::solver_t&
  SolverFactory<T>::operator () () throw ()
  {
    assert (solver_ != 0);
    return *solver_;
  }

} // end of namespace roboptim

#endif //! ROBOPTIM_CORE_SOLVER_FACTORY_HXX