Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ option('libc-subproject', type: 'array',
value: ['libc', 'libc_dep', 'libc_hosted_native_dep'],
yield: true,
description: 'This array is used in combination with use-libc-subproject. The first entry is the subproject name. The second is the cross-compilation dependency to use. The third value is optional. If used, it is a native dependency to use with native library targets.')
option('freelist-declared-static', type:'boolean', value: true, yield: true,
description: 'Set to false to make the freelist data structure accessible outside of the malloc_freelist.c file. By default, it has static linkage.')
13 changes: 12 additions & 1 deletion src/malloc_freelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
#include <memory.h>
#include <stdint.h>

/// By default, the freelist is declared as static so that it cannot be accessed
/// outside of the library. Users who wish to override this default declaration
/// can define `FREELIST_DECL_SPECIFIERS` to use an alternative.
/// One option is to make it an empty definition to make it publicly visible,
/// which may be useful for capturing state or performing metadata analysis.
///
/// Unless you have a specific use case, we recommend sticking with the default.
#ifndef FREELIST_DECL_SPECIFIERS
#define FREELIST_DECL_SPECIFIERS static
#endif

#pragma mark - Definitions -

/**
Expand Down Expand Up @@ -70,7 +81,7 @@ void malloc_unlock();
#pragma mark - Declarations -

// This macro simply declares and initializes our linked list
static LIST_INIT(free_list);
FREELIST_DECL_SPECIFIERS LIST_INIT(free_list);

#pragma mark - Private Functions -

Expand Down
10 changes: 10 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,18 @@ libmemory_assert_native_dep = declare_dependency(
# Freelist #
############

freelist_compile_args = []
if get_option('freelist-declared-static') == false
# Remove the static declaration option from the free list struct
# The = with an empty string is needed to prevent the compiler
# from unhelpfully making it FREELIST_DECL_SPECIFIERS=1 on our behalf
freelist_compile_args += '-DFREELIST_DECL_SPECIFIERS='
endif

libmemory_freelist = static_library(
'memory_freelist',
[common_files, 'malloc_freelist.c'],
c_args: freelist_compile_args,
include_directories: [libmemory_includes, dependency_includes],
dependencies: libc_dep,
# Do not built by default if we are a subproject
Expand All @@ -146,6 +155,7 @@ libmemory_freelist = static_library(
libmemory_freelist_native = static_library(
'memory_freelist_native',
[common_files, 'malloc_freelist.c'],
c_args: freelist_compile_args,
include_directories: [libmemory_includes, dependency_includes],
dependencies: libc_native_dep,
native: true,
Expand Down