am 3e7e176b: am 6e7f4ff0: am 54950687: Merge "Fix refcounting bug"

* commit '3e7e176b0625702745542679f96cdf2bcd42e242':
  Fix refcounting bug
diff --git a/rsScriptC_Lib.cpp b/rsScriptC_Lib.cpp
index 628190d..c404bde 100644
--- a/rsScriptC_Lib.cpp
+++ b/rsScriptC_Lib.cpp
@@ -142,28 +142,11 @@
 }
 
 // Legacy, remove when drivers are updated
-void rsrSetObject(const Context *rsc, void *dst, ObjectBase *src) {
-    ObjectBase **odst = (ObjectBase **)dst;
-    //ALOGE("rsrSetObject (base) %p,%p  %p", dst, *odst, src);
-    SetObjectRef(rsc, odst[0], src);
-    if (src != nullptr) {
-        src->callUpdateCacheObject(rsc, dst);
-    }
-}
-
-void rsrSetObject(const Context *rsc, rs_object_base *dst, const ObjectBase *src) {
-    ObjectBase **odst = (ObjectBase **)dst;
-    //ALOGE("rsrSetObject (base) %p,%p  %p", dst, *odst, src);
-    SetObjectRef(rsc, odst[0], src);
-    if (src != nullptr) {
-        src->callUpdateCacheObject(rsc, dst);
-    }
-}
-
-// Legacy, remove when drivers are updated
 void rsrClearObject(const Context *rsc, void *dst) {
     ObjectBase **odst = (ObjectBase **)dst;
-    //ALOGE("rsrClearObject  %p,%p", odst, *odst);
+    if (ObjectBase::gDebugReferences) {
+        ALOGE("rsrClearObject  %p,%p", odst, *odst);
+    }
     if (odst[0]) {
         CHECK_OBJ(odst[0]);
         odst[0]->decSysRef();
@@ -172,7 +155,9 @@
 }
 
 void rsrClearObject(const Context *rsc, rs_object_base *dst) {
-    //ALOGE("rsrClearObject  %p,%p", odst, *odst);
+    if (ObjectBase::gDebugReferences) {
+        ALOGE("rsrClearObject  %p,%p", dst, dst->p);
+    }
     if (dst->p) {
         CHECK_OBJ(dst->p);
         dst->p->decSysRef();
@@ -181,6 +166,35 @@
 }
 
 // Legacy, remove when drivers are updated
+void rsrSetObject(const Context *rsc, void *dst, ObjectBase *src) {
+    if (src == nullptr) {
+        rsrClearObject(rsc, dst);
+        return;
+    }
+
+    ObjectBase **odst = (ObjectBase **)dst;
+    if (ObjectBase::gDebugReferences) {
+        ALOGE("rsrSetObject (base) %p,%p  %p", dst, *odst, src);
+    }
+    SetObjectRef(rsc, odst[0], src);
+    src->callUpdateCacheObject(rsc, dst);
+}
+
+void rsrSetObject(const Context *rsc, rs_object_base *dst, const ObjectBase *src) {
+    if (src == nullptr) {
+        rsrClearObject(rsc, dst);
+        return;
+    }
+
+    ObjectBase **odst = (ObjectBase **)dst;
+    if (ObjectBase::gDebugReferences) {
+        ALOGE("rsrSetObject (base) %p,%p  %p", dst, *odst, src);
+    }
+    SetObjectRef(rsc, odst[0], src);
+    src->callUpdateCacheObject(rsc, dst);
+}
+
+// Legacy, remove when drivers are updated
 bool rsrIsObject(const Context *, ObjectBase* src) {
     ObjectBase **osrc = (ObjectBase **)src;
     return osrc != nullptr;