fix(templates): Corrected explicit template instantiations to avoid multiple instances.

This commit is contained in:
Matej Kenda 2025-01-14 11:18:10 +01:00
parent 38a1e30965
commit 674e2bae97
22 changed files with 284 additions and 47 deletions

View File

@ -10,7 +10,8 @@ include ODBC.make
objects = Binder ConnectionHandle Connector EnvironmentHandle \
Extractor ODBCException ODBCMetaColumn ODBCStatementImpl \
Parameter Preparator SessionImpl TypeInfo Unicode Utility
Parameter Preparator SessionImpl TypeInfo Unicode Utility \
Diagnostics Error
target_includes = $(POCO_BASE)/Data/testsuite/include

View File

@ -635,6 +635,14 @@
RelativePath=".\src\Unicode.cpp"
>
</File>
<File
RelativePath=".\src\Diagnostics.cpp"
>
</File>
<File
RelativePath=".\src\Error.cpp"
>
</File>
<File
RelativePath=".\src\Unicode_UNIXODBC.cpp"
>

View File

@ -677,7 +677,17 @@
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
<ClCompile Include="src\Unicode_UNIXODBC.cpp">
<ClCompile Include="src\Diagnostics.cpp">
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
<ClCompile Include="src\Error.cpp">
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
<ClCompile Include="src\Unicode_UNIXODBC.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug_shared|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug_shared|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug_static_md|Win32'">true</ExcludedFromBuild>

View File

@ -122,8 +122,14 @@
<ClCompile Include="src\Utility.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Diagnostics.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Error.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\DLLVersion.rc" />
</ItemGroup>
</Project>
</Project>

View File

@ -969,7 +969,17 @@
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
<ClCompile Include="src\Unicode_UNIXODBC.cpp">
<ClCompile Include="src\Diagnostics.cpp">
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
<ClCompile Include="src\Error.cpp">
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
<ClCompile Include="src\Unicode_UNIXODBC.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug_shared|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug_shared|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug_shared|x64'">true</ExcludedFromBuild>
@ -1039,4 +1049,4 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>
</Project>

View File

@ -122,8 +122,14 @@
<ClCompile Include="src\Utility.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Diagnostics.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Error.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\DLLVersion.rc" />
</ItemGroup>
</Project>
</Project>

View File

@ -19,6 +19,7 @@
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/Utility.h"
#include <vector>
#include <cstring>
#ifdef POCO_OS_FAMILY_WINDOWS
@ -243,10 +244,19 @@ private:
// explicit instantiation definition
#ifndef POCO_DOC
template class Diagnostics<SQLHENV, SQL_HANDLE_ENV>;
template class Diagnostics<SQLHDBC, SQL_HANDLE_DBC>;
template class Diagnostics<SQLHSTMT, SQL_HANDLE_STMT>;
template class Diagnostics<SQLHDESC, SQL_HANDLE_DESC>;
#if defined(POCO_OS_FAMILY_WINDOWS)
extern template class Diagnostics<SQLHENV, SQL_HANDLE_ENV>;
extern template class Diagnostics<SQLHDBC, SQL_HANDLE_DBC>;
extern template class Diagnostics<SQLHSTMT, SQL_HANDLE_STMT>;
extern template class Diagnostics<SQLHDESC, SQL_HANDLE_DESC>;
#else
extern template class ODBC_API Diagnostics<SQLHENV, SQL_HANDLE_ENV>;
extern template class ODBC_API Diagnostics<SQLHDBC, SQL_HANDLE_DBC>;
extern template class ODBC_API Diagnostics<SQLHSTMT, SQL_HANDLE_STMT>;
extern template class ODBC_API Diagnostics<SQLHDESC, SQL_HANDLE_DESC>;
#endif
#endif

View File

@ -126,12 +126,20 @@ private:
// explicit instantiation definition
#ifndef POCO_DOC
template class Error<SQLHENV, SQL_HANDLE_ENV>;
template class Error<SQLHDBC, SQL_HANDLE_DBC>;
template class Error<SQLHSTMT, SQL_HANDLE_STMT>;
template class Error<SQLHDESC, SQL_HANDLE_DESC>;
#if defined(POCO_OS_FAMILY_WINDOWS)
extern template class Error<SQLHENV, SQL_HANDLE_ENV>;
extern template class Error<SQLHDBC, SQL_HANDLE_DBC>;
extern template class Error<SQLHSTMT, SQL_HANDLE_STMT>;
extern template class Error<SQLHDESC, SQL_HANDLE_DESC>;
#else
extern template class ODBC_API Error<SQLHENV, SQL_HANDLE_ENV>;
extern template class ODBC_API Error<SQLHDBC, SQL_HANDLE_DBC>;
extern template class ODBC_API Error<SQLHSTMT, SQL_HANDLE_STMT>;
extern template class ODBC_API Error<SQLHDESC, SQL_HANDLE_DESC>;
#endif
#endif
using EnvironmentError = Error<SQLHENV, SQL_HANDLE_ENV>;
using ConnectionError = Error<SQLHDBC, SQL_HANDLE_DBC>;

View File

@ -140,10 +140,19 @@ private:
// explicit instantiation definition
#ifndef POCO_DOC
template class HandleException<SQLHENV, SQL_HANDLE_ENV>;
template class HandleException<SQLHDBC, SQL_HANDLE_DBC>;
template class HandleException<SQLHSTMT, SQL_HANDLE_STMT>;
template class HandleException<SQLHDESC, SQL_HANDLE_DESC>;
#if defined(POCO_OS_FAMILY_WINDOWS)
extern template class HandleException<SQLHENV, SQL_HANDLE_ENV>;
extern template class HandleException<SQLHDBC, SQL_HANDLE_DBC>;
extern template class HandleException<SQLHSTMT, SQL_HANDLE_STMT>;
extern template class HandleException<SQLHDESC, SQL_HANDLE_DESC>;
#else
extern template class ODBC_API HandleException<SQLHENV, SQL_HANDLE_ENV>;
extern template class ODBC_API HandleException<SQLHDBC, SQL_HANDLE_DBC>;
extern template class ODBC_API HandleException<SQLHSTMT, SQL_HANDLE_STMT>;
extern template class ODBC_API HandleException<SQLHDESC, SQL_HANDLE_DESC>;
#endif
#endif

View File

@ -0,0 +1,40 @@
//
// Diagnostics.cpp
//
// Library: Data/ODBC
// Package: ODBC
// Module: Diagnostics
//
// Copyright (c) 2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Data/ODBC/Diagnostics.h"
namespace Poco {
namespace Data {
namespace ODBC {
// explicit instantiation definition
#ifndef POCO_DOC
#if defined(POCO_OS_FAMILY_WINDOWS)
template class ODBC_API Diagnostics<SQLHENV, SQL_HANDLE_ENV>;
template class ODBC_API Diagnostics<SQLHDBC, SQL_HANDLE_DBC>;
template class ODBC_API Diagnostics<SQLHSTMT, SQL_HANDLE_STMT>;
template class ODBC_API Diagnostics<SQLHDESC, SQL_HANDLE_DESC>;
#else
template class Diagnostics<SQLHENV, SQL_HANDLE_ENV>;
template class Diagnostics<SQLHDBC, SQL_HANDLE_DBC>;
template class Diagnostics<SQLHSTMT, SQL_HANDLE_STMT>;
template class Diagnostics<SQLHDESC, SQL_HANDLE_DESC>;
#endif
#endif
} } } // namespace Poco::Data::ODBC

40
Data/ODBC/src/Error.cpp Normal file
View File

@ -0,0 +1,40 @@
//
// Error.cpp
//
// Library: Data/ODBC
// Package: ODBC
// Module: Error
//
// Copyright (c) 2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Data/ODBC/Error.h"
namespace Poco {
namespace Data {
namespace ODBC {
// explicit instantiation definition
#ifndef POCO_DOC
#if defined(POCO_OS_FAMILY_WINDOWS)
template class ODBC_API Error<SQLHENV, SQL_HANDLE_ENV>;
template class ODBC_API Error<SQLHDBC, SQL_HANDLE_DBC>;
template class ODBC_API Error<SQLHSTMT, SQL_HANDLE_STMT>;
template class ODBC_API Error<SQLHDESC, SQL_HANDLE_DESC>;
#else
template class Error<SQLHENV, SQL_HANDLE_ENV>;
template class Error<SQLHDBC, SQL_HANDLE_DBC>;
template class Error<SQLHSTMT, SQL_HANDLE_STMT>;
template class Error<SQLHDESC, SQL_HANDLE_DESC>;
#endif
#endif
} } } // namespace Poco::Data::ODBC

View File

@ -20,6 +20,17 @@ namespace Poco {
namespace Data {
namespace ODBC {
#if defined(POCO_OS_FAMILY_WINDOWS)
template class ODBC_API HandleException<SQLHENV, SQL_HANDLE_ENV>;
template class ODBC_API HandleException<SQLHDBC, SQL_HANDLE_DBC>;
template class ODBC_API HandleException<SQLHSTMT, SQL_HANDLE_STMT>;
template class ODBC_API HandleException<SQLHDESC, SQL_HANDLE_DESC>;
#else
template class HandleException<SQLHENV, SQL_HANDLE_ENV>;
template class HandleException<SQLHDBC, SQL_HANDLE_DBC>;
template class HandleException<SQLHSTMT, SQL_HANDLE_STMT>;
template class HandleException<SQLHDESC, SQL_HANDLE_DESC>;
#endif
POCO_IMPLEMENT_EXCEPTION(ODBCException, Poco::Data::DataException, "Generic ODBC error")
POCO_IMPLEMENT_EXCEPTION(InsufficientStorageException, ODBCException, "Insufficient storage error")

View File

@ -977,8 +977,11 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release_static_mt|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release_static_mt|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\FileStreamRWLock.cpp" />
<ClCompile Include="src\FileStreamRWLock_POSIX.cpp">
<ClCompile Include="src\BufferedBidirectionalStreamBuf.cpp" />
<ClCompile Include="src\BufferedStreamBuf.cpp" />
<ClCompile Include="src\UnbufferedStreamBuf.cpp" />
<ClCompile Include="src\FileStreamRWLock.cpp" />
<ClCompile Include="src\FileStreamRWLock_POSIX.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug_shared|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug_shared|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug_static_md|Win32'">true</ExcludedFromBuild>

View File

@ -1415,7 +1415,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release_static_mt|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release_static_mt|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\FileStreamRWLock.cpp" />
<ClCompile Include="src\BufferedBidirectionalStreamBuf.cpp" />
<ClCompile Include="src\BufferedStreamBuf.cpp" />
<ClCompile Include="src\UnbufferedStreamBuf.cpp" />
<ClCompile Include="src\FileStreamRWLock.cpp" />
<ClCompile Include="src\FileStreamRWLock_POSIX.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug_shared|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug_shared|x64'">true</ExcludedFromBuild>

View File

@ -34,7 +34,8 @@ objects = ArchiveStrategy Ascii ASCIIEncoding AsyncChannel AsyncNotificationCent
FileStreamFactory URIStreamFactory URIStreamOpener UTF32Encoding UTF16Encoding UTF8Encoding UTF8String \
Unicode UnicodeConverter Windows1250Encoding Windows1251Encoding Windows1252Encoding \
UUID UUIDGenerator Void Var VarHolder VarIterator VarVisitor Format Pipe PipeImpl PipeStream SharedMemory \
MemoryStream FileStream AtomicCounter DataURIStream DataURIStreamFactory FileStreamRWLock
MemoryStream FileStream AtomicCounter DataURIStream DataURIStreamFactory FileStreamRWLock \
BufferedBidirectionalStreamBuf BufferedStreamBuf UnbufferedStreamBuf
zlib_objects = adler32 compress crc32 deflate \
infback inffast inflate inftrees trees zutil

View File

@ -181,15 +181,14 @@ private:
//
// We provide an instantiation for char.
//
// Visual C++ needs a workaround - explicitly importing the template
// instantiation - to avoid duplicate symbols due to multiple
// instantiations in different libraries.
//
#if defined(_MSC_VER) && defined(POCO_DLL) && !defined(Foundation_EXPORTS)
template class Foundation_API BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
#if defined(POCO_OS_FAMILY_WINDOWS)
extern template class BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
#else
extern template class Foundation_API BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
#endif
using BufferedBidirectionalStreamBuf
= BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
using BufferedBidirectionalStreamBuf = BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
} // namespace Poco

View File

@ -160,18 +160,17 @@ private:
BasicBufferedStreamBuf& operator = (const BasicBufferedStreamBuf&);
};
//
// We provide an instantiation for char.
//
// Visual C++ needs a workaround - explicitly importing the template
// instantiation - to avoid duplicate symbols due to multiple
// instantiations in different libraries.
//
#if defined(_MSC_VER) && defined(POCO_DLL) && !defined(Foundation_EXPORTS)
template class Foundation_API BasicBufferedStreamBuf<char, std::char_traits<char>>;
#if defined(POCO_OS_FAMILY_WINDOWS)
extern template class BasicBufferedStreamBuf<char, std::char_traits<char>>;
#else
extern template class Foundation_API BasicBufferedStreamBuf<char, std::char_traits<char>>;
#endif
typedef BasicBufferedStreamBuf<char, std::char_traits<char>> BufferedStreamBuf;
using BufferedStreamBuf = BasicBufferedStreamBuf<char, std::char_traits<char>>;
} // namespace Poco

View File

@ -163,15 +163,14 @@ private:
//
// We provide an instantiation for char.
//
// Visual C++ needs a workaround - explicitly importing the template
// instantiation - to avoid duplicate symbols due to multiple
// instantiations in different libraries.
//
#if defined(_MSC_VER) && defined(POCO_DLL) && !defined(Foundation_EXPORTS)
template class Foundation_API BasicUnbufferedStreamBuf<char, std::char_traits<char>>;
#endif
typedef BasicUnbufferedStreamBuf<char, std::char_traits<char>> UnbufferedStreamBuf;
#if defined(POCO_OS_FAMILY_WINDOWS)
extern template class BasicUnbufferedStreamBuf<char, std::char_traits<char>>;
#else
extern template class Foundation_API BasicUnbufferedStreamBuf<char, std::char_traits<char>>;
#endif
using UnbufferedStreamBuf = BasicUnbufferedStreamBuf<char, std::char_traits<char>>;
} // namespace Poco

View File

@ -0,0 +1,25 @@
//
// BufferedBidirectionalStreamBuf.cpp
//
// Library: Foundation
// Package: Streams
// Module: StreamBuf
//
// Copyright (c) 2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/BufferedBidirectionalStreamBuf.h"
namespace Poco {
#if defined(POCO_OS_FAMILY_WINDOWS)
template class Foundation_API BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
#else
template class BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
#endif
}

View File

@ -0,0 +1,25 @@
//
// BufferedStreamBuf.cpp
//
// Library: Foundation
// Package: Streams
// Module: StreamBuf
//
// Copyright (c) 2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/BufferedStreamBuf.h"
namespace Poco {
#if defined(POCO_OS_FAMILY_WINDOWS)
template class Foundation_API BasicBufferedStreamBuf<char, std::char_traits<char>>;
#else
template class BasicBufferedStreamBuf<char, std::char_traits<char>>;
#endif
}

View File

@ -13,7 +13,6 @@
#include "Poco/FileStream.h"
#include "Poco/Exception.h"
#if defined(POCO_OS_FAMILY_WINDOWS)
#include "FileStream_WIN32.cpp"
#else

View File

@ -0,0 +1,25 @@
//
// UnbufferedStreamBuf.cpp
//
// Library: Foundation
// Package: Streams
// Module: StreamBuf
//
// Copyright (c) 2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/UnbufferedStreamBuf.h"
namespace Poco {
#if defined(POCO_OS_FAMILY_WINDOWS)
template class Foundation_API BasicUnbufferedStreamBuf<char, std::char_traits<char>>;
#else
template class BasicUnbufferedStreamBuf<char, std::char_traits<char>>;
#endif
}