Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added -d postfix to libs. Adjust int casting. #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ if(WIN32 OR RUN_WITH_WINE)
OUTPUT_NAME "nowide"
)

set_target_properties (nowide-shared PROPERTIES DEBUG_POSTFIX "-d")

add_library(nowide-static STATIC libs/nowide/src/iostream.cpp)
set_target_properties(nowide-static PROPERTIES
CLEAN_DIRECT_OUTPUT 1
OUTPUT_NAME "nowide"
)

set_target_properties (nowide-static PROPERTIES DEBUG_POSTFIX "-d")

if(MSVC)
set_target_properties(nowide-static PROPERTIES PREFIX "lib")
endif()
Expand Down
2 changes: 1 addition & 1 deletion boost/nowide/cenv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace nowide {
return 0;
if(n >= buf_size) {
tmp.resize(n+1,L'\0');
n = GetEnvironmentVariableW(name.c_str(),&tmp[0],tmp.size() - 1);
n = GetEnvironmentVariableW(name.c_str(),&tmp[0], static_cast<unsigned long>(tmp.size() - 1));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to https://msdn.microsoft.com/en-us/library/windows/desktop/ms683188(v=vs.85).aspx, cast should be written as static_cast<DWORD>

// The size may have changed
if(n >= tmp.size() - 1)
return 0;
Expand Down
30 changes: 16 additions & 14 deletions libs/nowide/src/iostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Note: does all pointer-math in DWORD, assumes no overflows.

#define BOOST_NOWIDE_SOURCE
#include <boost/nowide/iostream.hpp>
#include <boost/nowide/convert.hpp>
Expand Down Expand Up @@ -43,8 +45,8 @@ namespace details {
{
if(!handle_)
return -1;
int n = pptr() - pbase();
int r = 0;
DWORD n = static_cast<DWORD>(pptr() - pbase());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead DWORD, pointers math should be calculated with ptrdiff_t type.

DWORD r = 0;

if(n > 0 && (r=write(pbase(),n)) < 0)
return -1;
Expand All @@ -59,29 +61,29 @@ namespace details {
}
private:

int write(char const *p,int n)
DWORD write(char const *p, DWORD n)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that size_t is better for 64-bit portability

{
namespace uf = boost::locale::utf;
char const *b = p;
char const *e = p+n;
DWORD size=0;
if(!isatty_) {
if(!WriteFile(handle_,p,n,&size,0) || static_cast<int>(size) != n)
if(!WriteFile(handle_,p,n,&size,0) || size != n)
return -1;
return n;
}
if(n > buffer_size)
return -1;
wchar_t *out = wbuffer_;
uf::code_point c;
size_t decoded = 0;
DWORD decoded = 0;
while(p < e && (c = uf::utf_traits<char>::decode(p,e))!=uf::illegal && c!=uf::incomplete) {
out = uf::utf_traits<wchar_t>::encode(c,out);
decoded = p-b;
decoded = static_cast<DWORD>(p-b);
}
if(c==uf::illegal)
return -1;
if(!WriteConsoleW(handle_,wbuffer_,out - wbuffer_,&size,0))
if(!WriteConsoleW(handle_,wbuffer_, static_cast<DWORD>(out - wbuffer_),&size,0))
return -1;
return decoded;
}
Expand Down Expand Up @@ -167,19 +169,19 @@ namespace details {
return read_bytes;
}
DWORD read_wchars = 0;
size_t n = wbuffer_size - wsize_;
if(!ReadConsoleW(handle_,wbuffer_,n,&read_wchars,0))
DWORD n = wbuffer_size - wsize_;
if(!ReadConsoleW(handle_,wbuffer_, n, &read_wchars,0))
return 0;
wsize_ += read_wchars;
char *out = buffer_;
wchar_t *b = wbuffer_;
wchar_t *e = b + wsize_;
wchar_t *p = b;
uf::code_point c;
wsize_ = e-p;
wsize_ = static_cast<DWORD>(e-p);
while(p < e && (c = uf::utf_traits<wchar_t>::decode(p,e))!=uf::illegal && c!=uf::incomplete) {
out = uf::utf_traits<char>::encode(c,out);
wsize_ = e-p;
wsize_ = static_cast<DWORD>(e-p);
}

if(c==uf::illegal)
Expand All @@ -193,13 +195,13 @@ namespace details {
return out - buffer_;
}

static const size_t buffer_size = 1024 * 3;
static const size_t wbuffer_size = 1024;
static const DWORD buffer_size = 1024 * 3;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size_t was better for 64-bit portability

static const DWORD wbuffer_size = 1024;
char buffer_[buffer_size];
wchar_t wbuffer_[buffer_size]; // for null
HANDLE handle_;
bool isatty_;
int wsize_;
DWORD wsize_;
std::vector<char> pback_buffer_;
};

Expand Down