Changeset: c1de96124f28 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/c1de96124f28 Modified Files: monetdb5/mal/mal_module.c monetdb5/mal/mal_module.h monetdb5/modules/mal/manual.c monetdb5/optimizer/opt_macro.c Branch: default Log Message:
Allocate Space together with Module. They're always both allocated, and always of the same size, so might as well do it in one go. diffs (212 lines): diff --git a/monetdb5/mal/mal_module.c b/monetdb5/mal/mal_module.c --- a/monetdb5/mal/mal_module.c +++ b/monetdb5/mal/mal_module.c @@ -39,7 +39,7 @@ MALfcn findFunctionImplementation(const char *cname) { for (int i = 0; i < MODULE_HASH_SIZE; i++) { - if (moduleIndex[i] != NULL && moduleIndex[i]->space != NULL) { + if (moduleIndex[i] != NULL) { for (int j = 0; j < MAXSCOPE; j++) { Symbol s; if ((s = moduleIndex[i]->space[j]) != NULL) { @@ -221,11 +221,6 @@ globalModule(const char *nme) return NULL; cur->name = nme; cur->link = NULL; - cur->space = (Symbol *) GDKzalloc(MAXSCOPE * sizeof(Symbol)); - if (cur->space == NULL) { - GDKfree(cur); - return NULL; - } addModuleToIndex(cur); return cur; } @@ -242,12 +237,6 @@ userModule(void) return NULL; cur->name = putName("user"); cur->link = NULL; - cur->space = NULL; - cur->space = (Symbol *) GDKzalloc(MAXSCOPE * sizeof(Symbol)); - if (cur->space == NULL) { - GDKfree(cur); - return NULL; - } return cur; } @@ -276,8 +265,6 @@ freeSubScope(Module scope) int i; Symbol s; - if (scope->space == NULL) - return; for (i = 0; i < MAXSCOPE; i++) { if (scope->space[i]) { s = scope->space[i]; @@ -285,8 +272,6 @@ freeSubScope(Module scope) freeSymbolList(s); } } - GDKfree(scope->space); - scope->space = 0; } void @@ -340,12 +325,6 @@ insertSymbol(Module scope, Symbol prg) scope = c; } t = getSymbolIndex(getFunctionId(sig)); - if (scope->space == NULL) { - scope->space = (Symbol *) GDKzalloc(MAXSCOPE * sizeof(Symbol)); - if (scope->space == NULL) - return; - } - assert(scope->space); if (scope->space[t] == prg) { /* already known, last inserted */ } else { diff --git a/monetdb5/mal/mal_module.h b/monetdb5/mal/mal_module.h --- a/monetdb5/mal/mal_module.h +++ b/monetdb5/mal/mal_module.h @@ -12,16 +12,15 @@ #define _MAL_SCOPE_H_ #include "mal.h" -/* #define MAL_SCOPE_DEBUG */ #define MAXSCOPE 256 typedef struct SCOPEDEF { struct SCOPEDEF *link; /* module with same index value */ const char *name; /* index in namespace */ - Symbol *space; /* type dispatcher table */ int isAtomModule; /* atom module definition ? */ str help; /* short description of module functionality */ + Symbol space[MAXSCOPE]; /* type dispatcher table */ } *Module, ModuleRecord; mal_export Module userModule(void); diff --git a/monetdb5/modules/mal/manual.c b/monetdb5/modules/mal/manual.c --- a/monetdb5/modules/mal/manual.c +++ b/monetdb5/modules/mal/manual.c @@ -31,13 +31,10 @@ MANUALcreateOverview(Client cntxt, MalBl bat *sx = getArgReference_bat(stk, pci, 2); bat *ax = getArgReference_bat(stk, pci, 3); bat *cx = getArgReference_bat(stk, pci, 4); - Module s; Module *moduleList; int length; - int j, k, top = 0; - Symbol t; + int top = 0; Module list[256]; - char buf[BUFSIZ], *tt; mod = COLnew(0, TYPE_str, 0, TRANSIENT); fcn = COLnew(0, TYPE_str, 0, TRANSIENT); @@ -63,31 +60,30 @@ MANUALcreateOverview(Client cntxt, MalBl } freeModuleList(moduleList); - for (k = 0; k < top; k++) { - s = list[k]; - if (s->space) { - for (j = 0; j < MAXSCOPE; j++) { - if (s->space[j]) { - for (t = s->space[j]; t != NULL; t = t->peer) { - if (t->def->stmt[0]->fcnname[0] == '#') - continue; - (void) fcnDefinition(t->def, getInstrPtr(t->def, 0), - buf, TRUE, buf, sizeof(buf)); - tt = strstr(buf, "address "); - if (tt) { - *tt = 0; - tt += 8; - } - if (BUNappend(mod, t->def->stmt[0]->modname, false) != GDK_SUCCEED - || BUNappend(fcn, t->def->stmt[0]->fcnname, - false) != GDK_SUCCEED - || BUNappend(com, t->def->help ? t->def->help : "", - false) != GDK_SUCCEED - || BUNappend(sig, buf, false) != GDK_SUCCEED - || BUNappend(adr, tt ? tt : "", - false) != GDK_SUCCEED) { - goto bailout; - } + for (int k = 0; k < top; k++) { + Module s = list[k]; + for (int j = 0; j < MAXSCOPE; j++) { + if (s->space[j]) { + for (Symbol t = s->space[j]; t != NULL; t = t->peer) { + if (t->def->stmt[0]->fcnname[0] == '#') + continue; + char buf[1024]; + (void) fcnDefinition(t->def, getInstrPtr(t->def, 0), + buf, TRUE, buf, sizeof(buf)); + char *tt = strstr(buf, "address "); + if (tt) { + *tt = 0; + tt += 8; + } + if (BUNappend(mod, t->def->stmt[0]->modname, false) != GDK_SUCCEED + || BUNappend(fcn, t->def->stmt[0]->fcnname, + false) != GDK_SUCCEED + || BUNappend(com, t->def->help ? t->def->help : "", + false) != GDK_SUCCEED + || BUNappend(sig, buf, false) != GDK_SUCCEED + || BUNappend(adr, tt ? tt : "", + false) != GDK_SUCCEED) { + goto bailout; } } } diff --git a/monetdb5/optimizer/opt_macro.c b/monetdb5/optimizer/opt_macro.c --- a/monetdb5/optimizer/opt_macro.c +++ b/monetdb5/optimizer/opt_macro.c @@ -424,15 +424,13 @@ OPTmacroImplementation(Client cntxt, Mal s = findModule(cntxt->usermodule, putName(mod)); if (s == 0) return 0; - if (s->space) { - j = getSymbolIndex(fcn); - for (t = s->space[j]; t != NULL; t = t->peer) - if (t->def->errors == 0) { - if (getSignature(t)->token == FUNCTIONsymbol) { - actions += MACROprocessor(cntxt, target, t); - } + j = getSymbolIndex(fcn); + for (t = s->space[j]; t != NULL; t = t->peer) + if (t->def->errors == 0) { + if (getSignature(t)->token == FUNCTIONsymbol) { + actions += MACROprocessor(cntxt, target, t); } - } + } return actions; } @@ -472,16 +470,14 @@ OPTorcamImplementation(Client cntxt, Mal s = findModule(cntxt->usermodule, putName(mod)); if (s == 0) return 0; - if (s->space) { - j = getSymbolIndex(fcn); - for (t = s->space[j]; t != NULL; t = t->peer) - if (t->def->errors == 0) { - if (getSignature(t)->token == FUNCTIONsymbol) { - freeException(msg); - msg = ORCAMprocessor(cntxt, target, t, actions); - } + j = getSymbolIndex(fcn); + for (t = s->space[j]; t != NULL; t = t->peer) + if (t->def->errors == 0) { + if (getSignature(t)->token == FUNCTIONsymbol) { + freeException(msg); + msg = ORCAMprocessor(cntxt, target, t, actions); } - } + } return msg; } _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org