You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pylucene-commits@lucene.apache.org by va...@apache.org on 2020/11/28 03:17:36 UTC
svn commit: r1883885 - in /lucene/pylucene/trunk/jcc: CHANGES
jcc2/sources/JCCEnv.cpp jcc2/sources/JCCEnv.h jcc2/sources/jcc.cpp
jcc3/sources/JCCEnv.cpp jcc3/sources/JCCEnv.h jcc3/sources/jcc.cpp
Author: vajda
Date: Sat Nov 28 03:17:36 2020
New Revision: 1883885
URL: http://svn.apache.org/viewvc?rev=1883885&view=rev
Log:
fixed crash when failing to update classpath of running VM
Modified:
lucene/pylucene/trunk/jcc/CHANGES
lucene/pylucene/trunk/jcc/jcc2/sources/JCCEnv.cpp
lucene/pylucene/trunk/jcc/jcc2/sources/JCCEnv.h
lucene/pylucene/trunk/jcc/jcc2/sources/jcc.cpp
lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp
lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h
lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp
Modified: lucene/pylucene/trunk/jcc/CHANGES
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/CHANGES?rev=1883885&r1=1883884&r2=1883885&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/CHANGES (original)
+++ lucene/pylucene/trunk/jcc/CHANGES Sat Nov 28 03:17:36 2020
@@ -1,6 +1,7 @@
Version 3.8 ->
--------------
- fixed bug with --import support using python2's os.path.walk() from python3
+ - fixed crash when failing to update classpath of running VM
-
Version 3.7 -> 3.8
Modified: lucene/pylucene/trunk/jcc/jcc2/sources/JCCEnv.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc2/sources/JCCEnv.cpp?rev=1883885&r1=1883884&r2=1883885&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc2/sources/JCCEnv.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc2/sources/JCCEnv.cpp Sat Nov 28 03:17:36 2020
@@ -853,7 +853,7 @@ DEFINE_SET_FIELD(jint, Int)
DEFINE_SET_FIELD(jlong, Long)
DEFINE_SET_FIELD(jshort, Short)
-void JCCEnv::setClassPath(const char *classPath)
+bool JCCEnv::setClassPath(const char *classPath)
{
JNIEnv *vm_env = get_vm_env();
jclass _ucl = (jclass) vm_env->FindClass("java/net/URLClassLoader");
@@ -861,6 +861,10 @@ void JCCEnv::setClassPath(const char *cl
jmethodID mid = vm_env->GetStaticMethodID(_ucl, "getSystemClassLoader",
"()Ljava/lang/ClassLoader;");
jobject classLoader = vm_env->CallStaticObjectMethod(_ucl, mid);
+
+ if (!vm_env->IsInstanceOf(classLoader, _ucl))
+ return false;
+
jmethodID mf = vm_env->GetMethodID(_fil, "<init>", "(Ljava/lang/String;)V");
jmethodID mu = vm_env->GetMethodID(_fil, "toURL", "()Ljava/net/URL;");
jmethodID ma = vm_env->GetMethodID(_ucl, "addURL", "(Ljava/net/URL;)V");
@@ -882,6 +886,8 @@ void JCCEnv::setClassPath(const char *cl
vm_env->CallVoidMethod(classLoader, ma, url);
}
free(path);
+
+ return true;
}
char *JCCEnv::getClassPath()
Modified: lucene/pylucene/trunk/jcc/jcc2/sources/JCCEnv.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc2/sources/JCCEnv.h?rev=1883885&r1=1883884&r2=1883885&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc2/sources/JCCEnv.h (original)
+++ lucene/pylucene/trunk/jcc/jcc2/sources/JCCEnv.h Sat Nov 28 03:17:36 2020
@@ -276,7 +276,7 @@ public:
: 0;
}
- void setClassPath(const char *classPath);
+ bool setClassPath(const char *classPath);
char *getClassPath();
jstring fromUTF(const char *bytes) const;
Modified: lucene/pylucene/trunk/jcc/jcc2/sources/jcc.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc2/sources/jcc.cpp?rev=1883885&r1=1883884&r2=1883885&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc2/sources/jcc.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc2/sources/jcc.cpp Sat Nov 28 03:17:36 2020
@@ -282,9 +282,10 @@ static PyObject *t_jccenv__addClassPath(
if (!PyArg_ParseTuple(args, "s", &classpath))
return NULL;
- env->setClassPath(classpath);
+ if (env->setClassPath(classpath))
+ Py_RETURN_TRUE;
- Py_RETURN_NONE;
+ Py_RETURN_FALSE;
}
static PyObject *t_jccenv__get_jni_version(PyObject *self, void *data)
@@ -390,7 +391,21 @@ _DLL_EXPORT PyObject *initVM(PyObject *s
}
if (classpath && classpath[0])
- env->setClassPath(classpath);
+ {
+ if (!env->setClassPath(classpath))
+ {
+ PyErr_SetString(
+ PyExc_ValueError,
+ "JVM is already running and updating its classpath failed. "
+ "Call initVM() instead just once but with a classpath "
+ "keyword argument set to the module.CLASSPATH strings of "
+ "all the JCC extension modules to be imported by this "
+ "process");
+ Py_XDECREF(module_cp);
+
+ return NULL;
+ }
+ }
Py_XDECREF(module_cp);
Modified: lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp?rev=1883885&r1=1883884&r2=1883885&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp Sat Nov 28 03:17:36 2020
@@ -874,7 +874,7 @@ DEFINE_SET_FIELD(jint, Int)
DEFINE_SET_FIELD(jlong, Long)
DEFINE_SET_FIELD(jshort, Short)
-void JCCEnv::setClassPath(const char *classPath)
+bool JCCEnv::setClassPath(const char *classPath)
{
JNIEnv *vm_env = get_vm_env();
jclass _ucl = (jclass) vm_env->FindClass("java/net/URLClassLoader");
@@ -882,6 +882,10 @@ void JCCEnv::setClassPath(const char *cl
jmethodID mid = vm_env->GetStaticMethodID(_ucl, "getSystemClassLoader",
"()Ljava/lang/ClassLoader;");
jobject classLoader = vm_env->CallStaticObjectMethod(_ucl, mid);
+
+ if (!vm_env->IsInstanceOf(classLoader, _ucl))
+ return false;
+
jmethodID mf = vm_env->GetMethodID(_fil, "<init>", "(Ljava/lang/String;)V");
jmethodID mu = vm_env->GetMethodID(_fil, "toURL", "()Ljava/net/URL;");
jmethodID ma = vm_env->GetMethodID(_ucl, "addURL", "(Ljava/net/URL;)V");
@@ -903,6 +907,8 @@ void JCCEnv::setClassPath(const char *cl
vm_env->CallVoidMethod(classLoader, ma, url);
}
free(path);
+
+ return true;
}
char *JCCEnv::getClassPath()
Modified: lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h?rev=1883885&r1=1883884&r2=1883885&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h Sat Nov 28 03:17:36 2020
@@ -277,7 +277,7 @@ public:
: 0;
}
- void setClassPath(const char *classPath);
+ bool setClassPath(const char *classPath);
char *getClassPath();
jstring fromUTF32(const uint32_t *chars, jsize len) const;
Modified: lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp?rev=1883885&r1=1883884&r2=1883885&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp Sat Nov 28 03:17:36 2020
@@ -283,9 +283,10 @@ static PyObject *t_jccenv__addClassPath(
if (!PyArg_ParseTuple(args, "s", &classpath))
return NULL;
- env->setClassPath(classpath);
+ if (env->setClassPath(classpath))
+ Py_RETURN_TRUE;
- Py_RETURN_NONE;
+ Py_RETURN_FALSE;;
}
static PyObject *t_jccenv__get_jni_version(PyObject *self, void *data)
@@ -391,7 +392,21 @@ _DLL_EXPORT PyObject *initVM(PyObject *s
}
if (classpath && classpath[0])
- env->setClassPath(classpath);
+ {
+ if (!env->setClassPath(classpath))
+ {
+ PyErr_SetString(
+ PyExc_ValueError,
+ "JVM is already running and updating its classpath failed. "
+ "Call initVM() instead just once but with a classpath "
+ "keyword argument set to the module.CLASSPATH strings of "
+ "all the JCC extension modules to be imported by this "
+ "process");
+ Py_XDECREF(module_cp);
+
+ return NULL;
+ }
+ }
Py_XDECREF(module_cp);