Skip to content

Commit

Permalink
Various cleanups: extern "C" (#4143)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanTLavavej authored Nov 7, 2023
1 parent a34519b commit 3f15c7f
Show file tree
Hide file tree
Showing 43 changed files with 101 additions and 100 deletions.
2 changes: 0 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ StatementMacros:
- _STDEXT_END
- _FMT_P2286_BEGIN
- _FMT_P2286_END
- _EXTERN_C
- _END_EXTERN_C
- _EXTERN_C_UNLESS_PURE
- _END_EXTERN_C_UNLESS_PURE
# TabWidth: 8
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/__msvc_print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

_EXTERN_C
extern "C" {

enum class __std_unicode_console_handle : intptr_t { _Invalid = -1 };

Expand Down Expand Up @@ -55,7 +55,7 @@ _NODISCARD _Success_(return == __std_win_error::_Success) __std_win_error
__stdcall __std_print_to_unicode_console(_In_ __std_unicode_console_handle _Console_handle,
_In_reads_(_Str_size) const char* _Str, _In_ size_t _Str_size) noexcept;

_END_EXTERN_C
} // extern "C"

_STD_BEGIN

Expand Down
4 changes: 2 additions & 2 deletions stl/inc/__msvc_sanitizer_annotate_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ extern const bool _Asan_vector_should_annotate;
#ifdef _INSERT_STRING_ANNOTATION
extern const bool _Asan_string_should_annotate;
#endif
}
} // extern "C"

#if defined(_INSERT_VECTOR_ANNOTATION) || defined(_INSERT_STRING_ANNOTATION)
extern "C" {
// This must match ASan's primary declaration, which isn't marked `noexcept`.
void __cdecl __sanitizer_annotate_contiguous_container(
const void* _First, const void* _End, const void* _Old_last, const void* _New_last);
}
} // extern "C"

#ifdef _M_ARM64EC
#pragma comment(linker, \
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/__msvc_system_error_abi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ _STL_DISABLE_CLANG_WARNINGS
#define __CLRCALL_PURE_OR_STDCALL __stdcall
#endif

_EXTERN_C
extern "C" {
_NODISCARD size_t __CLRCALL_PURE_OR_STDCALL __std_get_string_size_without_trailing_whitespace(
const char* _Str, size_t _Size) noexcept;

_NODISCARD size_t __CLRCALL_PURE_OR_STDCALL __std_system_error_allocate_message(
unsigned long _Message_id, char** _Ptr_str) noexcept;
void __CLRCALL_PURE_OR_STDCALL __std_system_error_deallocate_message(char* _Str) noexcept;
_END_EXTERN_C
} // extern "C"

#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/__msvc_tzdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

_EXTERN_C
extern "C" {

using __std_tzdb_epoch_milli = double;

Expand Down Expand Up @@ -92,7 +92,7 @@ void __stdcall __std_tzdb_delete_leap_seconds(__std_tzdb_leap_info* _Info) noexc
_NODISCARD void* __stdcall __std_calloc_crt(size_t _Count, size_t _Size) noexcept;
void __stdcall __std_free_crt(void* _Ptr) noexcept;

_END_EXTERN_C
} // extern "C"

_STD_BEGIN

Expand Down
4 changes: 2 additions & 2 deletions stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _STL_DISABLE_CLANG_WARNINGS

#if _USE_STD_VECTOR_ALGORITHMS

_EXTERN_C
extern "C" {
struct _Min_max_element_t {
const void* _Min;
const void* _Max;
Expand Down Expand Up @@ -59,7 +59,7 @@ const void* __stdcall __std_find_last_trivial_1(const void* _First, const void*
const void* __stdcall __std_find_last_trivial_2(const void* _First, const void* _Last, uint16_t _Val) noexcept;
const void* __stdcall __std_find_last_trivial_4(const void* _First, const void* _Last, uint32_t _Val) noexcept;
const void* __stdcall __std_find_last_trivial_8(const void* _First, const void* _Last, uint64_t _Val) noexcept;
_END_EXTERN_C
} // extern "C"

template <class _Ty>
_STD pair<_Ty*, _Ty*> __std_minmax_element(_Ty* _First, _Ty* _Last) noexcept {
Expand Down
6 changes: 4 additions & 2 deletions stl/inc/atomic
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ extern "C" _NODISCARD char __stdcall __std_atomic_has_cmpxchg16b() noexcept;
// should be mirrored. Also: if any macros are added they should be
// #undefed in vcruntime as well

extern "C" {
enum {
_Atomic_memory_order_relaxed,
_Atomic_memory_order_consume,
Expand All @@ -91,6 +92,7 @@ enum {
_Atomic_memory_order_acq_rel,
_Atomic_memory_order_seq_cst,
};
} // extern "C"

#ifndef _INVALID_MEMORY_ORDER
#ifdef _DEBUG
Expand Down Expand Up @@ -282,9 +284,9 @@ extern "C" inline void _Atomic_thread_fence(const unsigned int _Order) noexcept

// End of code shared with vcruntime

_EXTERN_C
extern "C" {
_Smtx_t* __stdcall __std_atomic_get_mutex(const void* _Key) noexcept;
_END_EXTERN_C
} // extern "C"
// Padding bits should not participate in cmpxchg comparison starting in C++20.
// Clang does not have __builtin_zero_non_value_bits to exclude these bits to implement this C++20 feature.
// The EDG front-end substitutes everything and runs into incomplete types passed to atomic<T>.
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/cmath
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ _EXPORT_STD using _CSTD isunordered;
_STD_END

#if _HAS_CXX17
_EXTERN_C
extern "C" {
_NODISCARD _CRT_SATELLITE_2 double __stdcall __std_smf_assoc_laguerre(unsigned int, unsigned int, double) noexcept;
_NODISCARD _CRT_SATELLITE_2 float __stdcall __std_smf_assoc_laguerref(unsigned int, unsigned int, float) noexcept;
_NODISCARD _CRT_SATELLITE_2 double __stdcall __std_smf_assoc_legendre(unsigned int, unsigned int, double) noexcept;
Expand Down Expand Up @@ -956,7 +956,7 @@ _NODISCARD _CRT_SATELLITE_2 double __stdcall __std_smf_sph_neumann(unsigned int,
_NODISCARD _CRT_SATELLITE_2 float __stdcall __std_smf_sph_neumannf(unsigned int, float) noexcept;
_NODISCARD _CRT_SATELLITE_2 double __stdcall __std_smf_hypot3(double, double, double) noexcept;
_NODISCARD _CRT_SATELLITE_2 float __stdcall __std_smf_hypot3f(float, float, float) noexcept;
_END_EXTERN_C
} // extern "C"

_STD_BEGIN
_EXPORT_STD _NODISCARD inline double assoc_laguerre(
Expand Down
2 changes: 2 additions & 0 deletions stl/inc/complex
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ _STL_DISABLE_CLANG_WARNINGS
#ifndef _C_COMPLEX_T
#define _C_COMPLEX_T // Also defined by UCRT <complex.h>

extern "C" {
struct _C_double_complex {
double _Val[2];
};
Expand All @@ -51,6 +52,7 @@ struct _C_float_complex {
struct _C_ldouble_complex {
long double _Val[2];
};
} // extern "C"
#endif // _C_COMPLEX_T

// complex _Val offsets
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/execution
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

_EXTERN_C
extern "C" {
#ifdef _M_CEE
using __std_TP_WORK = void;
using __std_TP_CALLBACK_INSTANCE = void;
Expand Down Expand Up @@ -62,7 +62,7 @@ void __stdcall __std_execution_wait_on_uchar(
_In_ const volatile unsigned char* _Address, _In_ unsigned char _Compare) noexcept;

void __stdcall __std_execution_wake_by_address_all(_In_ const volatile void* _Address) noexcept;
_END_EXTERN_C
} // extern "C"

_STD_BEGIN
inline constexpr size_t _Oversubscription_multiplier = 32;
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/memory
Original file line number Diff line number Diff line change
Expand Up @@ -3717,10 +3717,10 @@ _NODISCARD_ASSUME_ALIGNED constexpr _Ty* assume_aligned(_Ty* const _Ptr) noexcep
}
#endif // _HAS_CXX20

_EXTERN_C
extern "C" {
_CRTIMP2_PURE void __cdecl _Lock_shared_ptr_spin_lock() noexcept;
_CRTIMP2_PURE void __cdecl _Unlock_shared_ptr_spin_lock() noexcept;
_END_EXTERN_C
} // extern "C"

struct _Shared_ptr_spin_lock { // class to manage a spin lock for shared_ptr atomic operations
_Shared_ptr_spin_lock() { // lock the spin lock
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/stacktrace
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ _STL_DISABLE_CLANG_WARNINGS
// string buffer for cases when the size is not known before an attempt to fill it -- this potentially avoids both an
// extra fill attempt and an extra allocation if the reserved size is enough.

extern "C" {
using _Stacktrace_string_fill_callback = size_t(__stdcall*)(char* _Data, size_t _Size, void* _Context) _NOEXCEPT_FNPTR;

using _Stacktrace_string_fill = size_t(__stdcall*)(
size_t _Size, void* _String, void* _Context, _Stacktrace_string_fill_callback _Callback);

_EXTERN_C
_NODISCARD unsigned short __stdcall __std_stacktrace_capture(unsigned long _Frames_to_skip,
unsigned long _Frames_to_capture, void** _Back_trace, unsigned long* _Back_trace_hash) noexcept;

Expand All @@ -64,7 +64,7 @@ _NODISCARD unsigned int __stdcall __std_stacktrace_source_line(const void* _Addr

void __stdcall __std_stacktrace_to_string(
const void* const* _Addresses, size_t _Size, void* _Str, _Stacktrace_string_fill _Fill) noexcept(false);
_END_EXTERN_C
} // extern "C"

_STD_BEGIN
inline size_t __stdcall _Stacktrace_string_fill_impl(
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/syncstream
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ _STL_DISABLE_CLANG_WARNINGS
#undef new
#undef emit

_EXTERN_C
extern "C" {
_NODISCARD _STD shared_mutex* __stdcall __std_acquire_shared_mutex_for_instance(void* _Ptr) noexcept;
void __stdcall __std_release_shared_mutex_for_instance(void* _Ptr) noexcept;
_END_EXTERN_C
} // extern "C"

_STD_BEGIN

Expand Down
4 changes: 2 additions & 2 deletions stl/inc/system_error
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,9 @@ _EXPORT_STD _NODISCARD inline const error_category& system_category() noexcept {
_STD_END

#if _HAS_CXX17
_EXTERN_C
extern "C" {
enum class __std_win_error : unsigned long;
_END_EXTERN_C
} // extern "C"

_STD_BEGIN
// We would really love to use the proper way of building error_code by specializing
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/xatomic_wait.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _STL_DISABLE_CLANG_WARNINGS
_INLINE_VAR constexpr unsigned long long _Atomic_wait_no_deadline = 0xFFFF'FFFF'FFFF'FFFF;
_INLINE_VAR constexpr unsigned long _Atomic_wait_no_timeout = 0xFFFF'FFFF; // Pass as partial timeout

_EXTERN_C
extern "C" {
enum class __std_atomic_api_level : unsigned long {
__not_set,
__detecting,
Expand Down Expand Up @@ -61,7 +61,7 @@ void __stdcall __std_atomic_notify_all_indirect(const void* _Storage) noexcept;
unsigned long long __stdcall __std_atomic_wait_get_deadline(unsigned long long _Timeout) noexcept;
unsigned long __stdcall __std_atomic_wait_get_remaining_timeout(unsigned long long _Deadline) noexcept;

_END_EXTERN_C
} // extern "C"

#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
Expand Down
24 changes: 12 additions & 12 deletions stl/inc/xfilesystem_abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

_EXTERN_C
extern "C" {
inline constexpr size_t __std_fs_max_path = 260; // #define MAX_PATH 260
inline constexpr size_t __std_fs_temp_path_max = __std_fs_max_path + 1;

Expand Down Expand Up @@ -76,11 +76,11 @@ enum class __std_fs_file_attr : unsigned long {

_Invalid = 0xFFFFFFFF, // #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
};
_END_EXTERN_C
} // extern "C"

_BITMASK_OPS(_EMPTY_ARGUMENT, __std_fs_file_attr)

_EXTERN_C
extern "C" {
enum class __std_fs_reparse_tag : unsigned long {
_None = 0,
_Mount_point = (0xA0000003L), // #define IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L)
Expand Down Expand Up @@ -121,11 +121,11 @@ enum class __std_fs_stats_flags : unsigned long {

_All_data = _Attributes | _Reparse_tag | _File_size | _Link_count | _Last_write_time
};
_END_EXTERN_C
} // extern "C"

_BITMASK_OPS(_EMPTY_ARGUMENT, __std_fs_stats_flags)

_EXTERN_C
extern "C" {
struct __std_fs_stats {
long long _Last_write_time;
unsigned long long _File_size;
Expand Down Expand Up @@ -197,21 +197,21 @@ enum class __std_access_rights : unsigned long {
// | FILE_WRITE_EA | FILE_APPEND_DATA | SYNCHRONIZE)
_File_generic_write = 0x00120116,
};
_END_EXTERN_C
} // extern "C"

_BITMASK_OPS(_EMPTY_ARGUMENT, __std_access_rights)

_EXTERN_C
extern "C" {
enum class __std_fs_file_flags : unsigned long {
_None = 0,
_Backup_semantics = 0x02000000, // #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000
_Open_reparse_point = 0x00200000, // #define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000
};
_END_EXTERN_C
} // extern "C"

_BITMASK_OPS(_EMPTY_ARGUMENT, __std_fs_file_flags)

_EXTERN_C
extern "C" {
enum class __std_fs_file_handle : intptr_t { _Invalid = -1 };

enum class __std_code_page : unsigned int { _Acp = 0, _Utf8 = 65001 };
Expand All @@ -234,11 +234,11 @@ enum class __std_fs_copy_options {
_Overwrite_existing = 0x2,
_Update_existing = 0x4,
};
_END_EXTERN_C
} // extern "C"

_BITMASK_OPS(_EMPTY_ARGUMENT, __std_fs_copy_options)

_EXTERN_C
extern "C" {
_NODISCARD __std_ulong_and_error __stdcall __std_fs_get_full_path_name(_In_z_ const wchar_t* _Source,
_In_ unsigned long _Target_size, _Out_writes_z_(_Target_size) wchar_t* _Target) noexcept;

Expand Down Expand Up @@ -352,7 +352,7 @@ _NODISCARD __std_win_error __stdcall __std_fs_resize_file(_In_z_ const wchar_t*

_NODISCARD __std_win_error __stdcall __std_fs_space(_In_z_ const wchar_t* _Target, _Out_ uintmax_t* _Available,
_Out_ uintmax_t* _Total_bytes, _Out_ uintmax_t* _Free_bytes) noexcept;
_END_EXTERN_C
} // extern "C"

_STD_BEGIN
struct _Fs_file {
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/xlocinfo
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ _CRTIMP2_PURE wchar_t __CLRCALL_PURE_OR_CDECL _Towupper(wchar_t, const _Ctypevec

_END_EXTERN_C_UNLESS_PURE

_EXTERN_C
extern "C" {
// These _should_ be explicitly `noexcept` but cannot be made so here because
// the primary declarations in the C runtime headers are not.

Expand All @@ -102,7 +102,7 @@ _ACRTIMP void* __cdecl _W_Gettnames();

_Success_(return > 0) _ACRTIMP size_t __cdecl _Wcsftime(
_Out_writes_z_(_Maxsize) wchar_t*, _In_ size_t _Maxsize, _In_z_ const wchar_t*, _In_ const tm*, _In_opt_ void*);
_END_EXTERN_C
} // extern "C"

_STD_BEGIN
extern "C++" class _CRTIMP2_PURE_IMPORT _Timevec { // smart pointer to information used by _Strftime
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/xthreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

_EXTERN_C
extern "C" {
using _Thrd_id_t = unsigned int;
struct _Thrd_t { // thread identifier for Win32
void* _Hnd; // Win32 HANDLE
Expand Down Expand Up @@ -130,7 +130,7 @@ _CRTIMP2_PURE _Thrd_result __cdecl _Cnd_signal(_Cnd_t) noexcept; // TRANSITION,
_CRTIMP2_PURE void __cdecl _Cnd_register_at_thread_exit(_Cnd_t, _Mtx_t, int*) noexcept;
_CRTIMP2_PURE void __cdecl _Cnd_unregister_at_thread_exit(_Mtx_t) noexcept;
_CRTIMP2_PURE void __cdecl _Cnd_do_broadcast_at_thread_exit() noexcept;
_END_EXTERN_C
} // extern "C"

_STD_BEGIN
enum { // constants for error codes
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/xtimec.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

_EXTERN_C
extern "C" {

#ifdef _CRTBLD
_CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis2(const _timespec64*, const _timespec64*) noexcept;
Expand All @@ -33,7 +33,7 @@ void _Timespec64_get_sys(_timespec64*) noexcept;
_CRTIMP2_PURE long long __cdecl _Query_perf_counter() noexcept;
_CRTIMP2_PURE long long __cdecl _Query_perf_frequency() noexcept;

_END_EXTERN_C
} // extern "C"

#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
Expand Down
Loading

0 comments on commit 3f15c7f

Please sign in to comment.