~quadrispro/codelite/trunk

« back to all changes in this revision

Viewing changes to CodeLite/dynamiclibrary.cpp

  • Committer: eranif
  • Date: 2008-09-25 10:34:59 UTC
  • Revision ID: svn-v4:9da81c78-c036-0410-9e1f-a2b0375e4b5a:trunk:2193
- Reverted changes done to ctags due to instabilty

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//////////////////////////////////////////////////////////////////////////////
2
 
//////////////////////////////////////////////////////////////////////////////
3
 
//
4
 
// copyright            : (C) 2008 by Eran Ifrah                            
5
 
// file name            : dynamiclibrary.cpp              
6
 
//                                                                          
7
 
// -------------------------------------------------------------------------
8
 
// A                                                                        
9
 
//              _____           _      _     _ _                            
10
 
//             /  __ \         | |    | |   (_) |                           
11
 
//             | /  \/ ___   __| | ___| |    _| |_ ___                      
12
 
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )                     
13
 
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/                     
14
 
//              \____/\___/ \__,_|\___\_____/_|\__\___|                     
15
 
//                                                                          
16
 
//                                                  F i l e                 
17
 
//                                                                          
18
 
//    This program is free software; you can redistribute it and/or modify  
19
 
//    it under the terms of the GNU General Public License as published by  
20
 
//    the Free Software Foundation; either version 2 of the License, or     
21
 
//    (at your option) any later version.                                   
22
 
//                                                                          
23
 
//////////////////////////////////////////////////////////////////////////////
24
 
//////////////////////////////////////////////////////////////////////////////
25
 
 #include "dynamiclibrary.h"
26
 
 
27
 
#if defined(__WXMAC__) || defined(__WXGTK__)
28
 
# include <dlfcn.h>
29
 
# include "precompiled_header.h"
30
 
#endif
31
 
 
32
 
clDynamicLibrary::clDynamicLibrary()
33
 
#if defined(__WXMAC__) || defined(__WXGTK__)
34
 
                : m_dllhandle(NULL)
35
 
#endif
36
 
{
37
 
}
38
 
 
39
 
clDynamicLibrary::~clDynamicLibrary()
40
 
{
41
 
#if defined(__WXMAC__) || defined(__WXGTK__)
42
 
        if(m_dllhandle){
43
 
                dlclose(m_dllhandle);
44
 
                m_dllhandle = NULL;
45
 
        }
46
 
#endif
47
 
}
48
 
 
49
 
bool clDynamicLibrary::Load(const wxString &name)
50
 
{
51
 
#if defined (__WXMSW__)
52
 
        return m_lib.Load(name, wxDL_NOSHARE);
53
 
#else
54
 
        // open the library
55
 
#if defined(__WXGTK__) && defined (ON_64_BIT)
56
 
        // on GTK we need to pass RTLD_DEEPBIND otherwise symbols clashes
57
 
        m_dllhandle = dlopen(_C(name), RTLD_LAZY| RTLD_LOCAL | RTLD_DEEPBIND);
58
 
#else   
59
 
        m_dllhandle = dlopen(_C(name), RTLD_LAZY);
60
 
#endif
61
 
 
62
 
        if (!m_dllhandle) {
63
 
                wxString error = wxString(dlerror(), wxConvUTF8);
64
 
                return false;
65
 
        }
66
 
        return true;
67
 
#endif
68
 
}
69
 
 
70
 
void clDynamicLibrary::Detach()
71
 
{
72
 
#if defined (__WXMSW__)
73
 
        m_lib.Detach();
74
 
#else
75
 
        if (m_dllhandle) {
76
 
                dlclose(m_dllhandle);
77
 
                m_dllhandle = NULL;
78
 
        }
79
 
#endif
80
 
}
81
 
 
82
 
void *clDynamicLibrary::GetSymbol(const wxString &name, bool *success)
83
 
{
84
 
#if defined (__WXMSW__)
85
 
        bool rc;
86
 
        void *symb = m_lib.GetSymbol(name, &rc);
87
 
        *success = rc;
88
 
        return symb;
89
 
#else
90
 
        dlerror(); // reset errors
91
 
 
92
 
        // load the symbol
93
 
        void *symb = dlsym(m_dllhandle, _C(name));
94
 
        if(symb){
95
 
                *success = true;
96
 
        }else{
97
 
                *success = false;
98
 
        }
99
 
        return symb;
100
 
#endif
101
 
}
102
 
 
103
 
bool clDynamicLibrary::IsLoaded()
104
 
{
105
 
#if defined (__WXMSW__)
106
 
        return m_lib.IsLoaded();
107
 
#else
108
 
        return m_dllhandle != NULL;
109
 
#endif
110
 
}