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 2017/03/19 22:47:17 UTC

svn commit: r1787670 - in /lucene/pylucene/trunk/jcc/jcc3/sources: JCCEnv.cpp JCCEnv.h JObject.cpp functions.cpp jcc.cpp

Author: vajda
Date: Sun Mar 19 22:47:17 2017
New Revision: 1787670

URL: http://svn.apache.org/viewvc?rev=1787670&view=rev
Log:
 - fixed bugs with surrogate pairs (now supported for the first time)

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

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp?rev=1787670&r1=1787669&r2=1787670&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp Sun Mar 19 22:47:17 2017
@@ -969,7 +969,7 @@ jstring JCCEnv::fromUTF32(const uint32_t
 
         if (c <= 0xd7ff || (c >= 0xe000 && c <= 0xffff)) {
             jchars.push_back((jchar) c);
-        } else if (c >= 0x10000 && c <= 0x10fff) {
+        } else if (c >= 0x10000 && c <= 0x10ffff) {
             jchars.push_back(U16_LEAD(c));
             jchars.push_back(U16_TRAIL(c));
         } else if (c >= 0xd800 && c <= 0xdfff) {
@@ -1156,6 +1156,30 @@ PyObject *JCCEnv::fromJString(jstring js
     return result;
 }
 
+PyObject *JCCEnv::toPyUnicode(jobject obj) const
+{
+    try {
+        if (obj)
+          return fromJString(
+              (jstring) callObjectMethod(obj, _mids[mid_obj_toString]), 0);
+        Py_RETURN_NONE;
+    } 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;
+        }
+    }
+}
 
 /* may be called from finalizer thread which has no vm_env thread local */
 void JCCEnv::finalizeObject(JNIEnv *jenv, PyObject *obj)

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h?rev=1787670&r1=1787669&r2=1787670&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h Sun Mar 19 22:47:17 2017
@@ -290,6 +290,7 @@ public:
     bool restorePythonException(jthrowable throwable) const;
     jstring fromPyString(PyObject *object) const;
     PyObject *fromJString(jstring js, int delete_local_ref) const;
+    PyObject *toPyUnicode(jobject obj) const;
     void finalizeObject(JNIEnv *jenv, PyObject *obj);
 #endif
 

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/JObject.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/JObject.cpp?rev=1787670&r1=1787669&r2=1787670&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/JObject.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/JObject.cpp Sun Mar 19 22:47:17 2017
@@ -140,30 +140,20 @@ static PyObject *t_JObject_richcmp(t_JOb
 static PyObject *t_JObject_str(t_JObject *self)
 {
     if (self->object.this$)
-    {
-        char *utf = env->toString(self->object.this$);
-
-        if (utf == NULL)
-            utf = env->getClassName(self->object.this$);
-
-        if (utf != NULL)
-        {
-            PyObject *unicode =
-                PyUnicode_DecodeUTF8(utf, strlen(utf), "strict");
-
-            free(utf);
-            return unicode;
-        }
-    }
+        return env->toPyUnicode(self->object.this$);
 
     return PyUnicode_FromString("<null>");
 }
 
 static PyObject *t_JObject_repr(t_JObject *self)
 {
-    PyObject *name = PyObject_GetAttrString((PyObject *) self->ob_base.ob_type,
-                                            "__name__");
     PyObject *str = self->ob_base.ob_type->tp_str((PyObject *) self);
+
+    if (str == NULL)
+        return NULL;
+
+    PyObject *name = PyObject_GetAttrString((PyObject *) Py_TYPE(self),
+                                            "__name__");
     PyObject *args = PyTuple_Pack(2, name, str);
     PyObject *format = PyUnicode_FromString("<%s: %s>");
     PyObject *repr = PyUnicode_Format(format, args);

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/functions.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/functions.cpp?rev=1787670&r1=1787669&r2=1787670&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/functions.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/functions.cpp Sun Mar 19 22:47:17 2017
@@ -538,7 +538,6 @@ int _parseArgs(PyObject **args, unsigned
                   if (last)
                   {
                       if ((PyBytes_Check(arg) && (PyBytes_Size(arg) == 1)) ||
-                          (PyUnicode_Check(arg) && (PyUnicode_GetLength(arg) == 1)) ||
                           PyLong_CheckExact(arg))
                       {
                           varargs = true;
@@ -548,8 +547,6 @@ int _parseArgs(PyObject **args, unsigned
               }
               else if (PyBytes_Check(arg) && (PyBytes_Size(arg) == 1))
                   break;
-              else if (PyUnicode_Check(arg) && (PyUnicode_GetLength(arg) == 1))
-                  break;
               else if (PyLong_CheckExact(arg))
                   break;
 
@@ -567,8 +564,10 @@ int _parseArgs(PyObject **args, unsigned
 
                   if (last)
                   {
-                      if ((PyBytes_Check(arg) && (PyBytes_Size(arg) == 1)) ||
-                          (PyUnicode_Check(arg) && (PyUnicode_GetLength(arg) == 1)))
+                      if ((PyBytes_Check(arg) && PyBytes_Size(arg) == 1) ||
+                          (PyUnicode_Check(arg) &&
+                           PyUnicode_GetLength(arg) == 1 &&
+                           PyUnicode_READ_CHAR(arg, 0) < 0x10000))
                       {
                           varargs = true;
                           break;
@@ -577,8 +576,10 @@ int _parseArgs(PyObject **args, unsigned
               }
               else if (PyBytes_Check(arg) && PyBytes_Size(arg) == 1)
                   break;
-              else if (PyUnicode_Check(arg) && PyUnicode_GetLength(arg) == 1)
+              else if (PyUnicode_Check(arg) && PyUnicode_GetLength(arg) == 1 &&
+                       PyUnicode_READ_CHAR(arg, 0) < 0x10000)
                   break;
+
               return -1;
           }
 

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp?rev=1787670&r1=1787669&r2=1787670&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp Sun Mar 19 22:47:17 2017
@@ -244,15 +244,12 @@ static PyObject *t_jccenv__dumpRefs(PyOb
         }
         else if (values)  // return list of (value string, ref count)
         {
-            char *str = env->toString(iter->second.global);
-            PyObject *key = PyUnicode_FromString(str);
+            PyObject *key = env->toPyUnicode(iter->second.global);
             PyObject *value = PyLong_FromLong(iter->second.count);
 
             PyList_SET_ITEM(result, count++, PyTuple_Pack(2, key, value));
             Py_DECREF(key);
             Py_DECREF(value);
-
-            delete str;
         }
         else  // return list of (id hash code, ref count)
         {