From 07b79693af66812c02044c36f1eb2e7cc3cabe8c Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sat, 14 Nov 2020 07:35:08 -0800 Subject: [PATCH] Deprecate/remove unused buffer alignment tools ByteBuffer::align() does not work as expected on some RTEMS targets where malloc() returns buffers aligned only to 4 bytes. SerializableControl::alignBuffer() and DeserializableControl::alignData() are implemented, but never called, in this module and pvAccessCPP. ByteBuffer::align() is only needed to implement these two methods. Leave non-pure virtual stubs to assist in migration. --- src/misc/pv/byteBuffer.h | 17 --------------- src/misc/pv/serialize.h | 24 ++++++++++----------- src/misc/serializeHelper.cpp | 18 ---------------- src/pv/pvIntrospect.h | 8 ------- testApp/misc/testByteBuffer.cpp | 34 +----------------------------- testApp/misc/testSerialization.cpp | 8 ------- 6 files changed, 12 insertions(+), 97 deletions(-) diff --git a/src/misc/pv/byteBuffer.h b/src/misc/pv/byteBuffer.h index ab96ca9..e507f15 100644 --- a/src/misc/pv/byteBuffer.h +++ b/src/misc/pv/byteBuffer.h @@ -494,23 +494,6 @@ public: { return sizeof(T)>1 && _reverseEndianess; } - /** - * Adjust position to the next multiple of 'size. - * @param size The alignment requirement, must be a power of 2. (unchecked) - * @param fill value to use for padding bytes (default '\0'). - * - * @note This alignment is absolute, not necessarily with respect to _buffer. - */ - inline void align(std::size_t size, char fill='\0') - { - const std::size_t k = size - 1, bufidx = (std::size_t)_position; - if(bufidx&k) { - std::size_t npad = size-(bufidx&k); - assert(npad<=getRemaining()); - std::fill(_position, _position+npad, fill); - _position += npad; - } - } /** * Put a boolean value into the byte buffer. * diff --git a/src/misc/pv/serialize.h b/src/misc/pv/serialize.h index 50000f7..39813a6 100644 --- a/src/misc/pv/serialize.h +++ b/src/misc/pv/serialize.h @@ -16,6 +16,14 @@ #include +#if defined(PVD_INTERNAL) +# define PVD_DEPRECATED(msg) +#elif __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 5 +# define PVD_DEPRECATED(msg) __attribute__((deprecated(msg))) +#else +# define PVD_DEPRECATED(msg) EPICS_DEPRECATED +#endif + namespace epics { namespace pvData { class SerializableControl; @@ -47,11 +55,7 @@ namespace epics { namespace pvData { * @param size The number of bytes. */ virtual void ensureBuffer(std::size_t size) =0; - /** - * Add pad bytes to buffer. - * @param alignment alignment required. - */ - virtual void alignBuffer(std::size_t alignment) =0; + virtual void alignBuffer(std::size_t alignment) PVD_DEPRECATED("Deprecated for lack of use") {} /** * Method for serializing primitive array data. * Hook for supplying custom serialization implementation. @@ -98,14 +102,8 @@ namespace epics { namespace pvData { * @param size The number of bytes. */ virtual void ensureData(std::size_t size) =0; - /** - * Align buffer. - * Note that this takes care only current buffer alignment. - * If streaming protocol is used, - * care must be taken that entire stream is aligned. - * @param alignment size in bytes, must be power of two. - */ - virtual void alignData(std::size_t alignment) =0; + // Deprecated for lack of use + virtual void alignData(std::size_t alignment) PVD_DEPRECATED("Deprecated for lack of use") {}; /** * Method for deserializing array data. * Hook for supplying custom deserialization implementation. diff --git a/src/misc/serializeHelper.cpp b/src/misc/serializeHelper.cpp index 33362d5..822ddec 100644 --- a/src/misc/serializeHelper.cpp +++ b/src/misc/serializeHelper.cpp @@ -174,14 +174,6 @@ struct ToString : public epics::pvData::SerializableControl assert(bufwrap.getRemaining()>0); } - virtual void alignBuffer(std::size_t alignment) - { - if(bufwrap.getRemaining()=alignment); - bufwrap.align(alignment); - } - virtual bool directSerialize( ByteBuffer *existingBuffer, const char* toSerialize, @@ -232,16 +224,6 @@ struct FromString : public epics::pvData::DeserializableControl throw std::logic_error("Incomplete buffer"); } - virtual void alignData(std::size_t alignment) - { - size_t pos = buf.getPosition(), k = alignment-1; - if(pos&k) { - std::size_t npad = alignment-(pos&k); - ensureData(npad); - buf.align(alignment); - } - } - virtual bool directDeserialize( ByteBuffer *existingBuffer, char* deserializeTo, diff --git a/src/pv/pvIntrospect.h b/src/pv/pvIntrospect.h index 5cee5d0..6039801 100644 --- a/src/pv/pvIntrospect.h +++ b/src/pv/pvIntrospect.h @@ -24,14 +24,6 @@ #include #include - -#if defined(PVD_INTERNAL) -# define PVD_DEPRECATED(msg) -#elif __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 5 -# define PVD_DEPRECATED(msg) __attribute__((deprecated(msg))) -#else -# define PVD_DEPRECATED(msg) EPICS_DEPRECATED -#endif #define PVD_DEPRECATED_52 PVD_DEPRECATED("See https://github.com/epics-base/pvDataCPP/issues/52") /* C++11 keywords diff --git a/testApp/misc/testByteBuffer.cpp b/testApp/misc/testByteBuffer.cpp index 3840e67..ff26f06 100644 --- a/testApp/misc/testByteBuffer.cpp +++ b/testApp/misc/testByteBuffer.cpp @@ -217,38 +217,6 @@ void testUnaligned() { testDiag("test correctness of unaligned access"); - ByteBuffer buf(32, EPICS_ENDIAN_BIG); - - // malloc() should give us a buffer aligned to at least native integer size - buf.align(sizeof(int)); - testOk1(buf.getPosition()==0); - - buf.clear(); - buf.put(0x42); - buf.put(0x1020); - buf.align(2, '\x41'); - testOk1(buf.getPosition()==4); - - testOk1(memcmp(buf.getBuffer(), "\x42\x10\x20\x41", 4)==0); - - buf.clear(); - buf.put(0x42); - buf.put(0x12345678); - buf.align(4, '\x41'); - testOk1(buf.getPosition()==8); - - testOk1(memcmp(buf.getBuffer(), "\x42\x12\x34\x56\x78\x41\x41\x41", 8)==0); - - buf.clear(); - buf.put(0x42); - uint64 val = 0x12345678; - val<<=32; - val |= 0x90abcdef; - buf.put(val); - buf.align(8, '\x41'); - testOk1(buf.getPosition()==16); - - testOk1(memcmp(buf.getBuffer(), "\x42\x12\x34\x56\x78\x90\xab\xcd\xef\x41\x41\x41", 8)==0); } static @@ -305,7 +273,7 @@ void testArrayBE() MAIN(testByteBuffer) { - testPlan(104); + testPlan(97); testDiag("Tests byteBuffer"); testBasicOperations(); testInverseEndianness(EPICS_ENDIAN_BIG, expect_be); diff --git a/testApp/misc/testSerialization.cpp b/testApp/misc/testSerialization.cpp index 823747a..dcbef23 100644 --- a/testApp/misc/testSerialization.cpp +++ b/testApp/misc/testSerialization.cpp @@ -67,10 +67,6 @@ public: virtual void ensureBuffer(std::size_t /*size*/) { } - virtual void alignBuffer(std::size_t alignment) { - buffer->align(alignment); - } - virtual bool directSerialize(ByteBuffer* /*existingBuffer*/, const char* /*toSerialize*/, std::size_t /*elementCount*/, std::size_t /*elementSize*/) { @@ -95,10 +91,6 @@ public: virtual void ensureData(size_t /*size*/) { } - virtual void alignData(size_t alignment) { - buffer->align(alignment); - } - virtual bool directDeserialize(ByteBuffer* /*existingBuffer*/, char* /*deserializeTo*/, std::size_t /*elementCount*/, std::size_t /*elementSize*/) {