Changeset: e105f1cca034 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e105f1cca034
Modified Files:
monetdb5/mal/mal_linker.c
sql/backends/monet5/UDF/pyapi/pyapi.c
sql/backends/monet5/UDF/pyapi/pyapi.h
sql/backends/monet5/UDF/pyapi/pyloader.c
Branch: python3udf
Log Message:
Change the way Python 2/3 UDFs are enabled. They are now enabled with --set
embedded_py=[2/3].
diffs (191 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
@@ -412,7 +412,17 @@ MSP_locate_sqlscript(const char *filenam
int
malLibraryEnabled(str name) {
if (strcmp(name, "pyapi") == 0) {
- return GDKgetenv_istrue("embedded_py") ||
GDKgetenv_isyes("embedded_py");
+ char *val = GDKgetenv("embedded_py");
+ if (val && (strcasecmp(val, "2") == 0 ||
GDKgetenv_istrue("embedded_py") || GDKgetenv_istrue("embedded_py"))) {
+ return true;
+ }
+ return false;
+ } else if (strcmp(name, "pyapi3") == 0) {
+ char *val = GDKgetenv("embedded_py");
+ if (val && strcasecmp(val, "3") == 0) {
+ return true;
+ }
+ return false;
}
return true;
}
@@ -420,7 +430,10 @@ malLibraryEnabled(str name) {
char*
malLibraryHowToEnable(str name) {
if (strcmp(name, "pyapi") == 0) {
- return "Embedded Python has not been enabled. Start server with
--set embedded_py=true";
+ return "Embedded Python 2 has not been enabled. Start server
with --set embedded_py=2";
+ }
+ if (strcmp(name, "pyapi3") == 0) {
+ return "Embedded Python 3 has not been enabled. Start server
with --set embedded_py=3";
}
return "";
}
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
@@ -29,17 +29,6 @@ static bool option_disable_fork = false;
static PyObject *marshal_module = NULL;
PyObject *marshal_loads = NULL;
-int PYFUNCNAME(PyAPIEnabled)(void) {
- char* env = GDKgetenv(pyapi_enableflag);
-#ifndef IS_PY3K
- return (GDKgetenv_istrue(pyapi_enableflag)
- || GDKgetenv_isyes(pyapi_enableflag) ||
- (env && strncmp(env, "2", 1) == 0));
-#else
- return (env && strncmp(env, "3", 1) == 0);
-#endif
-}
-
typedef struct _AggrParams{
PyInput **pyinput_values;
void ****split_bats;
@@ -190,12 +179,6 @@ static str PyAPIeval(Client cntxt, MalBl
(void) mapped;
#endif
- if (!PYFUNCNAME(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.");
@@ -1265,54 +1248,50 @@ PYFUNCNAME(PyAPIprelude)(void *ret) {
(void) ret;
MT_lock_init(&pyapiLock, "pyapi_lock");
MT_lock_init(&queryLock, "query_lock");
- if (PYFUNCNAME(PyAPIEnabled)()) {
- MT_lock_set(&pyapiLock);
- if (!pyapiInitialized) {
- str msg = MAL_SUCCEED;
- Py_Initialize();
- _import_array();
- 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.");
- }
- if (PyRun_SimpleString("import numpy") != 0) {
- return PyError_CreateException("Failed to initialize embedded
python", NULL);
- }
- 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();
+ _import_array();
+ msg = _connection_init();
+ if (msg != MAL_SUCCEED) {
+ MT_lock_unset(&pyapiLock);
+ return msg;
}
- MT_lock_unset(&pyapiLock);
+ 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.");
+ }
+ if (PyRun_SimpleString("import numpy") != 0) {
+ return PyError_CreateException("Failed to initialize embedded
python", NULL);
+ }
+ PyEval_SaveThread();
+ if (msg != MAL_SUCCEED) {
+ MT_lock_unset(&pyapiLock);
+ return msg;
+ }
+ pyapiInitialized++;
fprintf(stdout, "# MonetDB/Python%d module loaded\n",
#ifdef IS_PY3K
3
#else
2
#endif
-
- );
+ );
}
MT_lock_unset(&pyapiLock);
- fprintf(stdout, "# MonetDB/Python module loaded\n");
+ MT_lock_unset(&pyapiLock);
option_disable_fork = GDKgetenv_istrue(fork_disableflag) ||
GDKgetenv_isyes(fork_disableflag);
return MAL_SUCCEED;
}
diff --git a/sql/backends/monet5/UDF/pyapi/pyapi.h
b/sql/backends/monet5/UDF/pyapi/pyapi.h
--- a/sql/backends/monet5/UDF/pyapi/pyapi.h
+++ b/sql/backends/monet5/UDF/pyapi/pyapi.h
@@ -24,13 +24,10 @@ pyapi_export str PYFUNCNAME(PyAPIevalLoa
pyapi_export str PYFUNCNAME(PyAPIprelude)(void *ret);
-int PYFUNCNAME(PyAPIEnabled)(void);
int PYFUNCNAME(PyAPIInitialized)(void);
str _loader_init(void);
pyapi_export char *PyError_CreateException(char *error_text, char *pycall);
-#define pyapi_enableflag "embedded_py"
-
#endif /* _PYPI_LIB_ */
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
@@ -60,12 +60,6 @@ PYFUNCNAME(PyAPIevalLoader)(Client cntxt
char * loader_additional_args[] = {"_emit", "_conn"};
- if (!PYFUNCNAME(PyAPIEnabled())) {
- throw(MAL, "pyapi.eval",
- "Embedded Python has not been enabled. Start server with --set
%s=true",
- pyapi_enableflag);
- }
-
if (!PYFUNCNAME(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