progress on base, deciding to keep the MD namespace minimal on macros pre-c11 or cpp17 gen refactors

This commit is contained in:
ed
2025-02-05 11:20:32 -05:00
parent c1d24b3a07
commit 8936ae9aa7
15 changed files with 370 additions and 246 deletions
+9
View File
@@ -31,6 +31,15 @@ struct ArenaParams
void* optional_backing_buffer;
};
/* NOTE(Ed): This is a combination of several concepts into a single interface:
* A arena 'block' of memory with segmented chaining of the blocks
* An OS virtual memory allocation scheme
* A push/pop stack allocation interface for the arena
TODO(Ed): We need to lift the virtual memory tracking to its own data structure
and virtual memory interface utilizing memory_substrate.h
*/
typedef struct Arena Arena;
struct Arena
{
+1 -1
View File
@@ -6,7 +6,7 @@
# include "platform.h"
#endif
#if defined( MD_COMPILER_MSVC )
#if defined( COMPILER_MSVC )
# if _MSC_VER < 1300
typedef unsigned char U8;
typedef signed char S8;
+2 -2
View File
@@ -40,12 +40,12 @@
#define MD_S64_MIN ( -0x7fffffffffffffffll - 1 )
#define MD_S64_MAX 0x7fffffffffffffffll
#if defined( MD_ARCH_32_BIT )
#if defined( ARCH_32_BIT )
# define MD_USIZE_MIN MD_U32_MIN
# define MD_USIZE_MAX MD_U32_MAX
# define MD_ISIZE_MIN MD_S32_MIN
# define MD_ISIZE_MAX MD_S32_MAX
#elif defined( MD_ARCH_64_BIT )
#elif defined( ARCH_64_BIT )
# define MD_USIZE_MIN MD_U64_MIN
# define MD_USIZE_MAX MD_U64_MAX
# define MD_ISIZE_MIN MD_S64_MIN
+108 -108
View File
@@ -6,83 +6,83 @@
#if defined( _MSC_VER )
# pragma message("Detected MSVC")
// # define MD_COMPILER_CLANG 0
# define MD_COMPILER_MSVC 1
// # define MD_COMPILER_GCC 0
// # define COMPILER_CLANG 0
# define COMPILER_MSVC 1
// # define COMPILER_GCC 0
# if _MSC_VER >= 1920
# define MD_COMPILER_MSVC_YEAR 2019
# define COMPILER_MSVC_YEAR 2019
# elif _MSC_VER >= 1910
# define MD_COMPILER_MSVC_YEAR 2017
# define COMPILER_MSVC_YEAR 2017
# elif _MSC_VER >= 1900
# define MD_COMPILER_MSVC_YEAR 2015
# define COMPILER_MSVC_YEAR 2015
# elif _MSC_VER >= 1800
# define MD_COMPILER_MSVC_YEAR 2013
# define COMPILER_MSVC_YEAR 2013
# elif _MSC_VER >= 1700
# define MD_COMPILER_MSVC_YEAR 2012
# define COMPILER_MSVC_YEAR 2012
# elif _MSC_VER >= 1600
# define MD_COMPILER_MSVC_YEAR 2010
# define COMPILER_MSVC_YEAR 2010
# elif _MSC_VER >= 1500
# define M_DCOMPILER_MSVC_YEAR 2008
# elif _MSC_VER >= 1400
# define MD_COMPILER_MSVC_YEAR 2005
# define COMPILER_MSVC_YEAR 2005
# else
# define MD_COMPILER_MSVC_YEAR 0
# define COMPILER_MSVC_YEAR 0
# endif
#elif defined( __GNUC__ )
# pragma message("Detected GCC")
// # define MD_COMPILER_CLANG 0
// # define MD_COMPILER_MSVC 0
# define MD_COMPILER_GCC 1
// # define COMPILER_CLANG 0
// # define COMPILER_MSVC 0
# define COMPILER_GCC 1
#elif defined( __clang__ )
# pragma message("Detected CLANG")
# define MD_COMPILER_CLANG 1
// # define MD_COMPILER_MSVC 0
// # define MD_COMPILER_GCC 0
# define COMPILER_CLANG 1
// # define COMPILER_MSVC 0
// # define COMPILER_GCC 0
#else
# error Unknown compiler
#endif
#if defined( __has_attribute )
# define MD_HAS_ATTRIBUTE( attribute ) __has_attribute( attribute )
# define HAS_ATTRIBUTE( attribute ) __has_attribute( attribute )
#else
# define MD_HAS_ATTRIBUTE( attribute ) ( 0 )
# define HAS_ATTRIBUTE( attribute ) ( 0 )
#endif
#if defined(MD_GCC_VERSION_CHECK)
# undef MD_GCC_VERSION_CHECK
#if defined(GCC_VERSION_CHECK)
# undef GCC_VERSION_CHECK
#endif
#if defined(GEN_GCC_VERSION)
# define MD_GCC_VERSION_CHECK(major,minor,patch) (GEN_GCC_VERSION >= GEN_VERSION_ENCODE(major, minor, patch))
# define GCC_VERSION_CHECK(major,minor,patch) (GEN_GCC_VERSION >= GEN_VERSION_ENCODE(major, minor, patch))
#else
# define MD_GCC_VERSION_CHECK(major,minor,patch) (0)
# define GCC_VERSION_CHECK(major,minor,patch) (0)
#endif
#pragma endregion Compiler Vendor
#pragma endregion Language
#if ! defined(MD_LANG_C)
#if ! defined(LANG_C)
# ifdef __cplusplus
# define MD_LANG_C 0
# define MD_LANG_CPP 1
# define LANG_C 0
# define LANG_CPP 1
# else
# if defined(__STDC__)
# define MD_LANG_C 1
# define MD_LANG_CPP 0
# define LANG_C 1
# define LANG_CPP 0
# else
// Fallback for very old C compilers
# define MD_LANG_C 1
# define MD_LANG_CPP 0
# define LANG_C 1
# define LANG_CPP 0
# endif
# endif
#endif
#if MD_LANG_C
#if LANG_C
# pragma message("MD: Detected C")
#endif
#if MD_LANG_CPP
#if LANG_CPP
# pragma message("MD: Detected CPP")
#endif
@@ -90,56 +90,56 @@
#pragma region Hardware Architecture
#if MD_COMPILER_CLANG
#if COMPILER_CLANG
# if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
# define MD_ARCH_X64 1
# define ARCH_X64 1
# elif defined(i386) || defined(__i386) || defined(__i386__)
# define MD_ARCH_X86 1
# define ARCH_X86 1
# elif defined(__aarch64__)
# define MD_ARCH_ARM64 1
# define ARCH_ARM64 1
# elif defined(__arm__)
# define MD_ARCH_ARM32 1
# define ARCH_ARM32 1
# else
# error Architecture not supported.
# endif
#endif // MD_COMPILER_CLANG
#endif // COMPILER_CLANG
#if MD_COMPILER_MSVC
#if COMPILER_MSVC
# if defined(_M_AMD64)
# define MD_ARCH_X64 1
# define ARCH_X64 1
# elif defined(_M_IX86)
# define MD_ARCH_X86 1
# define ARCH_X86 1
# elif defined(_M_ARM64)
# define MD_ARCH_ARM64 1
# define ARCH_ARM64 1
# elif defined(_M_ARM)
# define MD_ARCH_ARM32 1
# define ARCH_ARM32 1
# else
# error Architecture not supported.
# endif
#endif // MD_COMPILER_MSVC
#endif // COMPILER_MSVC
#if MD_COMPILER_GCC
#if COMPILER_GCC
# if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
# define MD_ARCH_X64 1
# define ARCH_X64 1
# elif defined(i386) || defined(__i386) || defined(__i386__)
# define MD_ARCH_X86 1
# define ARCH_X86 1
# elif defined(__aarch64__)
# define MD_ARCH_ARM64 1
# define ARCH_ARM64 1
# elif defined(__arm__)
# define MD_ARCH_ARM32 1
# define ARCH_ARM32 1
# else
# error Architecture not supported.
# endif
#endif // MD_COMPILER_GCC
#endif // COMPILER_GCC
#if defined(MD_ARCH_X64)
# define MD_ARCH_64BIT 1
#elif defined(MD_ARCH_X86)
# define MD_ARCH_32BIT 1
#if defined(ARCH_X64)
# define ARCH_64BIT 1
#elif defined(ARCH_X86)
# define ARCH_32BIT 1
#endif
#if MD_ARCH_ARM32 || MD_ARCH_ARM64 || MD_ARCH_X64 || MD_ARCH_X86
# define MD_ARCH_LITTLE_ENDIAN 1
#if ARCH_ARM32 || ARCH_ARM64 || ARCH_X64 || ARCH_X86
# define ARCH_LITTLE_ENDIAN 1
#else
# error Endianness of this architecture not understood by context cracker.
#endif
@@ -149,46 +149,46 @@
#pragma region Operating System
#if defined( _WIN32 ) || defined( _WIN64 )
# ifndef MD_OS_WINDOWS
# define MD_OS_WINDOWS 1
# ifndef OS_WINDOWS
# define OS_WINDOWS 1
# endif
#elif defined( __APPLE__ ) && defined( __MACH__ )
# ifndef MD_OS_OSX
# define MD_OS_OSX 1
# ifndef OS_OSX
# define OS_OSX 1
# endif
# ifndef MD_OS_MACOS
# define MD_OS_MACOS 1
# ifndef OS_MACOS
# define OS_MACOS 1
# endif
#elif defined( __unix__ )
# ifndef MD_OS_UNIX
# define MD_OS_UNIX 1
# ifndef OS_UNIX
# define OS_UNIX 1
# endif
# if defined( ANDROID ) || defined( __ANDROID__ )
# ifndef MD_OS_ANDROID
# define MD_OS_ANDROID 1
# ifndef OS_ANDROID
# define OS_ANDROID 1
# endif
# ifndef MD_OS_LINUX
# define MD_OS_LINUX 1
# ifndef OS_LINUX
# define OS_LINUX 1
# endif
# elif defined( __linux__ )
# ifndef MD_OS_LINUX
# define MD_OS_LINUX 1
# ifndef OS_LINUX
# define OS_LINUX 1
# endif
# elif defined( __FreeBSD__ ) || defined( __FreeBSD_kernel__ )
# ifndef MD_OS_FREEBSD
# define MD_OS_FREEBSD 1
# ifndef OS_FREEBSD
# define OS_FREEBSD 1
# endif
# elif defined( __OpenBSD__ )
# ifndef MD_OS_OPENBSD
# define MD_OS_OPENBSD 1
# ifndef OS_OPENBSD
# define OS_OPENBSD 1
# endif
# elif defined( __EMSCRIPTEN__ )
# ifndef MD_OS_EMSCRIPTEN
# define MD_OS_EMSCRIPTEN 1
# ifndef OS_EMSCRIPTEN
# define OS_EMSCRIPTEN 1
# endif
# elif defined( __CYGWIN__ )
# ifndef MD_OS_CYGWIN
# define MD_OS_CYGWIN 1
# ifndef OS_CYGWIN
# define OS_CYGWIN 1
# endif
# else
# error This UNIX operating system is not supported
@@ -205,55 +205,55 @@
////////////////////////////////
//~ rjf: Zero All Undefined Options
#if !defined(MD_ARCH_32BIT)
# define MD_ARCH_32BIT 0
#if !defined(ARCH_32BIT)
# define ARCH_32BIT 0
#endif
#if !defined(MD_ARCH_64BIT)
# define MD_ARCH_64BIT 0
#if !defined(ARCH_64BIT)
# define ARCH_64BIT 0
#endif
#if !defined(MD_ARCH_X64)
# define MD_ARCH_X64 0
#if !defined(ARCH_X64)
# define ARCH_X64 0
#endif
#if !defined(MD_ARCH_X86)
# define MD_ARCH_X86 0
#if !defined(ARCH_X86)
# define ARCH_X86 0
#endif
#if !defined(MD_ARCH_ARM64)
# define MD_ARCH_ARM64 0
#if !defined(ARCH_ARM64)
# define ARCH_ARM64 0
#endif
#if !defined(MD_ARCH_ARM32)
# define MD_ARCH_ARM32 0
#if !defined(ARCH_ARM32)
# define ARCH_ARM32 0
#endif
#if !defined(MD_COMPILER_MSVC)
# define MD_COMPILER_MSVC 0
#if !defined(COMPILER_MSVC)
# define COMPILER_MSVC 0
#endif
#if !defined(MD_COMPILER_GCC)
# define MD_COMPILER_GCC 0
#if !defined(COMPILER_GCC)
# define COMPILER_GCC 0
#endif
#if !defined(MD_COMPILER_CLANG)
# define MD_COMPILER_CLANG 0
#if !defined(COMPILER_CLANG)
# define COMPILER_CLANG 0
#endif
#if !defined(MD_OS_WINDOWS)
# define MD_OS_WINDOWS 0
#if !defined(OS_WINDOWS)
# define OS_WINDOWS 0
#endif
#if !defined(MD_OS_LINUX)
# define MD_OS_LINUX 0
#if !defined(OS_LINUX)
# define OS_LINUX 0
#endif
#if !defined(MD_OS_MAC)
# define MD_OS_MAC 0
#if !defined(OS_MAC)
# define OS_MAC 0
#endif
#if !defined(MD_LANG_CPP)
# define MD_LANG_CPP 0
#if !defined(LANG_CPP)
# define LANG_CPP 0
#endif
#if !defined(MD_LANG_C)
# define MD_LANG_C 0
#if !defined(LANG_C)
# define LANG_C 0
#endif
////////////////////////////////
//~ rjf: Unsupported Errors
#if MD_ARCH_X86
#if ARCH_X86
# error You tried to build in x86 (32 bit) mode, but currently, only building in x64 (64 bit) mode is supported.
#endif
#if ! MD_ARCH_X64
#if ! ARCH_X64
# error You tried to build with an unsupported architecture. Currently, only building in x64 mode is supported.
#endif
+2 -2
View File
@@ -4,7 +4,7 @@
#endif
#ifndef MD_API
#if MD_COMPILER_MSVC
#if COMPILER_MSVC
# ifdef MD_DYN_LINK
# ifdef MD_DYN_EXPORT
# define MD_API __declspec(dllexport)
@@ -24,7 +24,7 @@
#endif // GEN_API
#ifndef MD_API_C_BEGIN
# if MD_LANG_C
# if LANG_C
# define MD_API_C_BEGIN
# define MD_API_C_END
# define MD_API_C
+10 -10
View File
@@ -8,16 +8,16 @@
#define local_persist static
#endif
#if MD_COMPILER_MSVC
#if COMPILER_MSVC
# define thread_static __declspec(thread)
#elif MD_COMPILER_CLANG || MD_COMPILER_GCC
#elif COMPILER_CLANG || COMPILER_GCC
# define thread_static __thread
#endif
////////////////////////////////
//~ rjf: Branch Predictor Hints
#if MD_COMPILER_CLANG
#if COMPILER_CLANG
# define expect(expr, val) __builtin_expect((expr), (val))
#else
# define expect(expr, val) (expr)
@@ -29,7 +29,7 @@
////////////////////////////////
//~ erg: type casting
#if MD_LANG_CPP
#if LANG_CPP
# ifndef ccast
# define ccast( type, value ) ( const_cast< type >( (value) ) )
# endif
@@ -57,8 +57,8 @@
# endif
#endif
#if ! defined(typeof) && ( ! MD_LANG_C || __STDC_VERSION__ < 202311L)
# if ! MD_LANG_C
#if ! defined(typeof) && ( ! LANG_C || __STDC_VERSION__ < 202311L)
# if ! LANG_C
# define typeof decltype
# elif defined(_MSC_VER)
# define typeof __typeof__
@@ -69,7 +69,7 @@
# endif
#endif
#if MD_LANG_C
#if LANG_C
# if __STDC_VERSION__ >= 202311L
# define enum_underlying(type) : type
# else
@@ -79,7 +79,7 @@
# define enum_underlying(type) : type
#endif
#if MD_LANG_C
#if LANG_C
# ifndef nullptr
# define nullptr NULL
# endif
@@ -89,13 +89,13 @@
# endif
#endif
#if ! defined(MD_PARAM_DEFAULT) && MD_LANG_CPP
#if ! defined(MD_PARAM_DEFAULT) && LANG_CPP
# define MD_PARAM_DEFAULT = {}
#else
# define MD_PARAM_DEFAULT
#endif
#if MD_LANG_C
#if LANG_C
# ifndef static_assert
# undef static_assert
# if __STDC_VERSION__ >= 201112L
+85 -24
View File
@@ -4,40 +4,75 @@
# include "linkage.h"
# include "macros.h"
# include "platform.h"
# include "memory_substrate.h"
#endif
////////////////////////////////
//~ rjf: Units
#define KB(n) (((U64)(n)) << 10)
#define MB(n) (((U64)(n)) << 20)
#define GB(n) (((U64)(n)) << 30)
#define TB(n) (((U64)(n)) << 40)
#ifndef KILOBTYES
#define KILOBYTES( x ) ( ( x ) * ( S64 )( 1024 ) )
#endif
#ifndef MEGABYTES
#define MEGABYTES( x ) ( MD_KILOBYTES( x ) * ( S64 )( 1024 ) )
#endif
#ifndef GIGABYTES
#define GIGABYTES( x ) ( MD_MEGABYTES( x ) * ( S64 )( 1024 ) )
#endif
#ifndef TERABYTES
#define TERABYTES( x ) ( MD_GIGABYTES( x ) * ( S64 )( 1024 ) )
#endif
#ifndef KB
#define KB(n) (((U64)(n)) << 10)
#endif
#ifndef MB
#define MB(n) (((U64)(n)) << 20)
#endif
#ifndef GB
#define GB(n) (((U64)(n)) << 30)
#endif
#ifndef TB
#define TB(n) (((U64)(n)) << 40)
#endif
#ifndef thosuand
#define thousand(n) ((n) * 1000)
#endif
#ifndef million
#define million(n) ((n) * 1000000)
#endif
#ifndef billion
#define billion(n) ((n) * 1000000000)
#endif
////////////////////////////////
//~ rjf: Clamps, Mins, Maxes
#ifndef min
#define min(A,B) (((A) < (B)) ? (A) : (B))
#endif
#ifndef max
#define max(A,B) (((A) > (B)) ? (A) : (B))
#endif
#ifndef clamp_top
#define clamp_top(A,X) Min(A, X)
#endif
#ifndef clamp_bot
#define clamp_bot(X,B) Max(X, B)
#endif
#define clamp(A,X,B) (((X) < (A)) ? (A) : ((X) > (B)) ? (B) : (X))
////////////////////////////////
//~ rjf: Type -> Alignment
#if MD_COMPILER_MSVC
#if COMPILER_MSVC
# define align_of(T) __alignof(T)
#elif MD_COMPILER_CLANG
#elif COMPILER_CLANG
# define align_of(T) __alignof(T)
#elif MD_COMPILER_GCC
#elif COMPILER_GCC
# define align_of(T) __alignof__(T)
#else
# error AlignOf not defined for this compiler.
@@ -87,9 +122,9 @@
////////////////////////////////
//~ rjf: Asserts
#if MD_COMPILER_MSVC
#if COMPILER_MSVC
# define trap() __debugbreak()
#elif MD_COMPILER_CLANG || COMPILER_GCC
#elif COMPILER_CLANG || COMPILER_GCC
# define trap() __builtin_trap()
#else
# error Unknown trap intrinsic for this compiler.
@@ -111,8 +146,8 @@
////////////////////////////////
//~ rjf: Atomic Operations
#if MD_OS_WINDOWS
# if MD_ARCH_X64
#if OS_WINDOWS
# if ARCH_X64
# define ins_atomic_u64_eval(x) InterlockedAdd64((volatile __int64 *)(x), 0)
# define ins_atomic_u64_inc_eval(x) InterlockedIncrement64((volatile __int64 *)(x))
# define ins_atomic_u64_dec_eval(x) InterlockedDecrement64((volatile __int64 *)(x))
@@ -126,8 +161,8 @@
# else
# error Atomic intrinsics not defined for this operating system / architecture combination.
# endif
#elif MD_OS_LINUX
# if MD_ARCH_X64
#elif OS_LINUX
# if ARCH_X64
# define ins_atomic_u64_inc_eval(x) __sync_fetch_and_add((volatile U64 *)(x), 1)
# else
# error Atomic intrinsics not defined for this operating system / architecture combination.
@@ -279,14 +314,14 @@
////////////////////////////////
//~ rjf: Address Sanitizer Markup
#if MD_COMPILER_MSVC
#if COMPILER_MSVC
# if defined(__SANITIZE_ADDRESS__)
# define ASAN_ENABLED 1
# define NO_ASAN __declspec(no_sanitize_address)
# else
# define NO_ASAN
# endif
#elif MD_COMPILER_CLANG
#elif COMPILER_CLANG
# if defined(__has_feature)
# if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
# define ASAN_ENABLED 1
@@ -312,24 +347,36 @@
////////////////////////////////
//~ rjf: Misc. Helper Macros
#ifndef stringify
#define stringify_(S) #S
#define stringify(S) stringify_(S)
#endif
#ifndef glue
#define glue_(A,B) A ## B
#define glue(A,B) glue_(A,B)
#endif
#ifndef array_count
#define array_count(a) (sizeof(a) / sizeof((a)[0]))
#endif
#ifndef ceil_integer_div
#define ceil_integer_div(a,b) (((a) + (b) - 1) / (b))
#endif
#ifndef swap
#define swap(T, a, b) do { T t__ = a; a = b; b = t__; } while(0)
#endif
#if MD_ARCH_64BIT
# define int_from_ptr(ptr) ((U64)(ptr))
#elif MD_ARCH_32BIT
# define int_from_ptr(ptr) ((U32)(ptr))
#else
# error Missing pointer-to-integer cast for this architecture.
#ifndef int_from_ptr
# if ARCH_64BIT
# define int_from_ptr(ptr) ((U64)(ptr))
# elif ARCH_32BIT
# define int_from_ptr(ptr) ((U32)(ptr))
# else
# error Missing pointer-to-integer cast for this architecture.
# endif
#endif
#define ptr_from_int(i) (void*)((U8*)0 + (i))
@@ -343,14 +390,28 @@
#define extract_bit(word, idx) (((word) >> (idx)) & 1)
#if MD_LANG_CPP
#if LANG_CPP
# define zero_struct {}
#else
# define zero_struct {0}
#endif
#if MD_COMPILER_MSVC && MD_COMPILER_MSVC_YEAR < 2015
#if COMPILER_MSVC && COMPILER_MSVC_YEAR < 2015
# define this_function_name "unknown"
#else
# define this_function_name __func__
#endif
#if COMPILER_MSVC || (COMPILER_CLANG && OS_WINDOWS)
# pragma section(".rdata$", read)
# define read_only __declspec(allocate(".rdata$"))
#elif (COMPILER_CLANG && OS_LINUX)
# define read_only __attribute__((section(".rodata")))
#else
// NOTE(rjf): I don't know of a useful way to do this in GCC land.
// __attribute__((section(".rodata"))) looked promising, but it introduces a
// strange warning about malformed section attributes, and it doesn't look
// like writing to that section reliably produces access violations, strangely
// enough. (It does on Clang)
# define read_only
#endif
+16 -20
View File
@@ -3,8 +3,9 @@
# include "context_cracking.h"
# include "linkage.h"
# include "macros.h"
# include "linkage.h"
# include "platform.h"
# include "base_types.h"
# include "memory.h"
#endif
// This provides an alterntive memory strategy to HMH/Casey Muratori/RJF styled arenas
@@ -12,29 +13,10 @@
// is related to the gb headers an thus the Odin-lang memory strategy
// Users can override the underlying memory allocator used, even for the HMH arena memory strategy.
#define MD_KILOBYTES( x ) ( ( x ) * ( S64 )( 1024 ) )
#define MD_MEGABYTES( x ) ( MD_KILOBYTES( x ) * ( S64 )( 1024 ) )
#define MD_GIGABYTES( x ) ( MD_MEGABYTES( x ) * ( S64 )( 1024 ) )
#define MD_TERABYTES( x ) ( MD_GIGABYTES( x ) * ( S64 )( 1024 ) )
#define MD__ONES ( scast( GEN_NS usize, - 1) / MD_U8_MAX )
#define MD__HIGHS ( MD__ONES * ( MD_U8_MAX / 2 + 1 ) )
#define MD__HAS_ZERO( x ) ( ( ( x ) - MD__ONES ) & ~( x ) & MD__HIGHS )
#if MD_COMPILER_MSVC || (MD_COMPILER_CLANG && MD_OS_WINDOWS)
# pragma section(".rdata$", read)
# define read_only __declspec(allocate(".rdata$"))
#elif (MD_COMPILER_CLANG && MD_OS_LINUX)
# define read_only __attribute__((section(".rodata")))
#else
// NOTE(rjf): I don't know of a useful way to do this in GCC land.
// __attribute__((section(".rodata"))) looked promising, but it introduces a
// strange warning about malformed section attributes, and it doesn't look
// like writing to that section reliably produces access violations, strangely
// enough. (It does on Clang)
# define read_only
#endif
typedef U32 AllocType;
enum AllocType enum_underlying(U32)
{
@@ -114,3 +96,17 @@ MD_API void* heap_allocator_proc( void* allocator_data, AllocType type, SSIZE si
//! Helper to free memory allocated by heap allocator.
#define mfree( ptr ) free( heap(), ptr )
typedef struct VMem;
struct VMem {
U32 cmt_size;
U32 res_size;
U64 base_pos;
};
AllocatorInfo vm_allocator(VMem* vm) {
AllocatorInfo info = { vm_allocator_proc, vm }
return info
}
MD_API void* vm_allocator_proc(void * allocator_data, AllocType type, SSIZE size, SSIZE alignment, void* old_memory, SSIZE old_size, U64 flags);
+2 -2
View File
@@ -4,8 +4,8 @@
#endif
// C++ namespace support
#if defined(MD_DONT_USE_NAMESPACE) || MD_LANG_C
# if MD_LANG_C
#if defined(MD_DONT_USE_NAMESPACE) || LANG_C
# if LANG_C
# define MD_NS
# define MD_NS_BEGIN
# define MD_NS_END
+2 -2
View File
@@ -8,7 +8,7 @@
#include <stdarg.h>
#include <stddef.h>
#if defined( MD_OS_WINDOWS )
#if defined( OS_WINDOWS )
# include <intrin.h>
# include <tmmintrin.h>
# include <wmmintrin.h>
@@ -28,7 +28,7 @@
# undef VC_EXTRALEAN
#endif
#if MD_LANG_C
#if LANG_C
# include <assert.h>
# include <stdbool.h>
#endif
+2 -2
View File
@@ -102,9 +102,9 @@ typedef enum PathStyle
PathStyle_WindowsAbsolute,
PathStyle_UnixAbsolute,
#if MD_OS_WINDOWS
#if OS_WINDOWS
PathStyle_SystemAbsolute = PathStyle_WindowsAbsolute
#elif MD_OS_LINUX
#elif OS_LINUX
PathStyle_SystemAbsolute = PathStyle_UnixAbsolute
#else
# error "absolute path style is undefined for this OS"