lucene-pylucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From va...@apache.org
Subject svn commit: r1787656 [2/2] - in /lucene/pylucene/trunk/jcc: ./ _jcc/ _jcc2/ _jcc3/ _jcc3/java/lang/ _jcc3/java/lang/reflect/ helpers/ helpers2/ helpers3/ jcc/ jcc2/ jcc3/ jcc3/sources/
Date Sun, 19 Mar 2017 20:26:49 GMT
Modified: lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp Sun Mar 19 20:26:48 2017
@@ -18,6 +18,8 @@
 #include <string.h>
 #include <jni.h>
 
+#include <vector>
+
 #include "JCCEnv.h"
 
 #if defined(_MSC_VER) || defined(__WIN32)
@@ -56,6 +58,25 @@ public:
 
 #endif
 
+// borrowed from ICU (http://icu-project.org/apiref/icu4c/utf16_8h.html)
+#define U16_LEAD(c) (jchar) (((c) >> 10) + 0xd7c0)
+#define U16_TRAIL(c) (jchar) (((c) & 0x3ff) | 0xdc00)
+#define U16_IS_LEAD(c) (((c) & 0xfffffc00) == 0xd800)
+#define U16_IS_TRAIL(c) (((c) & 0xfffffc00) == 0xdc00)
+#define U16_SURROGATE_OFFSET ((0xd800 << 10UL) + 0xdc00 - 0x10000)
+#define U16_GET_SUPPLEMENTARY(lead, trail) \
+    (((uint32_t) (lead) << 10UL) + (uint32_t) (trail) - U16_SURROGATE_OFFSET)
+#define U16_NEXT(s, i, length, c) { \
+    (c) = (s)[(i)++]; \
+    if (U16_IS_LEAD(c)) { \
+        jchar __c2; \
+        if ((i) != (length) && U16_IS_TRAIL(__c2 = (s)[(i)])) { \
+            ++(i); \
+            (c) = U16_GET_SUPPLEMENTARY((c), __c2); \
+        } \
+    } \
+}
+
 JCCEnv::JCCEnv(JavaVM *vm, JNIEnv *vm_env)
 {
 #if defined(_MSC_VER) || defined(__WIN32)
@@ -904,7 +925,7 @@ char *JCCEnv::getClassPath()
     int count = array ? vm_env->GetArrayLength(array) : 0;
     int first = 1, total = 0;
     char *classpath = NULL;
-    
+
     for (int i = 0; i < count; i++) {
         jobject url = vm_env->GetObjectArrayElement(array, i);
         jstring path = (jstring) vm_env->CallObjectMethod(url, gp);
@@ -930,7 +951,7 @@ char *JCCEnv::getClassPath()
     return classpath;
 }
 
-jstring JCCEnv::fromUTF(const char *bytes) const
+jstring JCCEnv::fromUTF8(const char *bytes) const
 {
     jstring str = get_vm_env()->NewStringUTF(bytes);
 
@@ -939,11 +960,35 @@ jstring JCCEnv::fromUTF(const char *byte
     return str;
 }
 
-char *JCCEnv::toUTF(jstring str) const
+jstring JCCEnv::fromUTF32(const uint32_t *chars, jsize len) const
+{
+    std::vector<jchar> jchars;
+
+    for (jsize i = 0; i < len; ++i) {
+        uint32_t c = chars[i];
+
+        if (c <= 0xd7ff || (c >= 0xe000 && c <= 0xffff)) {
+            jchars.push_back((jchar) c);
+        } else if (c >= 0x10000 && c <= 0x10fff) {
+            jchars.push_back(U16_LEAD(c));
+            jchars.push_back(U16_TRAIL(c));
+        } else if (c >= 0xd800 && c <= 0xdfff) {
+            jchars.push_back((jchar) 0xfffd);  // invalid char
+        }
+    }
+
+    jstring str = get_vm_env()->NewString(jchars.data(), jchars.size());
+
+    reportException();
+
+    return str;
+}
+
+char *JCCEnv::toUTF8(jstring str) const
 {
     JNIEnv *vm_env = get_vm_env();
     int len = vm_env->GetStringUTFLength(str);
-    char *bytes = new char[len + 1];
+    char *bytes = (char *) malloc(len + 1);
     jboolean isCopy = 0;
     const char *utf = vm_env->GetStringUTFChars(str, &isCopy);
 
@@ -962,7 +1007,7 @@ char *JCCEnv::toString(jobject obj) cons
 {
     try {
         return obj
-            ? toUTF((jstring) callObjectMethod(obj, _mids[mid_obj_toString]))
+            ? toUTF8((jstring) callObjectMethod(obj, _mids[mid_obj_toString]))
             : NULL;
     } catch (int e) {
         switch (e) {
@@ -998,40 +1043,54 @@ jstring JCCEnv::fromPyString(PyObject *o
 
     if (PyUnicode_Check(object))
     {
-        if (sizeof(Py_UNICODE) == sizeof(jchar))
-        {
-            jchar *buf = (jchar *) PyUnicode_AS_UNICODE(object);
-            jsize len = (jsize) PyUnicode_GET_SIZE(object);
+        PyUnicode_READY(object);
 
-            return get_vm_env()->NewString(buf, len);
-        }
-        else
-        {
-            jsize len = PyUnicode_GET_SIZE(object);
-            Py_UNICODE *pchars = PyUnicode_AS_UNICODE(object);
-            jchar *jchars = new jchar[len];
-            jstring str;
+        switch (PyUnicode_KIND(object)) {
+          case PyUnicode_WCHAR_KIND: {  // this code path should be deprecated
+              if (sizeof(Py_UNICODE) == sizeof(jchar))
+              {
+                  Py_ssize_t len;
+                  Py_UNICODE *pchars = PyUnicode_AsUnicodeAndSize(object, &len);
+
+                  return get_vm_env()->NewString((jchar *) pchars, (jsize) len);
+              }
+              else  // Py_UNICODE 32-bit case
+              {
+                  Py_ssize_t len;
+                  Py_UNICODE *pchars = PyUnicode_AsUnicodeAndSize(object, &len);
+
+                  return fromUTF32((uint32_t *) pchars, (jsize) len);
+              }
+          }
+
+          case PyUnicode_1BYTE_KIND:
+              return fromUTF8((const char *) PyUnicode_1BYTE_DATA(object));
 
-            for (int i = 0; i < len; i++)
-                jchars[i] = (jchar) pchars[i];
+          case PyUnicode_2BYTE_KIND: {
+              Py_ssize_t len = PyUnicode_GET_LENGTH(object);
+              Py_UCS2 *pchars = PyUnicode_2BYTE_DATA(object);
 
-            str = get_vm_env()->NewString(jchars, len);
-            delete[] jchars;
+              return get_vm_env()->NewString((jchar *) pchars, (jsize) len);
+          }
 
-            return str;
+          case PyUnicode_4BYTE_KIND: {
+              Py_ssize_t len = PyUnicode_GET_LENGTH(object);
+              Py_UCS4 *pchars = PyUnicode_4BYTE_DATA(object);
+
+              return fromUTF32((uint32_t *) pchars, (jsize) len);
+          }
         }
     }
-    else if (PyString_Check(object))
-        return fromUTF(PyString_AS_STRING(object));
-    else
-    {
-        PyObject *tuple = Py_BuildValue("(sO)", "expected a string", object);
+    else if (PyBytes_Check(object))
+        return fromUTF8(PyBytes_AS_STRING(object));
 
-        PyErr_SetObject(PyExc_TypeError, tuple);
-        Py_DECREF(tuple);
 
-        return NULL;
-    }
+    PyObject *tuple = Py_BuildValue("(sO)", "expected a string", object);
+
+    PyErr_SetObject(PyExc_TypeError, tuple);
+    Py_DECREF(tuple);
+
+    return NULL;
 }
 
 PyObject *JCCEnv::fromJString(jstring js, int delete_local_ref) const
@@ -1040,39 +1099,61 @@ PyObject *JCCEnv::fromJString(jstring js
         Py_RETURN_NONE;
 
     JNIEnv *vm_env = get_vm_env();
-    PyObject *string;
+    jsize len16 = vm_env->GetStringLength(js);
+    jboolean isCopy;
+    const jchar *utf16 = vm_env->GetStringChars(js, &isCopy);
 
-    if (sizeof(Py_UNICODE) == sizeof(jchar))
-    {
-        jboolean isCopy;
-        const jchar *buf = vm_env->GetStringChars(js, &isCopy);
-        jsize len = vm_env->GetStringLength(js);
+    int32_t len32 = 0;
+    uint32_t max_char = 0;
+
+    for (jsize i = 0; i < len16;) {
+        uint32_t cp;
 
-        string = PyUnicode_FromUnicode((const Py_UNICODE *) buf, len);
-        vm_env->ReleaseStringChars(js, buf);
+        U16_NEXT(utf16, i, len16, cp);
+        max_char |= cp;  // we only care about the leftmost bit
+        len32 += 1;
     }
-    else
-    {
-        jsize len = vm_env->GetStringLength(js);
 
-        string = PyUnicode_FromUnicode(NULL, len);
-        if (string)
-        {
-            jboolean isCopy;
-            const jchar *jchars = vm_env->GetStringChars(js, &isCopy);
-            Py_UNICODE *pchars = PyUnicode_AS_UNICODE(string);
+    PyObject *result = PyUnicode_New(len32, max_char);
 
-            for (int i = 0; i < len; i++)
-                pchars[i] = (Py_UNICODE) jchars[i];
-        
-            vm_env->ReleaseStringChars(js, jchars);
-        }
+    if (result == NULL) {
+        vm_env->ReleaseStringChars(js, utf16);
+        return NULL;
     }
 
+    switch (PyUnicode_KIND(result)) {
+      case PyUnicode_1BYTE_KIND:
+          // note: len16 == len32
+          for (int32_t i = 0; i < len32; ++i)
+              PyUnicode_1BYTE_DATA(result)[i] = (Py_UCS1) (utf16[i]);
+          break;
+
+      case PyUnicode_2BYTE_KIND:
+          // note: len16 == len32
+          memcpy(PyUnicode_2BYTE_DATA(result), utf16, len16 * 2);
+          break;
+
+      case PyUnicode_4BYTE_KIND:
+          len32 = 0;
+          for (jsize i = 0; i < len16;) {
+              uint32_t cp;
+
+              U16_NEXT(utf16, i, len16, cp);
+              PyUnicode_4BYTE_DATA(result)[len32++] = cp;
+          }
+          break;
+
+      default:
+          Py_DECREF(result);
+          vm_env->ReleaseStringChars(js, utf16);
+          return NULL;
+    }
+
+    vm_env->ReleaseStringChars(js, utf16);
     if (delete_local_ref)
         vm_env->DeleteLocalRef((jobject) js);
 
-    return string;
+    return result;
 }
 
 

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h Sun Mar 19 20:26:48 2017
@@ -18,6 +18,7 @@
 #define _JCCEnv_H
 
 #include <stdarg.h>
+#include <inttypes.h>
 #if defined(_MSC_VER) || defined(__WIN32)
 #define _DLL_IMPORT __declspec(dllimport)
 #define _DLL_EXPORT __declspec(dllexport)
@@ -279,8 +280,9 @@ public:
     void setClassPath(const char *classPath);
     char *getClassPath();
 
-    jstring fromUTF(const char *bytes) const;
-    char *toUTF(jstring str) const;
+    jstring fromUTF8(const char *bytes) const;
+    jstring fromUTF32(const uint32_t *chars, jsize len) const;
+    char *toUTF8(jstring str) const;
     char *toString(jobject obj) const;
     char *getClassName(jobject obj) const;
 #ifdef PYTHON

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/JObject.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/JObject.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/JObject.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/JObject.cpp Sun Mar 19 20:26:48 2017
@@ -50,8 +50,7 @@ static PyGetSetDef t_JObject_properties[
 };
 
 PyTypeObject PY_TYPE(JObject) = {
-    PyObject_HEAD_INIT(NULL)
-    0,                                   /* ob_size */
+    PyVarObject_HEAD_INIT(NULL, 0)
     "jcc.JObject",                       /* tp_name */
     sizeof(t_JObject),                   /* tp_basicsize */
     0,                                   /* tp_itemsize */
@@ -59,7 +58,7 @@ PyTypeObject PY_TYPE(JObject) = {
     0,                                   /* tp_print */
     0,                                   /* tp_getattr */
     0,                                   /* tp_setattr */
-    0,                                   /* tp_compare */
+    0,                                   /* tp_reserved */
     (reprfunc)t_JObject_repr,            /* tp_repr */
     0,                                   /* tp_as_number */
     0,                                   /* tp_as_sequence */
@@ -96,7 +95,7 @@ PyTypeObject PY_TYPE(JObject) = {
 static void t_JObject_dealloc(t_JObject *self)
 {
     self->object = JObject(NULL);
-    self->ob_type->tp_free((PyObject *) self);
+    self->ob_base.ob_type->tp_free((PyObject *) self);
 }
 
 static PyObject *t_JObject_new(PyTypeObject *type,
@@ -152,26 +151,22 @@ static PyObject *t_JObject_str(t_JObject
             PyObject *unicode =
                 PyUnicode_DecodeUTF8(utf, strlen(utf), "strict");
 
-            delete utf;
+            free(utf);
             return unicode;
         }
     }
 
-    return PyString_FromString("<null>");
+    return PyUnicode_FromString("<null>");
 }
 
 static PyObject *t_JObject_repr(t_JObject *self)
 {
-    PyObject *name = PyObject_GetAttrString((PyObject *) self->ob_type,
+    PyObject *name = PyObject_GetAttrString((PyObject *) self->ob_base.ob_type,
                                             "__name__");
-    PyObject *str = self->ob_type->tp_str((PyObject *) self);
-#if PY_VERSION_HEX < 0x02040000
-    PyObject *args = Py_BuildValue("(OO)", name, str);
-#else
+    PyObject *str = self->ob_base.ob_type->tp_str((PyObject *) self);
     PyObject *args = PyTuple_Pack(2, name, str);
-#endif
-    PyObject *format = PyString_FromString("<%s: %s>");
-    PyObject *repr = PyString_Format(format, args);
+    PyObject *format = PyUnicode_FromString("<%s: %s>");
+    PyObject *repr = PyUnicode_Format(format, args);
 
     Py_DECREF(name);
     Py_DECREF(str);
@@ -188,7 +183,7 @@ static int t_JObject_hash(t_JObject *sel
 
 static PyObject *t_JObject__getJObject(t_JObject *self, void *data)
 {
-    return PyCObject_FromVoidPtr((void *) self->object.this$, NULL);
+    return PyCapsule_New((void *) self->object.this$, "jobject", NULL);
 }
 
 #endif /* PYTHON */

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/functions.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/functions.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/functions.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/functions.cpp Sun Mar 19 20:26:48 2017
@@ -131,7 +131,7 @@ PyObject *makeInterface(PyObject *self,
     if (!PyArg_ParseTuple(args, "s#s#",
                           &name, &name_len, &extName, &extName_len))
         return NULL;
-    
+
     JNIEnv *vm_env = env->get_vm_env();
     jclass _ucl = (jclass) vm_env->FindClass("java/net/URLClassLoader");
     jmethodID mid = vm_env->GetStaticMethodID(_ucl, "getSystemClassLoader",
@@ -217,7 +217,7 @@ PyObject *makeClass(PyObject *self, PyOb
                           &name, &name_len, &extName, &extName_len,
                           &implName, &implName_len))
         return NULL;
-    
+
     JNIEnv *vm_env = env->get_vm_env();
     jclass _ucl = (jclass) vm_env->FindClass("java/net/URLClassLoader");
     jmethodID mid = vm_env->GetStaticMethodID(_ucl, "getSystemClassLoader",
@@ -266,14 +266,14 @@ PyObject *makeClass(PyObject *self, PyOb
 
 static boxfn get_boxfn(PyTypeObject *type)
 {
-    static PyObject *boxfn_ = PyString_FromString("boxfn_");
+    static PyObject *boxfn_ = PyUnicode_FromString("boxfn_");
     PyObject *cobj = PyObject_GetAttr((PyObject *) type, boxfn_);
     boxfn fn;
-    
+
     if (cobj == NULL)
         return NULL;
 
-    fn = (boxfn) PyCObject_AsVoidPtr(cobj);
+    fn = (boxfn) PyCapsule_GetPointer(cobj, "boxfn");
     Py_DECREF(cobj);
 
     return fn;
@@ -281,7 +281,7 @@ static boxfn get_boxfn(PyTypeObject *typ
 
 static int is_instance_of(PyObject *arg, PyTypeObject *type)
 {
-    static PyObject *class_ = PyString_FromString("class_");
+    static PyObject *class_ = PyUnicode_FromString("class_");
     PyObject *clsObj = PyObject_GetAttr((PyObject *) type, class_);
     int result;
 
@@ -300,13 +300,13 @@ static int is_instance_of(PyObject *arg,
 #if defined(_MSC_VER) || defined(__SUNPRO_CC)
 int __parseArgs(PyObject *args, char *types, ...)
 {
-    int count = ((PyTupleObject *)(args))->ob_size;
+    int count = PY_SIZE((PyTupleObject *) args);
     va_list list, check;
 
     va_start(list, types);
     va_start(check, types);
 
-    return _parseArgs(((PyTupleObject *)(args))->ob_item, count, types,
+    return _parseArgs(((PyTupleObject *) args)->ob_item, count, types,
 		      list, check);
 }
 
@@ -422,7 +422,7 @@ int _parseArgs(PyObject **args, unsigned
                       break;
 
                   if (PySequence_Check(arg) &&
-                      !PyString_Check(arg) && !PyUnicode_Check(arg))
+                      !PyBytes_Check(arg) && !PyUnicode_Check(arg))
                   {
                       if (PySequence_Length(arg) > 0)
                       {
@@ -537,17 +537,20 @@ int _parseArgs(PyObject **args, unsigned
 
                   if (last)
                   {
-                      if ((PyString_Check(arg) && (PyString_Size(arg) == 1)) ||
-                          PyInt_CheckExact(arg))
+                      if ((PyBytes_Check(arg) && (PyBytes_Size(arg) == 1)) ||
+                          (PyUnicode_Check(arg) && (PyUnicode_GetLength(arg) == 1)) ||
+                          PyLong_CheckExact(arg))
                       {
                           varargs = true;
                           break;
                       }
                   }
               }
-              else if (PyString_Check(arg) && (PyString_Size(arg) == 1))
+              else if (PyBytes_Check(arg) && (PyBytes_Size(arg) == 1))
                   break;
-              else if (PyInt_CheckExact(arg))
+              else if (PyUnicode_Check(arg) && (PyUnicode_GetLength(arg) == 1))
+                  break;
+              else if (PyLong_CheckExact(arg))
                   break;
 
               return -1;
@@ -564,14 +567,17 @@ int _parseArgs(PyObject **args, unsigned
 
                   if (last)
                   {
-                      if (PyUnicode_Check(arg) && (PyUnicode_GET_SIZE(arg) == 1))
+                      if ((PyBytes_Check(arg) && (PyBytes_Size(arg) == 1)) ||
+                          (PyUnicode_Check(arg) && (PyUnicode_GetLength(arg) == 1)))
                       {
                           varargs = true;
                           break;
                       }
                   }
               }
-              else if (PyUnicode_Check(arg) && PyUnicode_GET_SIZE(arg) == 1)
+              else if (PyBytes_Check(arg) && PyBytes_Size(arg) == 1)
+                  break;
+              else if (PyUnicode_Check(arg) && PyUnicode_GetLength(arg) == 1)
                   break;
               return -1;
           }
@@ -591,7 +597,7 @@ int _parseArgs(PyObject **args, unsigned
                       if (PySequence_Length(arg) > 0)
                       {
                           PyObject *obj = PySequence_GetItem(arg, 0);
-                          int ok = PyInt_CheckExact(obj);
+                          int ok = PyLong_CheckExact(obj);
 
                           Py_DECREF(obj);
                           if (ok)
@@ -601,13 +607,13 @@ int _parseArgs(PyObject **args, unsigned
                           break;
                   }
 
-                  if (last && PyInt_CheckExact(arg))
+                  if (last && PyLong_CheckExact(arg))
                   {
                       varargs = true;
                       break;
                   }
               }
-              else if (PyInt_CheckExact(arg))
+              else if (PyLong_CheckExact(arg))
                   break;
 
               return -1;
@@ -628,7 +634,7 @@ int _parseArgs(PyObject **args, unsigned
                       if (PySequence_Length(arg) > 0)
                       {
                           PyObject *obj = PySequence_GetItem(arg, 0);
-                          int ok = PyInt_CheckExact(obj);
+                          int ok = PyLong_CheckExact(obj);
 
                           Py_DECREF(obj);
                           if (ok)
@@ -638,13 +644,13 @@ int _parseArgs(PyObject **args, unsigned
                           break;
                   }
 
-                  if (last && PyInt_CheckExact(arg))
+                  if (last && PyLong_CheckExact(arg))
                   {
                       varargs = true;
                       break;
                   }
               }
-              else if (PyInt_CheckExact(arg))
+              else if (PyLong_CheckExact(arg))
                   break;
 
               return -1;
@@ -771,15 +777,15 @@ int _parseArgs(PyObject **args, unsigned
                   if (PyObject_TypeCheck(arg, PY_TYPE(JArrayString)))
                       break;
 
-                  if (PySequence_Check(arg) && 
-                      !PyString_Check(arg) && !PyUnicode_Check(arg))
+                  if (PySequence_Check(arg) &&
+                      !PyBytes_Check(arg) && !PyUnicode_Check(arg))
                   {
                       if (PySequence_Length(arg) > 0)
                       {
                           PyObject *obj = PySequence_GetItem(arg, 0);
                           int ok =
                               (obj == Py_None ||
-                               PyString_Check(obj) || PyUnicode_Check(obj));
+                               PyBytes_Check(obj) || PyUnicode_Check(obj));
 
                           Py_DECREF(obj);
                           if (ok)
@@ -787,17 +793,17 @@ int _parseArgs(PyObject **args, unsigned
                       }
                       else
                           break;
-                  } 
+                  }
 
                   if (last && (arg == Py_None ||
-                               PyString_Check(arg) || PyUnicode_Check(arg)))
+                               PyBytes_Check(arg) || PyUnicode_Check(arg)))
                   {
                       varargs = true;
                       break;
                   }
               }
               else if (arg == Py_None ||
-                       PyString_Check(arg) || PyUnicode_Check(arg))
+                       PyBytes_Check(arg) || PyUnicode_Check(arg))
                   break;
 
               return -1;
@@ -813,7 +819,7 @@ int _parseArgs(PyObject **args, unsigned
               if (type != NULL)
               {
                   boxfn fn = get_boxfn(type);
-    
+
                   if (fn == NULL || fn(type, arg, NULL) < 0)
                       return -1;
               }
@@ -822,7 +828,7 @@ int _parseArgs(PyObject **args, unsigned
 
           case 'T':         /* tuple of python types with wrapfn_ */
           {
-              static PyObject *wrapfn_ = PyString_FromString("wrapfn_");
+              static PyObject *wrapfn_ = PyUnicode_FromString("wrapfn_");
               int len = va_arg(list, int);
 
               if (PyTuple_Check(arg))
@@ -937,7 +943,7 @@ int _parseArgs(PyObject **args, unsigned
                       *array = fromPySequence(cls, args + a, count - a);
                   else if (PyObject_TypeCheck(arg, PY_TYPE(JArrayObject)))
                       *array = ((t_JArray<jobject> *) arg)->array;
-                  else 
+                  else
                       *array = JArray<jobject>(cls, arg);
 
                   if (PyErr_Occurred())
@@ -954,7 +960,7 @@ int _parseArgs(PyObject **args, unsigned
                   if (tc == 'K')
                   {
                       PyTypeObject ***tp = va_arg(list, PyTypeObject ***);
-                      PyTypeObject **(*parameters_)(void *) = 
+                      PyTypeObject **(*parameters_)(void *) =
                           va_arg(list, getparametersfn);
 
                       if (arg == Py_None)
@@ -1009,21 +1015,26 @@ int _parseArgs(PyObject **args, unsigned
                       *array = JArray<jbyte>(args + a, count - a);
                   else if (PyObject_TypeCheck(arg, PY_TYPE(JArrayByte)))
                       *array = ((t_JArray<jbyte> *) arg)->array;
-                  else 
+                  else
                       *array = JArray<jbyte>(arg);
 
                   if (PyErr_Occurred())
                       return -1;
               }
-              else if (PyString_Check(arg))
+              else if (PyBytes_Check(arg))
+              {
+                  jbyte *a = va_arg(list, jbyte *);
+                  *a = (jbyte) PyBytes_AS_STRING(arg)[0];
+              }
+              else if (PyUnicode_Check(arg))
               {
                   jbyte *a = va_arg(list, jbyte *);
-                  *a = (jbyte) PyString_AS_STRING(arg)[0];
+                  *a = (jbyte) PyUnicode_AsUTF8(arg)[0];
               }
               else
               {
                   jbyte *a = va_arg(list, jbyte *);
-                  *a = (jbyte) PyInt_AsLong(arg);
+                  *a = (jbyte) PyLong_AsLong(arg);
               }
               break;
           }
@@ -1040,7 +1051,7 @@ int _parseArgs(PyObject **args, unsigned
                       *array = JArray<jchar>(args + a, count - a);
                   else if (PyObject_TypeCheck(arg, PY_TYPE(JArrayChar)))
                       *array = ((t_JArray<jchar> *) arg)->array;
-                  else 
+                  else
                       *array = JArray<jchar>(arg);
 
                   if (PyErr_Occurred())
@@ -1049,7 +1060,7 @@ int _parseArgs(PyObject **args, unsigned
               else
               {
                   jchar *c = va_arg(list, jchar *);
-                  *c = (jchar) PyUnicode_AS_UNICODE(arg)[0];
+                  *c = (jchar) PyUnicode_READ_CHAR(arg, 0);
               }
               break;
           }
@@ -1066,7 +1077,7 @@ int _parseArgs(PyObject **args, unsigned
                       *array = JArray<jint>(args + a, count - a);
                   else if (PyObject_TypeCheck(arg, PY_TYPE(JArrayInt)))
                       *array = ((t_JArray<jint> *) arg)->array;
-                  else 
+                  else
                       *array = JArray<jint>(arg);
 
                   if (PyErr_Occurred())
@@ -1075,7 +1086,7 @@ int _parseArgs(PyObject **args, unsigned
               else
               {
                   jint *n = va_arg(list, jint *);
-                  *n = (jint) PyInt_AsLong(arg);
+                  *n = (jint) PyLong_AsLong(arg);
               }
               break;
           }
@@ -1092,7 +1103,7 @@ int _parseArgs(PyObject **args, unsigned
                       *array = JArray<jshort>(args + a, count - a);
                   else if (PyObject_TypeCheck(arg, PY_TYPE(JArrayShort)))
                       *array = ((t_JArray<jshort> *) arg)->array;
-                  else 
+                  else
                       *array = JArray<jshort>(arg);
 
                   if (PyErr_Occurred())
@@ -1101,7 +1112,7 @@ int _parseArgs(PyObject **args, unsigned
               else
               {
                   jshort *n = va_arg(list, jshort *);
-                  *n = (jshort) PyInt_AsLong(arg);
+                  *n = (jshort) PyLong_AsLong(arg);
               }
               break;
           }
@@ -1118,7 +1129,7 @@ int _parseArgs(PyObject **args, unsigned
                       *array = JArray<jdouble>(args + a, count - a);
                   else if (PyObject_TypeCheck(arg, PY_TYPE(JArrayDouble)))
                       *array = ((t_JArray<jdouble> *) arg)->array;
-                  else 
+                  else
                       *array = JArray<jdouble>(arg);
 
                   if (PyErr_Occurred())
@@ -1144,7 +1155,7 @@ int _parseArgs(PyObject **args, unsigned
                       *array = JArray<jfloat>(args + a, count - a);
                   else if (PyObject_TypeCheck(arg, PY_TYPE(JArrayFloat)))
                       *array = ((t_JArray<jfloat> *) arg)->array;
-                  else 
+                  else
                       *array = JArray<jfloat>(arg);
 
                   if (PyErr_Occurred())
@@ -1170,7 +1181,7 @@ int _parseArgs(PyObject **args, unsigned
                       *array = JArray<jlong>(args + a, count - a);
                   else if (PyObject_TypeCheck(arg, PY_TYPE(JArrayLong)))
                       *array = ((t_JArray<jlong> *) arg)->array;
-                  else 
+                  else
                       *array = JArray<jlong>(arg);
 
                   if (PyErr_Occurred())
@@ -1233,7 +1244,7 @@ int _parseArgs(PyObject **args, unsigned
                       *array = JArray<Object>(
                           env->getClass(Object::initializeClass),
                           args + a, count - a);
-                  else 
+                  else
                       *array = JArray<Object>(arg);
 
                   if (PyErr_Occurred())
@@ -1311,6 +1322,14 @@ PyObject *j2p(const String& js)
     return env->fromJString((jstring) js.this$, 0);
 }
 
+PyObject *c2p(jchar c)
+{
+    PyObject *result = PyUnicode_New(1, c);
+
+    PyUnicode_WriteChar(result, 0, c);
+    return result;
+}
+
 PyObject *PyErr_SetArgsError(char *name, PyObject *args)
 {
     if (!PyErr_Occurred())
@@ -1419,7 +1438,7 @@ void throwPythonError(void)
         PyObject *name = PyObject_GetAttrString(exc, "__name__");
 
         env->get_vm_env()->ThrowNew(env->getPythonExceptionClass(),
-                                    PyString_AS_STRING(name));
+                                    PyUnicode_AsUTF8(name));
         Py_DECREF(name);
     }
     else
@@ -1463,11 +1482,8 @@ PyObject *callSuper(PyTypeObject *type,
         value = PyObject_Call(method, args, NULL);
     else
     {
-#if PY_VERSION_HEX < 0x02040000
-        PyObject *tuple = Py_BuildValue("(O)", args);
-#else
         PyObject *tuple = PyTuple_Pack(1, args);
-#endif   
+
         value = PyObject_Call(method, tuple, NULL);
         Py_DECREF(tuple);
     }
@@ -1480,11 +1496,7 @@ PyObject *callSuper(PyTypeObject *type,
 PyObject *callSuper(PyTypeObject *type, PyObject *self,
                     const char *name, PyObject *args, int cardinality)
 {
-#if PY_VERSION_HEX < 0x02040000
-    PyObject *tuple = Py_BuildValue("(OO)", type, self);
-#else
     PyObject *tuple = PyTuple_Pack(2, type, self);
-#endif
     PyObject *super = PyObject_Call((PyObject *) &PySuper_Type, tuple, NULL);
     PyObject *method, *value;
 
@@ -1501,11 +1513,7 @@ PyObject *callSuper(PyTypeObject *type,
         value = PyObject_Call(method, args, NULL);
     else
     {
-#if PY_VERSION_HEX < 0x02040000
-        tuple = Py_BuildValue("(O)", args);
-#else
         tuple = PyTuple_Pack(1, args);
-#endif
         value = PyObject_Call(method, tuple, NULL);
         Py_DECREF(tuple);
     }
@@ -1563,7 +1571,7 @@ static bool setArrayObj(jobjectArray arr
 
     if (obj == Py_None)
       jobj = NULL;
-    else if (PyString_Check(obj) || PyUnicode_Check(obj))
+    else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
     {
         jobj = env->fromPyString(obj);
         deleteLocal = true;
@@ -1582,14 +1590,14 @@ static bool setArrayObj(jobjectArray arr
         jobj = env->boxDouble(PyFloat_AS_DOUBLE(obj));
         deleteLocal = true;
     }
-    else if (PyInt_Check(obj))
-    {
-        jobj = env->boxInteger(PyInt_AS_LONG(obj));
-        deleteLocal = true;
-    }
     else if (PyLong_Check(obj))
     {
-        jobj = env->boxLong(PyLong_AsLongLong(obj));
+        long long value = PyLong_AsLongLong(obj);
+
+        if (static_cast<long long>(static_cast<int>(value)) == value)
+          jobj = env->boxInteger((int) value);
+        else
+          jobj = env->boxLong(value);
         deleteLocal = true;
     }
     else
@@ -1700,7 +1708,7 @@ void installType(PyTypeObject *type, PyO
         Py_INCREF(type);
         if (isExtension)
         {
-            type->ob_type = &PY_TYPE(FinalizerClass);
+            Py_TYPE(type) = &PY_TYPE(FinalizerClass);
             Py_INCREF(&PY_TYPE(FinalizerClass));
         }
         PyModule_AddObject(module, name, (PyObject *) type);
@@ -1709,14 +1717,15 @@ void installType(PyTypeObject *type, PyO
 
 PyObject *wrapType(PyTypeObject *type, const jobject& obj)
 {
-    static PyObject *wrapfn_ = PyString_FromString("wrapfn_");
+    static PyObject *wrapfn_ = PyUnicode_FromString("wrapfn_");
     PyObject *cobj = PyObject_GetAttr((PyObject *) type, wrapfn_);
     PyObject *(*wrapfn)(const jobject&);
-    
+
     if (cobj == NULL)
         return NULL;
 
-    wrapfn = (PyObject *(*)(const jobject &)) PyCObject_AsVoidPtr(cobj);
+    wrapfn = (PyObject *(*)(const jobject &))
+        PyCapsule_GetPointer(cobj, "wrapfn");
     Py_DECREF(cobj);
 
     return wrapfn(obj);
@@ -1732,7 +1741,7 @@ PyObject *unboxBoolean(const jobject& ob
                             (PyObject *) &java::lang::PY_TYPE(Boolean));
             return NULL;
         }
-        
+
         if (env->booleanValue(obj))
             Py_RETURN_TRUE;
 
@@ -1752,8 +1761,8 @@ PyObject *unboxByte(const jobject &obj)
                             (PyObject *) &java::lang::PY_TYPE(Byte));
             return NULL;
         }
-        
-        return PyInt_FromLong((long) env->byteValue(obj));
+
+        return PyLong_FromLong((long) env->byteValue(obj));
     }
 
     Py_RETURN_NONE;
@@ -1769,9 +1778,8 @@ PyObject *unboxCharacter(const jobject &
                             (PyObject *) &java::lang::PY_TYPE(Character));
             return NULL;
         }
-        
-        jchar c = env->charValue(obj);
-        return PyUnicode_FromUnicode((Py_UNICODE *) &c, 1);
+
+        return c2p(env->charValue(obj));
     }
 
     Py_RETURN_NONE;
@@ -1787,7 +1795,7 @@ PyObject *unboxDouble(const jobject &obj
                             (PyObject *) &java::lang::PY_TYPE(Double));
             return NULL;
         }
-        
+
         return PyFloat_FromDouble((double) env->doubleValue(obj));
     }
 
@@ -1804,7 +1812,7 @@ PyObject *unboxFloat(const jobject &obj)
                             (PyObject *) &java::lang::PY_TYPE(Float));
             return NULL;
         }
-        
+
         return PyFloat_FromDouble((double) env->floatValue(obj));
     }
 
@@ -1821,8 +1829,8 @@ PyObject *unboxInteger(const jobject &ob
                             (PyObject *) &java::lang::PY_TYPE(Integer));
             return NULL;
         }
-        
-        return PyInt_FromLong((long) env->intValue(obj));
+
+        return PyLong_FromLong((long) env->intValue(obj));
     }
 
     Py_RETURN_NONE;
@@ -1838,7 +1846,7 @@ PyObject *unboxLong(const jobject &obj)
                             (PyObject *) &java::lang::PY_TYPE(Long));
             return NULL;
         }
-        
+
         return PyLong_FromLongLong((PY_LONG_LONG) env->longValue(obj));
     }
 
@@ -1855,8 +1863,8 @@ PyObject *unboxShort(const jobject &obj)
                             (PyObject *) &java::lang::PY_TYPE(Short));
             return NULL;
         }
-        
-        return PyInt_FromLong((long) env->shortValue(obj));
+
+        return PyLong_FromLong((long) env->shortValue(obj));
     }
 
     Py_RETURN_NONE;
@@ -1872,7 +1880,7 @@ PyObject *unboxString(const jobject &obj
                             (PyObject *) &java::lang::PY_TYPE(String));
             return NULL;
         }
-        
+
         return env->fromJString((jstring) obj, 0);
     }
 
@@ -1945,22 +1953,9 @@ int boxByte(PyTypeObject *type, PyObject
     if (result <= 0)
         return result;
 
-    if (PyInt_Check(arg))
-    {
-        int n = PyInt_AS_LONG(arg);
-        jbyte b = (jbyte) n;
-
-        if (b == n)
-        {
-            if (obj != NULL)
-                *obj = Byte(b);
-        }
-        else
-            return -1;
-    }
-    else if (PyLong_Check(arg))
+    if (PyLong_Check(arg))
     {
-        PY_LONG_LONG ln = PyLong_AsLongLong(arg);
+        long ln = PyLong_AS_LONG(arg);
         jbyte b = (jbyte) ln;
 
         if (b == ln)
@@ -1997,12 +1992,12 @@ int boxCharacter(PyTypeObject *type, PyO
     if (result <= 0)
         return result;
 
-    if (PyString_Check(arg))
+    if (PyBytes_Check(arg))
     {
         char *c;
         Py_ssize_t len;
 
-        if (PyString_AsStringAndSize(arg, &c, &len) < 0 || len != 1)
+        if (PyBytes_AsStringAndSize(arg, &c, &len) < 0 || len != 1)
             return -1;
 
         if (obj != NULL)
@@ -2010,13 +2005,13 @@ int boxCharacter(PyTypeObject *type, PyO
     }
     else if (PyUnicode_Check(arg))
     {
-        Py_ssize_t len = PyUnicode_GetSize(arg);
+        Py_ssize_t len = PyUnicode_GetLength(arg);
 
         if (len != 1)
             return -1;
 
         if (obj != NULL)
-            *obj = Character((jchar) PyUnicode_AsUnicode(arg)[0]);
+          *obj = Character((jchar) PyUnicode_READ_CHAR(arg, 0));
     }
     else
         return -1;
@@ -2031,7 +2026,7 @@ int boxCharSequence(PyTypeObject *type,
     if (result <= 0)
         return result;
 
-    if (PyString_Check(arg) || PyUnicode_Check(arg))
+    if (PyBytes_Check(arg) || PyUnicode_Check(arg))
     {
         if (obj != NULL)
         {
@@ -2042,7 +2037,7 @@ int boxCharSequence(PyTypeObject *type,
     }
     else
         return -1;
-    
+
     return 0;
 }
 
@@ -2053,12 +2048,7 @@ int boxDouble(PyTypeObject *type, PyObje
     if (result <= 0)
         return result;
 
-    if (PyInt_Check(arg))
-    {
-        if (obj != NULL)
-            *obj = Double((jdouble) PyInt_AS_LONG(arg));
-    }
-    else if (PyLong_Check(arg))
+    if (PyLong_Check(arg))
     {
         if (obj != NULL)
             *obj = Double((jdouble) PyLong_AsLongLong(arg));
@@ -2081,12 +2071,7 @@ int boxFloat(PyTypeObject *type, PyObjec
     if (result <= 0)
         return result;
 
-    if (PyInt_Check(arg))
-    {
-        if (obj != NULL)
-            *obj = Float((jfloat) PyInt_AS_LONG(arg));
-    }
-    else if (PyLong_Check(arg))
+    if (PyLong_Check(arg))
     {
         PY_LONG_LONG ln = PyLong_AsLongLong(arg);
         float f = (float) ln;
@@ -2125,12 +2110,7 @@ int boxInteger(PyTypeObject *type, PyObj
     if (result <= 0)
         return result;
 
-    if (PyInt_Check(arg))
-    {
-        if (obj != NULL)
-            *obj = Integer((jint) PyInt_AS_LONG(arg));
-    }
-    else if (PyLong_Check(arg))
+    if (PyLong_Check(arg))
     {
         PY_LONG_LONG ln = PyLong_AsLongLong(arg);
         int n = (int) ln;
@@ -2169,12 +2149,7 @@ int boxLong(PyTypeObject *type, PyObject
     if (result <= 0)
         return result;
 
-    if (PyInt_Check(arg))
-    {
-        if (obj != NULL)
-            *obj = Long((jlong) PyInt_AS_LONG(arg));
-    }
-    else if (PyLong_Check(arg))
+    if (PyLong_Check(arg))
     {
         if (obj != NULL)
             *obj = Long((jlong) PyLong_AsLongLong(arg));
@@ -2205,15 +2180,17 @@ int boxNumber(PyTypeObject *type, PyObje
     if (result <= 0)
         return result;
 
-    if (PyInt_Check(arg))
-    {
-        if (obj != NULL)
-            *obj = Integer((jint) PyInt_AS_LONG(arg));
-    }
-    else if (PyLong_Check(arg))
+    if (PyLong_Check(arg))
     {
         if (obj != NULL)
-            *obj = Long((jlong) PyLong_AsLongLong(arg));
+        {
+            long long value = PyLong_AsLongLong(arg);
+
+            if (static_cast<long long>(static_cast<int>(value)) == value)
+              *obj = Integer((jint) value);
+            else
+              *obj = Long((jlong) value);
+        }
     }
     else if (PyFloat_Check(arg))
     {
@@ -2233,20 +2210,7 @@ int boxShort(PyTypeObject *type, PyObjec
     if (result <= 0)
         return result;
 
-    if (PyInt_Check(arg))
-    {
-        int n = (int) PyInt_AS_LONG(arg);
-        short sn = (short) n;
-
-        if (sn == n)
-        {
-            if (obj != NULL)
-                *obj = Short((jshort) sn);
-        }
-        else
-            return -1;
-    }
-    else if (PyLong_Check(arg))
+    if (PyLong_Check(arg))
     {
         PY_LONG_LONG ln = PyLong_AsLongLong(arg);
         short sn = (short) ln;
@@ -2285,7 +2249,7 @@ int boxString(PyTypeObject *type, PyObje
     if (result <= 0)
         return result;
 
-    if (PyString_Check(arg) || PyUnicode_Check(arg))
+    if (PyBytes_Check(arg) || PyUnicode_Check(arg))
     {
         if (obj != NULL)
         {
@@ -2309,7 +2273,7 @@ int boxObject(PyTypeObject *type, PyObje
 
     if (obj != NULL)
     {
-        if (PyString_Check(arg) || PyUnicode_Check(arg))
+        if (PyBytes_Check(arg) || PyUnicode_Check(arg))
         {
             *obj = p2j(arg);
             if (PyErr_Occurred())
@@ -2319,27 +2283,23 @@ int boxObject(PyTypeObject *type, PyObje
             *obj = *Boolean::TRUE;
         else if (arg == Py_False)
             *obj = *Boolean::FALSE;
-        else if (PyInt_Check(arg))
+        else if (PyLong_Check(arg))
         {
-            long ln = PyInt_AS_LONG(arg);
-            int n = (int) ln;
+            long long value = PyLong_AsLongLong(arg);
 
-            if (ln != (long) n)
-                *obj = Long((jlong) ln);
+            if (static_cast<long long>(static_cast<int>(value)) == value)
+              *obj = Integer((jint) value);
             else
-                *obj = Integer((jint) n);
+              *obj = Long((jlong) value);
         }
-        else if (PyLong_Check(arg))
-            *obj = Long((jlong) PyLong_AsLongLong(arg));
         else if (PyFloat_Check(arg))
             *obj = Double((jdouble) PyFloat_AS_DOUBLE(arg));
         else
             return -1;
     }
-    else if (!(PyString_Check(arg) || PyUnicode_Check(arg) ||
+    else if (!(PyBytes_Check(arg) || PyUnicode_Check(arg) ||
                arg == Py_True || arg == Py_False ||
-               PyInt_Check(arg) || PyLong_Check(arg) ||
-               PyFloat_Check(arg)))
+               PyLong_Check(arg) || PyFloat_Check(arg)))
         return -1;
 
     return 0;
@@ -2354,7 +2314,7 @@ PyObject *typeParameters(PyTypeObject *t
 
     for (size_t i = 0; i < count; i++) {
         PyObject *type = (PyObject *) types[i];
-        
+
         if (type == NULL)
             type = Py_None;
 

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/functions.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/functions.h?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/functions.h (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/functions.h Sun Mar 19 20:26:48 2017
@@ -21,15 +21,6 @@
 #include "java/lang/Object.h"
 #include "macros.h"
 
-#if PY_VERSION_HEX < 0x02050000
-typedef int Py_ssize_t;
-typedef inquiry lenfunc;
-typedef intargfunc ssizeargfunc;
-typedef intintargfunc ssizessizeargfunc;
-typedef intobjargproc ssizeobjargproc;
-typedef intintobjargproc ssizessizeobjargproc;
-#endif
-
 typedef PyTypeObject **(*getparametersfn)(void *);
 typedef int (*boxfn)(PyTypeObject *, PyObject *, java::lang::Object *);
 
@@ -60,7 +51,7 @@ int _parseArgs(PyObject **args, unsigned
 
 #define parseArgs(args, types, rest...) \
     _parseArgs(((PyTupleObject *)(args))->ob_item, \
-               ((PyTupleObject *)(args))->ob_size, types, ##rest)
+               ((PyTupleObject *)(args))->ob_base.ob_size, types, ##rest)
 
 #define parseArg(arg, types, rest...) \
     _parseArgs(&(arg), 1, types, ##rest)
@@ -95,8 +86,9 @@ int boxShort(PyTypeObject *type, PyObjec
 int boxString(PyTypeObject *type, PyObject *arg, java::lang::Object *obj);
 int boxObject(PyTypeObject *type, PyObject *arg, java::lang::Object *obj);
 
-PyObject *j2p(const java::lang::String& js);
 java::lang::String p2j(PyObject *object);
+PyObject *j2p(const java::lang::String& js);
+PyObject *c2p(jchar c);
 
 PyObject *make_descriptor(PyTypeObject *value);
 PyObject *make_descriptor(getclassfn initializeClass);

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp Sun Mar 19 20:26:48 2017
@@ -38,7 +38,7 @@ public:
     PyObject_HEAD
     JCCEnv *env;
 };
-    
+
 static void t_jccenv_dealloc(t_jccenv *self);
 static PyObject *t_jccenv_attachCurrentThread(PyObject *self, PyObject *args);
 static PyObject *t_jccenv_detachCurrentThread(PyObject *self);
@@ -83,8 +83,7 @@ static PyMethodDef t_jccenv_methods[] =
 };
 
 PyTypeObject PY_TYPE(JCCEnv) = {
-    PyObject_HEAD_INIT(NULL)
-    0,                                   /* ob_size */
+    PyVarObject_HEAD_INIT(NULL, 0)
     "jcc.JCCEnv",                        /* tp_name */
     sizeof(t_jccenv),                    /* tp_basicsize */
     0,                                   /* tp_itemsize */
@@ -92,7 +91,7 @@ PyTypeObject PY_TYPE(JCCEnv) = {
     0,                                   /* tp_print */
     0,                                   /* tp_getattr */
     0,                                   /* tp_setattr */
-    0,                                   /* tp_compare */
+    0,                                   /* tp_reserved */
     0,                                   /* tp_repr */
     0,                                   /* tp_as_number */
     0,                                   /* tp_as_sequence */
@@ -126,26 +125,27 @@ PyTypeObject PY_TYPE(JCCEnv) = {
 
 static void t_jccenv_dealloc(t_jccenv *self)
 {
-    self->ob_type->tp_free((PyObject *) self);
+    self->ob_base.ob_type->tp_free((PyObject *) self);
 }
 
-static void add_option(char *name, char *value, JavaVMOption *option)
+static void add_option(char *name, const char *value, JavaVMOption *option)
 {
-    char *buf = new char[strlen(name) + strlen(value) + 1];
+    char *buf = (char *) malloc(strlen(name) + strlen(value) + 1);
 
     sprintf(buf, "%s%s", name, value);
     option->optionString = buf;
 }
 
 #ifdef _jcc_lib
-static void add_paths(char *name, char *p0, char *p1, JavaVMOption *option)
+static void add_paths(char *name, const char *p0, const char *p1,
+                      JavaVMOption *option)
 {
 #if defined(_MSC_VER) || defined(__WIN32)
     char pathsep = ';';
 #else
     char pathsep = ':';
 #endif
-    char *buf = new char[strlen(name) + strlen(p0) + strlen(p1) + 4];
+    char *buf = (char *) malloc(strlen(name) + strlen(p0) + strlen(p1) + 4);
 
     sprintf(buf, "%s%s%c%s", name, p0, pathsep, p1);
     option->optionString = buf;
@@ -162,8 +162,8 @@ static PyObject *t_jccenv_attachCurrentT
         return NULL;
 
     result = env->attachCurrentThread(name, asDaemon);
-        
-    return PyInt_FromLong(result);
+
+    return PyLong_FromLong(result);
 }
 
 static PyObject *t_jccenv_detachCurrentThread(PyObject *self)
@@ -172,7 +172,7 @@ static PyObject *t_jccenv_detachCurrentT
 
     env->set_vm_env(NULL);
 
-    return PyInt_FromLong(result);
+    return PyLong_FromLong(result);
 }
 
 static PyObject *t_jccenv_isCurrentThreadAttached(PyObject *self)
@@ -194,11 +194,12 @@ static PyObject *t_jccenv_isShared(PyObj
 
 static PyObject *t_jccenv_strhash(PyObject *self, PyObject *arg)
 {
-    int hash = PyObject_Hash(arg);
-    char buffer[10];
+    long hash = PyObject_Hash(arg);
+    size_t hexdig = sizeof(long) * 2;
+    char buffer[hexdig + 1];
 
-    sprintf(buffer, "%08x", (unsigned int) hash);
-    return PyString_FromStringAndSize(buffer, 8);
+    sprintf(buffer, "%0*lx", (int) hexdig, (unsigned long) hash);
+    return PyUnicode_FromStringAndSize(buffer, hexdig);
 }
 
 static PyObject *t_jccenv__dumpRefs(PyObject *self,
@@ -227,13 +228,13 @@ static PyObject *t_jccenv__dumpRefs(PyOb
         if (classes)  // return dict of { class name: instance count }
         {
             char *name = env->getClassName(iter->second.global);
-            PyObject *key = PyString_FromString(name);
+            PyObject *key = PyUnicode_FromString(name);
             PyObject *value = PyDict_GetItem(result, key);
 
             if (value == NULL)
-                value = PyInt_FromLong(1);
+                value = PyLong_FromLong(1);
             else
-                value = PyInt_FromLong(PyInt_AS_LONG(value) + 1);
+                value = PyLong_FromLong(PyLong_AsLong(value) + 1);
 
             PyDict_SetItem(result, key, value);
             Py_DECREF(key);
@@ -244,14 +245,10 @@ 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 = PyString_FromString(str);
-            PyObject *value = PyInt_FromLong(iter->second.count);
+            PyObject *key = PyUnicode_FromString(str);
+            PyObject *value = PyLong_FromLong(iter->second.count);
 
-#if PY_VERSION_HEX < 0x02040000
-            PyList_SET_ITEM(result, count++, Py_BuildValue("(OO)", key, value));
-#else
             PyList_SET_ITEM(result, count++, PyTuple_Pack(2, key, value));
-#endif
             Py_DECREF(key);
             Py_DECREF(value);
 
@@ -259,14 +256,10 @@ static PyObject *t_jccenv__dumpRefs(PyOb
         }
         else  // return list of (id hash code, ref count)
         {
-            PyObject *key = PyInt_FromLong(iter->first);
-            PyObject *value = PyInt_FromLong(iter->second.count);
+            PyObject *key = PyLong_FromLong(iter->first);
+            PyObject *value = PyLong_FromLong(iter->second.count);
 
-#if PY_VERSION_HEX < 0x02040000
-            PyList_SET_ITEM(result, count++, Py_BuildValue("(OO)", key, value));
-#else
             PyList_SET_ITEM(result, count++, PyTuple_Pack(2, key, value));
-#endif
             Py_DECREF(key);
             Py_DECREF(value);
         }
@@ -289,7 +282,7 @@ static PyObject *t_jccenv__addClassPath(
 
 static PyObject *t_jccenv__get_jni_version(PyObject *self, void *data)
 {
-    return PyInt_FromLong(env->getJNIVersion());
+    return PyLong_FromLong(env->getJNIVersion());
 }
 
 static PyObject *t_jccenv__get_java_version(PyObject *self, void *data)
@@ -303,7 +296,7 @@ static PyObject *t_jccenv__get_classpath
 
     if (classpath)
     {
-        PyObject *result = PyString_FromString(classpath);
+        PyObject *result = PyUnicode_FromString(classpath);
 
         free(classpath);
         return result;
@@ -334,9 +327,9 @@ _DLL_EXPORT PyObject *initJCC(PyObject *
     static int _once_only = 1;
 #if defined(_MSC_VER) || defined(__WIN32)
 #define verstring(n) #n
-    PyObject *ver = PyString_FromString(verstring(JCC_VER));
+    PyObject *ver = PyUnicode_FromString(verstring(JCC_VER));
 #else
-    PyObject *ver = PyString_FromString(JCC_VER);
+    PyObject *ver = PyUnicode_FromString(JCC_VER);
 #endif
     PyObject_SetAttrString(module, "JCC_VERSION", ver); Py_DECREF(ver);
 
@@ -361,7 +354,7 @@ _DLL_EXPORT PyObject *initVM(PyObject *s
         "classpath", "initialheap", "maxheap", "maxstack",
         "vmargs", NULL
     };
-    char *classpath = NULL;
+    const char *classpath = NULL;
     char *initialheap = NULL, *maxheap = NULL, *maxstack = NULL;
     PyObject *vmargs = NULL;
 
@@ -385,8 +378,8 @@ _DLL_EXPORT PyObject *initVM(PyObject *s
         if (classpath == NULL && self != NULL)
         {
             module_cp = PyObject_GetAttrString(self, "CLASSPATH");
-            if (module_cp != NULL)
-                classpath = PyString_AsString(module_cp);
+            if (module_cp)
+                classpath = PyUnicode_AsUTF8(module_cp);
         }
 
         if (classpath && classpath[0])
@@ -411,8 +404,8 @@ _DLL_EXPORT PyObject *initVM(PyObject *s
         if (classpath == NULL && self != NULL)
         {
             module_cp = PyObject_GetAttrString(self, "CLASSPATH");
-            if (module_cp != NULL)
-                classpath = PyString_AsString(module_cp);
+            if (module_cp)
+                classpath = PyUnicode_AsUTF8(module_cp);
         }
 
 #ifdef _jcc_lib
@@ -420,12 +413,12 @@ _DLL_EXPORT PyObject *initVM(PyObject *s
         PyObject *cp = PyObject_GetAttrString(jcc, "CLASSPATH");
 
         if (classpath)
-            add_paths("-Djava.class.path=", PyString_AsString(cp), classpath,
+            add_paths("-Djava.class.path=", PyUnicode_AsUTF8(cp), classpath,
                       &vm_options[nOptions++]);
         else
-            add_option("-Djava.class.path=", PyString_AsString(cp),
+            add_option("-Djava.class.path=", PyUnicode_AsUTF8(cp),
                        &vm_options[nOptions++]);
-            
+
         Py_DECREF(cp);
         Py_DECREF(jcc);
 #else
@@ -443,12 +436,12 @@ _DLL_EXPORT PyObject *initVM(PyObject *s
         if (maxstack)
             add_option("-Xss", maxstack, &vm_options[nOptions++]);
 
-        if (vmargs != NULL && PyString_Check(vmargs))
+        if (vmargs != NULL && PyUnicode_Check(vmargs))
         {
 #ifdef _MSC_VER
-            char *buf = _strdup(PyString_AS_STRING(vmargs));
+            char *buf = _strdup(PyUnicode_AsUTF8(vmargs));
 #else
-            char *buf = strdup(PyString_AS_STRING(vmargs));
+            char *buf = strdup(PyUnicode_AsUTF8(vmargs));
 #endif
             char *sep = ",";
             char *option;
@@ -480,9 +473,9 @@ _DLL_EXPORT PyObject *initVM(PyObject *s
             for (int i = 0; i < PySequence_Fast_GET_SIZE(fast); ++i) {
                 PyObject *arg = PySequence_Fast_GET_ITEM(fast, i);
 
-                if (PyString_Check(arg))
+                if (PyUnicode_Check(arg))
                 {
-                    char *option = PyString_AS_STRING(arg);
+                    char *option = PyUnicode_AsUTF8(arg);
 
                     if (nOptions < sizeof(vm_options) / sizeof(JavaVMOption))
                         add_option("", option, &vm_options[nOptions++]);
@@ -558,7 +551,7 @@ _DLL_EXPORT PyObject *getJavaModule(PyOb
     if (parent[0] == '\0')
     {
         parent_module = NULL;
-        full_name = PyString_FromString(name);
+        full_name = PyUnicode_FromString(name);
     }
     else if ((parent_module = PyDict_GetItemString(modules, parent)) == NULL)
     {
@@ -566,13 +559,13 @@ _DLL_EXPORT PyObject *getJavaModule(PyOb
         return NULL;
     }
     else
-        full_name = PyString_FromFormat("%s.%s", parent, name);
+        full_name = PyUnicode_FromFormat("%s.%s", parent, name);
 
     PyObject *child_module = PyDict_GetItem(modules, full_name);
 
     if (child_module == NULL)
     {
-        child_module = PyModule_New(PyString_AS_STRING(full_name));
+        child_module = PyModule_New(PyUnicode_AsUTF8(full_name));
         if (child_module != NULL)
         {
             if (parent_module != NULL)
@@ -589,7 +582,7 @@ _DLL_EXPORT PyObject *getJavaModule(PyOb
      */
     if (child_module != NULL)
     {
-        PyObject *__file__ = PyString_FromString("__file__");
+        PyObject *__file__ = PyUnicode_FromString("__file__");
         PyObject *file = PyDict_GetItem(PyModule_GetDict(module), __file__);
 
         if (file != NULL)
@@ -620,7 +613,8 @@ static void _PythonVM_init(JNIEnv *vm_en
     dlopen(buf, RTLD_NOW | RTLD_GLOBAL);
 #endif
 
-    Py_SetProgramName((char *) str);
+    Py_SetProgramName(Py_DecodeLocale(str, NULL));  // leaked to python vm
+    vm_env->ReleaseStringUTFChars(programName, str);
 
     PyEval_InitThreads();
     Py_Initialize();
@@ -628,26 +622,26 @@ static void _PythonVM_init(JNIEnv *vm_en
     if (args)
     {
         int argc = vm_env->GetArrayLength(args);
-        char **argv = (char **) calloc(argc + 1, sizeof(char *));
+        wchar_t **argv = (wchar_t **) calloc(argc + 1, sizeof(wchar_t *));
 
-        argv[0] = (char *) str;
+        argv[0] = Py_GetProgramName();
         for (int i = 0; i < argc; i++) {
             jstring arg = (jstring) vm_env->GetObjectArrayElement(args, i);
-            argv[i + 1] = (char *) vm_env->GetStringUTFChars(arg, JNI_FALSE);
+            const char *str = vm_env->GetStringUTFChars(arg, JNI_FALSE);
+
+            argv[i + 1] = Py_DecodeLocale(str, NULL);  // leaked to python vm
+            vm_env->ReleaseStringUTFChars(arg, str);
         }
 
         PySys_SetArgv(argc + 1, argv);
-
-        for (int i = 0; i < argc; i++) {
-            jstring arg = (jstring) vm_env->GetObjectArrayElement(args, i);
-            vm_env->ReleaseStringUTFChars(arg, argv[i + 1]);
-        }
         free(argv);
     }
     else
-        PySys_SetArgv(1, (char **) &str);
+    {
+        wchar_t *py_program_name = Py_GetProgramName();
+        PySys_SetArgv(1, &py_program_name);
+    }
 
-    vm_env->ReleaseStringUTFChars(programName, str);
     PyEval_ReleaseLock();
 }
 
@@ -657,8 +651,7 @@ static jobject _PythonVM_instantiate(JNI
     PythonGIL gil(vm_env);
 
     const char *modStr = vm_env->GetStringUTFChars(moduleName, JNI_FALSE);
-    PyObject *module =
-        PyImport_ImportModule((char *) modStr);  // python 2.4 cast
+    PyObject *module = PyImport_ImportModule(modStr);
 
     vm_env->ReleaseStringUTFChars(moduleName, modStr);
 
@@ -669,8 +662,7 @@ static jobject _PythonVM_instantiate(JNI
     }
 
     const char *clsStr = vm_env->GetStringUTFChars(className, JNI_FALSE);
-    PyObject *cls =
-        PyObject_GetAttrString(module, (char *) clsStr); // python 2.4 cast
+    PyObject *cls = PyObject_GetAttrString(module, clsStr);
     PyObject *obj;
     jobject jobj;
 
@@ -702,7 +694,7 @@ static jobject _PythonVM_instantiate(JNI
         return NULL;
     }
 
-    jobj = (jobject) PyCObject_AsVoidPtr(cObj);
+    jobj = (jobject) PyCapsule_GetPointer(cObj, "jobject");
     Py_DECREF(cObj);
 
     jobj = vm_env->NewLocalRef(jobj);
@@ -767,7 +759,7 @@ static void JNICALL _PythonException_pyt
     jclass jcls = vm_env->GetObjectClass(self);
     jfieldID fid = vm_env->GetFieldID(jcls, "py_error_state", "J");
     PyObject *state = (PyObject *) vm_env->GetLongField(self, fid);
-    
+
     if (state != NULL)
     {
         PythonGIL gil(vm_env);
@@ -819,7 +811,7 @@ static jstring JNICALL _PythonException_
     jclass jcls = vm_env->GetObjectClass(self);
     jfieldID fid = vm_env->GetFieldID(jcls, "py_error_state", "J");
     PyObject *state = (PyObject *) vm_env->GetLongField(self, fid);
-    
+
     if (state == NULL)
         return NULL;
 
@@ -844,7 +836,7 @@ static jstring JNICALL _PythonException_
     jclass jcls = vm_env->GetObjectClass(self);
     jfieldID fid = vm_env->GetFieldID(jcls, "py_error_state", "J");
     PyObject *state = (PyObject *) vm_env->GetLongField(self, fid);
-    
+
     if (state == NULL)
         return NULL;
 

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/macros.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/macros.h?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/macros.h (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/macros.h Sun Mar 19 20:26:48 2017
@@ -68,8 +68,7 @@
 #define DECLARE_TYPE(name, t_name, base, javaClass,                         \
                      init, iter, iternext, getset, mapping, sequence)       \
 PyTypeObject PY_TYPE(name) = {                                              \
-    PyObject_HEAD_INIT(NULL)                                                \
-    /* ob_size            */   0,                                           \
+    PyVarObject_HEAD_INIT(NULL, 0)                                          \
     /* tp_name            */   #name,                                       \
     /* tp_basicsize       */   sizeof(t_name),                              \
     /* tp_itemsize        */   0,                                           \
@@ -162,32 +161,4 @@ PyObject *t_name::wrap_jobject(const job
         return (PyObject *) self;                           \
     }
 
-
-#if PY_VERSION_HEX < 0x02040000
-
-#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
-#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
-#define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
-
-#define Py_CLEAR(op)                            \
-    do {                                        \
-        if (op) {                               \
-            PyObject *tmp = (PyObject *)(op);   \
-            (op) = NULL;                        \
-            Py_DECREF(tmp);                     \
-        }                                       \
-    } while (0)
-
-#define Py_VISIT(op)                                    \
-    do {                                                \
-        if (op) {                                       \
-            int vret = visit((PyObject *)(op), arg);    \
-            if (vret)                                   \
-                return vret;                            \
-        }                                               \
-    } while (0)
-          
-#endif /* Python 2.3.5 */
-
-
 #endif /* _macros_H */

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/types.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/types.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/types.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/types.cpp Sun Mar 19 20:26:48 2017
@@ -44,17 +44,13 @@ static PyObject *t_fp_seq_get(t_fp *self
 static int t_fp_seq_contains(t_fp *self, PyObject *value);
 static PyObject *t_fp_seq_concat(t_fp *self, PyObject *arg);
 static PyObject *t_fp_seq_repeat(t_fp *self, Py_ssize_t n);
-static PyObject *t_fp_seq_getslice(t_fp *self, Py_ssize_t low, Py_ssize_t high);
 static int t_fp_seq_set(t_fp *self, Py_ssize_t i, PyObject *value);
-static int t_fp_seq_setslice(t_fp *self, Py_ssize_t low,
-                             Py_ssize_t high, PyObject *arg);
 static PyObject *t_fp_seq_inplace_concat(t_fp *self, PyObject *arg);
 static PyObject *t_fp_seq_inplace_repeat(t_fp *self, Py_ssize_t n);
 
 
 PyTypeObject PY_TYPE(FinalizerClass) = {
-    PyObject_HEAD_INIT(NULL)
-    0,                                   /* ob_size */
+    PyVarObject_HEAD_INIT(NULL, 0)
     "jcc.FinalizerClass",                /* tp_name */
     PyType_Type.tp_basicsize,            /* tp_basicsize */
     0,                                   /* tp_itemsize */
@@ -62,7 +58,7 @@ PyTypeObject PY_TYPE(FinalizerClass) = {
     0,                                   /* tp_print */
     0,                                   /* tp_getattr */
     0,                                   /* tp_setattr */
-    0,                                   /* tp_compare */
+    0,                                   /* tp_reserved */
     0,                                   /* tp_repr */
     0,                                   /* tp_as_number */
     0,                                   /* tp_as_sequence */
@@ -105,17 +101,16 @@ static PySequenceMethods t_fp_as_sequenc
     (binaryfunc)t_fp_seq_concat,              /* sq_concat */
     (ssizeargfunc)t_fp_seq_repeat,            /* sq_repeat */
     (ssizeargfunc)t_fp_seq_get,               /* sq_item */
-    (ssizessizeargfunc)t_fp_seq_getslice,     /* sq_slice */
+    0,                                        /* was_sq_slice */
     (ssizeobjargproc)t_fp_seq_set,            /* sq_ass_item */
-    (ssizessizeobjargproc)t_fp_seq_setslice,  /* sq_ass_slice */
+    0,                                        /* was_sq_ass_slice */
     (objobjproc)t_fp_seq_contains,            /* sq_contains */
     (binaryfunc)t_fp_seq_inplace_concat,      /* sq_inplace_concat */
     (ssizeargfunc)t_fp_seq_inplace_repeat,    /* sq_inplace_repeat */
 };
 
 PyTypeObject PY_TYPE(FinalizerProxy) = {
-    PyObject_HEAD_INIT(NULL)
-    0,                                   /* ob_size */
+    PyVarObject_HEAD_INIT(NULL, 0)
     "jcc.FinalizerProxy",                /* tp_name */
     sizeof(t_fp),                        /* tp_basicsize */
     0,                                   /* tp_itemsize */
@@ -123,7 +118,7 @@ PyTypeObject PY_TYPE(FinalizerProxy) = {
     0,                                   /* tp_print */
     0,                                   /* tp_getattr */
     0,                                   /* tp_setattr */
-    0,                                   /* tp_compare */
+    0,                                   /* tp_reserved */
     (reprfunc)t_fp_repr,                 /* tp_repr */
     0,                                   /* tp_as_number */
     &t_fp_as_sequence,                   /* tp_as_sequence */
@@ -177,7 +172,7 @@ static void t_fp_dealloc(t_fp *self)
         ((t_JObject *) self->object)->object.weaken$();
 
     t_fp_clear(self);
-    self->ob_type->tp_free((PyObject *) self);
+    self->ob_base.ob_type->tp_free((PyObject *) self);
 }
 
 static int t_fp_traverse(t_fp *self, visitproc visit, void *arg)
@@ -255,22 +250,11 @@ static PyObject *t_fp_seq_repeat(t_fp *s
     return PySequence_Repeat(self->object, n);
 }
 
-static PyObject *t_fp_seq_getslice(t_fp *self, Py_ssize_t low, Py_ssize_t high)
-{
-    return PySequence_GetSlice(self->object, low, high);
-}
-
 static int t_fp_seq_set(t_fp *self, Py_ssize_t i, PyObject *value)
 {
     return PySequence_SetItem(self->object, i, value);
 }
 
-static int t_fp_seq_setslice(t_fp *self, Py_ssize_t low,
-                             Py_ssize_t high, PyObject *arg)
-{
-    return PySequence_SetSlice(self->object, low, high, arg);
-}
-
 static PyObject *t_fp_seq_inplace_concat(t_fp *self, PyObject *arg)
 {
     return PySequence_InPlaceConcat(self->object, arg);
@@ -293,7 +277,7 @@ public:
         getclassfn initializeClass;
     } access;
 };
-    
+
 #define DESCRIPTOR_VALUE   0x0001
 #define DESCRIPTOR_CLASS   0x0002
 #define DESCRIPTOR_GETFN   0x0004
@@ -309,8 +293,7 @@ static PyMethodDef t_descriptor_methods[
 
 
 PyTypeObject PY_TYPE(ConstVariableDescriptor) = {
-    PyObject_HEAD_INIT(NULL)
-    0,                                   /* ob_size */
+    PyVarObject_HEAD_INIT(NULL, 0)
     "jcc.ConstVariableDescriptor",       /* tp_name */
     sizeof(t_descriptor),                /* tp_basicsize */
     0,                                   /* tp_itemsize */
@@ -318,7 +301,7 @@ PyTypeObject PY_TYPE(ConstVariableDescri
     0,                                   /* tp_print */
     0,                                   /* tp_getattr */
     0,                                   /* tp_setattr */
-    0,                                   /* tp_compare */
+    0,                                   /* tp_reserved */
     0,                                   /* tp_repr */
     0,                                   /* tp_as_number */
     0,                                   /* tp_as_sequence */
@@ -356,7 +339,7 @@ static void t_descriptor_dealloc(t_descr
     {
         Py_DECREF(self->access.value);
     }
-    self->ob_type->tp_free((PyObject *) self);
+    self->ob_base.ob_type->tp_free((PyObject *) self);
 }
 
 PyObject *make_descriptor(PyTypeObject *value)
@@ -416,12 +399,12 @@ PyObject *make_descriptor(PyObject *valu
 
 PyObject *make_descriptor(PyObject *(*wrapfn)(const jobject &))
 {
-    return make_descriptor(PyCObject_FromVoidPtr((void *) wrapfn, NULL));
+    return make_descriptor(PyCapsule_New((void *) wrapfn, "wrapfn", NULL));
 }
 
 PyObject *make_descriptor(boxfn fn)
 {
-    return make_descriptor(PyCObject_FromVoidPtr((void *) fn, NULL));
+    return make_descriptor(PyCapsule_New((void *) fn, "boxfn", NULL));
 }
 
 PyObject *make_descriptor(jboolean b)
@@ -446,7 +429,7 @@ PyObject *make_descriptor(jbyte value)
 
     if (self)
     {
-        self->access.value = PyInt_FromLong(value);
+        self->access.value = PyLong_FromLong(value);
         self->flags = DESCRIPTOR_VALUE;
     }
 
@@ -460,9 +443,7 @@ PyObject *make_descriptor(jchar value)
 
     if (self)
     {
-        Py_UNICODE pchar = (Py_UNICODE) value;
-
-        self->access.value = PyUnicode_FromUnicode(&pchar, 1);
+        self->access.value = c2p(value);
         self->flags = DESCRIPTOR_VALUE;
     }
 
@@ -504,7 +485,7 @@ PyObject *make_descriptor(jint value)
 
     if (self)
     {
-        self->access.value = PyInt_FromLong(value);
+        self->access.value = PyLong_FromLong(value);
         self->flags = DESCRIPTOR_VALUE;
     }
 
@@ -532,7 +513,7 @@ PyObject *make_descriptor(jshort value)
 
     if (self)
     {
-        self->access.value = PyInt_FromLong((short) value);
+        self->access.value = PyLong_FromLong((short) value);
         self->flags = DESCRIPTOR_VALUE;
     }
 
@@ -560,4 +541,3 @@ static PyObject *t_descriptor___get__(t_
 
     Py_RETURN_NONE;
 }
-

Modified: lucene/pylucene/trunk/jcc/jcc3/windows.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/windows.py?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/windows.py (original)
+++ lucene/pylucene/trunk/jcc/jcc3/windows.py Sun Mar 19 20:26:48 2017
@@ -10,20 +10,20 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 
-import os, _winreg
+import os, winreg
 
 
 class WindowsRegistry(object):
 
     def __init__(self):
-        self.handle = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
+        self.handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
 
     def get(self, key, name):
 
         handle = None
         try:
-            handle = _winreg.OpenKey(self.handle, key)
-            return _winreg.QueryValueEx(handle, name)[0]
+            handle = winreg.OpenKey(self.handle, key)
+            return winreg.QueryValueEx(handle, name)[0]
         finally:
             if handle is not None:
                 handle.Close()
@@ -82,4 +82,4 @@ def add_jvm_dll_directory_to_path():
         os.environ['Path'] = os.pathsep.join(path)
         return True
 
-    raise ValueError, "jvm.dll could not be found"
+    raise ValueError("jvm.dll could not be found")

Modified: lucene/pylucene/trunk/jcc/setup.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/setup.py?rev=1787656&r1=1787655&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/setup.py (original)
+++ lucene/pylucene/trunk/jcc/setup.py Sun Mar 19 20:26:48 2017
@@ -12,8 +12,14 @@
 
 import os, sys, platform, subprocess
 
-jcc_ver = '2.23'
+jcc_ver = '3.0'
 machine = platform.machine()
+using_python2 = sys.version_info < (3,)
+
+if not using_python2 and sys.version_info < (3, 5):
+    raise RuntimeError('''
+Python 3 is supported from version 3.5, you are running version %s.%s'''
+                       %(sys.version_info.major, sys.version_info.minor))
 
 if machine.startswith("iPod") or machine.startswith("iPhone"):
     platform = 'ipod'
@@ -23,7 +29,7 @@ else:
     platform = sys.platform
 
 # Add or edit the entry corresponding to your system in the JDK, INCLUDES,
-# CFLAGS, DEBUG_CFLAGS, LFLAGS and JAVAC dictionaries below. 
+# CFLAGS, DEBUG_CFLAGS, LFLAGS and JAVAC dictionaries below.
 # These entries are used to build JCC _and_ by JCC to drive compiling and
 # linking via distutils or setuptools the extensions it generated code for.
 #
@@ -38,12 +44,18 @@ else:
 if platform in ("win32", "mingw32"):
     try:
         JAVAFRAMEWORKS = None
-        from helpers.windows import JAVAHOME
+        if using_python2:
+            from helpers2.windows import JAVAHOME
+        else:
+            from helpers3.windows import JAVAHOME
     except ImportError:
         JAVAHOME = None
 elif platform in ("darwin",):
     try:
-        from helpers.darwin import JAVAHOME, JAVAFRAMEWORKS
+        if using_python2:
+            from helpers2.darwin import JAVAHOME, JAVAFRAMEWORKS
+        else:
+            from helpers3.darwin import JAVAHOME, JAVAFRAMEWORKS
     except ImportError:
         JAVAHOME = None
         JAVAFRAMEWORKS = None
@@ -209,14 +221,20 @@ try:
             enable_shared = True
 
         elif platform == 'linux2':
-            from helpers.linux import patch_setuptools
+            if using_python2:
+                from helpers2.linux import patch_setuptools
+            else:
+                from helpers3.linux import patch_setuptools
             enable_shared = patch_setuptools(with_setuptools)
 
         elif platform == 'mingw32':
             enable_shared = True
             # need to monkeypatch the CygwinCCompiler class to generate
             # jcc.lib in the correct place
-            from helpers.mingw32 import JCCMinGW32CCompiler
+            if using_python2:
+                from helpers2.mingw32 import JCCMinGW32CCompiler
+            else:
+                from helpers3.mingw32 import JCCMinGW32CCompiler
             import distutils.cygwinccompiler
             distutils.cygwinccompiler.Mingw32CCompiler = JCCMinGW32CCompiler
 
@@ -225,7 +243,7 @@ try:
 
 except ImportError:
     if sys.version_info < (2, 4):
-        raise ImportError, 'setuptools is required when using Python 2.3'
+        raise ImportError('setuptools is required when using Python 2.3')
     else:
         from distutils.core import setup, Extension
         with_setuptools = None
@@ -234,6 +252,11 @@ except ImportError:
 
 def main(debug):
 
+    if using_python2:
+        py_version_suffix = '2'
+    else:
+        py_version_suffix = '3'
+
     _jcc_argsep = os.environ.get('JCC_ARGSEP', os.pathsep)
 
     if 'JCC_INCLUDES' in os.environ:
@@ -271,11 +294,14 @@ def main(debug):
     else:
         _javadoc = JAVADOC[platform]
 
-    from helpers.build import jcc_build_py
+    if using_python2:
+        from helpers2.build import jcc_build_py
+    else:
+        from helpers3.build import jcc_build_py
 
     jcc_build_py.config_file = \
         os.path.join(os.path.dirname(os.path.abspath(__file__)),
-                     'jcc', 'config.py')
+                     'jcc%s' %(py_version_suffix), 'config.py')
     jcc_build_py.config_text = \
         '\n'.join(['',
                    'INCLUDES=%s' %(_includes),
@@ -289,12 +315,12 @@ def main(debug):
 
     extensions = []
 
-    boot = '_jcc'
+    boot = '_jcc%s' %(py_version_suffix)
 
     cflags = ['-DPYTHON'] + _cflags
     if debug:
         cflags += _debug_cflags
-    includes = _includes + [boot, 'jcc/sources']
+    includes = _includes + [boot, 'jcc%s/sources' %(py_version_suffix)]
     lflags = _lflags
     if not debug:
         if platform == 'win32':
@@ -304,12 +330,12 @@ def main(debug):
         else:
             lflags += ['-Wl,-S']
 
-    sources = ['jcc/sources/jcc.cpp',
-               'jcc/sources/JCCEnv.cpp',
-               'jcc/sources/JObject.cpp',
-               'jcc/sources/JArray.cpp',
-               'jcc/sources/functions.cpp',
-               'jcc/sources/types.cpp']
+    sources = ['jcc%s/sources/jcc.cpp' %(py_version_suffix),
+               'jcc%s/sources/JCCEnv.cpp' %(py_version_suffix),
+               'jcc%s/sources/JObject.cpp' %(py_version_suffix),
+               'jcc%s/sources/JArray.cpp' %(py_version_suffix),
+               'jcc%s/sources/functions.cpp' %(py_version_suffix),
+               'jcc%s/sources/types.cpp' %(py_version_suffix)]
     for path, dirs, names in os.walk(boot):
         for name in names:
             if name.endswith('.cpp'):
@@ -327,7 +353,8 @@ def main(debug):
 
         if platform in ('darwin', 'ipod'):
             kwds["extra_link_args"] = \
-                lflags + ['-install_name', '@rpath/libjcc.dylib',
+                lflags + ['-install_name',
+                          '@rpath/libjcc%s.dylib' %(py_version_suffix),
                           '-current_version', jcc_ver,
                           '-compatibility_version', jcc_ver]
         elif platform == 'linux2':
@@ -335,29 +362,29 @@ def main(debug):
                 lflags + ['-lpython%s.%s' %(sys.version_info[0:2])]
             kwds["force_shared"] = True    # requires jcc/patches/patch.43
         elif platform in IMPLIB_LFLAGS:
-            jcclib = 'jcc%s.lib' %(debug and '_d' or '')
+            jcclib = 'jcc%s%s.lib' %(py_version_suffix, debug and '_d' or '')
             implib_flags = ' '.join(IMPLIB_LFLAGS[platform])
             kwds["extra_link_args"] = \
-                lflags + [implib_flags %(os.path.join('jcc', jcclib))]
+                lflags + [implib_flags %(os.path.join('jcc%s' %(py_version_suffix), jcclib))]
             package_data.append(jcclib)
         else:
             kwds["extra_link_args"] = lflags
 
-        extensions.append(Library('jcc', **kwds))
+        extensions.append(Library('jcc%s' %(py_version_suffix), **kwds))
 
         args = _javac[:]
-        args.extend(('-d', 'jcc/classes'))
+        args.extend(('-d', 'jcc%s/classes' %(py_version_suffix)))
         args.append('java/org/apache/jcc/PythonVM.java')
         args.append('java/org/apache/jcc/PythonException.java')
-        if not os.path.exists('jcc/classes'):
-            os.makedirs('jcc/classes')
+        if not os.path.exists('jcc%s/classes' %(py_version_suffix)):
+            os.makedirs('jcc%s/classes' %(py_version_suffix))
         try:
             process = Popen(args, stderr=PIPE)
-        except Exception, e:
-            raise type(e), "%s: %s" %(e, args)
+        except:
+            raise sys.exc_info()[0]("%s: %s" %(sys.exc_info()[1], args))
         process.wait()
         if process.returncode != 0:
-            raise OSError, process.stderr.read()
+            raise OSError(process.stderr.read())
         package_data.append('classes/org/apache/jcc/PythonVM.class')
         package_data.append('classes/org/apache/jcc/PythonException.class')
 
@@ -365,13 +392,13 @@ def main(debug):
         args.extend(('-d', 'javadoc', '-sourcepath', 'java', 'org.apache.jcc'))
         try:
             process = Popen(args, stderr=PIPE)
-        except Exception, e:
-            raise type(e), "%s: %s" %(e, args)
+        except:
+            raise sys.exc_info()[0]("%s: %s" %(sys.exc_info()[1], args))
         process.wait()
         if process.returncode != 0:
-            raise OSError, process.stderr.read()
+            raise OSError(process.stderr.read())
 
-    extensions.append(Extension('jcc._jcc',
+    extensions.append(Extension('jcc._jcc%s' %(py_version_suffix),
                                 extra_compile_args=cflags,
                                 extra_link_args=lflags,
                                 include_dirs=includes,
@@ -394,17 +421,20 @@ def main(debug):
                         'Programming Language :: C++',
                         'Programming Language :: Java',
                         'Programming Language :: Python',
+                        'Programming Language :: Python :: 2',
+                        'Programming Language :: Python :: 3',
+                        'Programming Language :: Python :: Implementation :: CPython',
                         'Topic :: Software Development :: Code Generators',
                         'Topic :: Software Development :: Libraries :: Java Libraries'],
         'packages': ['jcc'],
-        'package_dir': {'jcc': 'jcc'},
+        'package_dir': {'jcc': 'jcc%s' %(py_version_suffix)},
         'package_data': {'jcc': package_data},
         'ext_modules': extensions,
         "cmdclass": {"build_py": jcc_build_py},
     }
     if with_setuptools:
         args['zip_safe'] = False
-        
+
     setup(**args)
 
 



Mime
View raw message