From: Kruti Date: Tue, 27 Aug 2024 09:11:00 +0000 (-0700) Subject: Change to common source files not applicable to open-vm-tools. X-Git-Tag: stable-12.5.0~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21a843e74da24401049f40efeb313a858de53b07;p=thirdparty%2Fopen-vm-tools.git Change to common source files not applicable to open-vm-tools. --- diff --git a/open-vm-tools/services/plugins/dndcp/stringxx/autoCPtr.hh b/open-vm-tools/services/plugins/dndcp/stringxx/autoCPtr.hh index c78eb509c..4cf706f75 100644 --- a/open-vm-tools/services/plugins/dndcp/stringxx/autoCPtr.hh +++ b/open-vm-tools/services/plugins/dndcp/stringxx/autoCPtr.hh @@ -1,5 +1,6 @@ /********************************************************* - * Copyright (c) 2014-2018 VMware, Inc. All rights reserved. + * Copyright (c) 2014-2024 Broadcom. All Rights Reserved. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -16,80 +17,36 @@ * *********************************************************/ +#ifndef AUTOCPTR_HH +#define AUTOCPTR_HH + +#include + + /* - * autoCPtr.hh -- + *----------------------------------------------------------------------------- + * + * auto_unique -- * - * A simple, std::auto_ptr-like class for managing memory usually - * allocated by C functions. + * A helper function to create and return std::unique_ptr objects with + * deduced types. * - * Unlike std::auto_ptr, allows providing a customer deleter and disallows - * copying. This is basically a wanna-be std::unique_ptr for platforms - * that don't have C++11 available yet. + * Returns: + * Returns the constructed std::unique_ptr. * - * XXX: When everything uses C++11, this can be replaced with - * std::unique_ptr. + * Usage: + * auto foo = auto_unique(AllocateFoo(), DeleteFoo); + * + *----------------------------------------------------------------------------- */ -#ifndef AUTOCPTR_HH -#define AUTOCPTR_HH - -#include -#include - - -template -class AutoCPtr +template> +std::unique_ptr +auto_unique(T* p, // IN + Deleter deleter = Deleter()) // IN/OPT { -private: - typedef AutoCPtr SelfType; - -public: - explicit AutoCPtr(T* p = NULL, // IN/OPT - FreeFunc f = std::free) // IN/OPT - : mP(p), - mFree(f) - { - } - - ~AutoCPtr() { mFree(mP); } - - void reset(T* p = NULL) // IN/OPT - { - if (p == mP) { - return; - } - - SelfType copy(mP, mFree); - mP = p; - } - - T* release() - { - T* p = mP; - mP = NULL; - return p; - } - - T* get() const { return mP; } - T* operator->() const { return mP; } - T& operator*() const { return *mP; } - - void swap(SelfType& other) // IN/OUT - { - using std::swap; - swap(mP, other.mP); - swap(mFree, other.mFree); - } - -private: - T* mP; - FreeFunc mFree; - -private: - // Non-copyable. - AutoCPtr(const SelfType&); - SelfType& operator=(const SelfType&); -}; + return {p, deleter}; +} #endif // AUTOCPTR_HH diff --git a/open-vm-tools/services/plugins/dndcp/stringxx/string.cc b/open-vm-tools/services/plugins/dndcp/stringxx/string.cc index 9b7fea7c8..bd6da4848 100644 --- a/open-vm-tools/services/plugins/dndcp/stringxx/string.cc +++ b/open-vm-tools/services/plugins/dndcp/stringxx/string.cc @@ -1,5 +1,6 @@ /********************************************************* - * Copyright (c) 2008-2019,2022 VMware, Inc. All rights reserved. + * Copyright (c) 2008-2024 Broadcom. All Rights Reserved. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -169,7 +170,7 @@ string::string(const _bstr_t &s) // IN return; } - mUstr = AutoCPtr( + mUstr = auto_unique( Unicode_AllocWithUTF16(static_cast(s)), free).get(); ASSERT(Validate(mUstr)); @@ -240,8 +241,7 @@ string::string(const utf16_t *s) // IN */ mUtf16Cache = Unicode_UTF16Strdup(s); - mUstr = AutoCPtr(Unicode_AllocWithUTF16(s), - free).get(); + mUstr = auto_unique(Unicode_AllocWithUTF16(s), free).get(); ASSERT(Validate(mUstr)); } @@ -273,8 +273,7 @@ string::string(const char *s, // IN return; } - mUstr = AutoCPtr(Unicode_Alloc(s, encoding), - free).get(); + mUstr = auto_unique(Unicode_Alloc(s, encoding), free).get(); ASSERT(Validate(mUstr)); } @@ -2194,7 +2193,7 @@ CopyAndFree(char* utf8, // IN void (*freeFunc)(void*)) // IN/OPT { ASSERT(utf8 != NULL); - return AutoCPtr(utf8, freeFunc).get(); + return auto_unique(utf8, freeFunc).get(); } diff --git a/open-vm-tools/services/plugins/dndcp/stringxx/ubstr_t.hh b/open-vm-tools/services/plugins/dndcp/stringxx/ubstr_t.hh index 9713ee8ff..74f55f8b8 100644 --- a/open-vm-tools/services/plugins/dndcp/stringxx/ubstr_t.hh +++ b/open-vm-tools/services/plugins/dndcp/stringxx/ubstr_t.hh @@ -1,5 +1,6 @@ /********************************************************* - * Copyright (c) 2008-2019,2021-2023 VMware, Inc. All rights reserved. + * Copyright (c) 2008-2024 Broadcom. All Rights Reserved. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -238,7 +239,7 @@ ubstr_t::ubstr_t(const char *s) // IN: A UTF-8-encoded string. if (s != NULL) { // Since we already have the UTF-8 version of the string, cache it now. mUTF8 = std::shared_ptr(new UTF8Data(Util_SafeStrdup(s))); - mBstr = AutoCPtr(Unicode_GetAllocUTF16(s), free).get(); + mBstr = auto_unique(Unicode_GetAllocUTF16(s), free).get(); } } @@ -815,7 +816,7 @@ ubstr_t::GetUTF8Cache() } if (mUTF8->Get() == NULL) { - AutoCPtr utf8Str( + auto utf8Str = auto_unique( Unicode_AllocWithUTF16(static_cast(mBstr)), free); mUTF8->Set(utf8Str.get());