mirror of https://github.com/bjornbytes/lovr.git
Fix refcount alignment;
Once and for all? How does alignment even work.
This commit is contained in:
parent
16b93869ee
commit
fd437423e7
|
@ -3,8 +3,8 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
void* _lovrAlloc(size_t size) {
|
||||
Ref* ref = calloc(1, sizeof(Ref) + size);
|
||||
char* ref = calloc(1, sizeof(size_t) + size);
|
||||
lovrAssert(ref, "Out of memory");
|
||||
*ref = 1;
|
||||
return ref + 1;
|
||||
*((Ref*) ref) = 1;
|
||||
return ref + sizeof(size_t);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ static inline uint32_t ref_dec(Ref* ref) { return atomic_fetch_sub(ref, 1) - 1;
|
|||
#endif
|
||||
|
||||
void* _lovrAlloc(size_t size);
|
||||
#define toRef(o) (Ref*) (o) - 1
|
||||
#define toRef(o) ((Ref*) (((char*) (o)) - sizeof(size_t)))
|
||||
#define lovrAlloc(T) (T*) _lovrAlloc(sizeof(T))
|
||||
#define lovrRetain(o) if (o && !ref_inc(toRef(o))) { lovrThrow("Refcount overflow in %s:%d", __FILE__, __LINE__); }
|
||||
#define lovrRelease(T, o) if (o && !ref_dec(toRef(o))) lovr ## T ## Destroy(o), free(toRef(o));
|
||||
|
|
Loading…
Reference in New Issue