[proxy](5/n) use c headers instead of c++ headers (#720)

This commit is contained in:
Schrodinger ZHU Yifan
2025-01-09 17:45:24 +08:00
committed by GitHub
parent 6a3c5750bd
commit e874617d8e
21 changed files with 53 additions and 39 deletions

View File

@@ -16,7 +16,7 @@
# define SNMALLOC_TICK_USE_CLOCK_GETTIME
# endif
#endif
#include <cstdint>
#include <stdint.h>
#include <utility>
#ifndef SNMALLOC_TICK_USE_CLOCK_GETTIME

View File

@@ -12,7 +12,7 @@
# endif
#endif
#include <cstddef>
#include <stddef.h>
namespace snmalloc
{

View File

@@ -1,5 +1,5 @@
#pragma once
#include <cstdint>
#include <stdint.h>
namespace snmalloc
{

View File

@@ -1,7 +1,7 @@
#pragma once
#include "../ds_core/ds_core.h"
#include <cstdint>
#include <stdint.h>
namespace snmalloc
{

View File

@@ -27,7 +27,7 @@ namespace snmalloc
class ABA
{
public:
struct alignas(2 * sizeof(std::size_t)) Linked
struct alignas(2 * sizeof(size_t)) Linked
{
T* ptr{nullptr};
uintptr_t aba{0};
@@ -43,13 +43,13 @@ namespace snmalloc
sizeof(Linked) == sizeof(Independent),
"Expecting identical struct sizes in union");
static_assert(
sizeof(Linked) == (2 * sizeof(std::size_t)),
sizeof(Linked) == (2 * sizeof(size_t)),
"Expecting ABA to be the size of two pointers");
private:
union
{
alignas(2 * sizeof(std::size_t)) stl::Atomic<Linked> linked;
alignas(2 * sizeof(size_t)) stl::Atomic<Linked> linked;
Independent independent;
};

View File

@@ -1,7 +1,6 @@
#pragma once
#include <cstddef>
#include <limits>
#include <stddef.h>
// #define USE_LZCNT
@@ -9,9 +8,10 @@
#include "snmalloc/stl/atomic.h"
#include "snmalloc/stl/type_traits.h"
#include <climits>
#include <cstdint>
#include <limits.h>
#include <stdint.h>
#if defined(_MSC_VER)
# include <intrin.h>
# include <intsafe.h>
#endif
@@ -95,15 +95,15 @@ namespace snmalloc
return BITS - index - 1;
# endif
#else
if constexpr (stl::is_same_v<unsigned long, std::size_t>)
if constexpr (stl::is_same_v<unsigned long, size_t>)
{
return static_cast<size_t>(__builtin_clzl(x));
}
else if constexpr (stl::is_same_v<unsigned long long, std::size_t>)
else if constexpr (stl::is_same_v<unsigned long long, size_t>)
{
return static_cast<size_t>(__builtin_clzll(x));
}
else if constexpr (stl::is_same_v<unsigned int, std::size_t>)
else if constexpr (stl::is_same_v<unsigned int, size_t>)
{
return static_cast<size_t>(__builtin_clz(x));
}
@@ -182,15 +182,15 @@ namespace snmalloc
return _tzcnt_u32(static_cast<unsigned int>(x));
# endif
#else
if constexpr (stl::is_same_v<unsigned long, std::size_t>)
if constexpr (stl::is_same_v<unsigned long, size_t>)
{
return static_cast<size_t>(__builtin_ctzl(x));
}
else if constexpr (stl::is_same_v<unsigned long long, std::size_t>)
else if constexpr (stl::is_same_v<unsigned long long, size_t>)
{
return static_cast<size_t>(__builtin_ctzll(x));
}
else if constexpr (stl::is_same_v<unsigned int, std::size_t>)
else if constexpr (stl::is_same_v<unsigned int, size_t>)
{
return static_cast<size_t>(__builtin_ctz(x));
}

View File

@@ -1,5 +1,5 @@
#pragma once
#include <cstddef>
#include <stddef.h>
#if defined(_MSC_VER) && !defined(__clang__)
// 28 is FAST_FAIL_INVALID_BUFFER_ACCESS. Not using the symbolic constant to

View File

@@ -5,7 +5,7 @@
#include "snmalloc/stl/type_traits.h"
#include <array>
#include <cstddef>
#include <stddef.h>
namespace snmalloc
{

View File

@@ -1,7 +1,7 @@
#pragma once
#include "defines.h"
#include <cstddef>
#include <stddef.h>
namespace snmalloc
{

View File

@@ -1,8 +1,8 @@
#pragma once
#include <array>
#include <cstddef>
#include <cstdint>
#include <stddef.h>
#include <stdint.h>
namespace snmalloc
{

View File

@@ -4,7 +4,7 @@
#include "../ds_core/ds_core.h"
#include "snmalloc/stl/type_traits.h"
#include <cstdint>
#include <stdint.h>
namespace snmalloc
{

View File

@@ -4,7 +4,7 @@
#include "../pal/pal.h"
#include "snmalloc/stl/type_traits.h"
#include <cstdint>
#include <stdint.h>
namespace snmalloc
{

View File

@@ -37,7 +37,7 @@
#include "entropy.h"
#include "snmalloc/stl/new.h"
#include <cstdint>
#include <stdint.h>
namespace snmalloc
{

View File

@@ -1,5 +1,6 @@
#pragma once
#include "snmalloc/aal/address.h"
#if defined(_MSC_VER)
# define ALLOCATOR __declspec(allocator) __declspec(restrict)
#elif __has_attribute(malloc)
@@ -888,8 +889,18 @@ namespace snmalloc
auto sizeclass = entry.get_sizeclass();
return snmalloc::remaining_bytes(sizeclass, p);
#else
return reinterpret_cast<size_t>(
std::numeric_limits<decltype(p)>::max() - p);
constexpr address_t mask = static_cast<address_t>(-1);
constexpr bool is_signed = mask < 0;
constexpr address_t sign_bit =
bits::one_at_bit<address_t>(CHAR_BIT * sizeof(address_t) - 1);
if constexpr (is_signed)
{
return (mask ^ sign_bit) - p;
}
else
{
return mask - p;
}
#endif
}

View File

@@ -2,7 +2,7 @@
#include "../ds_core/ds_core.h"
#include <cstdint>
#include <stdint.h>
namespace snmalloc
{

View File

@@ -1,6 +1,7 @@
#include "override.h"
#include <errno.h>
#include <limits.h>
#include <string.h>
using namespace snmalloc;
@@ -182,7 +183,7 @@ extern "C"
return allocm_err_not_moved;
}
if (std::numeric_limits<size_t>::max() - size > extra)
if (SIZE_MAX - size > extra)
{
alloc_size = f.aligned_size(size + extra);
}

View File

@@ -1,7 +1,7 @@
#define SNMALLOC_NAME_MANGLE(a) sn_##a
#include "snmalloc/snmalloc.h"
#include <cstring>
#include <string.h>
#ifndef SNMALLOC_EXPORT
# define SNMALLOC_EXPORT
@@ -39,7 +39,7 @@ extern "C" SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(rust_realloc)(
void* p = ThreadAlloc::get().alloc(aligned_new_size);
if (p)
{
std::memcpy(p, ptr, old_size < new_size ? old_size : new_size);
memcpy(p, ptr, old_size < new_size ? old_size : new_size);
ThreadAlloc::get().dealloc(ptr, aligned_old_size);
}
return p;

View File

@@ -30,8 +30,8 @@ namespace snmalloc
template<typename PAL>
concept IsPAL_static_sizes =
requires() {
typename stl::integral_constant<std::size_t, PAL::address_bits>;
typename stl::integral_constant<std::size_t, PAL::page_size>;
typename stl::integral_constant<size_t, PAL::address_bits>;
typename stl::integral_constant<size_t, PAL::page_size>;
};
/**
@@ -48,7 +48,7 @@ namespace snmalloc
* PALs expose a basic library of memory operations.
*/
template<typename PAL>
concept IsPAL_memops = requires(void* vp, std::size_t sz) {
concept IsPAL_memops = requires(void* vp, size_t sz) {
{
PAL::notify_not_using(vp, sz)
} noexcept -> ConceptSame<void>;
@@ -72,7 +72,7 @@ namespace snmalloc
* Absent any feature flags, the PAL must support a crude primitive allocator
*/
template<typename PAL>
concept IsPAL_reserve = requires(PAL p, std::size_t sz) {
concept IsPAL_reserve = requires(PAL p, size_t sz) {
{
PAL::reserve(sz)
} noexcept -> ConceptSame<void*>;
@@ -82,7 +82,7 @@ namespace snmalloc
* Some PALs expose a richer allocator which understands aligned allocations
*/
template<typename PAL>
concept IsPAL_reserve_aligned = requires(std::size_t sz) {
concept IsPAL_reserve_aligned = requires(size_t sz) {
{
PAL::template reserve_aligned<true>(sz)
} noexcept -> ConceptSame<void*>;

View File

@@ -8,7 +8,7 @@
#include "pal_consts.h"
#include "pal_timer_default.h"
#include <cstring>
#include <string.h>
namespace snmalloc
{

View File

@@ -5,17 +5,18 @@
#if defined(SNMALLOC_BACKTRACE_HEADER)
# include SNMALLOC_BACKTRACE_HEADER
#endif
#include <cstdlib>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/mman.h>
#include <sys/uio.h>
#include <unistd.h>
#include <utility>
#if __has_include(<sys/random.h>)
# include <sys/random.h>
#endif

View File

@@ -1,4 +1,5 @@
#include <functional>
#include <limits.h>
#include <stdio.h>
#include <test/helpers.h>
#include <test/setup.h>
@@ -288,7 +289,7 @@ namespace
{
START_TEST("allocm out-of-memory behaviour");
void* ptr = nullptr;
int ret = Allocm(&ptr, nullptr, std::numeric_limits<size_t>::max() / 2, 0);
int ret = Allocm(&ptr, nullptr, SIZE_MAX / 2, 0);
EXPECT(
(ptr == nullptr) && (ret == OUR_ALLOCM_ERR_OOM),
"Expected massive allocation to fail with out of memory ({}), received "