Merge change 2658

* changes:
  Delete the acc script when deleting the Renderscript rsScriptC object.
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 7ae5709..979c441 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -94,7 +94,7 @@
 	rsType.cpp \
 	rsTriangleMesh.cpp
 
-LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL libGLESv1_CM libui 
+LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL libGLESv1_CM libui libacc
 LOCAL_LDLIBS := -lpthread -ldl
 LOCAL_MODULE:= libRS
 
diff --git a/libs/rs/jni/RenderScript_jni.cpp b/libs/rs/jni/RenderScript_jni.cpp
index 56b4e88..50849af 100644
--- a/libs/rs/jni/RenderScript_jni.cpp
+++ b/libs/rs/jni/RenderScript_jni.cpp
@@ -533,6 +533,7 @@
     jint remaining;
     jbyte* script_base = 0;
     jbyte* script_ptr;
+    ACCscript* script = 0;
     void* scriptEntry = 0;
     if (!scriptRef) {
         _exception = 1;
@@ -560,19 +561,21 @@
     script_ptr = script_base + offset;
 
     {
-        ACCscript* script = accCreateScript();
+        script = accCreateScript();
         const char* scriptSource[] = {(const char*) script_ptr};
         int scriptLength[] = {length} ;
         accScriptSource(script, 1, scriptSource, scriptLength);
         accCompileScript(script);
         accGetScriptLabel(script, "main", (ACCvoid**) &scriptEntry);
-        // TBD: We currently leak the script object. We can't delete it until
-        // we are done with the scriptEntry.
     }
     if (scriptEntry) {
-        rsScriptCSetScript((void *)scriptEntry);
+        rsScriptCSetScript((void*) script, (void *)scriptEntry);
+        script = 0;
     }
 exit:
+    if (script) {
+        accDeleteScript(script);
+    }
     if (script_base) {
         _env->ReleasePrimitiveArrayCritical(scriptRef, script_base,
                 _exception ? JNI_ABORT: 0);
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 65a4a82..98c7008 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -288,7 +288,8 @@
 	}
 
 ScriptCSetScript {
-	param void * ptr
+	param void * accScript
+	param void * codePtr
 	}
 
 ScriptCCreate {
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index 60339ec..2c7d884 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -18,17 +18,23 @@
 #include "rsScriptC.h"
 #include "rsMatrix.h"
 
+#include "acc/acc.h"
+
 using namespace android;
 using namespace android::renderscript;
 
 
 ScriptC::ScriptC()
 {
+    mAccScript = NULL;
     mScript = NULL;
 }
 
 ScriptC::~ScriptC()
 {
+    if (mAccScript) {
+        accDeleteScript(mAccScript);
+    }
 }
 
 extern "C" void matrixLoadIdentity(void *con, rsc_Matrix *mat)
@@ -394,6 +400,9 @@
 
 ScriptCState::~ScriptCState()
 {
+    if (mAccScript) {
+        accDeleteScript(mAccScript);
+    }
 }
 
 void ScriptCState::clear()
@@ -405,6 +414,7 @@
     mClearColor[3] = 1;
     mClearDepth = 1;
     mClearStencil = 0;
+    mAccScript = NULL;
     mScript = NULL;
     mIsRoot = false;
     mIsOrtho = true;
@@ -446,9 +456,10 @@
     ss->mConstantBufferTypes.add(static_cast<const Type *>(vt));
 }
 
-void rsi_ScriptCSetScript(Context * rsc, void *vp)
+void rsi_ScriptCSetScript(Context * rsc, void* accScript, void *vp)
 {
     ScriptCState *ss = &rsc->mScriptC;
+    ss->mAccScript = reinterpret_cast<ACCscript*>(accScript);
     ss->mScript = reinterpret_cast<rsc_RunScript>(vp);
 }
 
@@ -469,6 +480,8 @@
     ScriptCState *ss = &rsc->mScriptC;
 
     ScriptC *s = new ScriptC();
+    s->mAccScript = ss->mAccScript;
+    ss->mAccScript = NULL;
     s->mScript = ss->mScript;
     s->mClearColor[0] = ss->mClearColor[0];
     s->mClearColor[1] = ss->mClearColor[1];
diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h
index f35a130..c58dcf9 100644
--- a/libs/rs/rsScriptC.h
+++ b/libs/rs/rsScriptC.h
@@ -21,11 +21,13 @@
 
 #include "RenderScriptEnv.h"
 
+struct ACCscript;
+
 // ---------------------------------------------------------------------------
 namespace android {
 namespace renderscript {
 
-    
+
 
 class ScriptC : public Script
 {
@@ -38,6 +40,7 @@
     virtual void run(Context *, uint32_t launchID);
 
 
+    ACCscript*    mAccScript;
     rsc_RunScript mScript;
 
 
@@ -48,13 +51,13 @@
 
 };
 
-class ScriptCState 
+class ScriptCState
 {
 public:
     ScriptCState();
     ~ScriptCState();
 
-
+    ACCscript*    mAccScript;
     rsc_RunScript mScript;
     float mClearColor[4];
     float mClearDepth;