From b6183866b045b077e0eb6c5a2c5d65ccf77d1d5d Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 20 Jan 2026 01:44:57 +0100 Subject: [PATCH 1/3] Allow directly feeding generate() return value to another function The use of the `const` keyword for many a member functions precludes the use of `f(g())`, requiring to cumbersomly write auto v = g(); f(std::move(v)); --- src/vmime/component.cpp | 2 +- src/vmime/component.hpp | 2 +- src/vmime/message.cpp | 2 +- src/vmime/message.hpp | 2 +- tests/parser/mailboxTest.cpp | 8 ++++++++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/vmime/component.cpp b/src/vmime/component.cpp index 99c06548..e5e0370e 100644 --- a/src/vmime/component.cpp +++ b/src/vmime/component.cpp @@ -200,7 +200,7 @@ void component::parseImpl( } -const string component::generate( +string component::generate( const size_t maxLineLength, const size_t curLinePos ) const { diff --git a/src/vmime/component.hpp b/src/vmime/component.hpp index 40f87ff0..59acee0d 100644 --- a/src/vmime/component.hpp +++ b/src/vmime/component.hpp @@ -144,7 +144,7 @@ class VMIME_EXPORT component : public object { * @param curLinePos length of the current line in the output buffer * @return generated data */ - virtual const string generate( + virtual string generate( const size_t maxLineLength = lineLengthLimits::infinite, const size_t curLinePos = 0 ) const; diff --git a/src/vmime/message.cpp b/src/vmime/message.cpp index f034cdb5..9e6956d7 100644 --- a/src/vmime/message.cpp +++ b/src/vmime/message.cpp @@ -36,7 +36,7 @@ message::message() { } -const string message::generate( +string message::generate( const size_t maxLineLength, const size_t curLinePos ) const { diff --git a/src/vmime/message.hpp b/src/vmime/message.hpp index 1b97a5d7..53bc095a 100644 --- a/src/vmime/message.hpp +++ b/src/vmime/message.hpp @@ -47,7 +47,7 @@ class VMIME_EXPORT message : public bodyPart { // Override default generate() functions so that we can change // the default 'maxLineLength' value - const string generate( + string generate( const size_t maxLineLength = generationContext::getDefaultContext().getMaxLineLength(), const size_t curLinePos = 0 ) const; diff --git a/tests/parser/mailboxTest.cpp b/tests/parser/mailboxTest.cpp index d1af23f2..19d5bf95 100644 --- a/tests/parser/mailboxTest.cpp +++ b/tests/parser/mailboxTest.cpp @@ -194,4 +194,12 @@ VMIME_TEST_SUITE_BEGIN(mailboxTest) } + void testAPI() { + + auto take_string_directly = [](vmime::string &&) {}; + vmime::mailbox m; + take_string_directly(m.generate()); + + } + VMIME_TEST_SUITE_END From 38329e697637d3c10d7560d9562e9b025f7f1345 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 24 Mar 2026 00:19:51 +0100 Subject: [PATCH 2/3] Switch getThreadId to return unsigned long Some threading implementations are lightweight/do not have a corresponding PID-like identifier for them, but only a memory handle. This necessitates using a type that is a typical register wide. --- src/vmime/platform.hpp | 2 +- src/vmime/platforms/posix/posixHandler.cpp | 12 ++++++------ src/vmime/platforms/posix/posixHandler.hpp | 2 +- src/vmime/platforms/windows/windowsHandler.cpp | 4 ++-- src/vmime/platforms/windows/windowsHandler.hpp | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/vmime/platform.hpp b/src/vmime/platform.hpp index 03a7b234..97cab134 100644 --- a/src/vmime/platform.hpp +++ b/src/vmime/platform.hpp @@ -93,7 +93,7 @@ class VMIME_EXPORT platform { * * @return current thread id */ - virtual unsigned int getThreadId() const = 0; + virtual uintptr_t getThreadId() const = 0; /** Return the charset used on the system. * diff --git a/src/vmime/platforms/posix/posixHandler.cpp b/src/vmime/platforms/posix/posixHandler.cpp index db9c658a..b4d20e06 100644 --- a/src/vmime/platforms/posix/posixHandler.cpp +++ b/src/vmime/platforms/posix/posixHandler.cpp @@ -225,20 +225,20 @@ unsigned int posixHandler::getProcessId() const { } -unsigned int posixHandler::getThreadId() const { +uintptr_t posixHandler::getThreadId() const { #if VMIME_HAVE_GETTID - return static_cast (::gettid()); + return ::gettid(); #elif VMIME_HAVE_SYSCALL && VMIME_HAVE_SYSCALL_GETTID - return static_cast (::syscall(SYS_gettid)); + return ::syscall(SYS_gettid); #elif VMIME_HAVE_GETTHRID // OpenBSD - return static_cast (::getthrid()); + return ::getthrid(); #elif VMIME_HAVE_THR_SELF // FreeBSD long id = 0; ::thr_self(&id); - return static_cast (id); + return id; #elif VMIME_HAVE_LWP_SELF // Solaris - return static_cast (::_lwp_self()); + return ::_lwp_self(); #else #error We have no implementation of getThreadId() for this platform! #endif diff --git a/src/vmime/platforms/posix/posixHandler.hpp b/src/vmime/platforms/posix/posixHandler.hpp index 30417f17..1f124c93 100644 --- a/src/vmime/platforms/posix/posixHandler.hpp +++ b/src/vmime/platforms/posix/posixHandler.hpp @@ -64,7 +64,7 @@ class VMIME_EXPORT posixHandler : public vmime::platform::handler { const vmime::string getHostName() const; unsigned int getProcessId() const; - unsigned int getThreadId() const; + uintptr_t getThreadId() const; #if VMIME_HAVE_MESSAGING_FEATURES shared_ptr getSocketFactory(); diff --git a/src/vmime/platforms/windows/windowsHandler.cpp b/src/vmime/platforms/windows/windowsHandler.cpp index 551f6726..f2409402 100644 --- a/src/vmime/platforms/windows/windowsHandler.cpp +++ b/src/vmime/platforms/windows/windowsHandler.cpp @@ -258,9 +258,9 @@ unsigned int windowsHandler::getProcessId() const { } -unsigned int windowsHandler::getThreadId() const { +uintptr_t windowsHandler::getThreadId() const { - return static_cast (::GetCurrentThreadId()); + return ::GetCurrentThreadId(); } diff --git a/src/vmime/platforms/windows/windowsHandler.hpp b/src/vmime/platforms/windows/windowsHandler.hpp index 9dda256c..a5db52d9 100644 --- a/src/vmime/platforms/windows/windowsHandler.hpp +++ b/src/vmime/platforms/windows/windowsHandler.hpp @@ -63,7 +63,7 @@ class VMIME_EXPORT windowsHandler : public vmime::platform::handler { const vmime::string getHostName() const; unsigned int getProcessId() const; - unsigned int getThreadId() const; + uintptr_t getThreadId() const; #if VMIME_HAVE_MESSAGING_FEATURES shared_ptr getSocketFactory(); From 216be784de41d8e750ac5f3ef54f3b97919c620c Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 24 Mar 2026 00:27:20 +0100 Subject: [PATCH 3/3] Provide a generic implementation for getThreadId() on POSIX --- src/vmime/platforms/posix/posixHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vmime/platforms/posix/posixHandler.cpp b/src/vmime/platforms/posix/posixHandler.cpp index b4d20e06..df1cdc68 100644 --- a/src/vmime/platforms/posix/posixHandler.cpp +++ b/src/vmime/platforms/posix/posixHandler.cpp @@ -240,7 +240,7 @@ uintptr_t posixHandler::getThreadId() const { #elif VMIME_HAVE_LWP_SELF // Solaris return ::_lwp_self(); #else - #error We have no implementation of getThreadId() for this platform! + return (uintptr_t) pthread_self(); #endif }