Skip to content

Commit

Permalink
Making sure UNICODE on Windows does not break by default
Browse files Browse the repository at this point in the history
- flyby: Fixed typo in iostreams type declaration
- flyby: rename leftover BOOST_ names in logging library
  • Loading branch information
hkaiser committed May 22, 2017
1 parent 5aed010 commit 0c97fd1
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 70 deletions.
2 changes: 1 addition & 1 deletion hpx/components/iostreams/ostream.hpp
Expand Up @@ -38,7 +38,7 @@ namespace hpx { namespace iostreams
struct buffer_sink;
}

template <typename Char = char, typename Sink = detail::buffer_sink<char> >
template <typename Char = char, typename Sink = detail::buffer_sink<Char> >
struct ostream;

///////////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 1 addition & 13 deletions hpx/util/logging/defaults.hpp
Expand Up @@ -66,15 +66,6 @@ If you want to override any of the above, you should do the following:
*/

// define HPX_LOG_USE_WCHAR_T if you want your char type to be 'wchar_t'

#if defined(HPX_WINDOWS) && !defined(HPX_LOG_DONOT_USE_WCHAR_T)
#if defined( UNICODE) || defined(_UNICODE)
#undef HPX_LOG_USE_WCHAR_T
#define HPX_LOG_USE_WCHAR_T
#endif
#endif

// forward defines

namespace filter {
Expand All @@ -94,11 +85,8 @@ If you want to override any of the above, you should do the following:

struct default_types
{
#ifdef HPX_LOG_USE_WCHAR_T
typedef wchar_t char_type;
#else
typedef char char_type;
#endif

// this is the type we use to hold a string, internally
typedef std::basic_string<char_type> hold_string_type;

Expand Down
32 changes: 8 additions & 24 deletions hpx/util/logging/detail/scoped_log.hpp
Expand Up @@ -28,31 +28,15 @@
namespace hpx { namespace util { namespace logging {


#ifndef HPX_LOG_USE_WCHAR_T

#define BOOST_SCOPED_LOG_WITH_CLASS_NAME(logger, msg, class_name) \
#define HPX_SCOPED_LOG_WITH_CLASS_NAME(logger, msg, class_name) \
struct class_name { \
class_name() { logger ( "start of " msg ) ;} \
~class_name() { logger ( " end of " msg ) ; } \
} HPX_LOG_CONCATENATE(log_, __LINE__);

#define BOOST_SCOPED_LOG(logger, msg) \
BOOST_SCOPED_LOG_WITH_CLASS_NAME(logger, msg, \
HPX_LOG_CONCATENATE(boost_scoped_log,__LINE__) )

#else
// unicode
#define BOOST_SCOPED_LOG_WITH_CLASS_NAME(logger, msg, class_name) \
struct class_name { \
class_name() { logger ( L"start of " msg ) ;} \
~class_name() { logger ( L" end of " msg ) ; } \
} HPX_LOG_CONCATENATE(log_, __LINE__);

#define BOOST_SCOPED_LOG(logger, msg) \
BOOST_SCOPED_LOG_WITH_CLASS_NAME(logger, msg, \
HPX_LOG_CONCATENATE(boost_scoped_log,__LINE__) )

#endif
#define HPX_SCOPED_LOG(logger, msg) \
HPX_SCOPED_LOG_WITH_CLASS_NAME(logger, msg, \
HPX_LOG_CONCATENATE(hpx_scoped_log,__LINE__) )

// default scoped write - in case your gather
// class .read_msg().out() returns an STL ostream
Expand Down Expand Up @@ -110,7 +94,7 @@ namespace detail {



#define BOOST_SCOPED_LOG_CTX_IMPL(logger_macro, operator_, class_name) \
#define HPX_SCOPED_LOG_CTX_IMPL(logger_macro, operator_, class_name) \
struct class_name : ::hpx::util::logging::detail::scoped_gather_base<> { \
class_name() : m_is_enabled(false) { } \
~class_name() { if ( m_is_enabled) \
Expand All @@ -123,11 +107,11 @@ struct class_name : ::hpx::util::logging::detail::scoped_gather_base<> { \



// note: to use BOOST_SCOPED_LOG_CTX, you need to #include
// note: to use HPX_SCOPED_LOG_CTX, you need to #include
// <hpx/util/logging/gather/ostream_like.hpp>
// This is included by default, in #include <hpx/util/logging/format_fwd.hpp>
#define BOOST_SCOPED_LOG_CTX(logger) \
BOOST_SCOPED_LOG_CTX_IMPL(logger, << , HPX_LOG_CONCATENATE(boost_scoped_log,__LINE__) )
#define HPX_SCOPED_LOG_CTX(logger) \
HPX_SCOPED_LOG_CTX_IMPL(logger, << , HPX_LOG_CONCATENATE(hpx_scoped_log,__LINE__) )


}}}
Expand Down
10 changes: 0 additions & 10 deletions hpx/util/logging/detail/time_format_holder.hpp
Expand Up @@ -153,13 +153,8 @@ struct time_format_holder {

// ignore value at index 0
// - it's there so that I don't have to test for an index being -1
#ifdef HPX_LOG_USE_WCHAR_T
swprintf( buffer, m_format.c_str(), vals[1], vals[2], vals[3],
vals[4], vals[5], vals[6], vals[7], vals[8], vals[9], vals[10] );
#else
sprintf( buffer, m_format.c_str(), vals[1], vals[2], vals[3],
vals[4], vals[5], vals[6], vals[7], vals[8], vals[9], vals[10] );
#endif
}

void write_time(char_type buffer[], int day, int month, int year,
Expand All @@ -175,13 +170,8 @@ struct time_format_holder {

// ignore value at index 0
// - it's there so that I don't have to test for an index being -1
#ifdef HPX_LOG_USE_WCHAR_T
swprintf( buffer, m_format.c_str(), vals[1], vals[2], vals[3],
vals[4], vals[5], vals[6], vals[7]);
#else
sprintf( buffer, m_format.c_str(), vals[1], vals[2], vals[3],
vals[4], vals[5], vals[6], vals[7] );
#endif
}

private:
Expand Down
12 changes: 0 additions & 12 deletions hpx/util/logging/format/destination/defaults.hpp
Expand Up @@ -38,11 +38,7 @@ template<class convert_dest = do_convert_destination > struct cout_t : is_generi
hpx::util::logging::op_equal::always_equal {

template<class msg_type> void operator()(const msg_type & msg) const {
#ifndef HPX_LOG_USE_WCHAR_T
convert_dest::write(msg, std::cout);
#else
convert_dest::write(msg, std::wcout);
#endif
}
};

Expand All @@ -54,11 +50,7 @@ template<class convert_dest = do_convert_destination > struct cerr_t : is_generi
hpx::util::logging::op_equal::always_equal {

template<class msg_type> void operator()(const msg_type & msg) const {
#ifndef HPX_LOG_USE_WCHAR_T
convert_dest::write(msg, std::cerr);
#else
convert_dest::write(msg, std::wcerr);
#endif
}
};

Expand Down Expand Up @@ -115,11 +107,7 @@ hpx::util::logging::op_equal::always_equal {

template<class msg_type> void operator()(const msg_type & msg) const {
#ifdef HPX_WINDOWS
#ifndef HPX_LOG_USE_WCHAR_T
::OutputDebugStringA( convert_dest::do_convert(msg, into<const char*>() ) );
#else
::OutputDebugStringW( convert_dest::do_convert(msg, into<const wchar_t*>() ) );
#endif
#else
// non windows - dump to console
std::cout << msg;
Expand Down
4 changes: 0 additions & 4 deletions hpx/util/logging/format/formatter/time_strf.hpp
Expand Up @@ -58,11 +58,7 @@ template<class convert = do_convert_format::prepend> struct time_strf_t : is_gen
char_type buffer[64];
::time_t t = ::time (nullptr);
::tm t_details = m_localtime ? *localtime( &t) : *gmtime( &t);
#ifdef HPX_LOG_USE_WCHAR_T
if (0 != wcsftime (buffer, sizeof (buffer), m_format.c_str (), &t_details))
#else
if (0 != strftime (buffer, sizeof (buffer), m_format.c_str (), &t_details))
#endif
convert::write(buffer, msg);
}

Expand Down
10 changes: 5 additions & 5 deletions hpx/util/plugin/detail/dll_windows.hpp
Expand Up @@ -162,7 +162,7 @@ namespace hpx { namespace util { namespace plugin {
// a symbol, the LoadLibrary function increases the refcnt of the dll
// so in the end the dll class holds one refcnt and so does every
// symbol.
HMODULE handle = ::LoadLibrary(dll_name.c_str());
HMODULE handle = ::LoadLibraryA(dll_name.c_str());
if (!handle) {
std::ostringstream str;
str << "Hpx.Plugin: Could not open shared library '"
Expand Down Expand Up @@ -191,11 +191,11 @@ namespace hpx { namespace util { namespace plugin {
if (dll_name.empty()) {
// load main module
char buffer[_MAX_PATH];
::GetModuleFileName(nullptr, buffer, sizeof(buffer));
::GetModuleFileNameA(nullptr, buffer, sizeof(buffer));
dll_name = buffer;
}

dll_handle = ::LoadLibrary(dll_name.c_str());
dll_handle = ::LoadLibraryA(dll_name.c_str());
if (!dll_handle) {
std::ostringstream str;
str << "Hpx.Plugin: Could not open shared library '"
Expand All @@ -222,7 +222,7 @@ namespace hpx { namespace util { namespace plugin {
if (ec) return buffer;

DWORD name_length =
GetModuleFileName(dll_handle, buffer, sizeof(buffer));
GetModuleFileNameA(dll_handle, buffer, sizeof(buffer));

if (name_length <= 0) {
std::ostringstream str;
Expand All @@ -235,7 +235,7 @@ namespace hpx { namespace util { namespace plugin {
}

// extract the directory name
PathRemoveFileSpec(buffer);
PathRemoveFileSpecA(buffer);

if (&ec != &throws)
ec = make_success_code();
Expand Down
2 changes: 1 addition & 1 deletion src/util/find_prefix.cpp
Expand Up @@ -128,7 +128,7 @@ namespace hpx { namespace util
HPX_UNUSED(argv0);

char exe_path[MAX_PATH + 1] = { '\0' };
if (!GetModuleFileName(nullptr, exe_path, sizeof(exe_path)))
if (!GetModuleFileNameA(nullptr, exe_path, sizeof(exe_path)))
{
HPX_THROW_EXCEPTION(hpx::dynamic_link_failure,
"get_executable_filename",
Expand Down

0 comments on commit 0c97fd1

Please sign in to comment.