Skip to content

Commit

Permalink
Moving our safeint3 to be in its own namespace to not conflict with a…
Browse files Browse the repository at this point in the history
…ny Visual Studio version.
  • Loading branch information
stgates committed Mar 17, 2015
1 parent 84bdc2b commit ae828bd
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 45 deletions.
8 changes: 4 additions & 4 deletions Release/include/cpprest/containerstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ namespace Concurrency { namespace streams {
// seek beyond the current write_end.
_ASSERTE(m_current_position <= m_data.size());

SafeSize readhead(m_current_position);
SafeSize writeend(m_data.size());
msl::safeint3::SafeInt<size_t> readhead(m_current_position);
msl::safeint3::SafeInt<size_t> writeend(m_data.size());
return (size_t)(writeend - readhead);
}

Expand Down Expand Up @@ -434,8 +434,8 @@ namespace Concurrency { namespace streams {
if (!can_satisfy(count))
return 0;

SafeSize request_size(count);
SafeSize read_size = request_size.Min(in_avail());
msl::safeint3::SafeInt<size_t> request_size(count);
msl::safeint3::SafeInt<size_t> read_size = request_size.Min(in_avail());

size_t newPos = m_current_position + read_size;

Expand Down
16 changes: 4 additions & 12 deletions Release/include/cpprest/details/SafeInt3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,11 @@ SAFEINT_DISABLE_SHIFT_ASSERT - Set this option if you don't want to assert
#define __int64 long long
#endif

#if defined VISUAL_STUDIO_SAFEINT_COMPAT
namespace msl
{

namespace utilities
namespace safeint3
{
#endif

// catch these to handle errors
// Currently implemented code values:
Expand All @@ -555,10 +553,8 @@ enum SafeIntError
SafeIntDivideByZero
};

#if defined VISUAL_STUDIO_SAFEINT_COMPAT
} // utilities
} // safeint3
} // msl
#endif


/*
Expand Down Expand Up @@ -637,13 +633,11 @@ enum SafeIntError
#define SAFEINT_NOTHROW throw()
#endif

#if defined VISUAL_STUDIO_SAFEINT_COMPAT
namespace msl
{

namespace utilities
namespace safeint3
{
#endif

// If you would like to use your own custom assert
// Define SAFEINT_ASSERT
Expand Down Expand Up @@ -7050,8 +7044,6 @@ SafeInt< T, E > operator |( U lhs, SafeInt< T, E > rhs ) SAFEINT_NOTHROW
#endif
#endif //SAFEINT_HPP

#if defined VISUAL_STUDIO_SAFEINT_COMPAT
} // utilities
} // msl
#endif
} // safeint3

1 change: 0 additions & 1 deletion Release/include/cpprest/details/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#endif

#include "cpprest/details/SafeInt3.hpp"
typedef SafeInt<size_t> SafeSize;

namespace utility
{
Expand Down
2 changes: 1 addition & 1 deletion Release/include/cpprest/details/fileio.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace details
char *m_buffer;

size_t m_bufoff; // File position that the start of the buffer represents.
SafeSize m_bufsize; // Buffer allocated size, as actually allocated.
msl::safeint3::SafeInt<size_t> m_bufsize; // Buffer allocated size, as actually allocated.
size_t m_buffill; // Amount of file data actually in the buffer

std::ios_base::openmode m_mode;
Expand Down
6 changes: 3 additions & 3 deletions Release/include/cpprest/filestream.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ namespace details {
if ( m_info->m_buffer == nullptr || m_info->m_buffill == 0 ) return 0;
if ( m_info->m_bufoff > m_info->m_rdpos || (m_info->m_bufoff+m_info->m_buffill) < m_info->m_rdpos ) return 0;

SafeInt<size_t> rdpos(m_info->m_rdpos);
SafeInt<size_t> buffill(m_info->m_buffill);
SafeInt<size_t> bufpos = rdpos - m_info->m_bufoff;
msl::safeint3::SafeInt<size_t> rdpos(m_info->m_rdpos);
msl::safeint3::SafeInt<size_t> buffill(m_info->m_buffill);
msl::safeint3::SafeInt<size_t> bufpos = rdpos - m_info->m_bufoff;

return buffill - bufpos;
}
Expand Down
4 changes: 2 additions & 2 deletions Release/include/cpprest/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,9 @@ namespace json
/// <returns>A reference to the value kept in the field.</returns>
json::value& operator[](size_type index)
{
SafeInt<size_type> nMinSize(index);
msl::safeint3::SafeInt<size_type> nMinSize(index);
nMinSize += 1;
SafeInt<size_type> nlastSize(m_elements.size());
msl::safeint3::SafeInt<size_type> nlastSize(m_elements.size());
if (nlastSize < nMinSize)
m_elements.resize(nMinSize);

Expand Down
8 changes: 4 additions & 4 deletions Release/include/cpprest/producerconsumerstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ namespace Concurrency { namespace streams {
// Allocate a new block if necessary
if ( m_blocks.empty() || m_blocks.back()->wr_chars_left() < count )
{
SafeSize alloc = m_alloc_size.Max(count);
msl::safeint3::SafeInt<size_t> alloc = m_alloc_size.Max(count);
m_blocks.push_back(std::make_shared<_block>((size_t)alloc));
}

Expand Down Expand Up @@ -468,7 +468,7 @@ namespace Concurrency { namespace streams {
// Read up to count characters from the block
size_t read(_Out_writes_ (count) _CharType * dest, _In_ size_t count, bool advance = true)
{
SafeSize avail(rd_chars_left());
msl::safeint3::SafeInt<size_t> avail(rd_chars_left());
auto countRead = static_cast<size_t>(avail.Min(count));

_CharType * beg = rbegin();
Expand All @@ -492,7 +492,7 @@ namespace Concurrency { namespace streams {
// Write count characters into the block
size_t write(const _CharType * src, size_t count)
{
SafeSize avail(wr_chars_left());
msl::safeint3::SafeInt<size_t> avail(wr_chars_left());
auto countWritten = static_cast<size_t>(avail.Min(count));

const _CharType * srcEnd = src + countWritten;
Expand Down Expand Up @@ -647,7 +647,7 @@ namespace Concurrency { namespace streams {
std::ios_base::openmode m_mode;

// Default block size
SafeSize m_alloc_size;
msl::safeint3::SafeInt<size_t> m_alloc_size;

// Block used for alloc/commit
std::shared_ptr<_block> m_allocBlock;
Expand Down
16 changes: 8 additions & 8 deletions Release/include/cpprest/rawptrstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ namespace Concurrency { namespace streams {
// seek beyond the current size.
_ASSERTE(m_current_position <= m_size);

SafeSize readhead(m_current_position);
SafeSize writeend(m_size);
msl::safeint3::SafeInt<size_t> readhead(m_current_position);
msl::safeint3::SafeInt<size_t> writeend(m_size);
return (size_t)(writeend - readhead);
}

Expand Down Expand Up @@ -178,7 +178,7 @@ namespace Concurrency { namespace streams {

virtual pplx::task<size_t> _putn(const _CharType *ptr, size_t count)
{
SafeSize newSize = SafeSize(count) + m_current_position;
msl::safeint3::SafeInt<size_t> newSize = msl::safeint3::SafeInt<size_t>(count) + m_current_position;
if ( newSize > m_size )
return pplx::task_from_exception<size_t>(std::make_exception_ptr(std::runtime_error("Writing past the end of the buffer")));
return pplx::task_from_result<size_t>(this->write(ptr, count));
Expand All @@ -193,8 +193,8 @@ namespace Concurrency { namespace streams {
{
if (!this->can_write()) return nullptr;

SafeSize readhead(m_current_position);
SafeSize writeend(m_size);
msl::safeint3::SafeInt<size_t> readhead(m_current_position);
msl::safeint3::SafeInt<size_t> writeend(m_size);
size_t space_left = (size_t)(writeend - readhead);

if (space_left < count) return nullptr;
Expand Down Expand Up @@ -476,8 +476,8 @@ namespace Concurrency { namespace streams {
if (!can_satisfy(count))
return 0;

SafeSize request_size(count);
SafeSize read_size = request_size.Min(in_avail());
msl::safeint3::SafeInt<size_t> request_size(count);
msl::safeint3::SafeInt<size_t> read_size = request_size.Min(in_avail());

size_t newPos = m_current_position + read_size;

Expand Down Expand Up @@ -506,7 +506,7 @@ namespace Concurrency { namespace streams {
{
if (!this->can_write() || (count == 0)) return 0;

SafeSize newSize = SafeSize(count) + m_current_position;
msl::safeint3::SafeInt<size_t> newSize = msl::safeint3::SafeInt<size_t>(count) +m_current_position;

if ( newSize > m_size )
throw std::runtime_error("Writing past the end of the buffer");
Expand Down
2 changes: 1 addition & 1 deletion Release/src/http/client/http_client_winhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ class winhttp_client : public _http_client_communicator
static void _multiple_segment_write_data(_In_ winhttp_request_context * p_request_context)
{
auto rbuf = p_request_context->_get_readbuffer();
SafeInt<utility::size64_t> safeCount = p_request_context->m_remaining_to_write;
msl::safeint3::SafeInt<utility::size64_t> safeCount = p_request_context->m_remaining_to_write;
safeCount = safeCount.Min(p_request_context->m_http_client->client_config().chunksize());

uint8_t* block = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Release/src/http/client/http_client_winrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class IRequestStream
auto buffer = context->_get_readbuffer();

// Do not read more than the specified read_length
SafeSize safe_count = static_cast<size_t>(cb);
msl::safeint3::SafeInt<size_t> safe_count = static_cast<size_t>(cb);
size_t size_to_read = safe_count.Min(m_read_length);

const size_t count = buffer.getn((uint8_t *)pv, size_to_read).get();
Expand Down
8 changes: 4 additions & 4 deletions Release/src/http/listener/http_server_httpsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ void windows_request_context::async_process_request(HTTP_REQUEST_ID request_id,
// Save the http_request as the member of windows_request_context for the callback use.
m_msg = msg;

m_request_buffer = std::unique_ptr<unsigned char[]>(new unsigned char[SafeInt<unsigned long>(headers_size)]);
m_request_buffer = std::unique_ptr<unsigned char[]>(new unsigned char[msl::safeint3::SafeInt<unsigned long>(headers_size)]);
m_request = (HTTP_REQUEST *) m_request_buffer.get();

// The read_headers_io_completion callback function.
Expand Down Expand Up @@ -709,8 +709,8 @@ void windows_request_context::async_process_response()

size_t content_length = m_response._get_impl()->_get_content_length();

m_headers = std::unique_ptr<HTTP_UNKNOWN_HEADER []>(new HTTP_UNKNOWN_HEADER[SafeSize(m_response.headers().size())]);
m_headers_buffer.resize(SafeSize(m_response.headers().size()) * 2);
m_headers = std::unique_ptr<HTTP_UNKNOWN_HEADER []>(new HTTP_UNKNOWN_HEADER[msl::safeint3::SafeInt<size_t>(m_response.headers().size())]);
m_headers_buffer.resize(msl::safeint3::SafeInt<size_t>(m_response.headers().size()) * 2);

win_api_response.Headers.UnknownHeaderCount = (USHORT)m_response.headers().size();
win_api_response.Headers.pUnknownHeaders = m_headers.get();
Expand Down Expand Up @@ -810,7 +810,7 @@ void windows_request_context::transmit_body()
// In both cases here we could perform optimizations to try and use acquire on the streams to avoid an extra copy.
if ( m_sending_in_chunks )
{
SafeSize safeCount = m_remaining_to_write;
msl::safeint3::SafeInt<size_t> safeCount = m_remaining_to_write;
size_t next_chunk_size = safeCount.Min(CHUNK_SIZE);
m_body_data.resize(CHUNK_SIZE);

Expand Down
4 changes: 2 additions & 2 deletions Release/src/streams/fileio_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ _filestream_callback_fill_buffer<Func> *create_callback(_In_ _file_info *info, F

size_t _fill_buffer_fsb(_In_ _file_info_impl *fInfo, _In_ _filestream_callback *callback, size_t count, size_t char_size)
{
SafeSize safeCount = count;
msl::safeint3::SafeInt<size_t> safeCount = count;

if ( fInfo->m_buffer == nullptr || safeCount > fInfo->m_bufsize )
{
Expand Down Expand Up @@ -848,7 +848,7 @@ size_t __cdecl _putn_fsb(_In_ streams::details::_file_info *info, _In_ streams::
return (size_t)-1;
}

std::shared_ptr<uint8_t> buf(new uint8_t[SafeSize(count*char_size)]);
std::shared_ptr<uint8_t> buf(new uint8_t[msl::safeint3::SafeInt<size_t>(count*char_size)]);
memcpy(buf.get(), ptr, count*char_size);

// To preserve the async write order, we have to move the write head before read.
Expand Down
4 changes: 2 additions & 2 deletions Release/src/streams/fileio_winrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ _filestream_callback_fill_buffer<Func> *create_callback(_In_ _file_info *info, F

size_t _fill_buffer_fsb(_In_ _file_info_impl *fInfo, _In_ _filestream_callback *callback, size_t count, size_t char_size)
{
SafeInt<size_t> safeCount = count;
msl::safeint3::SafeInt<size_t> safeCount = count;

if ( fInfo->m_buffer == nullptr || safeCount > fInfo->m_bufsize )
{
Expand Down Expand Up @@ -547,7 +547,7 @@ size_t __cdecl _putn_fsb(_In_ Concurrency::streams::details::_file_info *info, _
if (fInfo->m_wrpos != static_cast<size_t>(-1))
fInfo->m_wrpos += count;

SafeInt<unsigned int> safeWriteSize = count;
msl::safeint3::SafeInt<unsigned int> safeWriteSize = count;
safeWriteSize *= char_size;


Expand Down

0 comments on commit ae828bd

Please sign in to comment.