Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3ed6ca9
Remove unnecessary parentheses.
StephanTLavavej Jun 19, 2020
e570c28
Use static_cast.
StephanTLavavej Jun 20, 2020
790c4f5
Use reinterpret_cast.
StephanTLavavej Jun 20, 2020
904acf2
static_cast from void*.
StephanTLavavej Jun 20, 2020
74a08fe
static_cast<const char*> memchr(), don't cast wmemchr().
StephanTLavavej Jun 20, 2020
e359eed
Use reinterpret_cast for _Dval/_Fval/_Lval, remove parens.
StephanTLavavej Jun 20, 2020
f60673f
Use const_cast.
StephanTLavavej Jun 20, 2020
662d461
Don't macroize ldexpf/sqrtf; the UCRT provides them.
StephanTLavavej Jun 20, 2020
1531555
const_cast<short*>, then implicitly convert to void*.
StephanTLavavej Jun 20, 2020
eaeda97
static_cast and const_cast to locale::facet*.
StephanTLavavej Jun 20, 2020
55e7b07
Use nullptr.
StephanTLavavej Jun 20, 2020
540e637
Change __alignof to alignof.
StephanTLavavej Jun 21, 2020
6f93267
Change wchar_t(0) to L'\0'.
StephanTLavavej Jun 21, 2020
d5f3617
unsigned long is always 32-bit.
StephanTLavavej Jun 21, 2020
c98869f
Use default template args, name typedefs consistently.
StephanTLavavej Jun 21, 2020
0f432fb
Fix preprocessor comment.
StephanTLavavej Jun 21, 2020
86c50ae
Adjust test strings in tr1.
StephanTLavavej Jun 19, 2020
776db9d
Drop reinterpret_cast<char*>, use const auto.
StephanTLavavej Jun 23, 2020
0eb9d4b
Define `unsigned short frac` at initializer.
StephanTLavavej Jun 23, 2020
7436f5e
Extract assignments before if-statements.
StephanTLavavej Jun 23, 2020
6d41d69
Merge branch 'master' into more_cleanups
StephanTLavavej Jun 24, 2020
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: 2 additions & 2 deletions stl/src/StlLCMapStringA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ extern "C" int __cdecl __crtLCMapStringA(LPCWSTR LocaleName, DWORD dwMapFlags, L

// do string mapping
if (0
== __crtLCMapStringEx(
LocaleName, dwMapFlags, inwbuffer.get(), inbuff_size, (LPWSTR) lpDestStr, cchDest)) {
== __crtLCMapStringEx(LocaleName, dwMapFlags, inwbuffer.get(), inbuff_size,
reinterpret_cast<LPWSTR>(lpDestStr), cchDest)) {
return retval;
}
}
Expand Down
18 changes: 9 additions & 9 deletions stl/src/_tolower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Tolower(int c, const _Ctypevec* ploc)
}

if (locale_name == nullptr) {
if ((c >= 'A') && (c <= 'Z')) {
if (c >= 'A' && c <= 'Z') {
c = c + ('a' - 'A');
}

Expand All @@ -74,11 +74,11 @@ _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Tolower(int c, const _Ctypevec* ploc)
// convert int c to multibyte string
if (ploc == nullptr ? _cpp_isleadbyte((c >> 8) & 0xff) : (ploc->_Table[(c >> 8) & 0xff] & _LEADBYTE) != 0) {
inbuffer[0] = (c >> 8 & 0xff);
inbuffer[1] = (unsigned char) c;
inbuffer[1] = static_cast<unsigned char>(c);
inbuffer[2] = 0;
size = 2;
} else {
inbuffer[0] = (unsigned char) c;
inbuffer[0] = static_cast<unsigned char>(c);
inbuffer[1] = 0;
size = 1;
}
Expand All @@ -93,9 +93,9 @@ _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Tolower(int c, const _Ctypevec* ploc)

// construct integer return value
if (size == 1) {
return (int) outbuffer[0];
return static_cast<int>(outbuffer[0]);
} else {
return (int) outbuffer[1] | ((int) outbuffer[0] << 8);
return static_cast<int>(outbuffer[1]) | (static_cast<int>(outbuffer[0]) << 8);
}
}

Expand All @@ -104,12 +104,12 @@ _CRTIMP2_PURE _Ctypevec __CLRCALL_PURE_OR_CDECL _Getctype() {
_Ctypevec ctype;

ctype._Page = ___lc_codepage_func();
ctype._Table = (const short*) _calloc_crt(256, sizeof(*__pctype_func()));
if (ctype._Table != 0) {
memcpy((void*) ctype._Table, __pctype_func(), 256 * sizeof(*__pctype_func()));
ctype._Table = static_cast<const short*>(_calloc_crt(256, sizeof(*__pctype_func())));
if (ctype._Table != nullptr) {
memcpy(const_cast<short*>(ctype._Table), __pctype_func(), 256 * sizeof(*__pctype_func()));
ctype._Delfl = 1;
} else {
ctype._Table = (const short*) __pctype_func();
ctype._Table = reinterpret_cast<const short*>(__pctype_func());
ctype._Delfl = 0;
}
ctype._LocaleName = ___lc_locale_name_func()[LC_COLLATE];
Expand Down
10 changes: 5 additions & 5 deletions stl/src/_toupper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Toupper(int c, const _Ctypevec* ploc)
}

if (locale_name == nullptr) {
if ((c >= 'a') && (c <= 'z')) {
if (c >= 'a' && c <= 'z') {
c = c - ('a' - 'A');
}

Expand All @@ -72,11 +72,11 @@ _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Toupper(int c, const _Ctypevec* ploc)
// convert int c to multibyte string
if (ploc == nullptr ? _cpp_isleadbyte((c >> 8) & 0xff) : (ploc->_Table[(c >> 8) & 0xff] & _LEADBYTE) != 0) {
inbuffer[0] = (c >> 8 & 0xff);
inbuffer[1] = (unsigned char) c;
inbuffer[1] = static_cast<unsigned char>(c);
inbuffer[2] = 0;
size = 2;
} else {
inbuffer[0] = (unsigned char) c;
inbuffer[0] = static_cast<unsigned char>(c);
inbuffer[1] = 0;
size = 1;
}
Expand All @@ -91,9 +91,9 @@ _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Toupper(int c, const _Ctypevec* ploc)

// construct integer return value
if (size == 1) {
return (int) outbuffer[0];
return static_cast<int>(outbuffer[0]);
} else {
return (int) outbuffer[1] | ((int) outbuffer[0] << 8);
return static_cast<int>(outbuffer[1]) | (static_cast<int>(outbuffer[0]) << 8);
}
}

Expand Down
2 changes: 1 addition & 1 deletion stl/src/atomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ _CRTIMP2_PURE void __cdecl _Lock_shared_ptr_spin_lock() { // spin until _Shared_
_CRTIMP2_PURE void __cdecl _Unlock_shared_ptr_spin_lock() { // release previously obtained lock
#ifdef _M_ARM
__dmb(_ARM_BARRIER_ISH);
__iso_volatile_store32((volatile int*) &_Shared_ptr_flag, 0);
__iso_volatile_store32(reinterpret_cast<volatile int*>(&_Shared_ptr_flag), 0);
#else // _M_ARM
_interlockedbittestandreset(&_Shared_ptr_flag, 0); // reset bit 0
#endif // _M_ARM
Expand Down
4 changes: 2 additions & 2 deletions stl/src/cthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace {
using _Thrd_callback_t = unsigned int(__stdcall*)(void*);

unsigned int __stdcall _Thrd_runner(void* d) { // call thread function
_Thrd_binder b = *(_Thrd_binder*) d;
_Thrd_binder b = *static_cast<_Thrd_binder*>(d);
_Mtx_lock(*b.mtx);
*b.started = 1;
_Cnd_signal(*b.cond);
Expand Down Expand Up @@ -59,7 +59,7 @@ int _Thrd_join(_Thrd_t thr, int* code) { // return exit code when thread termina
}

if (code) {
*code = (int) res;
*code = static_cast<int>(res);
}

return CloseHandle(thr._Hnd) == 0 ? _Thrd_error : _Thrd_success;
Expand Down
8 changes: 4 additions & 4 deletions stl/src/filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ _FS_DLL void* __CLRCALL_PURE_OR_CDECL _Open_dir(
if (_Handle == INVALID_HANDLE_VALUE) { // report failure
_Errno = ERROR_BAD_PATHNAME;
*_Dest = L'\0';
return 0;
return nullptr;
}

// success, get first directory entry
Expand All @@ -129,7 +129,7 @@ _FS_DLL void* __CLRCALL_PURE_OR_CDECL _Open_dir(

// no entries, release handle
_Close_dir(_Handle);
return 0;
return nullptr;
}

// get file type and return handle
Expand All @@ -145,7 +145,7 @@ _FS_DLL bool __CLRCALL_PURE_OR_CDECL _Current_get(wchar_t (&_Dest)[_MAX_FILESYS_
#ifdef _CRT_APP
return false; // no support
#else // _CRT_APP
return _wgetcwd(_Dest, _MAX_FILESYS_NAME) != 0;
return _wgetcwd(_Dest, _MAX_FILESYS_NAME) != nullptr;
#endif // _CRT_APP
}

Expand All @@ -161,7 +161,7 @@ _FS_DLL bool __CLRCALL_PURE_OR_CDECL _Current_set(const wchar_t* _Dirname) {

_FS_DLL wchar_t* __CLRCALL_PURE_OR_CDECL _Symlink_get(wchar_t (&_Dest)[_MAX_FILESYS_NAME], const wchar_t*) {
// get symlink -- DUMMY
_Dest[0] = wchar_t(0);
_Dest[0] = L'\0';
return &_Dest[0];
}

Expand Down
10 changes: 5 additions & 5 deletions stl/src/fiopen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,29 @@ FILE* _Xfiopen(const CharT* filename, ios_base::openmode mode, int prot) {
}

if (valid[n] == 0) {
return 0; // no valid mode
return nullptr; // no valid mode
}

if (norepflag && (mode & (ios_base::out | ios_base::app))
&& (fp = _Xfsopen(filename, 0, prot)) != nullptr) { // file must not exist, close and fail
fclose(fp);
return 0;
return nullptr;
}

if (fp != nullptr && fclose(fp) != 0) {
return 0; // can't close after test open
return nullptr; // can't close after test open
}

if ((fp = _Xfsopen(filename, n, prot)) == nullptr) {
return 0; // open failed
return nullptr; // open failed
}

if (!atendflag || fseek(fp, 0, SEEK_END) == 0) {
return fp; // no need to seek to end, or seek succeeded
}

fclose(fp); // can't position at end
return 0;
return nullptr;
}

_CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(
Expand Down
2 changes: 1 addition & 1 deletion stl/src/ios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void __CLRCALL_PURE_OR_CDECL ios_base::_Ios_base_dtor(ios_base* _This) { // dest
void __CLRCALL_PURE_OR_CDECL ios_base::_Addstd(ios_base* _This) { // add standard stream to destructor list
_BEGIN_LOCK(_LOCK_STREAM)
for (_This->_Stdstr = 1; _This->_Stdstr < _Nstdstr; ++_This->_Stdstr) {
if (stdstr[_This->_Stdstr] == 0 || stdstr[_This->_Stdstr] == _This) {
if (stdstr[_This->_Stdstr] == nullptr || stdstr[_This->_Stdstr] == _This) {
break; // found a candidate
}
}
Expand Down
49 changes: 24 additions & 25 deletions stl/src/locale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

_STD_BEGIN

using _Traits = char_traits<char>;
using _Initer = istreambuf_iterator<char, _Traits>;
using _Outiter = ostreambuf_iterator<char, _Traits>;


_MRTIMP2_PURE locale __CLRCALL_PURE_OR_CDECL locale::global(const locale& loc) { // change global locale
locale _Oldglobal;
_BEGIN_LOCK(_LOCK_LOCALE)
Expand Down Expand Up @@ -49,29 +44,31 @@ _MRTIMP2_PURE locale __CLRCALL_PURE_OR_CDECL locale::global(const locale& loc) {

#if STDCPP_IMPLIB || !defined(_M_CEE_PURE)
// facets associated with C categories
#define ADDFAC(Facet, cat, ptrimp, ptrloc) \
if ((_CATMASK(Facet::_Getcat()) & cat) == 0) { \
; \
} else if (ptrloc == nullptr) { \
ptrimp->_Addfac(new Facet(lobj), Facet::id); \
} else { \
ptrimp->_Addfac((locale::facet*) &_STD use_facet<Facet>(*ptrloc), Facet::id); \
#define ADDFAC(Facet, cat, ptrimp, ptrloc) \
if ((_CATMASK(Facet::_Getcat()) & cat) == 0) { \
; \
} else if (ptrloc == nullptr) { \
ptrimp->_Addfac(new Facet(lobj), Facet::id); \
} else { \
ptrimp->_Addfac( \
const_cast<locale::facet*>(static_cast<const locale::facet*>(&_STD use_facet<Facet>(*ptrloc))), \
Facet::id); \
}

using _T1 = ctype<char>;
using _T2 = num_get<char, _Initer>;
using _T3 = num_put<char, _Outiter>;
using _T4 = numpunct<char>;
using _T5 = codecvt<char, char, _Mbstatet>;
using _Tc1 = ctype<char>;
using _Tc2 = num_get<char>;
using _Tc3 = num_put<char>;
using _Tc4 = numpunct<char>;
using _Tc5 = codecvt<char, char, _Mbstatet>;
// others moved to wlocale and xlocale to ease subsetting

locale::_Locimp* __CLRCALL_OR_CDECL locale::_Locimp::_Makeloc(
const _Locinfo& lobj, locale::category cat, _Locimp* ptrimp, const locale* ptrloc) { // setup a new locale
ADDFAC(_T1, cat, ptrimp, ptrloc);
ADDFAC(_T2, cat, ptrimp, ptrloc);
ADDFAC(_T3, cat, ptrimp, ptrloc);
ADDFAC(_T4, cat, ptrimp, ptrloc);
ADDFAC(_T5, cat, ptrimp, ptrloc);
ADDFAC(_Tc1, cat, ptrimp, ptrloc);
ADDFAC(_Tc2, cat, ptrimp, ptrloc);
ADDFAC(_Tc3, cat, ptrimp, ptrloc);
ADDFAC(_Tc4, cat, ptrimp, ptrloc);
ADDFAC(_Tc5, cat, ptrimp, ptrloc);
_Locimp::_Makexloc(lobj, cat, ptrimp, ptrloc);
_Locimp::_Makewloc(lobj, cat, ptrimp, ptrloc);
#ifdef _NATIVE_WCHAR_T_DEFINED
Expand All @@ -91,10 +88,11 @@ void __CLRCALL_PURE_OR_CDECL locale::_Locimp::_Locimp_ctor(
} else { // lock to keep facets from disappearing
_BEGIN_LOCK(_LOCK_LOCALE)
if (0 < _This->_Facetcount) { // copy over nonempty facet vector
if ((_This->_Facetvec = (locale::facet**) _malloc_crt(_This->_Facetcount * sizeof(locale::facet*)))
== nullptr) { // report no memory
_This->_Facetvec = static_cast<locale::facet**>(_malloc_crt(_This->_Facetcount * sizeof(locale::facet*)));
if (_This->_Facetvec == nullptr) { // report no memory
_Xbad_alloc();
}

for (size_t count = _This->_Facetcount; 0 < count;) { // copy over facet pointers
locale::facet* ptrfac = imp._Facetvec[--count];
if ((_This->_Facetvec[count] = ptrfac) != nullptr) {
Expand All @@ -119,7 +117,8 @@ void __CLRCALL_PURE_OR_CDECL locale::_Locimp::_Locimp_Addfac(
count = MINCAT;
}

locale::facet** ptrnewvec = (locale::facet**) _realloc_crt(_This->_Facetvec, count * sizeof(locale::facet**));
locale::facet** ptrnewvec =
static_cast<locale::facet**>(_realloc_crt(_This->_Facetvec, count * sizeof(locale::facet**)));
if (ptrnewvec == nullptr) { // report no memory
_Xbad_alloc();
}
Expand Down
6 changes: 3 additions & 3 deletions stl/src/locale0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ _STD_END
_EXTERN_C

void __CLRCALL_OR_CDECL _Deletegloballocale(void* ptr) { // delete a global locale reference
std::locale::_Locimp* locptr = *(std::locale::_Locimp**) ptr;
std::locale::_Locimp* locptr = *static_cast<std::locale::_Locimp**>(ptr);
if (locptr != nullptr) {
delete locptr->_Decref();
}
Expand Down Expand Up @@ -116,7 +116,7 @@ _MRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL std::locale::_Setgloballocale(void* p
_atexit_m_appdomain(tidy_global);
#endif
}
global_locale = (std::locale::_Locimp*) ptr;
global_locale = static_cast<std::locale::_Locimp*>(ptr);
}

__PURE_APPDOMAIN_GLOBAL static locale classic_locale(_Noinit); // "C" locale object, uninitialized
Expand Down Expand Up @@ -213,4 +213,4 @@ void __CLRCALL_PURE_OR_CDECL _Locinfo::_Locinfo_dtor(_Locinfo* pLocinfo) { // de
}
_STD_END

#endif // !STDCPP_IMPLIB
#endif // !STDCPP_IMPLIB || defined(_M_CEE_PURE)
13 changes: 7 additions & 6 deletions stl/src/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ void _Mtx_destroy_in_situ(_Mtx_t mtx) { // destroy mutex in situ
}

int _Mtx_init(_Mtx_t* mtx, int type) { // initialize mutex
_Mtx_t mutex;
*mtx = 0;
*mtx = nullptr;

if ((mutex = static_cast<_Mtx_t>(_calloc_crt(1, sizeof(struct _Mtx_internal_imp_t)))) == 0) {
_Mtx_t mutex = static_cast<_Mtx_t>(_calloc_crt(1, sizeof(_Mtx_internal_imp_t)));

if (mutex == nullptr) {
return _Thrd_nomem; // report alloc failed
}

Expand Down Expand Up @@ -98,7 +99,7 @@ static int mtx_do_lock(_Mtx_t mtx, const xtime* target) { // lock mutex
return _Thrd_success;
} else { // handle timed or recursive mutex
int res = WAIT_TIMEOUT;
if (target == 0) { // no target --> plain wait (i.e. infinite timeout)
if (target == nullptr) { // no target --> plain wait (i.e. infinite timeout)
if (mtx->thread_id != static_cast<long>(GetCurrentThreadId())) {
mtx->_get_cs()->lock();
}
Expand Down Expand Up @@ -149,7 +150,7 @@ static int mtx_do_lock(_Mtx_t mtx, const xtime* target) { // lock mutex
return _Thrd_success;

case WAIT_TIMEOUT:
if (target == 0 || (target->sec == 0 && target->nsec == 0)) {
if (target == nullptr || (target->sec == 0 && target->nsec == 0)) {
return _Thrd_busy;
} else {
return _Thrd_timedout;
Expand All @@ -173,7 +174,7 @@ int _Mtx_unlock(_Mtx_t mtx) { // unlock mutex
}

int _Mtx_lock(_Mtx_t mtx) { // lock mutex
return mtx_do_lock(mtx, 0);
return mtx_do_lock(mtx, nullptr);
}

int _Mtx_trylock(_Mtx_t mtx) { // attempt to lock try_mutex
Expand Down
2 changes: 1 addition & 1 deletion stl/src/parallel_algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace {
void _Atomic_store_uint(volatile unsigned int* _Tgt, unsigned int _Value) {
// atomic store of unsigned int, copied from <atomic>
#if defined(_M_IX86) || defined(_M_X64)
_InterlockedExchange((volatile long*) _Tgt, static_cast<long>(_Value));
_InterlockedExchange(reinterpret_cast<volatile long*>(_Tgt), static_cast<long>(_Value));
#else // architecture, ditto no ARM support
#error Unsupported architecture
#endif // architecture
Expand Down
Loading