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 2010/07/12 21:30:06 UTC

svn commit: r963444 [1/2] - in /lucene/pylucene/branches/python_3/jcc: ./ _jcc/ _jcc/java/lang/ _jcc/java/lang/reflect/ helpers/ jcc/ jcc/sources/

Author: vajda
Date: Mon Jul 12 19:30:05 2010
New Revision: 963444

URL: http://svn.apache.org/viewvc?rev=963444&view=rev
Log:
   - ported jcc to Python 3.1.2

Modified:
    lucene/pylucene/branches/python_3/jcc/_jcc/boot.cpp
    lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/Class.cpp
    lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/String.cpp
    lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Constructor.cpp
    lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Field.cpp
    lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Method.cpp
    lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Modifier.cpp
    lucene/pylucene/branches/python_3/jcc/helpers/linux.py
    lucene/pylucene/branches/python_3/jcc/helpers/windows.py
    lucene/pylucene/branches/python_3/jcc/jcc/__init__.py
    lucene/pylucene/branches/python_3/jcc/jcc/__main__.py
    lucene/pylucene/branches/python_3/jcc/jcc/cpp.py
    lucene/pylucene/branches/python_3/jcc/jcc/python.py
    lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.cpp
    lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.h
    lucene/pylucene/branches/python_3/jcc/jcc/sources/JCCEnv.cpp
    lucene/pylucene/branches/python_3/jcc/jcc/sources/JObject.cpp
    lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.cpp
    lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.h
    lucene/pylucene/branches/python_3/jcc/jcc/sources/jcc.cpp
    lucene/pylucene/branches/python_3/jcc/jcc/sources/macros.h
    lucene/pylucene/branches/python_3/jcc/jcc/sources/types.cpp
    lucene/pylucene/branches/python_3/jcc/jcc/windows.py
    lucene/pylucene/branches/python_3/jcc/setup.py

Modified: lucene/pylucene/branches/python_3/jcc/_jcc/boot.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/_jcc/boot.cpp?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/_jcc/boot.cpp (original)
+++ lucene/pylucene/branches/python_3/jcc/_jcc/boot.cpp Mon Jul 12 19:30:05 2010
@@ -49,9 +49,24 @@ PyObject *__initialize__(PyObject *modul
 
 extern "C" {
 
-    void init_jcc(void)
+    static struct PyModuleDef _jccmodule = {
+        PyModuleDef_HEAD_INIT,   /* m_base     */
+        "_jcc",                  /* m_name     */
+        "_jcc module",           /* m_doc      */
+        0,                       /* m_size     */
+        jcc_funcs,               /* m_methods  */
+        0,                       /* m_reload   */
+        0,                       /* m_traverse */
+        0,                       /* m_clear    */
+        0,                       /* m_free     */
+    };
+
+    PyObject *PyInit__jcc(void)
     {
-        PyObject *m = Py_InitModule3("_jcc", jcc_funcs, "_jcc");
+        PyObject *m = PyModule_Create(&_jccmodule);
+
+        if (!m)
+            return NULL;
 
         initJCC(m);
 
@@ -59,5 +74,7 @@ extern "C" {
         INSTALL_TYPE(ConstVariableDescriptor, m);
         java::lang::__install__(m);
         java::io::__install__(m);
+
+        return m;
     }
 }

Modified: lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/Class.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/Class.cpp?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/Class.cpp (original)
+++ lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/Class.cpp Mon Jul 12 19:30:05 2010
@@ -395,17 +395,14 @@ namespace java {
 
         static PyObject *t_Class_forName(PyTypeObject *type, PyObject *arg)
         {
-            if (!PyString_Check(arg))
+            if (arg == Py_None)
             {
-                PyErr_SetObject(PyExc_TypeError, arg);
+                PyErr_SetObject(PyExc_ValueError, arg);
                 return NULL;
             }
 
             try {
-                char *className = PyString_AsString(arg);
-                String name = String(env->fromUTF(className));
-
-                return t_Class::wrap_Object(Class::forName(name));
+                return t_Class::wrap_Object(Class::forName(p2j(arg)));
             } catch (int e) {
                 switch (e) {
                   case _EXC_JAVA:
@@ -586,7 +583,7 @@ namespace java {
             jint modifiers;
 
             OBJ_CALL(modifiers = self->object.getModifiers());
-            return PyInt_FromLong(modifiers);            
+            return PyLong_FromLong(modifiers);
         }
 
 #ifdef _java_generics

Modified: lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/String.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/String.cpp?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/String.cpp (original)
+++ lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/String.cpp Mon Jul 12 19:30:05 2010
@@ -112,7 +112,7 @@ namespace java {
             jint length;
 
             OBJ_CALL(length = self->object.length());
-            return PyInt_FromLong(length);
+            return PyLong_FromLong(length);
         }
     }
 }

Modified: lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Constructor.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Constructor.cpp?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Constructor.cpp (original)
+++ lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Constructor.cpp Mon Jul 12 19:30:05 2010
@@ -159,7 +159,7 @@ namespace java {
                 jint modifiers;
 
                 OBJ_CALL(modifiers = self->object.getModifiers());
-                return PyInt_FromLong(modifiers);                
+                return PyLong_FromLong(modifiers);                
             }
 
             static PyObject *t_Constructor_getParameterTypes(t_Constructor *self)

Modified: lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Field.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Field.cpp?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Field.cpp (original)
+++ lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Field.cpp Mon Jul 12 19:30:05 2010
@@ -126,7 +126,7 @@ namespace java {
                 jint modifiers;
 
                 OBJ_CALL(modifiers = self->object.getModifiers());
-                return PyInt_FromLong(modifiers);
+                return PyLong_FromLong(modifiers);
             }
 
             static PyObject *t_Field_getType(t_Field *self)

Modified: lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Method.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Method.cpp?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Method.cpp (original)
+++ lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Method.cpp Mon Jul 12 19:30:05 2010
@@ -220,7 +220,7 @@ namespace java {
                 jint modifiers;
 
                 OBJ_CALL(modifiers = self->object.getModifiers());
-                return PyInt_FromLong(modifiers);
+                return PyLong_FromLong(modifiers);
             }
 
             static PyObject *t_Method_getReturnType(t_Method *self)

Modified: lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Modifier.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Modifier.cpp?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Modifier.cpp (original)
+++ lucene/pylucene/branches/python_3/jcc/_jcc/java/lang/reflect/Modifier.cpp Mon Jul 12 19:30:05 2010
@@ -150,105 +150,126 @@ namespace java {
 
             static PyObject *t_Modifier_isPublic(PyTypeObject *type, PyObject *arg)
             {
-                if (!PyInt_Check(arg))
+                if (!PyLong_Check(arg))
                 {
                     PyErr_SetObject(PyExc_TypeError, arg);
                     return NULL;
                 }
 
-                int mod = PyInt_AsLong(arg);
+                int mod = PyLong_AsLong(arg);
                 int isPublic;
 
+                if (PyErr_Occurred())
+                    return NULL;
+
                 OBJ_CALL(isPublic = Modifier::isPublic(mod));
                 Py_RETURN_BOOL(isPublic);
             }
 
             static PyObject *t_Modifier_isStatic(PyTypeObject *type, PyObject *arg)
             {
-                if (!PyInt_Check(arg))
+                if (!PyLong_Check(arg))
                 {
                     PyErr_SetObject(PyExc_TypeError, arg);
                     return NULL;
                 }
 
-                int mod = PyInt_AsLong(arg);
+                int mod = PyLong_AsLong(arg);
                 int isStatic;
 
+                if (PyErr_Occurred())
+                    return NULL;
+
                 OBJ_CALL(isStatic = Modifier::isStatic(mod));
                 Py_RETURN_BOOL(isStatic);
             }
 
             static PyObject *t_Modifier_isNative(PyTypeObject *type, PyObject *arg)
             {
-                if (!PyInt_Check(arg))
+                if (!PyLong_Check(arg))
                 {
                     PyErr_SetObject(PyExc_TypeError, arg);
                     return NULL;
                 }
 
-                int mod = PyInt_AsLong(arg);
+                int mod = PyLong_AsLong(arg);
                 int isNative;
 
+                if (PyErr_Occurred())
+                    return NULL;
+
                 OBJ_CALL(isNative = Modifier::isNative(mod));
                 Py_RETURN_BOOL(isNative);
             }
 
             static PyObject *t_Modifier_isFinal(PyTypeObject *type, PyObject *arg)
             {
-                if (!PyInt_Check(arg))
+                if (!PyLong_Check(arg))
                 {
                     PyErr_SetObject(PyExc_TypeError, arg);
                     return NULL;
                 }
 
-                int mod = PyInt_AsLong(arg);
+                int mod = PyLong_AsLong(arg);
                 int isFinal;
 
+                if (PyErr_Occurred())
+                    return NULL;
+
                 OBJ_CALL(isFinal = Modifier::isFinal(mod));
                 Py_RETURN_BOOL(isFinal);
             }
 
             static PyObject *t_Modifier_isAbstract(PyTypeObject *type, PyObject *arg)
             {
-                if (!PyInt_Check(arg))
+                if (!PyLong_Check(arg))
                 {
                     PyErr_SetObject(PyExc_TypeError, arg);
                     return NULL;
                 }
 
-                int mod = PyInt_AsLong(arg);
+                int mod = PyLong_AsLong(arg);
                 int isAbstract;
 
+                if (PyErr_Occurred())
+                    return NULL;
+
                 OBJ_CALL(isAbstract = Modifier::isAbstract(mod));
                 Py_RETURN_BOOL(isAbstract);
             }
 
             static PyObject *t_Modifier_isPrivate(PyTypeObject *type, PyObject *arg)
             {
-                if (!PyInt_Check(arg))
+                if (!PyLong_Check(arg))
                 {
                     PyErr_SetObject(PyExc_TypeError, arg);
                     return NULL;
                 }
 
-                int mod = PyInt_AsLong(arg);
+                int mod = PyLong_AsLong(arg);
                 int isPrivate;
 
+                if (PyErr_Occurred())
+                    return NULL;
+
                 OBJ_CALL(isPrivate = Modifier::isPrivate(mod));
                 Py_RETURN_BOOL(isPrivate);
             }
 
             static PyObject *t_Modifier_isProtected(PyTypeObject *type, PyObject *arg)
             {
-                if (!PyInt_Check(arg))
+                if (!PyLong_Check(arg))
                 {
                     PyErr_SetObject(PyExc_TypeError, arg);
                     return NULL;
                 }
 
-                int mod = PyInt_AsLong(arg);
+                int mod = PyLong_AsLong(arg);
                 int isProtected;
 
+                if (PyErr_Occurred())
+                    return NULL;
+
                 OBJ_CALL(isProtected = Modifier::isProtected(mod));
                 Py_RETURN_BOOL(isProtected);
             }

Modified: lucene/pylucene/branches/python_3/jcc/helpers/linux.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/helpers/linux.py?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/helpers/linux.py (original)
+++ lucene/pylucene/branches/python_3/jcc/helpers/linux.py Mon Jul 12 19:30:05 2010
@@ -60,10 +60,10 @@ def patch_setuptools(with_setuptools):
             patch_version = '0.6c11'
 
         if os.path.isdir(st_egg):
-            raise NotImplementedError, patch_st_dir(patch_version, st_egg,
-                                                    jccdir)
+            raise NotImplementedError(patch_st_dir(patch_version, st_egg,
+                                                    jccdir))
         else:
-            raise NotImplementedError, patch_st_zip(patch_version, st_egg,
-                                                    jccdir)
+            raise NotImplementedError(patch_st_zip(patch_version, st_egg,
+                                                    jccdir))
 
     return enable_shared

Modified: lucene/pylucene/branches/python_3/jcc/helpers/windows.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/helpers/windows.py?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/helpers/windows.py (original)
+++ lucene/pylucene/branches/python_3/jcc/helpers/windows.py Mon Jul 12 19:30:05 2010
@@ -19,7 +19,7 @@ if sys.platform == "win32":
     # figure out where the JDK lives
 
     try:
-        import _winreg as wreg
+        import winreg as wreg
 
         class WindowsRegistry:
             # see the Python Cookbook, #146305, Dirk Holtwick

Modified: lucene/pylucene/branches/python_3/jcc/jcc/__init__.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/__init__.py?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/jcc/__init__.py (original)
+++ lucene/pylucene/branches/python_3/jcc/jcc/__init__.py Mon Jul 12 19:30:05 2010
@@ -26,6 +26,6 @@ if sys.platform == 'win32':
 if __name__ == '__main__':
     import jcc.__main__
 else:
-    from _jcc import initVM
+    from ._jcc import initVM
 
 CLASSPATH=os.path.join(os.path.abspath(os.path.dirname(__file__)), "classes")

Modified: lucene/pylucene/branches/python_3/jcc/jcc/__main__.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/__main__.py?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/jcc/__main__.py (original)
+++ lucene/pylucene/branches/python_3/jcc/jcc/__main__.py Mon Jul 12 19:30:05 2010
@@ -2,7 +2,7 @@
 import sys
 
 if sys.platform == 'win32' and '--find-jvm-dll' in sys.argv:
-    from windows import add_jvm_dll_directory_to_path
+    from .windows import add_jvm_dll_directory_to_path
     add_jvm_dll_directory_to_path()
 
 from jcc import cpp
@@ -96,7 +96,7 @@ if len(sys.argv) == 1 or '--help' in sys
     --prefix PREFIX
     --home HOMEDIR
 '''
-    print help
+    print(help)
     sys.exit(0)
   
 cpp.jcc(sys.argv)

Modified: lucene/pylucene/branches/python_3/jcc/jcc/cpp.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/cpp.py?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/jcc/cpp.py (original)
+++ lucene/pylucene/branches/python_3/jcc/jcc/cpp.py Mon Jul 12 19:30:05 2010
@@ -10,39 +10,8 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 
-import os, sys, zipfile, _jcc
-
-python_ver = '%d.%d.%d' %(sys.version_info[0:3])
-if python_ver < '2.4':
-    from sets import Set as set
-
-    def split_pkg(string, sep):
-        parts = string.split(sep)
-        if len(parts) > 1:
-            return sep.join(parts[:-1]), parts[-1]
-        return parts
-
-    def sort(list, fn=None, key=None):
-        if fn:
-            list.sort(fn)
-        elif key:
-            def fn(x, y):
-                return cmp(key(x), key(y))
-            list.sort(fn)
-        else:
-            list.sort()
-
-else:
-    def split_pkg(string, sep):
-        return string.rsplit(sep, 1)
-
-    def sort(list, fn=None, key=None):
-        if fn:
-            list.sort(cmp=fn)
-        elif key:
-            list.sort(key=key)
-        else:
-            list.sort()
+import os, sys, zipfile
+import jcc._jcc as _jcc
 
 
 class JavaError(Exception):
@@ -63,7 +32,7 @@ class InvalidArgsError(Exception):
 
 
 _jcc._set_exception_types(JavaError, InvalidArgsError)
-from _jcc import *
+from jcc._jcc import *
 
 
 INDENT = '    '
@@ -130,9 +99,9 @@ def argnames(params, cls):
 
     count = len(params)
     decls = ', '.join(["%s a%d" %(typename(params[i], cls, True), i)
-                       for i in xrange(count)])
+                       for i in range(count)])
     args = ', '.join(['a%d%s' %(i, not params[i].isPrimitive() and '.this$' or '')
-                      for i in xrange(count)])
+                      for i in range(count)])
 
     return decls, ', ' + args
 
@@ -176,7 +145,7 @@ def known(cls, typeset, declares, packag
             return known(GenericArrayType.cast_(cls).getGenericComponentType(),
                          typeset, declares, packages, excludes, True)
         else:
-            raise TypeError, (cls, cls.getClass())
+            raise TypeError((cls, cls.getClass()))
 
     while cls.isArray():
         cls = cls.getComponentType()
@@ -192,7 +161,7 @@ def known(cls, typeset, declares, packag
         declares.add(cls)
         return True
 
-    if split_pkg(className, '.')[0] in packages:
+    if className.rsplit('.', 1)[0] in packages:
         typeset.add(cls)
         declares.add(cls)
         cls = cls.getSuperclass()
@@ -214,7 +183,7 @@ def find_method(cls, name, params):
             else:
                 method = cls.getMethod(name, params)
             break
-        except JavaError, e:
+        except JavaError as e:
             if (e.getJavaException().getClass().getName() == 'java.lang.NoSuchMethodException'):
                 if not declared:
                     declared = True
@@ -263,7 +232,7 @@ def signature(fn, argsOnly=False):
 
 def forward(out, namespace, indent):
 
-    for name, entries in namespace.iteritems():
+    for name, entries in namespace.items():
         if entries is True:
             line(out, indent, 'class %s;', cppname(name))
         else:
@@ -347,20 +316,20 @@ def jcc(args):
                 i += 1
                 vmargs.append(args[i])
             elif arg == '--python':
-                from python import python, module
+                from .python import python, module
                 i += 1
                 moduleName = args[i]
             elif arg == '--module':
                 i += 1
                 modules.append(args[i])
             elif arg == '--build':
-                from python import compile
+                from .python import compile
                 build = True
             elif arg == '--install':
-                from python import compile
+                from .python import compile
                 install = True
             elif arg == '--compile':
-                from python import compile
+                from .python import compile
                 recompile = True
             elif arg == '--output':
                 i += 1
@@ -405,10 +374,10 @@ def jcc(args):
             elif arg == '--shared':
                 shared = True
             elif arg == '--bdist':
-                from python import compile
+                from .python import compile
                 dist = True
             elif arg == '--wininst':
-                from python import compile
+                from .python import compile
                 wininst = True
                 dist = True
             elif arg == '--compiler':
@@ -431,7 +400,7 @@ def jcc(args):
                 i += 1
                 imports[args[i]] = ()
             else:
-                raise ValueError, "Invalid argument: %s" %(arg)
+                raise ValueError("Invalid argument: %s" %(arg))
         else:
             classNames.add(arg)
         i += 1
@@ -449,11 +418,11 @@ def jcc(args):
         if shared:
             imports = dict((__import__(import_), set()) for import_ in imports)
         else:
-            raise ValueError, "--shared must be used when using --import"
+            raise ValueError("--shared must be used when using --import")
 
     if recompile or not build and (install or dist):
         if moduleName is None:
-            raise ValueError, 'module name not specified (use --python)'
+            raise ValueError("module name not specified (use --python)")
         else:
             compile(env, os.path.dirname(args[0]), output, moduleName,
                     install, dist, debug, jars, version,
@@ -462,7 +431,8 @@ def jcc(args):
                     arch, generics, resources, imports)
     else:
         if imports:
-            def walk((include, importset), dirname, names):
+            def walk(args, dirname, names):
+                (include, importset) = args
                 for name in names:
                     if name.endswith('.h'):
                         className = os.path.join(dirname[len(include) + 1:],
@@ -470,7 +440,7 @@ def jcc(args):
                         if os.path.sep != '/':
                             className = className.replace(os.path.sep, '/')
                         importset.add(findClass(className))
-            for import_, importset in imports.iteritems():
+            for import_, importset in imports.items():
                 env._addClassPath(import_.CLASSPATH)
                 include = os.path.join(import_.__dir__, 'include')
                 os.path.walk(include, walk, (include, importset))
@@ -481,7 +451,7 @@ def jcc(args):
                 continue
             cls = findClass(className.replace('.', '/'))
             if cls is None:
-                raise ValueError, className
+                raise ValueError(className)
             if Modifier.isPublic(cls.getModifiers()):
                 typeset.add(cls)
                 cls = cls.getSuperclass()
@@ -523,18 +493,18 @@ def jcc(args):
             if not os.path.isdir(cppdir):
                 os.makedirs(cppdir)
             if wrapperFiles <= 1:
-                out_cpp = file(os.path.join(cppdir, '__wrap__.cpp'), 'w')
+                out_cpp = open(os.path.join(cppdir, '__wrap__.cpp'), 'w')
             else:
                 fileCount = 1
                 fileName = '__wrap%02d__.cpp' %(fileCount)
-                out_cpp = file(os.path.join(cppdir, fileName), 'w')
+                out_cpp = open(os.path.join(cppdir, fileName), 'w')
 
         done = set()
-        for importset in imports.itervalues():
+        for importset in imports.values():
             done.update(importset)
 
         todo = typeset - done
-	if allInOne and wrapperFiles > 1:
+        if allInOne and wrapperFiles > 1:
             classesPerFile = max(1, len(todo) / wrapperFiles)
         classCount = 0
         while todo:
@@ -547,7 +517,7 @@ def jcc(args):
                     os.makedirs(dir)
 
                 fileName = os.path.join(dir, names[-1])
-                out_h = file(fileName + '.h', "w")
+                out_h = open(fileName + '.h', "w")
                 line(out_h, 0, '#ifndef %s_H', '_'.join(names))
                 line(out_h, 0, '#define %s_H', '_'.join(names))
 
@@ -557,7 +527,7 @@ def jcc(args):
                            generics, _dll_export)
 
                 if not allInOne:
-                    out_cpp = file(fileName + '.cpp', 'w')
+                    out_cpp = open(fileName + '.cpp', 'w')
                 names, superNames = code(env, out_cpp,
                                          cls, superCls, constructors,
                                          methods, protectedMethods,
@@ -582,9 +552,9 @@ def jcc(args):
                 elif wrapperFiles > 1:
                     if classCount >= classesPerFile:
                         out_cpp.close()
-	                fileCount += 1
-	                fileName = '__wrap%02d__.cpp' %(fileCount)
-	                out_cpp = file(os.path.join(cppdir, fileName), 'w')
+                        fileCount += 1
+                        fileName = '__wrap%02d__.cpp' %(fileCount)
+                        out_cpp = open(os.path.join(cppdir, fileName), 'w')
                         classCount = 0
                         
             done.update(todo)
@@ -594,7 +564,7 @@ def jcc(args):
             out_cpp.close()
 
         if moduleName:
-            out = file(os.path.join(cppdir, moduleName) + '.cpp', 'w')
+            out = open(os.path.join(cppdir, moduleName) + '.cpp', 'w')
             module(out, allInOne, done, imports, cppdir, moduleName,
                    shared, generics)
             out.close()
@@ -652,7 +622,7 @@ def header(env, out, cls, typeset, packa
                     break
             else:
                 constructors.append(constructor)
-    sort(constructors, key=lambda x: len(x.getParameterTypes()))
+    constructors.sort(key=lambda x: len(x.getParameterTypes()))
 
     methods = {}
     protectedMethods = []
@@ -703,14 +673,8 @@ def header(env, out, cls, typeset, packa
                 else:
                     methods[sig] = method
 
-    def _compare(m0, m1):
-        value = cmp(m0.getName(), m1.getName())
-        if value == 0:
-            value = len(m0.getParameterTypes()) - len(m1.getParameterTypes())
-        return value
-
-    methods = methods.values()
-    sort(methods, fn=_compare)
+    methods = list(methods.values())
+    methods.sort(key=lambda x: (x.getName(), len(x.getParameterTypes())))
 
     for constructor in constructors:
         if generics:
@@ -743,8 +707,8 @@ def header(env, out, cls, typeset, packa
                 fields.append(field)
             else:
                 instanceFields.append(field)
-    sort(fields, key=lambda x: x.getName())
-    sort(instanceFields, key=lambda x: x.getName())
+    fields.sort(key=lambda x: x.getName())
+    instanceFields.sort(key=lambda x: x.getName())
 
     line(out)
     superNames = superClsName.split('.')

Modified: lucene/pylucene/branches/python_3/jcc/jcc/python.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/python.py?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/jcc/python.py (original)
+++ lucene/pylucene/branches/python_3/jcc/jcc/python.py Mon Jul 12 19:30:05 2010
@@ -12,39 +12,35 @@
 #   limitations under the License.
 #
 
-import os, sys, platform, shutil, _jcc
-from itertools import izip
+import os, sys, platform, shutil
 
-from cpp import PRIMITIVES, INDENT, HALF_INDENT
-from cpp import cppname, cppnames, typename
-from cpp import line, signature, find_method, split_pkg, sort
-from cpp import Modifier, Class, Method
-from _jcc import findClass
-from config import INCLUDES, CFLAGS, DEBUG_CFLAGS, LFLAGS, IMPLIB_LFLAGS, \
+
+from .cpp import PRIMITIVES, INDENT, HALF_INDENT
+from .cpp import cppname, cppnames, typename
+from .cpp import line, signature, find_method
+from .cpp import Modifier, Class, Method
+from ._jcc import findClass
+from .config import INCLUDES, CFLAGS, DEBUG_CFLAGS, LFLAGS, IMPLIB_LFLAGS, \
     SHARED, VERSION as JCC_VER
 
 try:
-    from cpp import ParameterizedType, TypeVariable
+    from .cpp import ParameterizedType, TypeVariable
 except ImportError:
     pass
 
-python_ver = '%d.%d.%d' %(sys.version_info[0:3])
-if python_ver < '2.4':
-    from sets import Set as set
-
 
 RESULTS = { 'boolean': 'Py_RETURN_BOOL(%s);',
-            'byte': 'return PyInt_FromLong((long) %s);',
+            'byte': 'return PyLong_FromLong((long) %s);',
             'char': 'return PyUnicode_FromUnicode((Py_UNICODE *) &%s, 1);',
             'double': 'return PyFloat_FromDouble((double) %s);',
             'float': 'return PyFloat_FromDouble((double) %s);',
-            'int': 'return PyInt_FromLong((long) %s);',
+            'int': 'return PyLong_FromLong((long) %s);',
             'long': 'return PyLong_FromLongLong((PY_LONG_LONG) %s);',
-            'short': 'return PyInt_FromLong((long) %s);',
+            'short': 'return PyLong_FromLong((long) %s);',
             'java.lang.String': 'return j2p(%s);' }
 
 CALLARGS = { 'boolean': ('O', '(%s ? Py_True : Py_False)', False),
-             'byte': ('O', 'PyInt_FromLong(%s)', True),
+             'byte': ('O', 'PyLong_FromLong(%s)', True),
              'char': ('O', 'PyUnicode_FromUnicode((Py_UNICODE *) &%s, 1)', True),
              'double': ('d', '(double) %s', False),
              'float': ('f', '(float) %s', False),
@@ -150,26 +146,26 @@ def parseArgs(params, current, generics,
             while cls.isArray():
                 cls = cls.getComponentType()
             if getTypeParameters(cls):
-                ns, sep, n = rpartition(typename(cls, current, False), '::')
+                ns, sep, n = typename(cls, current, False).rpartition('::')
                 return ', &a%d, &p%d, %s%st_%s::parameters_' %(i, i, ns, sep, n)
         return ', &a%d' %(i)
 
     if genericParams:
         sig = ''.join([signature(param, genericParam)
-                       for param, genericParam in izip(params, genericParams)])
+                       for param, genericParam in zip(params, genericParams)])
         chk = ''.join([checkarg(param, genericParam)
-                       for param, genericParam in izip(params, genericParams)])
+                       for param, genericParam in zip(params, genericParams)])
     else:
         sig = ''.join([signature(param) for param in params])
         chk = ''.join([checkarg(param) for param in params])
 
     return (sig, chk,
-            ''.join([callarg(params[i], i) for i in xrange(len(params))]))
+            ''.join([callarg(params[i], i) for i in range(len(params))]))
 
 
 def declareVars(out, indent, params, current, generics, typeParams):
 
-    for i in xrange(len(params)):
+    for i in range(len(params)):
         param = params[i]
         line(out, indent, '%s a%d%s;',
              typename(param, current, False), i,
@@ -207,7 +203,7 @@ def construct(out, indent, cls, inCase, 
         indent += 1
 
     line(out, indent, 'INT_CALL(object = %s(%s));',
-         cppname(names[-1]), ', '.join(['a%d' %(i) for i in xrange(count)]))
+         cppname(names[-1]), ', '.join(['a%d' %(i) for i in range(count)]))
     line(out, indent, 'self->object = object;')
     if inCase:
         line(out, indent, 'break;')
@@ -221,17 +217,6 @@ def construct(out, indent, cls, inCase, 
         line(out, indent, '}')
 
 
-def rpartition(string, sep):
-
-    if python_ver >= '2.5.0':
-        return string.rpartition(sep)
-    else:
-        parts = split_pkg(string, sep)
-        if len(parts) == 1:
-            return ('', '', parts[0])
-        return (parts[0], sep, parts[1])
-
-
 def fieldValue(cls, value, fieldType):
 
     if fieldType.isArray():
@@ -243,14 +228,14 @@ def fieldValue(cls, value, fieldType):
         elif fieldType.getName() == 'java.lang.String':
             result = 'JArray<jstring>(%s->this$).wrap()'
         else:
-            parts = rpartition(typename(fieldType, cls, False), '::')
+            parts = typename(fieldType, cls, False).rpartition('::')
             result = 'JArray<jobject>(%%s->this$).wrap(%s%st_%s::wrap_jobject)' %(parts)
 
     elif fieldType.getName() == 'java.lang.String':
         result = 'j2p(*%s)'
 
     elif not fieldType.isPrimitive():
-        parts = rpartition(typename(fieldType, cls, False), '::')
+        parts = typename(fieldType, cls, False).rpartition('::')
         result = '%s%st_%s::wrap_Object(*%%s)' %(parts)
 
     else:
@@ -278,10 +263,10 @@ def returnValue(cls, returnType, value, 
         elif returnType.getName() == 'java.lang.String':
             return 'return JArray<jstring>(%s.this$).wrap();' %(value)
 
-        ns, sep, n = rpartition(typename(returnType, cls, False), '::')
+        ns, sep, n = typename(returnType, cls, False).rpartition('::')
         return 'return JArray<jobject>(%s.this$).wrap(%s%st_%s::wrap_jobject);' %(value, ns, sep, n)
 
-    ns, sep, n = rpartition(typename(returnType, cls, False), '::')
+    ns, sep, n = typename(returnType, cls, False).rpartition('::')
     if genericRT is not None:
         if ParameterizedType.instance_(genericRT):
             genericRT = ParameterizedType.cast_(genericRT)
@@ -373,16 +358,16 @@ def call(out, indent, cls, inCase, metho
     if Modifier.isStatic(modifiers):
         line(out, indent, 'OBJ_CALL(%s%s::%s(%s));',
              result, '::'.join(cppnames(names)), name,
-             ', '.join(['a%d' %(i) for i in xrange(count)]))
+             ', '.join(['a%d' %(i) for i in range(count)]))
     else:
         line(out, indent, 'OBJ_CALL(%sself->object.%s(%s));',
-             result, name, ', '.join(['a%d' %(i) for i in xrange(count)]))
+             result, name, ', '.join(['a%d' %(i) for i in range(count)]))
 
     if isExtension and name == 'clone' and Modifier.isNative(modifiers):
         line(out)
         line(out, indent, '%s object(result.this$);', typename(cls, cls, False))
         line(out, indent, 'if (PyObject_TypeCheck(arg, &PY_TYPE(FinalizerProxy)) &&')
-        line(out, indent, '    PyObject_TypeCheck(((t_fp *) arg)->object, self->ob_type))')
+        line(out, indent, '    PyObject_TypeCheck(((t_fp *) arg)->object, self->ob_base.ob_type))')
         line(out, indent, '{')
         line(out, indent + 1, 'PyObject *_arg = ((t_fp *) arg)->object;')
         line(out, indent + 1, '((t_JObject *) _arg)->object = object;')
@@ -434,7 +419,7 @@ def jniargs(params):
 
     count = len(params)
     decls = ', '.join(['%s a%d' %(jniname(params[i]), i)
-                       for i in xrange(count)])
+                       for i in range(count)])
     if decls:
         return ', ' + decls
 
@@ -483,13 +468,13 @@ def extension(env, out, indent, cls, nam
             elif param.getName() == 'java.lang.String':
                 code = 'JArray<jstring>(%s).wrap()'
             else:
-                parts = rpartition(typename(param, cls, False), '::')
+                parts = typename(param, cls, False).rpartition('::')
                 code = 'JArray<jobject>(%%s).wrap(%s%st_%s::wrap_jobject)' %(parts)
             sig, decref = 'O', True
         elif param.getName() == 'java.lang.String':
             sig, code, decref = 'O', 'j2p(%%s))', True
         else:
-            parts = rpartition(typename(param, cls, False), '::')
+            parts = typename(param, cls, False).rpartition('::')
             sig, code, decref = 'O', '%s%st_%s::wrap_Object(%s%s%s(%%s))' %(parts*2), True
         if sig == 'O':
             line(out, indent, 'PyObject *o%d = %s;', i, code %('a%d' %(i)))
@@ -668,14 +653,14 @@ def python(env, out_h, out, cls, superCl
                         elif name + '_' in allMethods:
                             allMethods[name + '_'].append(method)
                         else:
-                            print >>sys.stderr, "  Warning: renaming static method '%s' on class %s to '%s_' since it is shadowed by non-static method of same name." %(name, '.'.join(names), name)
+                            print("  Warning: renaming static method '%s' on class %s to '%s_' since it is shadowed by non-static method of same name." %(name, '.'.join(names), name), file=sys.stderr)
                             allMethods[name + '_'] = [method]
                     else:
                         allMethods[name] = [method]
                 else:
                     if name in allMethods:
                         if Modifier.isStatic(allMethods[name][0].getModifiers()):
-                            print >>sys.stderr, "  Warning: renaming static method '%s' on class %s to '%s_' since it is shadowed by non-static method of same name." %(name, '.'.join(names), name)
+                            print("  Warning: renaming static method '%s' on class %s to '%s_' since it is shadowed by non-static method of same name." %(name, '.'.join(names), name), file=sys.stderr)
                             allMethods[name + '_'] = allMethods[name]
                             allMethods[name] = [method]
                         else:
@@ -696,15 +681,15 @@ def python(env, out_h, out, cls, superCl
                     propMethods.setdefault(name[2].lower() + name[3:],
                                            []).append(method)
 
-    properties = set([name for name in propMethods.iterkeys()
+    properties = set([name for name in propMethods.keys()
                       if name not in allMethods])
     propMethods = [(name, propMethods[name]) for name in properties]
-    sort(propMethods, key=lambda x: x[0])
+    propMethods.sort(key=lambda x: x[0])
 
-    extMethods = extMethods.items()
-    sort(extMethods, key=lambda x: x[0])
-    allMethods = allMethods.items()
-    sort(allMethods, key=lambda x: x[0])
+    extMethods = list(extMethods.items())
+    extMethods.sort(key=lambda x: x[0])
+    allMethods = list(allMethods.items())
+    allMethods.sort(key=lambda x: x[0])
 
     iteratorMethod = None
     iteratorExt = False
@@ -725,7 +710,7 @@ def python(env, out_h, out, cls, superCl
 
     for name, methods in allMethods:
         args, x, cardinality = methodargs(methods, superMethods)
-        sort(methods, key=lambda x: len(x.getParameterTypes()))
+        methods.sort(key=lambda x: len(x.getParameterTypes()))
         method = methods[0]
         modifiers = method.getModifiers()
         if name == 'iterator' and iteratorMethod is None:
@@ -763,7 +748,7 @@ def python(env, out_h, out, cls, superCl
 
     for name, methods in extMethods:
         args, x, cardinality = methodargs(methods, superMethods)
-        sort(methods, key=lambda x: len(x.getParameterTypes()))
+        methods.sort(key=lambda x: len(x.getParameterTypes()))
         method = methods[0]
         modifiers = method.getModifiers()
         if name == 'iterator' and iteratorMethod is None:
@@ -908,7 +893,7 @@ def python(env, out_h, out, cls, superCl
     elif nextMethod and iterable is not None and iterator.isAssignableFrom(cls):
         tp_iter = 'PyObject_SelfIter'
         returnName = typename(nextMethod.getReturnType(), cls, False)
-        ns, sep, n = rpartition(returnName, '::')
+        ns, sep, n = returnName.rpartition('::')
         if nextExt:
             tp_iternext = 'get_extension_next'
         else:
@@ -916,7 +901,7 @@ def python(env, out_h, out, cls, superCl
     elif nextElementMethod and enumeration.isAssignableFrom(cls):
         tp_iter = 'PyObject_SelfIter'
         returnName = typename(nextElementMethod.getReturnType(), cls, False)
-        ns, sep, n = rpartition(returnName, '::')
+        ns, sep, n = returnName.rpartition('::')
         if nextElementExt:
             tp_iternext = 'get_extension_nextElement'
         else:
@@ -924,7 +909,7 @@ def python(env, out_h, out, cls, superCl
     elif nextMethod:
         tp_iter = 'PyObject_SelfIter'
         returnName = typename(nextMethod.getReturnType(), cls, False)
-        ns, sep, n = rpartition(returnName, '::')
+        ns, sep, n = returnName.rpartition('::')
         if nextExt:
             tp_iternext = 'get_extension_next'
         else:
@@ -971,18 +956,11 @@ def python(env, out_h, out, cls, superCl
         line(out)
         line(out, indent, 'static PySequenceMethods t_%s_as_sequence = {',
              names[-1])
-        if python_ver < '2.5.0':
-            line(out, indent + 1, '(inquiry) %s,', lenName)
-            line(out, indent + 1, '0,')
-            line(out, indent + 1, '0,')
-            line(out, indent + 1, '(intargfunc) %s', getName)
-            line(out, indent, '};')
-        else:
-            line(out, indent + 1, '(lenfunc) %s,', lenName)
-            line(out, indent + 1, '0,')
-            line(out, indent + 1, '0,')
-            line(out, indent + 1, '(ssizeargfunc) %s', getName)
-            line(out, indent, '};')
+        line(out, indent + 1, '(lenfunc) %s,', lenName)
+        line(out, indent + 1, '0,')
+        line(out, indent + 1, '0,')
+        line(out, indent + 1, '(ssizeargfunc) %s', getName)
+        line(out, indent, '};')
         tp_as_sequence = '&t_%s_as_sequence' %(names[-1])
     else:
         tp_as_sequence = '0'
@@ -1298,7 +1276,7 @@ def python(env, out_h, out, cls, superCl
             line(out)
             getter = None
             setters = []
-            sort(methods, key=lambda x: x.getName())
+            methods.sort(key=lambda x: x.getName())
             for method in methods:
                 methodName = method.getName()
                 if not getter and (methodName.startswith('get') or
@@ -1404,7 +1382,7 @@ def python(env, out_h, out, cls, superCl
 def package(out, allInOne, cppdir, namespace, names):
 
     if not allInOne:
-        out = file(os.path.join(os.path.join(cppdir, *names),
+        out = open(os.path.join(os.path.join(cppdir, *names),
                                 '__init__.cpp'), 'w')
 
     if allInOne and not names or not allInOne:
@@ -1420,8 +1398,8 @@ def package(out, allInOne, cppdir, names
     packages = []
     types = []
 
-    namespaces = namespace.items()
-    sort(namespaces, key=lambda x: x[0])
+    namespaces = list(namespace.items())
+    namespaces.sort(key=lambda x: x[0])
     for name, entries in namespaces:
         if entries is True:
             if names:
@@ -1509,10 +1487,10 @@ def module(out, allInOne, classes, impor
     line(out, 0, '#include "jccfuncs.h"')
 
     if allInOne:
-        out_init = file(os.path.join(cppdir, '__init__.cpp'), 'w')
+        out_init = open(os.path.join(cppdir, '__init__.cpp'), 'w')
     namespaces = {}
     for cls in classes:
-        for importset in imports.itervalues():
+        for importset in imports.values():
             if cls in importset:
                 break
         else:
@@ -1535,11 +1513,17 @@ def module(out, allInOne, classes, impor
     line(out)
     line(out, 0, 'extern "C" {')
 
+    line(out, 1, 'static struct PyModuleDef %s_def = {', extname)
+    line(out, 2, 'PyModuleDef_HEAD_INIT,')
+    line(out, 2, '"%s",', extname);
+    line(out, 2, '"%s module",', extname);
+    line(out, 2, '0,')
+    line(out, 2, 'jcc_funcs,');
+    line(out, 1, '};')
     line(out)
-    line(out, 1, 'void init%s(void)', extname)
+    line(out, 1, 'PyObject *PyInit_%s(void)', extname)
     line(out, 1, '{')
-    line(out, 2, 'PyObject *module = Py_InitModule3("%s", jcc_funcs, "");',
-         extname);
+    line(out, 2, 'PyObject *module = PyModule_Create(&%s_def);', extname);
     line(out)
     line(out, 2, 'initJCC(module);')
     line(out)
@@ -1549,6 +1533,8 @@ def module(out, allInOne, classes, impor
     line(out, 2, 'INSTALL_TYPE(FinalizerProxy, module);')
     line(out, 2, '_install_jarray(module);')
     line(out, 2, '__install__(module);')
+    line(out)
+    line(out, 2, 'return module;')
     line(out, 1, '}')
     line(out, 0, '}')
 
@@ -1564,12 +1550,10 @@ def compile(env, jccPath, output, module
         from setuptools import setup, Extension
         with_setuptools = True
         if shared and not SHARED:
-            raise NotImplementedError, "JCC was not built with --shared mode support, see JCC's INSTALL file for more information"
+            raise NotImplementedError("JCC was not built with --shared mode support, see JCC's INSTALL file for more information")
     except ImportError:
-        if python_ver < '2.4':
-            raise ImportError, 'setuptools is required when using Python 2.3'
         if shared:
-            raise ImportError, 'setuptools is required when using --shared'
+            raise ImportError('setuptools is required when using --shared')
         from distutils.core import setup, Extension
         with_setuptools = False
 
@@ -1579,7 +1563,7 @@ def compile(env, jccPath, output, module
     if not os.path.isdir(modulePath):
         os.makedirs(modulePath)
 
-    out = file(os.path.join(modulePath, '__init__.py'), 'w')
+    out = open(os.path.join(modulePath, '__init__.py'), 'w')
     line(out)
     if shared:
         line(out, 0, "import os, sys")
@@ -1588,11 +1572,11 @@ def compile(env, jccPath, output, module
         if find_jvm_dll:
             line(out, 1, "from jcc.windows import add_jvm_dll_directory_to_path")
             line(out, 1, "add_jvm_dll_directory_to_path()")
-        line(out, 1, "import jcc, %s", extname)
+        line(out, 1, "import jcc, %s.%s as %s", moduleName, extname, extname)
         line(out, 0, "else:")
-        line(out, 1, "import %s", extname)
+        line(out, 1, "import %s.%s as %s", moduleName, extname, extname)
     else:
-        line(out, 0, 'import os, %s', extname)
+        line(out, 0, 'import os, %s.%s as %s', moduleName, extname, extname)
     line(out)
     line(out, 0, '__dir__ = os.path.abspath(os.path.dirname(__file__))')
 
@@ -1677,7 +1661,7 @@ def compile(env, jccPath, output, module
     line(out)
     for import_ in imports:
         line(out, 0, 'from %s._%s import *', import_.__name__, import_.__name__)
-    line(out, 0, 'from %s import *', extname)
+    line(out, 0, 'from %s.%s import *', moduleName, extname)
     out.close()
 
     includes = [os.path.join(output, extname),
@@ -1690,7 +1674,7 @@ def compile(env, jccPath, output, module
         sources.append('jcc.cpp')
         sources.append('JCCEnv.cpp')
     for source in sources:
-	shutil.copy2(os.path.join(jccPath, 'sources', source),
+        shutil.copy2(os.path.join(jccPath, 'sources', source),
                      os.path.join(output, extname))
 
     if shared:
@@ -1738,7 +1722,7 @@ def compile(env, jccPath, output, module
         script_args.append('--debug')
         compile_args += DEBUG_CFLAGS
     elif sys.platform == 'win32':
-	pass
+        pass
     elif sys.platform == 'sunos5':
         link_args.append('-Wl,-s')
     else:
@@ -1772,7 +1756,7 @@ def compile(env, jccPath, output, module
     }
 
     if shared:
-        shlibdir = os.path.dirname(os.path.dirname(_jcc.__file__))
+        shlibdir = os.path.dirname(os.path.dirname(jcc._jcc.__file__))
         if sys.platform == 'darwin':   # distutils no good with -R
             machine = platform.machine()
             if machine.startswith('iPod') or machine.startswith('iPhone'):
@@ -1810,7 +1794,7 @@ def compile(env, jccPath, output, module
                 for import_ in imports
             ] + [("_dll_%s" %(moduleName), '__declspec(dllexport)')]
         else:
-            raise NotImplementedError, "shared mode on %s" %(sys.platform)
+            raise NotImplementedError("shared mode on %s" %(sys.platform))
 
     if arch and sys.platform == 'darwin':
         from distutils import sysconfig

Modified: lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.cpp?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.cpp (original)
+++ lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.cpp Mon Jul 12 19:30:05 2010
@@ -57,7 +57,7 @@ public:
     static void dealloc(_t_iterator *self)
     {
         Py_XDECREF(self->obj);
-        self->ob_type->tp_free((PyObject *) self);
+        self->ob_base.ob_type->tp_free((PyObject *) self);
     }
 
     static PyObject *iternext(_t_iterator *self)
@@ -99,9 +99,9 @@ static int init(U *self, PyObject *args,
         if (PyErr_Occurred())
             return -1;
     }
-    else if (PyInt_Check(obj))
+    else if (PyLong_Check(obj))
     {
-        int n = PyInt_AsLong(obj);
+        int n = PyLong_AsLong(obj);
 
         if (n < 0)
         {
@@ -124,7 +124,7 @@ template<typename T, typename U>
 static void dealloc(U *self)
 {
     self->array = JArray<T>((jobject) NULL);
-    self->ob_type->tp_free((PyObject *) self);
+    self->ob_base.ob_type->tp_free((PyObject *) self);
 }
 
 template<typename U>
@@ -144,7 +144,7 @@ static PyObject *_format(U *self, PyObje
                 PyObject *args = PyTuple_New(1);
 
                 PyTuple_SET_ITEM(args, 0, result);
-                result = PyString_Format(U::format, args);
+                result = PyUnicode_Format(U::format, args);
                 Py_DECREF(args);
 
                 return result;
@@ -154,7 +154,7 @@ static PyObject *_format(U *self, PyObje
         return NULL;
     }
 
-    return PyString_FromString("<null>");
+    return PyUnicode_FromString("<null>");
 }
 
 template<typename U>
@@ -502,8 +502,8 @@ public:
         {
             memset(&type_object, 0, sizeof(type_object));
 
-            type_object.ob_refcnt = 1;
-            type_object.ob_type = NULL;
+            type_object.ob_base.ob_base.ob_refcnt = 1;
+            type_object.ob_base.ob_base.ob_type = NULL;
             type_object.tp_basicsize = sizeof(_t_iterator<U>);
             type_object.tp_dealloc = (destructor) _t_iterator<U>::dealloc;
             type_object.tp_flags = Py_TPFLAGS_DEFAULT;
@@ -529,7 +529,7 @@ public:
             PyModule_AddObject(module, name, (PyObject *) &type_object);
         }
 
-        U::format = PyString_FromFormat("JArray<%s>%%s", type_name);
+        U::format = PyUnicode_FromFormat("JArray<%s>%%s", type_name);
         iterator_type_object.install(iterator_name, module);
     }
 
@@ -575,20 +575,16 @@ public:
             (ssizeargfunc) (PyObject *(*)(U *, Py_ssize_t)) seq_repeat<U>;
         seq_methods.sq_item =
             (ssizeargfunc) (PyObject *(*)(U *, Py_ssize_t)) seq_get<U>;
-        seq_methods.sq_slice =
-            (ssizessizeargfunc) (PyObject *(*)(U *, Py_ssize_t, Py_ssize_t))
-            seq_getslice<U>;
+        seq_methods.was_sq_slice = NULL;
         seq_methods.sq_ass_item =
             (ssizeobjargproc) (int (*)(U *, Py_ssize_t, PyObject *)) seq_set<U>;
-        seq_methods.sq_ass_slice =
-            (ssizessizeobjargproc) (int (*)(U *, Py_ssize_t, Py_ssize_t,
-                                            PyObject *)) seq_setslice<U>;
+        seq_methods.was_sq_ass_slice = NULL;
         seq_methods.sq_contains =
             (objobjproc) (int (*)(U *, PyObject *)) seq_contains<U>;
         seq_methods.sq_inplace_concat = NULL;
         seq_methods.sq_inplace_repeat = NULL;
 
-        type_object.ob_refcnt = 1;
+        type_object.ob_base.ob_base.ob_refcnt = 1;
         type_object.tp_basicsize = sizeof(U);
         type_object.tp_dealloc = (destructor) (void (*)(U *)) dealloc<T,U>;
         type_object.tp_repr = (reprfunc) (PyObject *(*)(U *)) repr<U>;
@@ -693,9 +689,9 @@ template<> int init< jobject,_t_jobjecta
         if (PyErr_Occurred())
             return -1;
     }
-    else if (PyInt_Check(obj))
+    else if (PyLong_Check(obj))
     {
-        int n = PyInt_AsLong(obj);
+        int n = PyLong_AsLong(obj);
 
         if (n < 0)
         {
@@ -1081,7 +1077,7 @@ PyObject *JArray_Type(PyObject *self, Py
         if (!type_name)
             return NULL;
     }
-    else if (PyString_Check(arg))
+    else if (PyUnicode_Check(arg))
     {
         type_name = arg;
         Py_INCREF(type_name);
@@ -1102,9 +1098,8 @@ PyObject *JArray_Type(PyObject *self, Py
 
     if (type_name != NULL)
     {
-        name = PyString_AsString(type_name);
+        name = PyUnicode_AsString(type_name);
         Py_DECREF(type_name);
-
         if (!name)
             return NULL;
     }
@@ -1144,8 +1139,14 @@ static PyObject *t_jarray_jbyte__get_str
     return self->array.to_string_();
 }
 
+static PyObject *t_jarray_jbyte__get_bytes_(t_jarray<jbyte> *self, void *data)
+{
+    return self->array.to_bytes_();
+}
+
 static PyGetSetDef t_jarray_jbyte__fields[] = {
     { "string_", (getter) t_jarray_jbyte__get_string_, NULL, "", NULL },
+    { "bytes_", (getter) t_jarray_jbyte__get_bytes_, NULL, "", NULL },
     { NULL, NULL, NULL, NULL, NULL }
 };
 

Modified: lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.h?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.h (original)
+++ lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.h Mon Jul 12 19:30:05 2010
@@ -525,8 +525,8 @@ template<> class JArray<jbyte> : public 
         arrayElements elts = elements();
         jbyte *buf = (jbyte *) elts;
 
-        if (PyString_Check(sequence))
-            memcpy(buf, PyString_AS_STRING(sequence), length);
+        if (PyBytes_Check(sequence))
+            memcpy(buf, PyBytes_AS_STRING(sequence), length);
         else
             for (int i = 0; i < length; i++) {
                 PyObject *obj = PySequence_GetItem(sequence, i);
@@ -534,14 +534,14 @@ template<> class JArray<jbyte> : public 
                 if (!obj)
                     break;
 
-                if (PyString_Check(obj) && (PyString_GET_SIZE(obj) == 1))
+                if (PyBytes_Check(obj) && (PyBytes_GET_SIZE(obj) == 1))
                 {
-                    buf[i] = (jbyte) PyString_AS_STRING(obj)[0];
+                    buf[i] = (jbyte) PyBytes_AS_STRING(obj)[0];
                     Py_DECREF(obj);
                 }
-                else if (PyInt_CheckExact(obj))
+                else if (PyLong_CheckExact(obj))
                 {
-                    buf[i] = (jbyte) PyInt_AS_LONG(obj);
+                    buf[i] = (jbyte) PyLong_AS_LONG(obj);
                     Py_DECREF(obj);
                 }
                 else
@@ -581,11 +581,22 @@ template<> class JArray<jbyte> : public 
         PyObject *tuple = PyTuple_New(hi - lo);
         
         for (int i = 0; i < hi - lo; i++)
-            PyTuple_SET_ITEM(tuple, i, PyInt_FromLong(buf[lo + i]));
+            PyTuple_SET_ITEM(tuple, i, PyLong_FromLong(buf[lo + i]));
 
         return tuple;
     }
 
+    PyObject *to_bytes_()
+    {
+        if (this$ == NULL)
+            Py_RETURN_NONE;
+
+        arrayElements elts = elements();
+        jbyte *buf = (jbyte *) elts;
+
+        return PyBytes_FromStringAndSize((char *) buf, length);
+    }
+
     PyObject *to_string_()
     {
         if (this$ == NULL)
@@ -594,7 +605,7 @@ template<> class JArray<jbyte> : public 
         arrayElements elts = elements();
         jbyte *buf = (jbyte *) elts;
 
-        return PyString_FromStringAndSize((char *) buf, length);
+        return PyUnicode_FromStringAndSize((char *) buf, length);
     }
 
     PyObject *get(int n)
@@ -607,7 +618,7 @@ template<> class JArray<jbyte> : public 
             if (n >= 0 && n < length)
             {
                 jbyte b = (*this)[n];
-                return PyInt_FromLong(b);
+                return PyLong_FromLong(b);
             }
         }
 
@@ -624,13 +635,13 @@ template<> class JArray<jbyte> : public 
 
             if (n >= 0 && n < length)
             {
-                if (!PyInt_CheckExact(obj))
+                if (!PyLong_CheckExact(obj))
                 {
                     PyErr_SetObject(PyExc_TypeError, obj);
                     return -1;
                 }
 
-                elements()[n] = (jbyte) PyInt_AS_LONG(obj);
+                elements()[n] = (jbyte) PyLong_AS_LONG(obj);
                 return 0;
             }
         }
@@ -1186,9 +1197,9 @@ template<> class JArray<jint> : public j
             if (!obj)
                 break;
 
-            if (PyInt_Check(obj))
+            if (PyLong_Check(obj))
             {
-                buf[i] = (jint) PyInt_AS_LONG(obj);
+                buf[i] = (jint) PyLong_AS_LONG(obj);
                 Py_DECREF(obj);
             }
             else
@@ -1223,7 +1234,7 @@ template<> class JArray<jint> : public j
         jint *buf = (jint *) elts;
 
         for (int i = lo; i < hi; i++)
-            PyList_SET_ITEM(list, i - lo, PyInt_FromLong(buf[i]));
+            PyList_SET_ITEM(list, i - lo, PyLong_FromLong(buf[i]));
 
         return list;
     }
@@ -1236,7 +1247,7 @@ template<> class JArray<jint> : public j
                 n = length + n;
 
             if (n >= 0 && n < length)
-                return PyInt_FromLong((*this)[n]);
+                return PyLong_FromLong((*this)[n]);
         }
 
         PyErr_SetString(PyExc_IndexError, "index out of range");
@@ -1252,13 +1263,13 @@ template<> class JArray<jint> : public j
 
             if (n >= 0 && n < length)
             {
-                if (!PyInt_Check(obj))
+                if (!PyLong_Check(obj))
                 {
                     PyErr_SetObject(PyExc_TypeError, obj);
                     return -1;
                 }
 
-                elements()[n] = (jint) PyInt_AS_LONG(obj);
+                elements()[n] = (jint) PyLong_AS_LONG(obj);
                 return 0;
             }
         }
@@ -1480,9 +1491,9 @@ template<> class JArray<jshort> : public
             if (!obj)
                 break;
 
-            if (PyInt_Check(obj))
+            if (PyLong_Check(obj))
             {
-                buf[i] = (jshort) PyInt_AS_LONG(obj);
+                buf[i] = (jshort) PyLong_AS_LONG(obj);
                 Py_DECREF(obj);
             }
             else
@@ -1517,7 +1528,7 @@ template<> class JArray<jshort> : public
         jshort *buf = (jshort *) elts;
 
         for (int i = lo; i < hi; i++)
-            PyList_SET_ITEM(list, i - lo, PyInt_FromLong(buf[i]));
+            PyList_SET_ITEM(list, i - lo, PyLong_FromLong(buf[i]));
 
         return list;
     }
@@ -1530,7 +1541,7 @@ template<> class JArray<jshort> : public
                 n = length + n;
 
             if (n >= 0 && n < length)
-                return PyInt_FromLong((long) (*this)[n]);
+                return PyLong_FromLong((long) (*this)[n]);
         }
 
         PyErr_SetString(PyExc_IndexError, "index out of range");
@@ -1546,13 +1557,13 @@ template<> class JArray<jshort> : public
 
             if (n >= 0 && n < length)
             {
-                if (!PyInt_Check(obj))
+                if (!PyLong_Check(obj))
                 {
                     PyErr_SetObject(PyExc_TypeError, obj);
                     return -1;
                 }
 
-                elements()[n] = (jshort) PyInt_AS_LONG(obj);
+                elements()[n] = (jshort) PyLong_AS_LONG(obj);
                 return 0;
             }
         }

Modified: lucene/pylucene/branches/python_3/jcc/jcc/sources/JCCEnv.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/sources/JCCEnv.cpp?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/jcc/sources/JCCEnv.cpp (original)
+++ lucene/pylucene/branches/python_3/jcc/jcc/sources/JCCEnv.cpp Mon Jul 12 19:30:05 2010
@@ -847,8 +847,6 @@ jstring JCCEnv::fromPyString(PyObject *o
             return str;
         }
     }
-    else if (PyString_Check(object))
-        return fromUTF(PyString_AS_STRING(object));
     else
     {
         PyObject *tuple = Py_BuildValue("(sO)", "expected a string", object);

Modified: lucene/pylucene/branches/python_3/jcc/jcc/sources/JObject.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/sources/JObject.cpp?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/jcc/sources/JObject.cpp (original)
+++ lucene/pylucene/branches/python_3/jcc/jcc/sources/JObject.cpp Mon Jul 12 19:30:05 2010
@@ -50,8 +50,7 @@ static PyGetSetDef t_JObject_properties[
 };
 
 PyTypeObject PY_TYPE(JObject) = {
-    PyObject_HEAD_INIT(NULL)
-    0,                                   /* ob_size */
+    PyVarObject_HEAD_INIT(&PyType_Type, 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,
@@ -149,21 +148,21 @@ static PyObject *t_JObject_str(t_JObject
         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);
+    PyObject *str = self->ob_base.ob_type->tp_str((PyObject *) self);
 #if PY_VERSION_HEX < 0x02040000
     PyObject *args = Py_BuildValue("(OO)", name, str);
 #else
     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);

Modified: lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.cpp?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.cpp (original)
+++ lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.cpp Mon Jul 12 19:30:05 2010
@@ -97,7 +97,7 @@ PyObject *findClass(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;
     
@@ -112,7 +112,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;
 
@@ -245,8 +245,7 @@ int _parseArgs(PyObject **args, unsigned
                   if (PyObject_TypeCheck(arg, PY_TYPE(JArrayObject)))
                       break;
 
-                  if (PySequence_Check(arg) &&
-                      !PyString_Check(arg) && !PyUnicode_Check(arg))
+                  if (PySequence_Check(arg) && !PyUnicode_Check(arg))
                   {
                       if (PySequence_Length(arg) > 0)
                       {
@@ -329,9 +328,9 @@ int _parseArgs(PyObject **args, unsigned
                   if (PyObject_TypeCheck(arg, PY_TYPE(JArrayByte)))
                       break;
               }
-              else if (PyString_Check(arg) && (PyString_Size(arg) == 1))
+              else if (PyUnicode_Check(arg) && (PyUnicode_GetSize(arg) == 1))
                   break;
-              else if (PyInt_CheckExact(arg))
+              else if (PyLong_CheckExact(arg))
                   break;
 
               return -1;
@@ -366,7 +365,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)
@@ -376,7 +375,7 @@ int _parseArgs(PyObject **args, unsigned
                           break;
                   }
               }
-              else if (PyInt_CheckExact(arg))
+              else if (PyLong_CheckExact(arg))
                   break;
 
               return -1;
@@ -397,7 +396,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)
@@ -407,7 +406,7 @@ int _parseArgs(PyObject **args, unsigned
                           break;
                   }
               }
-              else if (PyInt_CheckExact(arg))
+              else if (PyLong_CheckExact(arg))
                   break;
 
               return -1;
@@ -516,15 +515,12 @@ 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) && !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));
+                          int ok = (obj == Py_None || PyUnicode_Check(obj));
 
                           Py_DECREF(obj);
                           if (ok)
@@ -534,8 +530,7 @@ int _parseArgs(PyObject **args, unsigned
                           break;
                   }
               }
-              else if (arg == Py_None ||
-                       PyString_Check(arg) || PyUnicode_Check(arg))
+              else if (arg == Py_None || PyUnicode_Check(arg))
                   break;
 
               return -1;
@@ -560,7 +555,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))
@@ -715,15 +710,15 @@ int _parseArgs(PyObject **args, unsigned
                   if (PyErr_Occurred())
                       return -1;
               }
-              else if (PyString_Check(arg))
+              else if (PyUnicode_Check(arg))
               {
                   jbyte *a = va_arg(list, jbyte *);
-                  *a = (jbyte) PyString_AS_STRING(arg)[0];
+                  *a = (jbyte) PyUnicode_AS_UNICODE(arg)[0];
               }
               else
               {
                   jbyte *a = va_arg(list, jbyte *);
-                  *a = (jbyte) PyInt_AsLong(arg);
+                  *a = (jbyte) PyLong_AsLong(arg);
               }
               break;
           }
@@ -771,7 +766,7 @@ int _parseArgs(PyObject **args, unsigned
               else
               {
                   jint *n = va_arg(list, jint *);
-                  *n = (jint) PyInt_AsLong(arg);
+                  *n = (jint) PyLong_AsLong(arg);
               }
               break;
           }
@@ -795,7 +790,7 @@ int _parseArgs(PyObject **args, unsigned
               else
               {
                   jshort *n = va_arg(list, jshort *);
-                  *n = (jshort) PyInt_AsLong(arg);
+                  *n = (jshort) PyLong_AsLong(arg);
               }
               break;
           }
@@ -1090,7 +1085,7 @@ void throwPythonError(void)
         PyObject *name = PyObject_GetAttrString(exc, "__name__");
 
         env->get_vm_env()->ThrowNew(env->getPythonExceptionClass(),
-                                    PyString_AS_STRING(name));
+                                    PyUnicode_AsString(name));
         Py_DECREF(name);
     }
     else
@@ -1266,7 +1261,7 @@ jobjectArray fromPySequence(jclass cls, 
             break;
         else if (obj == Py_None)
             jobj = NULL;
-        else if (PyString_Check(obj) || PyUnicode_Check(obj))
+        else if (PyUnicode_Check(obj))
         {
             jobj = env->fromPyString(obj);
             fromString = 1;
@@ -1310,7 +1305,7 @@ void installType(PyTypeObject *type, PyO
         Py_INCREF(type);
         if (isExtension)
         {
-            type->ob_type = &PY_TYPE(FinalizerClass);
+            type->ob_base.ob_base.ob_type = &PY_TYPE(FinalizerClass);
             Py_INCREF(&PY_TYPE(FinalizerClass));
         }
         PyModule_AddObject(module, name, (PyObject *) type);
@@ -1319,7 +1314,7 @@ 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&);
     
@@ -1363,7 +1358,7 @@ PyObject *unboxByte(const jobject &obj)
             return NULL;
         }
         
-        return PyInt_FromLong((long) env->byteValue(obj));
+        return PyLong_FromLong((long) env->byteValue(obj));
     }
 
     Py_RETURN_NONE;
@@ -1432,7 +1427,7 @@ PyObject *unboxInteger(const jobject &ob
             return NULL;
         }
         
-        return PyInt_FromLong((long) env->intValue(obj));
+        return PyLong_FromLong((long) env->intValue(obj));
     }
 
     Py_RETURN_NONE;
@@ -1466,7 +1461,7 @@ PyObject *unboxShort(const jobject &obj)
             return NULL;
         }
         
-        return PyInt_FromLong((long) env->shortValue(obj));
+        return PyLong_FromLong((long) env->shortValue(obj));
     }
 
     Py_RETURN_NONE;
@@ -1555,9 +1550,9 @@ int boxByte(PyTypeObject *type, PyObject
     if (result <= 0)
         return result;
 
-    if (PyInt_Check(arg))
+    if (PyLong_Check(arg))
     {
-        int n = PyInt_AS_LONG(arg);
+        long n = PyLong_AS_LONG(arg);
         jbyte b = (jbyte) n;
 
         if (b == n)
@@ -1568,19 +1563,6 @@ int boxByte(PyTypeObject *type, PyObject
         else
             return -1;
     }
-    else if (PyLong_Check(arg))
-    {
-        PY_LONG_LONG ln = PyLong_AsLongLong(arg);
-        jbyte b = (jbyte) ln;
-
-        if (b == ln)
-        {
-            if (obj != NULL)
-                *obj = Byte(b);
-        }
-        else
-            return -1;
-    }
     else if (PyFloat_Check(arg))
     {
         double d = PyFloat_AS_DOUBLE(arg);
@@ -1607,18 +1589,7 @@ int boxCharacter(PyTypeObject *type, PyO
     if (result <= 0)
         return result;
 
-    if (PyString_Check(arg))
-    {
-        char *c;
-        Py_ssize_t len;
-
-        if (PyString_AsStringAndSize(arg, &c, &len) < 0 || len != 1)
-            return -1;
-
-        if (obj != NULL)
-            *obj = Character((jchar) c[0]);
-    }
-    else if (PyUnicode_Check(arg))
+    if (PyUnicode_Check(arg))
     {
         Py_ssize_t len = PyUnicode_GetSize(arg);
 
@@ -1626,7 +1597,7 @@ int boxCharacter(PyTypeObject *type, PyO
             return -1;
 
         if (obj != NULL)
-            *obj = Character((jchar) PyUnicode_AsUnicode(arg)[0]);
+            *obj = Character((jchar) PyUnicode_AS_UNICODE(arg)[0]);
     }
     else
         return -1;
@@ -1641,7 +1612,7 @@ int boxCharSequence(PyTypeObject *type, 
     if (result <= 0)
         return result;
 
-    if (PyString_Check(arg) || PyUnicode_Check(arg))
+    if (PyUnicode_Check(arg))
     {
         if (obj != NULL)
         {
@@ -1663,15 +1634,12 @@ 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));
+        if (PyErr_Occurred())
+            return -1;
     }
     else if (PyFloat_Check(arg))
     {
@@ -1691,16 +1659,14 @@ 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;
 
+        if (PyErr_Occurred())
+            return -1;
+
         if ((PY_LONG_LONG) f == ln)
         {
             if (obj != NULL)
@@ -1735,16 +1701,14 @@ int boxInteger(PyTypeObject *type, PyObj
     if (result <= 0)
         return result;
 
-    if (PyInt_Check(arg))
+    if (PyLong_Check(arg))
     {
-        if (obj != NULL)
-            *obj = Integer((jint) PyInt_AS_LONG(arg));
-    }
-    else if (PyLong_Check(arg))
-    {
-        PY_LONG_LONG ln = PyLong_AsLongLong(arg);
+        long ln = PyLong_AsLong(arg);
         int n = (int) ln;
 
+        if (PyErr_Occurred())
+            return -1;
+
         if (n == ln)
         {
             if (obj != NULL)
@@ -1779,15 +1743,12 @@ 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));
+        if (PyErr_Occurred())
+            return -1;
     }
     else if (PyFloat_Check(arg))
     {
@@ -1815,15 +1776,12 @@ 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));
+        if (PyErr_Occurred())
+            return -1;
     }
     else if (PyFloat_Check(arg))
     {
@@ -1843,25 +1801,15 @@ int boxShort(PyTypeObject *type, PyObjec
     if (result <= 0)
         return result;
 
-    if (PyInt_Check(arg))
+    if (PyLong_Check(arg))
     {
-        int n = (int) PyInt_AS_LONG(arg);
-        short sn = (short) n;
+        long n = (long) PyLong_AsLong(arg);
+        short sn = (short) (int) n;
 
-        if (sn == n)
-        {
-            if (obj != NULL)
-                *obj = Short((jshort) sn);
-        }
-        else
+        if (PyErr_Occurred())
             return -1;
-    }
-    else if (PyLong_Check(arg))
-    {
-        PY_LONG_LONG ln = PyLong_AsLongLong(arg);
-        short sn = (short) ln;
 
-        if (sn == ln)
+        if (sn == n)
         {
             if (obj != NULL)
                 *obj = Short((jshort) sn);
@@ -1895,7 +1843,7 @@ int boxString(PyTypeObject *type, PyObje
     if (result <= 0)
         return result;
 
-    if (PyString_Check(arg) || PyUnicode_Check(arg))
+    if (PyUnicode_Check(arg))
     {
         if (obj != NULL)
         {
@@ -1919,7 +1867,7 @@ int boxObject(PyTypeObject *type, PyObje
 
     if (obj != NULL)
     {
-        if (PyString_Check(arg) || PyUnicode_Check(arg))
+        if (PyUnicode_Check(arg))
         {
             *obj = p2j(arg);
             if (PyErr_Occurred())
@@ -1929,27 +1877,30 @@ 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);
+            PY_LONG_LONG lln = PyLong_AsLongLong(arg);
+            long ln = (long) lln;
             int n = (int) ln;
 
-            if (ln != (long) n)
+            if (PyErr_Occurred())
+                return -1;
+
+            if (lln != (long) ln)
+                *obj = Long((jlong) lln);
+            else if (ln != (long) n)
                 *obj = Long((jlong) ln);
             else
                 *obj = Integer((jint) n);
         }
-        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 (!(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;

Modified: lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.h?rev=963444&r1=963443&r2=963444&view=diff
==============================================================================
--- lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.h (original)
+++ lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.h Mon Jul 12 19:30:05 2010
@@ -33,6 +33,8 @@ typedef intintobjargproc ssizessizeobjar
 typedef PyTypeObject **(*getparametersfn)(void *);
 typedef int (*boxfn)(PyTypeObject *, PyObject *, java::lang::Object *);
 
+const char *PyUnicode_AsString(PyObject *obj);
+
 PyObject *PyErr_SetArgsError(char *name, PyObject *args);
 PyObject *PyErr_SetArgsError(PyObject *self, char *name, PyObject *args);
 PyObject *PyErr_SetArgsError(PyTypeObject *type, char *name, PyObject *args);
@@ -60,7 +62,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)