rsScriptC.cpp revision afca6df36431af4dee8b8a8ee8c1bba18b01ef0d
1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "rsContext.h"
18#include "rsScriptC.h"
19#include "rsMatrix.h"
20#include "utils/Timers.h"
21#include "utils/StopWatch.h"
22extern "C" {
23#include "libdex/ZipArchive.h"
24}
25
26#include <GLES/gl.h>
27#include <GLES/glext.h>
28
29using namespace android;
30using namespace android::renderscript;
31
32#define GET_TLS()  Context::ScriptTLSStruct * tls = \
33    (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
34    Context * rsc = tls->mContext; \
35    ScriptC * sc = (ScriptC *) tls->mScript
36
37// Input: cacheDir
38// Input: resName
39// Input: extName
40//
41// Note: cacheFile = resName + extName
42//
43// Output: Returns cachePath == cacheDir + cacheFile
44char *genCacheFileName(const char *cacheDir,
45                       const char *resName,
46                       const char *extName) {
47    char cachePath[512];
48    char cacheFile[sizeof(cachePath)];
49    const size_t kBufLen = sizeof(cachePath) - 1;
50
51    cacheFile[0] = '\0';
52    // Note: resName today is usually something like
53    //       "/com.android.fountain:raw/fountain"
54    if (resName[0] != '/') {
55        // Get the absolute path of the raw/***.bc file.
56
57        // Generate the absolute path.  This doesn't do everything it
58        // should, e.g. if resName is "./out/whatever" it doesn't crunch
59        // the leading "./" out because this if-block is not triggered,
60        // but it'll make do.
61        //
62        if (getcwd(cacheFile, kBufLen) == NULL) {
63            LOGE("Can't get CWD while opening raw/***.bc file\n");
64            return NULL;
65        }
66        // Append "/" at the end of cacheFile so far.
67        strncat(cacheFile, "/", kBufLen);
68    }
69
70    // cacheFile = resName + extName
71    //
72    strncat(cacheFile, resName, kBufLen);
73    if (extName != NULL) {
74        // TODO(srhines): strncat() is a bit dangerous
75        strncat(cacheFile, extName, kBufLen);
76    }
77
78    // Turn the path into a flat filename by replacing
79    // any slashes after the first one with '@' characters.
80    char *cp = cacheFile + 1;
81    while (*cp != '\0') {
82        if (*cp == '/') {
83            *cp = '@';
84        }
85        cp++;
86    }
87
88    // Tack on the file name for the actual cache file path.
89    strncpy(cachePath, cacheDir, kBufLen);
90    strncat(cachePath, cacheFile, kBufLen);
91
92    LOGV("Cache file for '%s' '%s' is '%s'\n", resName, extName, cachePath);
93    return strdup(cachePath);
94}
95
96ScriptC::ScriptC(Context *rsc) : Script(rsc) {
97    mBccScript = NULL;
98    memset(&mProgram, 0, sizeof(mProgram));
99}
100
101ScriptC::~ScriptC() {
102    if (mBccScript) {
103        if (mProgram.mObjectSlotList) {
104            for (size_t ct=0; ct < mProgram.mObjectSlotCount; ct++) {
105                setVarObj(mProgram.mObjectSlotList[ct], NULL);
106            }
107            delete [] mProgram.mObjectSlotList;
108            mProgram.mObjectSlotList = NULL;
109            mProgram.mObjectSlotCount = 0;
110        }
111
112
113        LOGD(">>>> ~ScriptC  bccDisposeScript(%p)", mBccScript);
114        bccDisposeScript(mBccScript);
115    }
116    free(mEnviroment.mScriptText);
117    mEnviroment.mScriptText = NULL;
118}
119
120void ScriptC::setupScript(Context *rsc) {
121    mEnviroment.mStartTimeMillis
122                = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
123
124    for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) {
125        if (mSlots[ct].get() && !mTypes[ct].get()) {
126            mTypes[ct].set(mSlots[ct]->getType());
127        }
128
129        if (!mTypes[ct].get())
130            continue;
131        void *ptr = NULL;
132        if (mSlots[ct].get()) {
133            ptr = mSlots[ct]->getPtr();
134        }
135        void **dest = ((void ***)mEnviroment.mFieldAddress)[ct];
136
137        if (rsc->props.mLogScripts) {
138            if (mSlots[ct].get() != NULL) {
139                LOGV("%p ScriptC::setupScript slot=%i  dst=%p  src=%p  type=%p", rsc, ct, dest, ptr, mSlots[ct]->getType());
140            } else {
141                LOGV("%p ScriptC::setupScript slot=%i  dst=%p  src=%p  type=null", rsc, ct, dest, ptr);
142            }
143        }
144
145        if (dest) {
146            *dest = ptr;
147        }
148    }
149}
150
151const Allocation *ScriptC::ptrToAllocation(const void *ptr) const {
152    if (!ptr) {
153        return NULL;
154    }
155    for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) {
156        if (!mSlots[ct].get())
157            continue;
158        if (mSlots[ct]->getPtr() == ptr) {
159            return mSlots[ct].get();
160        }
161    }
162    LOGE("ScriptC::ptrToAllocation, failed to find %p", ptr);
163    return NULL;
164}
165
166Script * ScriptC::setTLS(Script *sc) {
167    Context::ScriptTLSStruct * tls = (Context::ScriptTLSStruct *)
168                                  pthread_getspecific(Context::gThreadTLSKey);
169    rsAssert(tls);
170    Script *old = tls->mScript;
171    tls->mScript = sc;
172    return old;
173}
174
175void ScriptC::setupGLState(Context *rsc) {
176    if (mEnviroment.mFragmentStore.get()) {
177        rsc->setProgramStore(mEnviroment.mFragmentStore.get());
178    }
179    if (mEnviroment.mFragment.get()) {
180        rsc->setProgramFragment(mEnviroment.mFragment.get());
181    }
182    if (mEnviroment.mVertex.get()) {
183        rsc->setProgramVertex(mEnviroment.mVertex.get());
184    }
185    if (mEnviroment.mRaster.get()) {
186        rsc->setProgramRaster(mEnviroment.mRaster.get());
187    }
188}
189
190uint32_t ScriptC::run(Context *rsc) {
191    if (mProgram.mRoot == NULL) {
192        rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script");
193        return 0;
194    }
195
196    setupGLState(rsc);
197    setupScript(rsc);
198
199    uint32_t ret = 0;
200    Script * oldTLS = setTLS(this);
201
202    if (rsc->props.mLogScripts) {
203        LOGV("%p ScriptC::run invoking root,  ptr %p", rsc, mProgram.mRoot);
204    }
205
206    ret = mProgram.mRoot();
207
208    if (rsc->props.mLogScripts) {
209        LOGV("%p ScriptC::run invoking complete, ret=%i", rsc, ret);
210    }
211
212    setTLS(oldTLS);
213    return ret;
214}
215
216typedef struct {
217    Context *rsc;
218    ScriptC *script;
219    const Allocation * ain;
220    Allocation * aout;
221    const void * usr;
222
223    uint32_t mSliceSize;
224    volatile int mSliceNum;
225
226    const uint8_t *ptrIn;
227    uint32_t eStrideIn;
228    uint8_t *ptrOut;
229    uint32_t eStrideOut;
230
231    uint32_t xStart;
232    uint32_t xEnd;
233    uint32_t yStart;
234    uint32_t yEnd;
235    uint32_t zStart;
236    uint32_t zEnd;
237    uint32_t arrayStart;
238    uint32_t arrayEnd;
239
240    uint32_t dimX;
241    uint32_t dimY;
242    uint32_t dimZ;
243    uint32_t dimArray;
244} MTLaunchStruct;
245typedef int (*rs_t)(const void *, void *, const void *, uint32_t, uint32_t, uint32_t, uint32_t);
246
247static void wc_xy(void *usr, uint32_t idx) {
248    MTLaunchStruct *mtls = (MTLaunchStruct *)usr;
249
250    while (1) {
251        uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum);
252        uint32_t yStart = mtls->yStart + slice * mtls->mSliceSize;
253        uint32_t yEnd = yStart + mtls->mSliceSize;
254        yEnd = rsMin(yEnd, mtls->yEnd);
255        if (yEnd <= yStart) {
256            return;
257        }
258
259        //LOGE("usr idx %i, x %i,%i  y %i,%i", idx, mtls->xStart, mtls->xEnd, yStart, yEnd);
260        //LOGE("usr ptr in %p,  out %p", mtls->ptrIn, mtls->ptrOut);
261        for (uint32_t y = yStart; y < yEnd; y++) {
262            uint32_t offset = mtls->dimX * y;
263            uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * offset);
264            const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * offset);
265
266            for (uint32_t x = mtls->xStart; x < mtls->xEnd; x++) {
267                ((rs_t)mtls->script->mProgram.mRoot) (xPtrIn, xPtrOut, mtls->usr, x, y, 0, 0);
268                xPtrIn += mtls->eStrideIn;
269                xPtrOut += mtls->eStrideOut;
270            }
271        }
272    }
273}
274
275static void wc_x(void *usr, uint32_t idx) {
276    MTLaunchStruct *mtls = (MTLaunchStruct *)usr;
277
278    while (1) {
279        uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum);
280        uint32_t xStart = mtls->xStart + slice * mtls->mSliceSize;
281        uint32_t xEnd = xStart + mtls->mSliceSize;
282        xEnd = rsMin(xEnd, mtls->xEnd);
283        if (xEnd <= xStart) {
284            return;
285        }
286
287        //LOGE("usr idx %i, x %i,%i  y %i,%i", idx, mtls->xStart, mtls->xEnd, yStart, yEnd);
288        //LOGE("usr ptr in %p,  out %p", mtls->ptrIn, mtls->ptrOut);
289        uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * xStart);
290        const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * xStart);
291        for (uint32_t x = xStart; x < xEnd; x++) {
292            ((rs_t)mtls->script->mProgram.mRoot) (xPtrIn, xPtrOut, mtls->usr, x, 0, 0, 0);
293            xPtrIn += mtls->eStrideIn;
294            xPtrOut += mtls->eStrideOut;
295        }
296    }
297}
298
299void ScriptC::runForEach(Context *rsc,
300                         const Allocation * ain,
301                         Allocation * aout,
302                         const void * usr,
303                         const RsScriptCall *sc) {
304    MTLaunchStruct mtls;
305    memset(&mtls, 0, sizeof(mtls));
306    Context::PushState ps(rsc);
307
308    if (ain) {
309        mtls.dimX = ain->getType()->getDimX();
310        mtls.dimY = ain->getType()->getDimY();
311        mtls.dimZ = ain->getType()->getDimZ();
312        //mtls.dimArray = ain->getType()->getDimArray();
313    } else if (aout) {
314        mtls.dimX = aout->getType()->getDimX();
315        mtls.dimY = aout->getType()->getDimY();
316        mtls.dimZ = aout->getType()->getDimZ();
317        //mtls.dimArray = aout->getType()->getDimArray();
318    } else {
319        rsc->setError(RS_ERROR_BAD_SCRIPT, "rsForEach called with null allocations");
320        return;
321    }
322
323    if (!sc || (sc->xEnd == 0)) {
324        mtls.xEnd = mtls.dimX;
325    } else {
326        rsAssert(sc->xStart < mtls.dimX);
327        rsAssert(sc->xEnd <= mtls.dimX);
328        rsAssert(sc->xStart < sc->xEnd);
329        mtls.xStart = rsMin(mtls.dimX, sc->xStart);
330        mtls.xEnd = rsMin(mtls.dimX, sc->xEnd);
331        if (mtls.xStart >= mtls.xEnd) return;
332    }
333
334    if (!sc || (sc->yEnd == 0)) {
335        mtls.yEnd = mtls.dimY;
336    } else {
337        rsAssert(sc->yStart < mtls.dimY);
338        rsAssert(sc->yEnd <= mtls.dimY);
339        rsAssert(sc->yStart < sc->yEnd);
340        mtls.yStart = rsMin(mtls.dimY, sc->yStart);
341        mtls.yEnd = rsMin(mtls.dimY, sc->yEnd);
342        if (mtls.yStart >= mtls.yEnd) return;
343    }
344
345    mtls.xEnd = rsMax((uint32_t)1, mtls.xEnd);
346    mtls.yEnd = rsMax((uint32_t)1, mtls.yEnd);
347    mtls.zEnd = rsMax((uint32_t)1, mtls.zEnd);
348    mtls.arrayEnd = rsMax((uint32_t)1, mtls.arrayEnd);
349
350    rsAssert(ain->getType()->getDimZ() == 0);
351
352    setupGLState(rsc);
353    setupScript(rsc);
354    Script * oldTLS = setTLS(this);
355
356    mtls.rsc = rsc;
357    mtls.ain = ain;
358    mtls.aout = aout;
359    mtls.script = this;
360    mtls.usr = usr;
361    mtls.mSliceSize = 10;
362    mtls.mSliceNum = 0;
363
364    mtls.ptrIn = NULL;
365    mtls.eStrideIn = 0;
366    if (ain) {
367        mtls.ptrIn = (const uint8_t *)ain->getPtr();
368        mtls.eStrideIn = ain->getType()->getElementSizeBytes();
369    }
370
371    mtls.ptrOut = NULL;
372    mtls.eStrideOut = 0;
373    if (aout) {
374        mtls.ptrOut = (uint8_t *)aout->getPtr();
375        mtls.eStrideOut = aout->getType()->getElementSizeBytes();
376    }
377
378    if ((rsc->getWorkerPoolSize() > 1) && mEnviroment.mIsThreadable) {
379        if (mtls.dimY > 1) {
380            rsc->launchThreads(wc_xy, &mtls);
381        } else {
382            rsc->launchThreads(wc_x, &mtls);
383        }
384
385        //LOGE("launch 1");
386    } else {
387        //LOGE("launch 3");
388        for (uint32_t ar = mtls.arrayStart; ar < mtls.arrayEnd; ar++) {
389            for (uint32_t z = mtls.zStart; z < mtls.zEnd; z++) {
390                for (uint32_t y = mtls.yStart; y < mtls.yEnd; y++) {
391                    uint32_t offset = mtls.dimX * mtls.dimY * mtls.dimZ * ar +
392                                      mtls.dimX * mtls.dimY * z +
393                                      mtls.dimX * y;
394                    uint8_t *xPtrOut = mtls.ptrOut + (mtls.eStrideOut * offset);
395                    const uint8_t *xPtrIn = mtls.ptrIn + (mtls.eStrideIn * offset);
396
397                    for (uint32_t x = mtls.xStart; x < mtls.xEnd; x++) {
398                        ((rs_t)mProgram.mRoot) (xPtrIn, xPtrOut, usr, x, y, z, ar);
399                        xPtrIn += mtls.eStrideIn;
400                        xPtrOut += mtls.eStrideOut;
401                    }
402                }
403            }
404        }
405    }
406
407    setTLS(oldTLS);
408}
409
410void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) {
411    if ((slot >= mEnviroment.mInvokeFunctionCount) ||
412        (mEnviroment.mInvokeFunctions[slot] == NULL)) {
413        rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script");
414        return;
415    }
416    setupScript(rsc);
417    Script * oldTLS = setTLS(this);
418
419    if (rsc->props.mLogScripts) {
420        LOGV("%p ScriptC::Invoke invoking slot %i,  ptr %p", rsc, slot, mEnviroment.mInvokeFunctions[slot]);
421    }
422    ((void (*)(const void *, uint32_t))
423        mEnviroment.mInvokeFunctions[slot])(data, len);
424    if (rsc->props.mLogScripts) {
425        LOGV("%p ScriptC::Invoke complete", rsc);
426    }
427
428    setTLS(oldTLS);
429}
430
431ScriptCState::ScriptCState() {
432}
433
434ScriptCState::~ScriptCState() {
435}
436
437static void* symbolLookup(void* pContext, char const* name) {
438    const ScriptCState::SymbolTable_t *sym;
439    ScriptC *s = (ScriptC *)pContext;
440    if (!strcmp(name, "__isThreadable")) {
441      return (void*) s->mEnviroment.mIsThreadable;
442    } else if (!strcmp(name, "__clearThreadable")) {
443      s->mEnviroment.mIsThreadable = false;
444      return NULL;
445    }
446    sym = ScriptCState::lookupSymbol(name);
447    if (!sym) {
448        sym = ScriptCState::lookupSymbolCL(name);
449    }
450    if (!sym) {
451        sym = ScriptCState::lookupSymbolGL(name);
452    }
453    if (sym) {
454        s->mEnviroment.mIsThreadable &= sym->threadable;
455        return sym->mPtr;
456    }
457    LOGE("ScriptC sym lookup failed for %s", name);
458    return NULL;
459}
460
461#if 0
462extern const char rs_runtime_lib_bc[];
463extern unsigned rs_runtime_lib_bc_size;
464#endif
465
466bool ScriptCState::runCompiler(Context *rsc,
467                               ScriptC *s,
468                               const char *resName,
469                               const char *cacheDir) {
470    s->mBccScript = bccCreateScript();
471
472    s->mEnviroment.mIsThreadable = true;
473
474    if (bccRegisterSymbolCallback(s->mBccScript, symbolLookup, s) != 0) {
475        LOGE("bcc: FAILS to register symbol callback");
476        return false;
477    }
478
479    if (bccReadBC(s->mBccScript,
480                  resName,
481                  s->mEnviroment.mScriptText,
482                  s->mEnviroment.mScriptTextLength, 0) != 0) {
483        LOGE("bcc: FAILS to read bitcode");
484        return false;
485    }
486
487#if 1
488    if (bccLinkFile(s->mBccScript, "/system/lib/libclcore.bc", 0) != 0) {
489        LOGE("bcc: FAILS to link bitcode");
490        return false;
491    }
492#endif
493    char *cachePath = genCacheFileName(cacheDir, resName, ".oBCC");
494
495    if (bccPrepareExecutable(s->mBccScript, cachePath, 0) != 0) {
496        LOGE("bcc: FAILS to prepare executable");
497        return false;
498    }
499
500    free(cachePath);
501
502    s->mProgram.mRoot = reinterpret_cast<int (*)()>(bccGetFuncAddr(s->mBccScript, "root"));
503    s->mProgram.mInit = reinterpret_cast<void (*)()>(bccGetFuncAddr(s->mBccScript, "init"));
504
505    if (s->mProgram.mInit) {
506        s->mProgram.mInit();
507    }
508
509    s->mEnviroment.mInvokeFunctionCount = bccGetExportFuncCount(s->mBccScript);
510    if (s->mEnviroment.mInvokeFunctionCount <= 0)
511        s->mEnviroment.mInvokeFunctions = NULL;
512    else {
513        s->mEnviroment.mInvokeFunctions = (Script::InvokeFunc_t*) calloc(s->mEnviroment.mInvokeFunctionCount, sizeof(Script::InvokeFunc_t));
514        bccGetExportFuncList(s->mBccScript, s->mEnviroment.mInvokeFunctionCount, (void **) s->mEnviroment.mInvokeFunctions);
515    }
516
517    s->mEnviroment.mFieldCount = bccGetExportVarCount(s->mBccScript);
518    if (s->mEnviroment.mFieldCount <= 0)
519        s->mEnviroment.mFieldAddress = NULL;
520    else {
521        s->mEnviroment.mFieldAddress = (void **) calloc(s->mEnviroment.mFieldCount, sizeof(void *));
522        bccGetExportVarList(s->mBccScript, s->mEnviroment.mFieldCount, (void **) s->mEnviroment.mFieldAddress);
523        s->initSlots();
524    }
525
526    s->mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
527    s->mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
528    s->mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore());
529    s->mEnviroment.mRaster.set(rsc->getDefaultProgramRaster());
530
531    const static int pragmaMax = 16;
532    size_t pragmaCount = bccGetPragmaCount(s->mBccScript);
533    char const *keys[pragmaMax];
534    char const *values[pragmaMax];
535    bccGetPragmaList(s->mBccScript, pragmaMax, keys, values);
536
537    for (size_t i=0; i < pragmaCount; ++i) {
538        //LOGE("pragma %s %s", keys[i], values[i]);
539        if (!strcmp(keys[i], "version")) {
540            if (!strcmp(values[i], "1")) {
541                continue;
542            }
543            LOGE("Invalid version pragma value: %s\n", values[i]);
544            return false;
545        }
546
547        if (!strcmp(keys[i], "stateVertex")) {
548            if (!strcmp(values[i], "default")) {
549                continue;
550            }
551            if (!strcmp(values[i], "parent")) {
552                s->mEnviroment.mVertex.clear();
553                continue;
554            }
555            LOGE("Unrecognized value %s passed to stateVertex", values[i]);
556            return false;
557        }
558
559        if (!strcmp(keys[i], "stateRaster")) {
560            if (!strcmp(values[i], "default")) {
561                continue;
562            }
563            if (!strcmp(values[i], "parent")) {
564                s->mEnviroment.mRaster.clear();
565                continue;
566            }
567            LOGE("Unrecognized value %s passed to stateRaster", values[i]);
568            return false;
569        }
570
571        if (!strcmp(keys[i], "stateFragment")) {
572            if (!strcmp(values[i], "default")) {
573                continue;
574            }
575            if (!strcmp(values[i], "parent")) {
576                s->mEnviroment.mFragment.clear();
577                continue;
578            }
579            LOGE("Unrecognized value %s passed to stateFragment", values[i]);
580            return false;
581        }
582
583        if (!strcmp(keys[i], "stateStore")) {
584            if (!strcmp(values[i], "default")) {
585                continue;
586            }
587            if (!strcmp(values[i], "parent")) {
588                s->mEnviroment.mFragmentStore.clear();
589                continue;
590            }
591            LOGE("Unrecognized value %s passed to stateStore", values[i]);
592            return false;
593        }
594    }
595
596    size_t objectSlotCount = bccGetObjectSlotCount(s->mBccScript);
597    uint32_t *objectSlots = NULL;
598    if (objectSlotCount) {
599        objectSlots = new uint32_t[objectSlotCount];
600        bccGetObjectSlotList(s->mBccScript, objectSlotCount, objectSlots);
601        s->mProgram.mObjectSlotList = objectSlots;
602        s->mProgram.mObjectSlotCount = objectSlotCount;
603    }
604
605    return true;
606}
607
608namespace android {
609namespace renderscript {
610
611void rsi_ScriptCBegin(Context * rsc) {
612}
613
614void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) {
615    ScriptCState *ss = &rsc->mScriptC;
616
617    char *t = (char *)malloc(len + 1);
618    memcpy(t, text, len);
619    t[len] = 0;
620    ss->mScriptText = t;
621    ss->mScriptLen = len;
622}
623
624
625RsScript rsi_ScriptCCreate(Context *rsc,
626                           const char *packageName /* deprecated */,
627                           const char *resName,
628                           const char *cacheDir)
629{
630    ScriptCState *ss = &rsc->mScriptC;
631
632    ScriptC *s = new ScriptC(rsc);
633    s->mEnviroment.mScriptText = ss->mScriptText;
634    s->mEnviroment.mScriptTextLength = ss->mScriptLen;
635    ss->mScriptText = NULL;
636    ss->mScriptLen = 0;
637    s->incUserRef();
638
639    if (!ss->runCompiler(rsc, s, resName, cacheDir)) {
640        // Error during compile, destroy s and return null.
641        delete s;
642        return NULL;
643    }
644    return s;
645}
646
647}
648}
649