Changeset: a0881b6f1609 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a0881b6f1609
Modified Files:
monetdb5/mal/mal_linker.c
monetdb5/mal/mal_linker.h
monetdb5/mal/mal_parser.c
monetdb5/mal/mal_resolve.c
sql/backends/monet5/UDF/pyapi/pyapi.c
sql/backends/monet5/UDF/pyapi/pyloader.c
Branch: default
Log Message:
Nicer way of preventing the loading of a MAL module when it is disabled.
Now show a custom error message if a disabled module is used, and don't do
enable/disable checking in the module itself anymore.
diffs (208 lines):
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
@@ -407,3 +407,20 @@ MSP_locate_sqlscript(const char *filenam
/* no directory semantics (yet) */
return locate_file(filename, SQL_EXT, recurse);
}
+
+
+bool
+malLibraryEnabled(str name) {
+ if (strcmp(name, "pyapi") == 0) {
+ return GDKgetenv_istrue("embedded_py") ||
GDKgetenv_isyes("embedded_py");
+ }
+ return true;
+}
+
+char*
+malLibraryHowToEnable(str name) {
+ if (strcmp(name, "pyapi") == 0) {
+ return "Embedded Python has not been enabled. Start server with
--set embedded_py=true";
+ }
+ return "";
+}
diff --git a/monetdb5/mal/mal_linker.h b/monetdb5/mal/mal_linker.h
--- a/monetdb5/mal/mal_linker.h
+++ b/monetdb5/mal/mal_linker.h
@@ -27,4 +27,6 @@ mal_export MALfcn getAddress(stream *out
mal_export char *MSP_locate_sqlscript(const char *mod_name, bit recurse);
mal_export str loadLibrary(str modulename, int flag);
mal_export char *locate_file(const char *basename, const char *ext, bit
recurse);
+mal_export bool malLibraryEnabled(str name);
+mal_export char* malLibraryHowToEnable(str name);
#endif /* _MAL_LINKER_H */
diff --git a/monetdb5/mal/mal_parser.c b/monetdb5/mal/mal_parser.c
--- a/monetdb5/mal/mal_parser.c
+++ b/monetdb5/mal/mal_parser.c
@@ -949,15 +949,6 @@ static str parseModule(Client cntxt)
return "";
}
-
-static int
-malLibraryEnabled(str name) {
- if (strcmp(name, "pyapi") == 0) {
- return GDKgetenv_istrue("embedded_py") ||
GDKgetenv_isyes("embedded_py");
- }
- return 1;
-}
-
/*
* Include statement
* An include statement is immediately taken into effect. This
diff --git a/monetdb5/mal/mal_resolve.c b/monetdb5/mal/mal_resolve.c
--- a/monetdb5/mal/mal_resolve.c
+++ b/monetdb5/mal/mal_resolve.c
@@ -19,6 +19,7 @@
#include "mal_resolve.h"
#include "mal_namespace.h"
#include "mal_private.h"
+#include "mal_linker.h"
static malType getPolyType(malType t, int *polytype);
static int updateTypeMap(int formal, int actual, int polytype[MAXTYPEVAR]);
@@ -626,15 +627,19 @@ typeChecker(stream *out, Module scope, M
if (!isaSignature(p) && !getInstrPtr(mb, 0)->polymorphic) {
mb->errors++;
if (!silent) {
- char *errsig;
+ if (!malLibraryEnabled(p->modname)) {
+ dumpExceptionsToStream(out,
malLibraryHowToEnable(p->modname));
+ } else {
+ char *errsig;
- errsig = instruction2str(mb,0,p,(LIST_MAL_NAME
| LIST_MAL_TYPE | LIST_MAL_VALUE));
- showScriptException(out, mb, getPC(mb, p), TYPE,
-
"'%s%s%s' undefined in: %s",
-
(getModuleId(p) ? getModuleId(p) : ""),
-
(getModuleId(p) ? "." : ""),
-
getFunctionId(p), errsig?errsig:"failed instruction2str()");
- GDKfree(errsig);
+ errsig =
instruction2str(mb,0,p,(LIST_MAL_NAME | LIST_MAL_TYPE | LIST_MAL_VALUE));
+ showScriptException(out, mb, getPC(mb,
p), TYPE,
+
"'%s%s%s' undefined in: %s",
+
(getModuleId(p) ? getModuleId(p) : ""),
+
(getModuleId(p) ? "." : ""),
+
getFunctionId(p), errsig?errsig:"failed instruction2str()");
+ GDKfree(errsig);
+ }
} else
mb->errors = olderrors;
p->typechk = TYPE_UNKNOWN;
diff --git a/sql/backends/monet5/UDF/pyapi/pyapi.c
b/sql/backends/monet5/UDF/pyapi/pyapi.c
--- a/sql/backends/monet5/UDF/pyapi/pyapi.c
+++ b/sql/backends/monet5/UDF/pyapi/pyapi.c
@@ -183,12 +183,6 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
(void) mapped;
#endif
- if (!PyAPIEnabled()) {
- throw(MAL, "pyapi.eval",
- "Embedded Python has not been enabled. Start server with --set
%s=true",
- pyapi_enableflag);
- }
-
if (!pyapiInitialized) {
throw(MAL, "pyapi.eval",
"Embedded Python is enabled but an error was thrown during
initialization.");
@@ -1250,48 +1244,46 @@ wrapup:
}
str
- PyAPIprelude(void *ret) {
+PyAPIprelude(void *ret) {
(void) ret;
MT_lock_init(&pyapiLock, "pyapi_lock");
MT_lock_init(&queryLock, "query_lock");
- if (PyAPIEnabled()) {
- MT_lock_set(&pyapiLock);
- if (!pyapiInitialized) {
- str msg = MAL_SUCCEED;
- Py_Initialize();
- if (PyRun_SimpleString("import numpy") != 0 || _import_array() <
0) {
- return PyError_CreateException("Failed to initialize embedded
python", NULL);
- }
- msg = _connection_init();
- if (msg != MAL_SUCCEED) {
- MT_lock_unset(&pyapiLock);
- return msg;
- }
- msg = _conversion_init();
- if (msg != MAL_SUCCEED) {
- MT_lock_unset(&pyapiLock);
- return msg;
- }
- _pytypes_init();
- _loader_init();
- marshal_module = PyImport_Import(PyString_FromString("marshal"));
- if (marshal_module == NULL) {
- return createException(MAL, "pyapi.eval", "Failed to load
Marshal module.");
- }
- marshal_loads = PyObject_GetAttrString(marshal_module, "loads");
- if (marshal_loads == NULL) {
- return createException(MAL, "pyapi.eval", "Failed to load
function \"loads\" from Marshal module.");
- }
- PyEval_SaveThread();
- if (msg != MAL_SUCCEED) {
- MT_lock_unset(&pyapiLock);
- return msg;
- }
- pyapiInitialized++;
+ MT_lock_set(&pyapiLock);
+ if (!pyapiInitialized) {
+ str msg = MAL_SUCCEED;
+ Py_Initialize();
+ if (PyRun_SimpleString("import numpy") != 0 || _import_array() < 0) {
+ return PyError_CreateException("Failed to initialize embedded
python", NULL);
}
- MT_lock_unset(&pyapiLock);
- fprintf(stdout, "# MonetDB/Python module loaded\n");
+ msg = _connection_init();
+ if (msg != MAL_SUCCEED) {
+ MT_lock_unset(&pyapiLock);
+ return msg;
+ }
+ msg = _conversion_init();
+ if (msg != MAL_SUCCEED) {
+ MT_lock_unset(&pyapiLock);
+ return msg;
+ }
+ _pytypes_init();
+ _loader_init();
+ marshal_module = PyImport_Import(PyString_FromString("marshal"));
+ if (marshal_module == NULL) {
+ return createException(MAL, "pyapi.eval", "Failed to load Marshal
module.");
+ }
+ marshal_loads = PyObject_GetAttrString(marshal_module, "loads");
+ if (marshal_loads == NULL) {
+ return createException(MAL, "pyapi.eval", "Failed to load function
\"loads\" from Marshal module.");
+ }
+ PyEval_SaveThread();
+ if (msg != MAL_SUCCEED) {
+ MT_lock_unset(&pyapiLock);
+ return msg;
+ }
+ pyapiInitialized++;
}
+ MT_lock_unset(&pyapiLock);
+ fprintf(stdout, "# MonetDB/Python module loaded\n");
option_disable_fork = GDKgetenv_istrue(fork_disableflag) ||
GDKgetenv_isyes(fork_disableflag);
return MAL_SUCCEED;
}
diff --git a/sql/backends/monet5/UDF/pyapi/pyloader.c
b/sql/backends/monet5/UDF/pyapi/pyloader.c
--- a/sql/backends/monet5/UDF/pyapi/pyloader.c
+++ b/sql/backends/monet5/UDF/pyapi/pyloader.c
@@ -58,12 +58,6 @@ str PyAPIevalLoader(Client cntxt, MalBlk
char * loader_additional_args[] = {"_emit", "_conn"};
- if (!PyAPIEnabled()) {
- throw(MAL, "pyapi.eval",
- "Embedded Python has not been enabled. Start server with --set
%s=true",
- pyapi_enableflag);
- }
-
if (!PyAPIInitialized()) {
throw(MAL, "pyapi.eval",
"Embedded Python is enabled but an error was thrown during
initialization.");
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list