Skip to content

Commit

Permalink
Standard Library Modules: Fix spurious _Init_locks dllexport (#3233)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanTLavavej authored Nov 18, 2022
1 parent 8ffd4a4 commit 47c90ae
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 25 deletions.
20 changes: 0 additions & 20 deletions stl/inc/yvals.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,26 +454,6 @@ class _CRTIMP2_PURE_IMPORT _EmptyLockit { // empty lock class used for bin compa
#endif // _M_CEE

#ifdef _CRTBLD
class _CRTIMP2_PURE_IMPORT _Init_locks { // initialize mutexes
public:
#ifdef _M_CEE_PURE
__CLR_OR_THIS_CALL _Init_locks() noexcept {
_Init_locks_ctor(this);
}

__CLR_OR_THIS_CALL ~_Init_locks() noexcept {
_Init_locks_dtor(this);
}

#else // _M_CEE_PURE
__thiscall _Init_locks() noexcept;
__thiscall ~_Init_locks() noexcept;
#endif // _M_CEE_PURE

private:
static void __cdecl _Init_locks_ctor(_Init_locks*) noexcept;
static void __cdecl _Init_locks_dtor(_Init_locks*) noexcept;
};

#ifdef _M_CEE
#define _RELIABILITY_CONTRACT \
Expand Down
2 changes: 2 additions & 0 deletions stl/src/cerr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <fstream>
#include <iostream>

#include "init_locks.hpp"

#pragma warning(disable : 4074)
#pragma init_seg(compiler)
static std::_Init_locks initlocks;
Expand Down
2 changes: 2 additions & 0 deletions stl/src/cin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <fstream>
#include <iostream>

#include "init_locks.hpp"

#pragma warning(disable : 4074)
#pragma init_seg(compiler)
static std::_Init_locks initlocks;
Expand Down
2 changes: 2 additions & 0 deletions stl/src/clog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <fstream>
#include <iostream>

#include "init_locks.hpp"

#ifndef MRTDLL
#pragma warning(disable : 4074)
#pragma init_seg(compiler)
Expand Down
2 changes: 2 additions & 0 deletions stl/src/cout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <fstream>
#include <iostream>

#include "init_locks.hpp"

#pragma warning(disable : 4074)
#pragma init_seg(compiler)
static std::_Init_locks initlocks;
Expand Down
31 changes: 31 additions & 0 deletions stl/src/init_locks.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#pragma once

#include <yvals.h>

_STD_BEGIN

class _CRTIMP2_PURE_IMPORT _Init_locks { // initialize mutexes
public:
#ifdef _M_CEE_PURE
__CLR_OR_THIS_CALL _Init_locks() noexcept {
_Init_locks_ctor(this);
}

__CLR_OR_THIS_CALL ~_Init_locks() noexcept {
_Init_locks_dtor(this);
}

#else // _M_CEE_PURE
__thiscall _Init_locks() noexcept;
__thiscall ~_Init_locks() noexcept;
#endif // _M_CEE_PURE

private:
static void __cdecl _Init_locks_ctor(_Init_locks*) noexcept;
static void __cdecl _Init_locks_dtor(_Init_locks*) noexcept;
};

_STD_END
3 changes: 3 additions & 0 deletions stl/src/iosptrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <iostream>

#include <Windows.h>

#include "init_locks.hpp"

_STD_BEGIN

#if defined(_M_CEE) && !defined(_M_CEE_MIXED)
Expand Down
14 changes: 9 additions & 5 deletions stl/src/stacktrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Do not include or define anything else here.
// In particular, basic_string must not be included here.

#include <yvals.h>

#include <cstdio>
#include <cstdlib>

Expand Down Expand Up @@ -166,7 +164,9 @@ namespace {

off = string_fill(fill, off + max_disp_num, str, [displacement, off](char* s, size_t) {
const int ret = std::snprintf(s + off, max_disp_num, "+0x%llX", displacement);
_STL_VERIFY(ret > 0, "formatting error");
if (ret <= 0) {
std::abort(); // formatting error
}
return off + ret;
});
}
Expand Down Expand Up @@ -230,7 +230,9 @@ namespace {

off = string_fill(fill, off + max_line_num, str, [line, off](char* s, size_t) {
const int ret = std::snprintf(s + off, max_line_num, "(%u): ", line);
_STL_VERIFY(ret > 0, "formatting error");
if (ret <= 0) {
std::abort(); // formatting error
}
return off + ret;
});
}
Expand Down Expand Up @@ -331,7 +333,9 @@ void __stdcall __std_stacktrace_to_string(const void* const* const _Addresses, c

off = string_fill(_Fill, off + max_entry_num, _Str, [off, i](char* s, size_t) {
const int ret = std::snprintf(s + off, max_entry_num, "%u> ", static_cast<unsigned int>(i));
_STL_VERIFY(ret > 0, "formatting error");
if (ret <= 0) {
std::abort(); // formatting error
}
return off + ret;
});

Expand Down
2 changes: 2 additions & 0 deletions stl/src/syncstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <shared_mutex>
#include <utility>

#include "init_locks.hpp"

#pragma warning(disable : 4074)
#pragma init_seg(compiler)
static std::_Init_locks initlocks;
Expand Down
1 change: 1 addition & 0 deletions stl/src/taskscheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <Windows.h>

#include "awint.hpp"
#include "init_locks.hpp"

#pragma warning(disable : 4074)
#pragma init_seg(compiler)
Expand Down
2 changes: 2 additions & 0 deletions stl/src/wcerr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <fstream>
#include <iostream>

#include "init_locks.hpp"

#pragma warning(disable : 4074)
#pragma init_seg(compiler)
static std::_Init_locks initlocks;
Expand Down
2 changes: 2 additions & 0 deletions stl/src/wcin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <fstream>
#include <iostream>

#include "init_locks.hpp"

#pragma warning(disable : 4074)
#pragma init_seg(compiler)
static std::_Init_locks initlocks;
Expand Down
2 changes: 2 additions & 0 deletions stl/src/wclog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <fstream>
#include <iostream>

#include "init_locks.hpp"

#pragma warning(disable : 4074)
#pragma init_seg(compiler)
static std::_Init_locks initlocks;
Expand Down
2 changes: 2 additions & 0 deletions stl/src/wcout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <fstream>
#include <iostream>

#include "init_locks.hpp"

#pragma warning(disable : 4074)
#pragma init_seg(compiler)
static std::_Init_locks initlocks;
Expand Down
1 change: 1 addition & 0 deletions stl/src/xlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <clocale>
#include <cstdlib>

#include "init_locks.hpp"
#include "xmtx.hpp"

_STD_BEGIN
Expand Down

0 comments on commit 47c90ae

Please sign in to comment.