]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Change to common source files not applicable to open-vm-tools.
authorKruti <kpendharkar@vmware.com>
Tue, 27 Aug 2024 09:11:00 +0000 (02:11 -0700)
committerKruti <kpendharkar@vmware.com>
Tue, 27 Aug 2024 09:11:00 +0000 (02:11 -0700)
open-vm-tools/services/plugins/dndcp/stringxx/autoCPtr.hh
open-vm-tools/services/plugins/dndcp/stringxx/string.cc
open-vm-tools/services/plugins/dndcp/stringxx/ubstr_t.hh

index c78eb509c7bcdbd6cb4d3fb7202857f2629e0746..4cf706f75ff41f4864bab59926fe04b60c61b968 100644 (file)
@@ -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
  *
  *********************************************************/
 
+#ifndef AUTOCPTR_HH
+#define AUTOCPTR_HH
+
+#include <memory>
+
+
 /*
- * 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 <cstdlib>
-#include <utility>
-
-
-template<typename T, typename FreeFunc = void (*)(void*)>
-class AutoCPtr
+template<typename T, typename Deleter = std::default_delete<T>>
+std::unique_ptr<T, Deleter>
+auto_unique(T* p,                        // IN
+            Deleter deleter = Deleter()) // IN/OPT
 {
-private:
-   typedef AutoCPtr<T, FreeFunc> 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
index 9b7fea7c8ab672837bff2093294da412c29b7890..bd6da4848af12a54d4d3342b1351c3b0046aa030 100644 (file)
@@ -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<char>(
+   mUstr = auto_unique(
       Unicode_AllocWithUTF16(static_cast<const utf16_t *>(s)),
       free).get();
    ASSERT(Validate(mUstr));
@@ -240,8 +241,7 @@ string::string(const utf16_t *s) // IN
     */
    mUtf16Cache = Unicode_UTF16Strdup(s);
 
-   mUstr = AutoCPtr<char>(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<char>(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<char>(utf8, freeFunc).get();
+   return auto_unique(utf8, freeFunc).get();
 }
 
 
index 9713ee8ff47bb13a581464d361f36003a6d43f6a..74f55f8b8faf99c8ee21680b902df3d7d08a7443 100644 (file)
@@ -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<UTF8Data>(new UTF8Data(Util_SafeStrdup(s)));
-      mBstr = AutoCPtr<utf16_t>(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<char> utf8Str(
+      auto utf8Str = auto_unique(
          Unicode_AllocWithUTF16(static_cast<wchar_t *>(mBstr)),
          free);
       mUTF8->Set(utf8Str.get());