You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2022/10/17 04:20:54 UTC
[logging-log4cxx] branch master updated: Prevent compilation errors when logchar is unichar (#142)
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
The following commit(s) were added to refs/heads/master by this push:
new 5109466a Prevent compilation errors when logchar is unichar (#142)
5109466a is described below
commit 5109466a844d1e5fb8b455a23077765a30325a24
Author: Stephen Webb <st...@ieee.org>
AuthorDate: Mon Oct 17 15:20:48 2022 +1100
Prevent compilation errors when logchar is unichar (#142)
---
src/main/cpp/logstream.cpp | 5 +++
src/main/cpp/messagebuffer.cpp | 5 +++
src/main/cpp/ndc.cpp | 4 +--
src/main/cpp/threadutility.cpp | 8 +++--
src/main/cpp/transcoder.cpp | 4 +--
src/main/include/CMakeLists.txt | 9 ++++++
.../include/log4cxx/private/log4cxx_private.h.in | 3 +-
src/test/cpp/pattern/patternparsertestcase.cpp | 6 ++--
src/test/cpp/rolling/manualrollingtest.cpp | 7 ++--
src/test/cpp/rolling/timebasedrollingtest.cpp | 37 ++++++++++------------
src/test/cpp/streamtestcase.cpp | 12 +++++--
11 files changed, 62 insertions(+), 38 deletions(-)
diff --git a/src/main/cpp/logstream.cpp b/src/main/cpp/logstream.cpp
index 29c3bcfa..a914040c 100644
--- a/src/main/cpp/logstream.cpp
+++ b/src/main/cpp/logstream.cpp
@@ -15,6 +15,11 @@
* limitations under the License.
*/
+#include <log4cxx/log4cxx.h>
+/* Prevent std::basic_streambuf etc destructor ... already defined in logstream.obj */
+#if defined(_MSC_VER) && (LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API)
+#define __FORCE_INSTANCE
+#endif
#include <log4cxx/logstring.h>
#include <log4cxx/stream.h>
#include <log4cxx/helpers/transcoder.h>
diff --git a/src/main/cpp/messagebuffer.cpp b/src/main/cpp/messagebuffer.cpp
index a551b133..5cc61598 100644
--- a/src/main/cpp/messagebuffer.cpp
+++ b/src/main/cpp/messagebuffer.cpp
@@ -15,6 +15,11 @@
* limitations under the License.
*/
+#include <log4cxx/log4cxx.h>
+/* Prevent error C2491: 'std::numpunct<_Elem>::id': definition of dllimport static data member not allowed */
+#if defined(_MSC_VER) && (LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API)
+#define __FORCE_INSTANCE
+#endif
#include <log4cxx/helpers/messagebuffer.h>
#include <log4cxx/helpers/transcoder.h>
diff --git a/src/main/cpp/ndc.cpp b/src/main/cpp/ndc.cpp
index 597f0fce..e2194ab5 100644
--- a/src/main/cpp/ndc.cpp
+++ b/src/main/cpp/ndc.cpp
@@ -327,7 +327,7 @@ bool NDC::pop(std::basic_string<UniChar>& dst)
if (!stack.empty())
{
- Transcoder::encode(stack.top().message, dst);
+ Transcoder::encode(getMessage(stack.top()), dst);
stack.pop();
data->recycle();
return true;
@@ -349,7 +349,7 @@ bool NDC::peek(std::basic_string<UniChar>& dst)
if (!stack.empty())
{
- Transcoder::encode(stack.top().message, dst);
+ Transcoder::encode(getMessage(stack.top()), dst);
return true;
}
diff --git a/src/main/cpp/threadutility.cpp b/src/main/cpp/threadutility.cpp
index c14c12fd..057ecd86 100644
--- a/src/main/cpp/threadutility.cpp
+++ b/src/main/cpp/threadutility.cpp
@@ -116,11 +116,13 @@ void ThreadUtility::threadStartedNameThread(LogString threadName,
std::thread::id /*threadId*/,
std::thread::native_handle_type nativeHandle){
#if LOG4CXX_HAS_PTHREAD_SETNAME
- if( pthread_setname_np( static_cast<pthread_t>( nativeHandle ), threadName.c_str() ) < 0 ){
- LOGLOG_ERROR( LOG4CXX_STR("unable to set thread name") );
+ LOG4CXX_ENCODE_CHAR(sthreadName, threadName);
+ if (pthread_setname_np(static_cast<pthread_t>(nativeHandle), sthreadName.c_str()) < 0) {
+ LOGLOG_ERROR(LOG4CXX_STR("unable to set thread name"));
}
#elif LOG4CXX_HAS_SETTHREADDESCRIPTION
- HRESULT hr = SetThreadDescription(static_cast<HANDLE>(nativeHandle), threadName.c_str());
+ LOG4CXX_ENCODE_WCHAR(wthreadName, threadName);
+ HRESULT hr = SetThreadDescription(static_cast<HANDLE>(nativeHandle), wthreadName.c_str());
if(FAILED(hr)){
LOGLOG_ERROR( LOG4CXX_STR("unable to set thread name") );
}
diff --git a/src/main/cpp/transcoder.cpp b/src/main/cpp/transcoder.cpp
index e3eff9a3..9b4b96b8 100644
--- a/src/main/cpp/transcoder.cpp
+++ b/src/main/cpp/transcoder.cpp
@@ -30,7 +30,7 @@
#endif
#include <log4cxx/private/log4cxx_private.h>
-#if LOG4CXX_LOGCHAR_IS_UNICHAR || LOG4CXX_CFSTRING_API || LOG4CXX_UNICHAR_API
+#if LOG4CXX_CFSTRING_API
#include <CoreFoundation/CFString.h>
#endif
@@ -651,7 +651,7 @@ CFStringRef Transcoder::encode(const LogString& src)
LOG4CXX_ENCODE_UNICHAR(tmp, src);
return CFStringCreateWithCharacters(kCFAllocatorDefault, tmp.data(), tmp.size());
}
-#endif
+#endif // #if LOG4CXX_CFSTRING_API
logchar Transcoder::decode(char val)
diff --git a/src/main/include/CMakeLists.txt b/src/main/include/CMakeLists.txt
index e31443fb..32122e41 100644
--- a/src/main/include/CMakeLists.txt
+++ b/src/main/include/CMakeLists.txt
@@ -39,9 +39,18 @@ endif()
if(${LOG4CXX_CHAR} STREQUAL "unichar")
set(LOGCHAR_IS_UNICHAR 1)
+ set(LOGCHAR_IS_WCHAR 0)
+ set(LOGCHAR_IS_UTF8 0)
elseif(${LOG4CXX_CHAR} STREQUAL "wchar_t")
set(LOGCHAR_IS_WCHAR 1)
+ set(LOGCHAR_IS_UNICHAR 0)
+ set(LOGCHAR_IS_UTF8 0)
+elseif(${LOG4CXX_CHAR} STREQUAL "utf-8")
+ set(LOGCHAR_IS_UNICHAR 0)
+ set(LOGCHAR_IS_WCHAR 0)
+ set(LOGCHAR_IS_UTF8 1)
endif()
+
option(LOG4CXX_WCHAR_T "Enable wchar_t API methods" ON)
option(LOG4CXX_UNICHAR "Enable UniChar API methods" OFF)
set(INIT_IOS_BASE 0)
diff --git a/src/main/include/log4cxx/private/log4cxx_private.h.in b/src/main/include/log4cxx/private/log4cxx_private.h.in
index 26281e07..88604f3d 100644
--- a/src/main/include/log4cxx/private/log4cxx_private.h.in
+++ b/src/main/include/log4cxx/private/log4cxx_private.h.in
@@ -35,7 +35,6 @@
#define LOG4CXX_HAS_STD_LOCALE @HAS_STD_LOCALE@
#define LOG4CXX_FORCE_WIDE_CONSOLE 0
#define LOG4CXX_FORCE_BYTE_CONSOLE 0
-#define LOG4CXX_MEMSET_IOS_BASE 0
#define LOG4CXX_HAVE_ODBC @HAS_ODBC@
#define LOG4CXX_HAS_MBSRTOWCS @HAS_MBSRTOWCS@
#define LOG4CXX_HAS_WCSTOMBS @HAS_WCSTOMBS@
@@ -71,6 +70,8 @@
#if defined(_MSC_VER)
#define LOG4CXX_MEMSET_IOS_BASE 1
+#else
+#define LOG4CXX_MEMSET_IOS_BASE 0
#endif
#endif
diff --git a/src/test/cpp/pattern/patternparsertestcase.cpp b/src/test/cpp/pattern/patternparsertestcase.cpp
index 93221b02..61f42310 100644
--- a/src/test/cpp/pattern/patternparsertestcase.cpp
+++ b/src/test/cpp/pattern/patternparsertestcase.cpp
@@ -87,11 +87,13 @@ public:
LogString threadName = LOG4CXX_STR("log4cxx-thr");
#if LOG4CXX_HAS_PTHREAD_SETNAME
- if( pthread_setname_np( pthread_self(), threadName.c_str() ) < 0 ){
+ LOG4CXX_ENCODE_CHAR(sthreadName, threadName);
+ if( pthread_setname_np( pthread_self(), sthreadName.c_str() ) < 0 ){
LOGLOG_ERROR( LOG4CXX_STR("unable to set thread name") );
}
#elif LOG4CXX_HAS_SETTHREADDESCRIPTION
- HRESULT hr = SetThreadDescription(GetCurrentThread(), threadName.c_str());
+ LOG4CXX_ENCODE_WCHAR(wthreadName, threadName);
+ HRESULT hr = SetThreadDescription(GetCurrentThread(), wthreadName.c_str());
if(FAILED(hr)){
LOGLOG_ERROR( LOG4CXX_STR("unable to set thread name") );
}
diff --git a/src/test/cpp/rolling/manualrollingtest.cpp b/src/test/cpp/rolling/manualrollingtest.cpp
index 13d5a925..9223ece5 100644
--- a/src/test/cpp/rolling/manualrollingtest.cpp
+++ b/src/test/cpp/rolling/manualrollingtest.cpp
@@ -328,11 +328,8 @@ public:
std::uniform_int_distribution<std::mt19937::result_type> dist(1,100000);
LogString filenamePattern = LOG4CXX_STR("output/directory-");
-#if LOG4CXX_LOGCHAR_IS_WCHAR
- LogString dirNumber = std::to_wstring(dist(rng));
-#else
- LogString dirNumber = std::to_string(dist(rng));
-#endif
+ LogString dirNumber;
+ StringHelper::toString(dist(rng), dirNumber);
filenamePattern.append( dirNumber );
LogString filenamePatternPrefix = filenamePattern;
diff --git a/src/test/cpp/rolling/timebasedrollingtest.cpp b/src/test/cpp/rolling/timebasedrollingtest.cpp
index 7825d947..9225d458 100644
--- a/src/test/cpp/rolling/timebasedrollingtest.cpp
+++ b/src/test/cpp/rolling/timebasedrollingtest.cpp
@@ -119,7 +119,7 @@ private:
template<size_t N>
void buildTsFnames(
Pool& pool,
- const logchar* prefix,
+ const LogString& prefix,
LogString (&fnames)[N],
bool compressed = false,
bool startInFuture = false)
@@ -227,7 +227,7 @@ private:
*/
void compareWitness(
Pool& pool,
- const logchar* prefix,
+ const LogString& prefix,
const LogString& fname,
size_t witnessIdx,
size_t srcLine)
@@ -255,7 +255,7 @@ private:
template<size_t N>
void compareWitnesses(
Pool& pool,
- const logchar* prefix,
+ const LogString& prefix,
LogString (&fnames)[N],
size_t srcLine)
{
@@ -284,7 +284,7 @@ private:
template<size_t N>
void checkFilesExist(
Pool& pool,
- const logchar* prefix,
+ const LogString& prefix,
LogString (&fnames)[N],
size_t witnessIdx,
size_t srcLine)
@@ -406,10 +406,10 @@ public:
rfa->activateOptions(pool);
logger->addAppender(rfa);
- this->buildTsFnames(pool, LOG4CXX_STR("test1-"), fnames);
+ this->buildTsFnames<4>(pool, LOG4CXX_STR("test1-"), fnames);
this->delayUntilNextSecondWithMsg();
this->logMsgAndSleep( pool, nrOfFnames + 1, __LOG4CXX_FUNC__, __LINE__);
- this->compareWitnesses( pool, LOG4CXX_STR("test1."), fnames, __LINE__);
+ this->compareWitnesses<4>( pool, LOG4CXX_STR("test1."), fnames, __LINE__);
}
@@ -434,7 +434,7 @@ public:
rfa1->activateOptions(pool);
logger->addAppender(rfa1);
- this->buildTsFnames(pool, LOG4CXX_STR("test2-"), fnames);
+ this->buildTsFnames<4>(pool, LOG4CXX_STR("test2-"), fnames);
this->delayUntilNextSecondWithMsg();
this->logMsgAndSleep(pool, 3, __LOG4CXX_FUNC__, __LINE__);
@@ -454,7 +454,7 @@ public:
logger->addAppender(rfa2);
this->logMsgAndSleep( pool, 2, __LOG4CXX_FUNC__, __LINE__, 3);
- this->compareWitnesses( pool, LOG4CXX_STR("test2."), fnames, __LINE__);
+ this->compareWitnesses<4>( pool, LOG4CXX_STR("test2."), fnames, __LINE__);
}
@@ -479,11 +479,11 @@ public:
rfa->activateOptions(pool);
logger->addAppender(rfa);
- this->buildTsFnames(pool, LOG4CXX_STR("test3-"), fnames, true);
+ this->buildTsFnames<4>(pool, LOG4CXX_STR("test3-"), fnames, true);
fnames[nrOfFnames - 1].resize(fnames[nrOfFnames - 1].size() - 3);
this->delayUntilNextSecondWithMsg();
this->logMsgAndSleep( pool, nrOfFnames + 1, __LOG4CXX_FUNC__, __LINE__);
- this->checkFilesExist( pool, LOG4CXX_STR("test3."), fnames, nrOfFnames - 1, __LINE__);
+ this->checkFilesExist<4>( pool, LOG4CXX_STR("test3."), fnames, nrOfFnames - 1, __LINE__);
}
/**
@@ -513,7 +513,7 @@ public:
logger->addAppender(rfa1);
this->delGenericLogFile(pool, rfa1->getFile());
- this->buildTsFnames(pool, LOG4CXX_STR("test4-"), fnames);
+ this->buildTsFnames<4>(pool, LOG4CXX_STR("test4-"), fnames);
fnames[0].assign(rfa1->getFile());
this->delayUntilNextSecondWithMsg();
this->logMsgAndSleep(pool, nrOfLogMsgs, __LOG4CXX_FUNC__, __LINE__);
@@ -567,12 +567,12 @@ public:
logger->addAppender(rfa);
this->delGenericLogFile(pool, rfa->getFile());
- this->buildTsFnames(pool, LOG4CXX_STR("test5-"), fnames);
+ this->buildTsFnames<4>(pool, LOG4CXX_STR("test5-"), fnames);
fnames[0].assign(rfa->getFile());
this->delayUntilNextSecondWithMsg();
this->logMsgAndSleep( pool, nrOfLogMsgs, __LOG4CXX_FUNC__, __LINE__);
- this->compareWitnesses( pool, LOG4CXX_STR("test5."), fnames, __LINE__);
+ this->compareWitnesses<4>( pool, LOG4CXX_STR("test5."), fnames, __LINE__);
}
/**
@@ -599,7 +599,7 @@ public:
logger->addAppender(rfa);
this->delGenericLogFile(pool, rfa->getFile());
- this->buildTsFnames(pool, LOG4CXX_STR("test6-"), fnames, true);
+ this->buildTsFnames<4>(pool, LOG4CXX_STR("test6-"), fnames, true);
fnames[0].assign(rfa->getFile());
this->delayUntilNextSecondWithMsg();
@@ -655,11 +655,8 @@ public:
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist(1,100000);
LogString filenamePattern = LOG4CXX_STR("" DIR_PRE_OUTPUT);
-#if LOG4CXX_LOGCHAR_IS_WCHAR
- LogString dirNumber = std::to_wstring(dist(rng));
-#else
- LogString dirNumber = std::to_string(dist(rng));
-#endif
+ LogString dirNumber;
+ StringHelper::toString(dist(rng), dirNumber);
LogString directoryName = LOG4CXX_STR("tbr-rollIntoDir-");
directoryName.append( dirNumber );
filenamePattern.append( directoryName );
@@ -676,7 +673,7 @@ public:
const logchar* prefix = directoryName.append(LOG4CXX_STR("/file-")).data();
this->delGenericLogFile(pool, rfa->getFile());
- this->buildTsFnames(pool, prefix, fnames);
+ this->buildTsFnames<4>(pool, prefix, fnames);
fnames[0].assign(rfa->getFile());
this->delayUntilNextSecondWithMsg();
diff --git a/src/test/cpp/streamtestcase.cpp b/src/test/cpp/streamtestcase.cpp
index 6f7267c5..e89d7192 100644
--- a/src/test/cpp/streamtestcase.cpp
+++ b/src/test/cpp/streamtestcase.cpp
@@ -14,6 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#include <log4cxx/log4cxx.h>
+ /* Prevent error C2491: 'std::numpunct<_Elem>::id': definition of dllimport static data member not allowed */
+#if defined(_MSC_VER) && (LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API)
+#define __FORCE_INSTANCE
+#endif
#include <ostream>
#include <iomanip>
@@ -475,7 +481,7 @@ public:
{
LoggerPtr root(Logger::getRootLogger());
const log4cxx::UniChar msg[] = { 'T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 't', 'e', 's', 't', 0 };
- LOG4CXX_INFO(root, msg)
+ LOG4CXX_INFO(root, msg);
LOGUNIT_ASSERT_EQUAL((size_t) 1, vectorAppender->getVector().size());
}
@@ -484,7 +490,7 @@ public:
LoggerPtr root(Logger::getRootLogger());
const log4cxx::UniChar msg1[] = { 'T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 't', 'e', 's', 't', 0 };
const log4cxx::UniChar msg2[] = { ':', ' ', 'D', 'e', 't', 'a', 'i', 'l', 's', ' ', 't', 'o', ' ', 'f', 'o', 'l', 'l', 'o', 'w', 0 };
- LOG4CXX_INFO(root, msg1 << msg2)
+ LOG4CXX_INFO(root, msg1 << msg2);
LOGUNIT_ASSERT_EQUAL((size_t) 1, vectorAppender->getVector().size());
}
@@ -493,7 +499,7 @@ public:
LoggerPtr root(Logger::getRootLogger());
const log4cxx::UniChar openBracket[] = { '[', 0 };
const log4cxx::UniChar closeBracket[] = { ']', 0 };
- LOG4CXX_INFO(root, openBracket << std::fixed << std::setprecision(2) << std::setw(7) << std::right << std::setfill((log4cxx::UniChar) '_') << 10.0 << closeBracket)
+ LOG4CXX_INFO(root, openBracket << std::fixed << std::setprecision(2) << std::setw(7) << std::right << std::setfill((log4cxx::UniChar)'_') << 10.0 << closeBracket);
spi::LoggingEventPtr event(vectorAppender->getVector()[0]);
LogString msg(event->getMessage());
LOGUNIT_ASSERT_EQUAL(LogString(LOG4CXX_STR("[__10.00]")), msg);