Migrated engine to using dlmalloc through eng::

This commit is contained in:
2022-02-24 02:17:41 -05:00
parent acc00289fb
commit f467944095
61 changed files with 631 additions and 590 deletions

View File

@@ -34,7 +34,7 @@ LuaDefine(getclass, "classname", "get the classtab with the specified name") {
LuaArg classname;
LuaRet classtab;
LuaStack LS(L, classname, classtab);
std::string err = LS.getclass(classtab, classname);
eng::string err = LS.getclass(classtab, classname);
if (err != "") {
luaL_error(L, "%s", err.c_str());
}
@@ -45,7 +45,7 @@ LuaDefine(classname, "classtable", "get the class name from a class table") {
LuaArg table;
LuaRet result;
LuaStack LS(L, table, result);
std::string rstr = LS.classname(table);
eng::string rstr = LS.classname(table);
if (rstr == "") {
LS.set(result, LuaNil);
} else {
@@ -54,10 +54,10 @@ LuaDefine(classname, "classtable", "get the class name from a class table") {
return LS.result();
}
static void get_reg_name(const LuaFunctionReg *reg, std::string &classname, std::string &funcname) {
std::string name = reg->get_name();
static void get_reg_name(const LuaFunctionReg *reg, eng::string &classname, eng::string &funcname) {
eng::string name = reg->get_name();
size_t upos = name.find('_');
if (upos == std::string::npos) {
if (upos == eng::string::npos) {
funcname = name;
classname = "";
} else {
@@ -86,7 +86,7 @@ static void load_builtin_class(lua_State *L, const char *name, lua_CFunction fun
LS.result();
}
static void erase_builtin(LuaStack &LS, LuaSlot globtab, const std::string &classname, const std::string &funcname) {
static void erase_builtin(LuaStack &LS, LuaSlot globtab, const eng::string &classname, const eng::string &funcname) {
if (classname.empty()) {
LS.rawset(globtab, funcname, LuaNil);
} else {
@@ -130,7 +130,7 @@ static void source_install_builtins(lua_State *L) {
LS.result();
}
static void get_info_table(LuaStack &LS, LuaSlot db, LuaSlot info, const std::string &fn) {
static void get_info_table(LuaStack &LS, LuaSlot db, LuaSlot info, const eng::string &fn) {
LS.rawget(info, db, fn);
if (!LS.istable(info)) {
LS.set(info, LuaNewTable);
@@ -139,13 +139,13 @@ static void get_info_table(LuaStack &LS, LuaSlot db, LuaSlot info, const std::st
LS.rawset(info, "name", fn);
}
static void calculate_loadresult(LuaStack &LS0, LuaSlot info, const std::string &fn, const std::string &code) {
static void calculate_loadresult(LuaStack &LS0, LuaSlot info, const eng::string &fn, const eng::string &code) {
LuaVar loadresult;
LuaStack LS(LS0.state(), loadresult);
if (code == "") {
LS.rawset(info, "loadresult", "missing or empty source file");
} else {
std::string chunk = "=" + fn;
eng::string chunk = "=" + fn;
luaL_loadbuffer(LS.state(), code.c_str(), code.size(), chunk.c_str());
lua_replace(LS.state(), loadresult.index());
LS.rawset(info, "loadresult", loadresult);
@@ -167,7 +167,7 @@ void SourceDB::diff(const SourceDB &auth, StreamBuffer *sb) {
// Loop over the master database.
MLS.set(mfn, LuaNil);
while (MLS.next(mdb, mfn, minfo) != 0) {
std::string fn = MLS.ckstring(mfn);
eng::string fn = MLS.ckstring(mfn);
assert(MLS.istable(minfo));
MLS.rawget(mseq, minfo, "sequence");
MLS.rawget(mhash, minfo, "hash");
@@ -196,7 +196,7 @@ void SourceDB::diff(const SourceDB &auth, StreamBuffer *sb) {
// Loop over synch database.
SLS.set(sfn, LuaNil);
while (SLS.next(sdb, sfn, sinfo) != 0) {
std::string fn = SLS.ckstring(sfn);
eng::string fn = SLS.ckstring(sfn);
assert(SLS.istable(sinfo));
MLS.set(mfn, fn);
MLS.rawget(minfo, mdb, mfn);
@@ -219,9 +219,9 @@ bool SourceDB::patch(StreamBuffer *sb, DebugCollector *dbc) {
LS.rawget(db, LuaRegistry, "sourcedb");
int nupdates = sb->read_int32();
for (int i = 0; i < nupdates; i++) {
std::string fn = sb->read_string();
eng::string fn = sb->read_string();
int sequence = sb->read_int32();
std::string code = sb->read_string();
eng::string code = sb->read_string();
DebugLine(dbc) << "Source file " << fn << " updated";
if (sequence < 0) {
LS.rawset(db, fn, LuaNil);
@@ -239,7 +239,7 @@ bool SourceDB::patch(StreamBuffer *sb, DebugCollector *dbc) {
return (nupdates > 0);
}
void SourceDB::set(const std::string &fn, const std::string &code, int sequence) {
void SourceDB::set(const eng::string &fn, const eng::string &code, int sequence) {
lua_State *L = lua_state_;
LuaVar db, info;
LuaStack LS(L, db, info);
@@ -253,7 +253,7 @@ void SourceDB::set(const std::string &fn, const std::string &code, int sequence)
LS.result();
}
std::string SourceDB::get(const std::string &fn) {
eng::string SourceDB::get(const eng::string &fn) {
lua_State *L = lua_state_;
LuaVar db, info, code, sequence, loadresult;
LuaStack LS(L, db, info, code, sequence, loadresult);
@@ -266,15 +266,15 @@ std::string SourceDB::get(const std::string &fn) {
LS.rawget(code, info, "code");
LS.rawget(sequence, info, "sequence");
LS.rawget(loadresult, info, "loadresult");
std::string ccode = LS.ckstring(code);
eng::string ccode = LS.ckstring(code);
int seqno = LS.ckint(sequence);
std::string cloadresult;
eng::string cloadresult;
if (LS.isfunction(loadresult)) {
cloadresult = "<function>";
} else {
cloadresult = LS.ckstring(loadresult);
}
std::ostringstream oss;
eng::ostringstream oss;
oss << seqno << ":" << ccode << ":" << cloadresult;
LS.result();
return oss.str();
@@ -294,8 +294,8 @@ void SourceDB::update(const util::LuaSourceVec &source) {
LS.cleartable(sourcedb, true);
for (int i = 0; i < int(source.size()); i++) {
const std::string &file = source[i].first;
const std::string &code = source[i].second;
const eng::string &file = source[i].first;
const eng::string &code = source[i].second;
std::cerr << "Compiling " << file << std::endl;
LS.newtable(info);
LS.rawset(info, "name", file);
@@ -340,8 +340,8 @@ static void source_load_cfunctions(lua_State *L) {
auto regs = LuaFunctionReg::all();
for (const LuaFunctionReg *r : regs) {
lua_CFunction func = r->get_func();
std::string classname;
std::string funcname;
eng::string classname;
eng::string funcname;
get_reg_name(r, classname, funcname);
if (classname.empty()) {
LS.getglobaltable(classobj);
@@ -356,7 +356,7 @@ static void source_load_cfunctions(lua_State *L) {
// Run all the closures from the source database.
//
static std::string source_load_lfunctions(lua_State *L) {
static eng::string source_load_lfunctions(lua_State *L) {
LuaVar sourcedb, key, info, seq, closure, err;
LuaStack LS(L, sourcedb, key, info, seq, closure, err);
@@ -368,7 +368,7 @@ static std::string source_load_lfunctions(lua_State *L) {
}
// Sort the keys by sequence number.
std::map<int, std::string> indices;
eng::map<int, eng::string> indices;
LS.set(key, LuaNil);
while (LS.next(sourcedb, key, info) != 0) {
LS.rawget(seq, info, "sequence");
@@ -376,7 +376,7 @@ static std::string source_load_lfunctions(lua_State *L) {
}
// Now call the closures in the proper order.
std::ostringstream errss;
eng::ostringstream errss;
for (const auto &p : indices) {
LS.rawget(info, sourcedb, p.second);
LS.rawget(closure, info, "loadresult");
@@ -399,12 +399,12 @@ static std::string source_load_lfunctions(lua_State *L) {
}
std::string SourceDB::rebuild() {
eng::string SourceDB::rebuild() {
lua_State *L = lua_state_;
source_clear_globals(L);
// source_install_builtins(L);
source_load_cfunctions(L);
std::string errs = source_load_lfunctions(L);
eng::string errs = source_load_lfunctions(L);
return errs;
}
@@ -417,7 +417,7 @@ void SourceDB::run_unittests() {
LS.rawget(unittests, globtab, "unittests");
// Sort the unit test names.
std::set<std::string> names;
eng::set<eng::string> names;
LS.set(name, LuaNil);
while (LS.next(unittests, name, func) != 0) {
if (LS.isfunction(func) && LS.isstring(name)) {
@@ -427,7 +427,7 @@ void SourceDB::run_unittests() {
// Run the functions in order
bool any = false;
for (const std::string &name : names) {
for (const eng::string &name : names) {
std::cerr << "Running unittests." << name << std::endl;
LS.rawget(func, unittests, name);
@@ -464,7 +464,7 @@ void SourceDB::init(lua_State *L) {
LS.set(funcname, LuaNil);
while (LS.next(classtab, funcname, funcp) != 0) {
if (LS.isstring(funcname) && LS.iscfunction(funcp)) {
std::string full = "cfunc:";
eng::string full = "cfunc:";
full += LS.ckstring(classname);
full += ".";
full += LS.ckstring(funcname);
@@ -491,8 +491,8 @@ void SourceDB::deserialize_source(util::LuaSourceVec *sv, StreamBuffer *sb) {
int count = sb->read_int32();
if ((count < 0) || (count > 10000)) throw StreamCorruption();
for (int i = 0; i < count; i++) {
std::string fn = sb->read_string();
std::string code = sb->read_string();
eng::string fn = sb->read_string();
eng::string code = sb->read_string();
sv->emplace_back(fn, code);
}
}
@@ -506,8 +506,8 @@ void SourceDB::register_lua_builtins() {
auto regs = LuaFunctionReg::all();
for (LuaFunctionReg *reg : regs) {
if (reg->get_func() == nullptr) {
std::string funcname;
std::string classname;
eng::string funcname;
eng::string classname;
get_reg_name(reg, classname, funcname);
if (classname.empty()) {
LS.rawget(func, globals, funcname);
@@ -529,7 +529,7 @@ void SourceDB::register_lua_builtins() {
}
std::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) {
eng::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) {
lua_State *L = LS0.state();
LuaVar sourcedb, fname, finfo, code;
LuaStack LS(L, sourcedb, fname, finfo, code);
@@ -540,12 +540,12 @@ std::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) {
if (reg == nullptr) {
return "";
}
std::string classname;
std::string funcname;
eng::string classname;
eng::string funcname;
get_reg_name(reg, classname, funcname);
std::ostringstream oss;
eng::ostringstream oss;
util::StringVec docs = util::split_docstring(reg->get_docs());
for (const std::string &line : docs) {
for (const eng::string &line : docs) {
oss << "-- " << line << std::endl;
}
oss << "function ";
@@ -567,7 +567,7 @@ std::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) {
}
// Get the finfo table from the source db.
LS.set(fname, std::string(ar.short_src));
LS.set(fname, eng::string(ar.short_src));
LS.rawget(finfo, sourcedb, fname);
if (!LS.istable(finfo)) {
return "";
@@ -591,7 +591,7 @@ std::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) {
while ((linelo > 0) && (util::is_lua_comment(lines[linelo-1]))) linelo -= 1;
// Output the docs.
std::ostringstream result;
eng::ostringstream result;
for (int i = linelo; i <= linehi; i++) {
result << lines[i] << std::endl;
}