Skip to content

Commit 27e4221

Browse files
Completely revamp class-new system. Add numem hooks
1 parent 38544a0 commit 27e4221

File tree

18 files changed

+585
-406
lines changed

18 files changed

+585
-406
lines changed

dub.sdl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ copyright "Copyright © 2023, Inochi2D Project"
55
license "BSD 2-clause"
66
targetPath "out/"
77

8-
dependency "tinyd-rt" version=">=0.0.0" optional=true
9-
108
buildOptions "debugInfoC" platform="windows"
119

1210
configuration "main" {

source/numem/all.d

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@
66
*/
77

88
/**
9-
Automatically imports all of the numem types.
9+
Automatically imports all of the base numem functionality.
10+
Some extra functionality has to be
1011
*/
12+
deprecated("To import core numem functionality, just import numem.")
1113
module numem.all;
1214

13-
public import numem.core;
14-
public import numem.core.memory;
15-
public import numem.collections;
16-
public import numem.core.exception;
17-
public import numem.io;
18-
public import numem.string;
19-
public import numem.conv;
20-
public import numem.events;
21-
public import numem.format;
15+
public import numem;

source/numem/collections/map.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ unittest {
258258
// Associative array of ints that are
259259
// indexed by string keys.
260260
// The KeyType is string.
261-
map!(string, int) aa = nogc_construct!(map!(string, int))();
261+
map!(string, int) aa;
262262
aa["hello"] = 3; // set value associated with key "hello" to 3
263263
int value = aa["hello"]; // lookup value from a key
264264
assert(value == 3);

source/numem/collections/set.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ unittest {
162162

163163
@("set: insertion, deletion and testing")
164164
unittest {
165-
set!(string) keywords = nogc_construct!(set!string)();
165+
set!(string) keywords;
166166

167167
assert(keywords.insert("public"));
168168
assert(keywords.insert("private"));

source/numem/collections/vector.d

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,7 @@ alias weak_vector(T) = VectorImpl!(T, false);
687687

688688
@("vector: Issue #2")
689689
unittest {
690-
class A {
691-
}
690+
class A { }
692691
shared_ptr!A a = shared_new!A();
693692
vector!(shared_ptr!A) v;
694693
v ~= a; // Used to crash, see Issue #2

source/numem/conv.d

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@
99
Utilities for converting between some basic types
1010
*/
1111
module numem.conv;
12+
import numem.string;
13+
import numem.format;
1214
import core.stdc.stdlib;
1315
import std.traits;
14-
import numem.all;
16+
17+
18+
//
19+
// TODO: REIMPLEMENT ALL OF THIS IN PURE D.
20+
//
1521

1622
@nogc:
1723

source/numem/core/env.d

Lines changed: 0 additions & 96 deletions
This file was deleted.

source/numem/core/hooks.d

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
Copyright © 2023, Inochi2D Project
3+
Distributed under the 2-Clause BSD License, see LICENSE file.
4+
5+
Authors: Luna Nielsen
6+
*/
7+
8+
/**
9+
Numem Hooks.
10+
11+
This file contains all the core hooks numem calls internally to handle memory.
12+
Given that some platforms may not have a C standard library, these hooks allow you
13+
to override how numem handles memory for such platforms from an external library.
14+
15+
In this case, all of the hooks presented here will need to be implemented to cover
16+
all of the used internal hooks within numem.
17+
18+
Various extra hooks are provided in other files throughout numem, but are optional.
19+
*/
20+
module numem.core.hooks;
21+
public import core.attribute : weak;
22+
23+
@nogc nothrow:
24+
25+
/**
26+
Allocates `bytes` worth of memory.
27+
28+
NOTE: External libraries may override this
29+
implementation.
30+
31+
By default calls C stdlib alloc.
32+
*/
33+
@weak
34+
extern(C)
35+
void* nuAlloc(size_t bytes) {
36+
import core.stdc.stdlib : malloc;
37+
return malloc(bytes);
38+
}
39+
40+
41+
/**
42+
Reallocates memory at `data` to be `bytes` worth of memory.
43+
44+
NOTE: External libraries may override this
45+
implementation.
46+
47+
By default calls C stdlib realloc.
48+
*/
49+
@weak
50+
extern(C)
51+
void* nuRealloc(void* data, size_t newSize) {
52+
import core.stdc.stdlib : realloc;
53+
return realloc(data, newSize);
54+
}
55+
56+
/**
57+
Frees the memory at `data`.
58+
59+
NOTE: External libraries may override this
60+
implementation.
61+
62+
By default calls C stdlib alloc.
63+
*/
64+
@weak
65+
extern(C)
66+
void nuFree(void* data) {
67+
import core.stdc.stdlib : free;
68+
free(data);
69+
}
70+
71+
/**
72+
Copies `bytes` worth of data from `src` into `dst`.
73+
Memory needs to be allocated and within range.
74+
75+
NOTE: External libraries may override this
76+
implementation.
77+
78+
By default calls C stdlib memcpy.
79+
*/
80+
@weak
81+
extern(C)
82+
void* nuMemcpy(inout(void)* dst, inout(void)* src, size_t bytes) {
83+
import core.stdc.string : memcpy;
84+
return memcpy(cast(void*)dst, cast(void*)src, bytes);
85+
}
86+
87+
/**
88+
Moves `bytes` worth of data from `src` into `dst`.
89+
Memory needs to be allocated and within range.
90+
91+
NOTE: External libraries may override this
92+
implementation.
93+
94+
By default calls C stdlib memmove.
95+
*/
96+
@weak
97+
extern(C)
98+
void* nuMemmove(void* dst, void* src, size_t bytes) {
99+
import core.stdc.string : memmove;
100+
return memmove(dst, src, bytes);
101+
}
102+
103+
/**
104+
Fills `dst` with `value` for `bytes` bytes.
105+
106+
NOTE: External libraries may override this
107+
implementation.
108+
109+
By default calls C stdlib memset.
110+
*/
111+
void* nuMemset(void* dst, ubyte value, size_t bytes) {
112+
import core.stdc.string : memset;
113+
return memset(dst, value, bytes);
114+
}
115+
116+
/**
117+
Hook which forcefully quits or crashes the application due to an invalid state.
118+
119+
NOTE: External libraries may override this
120+
implementation.
121+
122+
By default calls C stdlib abort.
123+
*/
124+
@weak
125+
extern(C)
126+
void nuAbort() {
127+
import core.stdc.stdlib : abort;
128+
abort();
129+
}

source/numem/core/memory/alloc.d

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)