This is an automated email from the ASF dual-hosted git repository. swebb2066 pushed a commit to branch simplify_transcoder in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit b33838f397940993b7fa497889cc762e7e1cfc5e Author: Stephen Webb <[email protected]> AuthorDate: Tue May 26 16:44:12 2026 +1000 Simplify the Transcoder interface in the next ABI version --- src/main/cpp/file.cpp | 61 +++++++++++++++------------ src/main/cpp/gzcompressaction.cpp | 5 +-- src/main/cpp/transcoder.cpp | 6 ++- src/main/cpp/zipcompressaction.cpp | 7 ++- src/main/include/log4cxx/helpers/transcoder.h | 9 +++- src/test/cpp/util/transformer.cpp | 2 +- 6 files changed, 51 insertions(+), 39 deletions(-) diff --git a/src/main/cpp/file.cpp b/src/main/cpp/file.cpp index 93756a6f..27dd1d5c 100644 --- a/src/main/cpp/file.cpp +++ b/src/main/cpp/file.cpp @@ -29,23 +29,31 @@ using namespace LOG4CXX_NS::helpers; struct File::FilePrivate{ FilePrivate() - {} + { + set_apr_path(); + } FilePrivate(const LogString& path) : path(path) - {} + { + set_apr_path(); + } FilePrivate(const LogString& path, bool autoDelete) : path(path) , autoDelete(autoDelete) - {} + { + set_apr_path(); + } LogString path; bool autoDelete{ false }; Pool p; - char* apr_path{ nullptr }; - char* getPath(); - static char* convertBackSlashes(char*); + const char* apr_path{ nullptr }; + std::string encodedPath; + + const char* getPath() const; + void set_apr_path(); }; File::File() : @@ -130,7 +138,7 @@ File& File::operator=(const File& src) m_priv->path.assign(src.m_priv->path); m_priv->autoDelete = src.m_priv->autoDelete; - + m_priv->set_apr_path(); return *this; } @@ -151,7 +159,7 @@ LogString File::getPath() const File& File::setPath(const LogString& newName) { m_priv->path.assign(newName); - m_priv->apr_path = nullptr; + m_priv->set_apr_path(); return *this; } @@ -168,23 +176,33 @@ LogString File::getName() const return m_priv->path; } -char* File::FilePrivate::getPath() +const char* File::FilePrivate::getPath() const +{ + return this->apr_path; +} + +void File::FilePrivate::set_apr_path() { - if (this->apr_path) - return this->apr_path; + this->encodedPath.clear(); int style = APR_FILEPATH_ENCODING_UNKNOWN; apr_filepath_encoding(&style, this->p.getAPRPool()); - if (style == APR_FILEPATH_ENCODING_UTF8) { - this->apr_path = Transcoder::encodeUTF8(this->path, this->p); + Transcoder::encodeUTF8(this->path, this->encodedPath); } else { - this->apr_path = Transcoder::encode(this->path, this->p); + Transcoder::encode(this->path, this->encodedPath); } - return convertBackSlashes(this->apr_path); + for (auto& c : this->encodedPath) + { + if (c == '\\') + { + c = '/'; + } + } + this->apr_path = this->encodedPath.c_str(); } const char* File::getAPRPath() const @@ -206,19 +224,6 @@ bool File::exists() const return rv == APR_SUCCESS; } -char* File::FilePrivate::convertBackSlashes(char* src) -{ - for (char* c = src; *c != 0; c++) - { - if (*c == '\\') - { - *c = '/'; - } - } - - return src; -} - bool File::deleteFile() const { apr_status_t rv = apr_file_remove(m_priv->getPath(), m_priv->p.getAPRPool()); diff --git a/src/main/cpp/gzcompressaction.cpp b/src/main/cpp/gzcompressaction.cpp index 83e51025..e43c1b8b 100644 --- a/src/main/cpp/gzcompressaction.cpp +++ b/src/main/cpp/gzcompressaction.cpp @@ -126,12 +126,11 @@ bool GZCompressAction::execute( LOG4CXX_EXECUTE_ACTION_FORMAL_PARAMETERS ) const priv->destination.setAutoDelete(true); - const char** args = (const char**) - apr_palloc(aprpool, 4 * sizeof(*args)); + const char* args[4]; int i = 0; args[i++] = "gzip"; args[i++] = "-c"; - args[i++] = Transcoder::encode(priv->source.getPath(), tempPool); + args[i++] = priv->source.getAPRPath(); args[i++] = NULL; apr_proc_t pid; diff --git a/src/main/cpp/transcoder.cpp b/src/main/cpp/transcoder.cpp index de0deadf..fb646958 100644 --- a/src/main/cpp/transcoder.cpp +++ b/src/main/cpp/transcoder.cpp @@ -85,6 +85,7 @@ void Transcoder::encodeUTF8(const LogString& src, std::string& dst) #endif } +#if LOG4CXX_ABI_VERSION <= 15 char* Transcoder::encodeUTF8(const LogString& src, Pool& p) { #if LOG4CXX_LOGCHAR_IS_UTF8 @@ -95,7 +96,7 @@ char* Transcoder::encodeUTF8(const LogString& src, Pool& p) return p.pstrdup(tmp); #endif } - +#endif void Transcoder::encodeUTF8(unsigned int sv, ByteBuffer& dst) { @@ -360,6 +361,7 @@ void Transcoder::decode(const std::string& src, LogString& dst) #endif } +#if LOG4CXX_ABI_VERSION <= 15 char* Transcoder::encode(const LogString& src, Pool& p) { #if LOG4CXX_CHARSET_UTF8 && LOG4CXX_LOGCHAR_IS_UTF8 @@ -370,7 +372,7 @@ char* Transcoder::encode(const LogString& src, Pool& p) return p.pstrdup(tmp); #endif } - +#endif void Transcoder::encode(const LogString& src, std::string& dst) diff --git a/src/main/cpp/zipcompressaction.cpp b/src/main/cpp/zipcompressaction.cpp index 5ef69a37..2685ad21 100644 --- a/src/main/cpp/zipcompressaction.cpp +++ b/src/main/cpp/zipcompressaction.cpp @@ -104,14 +104,13 @@ bool ZipCompressAction::execute( LOG4CXX_EXECUTE_ACTION_FORMAL_PARAMETERS ) cons } } - const char** args = (const char**) - apr_palloc(aprpool, 5 * sizeof(*args)); + const char* args[5]; int i = 0; args[i++] = "zip"; args[i++] = "-q"; - args[i++] = Transcoder::encode(priv->destination.getPath(), tempPool); - args[i++] = Transcoder::encode(priv->source.getPath(), tempPool); + args[i++] = priv->destination.getAPRPath(); + args[i++] = priv->source.getAPRPath(); args[i++] = NULL; if (priv->destination.exists()) diff --git a/src/main/include/log4cxx/helpers/transcoder.h b/src/main/include/log4cxx/helpers/transcoder.h index 20894283..9907ede0 100644 --- a/src/main/include/log4cxx/helpers/transcoder.h +++ b/src/main/include/log4cxx/helpers/transcoder.h @@ -46,10 +46,14 @@ class LOG4CXX_EXPORT Transcoder * Converts the LogString to a UTF-8 string. */ static void encodeUTF8(const LogString& src, std::string& dst); +#if LOG4CXX_ABI_VERSION <= 15 /** * Converts the LogString to a UTF-8 string. + * @deprecated This function is deprecated and will be removed in a future version. */ + [[ deprecated( "Use the encodeUTF8() without a Pool parameter" ) ]] static char* encodeUTF8(const LogString& src, LOG4CXX_NS::helpers::Pool& p); +#endif /** * Append UCS-4 code point to a byte buffer as UTF-8. */ @@ -94,15 +98,18 @@ class LOG4CXX_EXPORT Transcoder */ static void encode(const LogString& src, std::string& dst); +#if LOG4CXX_ABI_VERSION <= 15 /** * Encodes the specified LogString to the current * character set. + * @deprecated This function is deprecated and will be removed in a future version. * @param src string to encode. * @param p pool from which to allocate return value. * @return pool allocated string. */ + [[ deprecated( "Use an encode() without a Pool parameter" ) ]] static char* encode(const LogString& src, LOG4CXX_NS::helpers::Pool& p); - +#endif #if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR || defined(WIN32) || defined(_WIN32) diff --git a/src/test/cpp/util/transformer.cpp b/src/test/cpp/util/transformer.cpp index 526d2f45..d733774b 100644 --- a/src/test/cpp/util/transformer.cpp +++ b/src/test/cpp/util/transformer.cpp @@ -210,7 +210,7 @@ void Transformer::transform(const File& in, const File& out, // // specify the input file - args[i++] = Transcoder::encode(in.getPath(), p); + args[i++] = in.getAPRPath(); args[i] = NULL;
