@@ -42,21 +42,10 @@ struct in_puppet_t;
4242 $(D in_get_last_error)
4343*/
4444in_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*/
7564in_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*/
10387void 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