lucene-pylucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From va...@apache.org
Subject svn commit: r1154245 - in /lucene/pylucene/trunk/jcc/jcc/sources: JCCEnv.cpp JObject.cpp
Date Fri, 05 Aug 2011 14:45:10 GMT
Author: vajda
Date: Fri Aug  5 14:45:10 2011
New Revision: 1154245

URL: http://svn.apache.org/viewvc?rev=1154245&view=rev
Log:
 - improved recovery from toString() failure, displaying class name instead

Modified:
    lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.cpp
    lucene/pylucene/trunk/jcc/jcc/sources/JObject.cpp

Modified: lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.cpp?rev=1154245&r1=1154244&r2=1154245&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.cpp Fri Aug  5 14:45:10 2011
@@ -839,9 +839,26 @@ char *JCCEnv::toUTF(jstring str) const
 
 char *JCCEnv::toString(jobject obj) const
 {
-    return obj
-        ? toUTF((jstring) callObjectMethod(obj, _mids[mid_obj_toString]))
-        : NULL;
+    try {
+        return obj
+            ? toUTF((jstring) callObjectMethod(obj, _mids[mid_obj_toString]))
+            : NULL;
+    } catch (int e) {
+        switch (e) {
+          case _EXC_PYTHON:
+            return NULL;
+          case _EXC_JAVA: {
+              JNIEnv *vm_env = get_vm_env();
+
+              vm_env->ExceptionDescribe();
+              vm_env->ExceptionClear();
+
+              return NULL;
+          }
+          default:
+            throw;
+        }
+    }
 }
 
 char *JCCEnv::getClassName(jobject obj) const

Modified: lucene/pylucene/trunk/jcc/jcc/sources/JObject.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/sources/JObject.cpp?rev=1154245&r1=1154244&r2=1154245&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/sources/JObject.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc/sources/JObject.cpp Fri Aug  5 14:45:10 2011
@@ -143,10 +143,18 @@ static PyObject *t_JObject_str(t_JObject
     if (self->object.this$)
     {
         char *utf = env->toString(self->object.this$);
-        PyObject *unicode = PyUnicode_DecodeUTF8(utf, strlen(utf), "strict");
 
-        delete utf;
-        return unicode;
+        if (utf == NULL)
+            utf = env->getClassName(self->object.this$);
+
+        if (utf != NULL)
+        {
+            PyObject *unicode =
+                PyUnicode_DecodeUTF8(utf, strlen(utf), "strict");
+
+            delete utf;
+            return unicode;
+        }
     }
 
     return PyString_FromString("<null>");



Mime
View raw message