mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
The short answer for why we need to do this is so we can consistently do `#include "nix/..."`. Without this change, there are ways to still make that work, but they are hacky, and they have downsides such as making it harder to make sure headers from the wrong Nix library (e..g. `libnixexpr` headers in `libnixutil`) aren't being used. The C API alraedy used `nix_api_*`, so its headers are *not* put in subdirectories accordingly. Progress on #7876 We resisted doing this for a while because it would be annoying to not have the header source file pairs close by / easy to change file path/name from one to the other. But I am ameliorating that with symlinks in the next commit.
53 lines
762 B
C++
53 lines
762 B
C++
#pragma once
|
|
///@file
|
|
|
|
#include <cstddef>
|
|
|
|
#if HAVE_BOEHMGC
|
|
|
|
# define GC_INCLUDE_NEW
|
|
|
|
# include <gc/gc.h>
|
|
# include <gc/gc_cpp.h>
|
|
# include <gc/gc_allocator.h>
|
|
|
|
#else
|
|
|
|
# include <memory>
|
|
|
|
/* Some dummy aliases for Boehm GC definitions to reduce the number of
|
|
#ifdefs. */
|
|
|
|
template<typename T>
|
|
using traceable_allocator = std::allocator<T>;
|
|
|
|
template<typename T>
|
|
using gc_allocator = std::allocator<T>;
|
|
|
|
# define GC_MALLOC_ATOMIC std::malloc
|
|
|
|
struct gc
|
|
{};
|
|
|
|
#endif
|
|
|
|
namespace nix {
|
|
|
|
/**
|
|
* Initialise the Boehm GC, if applicable.
|
|
*/
|
|
void initGC();
|
|
|
|
/**
|
|
* Make sure `initGC` has already been called.
|
|
*/
|
|
void assertGCInitialized();
|
|
|
|
#ifdef HAVE_BOEHMGC
|
|
/**
|
|
* The number of GC cycles since initGC().
|
|
*/
|
|
size_t getGCCycles();
|
|
#endif
|
|
|
|
} // namespace nix
|