diff options
author | David Benjamin <davidben@chromium.org> | 2015-11-12 01:01:27 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2015-11-12 01:19:36 +0300 |
commit | ef14b2d86e4ce24d7adc2d7948b5372bc3b62c33 (patch) | |
tree | 3dc8352c02389149258e3734d6a1a3655840b38e /crypto/test | |
parent | cd24a39f1b3644da333bfcb43865ab7a6587c5cc (diff) |
Remove stl_compat.h.
Chromium's toolchains may now assume C++11 library support, so we may freely
use C++11 features. (Chromium's still in the process of deciding what to allow,
but we use Google's style guide directly, toolchain limitations aside.)
Change-Id: I1c7feb92b7f5f51d9091a4c686649fb574ac138d
Reviewed-on: https://boringssl-review.googlesource.com/6465
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/test')
-rw-r--r-- | crypto/test/file_test.cc | 2 | ||||
-rw-r--r-- | crypto/test/scoped_types.h | 14 | ||||
-rw-r--r-- | crypto/test/stl_compat.h | 144 |
3 files changed, 7 insertions, 153 deletions
diff --git a/crypto/test/file_test.cc b/crypto/test/file_test.cc index 6723350a..4752f04a 100644 --- a/crypto/test/file_test.cc +++ b/crypto/test/file_test.cc @@ -22,8 +22,6 @@ #include <openssl/err.h> -#include "stl_compat.h" - FileTest::FileTest(const char *path) { file_ = fopen(path, "r"); diff --git a/crypto/test/scoped_types.h b/crypto/test/scoped_types.h index 2ce45266..590f926a 100644 --- a/crypto/test/scoped_types.h +++ b/crypto/test/scoped_types.h @@ -18,6 +18,8 @@ #include <stdint.h> #include <stdio.h> +#include <memory> + #include <openssl/aead.h> #include <openssl/bio.h> #include <openssl/bn.h> @@ -34,8 +36,6 @@ #include <openssl/stack.h> #include <openssl/x509.h> -#include "stl_compat.h" - template<typename T, void (*func)(T*)> struct OpenSSLDeleter { @@ -66,11 +66,11 @@ struct FileCloser { }; template<typename T, void (*func)(T*)> -using ScopedOpenSSLType = bssl::unique_ptr<T, OpenSSLDeleter<T, func>>; +using ScopedOpenSSLType = std::unique_ptr<T, OpenSSLDeleter<T, func>>; template<typename StackType, typename T, void (*func)(T*)> using ScopedOpenSSLStack = - bssl::unique_ptr<StackType, OpenSSLStackDeleter<StackType, T, func>>; + std::unique_ptr<StackType, OpenSSLStackDeleter<StackType, T, func>>; template<typename T, typename CleanupRet, void (*init_func)(T*), CleanupRet (*cleanup_func)(T*)> @@ -129,9 +129,9 @@ using ScopedEVP_MD_CTX = ScopedOpenSSLContext<EVP_MD_CTX, int, EVP_MD_CTX_init, using ScopedHMAC_CTX = ScopedOpenSSLContext<HMAC_CTX, void, HMAC_CTX_init, HMAC_CTX_cleanup>; -using ScopedOpenSSLBytes = bssl::unique_ptr<uint8_t, OpenSSLFree<uint8_t>>; -using ScopedOpenSSLString = bssl::unique_ptr<char, OpenSSLFree<char>>; +using ScopedOpenSSLBytes = std::unique_ptr<uint8_t, OpenSSLFree<uint8_t>>; +using ScopedOpenSSLString = std::unique_ptr<char, OpenSSLFree<char>>; -using ScopedFILE = bssl::unique_ptr<FILE, FileCloser>; +using ScopedFILE = std::unique_ptr<FILE, FileCloser>; #endif // OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H diff --git a/crypto/test/stl_compat.h b/crypto/test/stl_compat.h deleted file mode 100644 index 1997a45c..00000000 --- a/crypto/test/stl_compat.h +++ /dev/null @@ -1,144 +0,0 @@ -/* Copyright (c) 2015, Google Inc. - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ - -#ifndef OPENSSL_HEADER_CRYPTO_TEST_STL_COMPAT_H -#define OPENSSL_HEADER_CRYPTO_TEST_STL_COMPAT_H - -#include <assert.h> - -#include <vector> - - -// This header contains re-implementations of library functions from C++11. They -// will be replaced with their standard counterparts once Chromium has C++11 -// library support in its toolchain. - -namespace bssl { - -// vector_data is a reimplementation of |std::vector::data| from C++11. -template <class T> -static T *vector_data(std::vector<T> *out) { - return out->empty() ? nullptr : &(*out)[0]; -} - -template <class T> -static const T *vector_data(const std::vector<T> *out) { - return out->empty() ? nullptr : &(*out)[0]; -} - -// remove_reference is a reimplementation of |std::remove_reference| from C++11. -template <class T> -struct remove_reference { - using type = T; -}; - -template <class T> -struct remove_reference<T&> { - using type = T; -}; - -template <class T> -struct remove_reference<T&&> { - using type = T; -}; - -// move is a reimplementation of |std::move| from C++11. -template <class T> -typename remove_reference<T>::type &&move(T &&t) { - return static_cast<typename remove_reference<T>::type&&>(t); -} - -// default_delete is a partial reimplementation of |std::default_delete| from -// C++11. -template <class T> -struct default_delete { - void operator()(T *t) const { - enum { type_must_be_complete = sizeof(T) }; - delete t; - } -}; - -// nullptr_t is |std::nullptr_t| from C++11. -using nullptr_t = decltype(nullptr); - -// unique_ptr is a partial reimplementation of |std::unique_ptr| from C++11. It -// intentionally does not support stateful deleters to avoid having to bother -// with the empty member optimization. -template <class T, class Deleter = default_delete<T>> -class unique_ptr { - public: - unique_ptr() : ptr_(nullptr) {} - unique_ptr(nullptr_t) : ptr_(nullptr) {} - unique_ptr(T *ptr) : ptr_(ptr) {} - unique_ptr(const unique_ptr &u) = delete; - - unique_ptr(unique_ptr &&u) : ptr_(nullptr) { - reset(u.release()); - } - - ~unique_ptr() { - reset(); - } - - unique_ptr &operator=(nullptr_t) { - reset(); - return *this; - } - - unique_ptr &operator=(unique_ptr &&u) { - reset(u.release()); - return *this; - } - - unique_ptr& operator=(const unique_ptr &u) = delete; - - explicit operator bool() const { - return ptr_ != nullptr; - } - - T &operator*() const { - assert(ptr_ != nullptr); - return *ptr_; - } - - T *operator->() const { - assert(ptr_ != nullptr); - return ptr_; - } - - T *get() const { - return ptr_; - } - - T *release() { - T *ptr = ptr_; - ptr_ = nullptr; - return ptr; - } - - void reset(T *ptr = nullptr) { - if (ptr_ != nullptr) { - Deleter()(ptr_); - } - ptr_ = ptr; - } - - private: - T *ptr_; -}; - -} // namespace bssl - - -#endif // OPENSSL_HEADER_CRYPTO_TEST_STL_COMPAT_H |