Skip to content
Snippets Groups Projects
  • Henry's avatar
    325b003b
    Added and verified support for 64bit labels · 325b003b
    Henry authored
    To compile with 64bit labels set
    
    WM_LABEL_SIZE=64
    
    in ~/OpenFOAM/dev/prefs.sh
    
    source ~/.bashrc
    
    then Allwmake in OpenFOAM-dev.
    
    This will build into for example OpenFOAM-dev/platforms/linux64ClangDPInt64Opt
    
    If WM_LABEL_SIZE is unset or set to 32:
    
    WM_LABEL_SIZE=32
    
    the build would be placed into OpenFOAM-dev/platforms/linux64ClangDPInt32Opt
    
    Thus both 32bit and 64bit label builds can coexist without problem.
    325b003b
    History
    Added and verified support for 64bit labels
    Henry authored
    To compile with 64bit labels set
    
    WM_LABEL_SIZE=64
    
    in ~/OpenFOAM/dev/prefs.sh
    
    source ~/.bashrc
    
    then Allwmake in OpenFOAM-dev.
    
    This will build into for example OpenFOAM-dev/platforms/linux64ClangDPInt64Opt
    
    If WM_LABEL_SIZE is unset or set to 32:
    
    WM_LABEL_SIZE=32
    
    the build would be placed into OpenFOAM-dev/platforms/linux64ClangDPInt32Opt
    
    Thus both 32bit and 64bit label builds can coexist without problem.
dlLibraryTable.C 4.82 KiB
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2011-2014 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM 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 General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "dlLibraryTable.H"
#include "OSspecific.H"
#include "int.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
    defineTypeNameAndDebug(dlLibraryTable, 0);
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::dlLibraryTable::dlLibraryTable()
{}


Foam::dlLibraryTable::dlLibraryTable
(
    const dictionary& dict,
    const word& libsEntry
)
{
    open(dict, libsEntry);
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::dlLibraryTable::~dlLibraryTable()
{
    forAllReverse(libPtrs_, i)
    {
        if (libPtrs_[i])
        {
            if (debug)
            {
                Info<< "dlLibraryTable::~dlLibraryTable() : closing "
                    << libNames_[i]
                    << " with handle " << uintptr_t(libPtrs_[i]) << endl;
            }
            dlClose(libPtrs_[i]);
        }
    }
}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

bool Foam::dlLibraryTable::open
(
    const fileName& functionLibName,
    const bool verbose
)
{
    if (functionLibName.size())
    {
        void* functionLibPtr = dlOpen(functionLibName, verbose);

        if (debug)
        {
            Info<< "dlLibraryTable::open : opened " << functionLibName
                << " resulting in handle " << uintptr_t(functionLibPtr) << endl;
        }

        if (!functionLibPtr)
        {
            if (verbose)
            {
                WarningIn
                (
                    "dlLibraryTable::open(const fileName&, const bool)"
                )   << "could not load " << functionLibName
                    << endl;
            }

            return false;
        }
        else
        {
            libPtrs_.append(functionLibPtr);
            libNames_.append(functionLibName);
            return true;
        }
    }
    else
    {
        return false;
    }
}


bool Foam::dlLibraryTable::close
(
    const fileName& functionLibName,
    const bool verbose
)
{
    label index = -1;
    forAllReverse(libNames_, i)
    {
        if (libNames_[i] == functionLibName)
        {
            index = i;
            break;
        }
    }

    if (index != -1)
    {
        if (debug)
        {
            Info<< "dlLibraryTable::close : closing " << functionLibName
                << " with handle " << uintptr_t(libPtrs_[index]) << endl;
        }

        bool ok = dlClose(libPtrs_[index]);

        libPtrs_[index] = NULL;
        libNames_[index] = fileName::null;

        if (!ok)
        {
            if (verbose)
            {
                WarningIn
                (
                    "dlLibraryTable::close(const fileName&)"
                )   << "could not close " << functionLibName
                    << endl;
            }

            return false;
        }

        return true;
    }
    return false;
}


void* Foam::dlLibraryTable::findLibrary(const fileName& functionLibName)
{
    label index = -1;
    forAllReverse(libNames_, i)
    {
        if (libNames_[i] == functionLibName)
        {
            index = i;
            break;
        }
    }

    if (index != -1)
    {
        return libPtrs_[index];
    }
    return NULL;
}


bool Foam::dlLibraryTable::open
(
    const dictionary& dict,
    const word& libsEntry
)
{
    if (dict.found(libsEntry))
    {
        fileNameList libNames(dict.lookup(libsEntry));

        bool allOpened = !libNames.empty();

        forAll(libNames, i)
        {
            allOpened = dlLibraryTable::open(libNames[i]) && allOpened;
        }

        return allOpened;
    }
    else
    {
        return false;
    }
}


// ************************************************************************* //