Skip to content

Commit

Permalink
Allow destroying without freeing
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Nov 13, 2024
1 parent af9b0e7 commit cb04ac7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
8 changes: 5 additions & 3 deletions source/numem/core/memory/alloc.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private extern (D) alias fp_t = void function (Object);
Destroy element with a destructor.
*/
@trusted
void destruct(T)(ref T obj_) {
void destruct(T, bool doFree=true)(ref T obj_) {

static if (isPointer!T || is(T == class)) {
if (obj_ !is null) {
Expand All @@ -36,8 +36,10 @@ void destruct(T)(ref T obj_) {
}
}

free(cast(void*)obj_);
obj_ = null;
static if (doFree) {
free(cast(void*)obj_);
obj_ = null;
}
}
} else {

Expand Down
4 changes: 2 additions & 2 deletions source/numem/core/memory/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ T* nogc_new(T)(T value = T.init) if (isBasicType!T) {
For structs this will call the struct's destructor if it has any.
*/
void nogc_delete(T)(ref T obj_) {
void nogc_delete(T, bool doFree=true)(ref T obj_) {

// Tracing
debug(trace) dbg_dealloc(obj_);

destruct(obj_);
destruct!(T, doFree)(obj_);
}

/**
Expand Down
12 changes: 7 additions & 5 deletions source/numem/platform.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
*/
module numem.platform;

version(OSX) version = AppleOS;
else version(iOS) version = AppleOS;
else version(TVOS) version = AppleOS;
else version(WatchOS) version = AppleOS;
else version(VisionOS) version = AppleOS;
mixin template CheckOS() {
version(OSX) version = AppleOS;
else version(iOS) version = AppleOS;
else version(TVOS) version = AppleOS;
else version(WatchOS) version = AppleOS;
else version(VisionOS) version = AppleOS;
}
2 changes: 2 additions & 0 deletions source/numem/sync/semaphore.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import numem.core.memory;
import core.sync.exception;
import core.time : convert;

mixin CheckOS;

version(Windows) {

import core.sys.windows.basetsd;
Expand Down

0 comments on commit cb04ac7

Please sign in to comment.