@@ -100,7 +100,7 @@ Handle<Value> Statement::New(const Arguments& args) {
100100void Statement::EIO_BeginPrepare (Baton* baton) {
101101 assert (baton->db ->open );
102102 assert (!baton->db ->locked );
103- // static_cast<PrepareBaton*>(baton)->stmt->Ref();
103+ static_cast <PrepareBaton*>(baton)->stmt ->Ref ();
104104 ev_ref (EV_DEFAULT_UC );
105105 fprintf (stderr, " Prepare started\n " );
106106 eio_custom (EIO_Prepare, EIO_PRI_DEFAULT , EIO_AfterPrepare, baton);
@@ -191,9 +191,19 @@ void Statement::Wrap(Handle<Object> handle) {
191191 handle_.MakeWeak (this , Destruct);
192192}
193193
194+ inline void Statement::MakeWeak (void ) {
195+ handle_.MakeWeak (this , Destruct);
196+ }
197+
198+ void Statement::Unref () {
199+ assert (!handle_.IsEmpty ());
200+ assert (!handle_.IsWeak ());
201+ assert (refs_ > 0 );
202+ if (--refs_ == 0 ) { MakeWeak (); }
203+ }
204+
194205void Statement::Destruct (Persistent<Value> value, void *data) {
195206 Statement* stmt = static_cast <Statement*>(data);
196- fprintf (stderr, " Auto-Finalizing handle started\n " );
197207 if (stmt->handle ) {
198208 eio_custom (EIO_Destruct, EIO_PRI_DEFAULT , EIO_AfterDestruct, stmt);
199209 ev_ref (EV_DEFAULT_UC );
0 commit comments