Skip to content

Commit

Permalink
fix(templates): Corrected explicit template instantiations to avoid m…
Browse files Browse the repository at this point in the history
…ultiple instances.
  • Loading branch information
matejk committed Jan 14, 2025
1 parent 7297033 commit daf19e5
Show file tree
Hide file tree
Showing 22 changed files with 283 additions and 46 deletions.
3 changes: 2 additions & 1 deletion Data/ODBC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions Data/ODBC/ODBC_VS90.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
Expand Down
12 changes: 11 additions & 1 deletion Data/ODBC/ODBC_vs160.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 7 additions & 1 deletion Data/ODBC/ODBC_vs160.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -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>
14 changes: 12 additions & 2 deletions Data/ODBC/ODBC_vs170.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -1039,4 +1049,4 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>
</Project>
8 changes: 7 additions & 1 deletion Data/ODBC/ODBC_vs170.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -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>
18 changes: 14 additions & 4 deletions Data/ODBC/include/Poco/Data/ODBC/Diagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -243,10 +244,19 @@ class Diagnostics

// 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


Expand Down
16 changes: 12 additions & 4 deletions Data/ODBC/include/Poco/Data/ODBC/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,20 @@ class Error

// 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>;
Expand Down
17 changes: 13 additions & 4 deletions Data/ODBC/include/Poco/Data/ODBC/ODBCException.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,19 @@ class HandleException: public ODBCException

// 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


Expand Down
40 changes: 40 additions & 0 deletions Data/ODBC/src/Diagnostics.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 40 additions & 0 deletions Data/ODBC/src/Error.cpp
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions Data/ODBC/src/ODBCException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 5 additions & 2 deletions Foundation/Foundation_vs160.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 4 additions & 1 deletion Foundation/Foundation_vs170.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion Foundation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions Foundation/include/Poco/BufferedBidirectionalStreamBuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,14 @@ class BasicBufferedBidirectionalStreamBuf: public std::basic_streambuf<ch, tr>
//
// 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

Expand Down
15 changes: 7 additions & 8 deletions Foundation/include/Poco/BufferedStreamBuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,17 @@ class BasicBufferedStreamBuf: public std::basic_streambuf<ch, tr>
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
Expand Down
13 changes: 6 additions & 7 deletions Foundation/include/Poco/UnbufferedStreamBuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,14 @@ class BasicUnbufferedStreamBuf: public std::basic_streambuf<ch, tr>
//
// 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>>;

#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
typedef BasicUnbufferedStreamBuf<char, std::char_traits<char>> UnbufferedStreamBuf;

using UnbufferedStreamBuf = BasicUnbufferedStreamBuf<char, std::char_traits<char>>;

} // namespace Poco

Expand Down
Loading

0 comments on commit daf19e5

Please sign in to comment.