Fix several bugs.
1. Incorrect string pool offset calculation.
2. Move the sha1 checksum calculation code forward.
3. Assign file to mFile (in order to share with different method).
diff --git a/lib/bcc/CacheReader.cpp b/lib/bcc/CacheReader.cpp
index ddb0258..8700eb9 100644
--- a/lib/bcc/CacheReader.cpp
+++ b/lib/bcc/CacheReader.cpp
@@ -57,6 +57,8 @@
return NULL;
}
+ mFile = file;
+
// Allocate ScriptCached object
mpResult.reset(new (nothrow) ScriptCached(S));
@@ -103,12 +105,6 @@
return false;
}
- // Dirty hack for libRS.
- // TODO(all): This should be removed in the future.
- if (mpHeader->libRS_threadable) {
- mpResult->mLibRSThreadable = true;
- }
-
return true;
}
@@ -131,6 +127,12 @@
return false;
}
+ // Dirty hack for libRS.
+ // TODO(all): This should be removed in the future.
+ if (mpHeader->libRS_threadable) {
+ mpResult->mLibRSThreadable = true;
+ }
+
return true;
}
@@ -196,7 +198,7 @@
CHECK_SECTION_OFFSET(str_pool);
CHECK_SECTION_OFFSET(depend_tab);
- CHECK_SECTION_OFFSET(reloc_tab);
+ //CHECK_SECTION_OFFSET(reloc_tab);
CHECK_SECTION_OFFSET(export_var_list);
CHECK_SECTION_OFFSET(export_func_list);
CHECK_SECTION_OFFSET(pragma_list);
diff --git a/lib/bcc/CacheWriter.cpp b/lib/bcc/CacheWriter.cpp
index 21ed2a8..87c554c 100644
--- a/lib/bcc/CacheWriter.cpp
+++ b/lib/bcc/CacheWriter.cpp
@@ -253,6 +253,8 @@
mpStringPoolSection = pool;
mpHeaderSection->str_pool_size = size;
+ pool->count = mStringPool.size();
+
char *strPtr = reinterpret_cast<char *>(pool) + strOffset;
for (size_t i = 0; i < mStringPool.size(); ++i) {
@@ -265,7 +267,7 @@
strPtr += str->length;
*strPtr++ = '\0';
- strOffset += str->length;
+ strOffset += str->length + 1;
}
return true;
diff --git a/lib/bcc/Script.cpp b/lib/bcc/Script.cpp
index c6ccfa1..133002b 100644
--- a/lib/bcc/Script.cpp
+++ b/lib/bcc/Script.cpp
@@ -188,6 +188,12 @@
return 1;
}
+ if (sourceBC) {
+ // If we are going to create cache file. We have to calculate sha1sum
+ // first (no matter we can open the file now or not.)
+ calcSHA1(sourceSHA1, sourceBC, sourceSize);
+ }
+
FileHandle file;
if (file.open(cacheFile, OpenMode::Read) < 0) {
@@ -202,7 +208,6 @@
reader.addDependency(BCC_FILE_RESOURCE, pathLibRS, sha1LibRS);
if (sourceBC) {
- calcSHA1(sourceSHA1, sourceBC, sourceSize);
reader.addDependency(BCC_APK_RESOURCE, sourceResName, sourceSHA1);
}
@@ -282,6 +287,14 @@
if (file.open(cacheFile, OpenMode::Write) >= 0) {
CacheWriter writer;
+ // Dependencies
+ writer.addDependency(BCC_FILE_RESOURCE, pathLibBCC, sha1LibBCC);
+ writer.addDependency(BCC_FILE_RESOURCE, pathLibRS, sha1LibRS);
+
+ if (sourceBC) {
+ writer.addDependency(BCC_APK_RESOURCE, sourceResName, sourceSHA1);
+ }
+
// libRS is threadable dirty hack
// TODO: This should be removed in the future
uint32_t libRS_threadable = 0;