LCOV - code coverage report
Current view: top level - tools - DLLoader.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 17 21 81.0 %
Date: 2024-10-11 08:09:47 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-2023 The plumed team
       3             :    (see the PEOPLE file at the root of the distribution for a list of names)
       4             : 
       5             :    See http://www.plumed.org for more information.
       6             : 
       7             :    This file is part of plumed, version 2.
       8             : 
       9             :    plumed is free software: you can redistribute it and/or modify
      10             :    it under the terms of the GNU Lesser General Public License as published by
      11             :    the Free Software Foundation, either version 3 of the License, or
      12             :    (at your option) any later version.
      13             : 
      14             :    plumed is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU Lesser General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU Lesser General Public License
      20             :    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
      21             : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
      22             : #include "DLLoader.h"
      23             : #include <cstdlib>
      24             : 
      25             : #ifdef __PLUMED_HAS_DLOPEN
      26             : #include <dlfcn.h>
      27             : #endif
      28             : 
      29             : namespace PLMD {
      30             : 
      31           2 : bool DLLoader::installed() {
      32             : #ifdef __PLUMED_HAS_DLOPEN
      33           2 :   return true;
      34             : #else
      35             :   return false;
      36             : #endif
      37             : }
      38             : 
      39             : 
      40           1 : void* DLLoader::load(const std::string&s) {
      41             : #ifdef __PLUMED_HAS_DLOPEN
      42           1 :   void* p=dlopen(s.c_str(),RTLD_NOW|RTLD_LOCAL);
      43           1 :   if(!p) {
      44           0 :     lastError=dlerror();
      45             :   } else {
      46           1 :     lastError="";
      47             :     handles.push(p);
      48             :   }
      49           1 :   return p;
      50             : #else
      51             :   return NULL;
      52             : #endif
      53             : }
      54             : 
      55           0 : const std::string & DLLoader::error() {
      56           0 :   return lastError;
      57             : }
      58             : 
      59      407840 : DLLoader::~DLLoader() {
      60      407840 :   auto debug=std::getenv("PLUMED_LOAD_DEBUG");
      61      407840 :   if(debug) std::fprintf(stderr,"delete dlloader\n");
      62             : #ifdef __PLUMED_HAS_DLOPEN
      63      407841 :   while(!handles.empty()) {
      64           1 :     int ret=dlclose(handles.top());
      65           1 :     if(ret) {
      66           0 :       std::fprintf(stderr,"+++ error reported by dlclose: %s\n",dlerror());
      67             :     }
      68             :     handles.pop();
      69             :   }
      70             : #endif
      71      407840 :   if(debug) std::fprintf(stderr,"end delete dlloader\n");
      72      407840 : }
      73             : 
      74      407840 : DLLoader::DLLoader() {
      75             :   // do nothing
      76      407840 : }
      77             : 
      78             : 
      79             : }

Generated by: LCOV version 1.15