Skip to content
Merged
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
9 changes: 5 additions & 4 deletions stl/src/filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,10 @@ _FS_DLL unsigned long long __CLRCALL_PURE_OR_CDECL _File_size(const wchar_t* _Fn
// 1908 is leap year #2
// 1968 is leap year #17

#define WIN_TICKS_PER_SECOND 10000000ULL

#define WIN_TICKS_FROM_EPOCH (((1970 - 1601) * 365 + 3 * 24 + 17) * 86400ULL * WIN_TICKS_PER_SECOND)
constexpr uint64_t _Win_ticks_per_second = 10000000ULL;
constexpr uint64_t _Win_ticks_from_epoch = ((1970 - 1601) * 365 + 3 * 24 + 17) * 86400ULL * _Win_ticks_per_second;


_FS_DLL int64_t __CLRCALL_PURE_OR_CDECL _Last_write_time(const wchar_t* _Fname) { // get last write time
WIN32_FILE_ATTRIBUTE_DATA _Data;
Expand All @@ -281,7 +282,7 @@ _FS_DLL int64_t __CLRCALL_PURE_OR_CDECL _Last_write_time(const wchar_t* _Fname)
// success, convert time
unsigned long long _Wtime = static_cast<unsigned long long>(_Data.ftLastWriteTime.dwHighDateTime) << 32
| _Data.ftLastWriteTime.dwLowDateTime;
return static_cast<int64_t>(_Wtime - WIN_TICKS_FROM_EPOCH);
return static_cast<int64_t>(_Wtime - _Win_ticks_from_epoch);
}


Expand All @@ -294,7 +295,7 @@ _FS_DLL int __CLRCALL_PURE_OR_CDECL _Set_last_write_time(const wchar_t* _Fname,
}

// convert to FILETIME and set
unsigned long long _Wtime = static_cast<unsigned long long>(_When) + WIN_TICKS_FROM_EPOCH;
unsigned long long _Wtime = static_cast<unsigned long long>(_When) + _Win_ticks_from_epoch;
FILETIME _Ft;
_Ft.dwLowDateTime = static_cast<DWORD>(_Wtime); // intentionally discard upper bits
_Ft.dwHighDateTime = static_cast<DWORD>(_Wtime >> 32);
Expand Down
8 changes: 4 additions & 4 deletions stl/src/ios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <xiosbase>
_STD_BEGIN

#define NSTDSTR 8 // cin, wcin, cout, wcout, cerr, wcerr, clog, wclog
constexpr int _Nstdstr = 8; // cin, wcin, cout, wcout, cerr, wcerr, clog, wclog

// TRANSITION, ABI: _BADOFF is preserved for binary compatibility
#if defined(_M_CEE_PURE)
Expand All @@ -22,8 +22,8 @@ __PURE_APPDOMAIN_GLOBAL int ios_base::_Index = 0; // initialize source of unique
__PURE_APPDOMAIN_GLOBAL bool ios_base::_Sync = true; // initialize synchronization flag


__PURE_APPDOMAIN_GLOBAL static ios_base* stdstr[NSTDSTR + 2] = {0}; // [1, NSTDSTR] hold pointers to standard streams
__PURE_APPDOMAIN_GLOBAL static char stdopens[NSTDSTR + 2] = {0}; // [1, NSTDSTR] hold open counts for standard streams
__PURE_APPDOMAIN_GLOBAL static ios_base* stdstr[_Nstdstr + 2] = {0}; // [1, _Nstdstr] hold pointers to standard streams
__PURE_APPDOMAIN_GLOBAL static char stdopens[_Nstdstr + 2] = {0}; // [1, _Nstdstr] hold open counts for standard streams

// void __CLR_OR_THIS_CALL ios_base::clear(iostate state, bool reraise) { // set state, possibly reraise exception
// _Mystate = (iostate)(state & _Statmask);
Expand Down Expand Up @@ -74,7 +74,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 = 0; ++_This->_Stdstr < NSTDSTR;) {
for (_This->_Stdstr = 0; ++_This->_Stdstr < _Nstdstr;) {
if (stdstr[_This->_Stdstr] == 0 || stdstr[_This->_Stdstr] == _This) {
break; // found a candidate
}
Expand Down
8 changes: 4 additions & 4 deletions stl/src/iosptrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ __PURE_APPDOMAIN_GLOBAL extern _CRTDATA2_IMPORT wostream* _Ptr_wclog = 0;
_STD_END

// FINALIZATION CODE
#define NATS 10 // fclose, xgetloc, locks, facet free, etc.
constexpr int _Nats = 10; // fclose, xgetloc, locks, facet free, etc.

// static data
__PURE_APPDOMAIN_GLOBAL static void(__cdecl* atfuns_cdecl[NATS])() = {0};
__PURE_APPDOMAIN_GLOBAL static size_t atcount_cdecl = {NATS};
__PURE_APPDOMAIN_GLOBAL static void(__cdecl* atfuns_cdecl[_Nats])() = {0};
__PURE_APPDOMAIN_GLOBAL static size_t atcount_cdecl = {_Nats};
_MRTIMP2 void __cdecl _Atexit(void(__cdecl* pf)()) { // add to wrapup list
if (atcount_cdecl == 0) {
abort(); // stack full, give up
Expand All @@ -45,7 +45,7 @@ _MRTIMP2 void __cdecl _Atexit(void(__cdecl* pf)()) { // add to wrapup list

struct _Init_atexit { // controller for atexit processing
__CLR_OR_THIS_CALL ~_Init_atexit() noexcept { // process wrapup functions
while (atcount_cdecl < NATS) {
while (atcount_cdecl < _Nats) {
void(__cdecl * pf)() = (void(__cdecl*)()) DecodePointer(atfuns_cdecl[atcount_cdecl++]);
if (pf) {
(*pf)();
Expand Down
21 changes: 11 additions & 10 deletions stl/src/xlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

_STD_BEGIN

#define MAX_LOCK 8 // must be power of two
constexpr int _Max_lock = 8; // must be power of two

#pragma warning(disable : 4074)
#pragma init_seg(compiler)

static _Rmtx mtx[MAX_LOCK];
static _Rmtx mtx[_Max_lock];
static long init = -1;

#if !defined(MRTDLL)
Expand Down Expand Up @@ -70,15 +70,15 @@ __thiscall _Lockit::_Lockit() noexcept : _Locktype(0) { // lock default mutex
__thiscall _Lockit::_Lockit(int kind) noexcept : _Locktype(kind) { // lock the mutex
if (_Locktype == _LOCK_LOCALE) {
_lock_locales();
} else if (_Locktype < MAX_LOCK) {
} else if (_Locktype < _Max_lock) {
_Mtxlock(&mtx[_Locktype]);
}
}

__thiscall _Lockit::~_Lockit() noexcept { // unlock the mutex
if (_Locktype == _LOCK_LOCALE) {
_unlock_locales();
} else if (_Locktype < MAX_LOCK) {
} else if (_Locktype < _Max_lock) {
_Mtxunlock(&mtx[_Locktype]);
}
}
Expand All @@ -93,7 +93,7 @@ void __cdecl _Lockit::_Lockit_ctor(_Lockit* _This, int kind) noexcept { // lock
if (kind == _LOCK_LOCALE) {
_lock_locales();
} else {
_This->_Locktype = kind & (MAX_LOCK - 1);
_This->_Locktype = kind & (_Max_lock - 1);
_Mtxlock(&mtx[_This->_Locktype]);
}
}
Expand All @@ -107,7 +107,7 @@ void __cdecl _Lockit::_Lockit_ctor(int kind) noexcept { // lock the mutex
if (kind == _LOCK_LOCALE) {
_lock_locales();
} else {
_Mtxlock(&mtx[kind & (MAX_LOCK - 1)]);
_Mtxlock(&mtx[kind & (_Max_lock - 1)]);
}
}

Expand All @@ -116,16 +116,17 @@ void __cdecl _Lockit::_Lockit_dtor(int kind) noexcept { // unlock the mutex
if (kind == _LOCK_LOCALE) {
_unlock_locales();
} else {
_Mtxunlock(&mtx[kind & (MAX_LOCK - 1)]);
_Mtxunlock(&mtx[kind & (_Max_lock - 1)]);
}
}

extern "C" void _Lock_at_thread_exit_mutex() { // lock the at-thread-exit mutex
_EXTERN_C
void _Lock_at_thread_exit_mutex() { // lock the at-thread-exit mutex
_Mtxlock(&mtx[_LOCK_AT_THREAD_EXIT]);
}

extern "C" void _Unlock_at_thread_exit_mutex() { // unlock the at-thread-exit mutex
void _Unlock_at_thread_exit_mutex() { // unlock the at-thread-exit mutex
_Mtxunlock(&mtx[_LOCK_AT_THREAD_EXIT]);
}
_END_EXTERN_C

_STD_END
12 changes: 6 additions & 6 deletions stl/src/xnotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <Windows.h>

#define NITEMS 20
constexpr int _Nitems = 20;

namespace {
struct _At_thread_exit_data { // data for condition-variable slot
Expand All @@ -20,7 +20,7 @@ namespace {
};

struct _At_thread_exit_block { // block of condition-variable slots
_At_thread_exit_data data[NITEMS];
_At_thread_exit_data data[_Nitems];
int num_used;
_At_thread_exit_block* next;
};
Expand All @@ -40,14 +40,14 @@ void _Cnd_register_at_thread_exit(

_Lock_at_thread_exit_mutex();
while (block != 0) { // loop through list of blocks
if (block->num_used == NITEMS) { // block is full; move to next block and allocate
if (block->num_used == _Nitems) { // block is full; move to next block and allocate
if (block->next == 0) {
block->next = (_At_thread_exit_block*) calloc(1, sizeof(_At_thread_exit_block));
}

block = block->next;
} else { // found block with available space
for (int i = 0; i < NITEMS; ++i) { // find empty slot
for (int i = 0; i < _Nitems; ++i) { // find empty slot
if (block->data[i].mtx == 0) { // store into empty slot
block->data[i].id._Id = GetCurrentThreadId();
block->data[i].mtx = mtx;
Expand All @@ -69,7 +69,7 @@ void _Cnd_unregister_at_thread_exit(_Mtx_t mtx) { // unregister condition variab

_Lock_at_thread_exit_mutex();
while (block != 0) { // loop through list of blocks
for (int i = 0; block->num_used != 0 && i < NITEMS; ++i) {
for (int i = 0; block->num_used != 0 && i < _Nitems; ++i) {
if (block->data[i].mtx == mtx) { // release slot
block->data[i].mtx = 0;
--block->num_used;
Expand All @@ -88,7 +88,7 @@ void _Cnd_do_broadcast_at_thread_exit() { // notify condition variables waiting

_Lock_at_thread_exit_mutex();
while (block != 0) { // loop through list of blocks
for (int i = 0; block->num_used != 0 && i < NITEMS; ++i) {
for (int i = 0; block->num_used != 0 && i < _Nitems; ++i) {
if (block->data[i].mtx != 0 && block->data[i].id._Id == currentThreadId) { // notify and release slot
if (block->data[i].res) {
*block->data[i].res = 1;
Expand Down
26 changes: 13 additions & 13 deletions stl/src/xstoflt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@

_EXTERN_C_UNLESS_PURE

#define BASE 10 // decimal
#define NDIG 9 // decimal digits per long word
#define MAXSIG (5 * NDIG) // maximum significant digits to keep
constexpr int _Base = 10; // decimal
constexpr int _Ndig = 9; // decimal digits per long word
constexpr int _Maxsig = 5 * _Ndig; // maximum significant digits to keep

int _Stoflt(const char* s0, const char* s, char** endptr, long lo[],
int maxsig) { // convert string to array of long plus exponent
char buf[MAXSIG + 1]; // worst case, with room for rounding digit
char buf[_Maxsig + 1]; // worst case, with room for rounding digit
int nsig = 0; // number of significant digits seen
int seen = 0; // any valid field characters seen
int sticky = 0; // note any nonzero digits discarded
int word = 0; // just before current long word to fill

maxsig *= NDIG; // convert word count to digit count
if (MAXSIG < maxsig) {
maxsig = MAXSIG; // protect against bad call
maxsig *= _Ndig; // convert word count to digit count
if (_Maxsig < maxsig) {
maxsig = _Maxsig; // protect against bad call
}

lo[0] = 0; // power of ten exponent
lo[1] = 0; // first NDIG-digit word of fraction
lo[1] = 0; // first _Ndig-digit word of fraction

while (*s == '0') { // strip leading zeros
seen = 1;
Expand Down Expand Up @@ -69,7 +69,7 @@ int _Stoflt(const char* s0, const char* s, char** endptr, long lo[],
}

if (sticky) {
buf[maxsig - 1] += 1; // okay if digit becomes BASE
buf[maxsig - 1] += 1; // okay if digit becomes _Base
}

for (; 0 < nsig && buf[nsig - 1] == '\0'; --nsig) {
Expand All @@ -82,14 +82,14 @@ int _Stoflt(const char* s0, const char* s, char** endptr, long lo[],

if (seen) { // convert digit sequence to words
int bufidx = 0; // next digit in buffer
int wordidx = NDIG - nsig % NDIG; // next digit in word (% NDIG)
int wordidx = _Ndig - nsig % _Ndig; // next digit in word (% _Ndig)

word = wordidx % NDIG == 0 ? 0 : 1;
word = wordidx % _Ndig == 0 ? 0 : 1;
for (; bufidx < nsig; ++wordidx, ++bufidx) {
if (wordidx % NDIG == 0) {
if (wordidx % _Ndig == 0) {
lo[++word] = buf[bufidx];
} else {
lo[word] = lo[word] * BASE + buf[bufidx];
lo[word] = lo[word] * _Base + buf[bufidx];
}
}

Expand Down
8 changes: 4 additions & 4 deletions stl/src/xstoul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
_EXTERN_C_UNLESS_PURE

// macros
#define BASE_MAX 36 // largest valid base
constexpr int _Base_max = 36; // largest valid base

// static data
static const char digits[] = // valid digits
"0123456789abcdefghijklmnopqrstuvwxyz";

#if (ULONG_MAX >> 16) >> 16 == 0xffffffff
// 64-bits!
static const char ndigs[BASE_MAX + 1] = {0, 0, 65, 41, 33, 28, 25, 23, 22, 21, 20, 19, 18, 18, 17, 17, 17, 16, 16, 16,
static const char ndigs[_Base_max + 1] = {0, 0, 65, 41, 33, 28, 25, 23, 22, 21, 20, 19, 18, 18, 17, 17, 17, 16, 16, 16,
15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13};
#else // (ULONG_MAX >> 16) >> 16 == 0xffffffff
// 32-bits!
static const char ndigs[BASE_MAX + 1] = {0, 0, 33, 21, 17, 14, 13, 12, 11, 11, 10, 10, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8,
static const char ndigs[_Base_max + 1] = {0, 0, 33, 21, 17, 14, 13, 12, 11, 11, 10, 10, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8,
8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
#endif // (ULONG_MAX >> 16) >> 16 == 0xffffffff

Expand All @@ -49,7 +49,7 @@ _CRTIMP2_PURE unsigned long __CLRCALL_PURE_OR_CDECL _Stoulx(
}

sign = *sc == '-' || *sc == '+' ? *sc++ : '+';
if (base < 0 || base == 1 || BASE_MAX < base) { // silly base
if (base < 0 || base == 1 || _Base_max < base) { // silly base
if (endptr != 0) {
*endptr = (char*) s;
}
Expand Down
7 changes: 3 additions & 4 deletions stl/src/xstoull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@

_EXTERN_C_UNLESS_PURE

// macros
#define BASE_MAX 36 // largest valid base
constexpr int _Base_max = 36; // largest valid base

// static data
static const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; // valid digits

// 64-bits!
static const char ndigs[BASE_MAX + 1] = {0, 0, 65, 41, 33, 28, 25, 23, 22, 21, 20, 19, 18, 18, 17, 17, 17, 16, 16, 16,
static const char ndigs[_Base_max + 1] = {0, 0, 65, 41, 33, 28, 25, 23, 22, 21, 20, 19, 18, 18, 17, 17, 17, 16, 16, 16,
15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13};

_CRTIMP2_PURE unsigned long long __CLRCALL_PURE_OR_CDECL _Stoullx(
Expand All @@ -41,7 +40,7 @@ _CRTIMP2_PURE unsigned long long __CLRCALL_PURE_OR_CDECL _Stoullx(
}

sign = (char) (*sc == '-' || *sc == '+' ? *sc++ : '+');
if (base < 0 || base == 1 || BASE_MAX < base) { // silly base
if (base < 0 || base == 1 || _Base_max < base) { // silly base
if (endptr != 0) {
*endptr = (char*) s;
}
Expand Down
28 changes: 14 additions & 14 deletions stl/src/xstoxflt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

_EXTERN_C_UNLESS_PURE

#define BASE 16 // hexadecimal
#define NDIG 7 // hexadecimal digits per long element
#define MAXSIG (5 * NDIG) // maximum significant digits to keep
constexpr int _Base = 16; // hexadecimal
constexpr int _Ndig = 7; // hexadecimal digits per long element
constexpr int _Maxsig = 5 * _Ndig; // maximum significant digits to keep

int _Stoxflt(const char* s0, const char* s, char** endptr, long lo[],
int maxsig) { // convert string to array of long plus exponent
char buf[MAXSIG + 1]; // worst case, with room for rounding digit
char buf[_Maxsig + 1]; // worst case, with room for rounding digit
int nsig = 0; // number of significant digits seen
int seen = 0; // any valid field characters seen
int word = 0; // current long word to fill
Expand All @@ -27,13 +27,13 @@ int _Stoxflt(const char* s0, const char* s, char** endptr, long lo[],
static const char vals[] = {// values of hex digits
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15};

maxsig *= NDIG; // convert word count to digit count
if (MAXSIG < maxsig) {
maxsig = MAXSIG; // protect against bad call
maxsig *= _Ndig; // convert word count to digit count
if (_Maxsig < maxsig) {
maxsig = _Maxsig; // protect against bad call
}

lo[0] = 0; // power of ten exponent
lo[1] = 0; // first NDIG-digit word of fraction
lo[1] = 0; // first _Ndig-digit word of fraction

while (*s == '0') { // strip leading zeros
++s;
Expand Down Expand Up @@ -69,8 +69,8 @@ int _Stoxflt(const char* s0, const char* s, char** endptr, long lo[],
}

if (maxsig < nsig) { // discard excess digit after rounding up
if (BASE / 2 <= buf[maxsig]) {
++buf[maxsig - 1]; // okay if digit becomes BASE
if (_Base / 2 <= buf[maxsig]) {
++buf[maxsig - 1]; // okay if digit becomes _Base
}

nsig = maxsig;
Expand All @@ -88,14 +88,14 @@ int _Stoxflt(const char* s0, const char* s, char** endptr, long lo[],
lo[0] <<= 2; // change hex exponent to binary exponent
if (seen) { // convert digit sequence to words
int bufidx = 0; // next digit in buffer
int wordidx = NDIG - nsig % NDIG; // next digit in word (% NDIG)
int wordidx = _Ndig - nsig % _Ndig; // next digit in word (% _Ndig)

word = wordidx % NDIG == 0 ? 0 : 1;
word = wordidx % _Ndig == 0 ? 0 : 1;
for (; bufidx < nsig; ++wordidx, ++bufidx) {
if (wordidx % NDIG == 0) {
if (wordidx % _Ndig == 0) {
lo[++word] = buf[bufidx];
} else {
lo[word] = lo[word] * BASE + buf[bufidx];
lo[word] = lo[word] * _Base + buf[bufidx];
}
}

Expand Down
Loading