Commit 8a42768 1 parent acf0985 commit 8a42768 Copy full SHA for 8a42768
File tree 1 file changed +9
-6
lines changed
1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import mir.type_info;
10
10
struct mir_rc_context
11
11
{
12
12
// /
13
- void * allocator ;
13
+ extern ( C ) void function (mir_rc_context * ) @system nothrow @nogc pure deallocator ;
14
14
// /
15
15
immutable (mir_type_info)* typeInfo;
16
16
// /
@@ -68,23 +68,26 @@ export extern(C)
68
68
void mir_rc_delete (ref mir_rc_context context)
69
69
@system nothrow @nogc pure
70
70
{
71
+ assert (context.deallocator);
71
72
with (context)
72
73
{
73
74
with (typeInfo)
74
75
{
75
76
if (destructor)
76
77
{
77
78
auto ptr = cast (void * )(&context + 1 );
78
- foreach (i; 0 .. length)
79
+ auto i = length;
80
+ assert (i);
81
+ do
79
82
{
80
83
destructor(ptr);
81
84
ptr += size;
82
85
}
86
+ while (-- i);
83
87
}
84
88
}
85
89
}
86
- import mir.internal.memory: free;
87
- free(&context);
90
+ context.deallocator(&context);
88
91
}
89
92
90
93
/+ +
@@ -98,14 +101,14 @@ mir_rc_context* mir_rc_create(
98
101
bool deallocate = true ,
99
102
) @system nothrow @nogc pure
100
103
{
101
- import mir.internal.memory: malloc;
104
+ import mir.internal.memory: malloc, free ;
102
105
import core.stdc.string : memset, memcpy;
103
106
104
107
assert (length);
105
108
auto size = length * typeInfo.size;
106
109
if (auto context = cast (mir_rc_context* )malloc(mir_rc_context.sizeof + size))
107
110
{
108
- context.allocator = null ;
111
+ context.deallocator = &free ;
109
112
context.typeInfo = &typeInfo;
110
113
context.counter = deallocate;
111
114
context.length = length;
You can’t perform that action at this time.
0 commit comments