Skip to content

Commit 61de01d

Browse files
Fix dynamic library compilation
1 parent ad2dcf0 commit 61de01d

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

source/inochi2d/cffi/puppet.d

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,10 @@ struct in_puppet_t;
4242
$(D in_get_last_error)
4343
*/
4444
in_puppet_t* in_puppet_load(const(char)* file) {
45-
import core.memory : GC;
45+
import nulib.string : fromStringz;
4646

4747
__in_clear_error();
48-
49-
string path = cast(string)file[0 .. nu_strlen(file)];
50-
return cast(in_puppet_t*)assumeNoGC((string file) {
51-
try {
52-
Puppet p = assumeNoGC(&inLoadPuppet!Puppet, file);
53-
GC.addRoot(cast(void*)p);
54-
return p;
55-
} catch (Exception ex) {
56-
__in_set_error(ex);
57-
return null;
58-
}
59-
}, path);
48+
return cast(in_puppet_t*)Puppet.fromFile(cast(string)file.fromStringz);
6049
}
6150

6251
/**
@@ -73,20 +62,15 @@ in_puppet_t* in_puppet_load(const(char)* file) {
7362
$(D in_get_last_error)
7463
*/
7564
in_puppet_t* in_puppet_load_from_memory(const(ubyte)* data, uint length) {
76-
import core.memory : GC;
65+
import nulib.io.stream : MemoryStream;
7766

7867
__in_clear_error();
79-
80-
return cast(in_puppet_t*)assumeNoGC((ubyte[] buffer) {
81-
try {
82-
Puppet p = assumeNoGC(&inLoadINPPuppet!Puppet, buffer);
83-
GC.addRoot(cast(void*)p);
84-
return p;
85-
} catch (Exception ex) {
86-
__in_set_error(ex);
87-
return null;
88-
}
89-
}, cast(ubyte[])data[0 .. length]);
68+
auto stream = nogc_new!MemoryStream(cast(ubyte[])data[0..length]);
69+
scope(exit) {
70+
stream.take();
71+
nogc_delete(stream);
72+
}
73+
return cast(in_puppet_t*)Puppet.fromStream(stream);
9074
}
9175

9276
/**
@@ -101,13 +85,8 @@ in_puppet_t* in_puppet_load_from_memory(const(ubyte)* data, uint length) {
10185
obj = The puppet object.
10286
*/
10387
void in_puppet_free(in_puppet_t* obj) {
104-
import core.memory : GC;
105-
106-
if (obj) {
107-
GC.removeRoot(cast(void*)obj);
108-
assumeNoGC(&destroy!(false, Puppet), cast(Puppet)obj);
109-
GC.free(obj);
110-
}
88+
Puppet puppet = cast(Puppet)obj;
89+
nogc_delete(puppet);
11190
}
11291

11392
/**

0 commit comments

Comments
 (0)