aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordfyz <dfyz@yandex-team.com>2022-10-29 16:03:13 +0300
committerdfyz <dfyz@yandex-team.com>2022-10-29 16:03:13 +0300
commit8985a698521744e4065500f5945d44ca52f797a9 (patch)
treeff7d781a5f3109e28ba658bb2a81f163cbd64dcc
parent45b67d57b5cf073f8d2fa3350ff8f1156ff18e9a (diff)
downloadydb-8985a698521744e4065500f5945d44ca52f797a9.tar.gz
Remove a workaround for ancient CUDA versions
`#define noexcept throw()` is a questionable idea, since replacing `noexcept` with `throw()` in expressions such as `noexcept(true)` results in spectacular compiler errors. We stopped supporting CUDA 8 (and even CUDA 9) long ago, which means we can just get rid of the problematic define.
-rw-r--r--library/cpp/yt/memory/serialize.h34
-rw-r--r--library/cpp/yt/memory/unittests/intrusive_ptr_ut.cpp60
-rw-r--r--util/system/compiler.h7
3 files changed, 94 insertions, 7 deletions
diff --git a/library/cpp/yt/memory/serialize.h b/library/cpp/yt/memory/serialize.h
new file mode 100644
index 0000000000..03fc286515
--- /dev/null
+++ b/library/cpp/yt/memory/serialize.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include "new.h"
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class T>
+class TSerializer<NYT::TIntrusivePtr<T>>
+{
+public:
+ static inline void Save(IOutputStream* out, const NYT::TIntrusivePtr<T>& ptr)
+ {
+ bool hasValue = ptr.operator bool();
+ ::Save(out, hasValue);
+ if (hasValue) {
+ ::Save(out, *ptr);
+ }
+ }
+
+ static inline void Load(IInputStream* in, NYT::TIntrusivePtr<T>& ptr)
+ {
+ bool hasValue;
+ ::Load(in, hasValue);
+ if (hasValue) {
+ auto tmp = NYT::New<T>();
+ ::Load(in, *tmp);
+ ptr = std::move(tmp);
+ } else {
+ ptr.Reset();
+ }
+ }
+};
+
+////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/memory/unittests/intrusive_ptr_ut.cpp b/library/cpp/yt/memory/unittests/intrusive_ptr_ut.cpp
index 5c35612ee0..9a94c82411 100644
--- a/library/cpp/yt/memory/unittests/intrusive_ptr_ut.cpp
+++ b/library/cpp/yt/memory/unittests/intrusive_ptr_ut.cpp
@@ -2,6 +2,11 @@
#include <library/cpp/yt/memory/new.h>
#include <library/cpp/yt/memory/ref_counted.h>
+#include <library/cpp/yt/memory/serialize.h>
+
+#include <util/generic/buffer.h>
+#include <util/stream/buffer.h>
+#include <util/ysaveload.h>
namespace NYT {
namespace {
@@ -556,6 +561,61 @@ TEST(TIntrusivePtrTest, InitStruct)
New<TObj6>(1, 2);
}
+TEST(TIntrusivePtrTest, Serialize)
+{
+ TBufferStream stream;
+
+ struct TObject
+ : public TRefCounted
+ {
+ ui64 Data;
+
+ TObject()
+ : Data(0)
+ { }
+ TObject(ui64 value)
+ : Data(value)
+ { }
+
+ inline void Save(IOutputStream* out) const
+ {
+ ::Save(out, Data);
+ }
+
+ inline void Load(IInputStream* in)
+ {
+ ::Load(in, Data);
+ }
+ };
+
+ ::Save(&stream, TIntrusivePtr<TObject>(nullptr));
+
+ bool hasValue = true;
+ ::Load(&stream, hasValue);
+ EXPECT_FALSE(hasValue);
+ EXPECT_EQ(stream.Buffer().Size(), 1ull);
+
+ auto data = New<TObject>(42ull);
+ ::Save(&stream, data);
+
+ ::Load(&stream, hasValue);
+ EXPECT_TRUE(hasValue);
+ data->Data = 0;
+ ::Load(&stream, data->Data);
+ EXPECT_EQ(data->Data, 42ull);
+
+ ::Save(&stream, data);
+ TIntrusivePtr<TObject> ptr;
+ ::Load(&stream, ptr);
+ EXPECT_TRUE(ptr);
+ EXPECT_EQ(data->Data, ptr->Data);
+
+ ptr = nullptr;
+ ::Save(&stream, TIntrusivePtr<TObject>(nullptr));
+ ::Load(&stream, ptr);
+ EXPECT_FALSE(ptr);
+}
+
////////////////////////////////////////////////////////////////////////////////
} // namespace
diff --git a/util/system/compiler.h b/util/system/compiler.h
index e7aa4eac38..c7b73ed51d 100644
--- a/util/system/compiler.h
+++ b/util/system/compiler.h
@@ -332,13 +332,6 @@ _YandexAbort();
#define Y_CUDA_AT_LEAST(x, y) 0
#endif
-// NVidia CUDA C++ Compiler did not know about noexcept keyword until version 9.0
-#if !Y_CUDA_AT_LEAST(9, 0)
- #if defined(__CUDACC__) && !defined(noexcept)
- #define noexcept throw()
- #endif
-#endif
-
#if defined(__GNUC__)
#define Y_COLD __attribute__((cold))
#define Y_LEAF __attribute__((leaf))