Skip to content

Commit

Permalink
Breaking Change: Mark final ZeroCopyInputStream, ZeroCopyOutputStream…
Browse files Browse the repository at this point in the history
…, and DefaultFieldComparator classes.

PiperOrigin-RevId: 503297575
  • Loading branch information
zhangskz authored and copybara-github committed Jan 20, 2023
1 parent 119ea4c commit bf9c22e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 35 deletions.
6 changes: 2 additions & 4 deletions src/google/protobuf/io/gzip_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ namespace protobuf {
namespace io {

// A ZeroCopyInputStream that reads compressed data through zlib
class PROTOBUF_EXPORT GzipInputStream PROTOBUF_FUTURE_FINAL
: public ZeroCopyInputStream {
class PROTOBUF_EXPORT GzipInputStream final : public ZeroCopyInputStream {
public:
// Format key for constructor
enum Format {
Expand Down Expand Up @@ -105,8 +104,7 @@ class PROTOBUF_EXPORT GzipInputStream PROTOBUF_FUTURE_FINAL
void DoNextOutput(const void** data, int* size);
};

class PROTOBUF_EXPORT GzipOutputStream PROTOBUF_FUTURE_FINAL
: public ZeroCopyOutputStream {
class PROTOBUF_EXPORT GzipOutputStream final : public ZeroCopyOutputStream {
public:
// Format key for constructor
enum Format {
Expand Down
21 changes: 9 additions & 12 deletions src/google/protobuf/io/zero_copy_stream_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ namespace io {
// The latter will introduce an extra layer of buffering, harming performance.
// Also, it's conceivable that FileInputStream could someday be enhanced
// to use zero-copy file descriptors on OSs which support them.
class PROTOBUF_EXPORT FileInputStream PROTOBUF_FUTURE_FINAL
: public ZeroCopyInputStream {
class PROTOBUF_EXPORT FileInputStream final : public ZeroCopyInputStream {
public:
// Creates a stream that reads from the given Unix file descriptor.
// If a block_size is given, it specifies the number of bytes that
Expand Down Expand Up @@ -98,7 +97,7 @@ class PROTOBUF_EXPORT FileInputStream PROTOBUF_FUTURE_FINAL
int64_t ByteCount() const override;

private:
class PROTOBUF_EXPORT CopyingFileInputStream PROTOBUF_FUTURE_FINAL
class PROTOBUF_EXPORT CopyingFileInputStream final
: public CopyingInputStream {
public:
CopyingFileInputStream(int file_descriptor);
Expand Down Expand Up @@ -141,7 +140,7 @@ class PROTOBUF_EXPORT FileInputStream PROTOBUF_FUTURE_FINAL
// harming performance. Also, it's conceivable that FileOutputStream could
// someday be enhanced to use zero-copy file descriptors on OSs which
// support them.
class PROTOBUF_EXPORT FileOutputStream PROTOBUF_FUTURE_FINAL
class PROTOBUF_EXPORT FileOutputStream final
: public CopyingOutputStreamAdaptor {
public:
// Creates a stream that writes to the given Unix file descriptor.
Expand Down Expand Up @@ -173,7 +172,7 @@ class PROTOBUF_EXPORT FileOutputStream PROTOBUF_FUTURE_FINAL
int GetErrno() const { return copying_output_.GetErrno(); }

private:
class PROTOBUF_EXPORT CopyingFileOutputStream PROTOBUF_FUTURE_FINAL
class PROTOBUF_EXPORT CopyingFileOutputStream final
: public CopyingOutputStream {
public:
CopyingFileOutputStream(int file_descriptor);
Expand Down Expand Up @@ -207,8 +206,7 @@ class PROTOBUF_EXPORT FileOutputStream PROTOBUF_FUTURE_FINAL
//
// Note that for reading files (or anything represented by a file descriptor),
// FileInputStream is more efficient.
class PROTOBUF_EXPORT IstreamInputStream PROTOBUF_FUTURE_FINAL
: public ZeroCopyInputStream {
class PROTOBUF_EXPORT IstreamInputStream final : public ZeroCopyInputStream {
public:
// Creates a stream that reads from the given C++ istream.
// If a block_size is given, it specifies the number of bytes that
Expand All @@ -225,7 +223,7 @@ class PROTOBUF_EXPORT IstreamInputStream PROTOBUF_FUTURE_FINAL
int64_t ByteCount() const override;

private:
class PROTOBUF_EXPORT CopyingIstreamInputStream PROTOBUF_FUTURE_FINAL
class PROTOBUF_EXPORT CopyingIstreamInputStream final
: public CopyingInputStream {
public:
CopyingIstreamInputStream(std::istream* input);
Expand Down Expand Up @@ -253,8 +251,7 @@ class PROTOBUF_EXPORT IstreamInputStream PROTOBUF_FUTURE_FINAL
//
// Note that for writing files (or anything represented by a file descriptor),
// FileOutputStream is more efficient.
class PROTOBUF_EXPORT OstreamOutputStream PROTOBUF_FUTURE_FINAL
: public ZeroCopyOutputStream {
class PROTOBUF_EXPORT OstreamOutputStream final : public ZeroCopyOutputStream {
public:
// Creates a stream that writes to the given C++ ostream.
// If a block_size is given, it specifies the size of the buffers
Expand All @@ -271,7 +268,7 @@ class PROTOBUF_EXPORT OstreamOutputStream PROTOBUF_FUTURE_FINAL
int64_t ByteCount() const override;

private:
class PROTOBUF_EXPORT CopyingOstreamOutputStream PROTOBUF_FUTURE_FINAL
class PROTOBUF_EXPORT CopyingOstreamOutputStream final
: public CopyingOutputStream {
public:
CopyingOstreamOutputStream(std::ostream* output);
Expand Down Expand Up @@ -301,7 +298,7 @@ class PROTOBUF_EXPORT OstreamOutputStream PROTOBUF_FUTURE_FINAL
// ConcatenatingInputStream may do odd things. It is suggested that you do
// not use ConcatenatingInputStream on streams that might produce read errors
// other than end-of-stream.
class PROTOBUF_EXPORT ConcatenatingInputStream PROTOBUF_FUTURE_FINAL
class PROTOBUF_EXPORT ConcatenatingInputStream final
: public ZeroCopyInputStream {
public:
// All streams passed in as well as the array itself must remain valid
Expand Down
12 changes: 4 additions & 8 deletions src/google/protobuf/io/zero_copy_stream_impl_lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ namespace io {
// ===================================================================

// A ZeroCopyInputStream backed by an in-memory array of bytes.
class PROTOBUF_EXPORT ArrayInputStream PROTOBUF_FUTURE_FINAL
: public ZeroCopyInputStream {
class PROTOBUF_EXPORT ArrayInputStream final : public ZeroCopyInputStream {
public:
// Create an InputStream that returns the bytes pointed to by "data".
// "data" remains the property of the caller but must remain valid until
Expand Down Expand Up @@ -105,8 +104,7 @@ class PROTOBUF_EXPORT ArrayInputStream PROTOBUF_FUTURE_FINAL
// ===================================================================

// A ZeroCopyOutputStream backed by an in-memory array of bytes.
class PROTOBUF_EXPORT ArrayOutputStream PROTOBUF_FUTURE_FINAL
: public ZeroCopyOutputStream {
class PROTOBUF_EXPORT ArrayOutputStream final : public ZeroCopyOutputStream {
public:
// Create an OutputStream that writes to the bytes pointed to by "data".
// "data" remains the property of the caller but must remain valid until
Expand Down Expand Up @@ -140,8 +138,7 @@ class PROTOBUF_EXPORT ArrayOutputStream PROTOBUF_FUTURE_FINAL
// ===================================================================

// A ZeroCopyOutputStream which appends bytes to a string.
class PROTOBUF_EXPORT StringOutputStream PROTOBUF_FUTURE_FINAL
: public ZeroCopyOutputStream {
class PROTOBUF_EXPORT StringOutputStream final : public ZeroCopyOutputStream {
public:
// Create a StringOutputStream which appends bytes to the given string.
// The string remains property of the caller, but it is mutated in arbitrary
Expand Down Expand Up @@ -364,8 +361,7 @@ class PROTOBUF_EXPORT CopyingOutputStreamAdaptor : public ZeroCopyOutputStream {

// A ZeroCopyInputStream which wraps some other stream and limits it to
// a particular byte count.
class PROTOBUF_EXPORT LimitingInputStream PROTOBUF_FUTURE_FINAL
: public ZeroCopyInputStream {
class PROTOBUF_EXPORT LimitingInputStream final : public ZeroCopyInputStream {
public:
LimitingInputStream(ZeroCopyInputStream* input, int64_t limit);
~LimitingInputStream() override;
Expand Down
7 changes: 0 additions & 7 deletions src/google/protobuf/port_def.inc
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,6 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and
// Owner: mordberg@
#define PROTOBUF_FUTURE_MAP_PAIR_UPGRADE 1

// Used on classes that are historically not marked as final, but that may be
// marked final in future (breaking) releases.
// Owner: kfm@
#define PROTOBUF_FUTURE_FINAL final

// Used to remove the RTTI checks for `DefaultFieldComparator`.
// Owner: kfm@
#define PROTOBUF_FUTURE_REMOVE_DEFAULT_FIELD_COMPARATOR 1
Expand All @@ -221,8 +216,6 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and
// Owner: mkruskal@
#define PROTOBUF_FUTURE_REMOVE_CLEARED_API 1

#else
#define PROTOBUF_FUTURE_FINAL
#endif

#ifdef PROTOBUF_VERSION
Expand Down
3 changes: 0 additions & 3 deletions src/google/protobuf/port_undef.inc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
#undef PROTOBUF_EXPORT_TEMPLATE_DEFINE
#undef PROTOBUF_ALIGNAS
#undef PROTOBUF_FINAL
#undef PROTOBUF_FUTURE_FINAL
#undef PROTOBUF_THREAD_LOCAL
#undef PROTOBUF_LITTLE_ENDIAN
#undef PROTOBUF_BIG_ENDIAN
Expand Down Expand Up @@ -123,8 +122,6 @@
#undef PROTOBUF_FUTURE_REMOVE_CLEARED_API
#endif

#undef PROTOBUF_FUTURE_FINAL

// Restore macros that may have been #undef'd in port_def.inc.

#ifdef PROTOBUF_DID_UNDEF_PACKAGE
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/util/field_comparator.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class PROTOBUF_EXPORT SimpleFieldComparator : public FieldComparator {
};

// Default field comparison: use the basic implementation of FieldComparator.
class PROTOBUF_EXPORT DefaultFieldComparator PROTOBUF_FUTURE_FINAL
class PROTOBUF_EXPORT DefaultFieldComparator final
: public SimpleFieldComparator {
public:
ComparisonResult Compare(const Message& message_1, const Message& message_2,
Expand Down

0 comments on commit bf9c22e

Please sign in to comment.