Some changes to make the forwarding/implementation way work on MSVC.

This commit is contained in:
Steffen Schümann 2019-03-24 12:46:19 +01:00
parent 243963558e
commit e8b2bee859
4 changed files with 90 additions and 85 deletions

View File

@ -66,32 +66,37 @@
#define GHC_EXPAND_IMPL
#define GHC_INLINE
#ifdef GHC_OS_WINDOWS
# define GHC_FS_API __declspec(dllexport)
#define GHC_FS_API
#define GHC_FS_API_CLASS
#else
#define GHC_FS_API __attribute__((visibility("default")))
#define GHC_FS_API_CLASS __attribute__((visibility("default")))
#endif
#elif defined(GHC_FILESYSTEM_FWD)
#define GHC_INLINE
#ifdef GHC_OS_WINDOWS
# define GHC_FS_API __declspec(dllimport)
#define GHC_FS_API extern
#define GHC_FS_API_CLASS
#else
# define GHC_FS_API
#define GHC_FS_API extern
#define GHC_FS_API_CLASS
#endif
#else
#define GHC_EXPAND_IMPL
#define GHC_INLINE inline
#define GHC_FS_API
#define GHC_FS_API_CLASS
#endif
#ifdef GHC_EXPAND_IMPL
#ifdef GHC_OS_WINDOWS
#include <windows.h>
#include <shellapi.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <wchar.h>
#include <windows.h>
#include <winioctl.h>
#include <shellapi.h>
#else
#include <dirent.h>
#include <fcntl.h>
@ -147,7 +152,7 @@ namespace ghc {
namespace filesystem {
// temporary existing exception type for yet unimplemented parts
class GHC_FS_API not_implemented_exception : public std::logic_error
class GHC_FS_API_CLASS not_implemented_exception : public std::logic_error
{
public:
not_implemented_exception()
@ -157,7 +162,7 @@ public:
};
// 30.10.8 class path
class GHC_FS_API path
class GHC_FS_API_CLASS path
{
public:
using value_type = std::string::value_type;
@ -369,7 +374,7 @@ template <class InputIterator>
path u8path(InputIterator first, InputIterator last);
// 30.10.9 class filesystem_error
class GHC_FS_API filesystem_error : public std::system_error
class GHC_FS_API_CLASS filesystem_error : public std::system_error
{
public:
filesystem_error(const std::string& what_arg, std::error_code ec);
@ -385,7 +390,7 @@ private:
path _p1, _p2;
};
class GHC_FS_API path::iterator
class GHC_FS_API_CLASS path::iterator
{
public:
using value_type = const path;
@ -495,7 +500,7 @@ enum class directory_options : uint16_t {
};
// 30.10.11 class file_status
class GHC_FS_API file_status
class GHC_FS_API_CLASS file_status
{
public:
// 30.10.11.1 constructors and destructor
@ -522,7 +527,7 @@ private:
using file_time_type = std::chrono::time_point<std::chrono::system_clock>;
// 30.10.12 Class directory_entry
class GHC_FS_API directory_entry
class GHC_FS_API_CLASS directory_entry
{
public:
// 30.10.12.1 constructors and destructor
@ -598,10 +603,10 @@ private:
};
// 30.10.13 Class directory_iterator
class GHC_FS_API directory_iterator
class GHC_FS_API_CLASS directory_iterator
{
public:
class GHC_FS_API proxy
class GHC_FS_API_CLASS proxy
{
public:
const directory_entry& operator*() const& noexcept { return _dir_entry; }
@ -660,7 +665,7 @@ GHC_FS_API directory_iterator begin(directory_iterator iter) noexcept;
GHC_FS_API directory_iterator end(const directory_iterator&) noexcept;
// 30.10.14 class recursive_directory_iterator
class GHC_FS_API recursive_directory_iterator
class GHC_FS_API_CLASS recursive_directory_iterator
{
public:
using iterator_category = std::input_iterator_tag;
@ -947,7 +952,7 @@ typedef basic_ofstream<wchar_t> wofstream;
typedef basic_fstream<char> fstream;
typedef basic_fstream<wchar_t> wfstream;
class GHC_FS_API u8arguments
class GHC_FS_API_CLASS u8arguments
{
public:
u8arguments(int& argc, char**& argv);
@ -957,10 +962,7 @@ public:
_refargv = _argv;
}
bool valid() const
{
return _isvalid;
}
bool valid() const { return _isvalid; }
private:
int _argc;
@ -995,7 +997,7 @@ namespace detail {
invalid_argument,
};
GHC_FS_API std::error_code make_error_code(portable_error err);
}
} // namespace detail
namespace detail {
@ -1152,7 +1154,7 @@ GHC_INLINE unsigned consumeUtf8Fragment(const unsigned state, const uint8_t frag
return state == S_RJCT ? static_cast<unsigned>(S_RJCT) : static_cast<unsigned>((utf8_state_info[category + 16] >> (state << 2)) & 0xf);
}
} // detail
} // namespace detail
#endif
@ -1238,7 +1240,7 @@ inline std::string toUtf8(const SourceType* unicodeString)
return toUtf8(std::basic_string<SourceType, std::char_traits<SourceType>>(unicodeString));
}
} // detail
} // namespace detail
#ifdef GHC_EXPAND_IMPL
@ -1637,7 +1639,9 @@ GHC_INLINE file_status symlink_status_ex(const path& p, std::error_code& ec, uin
}
return ec ? file_status(file_type::none) : fs;
#else
(void)sz; (void)nhl; (void)lwt;
(void)sz;
(void)nhl;
(void)lwt;
struct ::stat fs;
auto result = ::lstat(p.c_str(), &fs);
if (result == 0) {

View File

@ -42,3 +42,6 @@ target_link_libraries(multifile_test ghc_filesystem)
add_executable(fwd_impl_test fwd_test.cpp impl_test.cpp)
target_link_libraries(fwd_impl_test ghc_filesystem)
if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
target_compile_definitions(fwd_impl_test PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

View File

@ -34,12 +34,15 @@
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <random>
#include <sstream>
#include <thread>
#ifndef WIN32
#ifdef WIN32
#define NOMINMAX
#include <windows.h>
#else
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
@ -53,7 +56,7 @@ using namespace std::filesystem;
using ifstream = std::ifstream;
using ofstream = std::ofstream;
using fstream = std::fstream;
}
} // namespace fs
#ifdef __GNUC__
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif
@ -75,7 +78,7 @@ using namespace ghc::filesystem;
using ifstream = ghc::filesystem::ifstream;
using ofstream = ghc::filesystem::ofstream;
using fstream = ghc::filesystem::fstream;
}
} // namespace fs
#endif
#ifndef GHC_FILESYSTEM_FWD_TEST
@ -110,7 +113,8 @@ struct StringMaker<fs::perms>
template <>
struct StringMaker<fs::file_time_type>
{
static std::string convert(fs::file_time_type const& value) {
static std::string convert(fs::file_time_type const& value)
{
std::time_t t = to_time_t(value);
std::tm ttm = *std::localtime(&t);
std::ostringstream os;
@ -135,8 +139,7 @@ public:
filename += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[rng()];
}
_path = fs::canonical(fs::temp_directory_path()) / filename;
}
while(fs::exists(_path));
} while (fs::exists(_path));
fs::create_directories(_path);
if (opt == TempOpt::change_path) {
_orig_dir = fs::current_path();
@ -210,7 +213,6 @@ static bool has_host_root_name_support()
return fs::path("//host").has_root_name();
}
template <class T>
class TestAllocator
{
@ -218,17 +220,14 @@ public:
using value_type = T;
TestAllocator() noexcept {}
template <class U> TestAllocator(TestAllocator<U> const&) noexcept {}
value_type* allocate(std::size_t n)
template <class U>
TestAllocator(TestAllocator<U> const&) noexcept
{
return static_cast<value_type*>(::operator new (n*sizeof(value_type)));
}
void deallocate(value_type* p, std::size_t) noexcept
{
::operator delete(p);
}
value_type* allocate(std::size_t n) { return static_cast<value_type*>(::operator new(n * sizeof(value_type))); }
void deallocate(value_type* p, std::size_t) noexcept { ::operator delete(p); }
};
template <class T, class U>
@ -243,8 +242,6 @@ bool operator!=(TestAllocator<T> const& x, TestAllocator<U> const& y) noexcept
return !(x == y);
}
TEST_CASE("Temporary Directory", "[temp dir]")
{
fs::path tempPath;

View File

@ -3,6 +3,7 @@
// where exactly one cpp includes fs_impl.hpp and all others use
// fs_fwd.hpp (to test this with maximum functionality, the unit tests
// are included here, signaling they should only include the fs_fwd.hpp)
#define NOMINMAX
#include <ghc/fs_impl.hpp>
#define CATCH_CONFIG_MAIN
#include "catch.hpp"