mv ref->free ref->destructor;

This commit is contained in:
bjorn 2018-12-19 01:33:47 -08:00
parent 4c9b02a6ff
commit 5b52a91778
2 changed files with 5 additions and 3 deletions

View File

@ -31,7 +31,7 @@ void lovrThrow(const char* format, ...) {
void* _lovrAlloc(const char* type, size_t size, void (*destructor)(void*)) {
Ref* ref = calloc(1, size);
if (!ref) return lovrThrow("Out of memory"), NULL;
ref->free = destructor;
ref->destructor = destructor;
ref->type = type;
ref->count = 1;
return ref;
@ -43,7 +43,9 @@ void lovrRetain(void* object) {
void lovrRelease(void* object) {
Ref* ref = object;
if (ref && --ref->count == 0) ref->free(object);
if (ref && --ref->count == 0) {
ref->destructor(object);
}
}
// https://github.com/starwing/luautf8

View File

@ -31,7 +31,7 @@
#define ALIGN(p, n) ((uintptr_t) p & -n)
typedef struct ref {
void (*free)(void*);
void (*destructor)(void*);
const char* type;
int count;
} Ref;