From: Kruti Pendharkar Date: Tue, 22 Apr 2025 08:53:45 +0000 (-0700) Subject: Change to common source files not applicable to open-vm-tools. X-Git-Tag: stable-13.1.0~198 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=14ccb99791aaa332fa3f8d5246cf746abd282be0;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/string.cc b/open-vm-tools/services/plugins/dndcp/stringxx/string.cc index bd6da4848..33e1d9251 100644 --- a/open-vm-tools/services/plugins/dndcp/stringxx/string.cc +++ b/open-vm-tools/services/plugins/dndcp/stringxx/string.cc @@ -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 @@ -25,6 +25,10 @@ * 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 #include @@ -33,19 +37,15 @@ #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 { /* *----------------------------------------------------------------------------- diff --git a/open-vm-tools/services/plugins/dndcp/stringxx/string.hh b/open-vm-tools/services/plugins/dndcp/stringxx/string.hh index ec60f5bfa..480974f3b 100644 --- a/open-vm-tools/services/plugins/dndcp/stringxx/string.hh +++ b/open-vm-tools/services/plugins/dndcp/stringxx/string.hh @@ -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 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(-1); // Normalize mode map to Glib::NormalizeMode #if GIOMM_MAJOR_VERSION >= 2 && GIOMM_MINOR_VERSION >= 68