From 12e18ea6c422d7a93e644b9aa1c520c47d1f0c97 Mon Sep 17 00:00:00 2001 From: Stefan Vigerske Date: Fri, 1 Apr 2022 10:45:43 +0200 Subject: [PATCH] eliminate use of std::make_unique, remove zstr_make_unique_polyfill.h - avoids use of 3rd party code that may not be MIT licensed while preserving C++11 compatibility - same as ERGO-Code/HiGHS@9bdf81d --- src/zstr.hpp | 16 +++--- src/zstr_make_unique_polyfill.h | 86 --------------------------------- 2 files changed, 6 insertions(+), 96 deletions(-) delete mode 100644 src/zstr_make_unique_polyfill.h diff --git a/src/zstr.hpp b/src/zstr.hpp index d8b4fbe..fee4359 100644 --- a/src/zstr.hpp +++ b/src/zstr.hpp @@ -16,10 +16,6 @@ #include #include -#if __cplusplus == 201103L -#include -#endif - namespace zstr { @@ -140,10 +136,10 @@ class istreambuf window_bits(_window_bits) { assert(sbuf_p); - in_buff = std::make_unique(buff_size); + in_buff = std::unique_ptr(new char[buff_size]); in_buff_start = in_buff.get(); in_buff_end = in_buff.get(); - out_buff = std::make_unique(buff_size); + out_buff = std::unique_ptr(new char[buff_size]); setg(out_buff.get(), out_buff.get(), out_buff.get()); } @@ -213,7 +209,7 @@ class istreambuf else { // run inflate() on input - if (! zstrm_p) zstrm_p = std::make_unique(true, Z_DEFAULT_COMPRESSION, window_bits); + if (! zstrm_p) zstrm_p = std::unique_ptr(new detail::z_stream_wrapper(true, Z_DEFAULT_COMPRESSION, window_bits)); zstrm_p->next_in = reinterpret_cast< decltype(zstrm_p->next_in) >(in_buff_start); zstrm_p->avail_in = uint32_t(in_buff_end - in_buff_start); zstrm_p->next_out = reinterpret_cast< decltype(zstrm_p->next_out) >(out_buff_free_start); @@ -266,12 +262,12 @@ class ostreambuf : sbuf_p(_sbuf_p), in_buff(), out_buff(), - zstrm_p(std::make_unique(false, _level, _window_bits)), + zstrm_p(new detail::z_stream_wrapper(false, _level, _window_bits)), buff_size(_buff_size) { assert(sbuf_p); - in_buff = std::make_unique(buff_size); - out_buff = std::make_unique(buff_size); + in_buff = std::unique_ptr(new char[buff_size]); + out_buff = std::unique_ptr(new char[buff_size]); setp(in_buff.get(), in_buff.get() + buff_size); } diff --git a/src/zstr_make_unique_polyfill.h b/src/zstr_make_unique_polyfill.h deleted file mode 100644 index 898bf9b..0000000 --- a/src/zstr_make_unique_polyfill.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/** - * @file make_unique.h - * @brief Implementation of std::make_unique for pre C++14 compilation - * environments - */ - -#pragma once - -// Define std::make_unique if the compiler is C++11, but not C++14 -// (which provides this itself) -// When C++14 support is a KiCad pre-requisite, this entire file -// can be removed. -#if __cplusplus == 201103L - -#include -#include -#include -#include - -// It's a bit naughty to add things to std::, but the point is to -// "polyfill" this function in only if std:: doesn't have it -// -// This implementation is the one proposed by Stephan T. Lavavej -// in N3656: https://isocpp.org/files/papers/N3656.txt -// This is more or less exactly how it is implemented in GCC (e.g. 6.3.1) -// when C++14 is enabled. -namespace std -{ - template struct _Unique_if { - typedef unique_ptr _Single_object; - }; - - template struct _Unique_if { - typedef unique_ptr _Unknown_bound; - }; - - template struct _Unique_if { - typedef void _Known_bound; - }; - - /// std::make_unique for single objects - template - typename _Unique_if::_Single_object - make_unique(Args&&... args) { - return unique_ptr(new T(std::forward(args)...)); - } - - /// std::make_unique for arrays of unknown bound - template - typename _Unique_if::_Unknown_bound - make_unique(size_t n) { - typedef typename remove_extent::type U; - return unique_ptr(new U[n]()); - } - - /// Disable std::make_unique for arrays of known bound - template - typename _Unique_if::_Known_bound - make_unique(Args&&...) = delete; -} - -#endif // __cplusplus == 201103L -