From 9ac7eb3d84076b0fad6a8b41d79d3375d1c10e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Thu, 12 Aug 2021 01:41:26 +0200 Subject: [PATCH] Fixes #145 ("1.76 now requires unicode paths on windows") --- doc/interprocess.qbk | 15 ++- .../interprocess/detail/os_file_functions.hpp | 3 +- .../detail/shared_dir_helpers.hpp | 22 ++++- test/windows_shared_dir_path.cpp | 91 +++++++++++++++++++ 4 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 test/windows_shared_dir_path.cpp diff --git a/doc/interprocess.qbk b/doc/interprocess.qbk index d845059..ad8456a 100644 --- a/doc/interprocess.qbk +++ b/doc/interprocess.qbk @@ -6664,8 +6664,9 @@ can force this Event Log based timestamp defining BOOST_INTERPROCESS_BOOTSTAMP_I In any error case (shared documents folder is not defined or bootup time could not be obtained), the library throws an error. You still can use [*Boost.Interprocess] defining your own directory as the shared directory. When your shared directory is a compile-time constant, -define `BOOST_INTERPROCESS_SHARED_DIR_PATH` when using the library and that path will be used to place shared memory files. When you have -to determine the shared directory at runtime, define `BOOST_INTERPROCESS_SHARED_DIR_FUNC` and implement the function +define `BOOST_INTERPROCESS_SHARED_DIR_PATH` (and BOOST_INTERPROCESS_SHARED_DIR_WPATH in Windows systems) when using the library and that +path will be used to place shared memory files. When you have to determine the shared directory at runtime, +define `BOOST_INTERPROCESS_SHARED_DIR_FUNC` and implement the following functions [c++] @@ -6673,6 +6674,8 @@ to determine the shared directory at runtime, define `BOOST_INTERPROCESS_SHARED_ namespace interprocess { namespace ipcdetail { void get_shared_dir(std::string &shared_dir); + //wstring overload is only needed for Windows systems + void get_shared_dir(std::wstring &shared_dir); } } } @@ -6792,6 +6795,14 @@ thank them: [section:release_notes Release Notes] +[section:release_notes_boost_1_78_00 Boost 1.78 Release] + +* Fixed bugs: + * [@https://github.com/boostorg/interprocess/issues/145 GitHub #145 (['"1.76 now requires unicode paths on windows"])]. + +[endsect] + + [section:release_notes_boost_1_77_00 Boost 1.77 Release] * Interprocess no longer depends on Boost.DateTime. Instead, all timed diff --git a/include/boost/interprocess/detail/os_file_functions.hpp b/include/boost/interprocess/detail/os_file_functions.hpp index 6ff4cb5..25e83d8 100644 --- a/include/boost/interprocess/detail/os_file_functions.hpp +++ b/include/boost/interprocess/detail/os_file_functions.hpp @@ -104,7 +104,8 @@ template inline bool create_directory(const CharT *path) { return winapi::create_directory(path); } -inline bool remove_directory(const char *path) +template +inline bool remove_directory(const CharT *path) { return winapi::remove_directory(path); } inline bool get_temporary_path(char *buffer, std::size_t buf_len, std::size_t &required_len) diff --git a/include/boost/interprocess/detail/shared_dir_helpers.hpp b/include/boost/interprocess/detail/shared_dir_helpers.hpp index 6cc5eb1..93a1e25 100644 --- a/include/boost/interprocess/detail/shared_dir_helpers.hpp +++ b/include/boost/interprocess/detail/shared_dir_helpers.hpp @@ -161,18 +161,32 @@ inline void get_shared_dir_root(std::basic_string &dir_path) #else +#if defined(BOOST_INTERPROCESS_SHARED_DIR_PATH) + +inline void get_shared_dir(std::string &shared_dir) +{ + shared_dir = BOOST_INTERPROCESS_SHARED_DIR_PATH; +} + +#endif + +#if defined(BOOST_INTERPROCESS_SHARED_DIR_WPATH) + +inline void get_shared_dir(std::wstring &shared_dir) +{ + shared_dir = BOOST_INTERPROCESS_SHARED_DIR_WPATH; +} + +#endif + template inline void get_shared_dir(std::basic_string &shared_dir) { - #if defined(BOOST_INTERPROCESS_SHARED_DIR_PATH) - shared_dir = BOOST_INTERPROCESS_SHARED_DIR_PATH; - #else get_shared_dir_root(shared_dir); #if defined(BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME) shared_dir += shared_dir_constants::dir_separator(); get_bootstamp(shared_dir, true); #endif - #endif } #endif diff --git a/test/windows_shared_dir_path.cpp b/test/windows_shared_dir_path.cpp new file mode 100644 index 0000000..c716178 --- /dev/null +++ b/test/windows_shared_dir_path.cpp @@ -0,0 +1,91 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under 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) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include + +#ifdef BOOST_WINDOWS + +//Force user-defined get_shared_dir +#define BOOST_INTERPROCESS_SHARED_DIR_PATH boost::interprocess::ipcdetail::get_temporary_path() +#define BOOST_INTERPROCESS_SHARED_DIR_WPATH boost::interprocess::ipcdetail::get_temporary_wpath() +#include + +#include "get_process_id_name.hpp" + +#include +#include + +int main () +{ + using namespace boost::interprocess; + + int ret = 0; + + { + std::string pname= boost::interprocess::test::get_process_id_name(); + const char *const shm_name = pname.c_str(); + + shared_memory_object::remove(shm_name); + std::string shared_dir; + ipcdetail::get_shared_dir(shared_dir); + + std::string shm_path(shared_dir); + shm_path += "/"; + shm_path += shm_name; + { + shared_memory_object shm(create_only, shm_name, read_write); + } + + ret = ipcdetail::invalid_file() == ipcdetail::open_existing_file(shm_path.c_str(), read_only) ? + 1 : 0; + if(ret) + { + std::cerr << "Error opening user get_shared_dir()/shm file" << std::endl; + return ret; + } + + shared_memory_object::remove(shm_name); + } + { + std::wstring wpname= boost::interprocess::test::get_process_id_wname(); + const wchar_t *const wshm_name = wpname.c_str(); + + shared_memory_object::remove(wshm_name); + std::wstring wshared_dir; + ipcdetail::get_shared_dir(wshared_dir); + + shared_memory_object::remove(wshm_name); + std::wstring wshm_path(wshared_dir); + wshm_path += L"/"; + wshm_path += wshm_name; + { + shared_memory_object shm(create_only, wshm_name, read_write); + } + ret = ipcdetail::invalid_file() == ipcdetail::open_existing_file(wshm_path.c_str(), read_only) ? + 1 : 0; + if(ret) + { + std::cerr << "Error opening user get_shared_dir()/wshm file" << std::endl; + return ret; + } + shared_memory_object::remove(wshm_name); + } + + return ret; +} + +#else + +int main() +{ + return 0; +} + +#endif //#ifdef BOOST_WINDOWS