Rewrite the internal code of get functions.
getExportVars -> getExportVarCount , getExportVarList
getExportFuncs -> getExportFuncCount , getExportFuncList
getPragmas -> getPragmaCount , getPragmaList
getFunctions -> getFuncCount, getFuncNameList
getFunctionBinary -> getFuncBinary
diff --git a/lib/bcc/CacheWriter.cpp b/lib/bcc/CacheWriter.cpp
index 2eaa8ce..a0b5da2 100644
--- a/lib/bcc/CacheWriter.cpp
+++ b/lib/bcc/CacheWriter.cpp
@@ -144,9 +144,7 @@
bool CacheWriter::prepareFuncTable() {
- ssize_t funcCount = 0;
-
- mpOwner->getFunctions(&funcCount, 0, NULL);
+ size_t funcCount = mpOwner->getFuncCount();
size_t tableSize = sizeof(OBCC_FuncTable) +
sizeof(OBCC_FuncInfo) * funcCount;
@@ -164,16 +162,16 @@
tab->count = static_cast<size_t>(funcCount);
// Get the function informations
- vector<char *> funcNameList(funcCount);
- mpOwner->getFunctions(0, funcCount, &*funcNameList.begin());
+ vector<char const *> funcNameList(funcCount);
+ mpOwner->getFuncNameList(funcCount, &*funcNameList.begin());
- for (int i = 0; i < funcCount; ++i) {
- char *funcName = funcNameList[i];
+ for (size_t i = 0; i < funcCount; ++i) {
+ char const *funcName = funcNameList[i];
size_t funcNameLen = strlen(funcName);
void *funcAddr = NULL;
- ssize_t funcBinarySize = 0;
- mpOwner->getFunctionBinary(funcName, &funcAddr, &funcBinarySize);
+ size_t funcBinarySize = 0;
+ mpOwner->getFuncBinary(funcName, &funcAddr, &funcBinarySize);
OBCC_FuncInfo *funcInfo = &tab->table[i];
funcInfo->name_strp_index = addString(funcName, funcNameLen);
@@ -186,11 +184,7 @@
bool CacheWriter::preparePragmaList() {
- ssize_t stringCount;
-
- mpOwner->getPragmas(&stringCount, 0, NULL);
-
- size_t pragmaCount = static_cast<size_t>(stringCount) / 2;
+ size_t pragmaCount = mpOwner->getPragmaCount();
size_t listSize = sizeof(OBCC_PragmaList) +
sizeof(OBCC_Pragma) * pragmaCount;
@@ -207,14 +201,15 @@
list->count = pragmaCount;
- vector<char *> strings(stringCount);
- mpOwner->getPragmas(&stringCount, stringCount, &*strings.begin());
+ vector<char const *> keyList(pragmaCount);
+ vector<char const *> valueList(pragmaCount);
+ mpOwner->getPragmaList(pragmaCount, &*keyList.begin(), &*valueList.begin());
for (size_t i = 0; i < pragmaCount; ++i) {
- char *key = strings[2 * i];
- size_t keyLen = strlen(key);
+ char const *key = keyList[i];
+ char const *value = valueList[i];
- char *value = strings[2 * i + 1];
+ size_t keyLen = strlen(key);
size_t valueLen = strlen(value);
OBCC_Pragma *pragma = &list->list[i];
@@ -276,10 +271,7 @@
bool CacheWriter::prepareExportVarList() {
- ssize_t varCount;
-
- mpOwner->getExportVars(&varCount, 0, NULL);
-
+ size_t varCount = mpOwner->getExportVarCount();
size_t listSize = sizeof(OBCC_ExportVarList) + sizeof(void *) * varCount;
OBCC_ExportVarList *list = (OBCC_ExportVarList *)malloc(listSize);
@@ -294,16 +286,13 @@
list->count = static_cast<size_t>(varCount);
- mpOwner->getExportVars(&varCount, varCount, list->cached_addr_list);
+ mpOwner->getExportVarList(varCount, list->cached_addr_list);
return true;
}
bool CacheWriter::prepareExportFuncList() {
- ssize_t funcCount;
-
- mpOwner->getExportFuncs(&funcCount, 0, NULL);
-
+ size_t funcCount = mpOwner->getExportFuncCount();
size_t listSize = sizeof(OBCC_ExportFuncList) + sizeof(void *) * funcCount;
OBCC_ExportFuncList *list = (OBCC_ExportFuncList *)malloc(listSize);
@@ -318,7 +307,7 @@
list->count = static_cast<size_t>(funcCount);
- mpOwner->getExportFuncs(&funcCount, funcCount, list->cached_addr_list);
+ mpOwner->getExportFuncList(funcCount, list->cached_addr_list);
return true;
}
diff --git a/lib/bcc/Script.cpp b/lib/bcc/Script.cpp
index af4b51e..735b2f7 100644
--- a/lib/bcc/Script.cpp
+++ b/lib/bcc/Script.cpp
@@ -161,7 +161,7 @@
}
-int Script::compile() {
+int Script::prepareExecutable() {
if (mStatus != ScriptStatus::Unknown) {
mErrorCode = BCC_INVALID_OPERATION;
LOGE("Invalid operation: %s\n", __func__);
@@ -340,11 +340,8 @@
void *Script::lookup(const char *name) {
switch (mStatus) {
- case ScriptStatus::Compiled:
- return mCompiled->lookup(name);
-
- case ScriptStatus::Cached:
- return mCached->lookup(name);
+ case ScriptStatus::Compiled: return mCompiled->lookup(name);
+ case ScriptStatus::Cached: return mCached->lookup(name);
default:
mErrorCode = BCC_INVALID_OPERATION;
@@ -353,17 +350,52 @@
}
-void Script::getExportVars(BCCsizei *actualVarCount,
- BCCsizei maxVarCount,
- BCCvoid **vars) {
+size_t Script::getExportVarCount() const {
switch (mStatus) {
- case ScriptStatus::Compiled:
- mCompiled->getExportVars(actualVarCount, maxVarCount, vars);
+ case ScriptStatus::Compiled: return mCompiled->getExportVarCount();
+ case ScriptStatus::Cached: return mCached->getExportVarCount();
+ default: return 0;
+ }
+}
+
+
+size_t Script::getExportFuncCount() const {
+ switch (mStatus) {
+ case ScriptStatus::Compiled: return mCompiled->getExportFuncCount();
+ case ScriptStatus::Cached: return mCached->getExportFuncCount();
+ default: return 0;
+ }
+}
+
+
+size_t Script::getPragmaCount() const {
+ switch (mStatus) {
+ case ScriptStatus::Compiled: return mCompiled->getPragmaCount();
+ case ScriptStatus::Cached: return mCached->getPragmaCount();
+ default: return 0;
+ }
+}
+
+
+size_t Script::getFuncCount() const {
+ switch (mStatus) {
+ case ScriptStatus::Compiled: return mCompiled->getFuncCount();
+ case ScriptStatus::Cached: return mCached->getFuncCount();
+ default: return 0;
+ }
+}
+
+
+void Script::getExportVarList(size_t varListSize, void **varList) {
+ switch (mStatus) {
+#define DELEGATE(STATUS) \
+ case ScriptStatus::STATUS: \
+ m##STATUS->getExportVarList(varListSize, varList); \
break;
- case ScriptStatus::Cached:
- mCached->getExportVars(actualVarCount, maxVarCount, vars);
- break;
+ DELEGATE(Cached);
+ DELEGATE(Compiled);
+#undef DELEGATE
default:
mErrorCode = BCC_INVALID_OPERATION;
@@ -371,17 +403,16 @@
}
-void Script::getExportFuncs(BCCsizei *actualFuncCount,
- BCCsizei maxFuncCount,
- BCCvoid **funcs) {
+void Script::getExportFuncList(size_t funcListSize, void **funcList) {
switch (mStatus) {
- case ScriptStatus::Compiled:
- mCompiled->getExportFuncs(actualFuncCount, maxFuncCount, funcs);
+#define DELEGATE(STATUS) \
+ case ScriptStatus::STATUS: \
+ m##STATUS->getExportFuncList(funcListSize, funcList); \
break;
- case ScriptStatus::Cached:
- mCached->getExportFuncs(actualFuncCount, maxFuncCount, funcs);
- break;
+ DELEGATE(Cached);
+ DELEGATE(Compiled);
+#undef DELEGATE
default:
mErrorCode = BCC_INVALID_OPERATION;
@@ -389,17 +420,18 @@
}
-void Script::getPragmas(BCCsizei *actualStringCount,
- BCCsizei maxStringCount,
- BCCchar **strings) {
+void Script::getPragmaList(size_t pragmaListSize,
+ char const **keyList,
+ char const **valueList) {
switch (mStatus) {
- case ScriptStatus::Compiled:
- mCompiled->getPragmas(actualStringCount, maxStringCount, strings);
+#define DELEGATE(STATUS) \
+ case ScriptStatus::STATUS: \
+ m##STATUS->getPragmaList(pragmaListSize, keyList, valueList); \
break;
- case ScriptStatus::Cached:
- mCached->getPragmas(actualStringCount, maxStringCount, strings);
- break;
+ DELEGATE(Cached);
+ DELEGATE(Compiled);
+#undef DELEGATE
default:
mErrorCode = BCC_INVALID_OPERATION;
@@ -407,17 +439,17 @@
}
-void Script::getFunctions(BCCsizei *actualFunctionCount,
- BCCsizei maxFunctionCount,
- BCCchar **functions) {
+void Script::getFuncNameList(size_t funcNameListSize,
+ char const **funcNameList) {
switch (mStatus) {
- case ScriptStatus::Compiled:
- mCompiled->getFunctions(actualFunctionCount, maxFunctionCount, functions);
+#define DELEGATE(STATUS) \
+ case ScriptStatus::STATUS: \
+ m##STATUS->getFuncNameList(funcNameListSize, funcNameList);
break;
- case ScriptStatus::Cached:
- mCached->getFunctions(actualFunctionCount, maxFunctionCount, functions);
- break;
+ DELEGATE(Cached);
+ DELEGATE(Compiled);
+#undef DELEGATE
default:
mErrorCode = BCC_INVALID_OPERATION;
@@ -426,11 +458,8 @@
char *Script::getContext() {
switch (mStatus) {
- case ScriptStatus::Compiled:
- return mCompiled->getContext();
-
- case ScriptStatus::Cached:
- return mCached->getContext();
+ case ScriptStatus::Cached: return mCached->getContext();
+ case ScriptStatus::Compiled: return mCompiled->getContext();
default:
mErrorCode = BCC_INVALID_OPERATION;
@@ -439,24 +468,23 @@
}
-void Script::getFunctionBinary(BCCchar *function,
- BCCvoid **base,
- BCCsizei *length) {
+void Script::getFuncBinary(char const *funcname,
+ void **base,
+ size_t *length) {
switch (mStatus) {
- case ScriptStatus::Compiled:
- mCompiled->getFunctionBinary(function, base, length);
- return;
+#define DELEGATE(STATUS) \
+ case ScriptStatus::STATUS: \
+ m##STATUS->getFuncBinary(funcname, base, length); \
+ break;
- case ScriptStatus::Cached:
- mCached->getFunctionBinary(function, base, length);
- return;
+ DELEGATE(Cached);
+ DELEGATE(Compiled);
+#undef DELEGATE
default:
*base = NULL;
*length = 0;
- return;
}
-
}
diff --git a/lib/bcc/Script.h b/lib/bcc/Script.h
index 306cf23..7bbb36c 100644
--- a/lib/bcc/Script.h
+++ b/lib/bcc/Script.h
@@ -21,6 +21,8 @@
#include "Compiler.h"
+#include <stddef.h>
+
namespace llvm {
class Module;
}
@@ -87,36 +89,39 @@
int linkBC(const char *bitcode, size_t bitcodeSize);
- int compile(); // deprecated
+ int prepareExecutable();
char const *getCompilerErrorMessage();
void *lookup(const char *name);
- void getExportVars(BCCsizei *actualVarCount,
- BCCsizei maxVarCount,
- BCCvoid **vars);
- void getExportFuncs(BCCsizei *actualFuncCount,
- BCCsizei maxFuncCount,
- BCCvoid **funcs);
+ size_t getExportVarCount() const;
- void getPragmas(BCCsizei *actualStringCount,
- BCCsizei maxStringCount,
- BCCchar **strings);
+ size_t getExportFuncCount() const;
- void getFunctions(BCCsizei *actualFunctionCount,
- BCCsizei maxFunctionCount,
- BCCchar **functions);
+ size_t getPragmaCount() const;
- void getFunctionBinary(BCCchar *function,
- BCCvoid **base,
- BCCsizei *length);
+ size_t getFuncCount() const;
- char *getContext();
+
+ void getExportVarList(size_t size, void **list);
+
+ void getExportFuncList(size_t size, void **list);
+
+ void getPragmaList(size_t size,
+ char const **keyList,
+ char const **valueList);
+
+ void getFuncNameList(size_t size, char const **list);
+
+ void getFuncBinary(char const *funcname, void **base, size_t *length);
+
void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext);
+ char *getContext();
+
void setError(BCCenum error) {
if (mErrorCode == BCC_NO_ERROR && error != BCC_NO_ERROR) {
diff --git a/lib/bcc/ScriptCached.cpp b/lib/bcc/ScriptCached.cpp
index 6b27388..8011458 100644
--- a/lib/bcc/ScriptCached.cpp
+++ b/lib/bcc/ScriptCached.cpp
@@ -40,57 +40,51 @@
if (mpExportFuncs) { free(mpExportFuncs); }
}
-void ScriptCached::getExportVars(BCCsizei *actualVarCount,
- BCCsizei maxVarCount,
- BCCvoid **vars) {
- int varCount = static_cast<int>(mpExportVars->count);
+void ScriptCached::getExportVarList(size_t varListSize, void **varList) {
+ if (varList) {
+ size_t varCount = getExportVarCount();
- if (actualVarCount)
- *actualVarCount = varCount;
- if (varCount > maxVarCount)
- varCount = maxVarCount;
- if (vars) {
- void **ptr = mpExportVars->cached_addr_list;
- for (int i = 0; i < varCount; i++) {
- *vars++ = *ptr++;
+ if (varCount > varListSize) {
+ varCount = varListSize;
}
+
+ memcpy(varList, mpExportVars->cached_addr_list, sizeof(void *) * varCount);
}
}
-void ScriptCached::getExportFuncs(BCCsizei *actualFuncCount,
- BCCsizei maxFuncCount,
- BCCvoid **funcs) {
- int funcCount = static_cast<int>(mpExportFuncs->count);
+void ScriptCached::getExportFuncList(size_t funcListSize, void **funcList) {
+ if (funcList) {
+ size_t funcCount = getExportFuncCount();
- if (actualFuncCount)
- *actualFuncCount = funcCount;
- if (funcCount > maxFuncCount)
- funcCount = maxFuncCount;
- if (funcs) {
- void **ptr = mpExportFuncs->cached_addr_list;
- for (int i = 0; i < funcCount; i++) {
- *funcs++ = *ptr++;
+ if (funcCount > funcListSize) {
+ funcCount = funcListSize;
}
+
+ memcpy(funcList, mpExportFuncs->cached_addr_list,
+ sizeof(void *) * funcCount);
}
}
-void ScriptCached::getPragmas(BCCsizei *actualStringCount,
- BCCsizei maxStringCount,
- BCCchar **strings) {
- int stringCount = static_cast<int>(mPragmas.size()) * 2;
+void ScriptCached::getPragmaList(size_t pragmaListSize,
+ char const **keyList,
+ char const **valueList) {
+ size_t pragmaCount = getPragmaCount();
- if (actualStringCount)
- *actualStringCount = stringCount;
+ if (pragmaCount > pragmaListSize) {
+ pragmaCount = pragmaListSize;
+ }
- if (stringCount > maxStringCount)
- stringCount = maxStringCount;
+ if (keyList) {
+ for (size_t i = 0; i < pragmaCount; ++i) {
+ *keyList++ = mPragmas[i].first;
+ }
+ }
- if (strings) {
- for (int i = 0; stringCount >= 2; stringCount -= 2, ++i) {
- *strings++ = const_cast<BCCchar *>(mPragmas[i].first);
- *strings++ = const_cast<BCCchar *>(mPragmas[i].second);
+ if (valueList) {
+ for (size_t i = 0; i < pragmaCount; ++i) {
+ *valueList++ = mPragmas[i].second;
}
}
}
@@ -102,36 +96,40 @@
}
-void ScriptCached::getFunctions(BCCsizei *actualFunctionCount,
- BCCsizei maxFunctionCount,
- BCCchar **functions) {
- int functionCount = mFunctions.size();
+void ScriptCached::getFuncNameList(size_t funcNameListSize,
+ char const **funcNameList) {
+ if (funcNameList) {
+ size_t funcCount = getFuncCount();
- if (actualFunctionCount)
- *actualFunctionCount = functionCount;
- if (functionCount > maxFunctionCount)
- functionCount = maxFunctionCount;
- if (functions) {
+ if (funcCount > funcNameListSize) {
+ funcCount = funcNameListSize;
+ }
+
for (FuncTable::const_iterator
I = mFunctions.begin(), E = mFunctions.end();
- I != E && (functionCount > 0); I++, functionCount--) {
- *functions++ = const_cast<BCCchar*>(I->first.c_str());
+ I != E && funcCount > 0; I++, funcCount--) {
+ *funcNameList++ = I->first.c_str();
}
}
}
-void ScriptCached::getFunctionBinary(BCCchar *funcname,
- BCCvoid **base,
- BCCsizei *length) {
+void ScriptCached::getFuncBinary(char const *funcname,
+ void **base,
+ size_t *length) {
FuncTable::const_iterator I = mFunctions.find(funcname);
+
+#define DEREF_ASSIGN(VAR, VALUE) if (VAR) { *(VAR) = (VALUE); }
+
if (I == mFunctions.end()) {
- *base = NULL;
- *length = 0;
+ DEREF_ASSIGN(base, NULL);
+ DEREF_ASSIGN(length, 0);
} else {
- *base = I->second.first;
- *length = I->second.second;
+ DEREF_ASSIGN(base, I->second.first);
+ DEREF_ASSIGN(length, I->second.second);
}
+
+#undef DEREF_ASSIGN
}
diff --git a/lib/bcc/ScriptCached.h b/lib/bcc/ScriptCached.h
index 8950a11..49495dd 100644
--- a/lib/bcc/ScriptCached.h
+++ b/lib/bcc/ScriptCached.h
@@ -73,25 +73,38 @@
void *lookup(const char *name);
- void getExportVars(BCCsizei *actualVarCount,
- BCCsizei maxVarCount,
- BCCvoid **vars);
- void getExportFuncs(BCCsizei *actualFuncCount,
- BCCsizei maxFuncCount,
- BCCvoid **funcs);
+ size_t getExportVarCount() const {
+ return mpExportVars->count;
+ }
- void getPragmas(BCCsizei *actualStringCount,
- BCCsizei maxStringCount,
- BCCchar **strings);
+ size_t getExportFuncCount() const {
+ return mpExportFuncs->count;
+ }
- void getFunctions(BCCsizei *actualFunctionCount,
- BCCsizei maxFunctionCount,
- BCCchar **functions);
+ size_t getPragmaCount() const {
+ return mPragmas.size();
+ }
- void getFunctionBinary(BCCchar *function,
- BCCvoid **base,
- BCCsizei *length);
+ size_t getFuncCount() const {
+ return mFunctions.size();
+ }
+
+
+ void getExportVarList(size_t varListSize, void **varList);
+
+ void getExportFuncList(size_t funcListSize, void **funcList);
+
+ void getPragmaList(size_t pragmaListSize,
+ char const **keyList,
+ char const **valueList);
+
+ void getFuncNameList(size_t funcNameListSize, char const **funcNameList);
+
+ void getFuncBinary(char const *function,
+ void **base,
+ size_t *length);
+
char *getContext() {
return mContext;
diff --git a/lib/bcc/ScriptCompiled.cpp b/lib/bcc/ScriptCompiled.cpp
index 5c07d99..9868580 100644
--- a/lib/bcc/ScriptCompiled.cpp
+++ b/lib/bcc/ScriptCompiled.cpp
@@ -39,56 +39,54 @@
}
}
-void ScriptCompiled::getExportVars(BCCsizei *actualVarCount,
- BCCsizei maxVarCount,
- BCCvoid **vars) {
- int varCount = mExportVars.size();
- if (actualVarCount)
- *actualVarCount = varCount;
- if (varCount > maxVarCount)
- varCount = maxVarCount;
- if (vars) {
+void ScriptCompiled::getExportVarList(size_t varListSize, void **varList) {
+ if (varList) {
+ size_t varCount = getExportVarCount();
+
+ if (varCount > varListSize) {
+ varCount = varListSize;
+ }
+
for (ExportVarList::const_iterator
- I = mExportVars.begin(), E = mExportVars.end(); I != E; I++) {
- *vars++ = *I;
+ I = mExportVars.begin(), E = mExportVars.end();
+ I != E && varCount > 0; ++I, --varCount) {
+ *varList++ = *I;
}
}
}
-void ScriptCompiled::getExportFuncs(BCCsizei *actualFuncCount,
- BCCsizei maxFuncCount,
- BCCvoid **funcs) {
- int funcCount = mExportFuncs.size();
- if (actualFuncCount)
- *actualFuncCount = funcCount;
- if (funcCount > maxFuncCount)
- funcCount = maxFuncCount;
- if (funcs) {
+void ScriptCompiled::getExportFuncList(size_t funcListSize, void **funcList) {
+ if (funcList) {
+ size_t funcCount = getExportFuncCount();
+
+ if (funcCount > funcListSize) {
+ funcCount = funcListSize;
+ }
+
for (ExportFuncList::const_iterator
- I = mExportFuncs.begin(), E = mExportFuncs.end(); I != E; I++) {
- *funcs++ = *I;
+ I = mExportFuncs.begin(), E = mExportFuncs.end();
+ I != E && funcCount > 0; ++I, --funcCount) {
+ *funcList++ = *I;
}
}
}
-void ScriptCompiled::getPragmas(BCCsizei *actualStringCount,
- BCCsizei maxStringCount,
- BCCchar **strings) {
- int stringCount = mPragmas.size() * 2;
+void ScriptCompiled::getPragmaList(size_t pragmaListSize,
+ char const **keyList,
+ char const **valueList) {
+ size_t pragmaCount = getPragmaCount();
- if (actualStringCount)
- *actualStringCount = stringCount;
- if (stringCount > maxStringCount)
- stringCount = maxStringCount;
- if (strings) {
- size_t i = 0;
- for (PragmaList::const_iterator it = mPragmas.begin();
- stringCount >= 2; stringCount -= 2, it++, ++i) {
- *strings++ = const_cast<BCCchar*>(it->first.c_str());
- *strings++ = const_cast<BCCchar*>(it->second.c_str());
- }
+ if (pragmaCount > pragmaListSize) {
+ pragmaCount = pragmaListSize;
+ }
+
+ for (PragmaList::const_iterator
+ I = mPragmas.begin(), E = mPragmas.end();
+ I != E && pragmaCount > 0; ++I, --pragmaCount) {
+ if (keyList) { *keyList++ = I->first.c_str(); }
+ if (valueList) { *valueList++ = I->second.c_str(); }
}
}
@@ -99,37 +97,40 @@
}
-void ScriptCompiled::getFunctions(BCCsizei *actualFunctionCount,
- BCCsizei maxFunctionCount,
- BCCchar **functions) {
+void ScriptCompiled::getFuncNameList(size_t funcNameListSize,
+ char const **funcNameList) {
+ if (funcNameList) {
+ size_t funcCount = getFuncCount();
- int functionCount = mEmittedFunctions.size();
+ if (funcCount > funcNameListSize) {
+ funcCount = funcNameListSize;
+ }
- if (actualFunctionCount)
- *actualFunctionCount = functionCount;
- if (functionCount > maxFunctionCount)
- functionCount = maxFunctionCount;
- if (functions) {
for (EmittedFunctionsMapTy::const_iterator
I = mEmittedFunctions.begin(), E = mEmittedFunctions.end();
- I != E && (functionCount > 0); I++, functionCount--) {
- *functions++ = const_cast<BCCchar*>(I->first.c_str());
+ I != E && funcCount > 0; ++I, --funcCount) {
+ *funcNameList++ = I->first.c_str();
}
}
}
-void ScriptCompiled::getFunctionBinary(BCCchar *funcname,
- BCCvoid **base,
- BCCsizei *length) {
+void ScriptCompiled::getFuncBinary(char const *funcname,
+ void **base,
+ size_t *length) {
EmittedFunctionsMapTy::const_iterator I = mEmittedFunctions.find(funcname);
+
+#define DEREF_ASSIGN(VAR, VALUE) if (VAR) { *(VAR) = (VALUE); }
+
if (I == mEmittedFunctions.end()) {
- *base = NULL;
- *length = 0;
+ DEREF_ASSIGN(base, NULL);
+ DEREF_ASSIGN(length, 0);
} else {
- *base = I->second->Code;
- *length = I->second->Size;
+ DEREF_ASSIGN(base, I->second->Code);
+ DEREF_ASSIGN(length, I->second->Size);
}
+
+#undef DEREF_ASSIGN
}
diff --git a/lib/bcc/ScriptCompiled.h b/lib/bcc/ScriptCompiled.h
index 4d332b1..a160b78 100644
--- a/lib/bcc/ScriptCompiled.h
+++ b/lib/bcc/ScriptCompiled.h
@@ -86,25 +86,37 @@
void *lookup(const char *name);
- void getExportVars(BCCsizei *actualVarCount,
- BCCsizei maxVarCount,
- BCCvoid **vars);
- void getExportFuncs(BCCsizei *actualFuncCount,
- BCCsizei maxFuncCount,
- BCCvoid **funcs);
+ size_t getExportVarCount() const {
+ return mExportVars.size();
+ }
- void getPragmas(BCCsizei *actualStringCount,
- BCCsizei maxStringCount,
- BCCchar **strings);
+ size_t getExportFuncCount() const {
+ return mExportFuncs.size();
+ }
- void getFunctions(BCCsizei *actualFunctionCount,
- BCCsizei maxFunctionCount,
- BCCchar **functions);
+ size_t getPragmaCount() const {
+ return mPragmas.size();
+ }
- void getFunctionBinary(BCCchar *function,
- BCCvoid **base,
- BCCsizei *length);
+ size_t getFuncCount() const {
+ return mEmittedFunctions.size();
+ }
+
+
+ void getExportVarList(size_t varListSize, void **varList);
+
+ void getExportFuncList(size_t funcListSize, void **funcList);
+
+ void getPragmaList(size_t pragmaListSize,
+ char const **keyList,
+ char const **valueList);
+
+ void getFuncNameList(size_t funcNameListSize, char const **funcNameList);
+
+ void getFuncBinary(char const *function,
+ void **base,
+ size_t *length);
char *getContext() {
return mContext;
diff --git a/lib/bcc/bcc.cpp b/lib/bcc/bcc.cpp
index 9efa020..a52c8f9 100644
--- a/lib/bcc/bcc.cpp
+++ b/lib/bcc/bcc.cpp
@@ -104,7 +104,7 @@
android::StopWatch compileTimer("bcc: PrepareExecutable time");
#endif
- int result = script->compile();
+ int result = script->prepareExecutable();
if (result)
script->setError(BCC_INVALID_OPERATION);
@@ -116,19 +116,7 @@
BCCsizei *length,
BCCchar *infoLog) {
BCC_FUNC_LOGGER();
- char const *message = script->getCompilerErrorMessage();
- int messageLength = strlen(message) + 1;
- if (length)
- *length = messageLength;
-
- if (infoLog && maxLength > 0) {
- int trimmedLength = maxLength < messageLength ? maxLength : messageLength;
- memcpy(infoLog, message, trimmedLength);
- infoLog[trimmedLength] = 0;
-#if defined(USE_DISASSEMBLER_FILE)
- LOGI("[GetScriptInfoLog] %s", infoLog);
-#endif
- }
+ LOGE("%s is deprecated. *********************************\n", __func__);
}
extern "C" void bccGetScriptLabel(BCCscript *script,
@@ -147,73 +135,133 @@
}
extern "C" void bccGetExportVars(BCCscript *script,
- BCCsizei *actualVarCount,
- BCCsizei maxVarCount,
- BCCvoid **vars) {
+ BCCsizei *actualCount,
+ BCCsizei varListSize,
+ BCCvoid **varList) {
BCC_FUNC_LOGGER();
- script->getExportVars(actualVarCount, maxVarCount, vars);
+
+ if (actualCount) {
+ *actualCount = static_cast<BCCsizei>(script->getExportVarCount());
+ }
+
+ if (varList) {
+ script->getExportVarList(static_cast<size_t>(varListSize), varList);
#if defined(USE_DISASSEMBLER_FILE)
- int i;
- if (actualVarCount) {
- LOGI("[ExportVars] #=%d:", *actualVarCount);
- } else {
- for (i = 0; i < maxVarCount; i++) {
- LOGI("[ExportVars] #%d=0x%x", i, vars[i]);
+ size_t count = script->getExportVarCount();
+ LOGD("ExportVarCount = %lu\n", (unsigned long)count);
+
+ if (count > varListSize) {
+ count = varListSize;
}
- }
+
+ for (size_t i = 0; i < count; ++i) {
+ LOGD("ExportVarList[%lu] = 0x%p\n", (unsigned long)i, varList[i]);
+ }
#endif
+ }
}
extern "C" void bccGetExportFuncs(BCCscript *script,
- BCCsizei *actualFuncCount,
- BCCsizei maxFuncCount,
- BCCvoid **funcs) {
+ BCCsizei *actualCount,
+ BCCsizei funcListSize,
+ BCCvoid **funcList) {
BCC_FUNC_LOGGER();
- script->getExportFuncs(actualFuncCount, maxFuncCount, funcs);
+
+ if (actualCount) {
+ *actualCount = static_cast<BCCsizei>(script->getExportFuncCount());
+ }
+
+ if (funcList) {
+ script->getExportFuncList(static_cast<size_t>(funcListSize), funcList);
#if defined(USE_DISASSEMBLER_FILE)
- int i;
- if (actualFuncCount) {
- LOGI("[ExportFunc] #=%d:", *actualFuncCount);
- } else {
- for (i = 0; i < maxFuncCount; i++) {
- LOGI("[ExportFunc] #%d=0x%x", i, funcs[i]);
+ size_t count = script->getExportFuncCount();
+ LOGD("ExportFuncCount = %lu\n", (unsigned long)count);
+
+ if (count > funcListSize) {
+ count = funcListSize;
}
- }
+
+ for (size_t i = 0; i < count; ++i) {
+ LOGD("ExportFuncList[%lu] = 0x%p\n", (unsigned long)i, funcList[i]);
+ }
#endif
+ }
}
extern "C" void bccGetPragmas(BCCscript *script,
- BCCsizei *actualStringCount,
- BCCsizei maxStringCount,
- BCCchar **strings) {
+ BCCsizei *actualCount,
+ BCCsizei stringListSize,
+ BCCchar **stringList) {
BCC_FUNC_LOGGER();
- script->getPragmas(actualStringCount, maxStringCount, strings);
+
+ if (actualCount) {
+ *actualCount = static_cast<BCCsizei>(script->getPragmaCount() * 2);
+ }
+
+ if (stringList) {
+ size_t pragmaListSize = static_cast<size_t>(stringListSize) / 2;
+
+ char const **buf = new (nothrow) char const *[pragmaListSize * 2];
+ if (!buf) {
+ return;
+ }
+
+ char const **keyList = buf;
+ char const **valueList = buf + pragmaListSize;
+
+ script->getPragmaList(pragmaListSize, keyList, valueList);
+
+ for (size_t i = 0; i < pragmaListSize; ++i) {
+ *stringList++ = const_cast<BCCchar *>(keyList[i]);
+ *stringList++ = const_cast<BCCchar *>(valueList[i]);
+ }
+
+ delete [] buf;
#if defined(USE_DISASSEMBLER_FILE)
- int i;
- LOGI("[Pragma] #=%d:", *actualStringCount);
- for (i = 0; i < *actualStringCount; i++) {
- LOGI(" %s", strings[i]);
- }
+ size_t count = script->getPragmaCount();
+ LOGD("PragmaCount = %lu\n", count);
+
+ if (count > pragmaListSize) {
+ count = pragmaListSize;
+ }
+
+ for (size_t i = 0; i < count; ++i) {
+ LOGD("Pragma[%lu] = (%s , %s)\n",
+ (unsigned long)i, stringList[2 * i], stringList[2 * i + 1]);
+ }
#endif
+ }
}
extern "C" void bccGetFunctions(BCCscript *script,
- BCCsizei *actualFunctionCount,
- BCCsizei maxFunctionCount,
- BCCchar **functions) {
+ BCCsizei *actualCount,
+ BCCsizei funcNameListSize,
+ BCCchar **funcNameList) {
BCC_FUNC_LOGGER();
- script->getFunctions(actualFunctionCount,
- maxFunctionCount,
- functions);
+
+ if (actualCount) {
+ *actualCount = static_cast<BCCsizei>(script->getFuncCount());
+ }
+
+ if (funcNameList) {
+ script->getFuncNameList(static_cast<size_t>(funcNameListSize),
+ const_cast<char const **>(funcNameList));
+ }
}
extern "C" void bccGetFunctionBinary(BCCscript *script,
- BCCchar *function,
+ BCCchar *funcname,
BCCvoid **base,
BCCsizei *length) {
BCC_FUNC_LOGGER();
- script->getFunctionBinary(function, base, length);
+
+ size_t funcLength = 0;
+ script->getFuncBinary(funcname, base, &funcLength);
+
+ if (length) {
+ *length = static_cast<BCCsizei>(funcLength);
+ }
}