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 eebcb0aa Use size_t for DatagramPacket length and offset in the next 
ABI version (#696)
eebcb0aa is described below

commit eebcb0aa14bc352010b5df4b9cef43ef4acfb2f6
Author: jmestwa-coder <[email protected]>
AuthorDate: Thu Jun 11 06:30:45 2026 +0530

    Use size_t for DatagramPacket length and offset in the next ABI version 
(#696)
---
 src/main/cpp/datagrampacket.cpp                   | 37 +++++++++++++--------
 src/main/include/log4cxx/helpers/datagrampacket.h | 40 +++++++++++++++++++++++
 2 files changed, 63 insertions(+), 14 deletions(-)

diff --git a/src/main/cpp/datagrampacket.cpp b/src/main/cpp/datagrampacket.cpp
index 4482e99f..7d5eb9d0 100644
--- a/src/main/cpp/datagrampacket.cpp
+++ b/src/main/cpp/datagrampacket.cpp
@@ -20,25 +20,34 @@
 
 using namespace LOG4CXX_NS::helpers;
 
+namespace
+{
+#if LOG4CXX_ABI_VERSION <= 15
+using PacketSizeType = int;
+#else
+using PacketSizeType = std::size_t;
+#endif
+}
+
 struct DatagramPacket::DatagramPacketPriv
 {
-       DatagramPacketPriv(void* buf1, int length1)
+       DatagramPacketPriv(void* buf1, PacketSizeType length1)
                : buf(buf1), offset(0), length(length1), address(), port(0)
        {
        }
 
-       DatagramPacketPriv(void* buf1, int length1, InetAddressPtr address1,
+       DatagramPacketPriv(void* buf1, PacketSizeType length1, InetAddressPtr 
address1,
                int port1)
                : buf(buf1), offset(0), length(length1), address(address1), 
port(port1)
        {
        }
 
-       DatagramPacketPriv(void* buf1, int offset1, int length1)
+       DatagramPacketPriv(void* buf1, PacketSizeType offset1, PacketSizeType 
length1)
                : buf(buf1), offset(offset1), length(length1), address(), 
port(0)
        {
        }
 
-       DatagramPacketPriv(void* buf1, int offset1, int length1,
+       DatagramPacketPriv(void* buf1, PacketSizeType offset1, PacketSizeType 
length1,
                InetAddressPtr address1, int port1)
                : buf(buf1), offset(offset1), length(length1), 
address(address1), port(port1)
        {
@@ -48,10 +57,10 @@ struct DatagramPacket::DatagramPacketPriv
        void* buf;
 
        /** The offset of the data for this packet. */
-       int offset;
+       PacketSizeType offset;
 
        /** The length of the data for this packet. */
-       int length;
+       PacketSizeType length;
 
        /** The IP address for this packet. */
        InetAddressPtr address;
@@ -64,7 +73,7 @@ IMPLEMENT_LOG4CXX_OBJECT(DatagramPacket)
 
 /** Constructs a DatagramPacket for receiving packets of length
 <code>length</code>. */
-DatagramPacket::DatagramPacket(void* buf1, int length1)
+DatagramPacket::DatagramPacket(void* buf1, PacketSizeType length1)
        : m_priv(std::make_unique<DatagramPacketPriv>(buf1, length1))
 {
 }
@@ -72,7 +81,7 @@ DatagramPacket::DatagramPacket(void* buf1, int length1)
 /** Constructs a datagram packet for sending packets of length
 <code>length/<code> to the specified port number on the specified
 host. */
-DatagramPacket::DatagramPacket(void* buf1, int length1, InetAddressPtr 
address1,
+DatagramPacket::DatagramPacket(void* buf1, PacketSizeType length1, 
InetAddressPtr address1,
        int port1)
        : m_priv(std::make_unique<DatagramPacketPriv>(buf1, length1, address1, 
port1))
 {
@@ -80,14 +89,14 @@ DatagramPacket::DatagramPacket(void* buf1, int length1, 
InetAddressPtr address1,
 
 /** Constructs a DatagramPacket for receiving packets of length
 <code>length</code>, specifying an offset into the buffer. */
-DatagramPacket::DatagramPacket(void* buf1, int offset1, int length1)
+DatagramPacket::DatagramPacket(void* buf1, PacketSizeType offset1, 
PacketSizeType length1)
        : m_priv(std::make_unique<DatagramPacketPriv>(buf1, offset1, length1))
 {
 }
 /** Constructs a datagram packet for sending packets of length
 <code>length</code> with offset <code>offset</code> to the
 specified port number on the specified host. */
-DatagramPacket::DatagramPacket(void* buf1, int offset1, int length1,
+DatagramPacket::DatagramPacket(void* buf1, PacketSizeType offset1, 
PacketSizeType length1,
        InetAddressPtr address1, int port1)
        : m_priv(std::make_unique<DatagramPacketPriv>(buf1, offset1, length1, 
address1, port1))
 {
@@ -107,12 +116,12 @@ void* DatagramPacket::getData() const
        return m_priv->buf;
 }
 
-int DatagramPacket::getLength() const
+PacketSizeType DatagramPacket::getLength() const
 {
        return m_priv->length;
 }
 
-int DatagramPacket::getOffset() const
+PacketSizeType DatagramPacket::getOffset() const
 {
        return m_priv->offset;
 }
@@ -132,14 +141,14 @@ void DatagramPacket::setData(void* buf1)
        m_priv->buf = buf1;
 }
 
-void DatagramPacket::setData(void* buf1, int offset1, int length1)
+void DatagramPacket::setData(void* buf1, PacketSizeType offset1, 
PacketSizeType length1)
 {
        m_priv->buf = buf1;
        m_priv->offset = offset1;
        m_priv->length = length1;
 }
 
-void DatagramPacket::setLength(int length1)
+void DatagramPacket::setLength(PacketSizeType length1)
 {
        m_priv->length = length1;
 }
diff --git a/src/main/include/log4cxx/helpers/datagrampacket.h 
b/src/main/include/log4cxx/helpers/datagrampacket.h
index 92918f5c..ee151941 100644
--- a/src/main/include/log4cxx/helpers/datagrampacket.h
+++ b/src/main/include/log4cxx/helpers/datagrampacket.h
@@ -20,6 +20,7 @@
 
 #include <log4cxx/helpers/object.h>
 #include <log4cxx/helpers/inetaddress.h>
+#include <cstddef>
 
 namespace LOG4CXX_NS
 {
@@ -44,6 +45,7 @@ class LOG4CXX_EXPORT DatagramPacket : public helpers::Object
                LOG4CXX_CAST_ENTRY(DatagramPacket)
                END_LOG4CXX_CAST_MAP()
 
+#if LOG4CXX_ABI_VERSION <= 15
                /** Constructs a DatagramPacket for receiving packets of length
                <code>length</code>. */
                DatagramPacket(void* buf, int length);
@@ -62,6 +64,26 @@ class LOG4CXX_EXPORT DatagramPacket : public helpers::Object
                specified port number on the specified host. */
                DatagramPacket(void* buf, int offset, int length, 
InetAddressPtr address,
                        int port);
+#else
+               /** Constructs a DatagramPacket for receiving packets of length
+               <code>length</code>. */
+               DatagramPacket(void* buf, std::size_t length);
+
+               /** Constructs a datagram packet for sending packets of length
+               <code>length</code> to the specified port number on the 
specified
+               host. */
+               DatagramPacket(void* buf, std::size_t length, InetAddressPtr 
address, int port);
+
+               /** Constructs a DatagramPacket for receiving packets of length
+               <code>length</code>, specifying an offset into the buffer. */
+               DatagramPacket(void* buf, std::size_t offset, std::size_t 
length);
+
+               /** Constructs a datagram packet for sending packets of length
+               <code>length</code> with offset <code>offset</code> to the
+               specified port number on the specified host. */
+               DatagramPacket(void* buf, std::size_t offset, std::size_t 
length, InetAddressPtr address,
+                       int port);
+#endif
 
                ~DatagramPacket();
 
@@ -72,6 +94,7 @@ class LOG4CXX_EXPORT DatagramPacket : public helpers::Object
                /** Returns the data received or the data to be sent. */
                void* getData() const;
 
+#if LOG4CXX_ABI_VERSION <= 15
                /** Returns the length of the data to be sent or the length of 
the
                data received. */
                int getLength() const;
@@ -79,6 +102,15 @@ class LOG4CXX_EXPORT DatagramPacket : public helpers::Object
                /** Returns the offset of the data to be sent or the offset of 
the
                data received. */
                int getOffset() const;
+#else
+               /** Returns the length of the data to be sent or the length of 
the
+               data received. */
+               std::size_t getLength() const;
+
+               /** Returns the offset of the data to be sent or the offset of 
the
+               data received. */
+               std::size_t getOffset() const;
+#endif
 
                /** Returns the port number on the remote host to which this
                 datagram is being sent or from which the datagram was 
received. */
@@ -89,11 +121,19 @@ class LOG4CXX_EXPORT DatagramPacket : public 
helpers::Object
                /** Set the data buffer for this packet. */
                void setData(void* buf1);
 
+#if LOG4CXX_ABI_VERSION <= 15
                /** Set the data buffer for this packet. */
                void setData(void* buf1, int offset1, int length1);
 
                /** Set the length for this packet. */
                void setLength(int length1);
+#else
+               /** Set the data buffer for this packet. */
+               void setData(void* buf1, std::size_t offset1, std::size_t 
length1);
+
+               /** Set the length for this packet. */
+               void setLength(std::size_t length1);
+#endif
 
                void setPort(int port1);
 

Reply via email to