Changeset: cc4d17ef7920 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/cc4d17ef7920
Modified Files:
clients/Tests/exports.stable.out
monetdb5/extras/rapi/rapi.c
monetdb5/mal/mal_authorize.c
monetdb5/mal/mal_authorize.h
monetdb5/mal/mal_exception.c
monetdb5/mal/mal_import.c
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_linker.c
monetdb5/mal/mal_linker.h
monetdb5/mal/mal_private.h
monetdb5/mal/mal_utils.c
monetdb5/mal/mal_utils.h
sql/backends/monet5/sql_scenario.c
sql/backends/monet5/sql_user.c
Branch: Dec2025
Log Message:
Use allocator; remove MAL include of directories.
diffs (truncated from 677 to 300 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -769,8 +769,8 @@ size_t msettings_write_url(const msettin
const char *wsaerror(int);
# monetdb5
-str AUTHGeneratePasswordHash(str *res, const char *value);
-str AUTHcypherValue(str *ret, const char *value);
+str AUTHGeneratePasswordHash(allocator *, str *res, const char *value);
+str AUTHcypherValue(allocator *, str *ret, const char *value);
str AUTHdecypherValue(allocator *, str *ret, const char *value);
str AUTHrequireAdmin(Client c);
str AUTHunlockVault(const char *password);
@@ -800,7 +800,7 @@ void MCsetClientInfo(Client c, const cha
void MCstopClients(Client c);
str MCsuspendClient(int id);
int MCvalid(Client c);
-char *MSP_locate_sqlscript(const char *mod_name, bit recurse);
+char *MSP_locate_sqlscript(allocator *ma, const char *mod_name);
str MSinitClientPrg(Client cntxt, const char *mod, const char *nme);
void MSresetInstructions(MalBlkPtr mb, int start);
void MSresetStack(Client cntxt, MalBlkPtr mb, MalStkPtr glb);
@@ -1056,7 +1056,7 @@ const char likeselectRef[];
const char likeuselectRef[];
const char lngRef[];
str loadLibrary(const char *modulename, int flag);
-char *locate_file(const char *basename, const char *ext, bit recurse);
+char *locate_file(allocator *ma, const char *basename, const char *ext);
const char lockRef[];
const char lookupRef[];
const char mainRef[];
diff --git a/monetdb5/extras/rapi/rapi.c b/monetdb5/extras/rapi/rapi.c
--- a/monetdb5/extras/rapi/rapi.c
+++ b/monetdb5/extras/rapi/rapi.c
@@ -520,9 +520,11 @@ static char *RAPIinstalladdons(void) {
// run rapi.R environment setup script
{
- char *f = locate_file("rapi", ".R", 0);
+ allocator *ta = MT_thread_getallocator();
+ allocator_state ta_state = ma_open(ta);
+ char *f = locate_file(ta, "rapi", ".R");
snprintf(rapiinclude, sizeof(rapiinclude), "source(\"%s\")", f);
- GDKfree(f);
+ ma_close(ta, &ta_state);
}
#if DIR_SEP != '/'
{
diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c
--- a/monetdb5/mal/mal_authorize.c
+++ b/monetdb5/mal/mal_authorize.c
@@ -168,10 +168,10 @@ AUTHdecypherValue(allocator *ma, str *re
/**
* Cyphers the given string using the vaultKey. If the cypher algorithm
* fails or detects an invalid password, it might throw an exception.
- * The ret string is GDKmalloced, and should be GDKfreed by the caller.
+ * The ret string is allocated using the passed allocator.
*/
static str
-AUTHcypherValueLocked(str *ret, const char *value)
+AUTHcypherValueLocked(allocator *ma, str *ret, const char *value)
{
/* this is the XOR cypher implementation */
str r, w;
@@ -182,7 +182,7 @@ AUTHcypherValueLocked(str *ret, const ch
if (vaultKey == NULL)
throw(MAL, "cypherValue", "The vault is still locked!");
- w = r = GDKmalloc(sizeof(char) * (strlen(value) * 2 + 1));
+ w = r = ma_alloc(ma, sizeof(char) * (strlen(value) * 2 + 1));
if (r == NULL)
throw(MAL, "cypherValue", SQLSTATE(HY013) MAL_MALLOC_FAIL);
@@ -213,10 +213,10 @@ AUTHcypherValueLocked(str *ret, const ch
}
str
-AUTHcypherValue(str *ret, const char *value)
+AUTHcypherValue(allocator *ma, str *ret, const char *value)
{
MT_rwlock_rdlock(&rt_lock);
- str err = AUTHcypherValueLocked(ret, value);
+ str err = AUTHcypherValueLocked(ma, ret, value);
MT_rwlock_rdunlock(&rt_lock);
return err;
}
@@ -253,7 +253,7 @@ AUTHverifyPassword(const char *passwd)
}
str
-AUTHGeneratePasswordHash(str *res, const char *value)
+AUTHGeneratePasswordHash(allocator *ma, str *res, const char *value)
{
- return AUTHcypherValue(res, value);
+ return AUTHcypherValue(ma, res, value);
}
diff --git a/monetdb5/mal/mal_authorize.h b/monetdb5/mal/mal_authorize.h
--- a/monetdb5/mal/mal_authorize.h
+++ b/monetdb5/mal/mal_authorize.h
@@ -23,8 +23,8 @@
mal_export str AUTHunlockVault(const char *password);
mal_export str AUTHverifyPassword(const char *passwd);
mal_export str AUTHdecypherValue(allocator *, str *ret, const char *value);
-mal_export str AUTHcypherValue(str *ret, const char *value);
+mal_export str AUTHcypherValue(allocator *, str *ret, const char *value);
mal_export str AUTHrequireAdmin(Client c);
-mal_export str AUTHGeneratePasswordHash(str *res, const char *value);
+mal_export str AUTHGeneratePasswordHash(allocator *, str *res, const char
*value);
#endif /* _MAL_AUTHORIZE_H */
diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c
--- a/monetdb5/mal/mal_exception.c
+++ b/monetdb5/mal/mal_exception.c
@@ -319,8 +319,7 @@ getExceptionType(const char *exception)
/**
* Returns the location the exception was raised, if known. It
* depends on how the exception was created, what the location looks
- * like. The returned string is mallocced with GDKmalloc, and hence
- * needs to be GDKfreed.
+ * like. The returned string is allocated using the passed allocator.
*/
str
getExceptionPlace(allocator *ma, const char *exception)
diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c
--- a/monetdb5/mal/mal_import.c
+++ b/monetdb5/mal/mal_import.c
@@ -51,7 +51,7 @@ slash_2_dir_sep(str fname)
}
static str
-malResolveFile(const char *fname)
+malResolveFile(allocator *ma, const char *fname)
{
char path[FILENAME_MAX];
str script;
@@ -61,7 +61,7 @@ malResolveFile(const char *fname)
if (written == -1 || written >= FILENAME_MAX)
return NULL;
slash_2_dir_sep(path);
- if ((script = MSP_locate_script(path)) == NULL) {
+ if ((script = MSP_locate_script(ma, path)) == NULL) {
/* this function is also called for scripts that are not located
* in the modpath, so if we can't find it, just default to
* whatever was given, as it can be in current dir, or an
@@ -178,11 +178,15 @@ malIncludeString(Client c, const char *n
size_t mal_len = strlen(mal);
buffer *mal_buf;
stream *mal_stream;
+ allocator *ta = MT_thread_getallocator();
+ allocator_state ta_state = ma_open(ta);
- if ((mal_buf = GDKmalloc(sizeof(buffer))) == NULL)
+ if ((mal_buf = ma_alloc(ta, sizeof(buffer))) == NULL) {
+ ma_close(ta, &ta_state);
throw(MAL, "malIncludeString", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ }
if ((mal_stream = buffer_rastream(mal_buf, name)) == NULL) {
- GDKfree(mal_buf);
+ ma_close(ta, &ta_state);
throw(MAL, "malIncludeString", SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
buffer_init(mal_buf, mal, mal_len);
@@ -191,7 +195,7 @@ malIncludeString(Client c, const char *n
c->bak = NULL;
if ((c->fdin = bstream_create(mal_stream, mal_len)) == NULL) {
mnstr_destroy(mal_stream);
- GDKfree(mal_buf);
+ ma_close(ta, &ta_state);
throw(MAL, "malIncludeString", SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
c->qryctx.bs = c->fdin;
@@ -200,7 +204,7 @@ malIncludeString(Client c, const char *n
bstream_destroy(c->fdin);
c->fdin = NULL;
c->qryctx.bs = NULL;
- GDKfree(mal_buf);
+ ma_close(ta, &ta_state);
restoreClient;
return msg;
@@ -230,6 +234,8 @@ malInclude(Client c, const char *name, i
Module oldusermodule = c->usermodule;
Module oldcurmodule = c->curmodule;
Symbol oldprg = c->curprg;
+ allocator *ta = MT_thread_getallocator();
+ allocator_state ta_state = ma_open(ta);
c->prompt = ""; /* do not produce visible
prompts */
c->promptlength = 0;
@@ -237,7 +243,7 @@ malInclude(Client c, const char *name, i
c->fdin = NULL;
c->qryctx.bs = NULL;
- if ((filename = malResolveFile(name)) != NULL) {
+ if ((filename = malResolveFile(ta, name)) != NULL) {
char *fname = filename;
do {
p = strchr(filename, PATH_SEP);
@@ -257,10 +263,12 @@ malInclude(Client c, const char *name, i
if (p)
filename = p + 1;
} while (p);
+ c->srcFile = NULL;
GDKfree(fname);
c->fdin = NULL;
c->qryctx.bs = NULL;
}
+ ma_close(ta, &ta_state);
restoreClient;
return msg;
}
diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -1253,24 +1253,7 @@ runMALsequence(Client cntxt, MalBlkPtr m
snprintf(nme, sizeof(nme), "%s.%s[%d]",
getModuleId(getInstrPtr(mb, 0)),
getFunctionId(getInstrPtr(mb, 0)), stkpc);
if (ret != MAL_SUCCEED) {
- str new, n;
- n = createException(MAL, nme, "exception not caught");
- if (n) {
- new = GDKmalloc(strlen(ret) + strlen(n) + 16);
- if (new) {
- char *p = stpcpy(new, ret);
- if (p[-1] != '\n')
- *p++ = '\n';
- *p++ = '!';
- p = stpcpy(p, n);
- freeException(n);
- freeException(ret);
- ret = new;
- } else {
- freeException(ret);
- ret = n;
- }
- }
+ ret = appendException(MAL, nme, "exception not caught");
} else {
ret = createException(MAL, nme, "Exception not caught");
}
diff --git a/monetdb5/mal/mal_linker.c b/monetdb5/mal/mal_linker.c
--- a/monetdb5/mal/mal_linker.c
+++ b/monetdb5/mal/mal_linker.c
@@ -389,27 +389,12 @@ mal_linker_reset(void)
* The plausible locations of the modules can be designated by
* an environment variable.
*/
-static int
-cmpstr(const void *_p1, const void *_p2)
-{
- const char *p1 = *(char *const *) _p1;
- const char *p2 = *(char *const *) _p2;
- const char *f1 = strrchr(p1, (int) DIR_SEP);
- const char *f2 = strrchr(p2, (int) DIR_SEP);
- return strcmp(f1 ? f1 : p1, f2 ? f2 : p2);
-}
-
-
-#define MAXMULTISCRIPT 48
char *
-locate_file(const char *basename, const char *ext, bit recurse)
+locate_file(allocator *ma, const char *basename, const char *ext)
{
const char *mod_path = GDKgetenv("monet_mod_path");
char *fullname;
- size_t fullnamelen;
size_t filelen = strlen(basename) + strlen(ext);
- str strs[MAXMULTISCRIPT]; /* hardwired limit */
- int lasts = 0;
if (mod_path == NULL)
return NULL;
@@ -418,131 +403,52 @@ locate_file(const char *basename, const
mod_path++;
if (*mod_path == 0)
return NULL;
- fullnamelen = 512;
- fullname = GDKmalloc(fullnamelen);
+ fullname = ma_alloc(ma, PATH_MAX);
if (fullname == NULL)
return NULL;
while (*mod_path) {
size_t i;
const char *p;
int fd;
- DIR *rdir;
if ((p = strchr(mod_path, PATH_SEP)) != NULL) {
i = p - mod_path;
} else {
i = strlen(mod_path);
}
- while (i + filelen + 2 > fullnamelen) {
- char *tmp;
- fullnamelen += 512;
- tmp = GDKrealloc(fullname, fullnamelen);
- if (tmp == NULL) {
- GDKfree(fullname);
- return NULL;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]