LibJuno 1.0.1
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
memory_api.h
Go to the documentation of this file.
1/*
2 MIT License
3
4 Copyright (c) 2025 Robin A. Onsay
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files
8 (the "Software"), to deal in the Software without restriction,
9 including without limitation the rights to use, copy, modify, merge,
10 publish, distribute, sublicense, and/or sell copies of the Software,
11 and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
16*/
17
56#ifndef JUNO_MEMORY_API_H
57#define JUNO_MEMORY_API_H
58#include "juno/macros.h"
59#include "juno/status.h"
60#include "juno/module.h"
61#include <stddef.h>
62#include <stdalign.h>
64#ifdef __cplusplus
65extern "C"
66{
67#endif
68
70typedef struct JUNO_MEMORY_ALLOC_ROOT_TAG JUNO_MEMORY_ALLOC_ROOT_T;
71
72struct JUNO_MEMORY_ALLOC_ROOT_TAG JUNO_MODULE_ROOT(JUNO_MEMORY_ALLOC_API_T,
73 const JUNO_POINTER_API_T *ptPointerApi;
74);
75
80{
85 JUNO_RESULT_POINTER_T (*Get)(JUNO_MEMORY_ALLOC_ROOT_T *ptMem, size_t zSize);
86
92 JUNO_STATUS_T (*Update)(JUNO_MEMORY_ALLOC_ROOT_T *ptMem, JUNO_POINTER_T *ptMemory, size_t zNewSize);
93
99};
100
108{
110 ptAllocApi &&
111 ptAllocApi->Get &&
112 ptAllocApi->Put &&
113 ptAllocApi->Update
114 );
115 return JUNO_STATUS_SUCCESS;
116}
117
125{
127 ptAlloc &&
128 ptAlloc->ptApi &&
129 ptAlloc->ptPointerApi
130 );
131 JUNO_STATUS_T tStatus = JunoMemory_AllocApiVerify(ptAlloc->ptApi);
132 JUNO_ASSERT_SUCCESS(tStatus, return tStatus);
133 tStatus = JunoMemory_PointerApiVerify(ptAlloc->ptPointerApi);
134 JUNO_ASSERT_SUCCESS(tStatus, return tStatus);
135 return tStatus;
136}
137
138#ifdef __cplusplus
139}
140#endif
141#endif // JUNO_MEMORY_API_H
#define JUNO_ASSERT_EXISTS(ptr)
Returns JUNO_STATUS_NULLPTR_ERROR if the expression is falsy.
Definition macros.h:50
#define JUNO_ASSERT_SUCCESS(tStatus,...)
Execute the provided failure operation(s) if status is not success.
Definition macros.h:87
static JUNO_STATUS_T JunoMemory_AllocVerify(const JUNO_MEMORY_ALLOC_ROOT_T *ptAlloc)
Verify a memory allocator instance and its dependent pointer API.
Definition memory_api.h:124
static JUNO_STATUS_T JunoMemory_AllocApiVerify(const JUNO_MEMORY_ALLOC_API_T *ptAllocApi)
Verify that a memory allocator API provides required functions.
Definition memory_api.h:107
static JUNO_STATUS_T JunoMemory_PointerApiVerify(const JUNO_POINTER_API_T *ptPointerApi)
Verify that a pointer API provides required functions.
Definition pointer_api.h:154
#define JUNO_MODULE_ROOT(API_T,...)
Implement a module root struct containing ptApi and failure fields.
Definition module.h:126
#define JUNO_STATUS_SUCCESS
Operation completed successfully.
Definition status.h:56
int32_t JUNO_STATUS_T
Canonical status type for LibJuno functions.
Definition status.h:49
Common assertion and helper macros for LibJuno modules.
struct JUNO_MEMORY_ALLOC_ROOT_TAG JUNO_MEMORY_ALLOC_ROOT_T
Definition memory_api.h:70
Module system and dependency injection primitives for LibJuno.
Pointer trait and helpers for memory operations.
struct JUNO_POINTER_TAG JUNO_POINTER_T
Definition pointer_api.h:49
Status codes and failure-handling helpers for LibJuno.
Vtable for memory allocation operations.
Definition memory_api.h:80
JUNO_STATUS_T(* Put)(JUNO_MEMORY_ALLOC_ROOT_T *ptMem, JUNO_POINTER_T *pvAddr)
Free a previously allocated memory region.
Definition memory_api.h:98
JUNO_STATUS_T(* Update)(JUNO_MEMORY_ALLOC_ROOT_T *ptMem, JUNO_POINTER_T *ptMemory, size_t zNewSize)
Update an existing allocation to a new size (in-place descriptor update).
Definition memory_api.h:92
JUNO_RESULT_POINTER_T(* Get)(JUNO_MEMORY_ALLOC_ROOT_T *ptMem, size_t zSize)
Allocate a memory region of at least zSize bytes.
Definition memory_api.h:85
Pointer operations API (copy/reset).
Definition pointer_api.h:74