Skip to content

Commit

Permalink
Completely revamp class-new system. Add numem hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Dec 12, 2024
1 parent 38544a0 commit 27e4221
Show file tree
Hide file tree
Showing 18 changed files with 585 additions and 406 deletions.
2 changes: 0 additions & 2 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ copyright "Copyright © 2023, Inochi2D Project"
license "BSD 2-clause"
targetPath "out/"

dependency "tinyd-rt" version=">=0.0.0" optional=true

buildOptions "debugInfoC" platform="windows"

configuration "main" {
Expand Down
14 changes: 4 additions & 10 deletions source/numem/all.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
*/

/**
Automatically imports all of the numem types.
Automatically imports all of the base numem functionality.
Some extra functionality has to be
*/
deprecated("To import core numem functionality, just import numem.")
module numem.all;

public import numem.core;
public import numem.core.memory;
public import numem.collections;
public import numem.core.exception;
public import numem.io;
public import numem.string;
public import numem.conv;
public import numem.events;
public import numem.format;
public import numem;
2 changes: 1 addition & 1 deletion source/numem/collections/map.d
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ unittest {
// Associative array of ints that are
// indexed by string keys.
// The KeyType is string.
map!(string, int) aa = nogc_construct!(map!(string, int))();
map!(string, int) aa;
aa["hello"] = 3; // set value associated with key "hello" to 3
int value = aa["hello"]; // lookup value from a key
assert(value == 3);
Expand Down
2 changes: 1 addition & 1 deletion source/numem/collections/set.d
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ unittest {

@("set: insertion, deletion and testing")
unittest {
set!(string) keywords = nogc_construct!(set!string)();
set!(string) keywords;

assert(keywords.insert("public"));
assert(keywords.insert("private"));
Expand Down
3 changes: 1 addition & 2 deletions source/numem/collections/vector.d
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,7 @@ alias weak_vector(T) = VectorImpl!(T, false);

@("vector: Issue #2")
unittest {
class A {
}
class A { }
shared_ptr!A a = shared_new!A();
vector!(shared_ptr!A) v;
v ~= a; // Used to crash, see Issue #2
Expand Down
8 changes: 7 additions & 1 deletion source/numem/conv.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
Utilities for converting between some basic types
*/
module numem.conv;
import numem.string;
import numem.format;
import core.stdc.stdlib;
import std.traits;
import numem.all;


//
// TODO: REIMPLEMENT ALL OF THIS IN PURE D.
//

@nogc:

Expand Down
96 changes: 0 additions & 96 deletions source/numem/core/env.d

This file was deleted.

129 changes: 129 additions & 0 deletions source/numem/core/hooks.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
Copyright © 2023, Inochi2D Project
Distributed under the 2-Clause BSD License, see LICENSE file.
Authors: Luna Nielsen
*/

/**
Numem Hooks.
This file contains all the core hooks numem calls internally to handle memory.
Given that some platforms may not have a C standard library, these hooks allow you
to override how numem handles memory for such platforms from an external library.
In this case, all of the hooks presented here will need to be implemented to cover
all of the used internal hooks within numem.
Various extra hooks are provided in other files throughout numem, but are optional.
*/
module numem.core.hooks;
public import core.attribute : weak;

@nogc nothrow:

/**
Allocates `bytes` worth of memory.
NOTE: External libraries may override this
implementation.
By default calls C stdlib alloc.
*/
@weak
extern(C)
void* nuAlloc(size_t bytes) {
import core.stdc.stdlib : malloc;
return malloc(bytes);
}


/**
Reallocates memory at `data` to be `bytes` worth of memory.
NOTE: External libraries may override this
implementation.
By default calls C stdlib realloc.
*/
@weak
extern(C)
void* nuRealloc(void* data, size_t newSize) {
import core.stdc.stdlib : realloc;
return realloc(data, newSize);
}

/**
Frees the memory at `data`.
NOTE: External libraries may override this
implementation.
By default calls C stdlib alloc.
*/
@weak
extern(C)
void nuFree(void* data) {
import core.stdc.stdlib : free;
free(data);
}

/**
Copies `bytes` worth of data from `src` into `dst`.
Memory needs to be allocated and within range.
NOTE: External libraries may override this
implementation.
By default calls C stdlib memcpy.
*/
@weak
extern(C)
void* nuMemcpy(inout(void)* dst, inout(void)* src, size_t bytes) {
import core.stdc.string : memcpy;
return memcpy(cast(void*)dst, cast(void*)src, bytes);
}

/**
Moves `bytes` worth of data from `src` into `dst`.
Memory needs to be allocated and within range.
NOTE: External libraries may override this
implementation.
By default calls C stdlib memmove.
*/
@weak
extern(C)
void* nuMemmove(void* dst, void* src, size_t bytes) {
import core.stdc.string : memmove;
return memmove(dst, src, bytes);
}

/**
Fills `dst` with `value` for `bytes` bytes.
NOTE: External libraries may override this
implementation.
By default calls C stdlib memset.
*/
void* nuMemset(void* dst, ubyte value, size_t bytes) {
import core.stdc.string : memset;
return memset(dst, value, bytes);
}

/**
Hook which forcefully quits or crashes the application due to an invalid state.
NOTE: External libraries may override this
implementation.
By default calls C stdlib abort.
*/
@weak
extern(C)
void nuAbort() {
import core.stdc.stdlib : abort;
abort();
}
73 changes: 0 additions & 73 deletions source/numem/core/memory/alloc.d

This file was deleted.

Loading

0 comments on commit 27e4221

Please sign in to comment.