]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Change to common source files not applicable to open-vm-tools.
authorKruti Pendharkar <kp025370@broadcom.com>
Tue, 22 Apr 2025 08:53:45 +0000 (01:53 -0700)
committerKruti Pendharkar <kp025370@broadcom.com>
Tue, 22 Apr 2025 08:53:45 +0000 (01:53 -0700)
open-vm-tools/services/plugins/dndcp/stringxx/string.cc
open-vm-tools/services/plugins/dndcp/stringxx/string.hh

index bd6da4848af12a54d4d3342b1351c3b0046aa030..33e1d925143feda6886cdffa301a6d4c9edb1d33 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (c) 2008-2024 Broadcom. All Rights Reserved.
+ * Copyright (c) 2008-2025 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
  *     between different types of string classes.
  */
 
+// Force `glib::ustring::npos` to be defined inline as a compile-time constant.
+#ifndef GLIBMM_HAVE_ALLOWS_STATIC_INLINE_NPOS
+#define GLIBMM_HAVE_ALLOWS_STATIC_INLINE_NPOS 1
+#endif
 
 #include <sstream>
 #include <iostream>
 #include "string.hh"
 #include "unicode.h"
 #include "util.h"
+#include "vm_assert.h"
 
 
-namespace utf {
+// See the comment to `utf::string::npos`.
+static_assert(utf::string::npos == Glib::ustring::npos,
+              "utf::string::npos must match Glib::ustring::npos");
 
-/*
- * Initialize static scope variables,
- *
- * Note that with the way this is done, it's important not to delay load glib
- * libraries. See bug 397373 for more details. If you're getting crazy values
- * for utf::string::npos, check your linker flags.
- */
-const string::size_type string::npos = Glib::ustring::npos;
 
+namespace utf {
 
 /*
  *-----------------------------------------------------------------------------
index ec60f5bfa5e73d7ca815b85a70e17e084018a4ce..480974f3b09f3aa74368fe6e1fa83444fad515ec 100644 (file)
@@ -1,5 +1,6 @@
 /*********************************************************
- * Copyright (C) 2008-2019,2022 VMware, Inc. All rights reserved.
+ * Copyright (c) 2008-2025 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
@@ -92,14 +93,27 @@ typedef std::basic_string<utf16_t> utf16string;
 class VMSTRING_EXPORT string
 {
 public:
-   // type definitions
+   // Type definitions.
    typedef Glib::ustring::size_type size_type;
    typedef Glib::ustring::value_type value_type;
    typedef Glib::ustring::iterator iterator;
    typedef Glib::ustring::const_iterator const_iterator;
 
-   // constant definitions
-   static const size_type npos;
+   // Constant definitions.
+   /*
+    * XXX: Ideally we'd initialize `npos = Glib::ustring::npos` directly, but
+    * `Glib::ustring::npos` might itself not be initialized inline, preventing
+    * it from being used as a compile-time constant.  There is a
+    * `GLIBMM_HAVE_ALLOWS_STATIC_INLINE_NPOS` macro that we can define to make
+    * `Glib::ustring::npos` initialized inline, but then we would need to
+    * ensure that nothing includes `glibmm/ustring.h` (whether directly or
+    * indirectly) before this header file, which is an awkward restriction.
+    *
+    * In practice, the value of `Glib::ustring::npos` will always be the same
+    * as `std::string::npos` which is defined to be -1 (which we additionally
+    * verify with a `static_assert` elsewhere).
+    */
+   static const size_type npos = static_cast<size_type>(-1);
 
    // Normalize mode map to Glib::NormalizeMode
 #if GIOMM_MAJOR_VERSION >= 2 && GIOMM_MINOR_VERSION >= 68