Fixes #145 ("1.76 now requires unicode paths on windows")

This commit is contained in:
Ion Gaztañaga
2021-08-12 01:41:26 +02:00
parent 7b2a37e614
commit 9ac7eb3d84
4 changed files with 124 additions and 7 deletions

View File

@@ -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

View File

@@ -104,7 +104,8 @@ template<class CharT>
inline bool create_directory(const CharT *path)
{ return winapi::create_directory(path); }
inline bool remove_directory(const char *path)
template <class CharT>
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)

View File

@@ -161,18 +161,32 @@ inline void get_shared_dir_root(std::basic_string<CharT> &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<class CharT>
inline void get_shared_dir(std::basic_string<CharT> &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<CharT>::dir_separator();
get_bootstamp(shared_dir, true);
#endif
#endif
}
#endif

View File

@@ -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 <boost/config.hpp>
#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 <string>
#include "get_process_id_name.hpp"
#include <boost/interprocess/shared_memory_object.hpp>
#include <iostream>
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