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
13 changes: 13 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,22 @@ SpaceAfterCStyleCast: true
# SpacesInParentheses: false
# SpacesInSquareBrackets: false
# Standard: Cpp11

# NOTE: _STD_BEGIN, _STD_END, etc. aren't macros for complete statements, but telling clang-format that they are
# produces the behavior that we want (with no block indentation).
# StatementMacros:
# - Q_UNUSED
# - QT_REQUIRE_VERSION
StatementMacros:
- _STD_BEGIN
- _STD_END
- _STDEXT_BEGIN
- _STDEXT_END
- _EXTERN_C
- _END_EXTERN_C
- _EXTERN_C_UNLESS_PURE
- _END_EXTERN_C_UNLESS_PURE

# TabWidth: 8
# UseTab: Never
...
1 change: 1 addition & 0 deletions stl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ endforeach()
# Objs that exist in both libcpmt[d][01].lib and msvcprt[d].lib.
set(IMPLIB_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/filesystem.cpp
${CMAKE_CURRENT_LIST_DIR}/src/filesystem_space.cpp
${CMAKE_CURRENT_LIST_DIR}/src/locale0_implib.cpp
${CMAKE_CURRENT_LIST_DIR}/src/nothrow.cpp
${CMAKE_CURRENT_LIST_DIR}/src/parallel_algorithms.cpp
Expand Down
145 changes: 68 additions & 77 deletions stl/inc/execution

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions stl/inc/xlocinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ _Success_(return > 0) _ACRTIMP size_t __cdecl _Wcsftime(
_END_EXTERN_C

#ifdef _M_CEE_PURE
[System::Runtime::InteropServices::DllImport(_CRT_MSVCP_CURRENT, EntryPoint = "_GetLocaleForCP",
CallingConvention = System::Runtime::InteropServices::CallingConvention::Cdecl)] extern "C" _locale_t
[System::Runtime::InteropServices::DllImport(_CRT_MSVCP_CURRENT, EntryPoint = "_GetLocaleForCP",
CallingConvention = System::Runtime::InteropServices::CallingConvention::Cdecl)] extern "C" _locale_t
_GetLocaleForCP(unsigned int);

#else // _M_CEE_PURE
_MRTIMP2 _locale_t __cdecl _GetLocaleForCP(unsigned int);
#endif // _M_CEE_PURE
Expand Down
1 change: 1 addition & 0 deletions stl/msbuild/stl_base/stl.files.settings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
(controlled by IncludeInLink and IncludeInImportLib). -->
<BuildFiles Include="
$(CrtRoot)\github\stl\src\filesystem.cpp;
$(CrtRoot)\github\stl\src\filesystem_space.cpp;
$(CrtRoot)\github\stl\src\locale0_implib.cpp;
$(CrtRoot)\github\stl\src\nothrow.cpp;
$(CrtRoot)\github\stl\src\parallel_algorithms.cpp;
Expand Down
57 changes: 2 additions & 55 deletions stl/src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,28 +259,12 @@ namespace {

return _Last_error;
}

static_assert(sizeof(uintmax_t) == sizeof(ULARGE_INTEGER) && alignof(uintmax_t) == alignof(ULARGE_INTEGER),
"Size and alignment must match for reinterpret_cast<PULARGE_INTEGER>");

[[nodiscard]] __std_win_error _Fs_space_attempt(wchar_t* const _Temp_buffer, const DWORD _Temp_buffer_characters,
const wchar_t* const _Target, uintmax_t* const _Available, uintmax_t* const _Total_bytes,
uintmax_t* const _Free_bytes) noexcept {
if (GetVolumePathNameW(_Target, _Temp_buffer, _Temp_buffer_characters)) {
if (GetDiskFreeSpaceExW(_Temp_buffer, reinterpret_cast<PULARGE_INTEGER>(_Available),
reinterpret_cast<PULARGE_INTEGER>(_Total_bytes), reinterpret_cast<PULARGE_INTEGER>(_Free_bytes))) {
return __std_win_error::_Success;
}
}

return __std_win_error{GetLastError()};
}
} // unnamed namespace

_EXTERN_C

[[nodiscard]] __std_ulong_and_error __stdcall __std_fs_get_full_path_name(
const wchar_t* _Source, unsigned long _Target_size, wchar_t* _Target) noexcept { // calls GetFullPathNameW
[[nodiscard]] __std_ulong_and_error __stdcall __std_fs_get_full_path_name(
const wchar_t* _Source, unsigned long _Target_size, wchar_t* _Target) noexcept { // calls GetFullPathNameW
const auto _Result = GetFullPathNameW(_Source, _Target_size, _Target, nullptr);
return {_Result, _Result == 0 ? __std_win_error{GetLastError()} : __std_win_error::_Success};
}
Expand Down Expand Up @@ -760,43 +744,6 @@ __std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, cons
return __std_win_error::_Success;
}

[[nodiscard]] __std_win_error __stdcall __std_fs_space(const wchar_t* const _Target, uintmax_t* const _Available,
uintmax_t* const _Total_bytes, uintmax_t* const _Free_bytes) noexcept {
// get capacity information for the volume on which the file _Target resides
__std_win_error _Last_error;
if (GetFileAttributesW(_Target) == INVALID_FILE_ATTRIBUTES) {
_Last_error = __std_win_error{GetLastError()};
} else {
{
constexpr DWORD _Static_size = MAX_PATH;
wchar_t _Temp_buf[_Static_size];
_Last_error = _Fs_space_attempt(_Temp_buf, _Static_size, _Target, _Available, _Total_bytes, _Free_bytes);
if (_Last_error == __std_win_error::_Success) {
return __std_win_error::_Success;
}
}

if (_Last_error == __std_win_error::_Filename_exceeds_range) {
constexpr DWORD _Dynamic_size = USHRT_MAX + 1; // assuming maximum NT path fits in a UNICODE_STRING
const auto _Temp_buf = _malloc_crt_t(wchar_t, _Dynamic_size);
if (_Temp_buf) {
_Last_error =
_Fs_space_attempt(_Temp_buf.get(), _Dynamic_size, _Target, _Available, _Total_bytes, _Free_bytes);
if (_Last_error == __std_win_error::_Success) {
return __std_win_error::_Success;
}
} else {
_Last_error = __std_win_error::_Not_enough_memory;
}
}
}

*_Available = ~0ull;
*_Total_bytes = ~0ull;
*_Free_bytes = ~0ull;
return _Last_error;
}

[[nodiscard]] __std_ulong_and_error __stdcall __std_fs_get_temp_path(wchar_t* const _Target) noexcept {
// calls GetTempPathW
// If getting the path failed, returns 0 size; otherwise, returns the size of the
Expand Down
73 changes: 73 additions & 0 deletions stl/src/filesystem_space.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

// This must be as small as possible, because its contents are
// injected into the msvcprt.lib and msvcprtd.lib import libraries.
// Do not include or define anything else here.
// In particular, basic_string must not be included here.

// TRANSITION, the code in this file should be moved back to filesystem.cpp
// when a Windows 10 SDK beyond version 1903 is available (see GH-322).

#include <internal_shared.h>
#include <limits.h>
#include <xfilesystem_abi.h>

#include <Windows.h>

namespace {
static_assert(sizeof(uintmax_t) == sizeof(ULARGE_INTEGER) && alignof(uintmax_t) == alignof(ULARGE_INTEGER),
"Size and alignment must match for reinterpret_cast<PULARGE_INTEGER>");

[[nodiscard]] __std_win_error _Fs_space_attempt(wchar_t* const _Temp_buffer, const DWORD _Temp_buffer_characters,
const wchar_t* const _Target, uintmax_t* const _Available, uintmax_t* const _Total_bytes,
uintmax_t* const _Free_bytes) noexcept {
if (GetVolumePathNameW(_Target, _Temp_buffer, _Temp_buffer_characters)) {
if (GetDiskFreeSpaceExW(_Temp_buffer, reinterpret_cast<PULARGE_INTEGER>(_Available),
reinterpret_cast<PULARGE_INTEGER>(_Total_bytes), reinterpret_cast<PULARGE_INTEGER>(_Free_bytes))) {
return __std_win_error::_Success;
}
}

return __std_win_error{GetLastError()};
}
} // unnamed namespace

_EXTERN_C
[[nodiscard]] __std_win_error __stdcall __std_fs_space(const wchar_t* const _Target, uintmax_t* const _Available,
uintmax_t* const _Total_bytes, uintmax_t* const _Free_bytes) noexcept {
// get capacity information for the volume on which the file _Target resides
__std_win_error _Last_error;
if (GetFileAttributesW(_Target) == INVALID_FILE_ATTRIBUTES) {
_Last_error = __std_win_error{GetLastError()};
} else {
{
constexpr DWORD _Static_size = MAX_PATH;
wchar_t _Temp_buf[_Static_size];
_Last_error = _Fs_space_attempt(_Temp_buf, _Static_size, _Target, _Available, _Total_bytes, _Free_bytes);
if (_Last_error == __std_win_error::_Success) {
return __std_win_error::_Success;
}
}

if (_Last_error == __std_win_error::_Filename_exceeds_range) {
constexpr DWORD _Dynamic_size = USHRT_MAX + 1; // assuming maximum NT path fits in a UNICODE_STRING
const auto _Temp_buf = _malloc_crt_t(wchar_t, _Dynamic_size);
if (_Temp_buf) {
_Last_error =
_Fs_space_attempt(_Temp_buf.get(), _Dynamic_size, _Target, _Available, _Total_bytes, _Free_bytes);
if (_Last_error == __std_win_error::_Success) {
return __std_win_error::_Success;
}
} else {
_Last_error = __std_win_error::_Not_enough_memory;
}
}
}

*_Available = ~0ull;
*_Total_bytes = ~0ull;
*_Free_bytes = ~0ull;
return _Last_error;
}
_END_EXTERN_C
7 changes: 3 additions & 4 deletions stl/src/future.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
#include <cstdlib>
#include <exception>
#include <future>

_STD_BEGIN

[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
_Throw_future_error(const error_code& _Code) { // throw an exception
[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Throw_future_error(const error_code& _Code) {
_THROW(future_error(_Code));
}

[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Rethrow_future_exception(
exception_ptr _Ptr) { // rethrow an exception
[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Rethrow_future_exception(exception_ptr _Ptr) {
_STD rethrow_exception(_Ptr);
}

Expand Down
4 changes: 1 addition & 3 deletions stl/src/locale0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
#pragma init_seg(lib)

_STD_BEGIN

[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
_Xbad_alloc();
[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Xbad_alloc();

struct _Fac_node { // node for lazy facet recording
_Fac_node(_Fac_node* _Nextarg, _Facet_base* _Facptrarg)
Expand Down
4 changes: 1 addition & 3 deletions stl/src/xthrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
#include <stdexcept>

_STD_BEGIN

[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
_Xbad_alloc() {
[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Xbad_alloc() {
_THROW(bad_alloc{});
}

Expand Down