Reference_Linking/rl.h

35 Zeilen
1.1 KiB
C

2023-03-16 12:28:35 +01:00
#pragma once
#include <stddef.h>
typedef struct Rl Rl;
typedef void (*Destructor)(void*);
struct Rl {
2023-03-16 15:52:22 +01:00
void* ref;
struct RlBox* owner;
2023-03-16 12:28:35 +01:00
Rl* prev;
Rl* next;
};
/*
* rl_alloc has to be used for new object allocation of the size size.
* reference will point to the new function afterwards.
* owner should be the struct containing reference and may be NULL if Rl is on the stack or in a global variable.
* The destructor has to rl_free all references inside the newly allocated object.
*
* This function disregards potential malloc() failures.
*/
void rl_alloc(Rl* reference, const void* owner, size_t size, Destructor destructor);
/*
* rl_set has to be used to set the reference Rl to point to the same object as copy.
* owner should be the struct containing reference and may be NULL if Rl is on the stack or in a global variable.
*/
void rl_set(Rl* reference, const void* owner, const Rl* copy);
/*
* rl_free has to be called prior to discarding a Rl to prevent resource leaks.
* Rl* has to point to a valid object (not NULL)
*/
void rl_free(Rl* reference);