From bc8095534b2954ef544bc8e4a7b5e0d219f75d71 Mon Sep 17 00:00:00 2001 From: Simon Hailes Date: Sun, 12 Nov 2017 17:48:36 +0000 Subject: [PATCH] comment out Addref - too dangerous to leave in. Modify test example. --- examples/matrix-ref-count.js | 20 ++++++-------------- src/Matrix.cc | 24 +++++++++++++----------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/examples/matrix-ref-count.js b/examples/matrix-ref-count.js index 2540f5d..cd0ad08 100755 --- a/examples/matrix-ref-count.js +++ b/examples/matrix-ref-count.js @@ -4,27 +4,19 @@ cv.readImage('./files/mona.png', function(err, im) { if (err) throw err; if (im.width() < 1 || im.height() < 1) throw new Error('Image has no size'); + + // getrefCount will give the refcount. if > 0, then a reference ptr is present, and the value returned. + // if -1, no reference pointer was present (i.e. the mat does not know about any data). var refcount = im.getrefCount(); console.log('initial refcount '+refcount); + if (refcount !== 1) + throw "refcountmismatch - initial should be 1"; - im.addref(); - var refcount2 = im.getrefCount(); - console.log('refcount after addref '+refcount2); - if (refcount2 !== (refcount + 1)) - throw "refcountmismatch"; - - im.addref(); - refcount2 = im.getrefCount(); - console.log('refcount after addref 2 '+refcount2); - if (refcount2 !== (refcount + 2)) - throw "refcountmismatch"; - - im.release(); var refcount3 = im.getrefCount(); console.log('refcount after release (seems should be -1) '+refcount3); if (refcount3 !== -1) - throw "refcountmismatch"; + throw "refcountmismatch - after release should be -1"; // data is now still there somewhere, but lost to us - this is NOT a good situation. diff --git a/src/Matrix.cc b/src/Matrix.cc index a282e4d..653de26 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -117,7 +117,8 @@ void Matrix::Init(Local target) { Nan::SetPrototypeMethod(ctor, "mean", Mean); Nan::SetPrototypeMethod(ctor, "shift", Shift); Nan::SetPrototypeMethod(ctor, "reshape", Reshape); - Nan::SetPrototypeMethod(ctor, "addref", Addref); +// leave this out - can't see a way it could be useful to us, as release() always completely forgets the data +// Nan::SetPrototypeMethod(ctor, "addref", Addref); Nan::SetPrototypeMethod(ctor, "release", Release); Nan::SetPrototypeMethod(ctor, "getrefCount", GetrefCount); Nan::SetPrototypeMethod(ctor, "subtract", Subtract); @@ -3027,14 +3028,15 @@ NAN_METHOD(Matrix::Release) { return; } -NAN_METHOD(Matrix::Addref) { - Nan::HandleScope scope; - - Matrix *self = Nan::ObjectWrap::Unwrap(info.This()); - self->mat.addref(); - - return; -} +// leave this out - can't see a way it could be useful to us, as release() always completely forgets the data +//NAN_METHOD(Matrix::Addref) { +// Nan::HandleScope scope; +// +// Matrix *self = Nan::ObjectWrap::Unwrap(info.This()); +// self->mat.addref(); +// +// return; +//} NAN_METHOD(Matrix::GetrefCount) { @@ -3047,13 +3049,13 @@ NAN_METHOD(Matrix::GetrefCount) { if (self->mat.u){ refcount = self->mat.u->refcount; } else { - refcount = -1; + refcount = -1; // indicates no reference ptr } #else if (self->mat.refcount){ refcount = *(self->mat.refcount); } else { - refcount = -1; + refcount = -1; // indicates no reference ptr } #endif