mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
[cmark] Move wrapped allocator next to get_default_allocator
This commit is contained in:
Vendored
+14
-10
@@ -125,6 +125,20 @@ foreign lib {
|
|||||||
get_default_mem_allocator :: proc() -> (mem: ^Allocator) ---
|
get_default_mem_allocator :: proc() -> (mem: ^Allocator) ---
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// You can use the current context.allocator to make a custom allocator for CMark.
|
||||||
|
// WARNING: It needs to remain the context.allocator for any subsequent calls into this package.
|
||||||
|
//
|
||||||
|
// To use:
|
||||||
|
// alloc := get_default_allocator()
|
||||||
|
// alloc^ = make_allocator()
|
||||||
|
make_allocator :: proc() -> (res: Allocator) {
|
||||||
|
return Allocator{
|
||||||
|
calloc = _calloc,
|
||||||
|
realloc = _realloc,
|
||||||
|
free = _free,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bufsize_t :: distinct i32
|
bufsize_t :: distinct i32
|
||||||
|
|
||||||
// Node creation, destruction, and tree traversal
|
// Node creation, destruction, and tree traversal
|
||||||
@@ -477,16 +491,6 @@ free_string :: proc "c" (s: string) {
|
|||||||
}
|
}
|
||||||
free :: proc{free_rawptr, free_cstring}
|
free :: proc{free_rawptr, free_cstring}
|
||||||
|
|
||||||
// You can use the current context.allocator to make a custom allocator for CMark.
|
|
||||||
// WARNING: It needs to remain the context.allocator for any subsequent calls into this package.
|
|
||||||
make_allocator :: proc() -> (res: Allocator) {
|
|
||||||
return Allocator{
|
|
||||||
calloc = _calloc,
|
|
||||||
realloc = _realloc,
|
|
||||||
free = _free,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@(private)
|
@(private)
|
||||||
_calloc :: proc "c" (num: c.size_t, size: c.size_t) -> (alloc: rawptr) {
|
_calloc :: proc "c" (num: c.size_t, size: c.size_t) -> (alloc: rawptr) {
|
||||||
context = runtime.default_context()
|
context = runtime.default_context()
|
||||||
|
|||||||
Reference in New Issue
Block a user