[asterisk-scf-commits] asterisk-scf/release/ice.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Mar 18 13:01:20 CDT 2011


branch "master" has been updated
       via  cad92d3d6078843d75105d75eac87a9753052724 (commit)
       via  a1c5db7561ca56ba69a6022c55a620cb0ee9ee6d (commit)
      from  00a40f0025fbb1283d88fc9bcd1d902d08c60854 (commit)

Summary of changes:
 cpp/src/IceUtil/DynamicLibrary.cpp |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)


- Log -----------------------------------------------------------------
commit cad92d3d6078843d75105d75eac87a9753052724
Merge: 00a40f0 a1c5db7
Author: David M. Lee <dlee at digium.com>
Date:   Fri Mar 18 13:00:32 2011 -0500

    Merge branch 'origin-fix-apple-so'

diff --cc cpp/src/IceUtil/DynamicLibrary.cpp
index da851fc,0000000..40b8dd8
mode 100755,000000..100755
--- a/cpp/src/IceUtil/DynamicLibrary.cpp
+++ b/cpp/src/IceUtil/DynamicLibrary.cpp
@@@ -1,257 -1,0 +1,261 @@@
 +// **********************************************************************
 +//
 +// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
 +//
 +// This copy of Ice is licensed to you under the terms described in the
 +// ICE_LICENSE file included in this distribution.
 +//
 +// **********************************************************************
 +
 +#include <IceUtil/DynamicLibrary.h>
 +#include <IceUtil/StringUtil.h>
 +
 +#ifndef _WIN32
 +#   include <dlfcn.h>
 +#endif
 +
 +using namespace Ice;
 +using namespace std;
 +
 +IceUtil::Shared* IceUtilInternal::upCast(DynamicLibrary* p) { return p; }
 +IceUtil::Shared* IceUtilInternal::upCast(DynamicLibraryList* p) { return p; }
 +
 +IceUtilInternal::DynamicLibrary::DynamicLibrary()
 +    : _hnd(0)
 +{
 +}
 +
 +IceUtilInternal::DynamicLibrary::~DynamicLibrary()
 +{
 +    /*
 +     * Closing the library here can cause a crash at program exit if
 +     * the application holds references to library resources in global
 +     * or static variables. Instead, we let the process discard the
 +     * library.
 +     *
 +    if(_hnd != 0)
 +    {
 +#ifdef _WIN32
 +        FreeLibrary(_hnd);
 +#else
 +        dlclose(_hnd);
 +#endif
 +    }
 +    */
 +}
 +
 +IceUtilInternal::DynamicLibrary::symbol_type
 +IceUtilInternal::DynamicLibrary::loadEntryPoint(const string& entryPoint, bool useIceVersion)
 +{
 +    // entryPoint format: [libPath@]libName[,version]:funcName
 +    string::size_type colon = entryPoint.rfind(':');
 +    string::size_type comma = entryPoint.find(',');
 +    string::size_type at = entryPoint.find('@');
 +    if(colon == string::npos || colon == entryPoint.size() - 1 ||
 +        (comma != string::npos && (comma > colon || comma == colon - 1)) ||
 +        (at != string::npos && (at >= colon - 1 ||
 +            (comma != string::npos && at >= comma - 1))))
 +    {
 +        _err = "invalid entry point format `" + entryPoint + "'";
 +        return 0;
 +    }
 +    string libSpec = entryPoint.substr(0, colon);
 +    string funcName = entryPoint.substr(colon + 1);
 +    string libName, version, debug;
 +    if(comma == string::npos)
 +    {
 +        libName = libSpec;
 +        if(useIceVersion)
 +        {
 +            int majorVersion = (ICE_INT_VERSION / 10000);
 +            int minorVersion = (ICE_INT_VERSION / 100) - majorVersion * 100;
 +            ostringstream os;
 +            os << majorVersion * 10 + minorVersion;
 +            
 +            int patchVersion = ICE_INT_VERSION % 100;
 +            if(patchVersion > 50)
 +            {
 +                os << 'b';
 +                if(patchVersion >= 52)
 +                {
 +                    os << (patchVersion - 50);
 +                }
 +            }
 +            version = os.str();
 +        }
 +    }
 +    else
 +    {
 +        libName = libSpec.substr(0, comma);
 +        version = libSpec.substr(comma + 1);
 +    }
 +
 +    string lib, libPath;
 +
 +    if (at != string::npos)
 +    {
 +        libPath = libName.substr(0, at) + '/';
 +        libName = libName.substr(at + 1);
 +    }
 +
 +
 +#ifdef _WIN32
 +    // convert forward slash to back slash
 +    string::size_type slash;
 +    while ((slash = libPath.find('/')) != string::npos)
 +    {
 +        libPath.replace(slash, 1, 1, '\\');
 +    }
 +    lib = libPath + libName;
 +
 +#   ifdef COMPSUFFIX
 +    //
 +    // If using unique dll names we need to add compiler suffix
 +    // to IceSSL so that we do not have to use compiler suffix
 +    // in the configuration.
 +    //
 +    if(IceUtilInternal::toLower(libName) == "icessl")
 +    {
 +        lib += COMPSUFFIX;
 +    }
 +#   endif
 +
 +    lib += version;
 +
 +#   ifdef _DEBUG
 +    lib += 'd';
 +#   endif
 +
 +    lib += ".dll";
 +#elif defined(__APPLE__)
 +    lib = libPath + "lib" + libName;
 +    if(!version.empty()) 
 +    {
 +        lib += "." + version;
 +    }
-     lib += ".so"; // .so for loadable module on Mach-O
++    lib += ".dylib";
 +#elif defined(__hpux)
 +    lib = libPath + "lib" + libName;
 +    if(!version.empty())
 +    {
 +        lib += "." + version;
 +    }
 +    else
 +    {
 +        lib += ".sl";
 +    }
 +#elif defined(_AIX)
 +    lib = libPath + "lib" + libName + ".a(lib" + libName + ".so";
 +    if(!version.empty())
 +    {
 +        lib += "." + version;
 +    }
 +    lib += ")";
 +#else
 +    lib = libPath + "lib" + libName + ".so";
 +    if(!version.empty())
 +    {
 +        lib += "." + version;
 +    }
 +#endif
 +
 +    if(!load(lib))
 +    {
 +#ifdef __APPLE__
-         string olderr = _err;
-         // Previous versions of Ice mistakenly loaded .dylib.  If it can't
-         // load a .so, fallback to loading a .dylib.  For more info on
-         // shared libraries (.dylib) vs. loadable modules (.so), see
-         // http://www.finkproject.org/doc/porting/shared.php
++        string allerr = _err;
++        // For Mac OS X, there is a distinction between shared libraries
++        // (.dylib) and loadable modules (usually .bundle or .so).  If we can't
++        // load as a shared library, try loading as a bundle.  For more info,
++        // see http://www.finkproject.org/doc/porting/shared.php
 +        lib = "lib" + libName;
 +        if(!version.empty())
 +        {
 +            lib += "." + version;
 +        }
-         lib += ".dylib";
-         if(!load(lib))
++        if(!load(lib + ".so"))
 +        {
-             // restore old error message
-             _err = olderr;
-             return 0;
++            allerr += "; " + _err;
++            if (!load(lib + ".bundle"))
++            {
++                // failed to load .dylib, .so and .bundle.
++                allerr += "; " + _err;
++                _err = allerr;
++                return 0;
++            }
 +        }
 +#else
 +        return 0;
 +#endif
 +    }
 +
 +    return getSymbol(funcName);
 +}
 +
 +bool
 +IceUtilInternal::DynamicLibrary::load(const string& lib)
 +{
 +#ifdef _WIN32
 +    _hnd = LoadLibrary(lib.c_str());
 +#else
 +
 +    int flags = RTLD_NOW | RTLD_GLOBAL;
 +#ifdef _AIX
 +    flags |= RTLD_MEMBER;
 +#endif
 +
 +    _hnd = dlopen(lib.c_str(), flags);
 +    if(_hnd == 0)
 +    {
 +        //
 +        // Remember the most recent error in _err.
 +        //
 +        const char* err = dlerror();
 +
 +        if(err)
 +        {
 +            _err = err;
 +        }
 +    }
 +#endif
 +    return _hnd != 0;
 +}
 +
 +IceUtilInternal::DynamicLibrary::symbol_type
 +IceUtilInternal::DynamicLibrary::getSymbol(const string& name)
 +{
 +    assert(_hnd != 0);
 +#ifdef _WIN32
 +#  ifdef __BCPLUSPLUS__
 +    string newName = "_" + name;
 +    return GetProcAddress(_hnd, newName.c_str());
 +#  else
 +    return GetProcAddress(_hnd, name.c_str());
 +#  endif
 +#else
 +    symbol_type result = dlsym(_hnd, name.c_str());
 +    if(result == 0)
 +    {
 +        //
 +        // Remember the most recent error in _err.
 +        //
 +        const char* err = dlerror();
 +        if(err)
 +        {
 +            _err = err;
 +        }
 +    }
 +    return result;
 +#endif
 +}
 +
 +const string&
 +IceUtilInternal::DynamicLibrary::getErrorMessage() const
 +{
 +    return _err;
 +}
 +
 +void
 +IceUtilInternal::DynamicLibraryList::add(const DynamicLibraryPtr& library)
 +{
 +    _libraries.push_back(library);
 +}

-----------------------------------------------------------------------


-- 
asterisk-scf/release/ice.git



More information about the asterisk-scf-commits mailing list