From e68f82c346f17208cfc230394be47a6fc87818f1 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Tue, 5 Oct 2021 19:55:01 +0100 Subject: [PATCH 1/2] Remove windows.h dependency. --- include/boost/regex/v5/w32_regex_traits.hpp | 339 ++++++++++++++------ 1 file changed, 235 insertions(+), 104 deletions(-) diff --git a/include/boost/regex/v5/w32_regex_traits.hpp b/include/boost/regex/v5/w32_regex_traits.hpp index 5a9e93b6..16f7ee4e 100644 --- a/include/boost/regex/v5/w32_regex_traits.hpp +++ b/include/boost/regex/v5/w32_regex_traits.hpp @@ -29,14 +29,6 @@ #include #include -#ifndef VC_EXTRALEAN -# define VC_EXTRALEAN -#endif -#ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -#endif -#include - #if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(UNDER_CE) #pragma comment(lib, "user32.lib") #endif @@ -49,6 +41,31 @@ #endif #endif +#ifndef BASETYPES +// +// windows.h not included, so lets forward declare what we need: +// +#ifndef NO_STRICT +#ifndef STRICT +#define STRICT 1 +#endif +#endif + +#if defined(STRICT) +#define BOOST_RE_DETAIL_DECLARE_HANDLE(x) struct x##__; typedef struct x##__ *x +#else +#define BOOST_RE_DETAIL_DECLARE_HANDLE(x) typedef void* x +#endif +// +// This must be in the global namespace: +// +extern "C" { + + BOOST_RE_DETAIL_DECLARE_HANDLE(HINSTANCE); + typedef HINSTANCE HMODULE; +} +#endif + namespace boost{ // @@ -62,7 +79,7 @@ namespace BOOST_REGEX_DETAIL_NS{ // // start by typedeffing the types we'll need: // -typedef std::uint32_t lcid_type; // placeholder for LCID. +typedef unsigned long lcid_type; // placeholder for LCID. typedef std::shared_ptr cat_type; // placeholder for dll HANDLE. // @@ -97,6 +114,125 @@ wchar_t w32_toupper(wchar_t c, lcid_type); bool w32_is(lcid_type, std::uint32_t mask, char c); #ifndef BOOST_NO_WREGEX bool w32_is(lcid_type, std::uint32_t mask, wchar_t c); +#endif + +#ifndef BASETYPES +// +// Forward declarations of the small number of windows types and API's we use: +// + +#if !defined(__LP64__) +using dword = unsigned long; +#else +using DWORD = unsigned int; +#endif +using word = unsigned short; +using lctype = dword; + +static constexpr dword ct_ctype1 = 0x00000001; +static constexpr dword c1_upper = 0x0001; // upper case +static constexpr dword c1_lower = 0x0002; // lower case +static constexpr dword c1_digit = 0x0004; // decimal digits +static constexpr dword c1_space = 0x0008; // spacing characters +static constexpr dword c1_punct = 0x0010; // punctuation characters +static constexpr dword c1_cntrl = 0x0020; // control characters +static constexpr dword c1_blank = 0x0040; // blank characters +static constexpr dword c1_xdigit = 0x0080; // other digits +static constexpr dword c1_alpha = 0x0100; // any linguistic character +static constexpr dword c1_defined = 0x0200; // defined character +static constexpr unsigned int cp_acp = 0; +static constexpr dword lcmap_lowercase = 0x00000100; +static constexpr dword lcmap_uppercase = 0x00000200; +static constexpr dword lcmap_sortkey = 0x00000400; // WC sort key (normalize) +static constexpr lctype locale_idefaultansicodepage = 0x00001004; + +# ifdef UNDER_CE +# ifndef WINAPI +# ifndef _WIN32_WCE_EMULATION +# define BOOST_RE_STDCALL __cdecl // Note this doesn't match the desktop definition +# else +# define BOOST_RE_STDCALL __stdcall +# endif +# endif +# else +# if defined(_M_IX86) || defined(__i386__) +# define BOOST_RE_STDCALL __stdcall +# else + // On architectures other than 32-bit x86 __stdcall is ignored. Clang also issues a warning. +# define BOOST_RE_STDCALL +# endif +# endif + +#if defined (WIN32_PLATFORM_PSPC) +#define BOOST_RE_IMPORT __declspec( dllimport ) +#elif defined (_WIN32_WCE) +#define BOOST_RE_IMPORT +#else +#define BOOST_RE_IMPORT __declspec( dllimport ) +#endif + +extern "C" { + + BOOST_RE_IMPORT int BOOST_RE_STDCALL FreeLibrary(HMODULE hLibModule); + BOOST_RE_IMPORT int BOOST_RE_STDCALL LCMapStringA(lcid_type Locale, dword dwMapFlags, const char* lpSrcStr, int cchSrc, char* lpDestStr, int cchDest); + BOOST_RE_IMPORT int BOOST_RE_STDCALL LCMapStringW(lcid_type Locale, dword dwMapFlags, const wchar_t* lpSrcStr, int cchSrc, wchar_t* lpDestStr, int cchDest); + BOOST_RE_IMPORT int BOOST_RE_STDCALL MultiByteToWideChar(unsigned int CodePage, dword dwFlags, const char* lpMultiByteStr, int cbMultiByte, wchar_t* lpWideCharStr, int cchWideChar); + BOOST_RE_IMPORT int BOOST_RE_STDCALL LCMapStringW(lcid_type Locale, dword dwMapFlags, const wchar_t* lpSrcStr, int cchSrc, wchar_t* lpDestStr, int cchDest); + BOOST_RE_IMPORT int BOOST_RE_STDCALL WideCharToMultiByte(unsigned int CodePage, dword dwFlags, const wchar_t* lpWideCharStr, int cchWideChar, char* lpMultiByteStr, int cbMultiByte, const char* lpDefaultChar, int* lpUsedDefaultChar); + BOOST_RE_IMPORT int BOOST_RE_STDCALL GetStringTypeExA(lcid_type Locale, dword dwInfoType, const char* lpSrcStr, int cchSrc, word* lpCharType); + BOOST_RE_IMPORT int BOOST_RE_STDCALL GetStringTypeExW(lcid_type Locale, dword dwInfoType, const wchar_t* lpSrcStr, int cchSrc, word* lpCharType); + BOOST_RE_IMPORT lcid_type BOOST_RE_STDCALL GetUserDefaultLCID(); + BOOST_RE_IMPORT int BOOST_RE_STDCALL GetStringTypeExA(lcid_type Locale, dword dwInfoType, const char* lpSrcStr, int cchSrc, word* lpCharType); + BOOST_RE_IMPORT int BOOST_RE_STDCALL GetStringTypeExW(lcid_type Locale, dword dwInfoType, const wchar_t* lpSrcStr, int cchSrc, word* lpCharType); + BOOST_RE_IMPORT HMODULE BOOST_RE_STDCALL LoadLibraryA(const char* lpLibFileName); + BOOST_RE_IMPORT HMODULE BOOST_RE_STDCALL LoadLibraryW(const wchar_t* lpLibFileName); + BOOST_RE_IMPORT int BOOST_RE_STDCALL LoadStringW(HINSTANCE hInstance, unsigned int uID, wchar_t* lpBuffer, int cchBufferMax); + BOOST_RE_IMPORT int BOOST_RE_STDCALL LoadStringA(HINSTANCE hInstance, unsigned int uID, char* lpBuffer, int cchBufferMax); + BOOST_RE_IMPORT int BOOST_RE_STDCALL GetLocaleInfoW(lcid_type Locale, lctype LCType, wchar_t* lpLCData, int cchData); +} + +#else +// +// We have windows.h already included: +// +using dword = DWORD; +using word = WORD; +using lctype = LCTYPE; + +static constexpr dword ct_ctype1 = 0x00000001; +static constexpr dword c1_upper = 0x0001; // upper case +static constexpr dword c1_lower = 0x0002; // lower case +static constexpr dword c1_digit = 0x0004; // decimal digits +static constexpr dword c1_space = 0x0008; // spacing characters +static constexpr dword c1_punct = 0x0010; // punctuation characters +static constexpr dword c1_cntrl = 0x0020; // control characters +static constexpr dword c1_blank = 0x0040; // blank characters +static constexpr dword c1_xdigit = 0x0080; // other digits +static constexpr dword c1_alpha = 0x0100; // any linguistic character +static constexpr dword c1_defined = 0x0200; // defined character +static constexpr unsigned int cp_acp = 0; +static constexpr dword lcmap_lowercase = 0x00000100; +static constexpr dword lcmap_uppercase = 0x00000200; +static constexpr dword lcmap_sortkey = 0x00000400; // WC sort key (normalize) +static constexpr lctype locale_idefaultansicodepage = 0x00001004; + +using ::FreeLibrary; +using ::LCMapStringA; +using ::LCMapStringW; +using ::MultiByteToWideChar; +using ::LCMapStringW; +using ::WideCharToMultiByte; +using ::GetStringTypeExA; +using ::GetStringTypeExW; +using ::GetUserDefaultLCID; +using ::GetStringTypeExA; +using ::GetStringTypeExW; +using ::LoadLibraryA; +using ::LoadLibraryW; +using ::LoadStringW; +using ::LoadStringA; +using ::GetLocaleInfoW; + #endif // // class w32_regex_traits_base: @@ -679,13 +815,13 @@ std::mutex& w32_regex_traits::get_mutex_inst() namespace BOOST_REGEX_DETAIL_NS { #ifdef BOOST_NO_ANSI_APIS - inline UINT get_code_page_for_locale_id(lcid_type idx) + inline unsigned int get_code_page_for_locale_id(lcid_type idx) { - WCHAR code_page_string[7]; - if (::GetLocaleInfoW(idx, LOCALE_IDEFAULTANSICODEPAGE, code_page_string, 7) == 0) + wchar_t code_page_string[7]; + if (boost::BOOST_REGEX_DETAIL_NS::GetLocaleInfoW(idx, locale_idefaultansicodepage, code_page_string, 7) == 0) return 0; - return static_cast(_wtol(code_page_string)); + return static_cast(_wtol(code_page_string)); } #endif @@ -755,21 +891,21 @@ namespace BOOST_REGEX_DETAIL_NS { for (int ii = 0; ii < (1 << CHAR_BIT); ++ii) char_map[ii] = static_cast(ii); #ifndef BOOST_NO_ANSI_APIS - int r = ::LCMapStringA(this->m_locale, LCMAP_LOWERCASE, char_map, 1 << CHAR_BIT, this->m_lower_map, 1 << CHAR_BIT); + int r = boost::BOOST_REGEX_DETAIL_NS::LCMapStringA(this->m_locale, lcmap_lowercase, char_map, 1 << CHAR_BIT, this->m_lower_map, 1 << CHAR_BIT); BOOST_REGEX_ASSERT(r != 0); #else - UINT code_page = get_code_page_for_locale_id(this->m_locale); + unsigned int code_page = get_code_page_for_locale_id(this->m_locale); BOOST_REGEX_ASSERT(code_page != 0); - WCHAR wide_char_map[1 << CHAR_BIT]; - int conv_r = ::MultiByteToWideChar(code_page, 0, char_map, 1 << CHAR_BIT, wide_char_map, 1 << CHAR_BIT); + wchar_t wide_char_map[1 << CHAR_BIT]; + int conv_r = boost::BOOST_REGEX_DETAIL_NS::MultiByteToWideChar(code_page, 0, char_map, 1 << CHAR_BIT, wide_char_map, 1 << CHAR_BIT); BOOST_REGEX_ASSERT(conv_r != 0); - WCHAR wide_lower_map[1 << CHAR_BIT]; - int r = ::LCMapStringW(this->m_locale, LCMAP_LOWERCASE, wide_char_map, 1 << CHAR_BIT, wide_lower_map, 1 << CHAR_BIT); + wchar_t wide_lower_map[1 << CHAR_BIT]; + int r = boost::BOOST_REGEX_DETAIL_NS::LCMapStringW(this->m_locale, lcmap_lowercase, wide_char_map, 1 << CHAR_BIT, wide_lower_map, 1 << CHAR_BIT); BOOST_REGEX_ASSERT(r != 0); - conv_r = ::WideCharToMultiByte(code_page, 0, wide_lower_map, r, this->m_lower_map, 1 << CHAR_BIT, NULL, NULL); + conv_r = boost::BOOST_REGEX_DETAIL_NS::WideCharToMultiByte(code_page, 0, wide_lower_map, r, this->m_lower_map, 1 << CHAR_BIT, NULL, NULL); BOOST_REGEX_ASSERT(conv_r != 0); #endif if (r < (1 << CHAR_BIT)) @@ -781,36 +917,36 @@ namespace BOOST_REGEX_DETAIL_NS { } #ifndef BOOST_NO_ANSI_APIS - r = ::GetStringTypeExA(this->m_locale, CT_CTYPE1, char_map, 1 << CHAR_BIT, this->m_type_map); + r = boost::BOOST_REGEX_DETAIL_NS::GetStringTypeExA(this->m_locale, ct_ctype1, char_map, 1 << CHAR_BIT, this->m_type_map); #else - r = ::GetStringTypeExW(this->m_locale, CT_CTYPE1, wide_char_map, 1 << CHAR_BIT, this->m_type_map); + r = boost::BOOST_REGEX_DETAIL_NS::GetStringTypeExW(this->m_locale, ct_ctype1, wide_char_map, 1 << CHAR_BIT, this->m_type_map); #endif BOOST_REGEX_ASSERT(0 != r); } inline lcid_type w32_get_default_locale() { - return ::GetUserDefaultLCID(); + return boost::BOOST_REGEX_DETAIL_NS::GetUserDefaultLCID(); } inline bool w32_is_lower(char c, lcid_type idx) { #ifndef BOOST_NO_ANSI_APIS - WORD mask; - if (::GetStringTypeExA(idx, CT_CTYPE1, &c, 1, &mask) && (mask & C1_LOWER)) + word mask; + if (boost::BOOST_REGEX_DETAIL_NS::GetStringTypeExA(idx, ct_ctype1, &c, 1, &mask) && (mask & c1_lower)) return true; return false; #else - UINT code_page = get_code_page_for_locale_id(idx); + unsigned int code_page = get_code_page_for_locale_id(idx); if (code_page == 0) return false; - WCHAR wide_c; - if (::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0) + wchar_t wide_c; + if (boost::BOOST_REGEX_DETAIL_NS::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0) return false; - WORD mask; - if (::GetStringTypeExW(idx, CT_CTYPE1, &wide_c, 1, &mask) && (mask & C1_LOWER)) + word mask; + if (boost::BOOST_REGEX_DETAIL_NS::GetStringTypeExW(idx, ct_ctype1, &wide_c, 1, &mask) && (mask & c1_lower)) return true; return false; #endif @@ -818,8 +954,8 @@ namespace BOOST_REGEX_DETAIL_NS { inline bool w32_is_lower(wchar_t c, lcid_type idx) { - WORD mask; - if (::GetStringTypeExW(idx, CT_CTYPE1, &c, 1, &mask) && (mask & C1_LOWER)) + word mask; + if (boost::BOOST_REGEX_DETAIL_NS::GetStringTypeExW(idx, ct_ctype1, &c, 1, &mask) && (mask & c1_lower)) return true; return false; } @@ -827,21 +963,21 @@ namespace BOOST_REGEX_DETAIL_NS { inline bool w32_is_upper(char c, lcid_type idx) { #ifndef BOOST_NO_ANSI_APIS - WORD mask; - if (::GetStringTypeExA(idx, CT_CTYPE1, &c, 1, &mask) && (mask & C1_UPPER)) + word mask; + if (boost::BOOST_REGEX_DETAIL_NS::GetStringTypeExA(idx, ct_ctype1, &c, 1, &mask) && (mask & c1_upper)) return true; return false; #else - UINT code_page = get_code_page_for_locale_id(idx); + unsigned int code_page = get_code_page_for_locale_id(idx); if (code_page == 0) return false; - WCHAR wide_c; - if (::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0) + wchar_t wide_c; + if (boost::BOOST_REGEX_DETAIL_NS::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0) return false; - WORD mask; - if (::GetStringTypeExW(idx, CT_CTYPE1, &wide_c, 1, &mask) && (mask & C1_UPPER)) + word mask; + if (boost::BOOST_REGEX_DETAIL_NS::GetStringTypeExW(idx, ct_ctype1, &wide_c, 1, &mask) && (mask & c1_upper)) return true; return false; #endif @@ -849,28 +985,28 @@ namespace BOOST_REGEX_DETAIL_NS { inline bool w32_is_upper(wchar_t c, lcid_type idx) { - WORD mask; - if (::GetStringTypeExW(idx, CT_CTYPE1, &c, 1, &mask) && (mask & C1_UPPER)) + word mask; + if (boost::BOOST_REGEX_DETAIL_NS::GetStringTypeExW(idx, ct_ctype1, &c, 1, &mask) && (mask & c1_upper)) return true; return false; } inline void free_module(void* mod) { - ::FreeLibrary(static_cast(mod)); + boost::BOOST_REGEX_DETAIL_NS::FreeLibrary(static_cast(mod)); } inline cat_type w32_cat_open(const std::string& name) { #ifndef BOOST_NO_ANSI_APIS - cat_type result(::LoadLibraryA(name.c_str()), &free_module); + cat_type result(boost::BOOST_REGEX_DETAIL_NS::LoadLibraryA(name.c_str()), &free_module); return result; #else - LPWSTR wide_name = (LPWSTR)_alloca((name.size() + 1) * sizeof(WCHAR)); - if (::MultiByteToWideChar(CP_ACP, 0, name.c_str(), name.size(), wide_name, name.size() + 1) == 0) + wchar_t* wide_name = (wchar_t*)_alloca((name.size() + 1) * sizeof(wchar_t)); + if (boost::BOOST_REGEX_DETAIL_NS::MultiByteToWideChar(cp_acp, 0, name.c_str(), (int)name.size(), wide_name, (int)(name.size() + 1)) == 0) return cat_type(); - cat_type result(::LoadLibraryW(wide_name), &free_module); + cat_type result(boost::BOOST_REGEX_DETAIL_NS::LoadLibraryW(wide_name), &free_module); return result; #endif } @@ -879,7 +1015,7 @@ namespace BOOST_REGEX_DETAIL_NS { { #ifndef BOOST_NO_ANSI_APIS char buf[256]; - if (0 == ::LoadStringA( + if (0 == boost::BOOST_REGEX_DETAIL_NS::LoadStringA( static_cast(cat.get()), i, buf, @@ -889,8 +1025,8 @@ namespace BOOST_REGEX_DETAIL_NS { return def; } #else - WCHAR wbuf[256]; - int r = ::LoadStringW( + wchar_t wbuf[256]; + int r = boost::BOOST_REGEX_DETAIL_NS::LoadStringW( static_cast(cat.get()), i, wbuf, @@ -900,9 +1036,9 @@ namespace BOOST_REGEX_DETAIL_NS { return def; - int buf_size = 1 + ::WideCharToMultiByte(CP_ACP, 0, wbuf, r, NULL, 0, NULL, NULL); - LPSTR buf = (LPSTR)_alloca(buf_size); - if (::WideCharToMultiByte(CP_ACP, 0, wbuf, r, buf, buf_size, NULL, NULL) == 0) + int buf_size = 1 + boost::BOOST_REGEX_DETAIL_NS::WideCharToMultiByte(cp_acp, 0, wbuf, r, NULL, 0, NULL, NULL); + char* buf = (char*)_alloca(buf_size); + if (boost::BOOST_REGEX_DETAIL_NS::WideCharToMultiByte(cp_acp, 0, wbuf, r, buf, buf_size, NULL, NULL) == 0) return def; // failed conversion. #endif return std::string(buf); @@ -912,12 +1048,7 @@ namespace BOOST_REGEX_DETAIL_NS { inline std::wstring w32_cat_get(const cat_type& cat, lcid_type, int i, const std::wstring& def) { wchar_t buf[256]; - if (0 == ::LoadStringW( - static_cast(cat.get()), - i, - buf, - 256 - )) + if (0 == boost::BOOST_REGEX_DETAIL_NS::LoadStringW(static_cast(cat.get()), i, buf, 256)) { return def; } @@ -927,9 +1058,9 @@ namespace BOOST_REGEX_DETAIL_NS { inline std::string w32_transform(lcid_type idx, const char* p1, const char* p2) { #ifndef BOOST_NO_ANSI_APIS - int bytes = ::LCMapStringA( + int bytes = boost::BOOST_REGEX_DETAIL_NS::LCMapStringA( idx, // locale identifier - LCMAP_SORTKEY, // mapping transformation type + lcmap_sortkey, // mapping transformation type p1, // source string static_cast(p2 - p1), // number of characters in source string 0, // destination buffer @@ -938,27 +1069,27 @@ namespace BOOST_REGEX_DETAIL_NS { if (!bytes) return std::string(p1, p2); std::string result(++bytes, '\0'); - bytes = ::LCMapStringA( + bytes = boost::BOOST_REGEX_DETAIL_NS::LCMapStringA( idx, // locale identifier - LCMAP_SORTKEY, // mapping transformation type + lcmap_sortkey, // mapping transformation type p1, // source string static_cast(p2 - p1), // number of characters in source string &*result.begin(), // destination buffer bytes // size of destination buffer ); #else - UINT code_page = get_code_page_for_locale_id(idx); + unsigned int code_page = get_code_page_for_locale_id(idx); if (code_page == 0) return std::string(p1, p2); int src_len = static_cast(p2 - p1); - LPWSTR wide_p1 = (LPWSTR)_alloca((src_len + 1) * 2); - if (::MultiByteToWideChar(code_page, 0, p1, src_len, wide_p1, src_len + 1) == 0) + wchar_t* wide_p1 = (wchar_t*)_alloca((src_len + 1) * 2); + if (boost::BOOST_REGEX_DETAIL_NS::MultiByteToWideChar(code_page, 0, p1, src_len, wide_p1, src_len + 1) == 0) return std::string(p1, p2); - int bytes = ::LCMapStringW( + int bytes = boost::BOOST_REGEX_DETAIL_NS::LCMapStringW( idx, // locale identifier - LCMAP_SORTKEY, // mapping transformation type + lcmap_sortkey, // mapping transformation type wide_p1, // source string src_len, // number of characters in source string 0, // destination buffer @@ -967,12 +1098,12 @@ namespace BOOST_REGEX_DETAIL_NS { if (!bytes) return std::string(p1, p2); std::string result(++bytes, '\0'); - bytes = ::LCMapStringW( + bytes = boost::BOOST_REGEX_DETAIL_NS::LCMapStringW( idx, // locale identifier - LCMAP_SORTKEY, // mapping transformation type + lcmap_sortkey, // mapping transformation type wide_p1, // source string src_len, // number of characters in source string - (LPWSTR) & *result.begin(), // destination buffer + (wchar_t*) & *result.begin(), // destination buffer bytes // size of destination buffer ); #endif @@ -988,9 +1119,9 @@ namespace BOOST_REGEX_DETAIL_NS { #ifndef BOOST_NO_WREGEX inline std::wstring w32_transform(lcid_type idx, const wchar_t* p1, const wchar_t* p2) { - int bytes = ::LCMapStringW( + int bytes = boost::BOOST_REGEX_DETAIL_NS::LCMapStringW( idx, // locale identifier - LCMAP_SORTKEY, // mapping transformation type + lcmap_sortkey, // mapping transformation type p1, // source string static_cast(p2 - p1), // number of characters in source string 0, // destination buffer @@ -999,9 +1130,9 @@ namespace BOOST_REGEX_DETAIL_NS { if (!bytes) return std::wstring(p1, p2); std::string result(++bytes, '\0'); - bytes = ::LCMapStringW( + bytes = boost::BOOST_REGEX_DETAIL_NS::LCMapStringW( idx, // locale identifier - LCMAP_SORTKEY, // mapping transformation type + lcmap_sortkey, // mapping transformation type p1, // source string static_cast(p2 - p1), // number of characters in source string reinterpret_cast(&*result.begin()), // destination buffer *of bytes* @@ -1023,9 +1154,9 @@ namespace BOOST_REGEX_DETAIL_NS { { char result[2]; #ifndef BOOST_NO_ANSI_APIS - int b = ::LCMapStringA( + int b = boost::BOOST_REGEX_DETAIL_NS::LCMapStringA( idx, // locale identifier - LCMAP_LOWERCASE, // mapping transformation type + lcmap_lowercase, // mapping transformation type &c, // source string 1, // number of characters in source string result, // destination buffer @@ -1033,18 +1164,18 @@ namespace BOOST_REGEX_DETAIL_NS { if (b == 0) return c; #else - UINT code_page = get_code_page_for_locale_id(idx); + unsigned int code_page = get_code_page_for_locale_id(idx); if (code_page == 0) return c; - WCHAR wide_c; - if (::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0) + wchar_t wide_c; + if (boost::BOOST_REGEX_DETAIL_NS::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0) return c; - WCHAR wide_result; - int b = ::LCMapStringW( + wchar_t wide_result; + int b = boost::BOOST_REGEX_DETAIL_NS::LCMapStringW( idx, // locale identifier - LCMAP_LOWERCASE, // mapping transformation type + lcmap_lowercase, // mapping transformation type &wide_c, // source string 1, // number of characters in source string &wide_result, // destination buffer @@ -1052,7 +1183,7 @@ namespace BOOST_REGEX_DETAIL_NS { if (b == 0) return c; - if (::WideCharToMultiByte(code_page, 0, &wide_result, 1, result, 2, NULL, NULL) == 0) + if (boost::BOOST_REGEX_DETAIL_NS::WideCharToMultiByte(code_page, 0, &wide_result, 1, result, 2, NULL, NULL) == 0) return c; // No single byte lower case equivalent available #endif return result[0]; @@ -1062,9 +1193,9 @@ namespace BOOST_REGEX_DETAIL_NS { inline wchar_t w32_tolower(wchar_t c, lcid_type idx) { wchar_t result[2]; - int b = ::LCMapStringW( + int b = boost::BOOST_REGEX_DETAIL_NS::LCMapStringW( idx, // locale identifier - LCMAP_LOWERCASE, // mapping transformation type + lcmap_lowercase, // mapping transformation type &c, // source string 1, // number of characters in source string result, // destination buffer @@ -1078,9 +1209,9 @@ namespace BOOST_REGEX_DETAIL_NS { { char result[2]; #ifndef BOOST_NO_ANSI_APIS - int b = ::LCMapStringA( + int b = boost::BOOST_REGEX_DETAIL_NS::LCMapStringA( idx, // locale identifier - LCMAP_UPPERCASE, // mapping transformation type + lcmap_uppercase, // mapping transformation type &c, // source string 1, // number of characters in source string result, // destination buffer @@ -1088,18 +1219,18 @@ namespace BOOST_REGEX_DETAIL_NS { if (b == 0) return c; #else - UINT code_page = get_code_page_for_locale_id(idx); + unsigned int code_page = get_code_page_for_locale_id(idx); if (code_page == 0) return c; - WCHAR wide_c; - if (::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0) + wchar_t wide_c; + if (boost::BOOST_REGEX_DETAIL_NS::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0) return c; - WCHAR wide_result; - int b = ::LCMapStringW( + wchar_t wide_result; + int b = boost::BOOST_REGEX_DETAIL_NS::LCMapStringW( idx, // locale identifier - LCMAP_UPPERCASE, // mapping transformation type + lcmap_uppercase, // mapping transformation type &wide_c, // source string 1, // number of characters in source string &wide_result, // destination buffer @@ -1107,7 +1238,7 @@ namespace BOOST_REGEX_DETAIL_NS { if (b == 0) return c; - if (::WideCharToMultiByte(code_page, 0, &wide_result, 1, result, 2, NULL, NULL) == 0) + if (boost::BOOST_REGEX_DETAIL_NS::WideCharToMultiByte(code_page, 0, &wide_result, 1, result, 2, NULL, NULL) == 0) return c; // No single byte upper case equivalent available. #endif return result[0]; @@ -1117,9 +1248,9 @@ namespace BOOST_REGEX_DETAIL_NS { inline wchar_t w32_toupper(wchar_t c, lcid_type idx) { wchar_t result[2]; - int b = ::LCMapStringW( + int b = boost::BOOST_REGEX_DETAIL_NS::LCMapStringW( idx, // locale identifier - LCMAP_UPPERCASE, // mapping transformation type + lcmap_uppercase, // mapping transformation type &c, // source string 1, // number of characters in source string result, // destination buffer @@ -1131,20 +1262,20 @@ namespace BOOST_REGEX_DETAIL_NS { #endif inline bool w32_is(lcid_type idx, std::uint32_t m, char c) { - WORD mask; + word mask; #ifndef BOOST_NO_ANSI_APIS - if (::GetStringTypeExA(idx, CT_CTYPE1, &c, 1, &mask) && (mask & m & w32_regex_traits_implementation::mask_base)) + if (boost::BOOST_REGEX_DETAIL_NS::GetStringTypeExA(idx, ct_ctype1, &c, 1, &mask) && (mask & m & w32_regex_traits_implementation::mask_base)) return true; #else - UINT code_page = get_code_page_for_locale_id(idx); + unsigned int code_page = get_code_page_for_locale_id(idx); if (code_page == 0) return false; - WCHAR wide_c; - if (::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0) + wchar_t wide_c; + if (boost::BOOST_REGEX_DETAIL_NS::MultiByteToWideChar(code_page, 0, &c, 1, &wide_c, 1) == 0) return false; - if (::GetStringTypeExW(idx, CT_CTYPE1, &wide_c, 1, &mask) && (mask & m & w32_regex_traits_implementation::mask_base)) + if (boost::BOOST_REGEX_DETAIL_NS::GetStringTypeExW(idx, ct_ctype1, &wide_c, 1, &mask) && (mask & m & w32_regex_traits_implementation::mask_base)) return true; #endif if ((m & w32_regex_traits_implementation::mask_word) && (c == '_')) @@ -1155,8 +1286,8 @@ namespace BOOST_REGEX_DETAIL_NS { #ifndef BOOST_NO_WREGEX inline bool w32_is(lcid_type idx, std::uint32_t m, wchar_t c) { - WORD mask; - if (::GetStringTypeExW(idx, CT_CTYPE1, &c, 1, &mask) && (mask & m & w32_regex_traits_implementation::mask_base)) + word mask; + if (boost::BOOST_REGEX_DETAIL_NS::GetStringTypeExW(idx, ct_ctype1, &c, 1, &mask) && (mask & m & w32_regex_traits_implementation::mask_base)) return true; if ((m & w32_regex_traits_implementation::mask_word) && (c == '_')) return true; From 6050fa4fd4fdd1abc2c0b2841387d37adab767e6 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Wed, 6 Oct 2021 08:41:00 +0100 Subject: [PATCH 2/2] Add some more windows checks, remove outdated CI tests (Xenial is no longer supported). --- .github/workflows/ci.yml | 51 ------------------------------------ test/Jamfile.v2 | 5 ++++ test/test_windows_defs_1.cpp | 29 ++++++++++++++++++++ test/test_windows_defs_2.cpp | 29 ++++++++++++++++++++ test/test_windows_defs_3.cpp | 27 +++++++++++++++++++ test/test_windows_defs_4.cpp | 28 ++++++++++++++++++++ 6 files changed, 118 insertions(+), 51 deletions(-) create mode 100644 test/test_windows_defs_1.cpp create mode 100644 test/test_windows_defs_2.cpp create mode 100644 test/test_windows_defs_3.cpp create mode 100644 test/test_windows_defs_4.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c104347..ce5e3275 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,57 +108,6 @@ jobs: - name: Test run: ../../../b2 toolset=$TOOLSET define=CI_SUPPRESS_KNOWN_ISSUES define=SLOW_COMPILER working-directory: ../boost-root/libs/regex/test - ubuntu-xenial: - runs-on: ubuntu-16.04 - strategy: - fail-fast: false - matrix: - compiler: [ g++-5, g++-6, clang++-5.0, clang++-6.0 ] - standard: [ c++03 c++11, c++14, c++1z ] - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: '0' - - uses: mstachniuk/ci-skip@v1 - with: - commit-filter: '[skip ci];[ci skip];[CI SKIP];[SKIP CI];***CI SKIP***;***SKIP CI***;[windows];[Windows];[WINDOWS];[apple];[Apple];[APPLE]' - commit-filter-separator: ';' - fail-fast: true - - name: Set TOOLSET - run: echo ${{ matrix.compiler }} | awk '/^g/ { print "TOOLSET=gcc" } /^clang/ { print "TOOLSET=clang" }' >> $GITHUB_ENV - - name: Add repository - run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test" - - name: Install packages - run: sudo apt install g++-5 g++-6 clang-5.0 clang-6.0 - - name: Checkout main boost - run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root - - name: Update tools/boostdep - run: git submodule update --init tools/boostdep - working-directory: ../boost-root - - name: Copy files - run: cp -r $GITHUB_WORKSPACE/* libs/regex - working-directory: ../boost-root - - name: Install deps - run: python tools/boostdep/depinst/depinst.py -I example -g "--jobs 3" regex - working-directory: ../boost-root - - name: Bootstrap - run: ./bootstrap.sh - working-directory: ../boost-root - - name: Generate headers - run: ./b2 headers - working-directory: ../boost-root - - name: Generate user config - run: 'echo "using $TOOLSET : : ${{ matrix.compiler }} : -std=${{ matrix.standard }} ;" > ~/user-config.jam' - working-directory: ../boost-root - - name: Config info install - run: ../../../b2 config_info_travis_install toolset=$TOOLSET - working-directory: ../boost-root/libs/config/test - - name: Config info - run: ./config_info_travis - working-directory: ../boost-root/libs/config/test - - name: Test - run: ../../../b2 toolset=$TOOLSET - working-directory: ../boost-root/libs/regex/test macos: runs-on: macos-latest strategy: diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 9a50918c..04514302 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -224,3 +224,8 @@ compile test_warnings.cpp BOOST_REGEX_STANDALONE [ check-target-builds ../build//is_legacy_03 : : no ] : test_warnings_standalone ; + +compile test_windows_defs_1.cpp ; +compile test_windows_defs_2.cpp ; +compile test_windows_defs_3.cpp ; +compile test_windows_defs_4.cpp ; diff --git a/test/test_windows_defs_1.cpp b/test/test_windows_defs_1.cpp new file mode 100644 index 00000000..5415a607 --- /dev/null +++ b/test/test_windows_defs_1.cpp @@ -0,0 +1,29 @@ +/* +* +* Copyright (c) 2021 +* John Maddock +* +* Use, modification and distribution are subject to the +* Boost Software License, Version 1.0. (See accompanying file +* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +* +*/ + +#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32) +// +// Make sure our forward declarations match those in windows.h: +// + +#define STRICT + +#include +#include + +void test_proc() +{ + std::string text, re; + boost::regex exp(re); + regex_match(text, exp); +} + +#endif diff --git a/test/test_windows_defs_2.cpp b/test/test_windows_defs_2.cpp new file mode 100644 index 00000000..8707b36b --- /dev/null +++ b/test/test_windows_defs_2.cpp @@ -0,0 +1,29 @@ +/* +* +* Copyright (c) 2021 +* John Maddock +* +* Use, modification and distribution are subject to the +* Boost Software License, Version 1.0. (See accompanying file +* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +* +*/ + +#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32) +// +// Make sure our forward declarations match those in windows.h: +// + +#define NO_STRICT + +#include +#include + +void test_proc() +{ + std::string text, re; + boost::regex exp(re); + regex_match(text, exp); +} + +#endif diff --git a/test/test_windows_defs_3.cpp b/test/test_windows_defs_3.cpp new file mode 100644 index 00000000..bc369d34 --- /dev/null +++ b/test/test_windows_defs_3.cpp @@ -0,0 +1,27 @@ +/* +* +* Copyright (c) 2021 +* John Maddock +* +* Use, modification and distribution are subject to the +* Boost Software License, Version 1.0. (See accompanying file +* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +* +*/ + +#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32) +// +// Make sure our forward declarations match those in windows.h: +// + +#include +#include + +void test_proc() +{ + std::string text, re; + boost::regex exp(re); + regex_match(text, exp); +} + +#endif diff --git a/test/test_windows_defs_4.cpp b/test/test_windows_defs_4.cpp new file mode 100644 index 00000000..09a0015c --- /dev/null +++ b/test/test_windows_defs_4.cpp @@ -0,0 +1,28 @@ +/* +* +* Copyright (c) 2021 +* John Maddock +* +* Use, modification and distribution are subject to the +* Boost Software License, Version 1.0. (See accompanying file +* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +* +*/ + +#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32) +// +// Make sure our forward declarations match those in windows.h: +// +#define STRICT +#define BOOST_NO_ANSI_APIS +#include +#include + +void test_proc() +{ + std::string text, re; + boost::regex exp(re); + regex_match(text, exp); +} + +#endif