35 Zeilen
1.1 KiB
C
35 Zeilen
1.1 KiB
C
#pragma once
|
|
#include <stddef.h>
|
|
|
|
typedef struct Rl Rl;
|
|
typedef void (*Destructor)(void*);
|
|
|
|
struct Rl {
|
|
Rl* prev;
|
|
Rl* next;
|
|
struct RlBox* owner;
|
|
void* ref;
|
|
};
|
|
|
|
/*
|
|
* 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);
|