You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pylucene-commits@lucene.apache.org by va...@apache.org on 2017/03/19 20:26:49 UTC
svn commit: r1787656 [1/2] - in /lucene/pylucene/trunk/jcc: ./ _jcc/ _jcc2/
_jcc3/ _jcc3/java/lang/ _jcc3/java/lang/reflect/ helpers/ helpers2/
helpers3/ jcc/ jcc2/ jcc3/ jcc3/sources/
Author: vajda
Date: Sun Mar 19 20:26:48 2017
New Revision: 1787656
URL: http://svn.apache.org/viewvc?rev=1787656&view=rev
Log:
Added support for Python 3 (3.6+) (with R�diger Meier and Thomas Koch).
So far, tested only on Mac OSX 10.12.
Added:
lucene/pylucene/trunk/jcc/_jcc2/
- copied from r1759171, lucene/pylucene/trunk/jcc/_jcc/
lucene/pylucene/trunk/jcc/_jcc3/
- copied from r1759171, lucene/pylucene/trunk/jcc/_jcc/
lucene/pylucene/trunk/jcc/helpers2/
- copied from r1759171, lucene/pylucene/trunk/jcc/helpers/
lucene/pylucene/trunk/jcc/helpers3/
- copied from r1759171, lucene/pylucene/trunk/jcc/helpers/
lucene/pylucene/trunk/jcc/jcc2/
- copied from r1759171, lucene/pylucene/trunk/jcc/jcc/
lucene/pylucene/trunk/jcc/jcc2/cpp.py
- copied, changed from r1766805, lucene/pylucene/trunk/jcc/jcc/cpp.py
lucene/pylucene/trunk/jcc/jcc3/
- copied from r1759171, lucene/pylucene/trunk/jcc/jcc/
lucene/pylucene/trunk/jcc/jcc3/cpp.py
- copied, changed from r1766805, lucene/pylucene/trunk/jcc/jcc/cpp.py
Removed:
lucene/pylucene/trunk/jcc/_jcc/
lucene/pylucene/trunk/jcc/helpers/
lucene/pylucene/trunk/jcc/jcc/
Modified:
lucene/pylucene/trunk/jcc/CHANGES
lucene/pylucene/trunk/jcc/DESCRIPTION
lucene/pylucene/trunk/jcc/MANIFEST.in
lucene/pylucene/trunk/jcc/_jcc2/boot.cpp
lucene/pylucene/trunk/jcc/_jcc3/boot.cpp
lucene/pylucene/trunk/jcc/_jcc3/java/lang/Class.cpp
lucene/pylucene/trunk/jcc/_jcc3/java/lang/String.cpp
lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Constructor.cpp
lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Field.cpp
lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Method.cpp
lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Modifier.cpp
lucene/pylucene/trunk/jcc/helpers3/build.py
lucene/pylucene/trunk/jcc/helpers3/darwin.py
lucene/pylucene/trunk/jcc/helpers3/linux.py
lucene/pylucene/trunk/jcc/helpers3/windows.py
lucene/pylucene/trunk/jcc/jcc2/__init__.py
lucene/pylucene/trunk/jcc/jcc2/__main__.py
lucene/pylucene/trunk/jcc/jcc2/python.py
lucene/pylucene/trunk/jcc/jcc3/__init__.py
lucene/pylucene/trunk/jcc/jcc3/__main__.py
lucene/pylucene/trunk/jcc/jcc3/python.py
lucene/pylucene/trunk/jcc/jcc3/sources/JArray.cpp
lucene/pylucene/trunk/jcc/jcc3/sources/JArray.h
lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.cpp
lucene/pylucene/trunk/jcc/jcc3/sources/JCCEnv.h
lucene/pylucene/trunk/jcc/jcc3/sources/JObject.cpp
lucene/pylucene/trunk/jcc/jcc3/sources/functions.cpp
lucene/pylucene/trunk/jcc/jcc3/sources/functions.h
lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp
lucene/pylucene/trunk/jcc/jcc3/sources/macros.h
lucene/pylucene/trunk/jcc/jcc3/sources/types.cpp
lucene/pylucene/trunk/jcc/jcc3/windows.py
lucene/pylucene/trunk/jcc/setup.py
Modified: lucene/pylucene/trunk/jcc/CHANGES
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/CHANGES?rev=1787656&r1=1787655&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/CHANGES (original)
+++ lucene/pylucene/trunk/jcc/CHANGES Sun Mar 19 20:26:48 2017
@@ -1,3 +1,8 @@
+Version 2.23 -> 3.0
+-------------------
+ - added support for Python 3.6 (with R�diger Meier and Thomas Koch)
+ -
+
Version 2.22 -> 2.23
--------------------
- extended ability to explicitely requesting wrappers to fields
Modified: lucene/pylucene/trunk/jcc/DESCRIPTION
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/DESCRIPTION?rev=1787656&r1=1787655&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/DESCRIPTION (original)
+++ lucene/pylucene/trunk/jcc/DESCRIPTION Sun Mar 19 20:26:48 2017
@@ -13,13 +13,10 @@ Python interpreter. JCC attempts to make
detecting iterators and property accessors. Iterators and mappings may also
be declared to JCC.
-JCC has been built on Python 2.3, 2.4, 2.5, 2.6 and 2.7 and has been used with
-various Java Runtime Environments such as Sun Java 1.5 and 1.6, Apple's
+JCC has been built on Python 2.3 to 2.7, on Python 3.6, and has been used
+with various Java Runtime Environments such as Sun Java 1.5 and 1.6, Apple's
Java 1.5 and 1.6 on Mac OS X, open source Java OpenJDK 1.7 builds as well as
-Oracle Java 1.7.
-
-An experimental port to Python 3 is available from a branch:
- http://svn.apache.org/repos/asf/lucene/pylucene/branches/python_3/jcc/
+Oracle Java 1.7 and 1.8.
JCC is supported on Mac OS X, Linux, Solaris and Windows.
@@ -33,10 +30,8 @@ JCC is built with distutils or setuptool
Setuptools is required to build JCC on Python 2.3.
-Except for Mac OS X - where Apple's Java comes pre-installed in a known
-framework location - JCC's setup.py file needs to be edited before building
-JCC to specify the location of the Java Runtime Environment's header files
-and libraries.
+JCC's setup.py file needs to be edited before building JCC to specify the
+location of the Java Runtime Environment's header files and libraries.
The svn sources for JCC are available at:
http://svn.apache.org/repos/asf/lucene/pylucene/trunk/jcc/
Modified: lucene/pylucene/trunk/jcc/MANIFEST.in
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/MANIFEST.in?rev=1787656&r1=1787655&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/MANIFEST.in (original)
+++ lucene/pylucene/trunk/jcc/MANIFEST.in Sun Mar 19 20:26:48 2017
@@ -1,9 +1,14 @@
-exclude jcc/config.py
-include jcc/patches/patch.*
-recursive-include jcc *.h
-recursive-include _jcc *.h
+exclude jcc2/config.py
+exclude jcc3/config.py
+include jcc2/patches/patch.*
+include jcc3/patches/patch.*
+recursive-include jcc2 *.h
+recursive-include jcc3 *.h
+recursive-include _jcc2 *.h
+recursive-include _jcc3 *.h
recursive-include java *.java
-recursive-include helpers *.py
+recursive-include helpers2 *.py
+recursive-include helpers3 *.py
include CHANGES
include DESCRIPTION
include INSTALL
Modified: lucene/pylucene/trunk/jcc/_jcc2/boot.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc2/boot.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc2/boot.cpp (original)
+++ lucene/pylucene/trunk/jcc/_jcc2/boot.cpp Sun Mar 19 20:26:48 2017
@@ -49,9 +49,9 @@ PyObject *__initialize__(PyObject *modul
extern "C" {
- void init_jcc(void)
+ void init_jcc2(void)
{
- PyObject *m = Py_InitModule3("_jcc", jcc_funcs, "_jcc");
+ PyObject *m = Py_InitModule3("_jcc2", jcc_funcs, "_jcc2");
initJCC(m);
Modified: lucene/pylucene/trunk/jcc/_jcc3/boot.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc3/boot.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc3/boot.cpp (original)
+++ lucene/pylucene/trunk/jcc/_jcc3/boot.cpp Sun Mar 19 20:26:48 2017
@@ -49,9 +49,24 @@ PyObject *__initialize__(PyObject *modul
extern "C" {
- void init_jcc(void)
+static struct PyModuleDef _jccmodule = {
+ PyModuleDef_HEAD_INIT, /* m_base */
+ "_jcc3", /* m_name */
+ "_jcc3 module", /* m_doc */
+ 0, /* m_size */
+ jcc_funcs, /* m_methods */
+ 0, /* m_reload */
+ 0, /* m_traverse */
+ 0, /* m_clear */
+ 0, /* m_free */
+ };
+
+ PyObject *PyInit__jcc3(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/trunk/jcc/_jcc3/java/lang/Class.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc3/java/lang/Class.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc3/java/lang/Class.cpp (original)
+++ lucene/pylucene/trunk/jcc/_jcc3/java/lang/Class.cpp Sun Mar 19 20:26:48 2017
@@ -397,17 +397,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:
@@ -588,7 +585,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/trunk/jcc/_jcc3/java/lang/String.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc3/java/lang/String.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc3/java/lang/String.cpp (original)
+++ lucene/pylucene/trunk/jcc/_jcc3/java/lang/String.cpp Sun Mar 19 20:26:48 2017
@@ -41,13 +41,13 @@ namespace java {
jclass cls = env->findClass("java/lang/String");
_mids = new jmethodID[max_mid];
- _mids[mid__init_] =
+ _mids[mid__init_] =
env->getMethodID(cls, "<init>",
"()V");
- _mids[mid_toString] =
+ _mids[mid_toString] =
env->getMethodID(cls, "toString",
"()Ljava/lang/String;");
- _mids[mid_length] =
+ _mids[mid_length] =
env->getMethodID(cls, "length",
"()I");
@@ -99,13 +99,13 @@ namespace java {
case 1:
if (!PyArg_ParseTuple(args, "s", &bytes))
return -1;
- INT_CALL(self->object = String(env->fromUTF(bytes)));
+ INT_CALL(self->object = String(env->fromUTF8(bytes)));
break;
default:
PyErr_SetString(PyExc_ValueError, "invalid args");
return -1;
}
-
+
return 0;
}
@@ -114,7 +114,7 @@ namespace java {
jint length;
OBJ_CALL(length = self->object.length());
- return PyInt_FromLong(length);
+ return PyLong_FromLong(length);
}
}
}
Modified: lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Constructor.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Constructor.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Constructor.cpp (original)
+++ lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Constructor.cpp Sun Mar 19 20:26:48 2017
@@ -78,7 +78,7 @@ namespace java {
class$ = (Class *) new JObject(cls);
}
-
+
return (jclass) class$->this$;
}
@@ -161,7 +161,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/trunk/jcc/_jcc3/java/lang/reflect/Field.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Field.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Field.cpp (original)
+++ lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Field.cpp Sun Mar 19 20:26:48 2017
@@ -128,7 +128,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/trunk/jcc/_jcc3/java/lang/reflect/Method.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Method.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Method.cpp (original)
+++ lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Method.cpp Sun Mar 19 20:26:48 2017
@@ -101,7 +101,7 @@ namespace java {
class$ = (Class *) new JObject(cls);
}
-
+
return (jclass) class$->this$;
}
@@ -244,7 +244,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/trunk/jcc/_jcc3/java/lang/reflect/Modifier.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Modifier.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Modifier.cpp (original)
+++ lucene/pylucene/trunk/jcc/_jcc3/java/lang/reflect/Modifier.cpp Sun Mar 19 20:26:48 2017
@@ -70,7 +70,7 @@ namespace java {
class$ = (Class *) new JObject(cls);
}
-
+
return (jclass) class$->this$;
}
@@ -152,105 +152,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/trunk/jcc/helpers3/build.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/helpers3/build.py?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/helpers3/build.py (original)
+++ lucene/pylucene/trunk/jcc/helpers3/build.py Sun Mar 19 20:26:48 2017
@@ -24,7 +24,7 @@ class jcc_build_py(build_py):
return build_py.run(self)
def write_jcc_config(self):
- # only write jcc's config.py file if it doesn't exist or a build
+ # only write jcc's config.py file if it doesn't exist or a build
# command is given
write = False
if not os.path.isfile(self.config_file):
Modified: lucene/pylucene/trunk/jcc/helpers3/darwin.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/helpers3/darwin.py?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/helpers3/darwin.py (original)
+++ lucene/pylucene/trunk/jcc/helpers3/darwin.py Sun Mar 19 20:26:48 2017
@@ -19,22 +19,21 @@ JAVAFRAMEWORKS = None
if sys.platform == "darwin":
# figure out where the JDK lives
- from subprocess import Popen, PIPE
+ from subprocess import run, PIPE
try:
args = ['/usr/libexec/java_home']
- process = Popen(args, stdout=PIPE, stderr=PIPE)
- except Exception, e:
- print >>sys.stderr, "%s: %s" %(e, args)
+ process = run(args, stdout=PIPE, stderr=PIPE, encoding='utf8')
+ except Exception as e:
+ print("%s: %s" %(e, args), file=sys.stderr)
else:
- process.wait()
if process.returncode == 0:
- _path = process.stdout.read().strip()
+ _path = process.stdout.strip()
if os.path.exists(os.path.join(_path, "include", "jni.h")):
JAVAHOME = _path
- print >>sys.stderr, 'found JAVAHOME =', JAVAHOME
+ print('found JAVAHOME =', JAVAHOME, file=sys.stderr)
else:
- print >>sys.stderr, process.stderr.read()
+ print(process.stderr.read(), file=sys.stderr)
# figure out where the JDK Frameworks lives
import platform, re
@@ -44,22 +43,26 @@ if sys.platform == "darwin":
_path = "/System/Library/Frameworks/JavaVM.framework"
if os.path.exists(os.path.join(_path, "Headers", "jni.h")):
JAVAFRAMEWORKS = _path
- print >>sys.stderr, 'found JAVAFRAMEWORKS =', JAVAFRAMEWORKS
+ print('found JAVAFRAMEWORKS =', JAVAFRAMEWORKS, file=sys.stderr)
else:
- # but their updates don't always match their documentation,
+ # but their updates don't always match their documentation,
# so look up the same path in the OS's /Developer tree
_path = "/Developer/SDKs/MacOSX%s.sdk%s" %(_os_version, _path)
if os.path.exists(os.path.join(_path, "Headers", "jni.h")):
JAVAFRAMEWORKS = _path
- print >>sys.stderr, 'found JAVAFRAMEWORKS =', JAVAFRAMEWORKS
+ print('found JAVAFRAMEWORKS =', JAVAFRAMEWORKS, file=sys.stderr)
- # monkeypatch customize_compiler so that we can remove -Wl,-x from LDSHARED
- # set in setuptools.command.build_ext.build_ext.setup_shlib_compiler
- from distutils.sysconfig import customize_compiler, get_config_vars
-
- def _customize_compiler(compiler):
- get_config_vars()['LDSHARED'] = "gcc -dynamiclib -undefined dynamic_lookup"
- customize_compiler(compiler)
+ # monkeypatch build_ext so that it doesn't mess with a Library's extension
+ from setuptools.command.build_ext import build_ext as _build_ext
+ from setuptools.extension import Library
+
+ class build_ext_(_build_ext):
+ def get_ext_filename(self, fullname):
+ if fullname in self.ext_map:
+ ext = self.ext_map[fullname]
+ if isinstance(ext, Library):
+ return "lib%s.dylib" %(fullname)
+ return _build_ext.get_ext_filename(self, fullname)
- from distutils import sysconfig
- sysconfig.customize_compiler = _customize_compiler
+ from setuptools.command import build_ext
+ build_ext.build_ext = build_ext_
Modified: lucene/pylucene/trunk/jcc/helpers3/linux.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/helpers3/linux.py?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/helpers3/linux.py (original)
+++ lucene/pylucene/trunk/jcc/helpers3/linux.py Sun Mar 19 20:26:48 2017
@@ -57,7 +57,7 @@ def patch_setuptools(with_setuptools):
except ImportError:
jccdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
st_egg = os.path.dirname(setuptools.__path__[0])
-
+
setuptools.Library = LinuxLibrary
extension.Library = LinuxLibrary
build_ext.build_ext = LinuxBuildExt
@@ -69,8 +69,8 @@ def patch_setuptools(with_setuptools):
# Build static libraries every where else (unless forced)
build_ext.libtype = 'static'
build_ext.link_shared_object = st_link_shared_object
-
- print >>sys.stderr, "Applied shared mode monkey patch to:", setuptools
+
+ print("Applied shared mode monkey patch to:", setuptools, file=sys.stderr)
return True # monkey patch was applied
return enable_shared
Modified: lucene/pylucene/trunk/jcc/helpers3/windows.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/helpers3/windows.py?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/helpers3/windows.py (original)
+++ lucene/pylucene/trunk/jcc/helpers3/windows.py Sun Mar 19 20:26:48 2017
@@ -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/trunk/jcc/jcc2/__init__.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc2/__init__.py?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc2/__init__.py (original)
+++ lucene/pylucene/trunk/jcc/jcc2/__init__.py Sun Mar 19 20:26:48 2017
@@ -20,7 +20,7 @@ if sys.platform == 'win32':
from windows import add_jvm_dll_directory_to_path
add_jvm_dll_directory_to_path()
- from jcc.config import SHARED
+ from jcc2.config import SHARED
if SHARED:
path = os.environ['Path'].split(os.pathsep)
eggpath = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
@@ -28,13 +28,13 @@ if sys.platform == 'win32':
path.insert(0, eggpath)
os.environ['Path'] = os.pathsep.join(path)
-from jcc import _jcc
+from jcc import _jcc2
# used when jcc is invoked with -m from python 2.5
if __name__ == '__main__':
import jcc.__main__
else:
- from _jcc import initVM
+ from _jcc2 import initVM
CLASSPATH=os.path.join(os.path.abspath(os.path.dirname(__file__)), "classes")
-_jcc.CLASSPATH = CLASSPATH
+_jcc2.CLASSPATH = CLASSPATH
Modified: lucene/pylucene/trunk/jcc/jcc2/__main__.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc2/__main__.py?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc2/__main__.py (original)
+++ lucene/pylucene/trunk/jcc/jcc2/__main__.py Sun Mar 19 20:26:48 2017
@@ -12,7 +12,7 @@ if len(sys.argv) == 1 or '--help' in sys
Input options:
--jar JARFILE - make JCC wrap all public classes found in
JARFILE, add it to the module's CLASSPATH and
- include it in the distribution
+ include it in the distribution
--include JARFILE - include JARFILE in the distribution and add
it to the module's CLASSPATH
--import MODULE - link against the wrappers to classes shared
@@ -22,9 +22,9 @@ if len(sys.argv) == 1 or '--help' in sys
--package PACKAGE - add PACKAGE to the list of packages from
which dependencies are automatically wrapped
--classpath [PATH|JAR] - add [PATH|JAR] to CLASSPATH while generating
- wrappers
+ wrappers
--libpath [PATH] - add [PATH] to java.library.path while generating
- wrappers
+ wrappers
--module MODULE - include Python MODULE in the distribution
--reserved SYMBOL - mark SYMBOL as a reserved word that will be
mangled in the generated C++ code to avoid
@@ -70,7 +70,7 @@ if len(sys.argv) == 1 or '--help' in sys
'build' by default
--files N - split the generated wrapper file into at least
N files to workaround C++ compiler file size
- limitations
+ limitations
--arch - Mac OS X only: filter the -arch parameters
Python was configured with to build leaner
binaries, faster
@@ -103,5 +103,5 @@ if len(sys.argv) == 1 or '--help' in sys
'''
print help
sys.exit(0)
-
+
cpp.jcc(sys.argv)
Copied: lucene/pylucene/trunk/jcc/jcc2/cpp.py (from r1766805, lucene/pylucene/trunk/jcc/jcc/cpp.py)
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc2/cpp.py?p2=lucene/pylucene/trunk/jcc/jcc2/cpp.py&p1=lucene/pylucene/trunk/jcc/jcc/cpp.py&r1=1766805&r2=1787656&rev=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/cpp.py (original)
+++ lucene/pylucene/trunk/jcc/jcc2/cpp.py Sun Mar 19 20:26:48 2017
@@ -10,7 +10,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os, sys, zipfile, _jcc
+import os, sys, zipfile, _jcc2
python_ver = '%d.%d.%d' %(sys.version_info[0:3])
if python_ver < '2.4':
@@ -62,9 +62,9 @@ class InvalidArgsError(Exception):
pass
-_jcc._set_exception_types(JavaError, InvalidArgsError)
-from _jcc import findClass as _findClass
-from _jcc import *
+_jcc2._set_exception_types(JavaError, InvalidArgsError)
+from _jcc2 import findClass as _findClass
+from _jcc2 import *
def findClass(className):
@@ -383,7 +383,7 @@ def jcc(args):
listedMethodOrFieldNames = {}
packages = set()
jars = []
- classpath = [_jcc.CLASSPATH]
+ classpath = [_jcc2.CLASSPATH]
libpath = []
vmargs = ['-Djava.awt.headless=true']
moduleName = None
@@ -412,13 +412,13 @@ def jcc(args):
wininst = False
find_jvm_dll = False
compiler = None
- generics = hasattr(_jcc, "Type")
+ generics = hasattr(_jcc2, "Type")
arch = []
resources = []
imports = {}
extra_setup_args = []
initvm_args = {}
-
+
i = 1
while i < len(args):
arg = args[i]
Modified: lucene/pylucene/trunk/jcc/jcc2/python.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc2/python.py?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc2/python.py (original)
+++ lucene/pylucene/trunk/jcc/jcc2/python.py Sun Mar 19 20:26:48 2017
@@ -12,7 +12,7 @@
# limitations under the License.
#
-import os, sys, platform, shutil, _jcc
+import os, sys, platform, shutil, _jcc2
from itertools import izip
from cpp import PRIMITIVES, INDENT, HALF_INDENT
@@ -1766,7 +1766,7 @@ def compile(env, jccPath, output, module
if egg_info:
script_args = ['egg_info']
- else:
+ else:
script_args = ['build_ext']
includes[0:0] = INCLUDES
@@ -1821,7 +1821,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(_jcc2.__file__))
if sys.platform == 'darwin': # distutils no good with -R
machine = platform.machine()
if machine.startswith('iPod') or machine.startswith('iPhone'):
@@ -1829,11 +1829,11 @@ def compile(env, jccPath, output, module
else:
args['extra_link_args'] += ['-Wl,-rpath', shlibdir]
args['library_dirs'] = [shlibdir]
- args['libraries'] = ['jcc']
+ args['libraries'] = ['jcc2']
elif sys.platform == 'linux2': # distutils no good with -R
args['extra_link_args'] += ['-Wl,-rpath', shlibdir]
args['library_dirs'] = [shlibdir]
- args['libraries'] = ['jcc']
+ args['libraries'] = ['jcc2']
args['extra_link_args'] += [
getattr(import_, "_%s" %(import_.__name__)).__file__
for import_ in imports
@@ -1846,7 +1846,7 @@ def compile(env, jccPath, output, module
extlib = os.path.join('lib', "%s%s.lib" %(extname, _d))
package_data.append(extlib)
args['extra_link_args'] += [
- os.path.join(shlibdir, 'jcc', 'jcc%s.lib' %(_d)),
+ os.path.join(shlibdir, 'jcc2', 'jcc2%s.lib' %(_d)),
' '.join(IMPLIB_LFLAGS) %(os.path.join(modulePath, extlib))
]
args['libraries'] = [
Modified: lucene/pylucene/trunk/jcc/jcc3/__init__.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/__init__.py?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/__init__.py (original)
+++ lucene/pylucene/trunk/jcc/jcc3/__init__.py Sun Mar 19 20:26:48 2017
@@ -17,7 +17,7 @@ import os, sys
if sys.platform == 'win32':
if '--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.config import SHARED
@@ -28,13 +28,13 @@ if sys.platform == 'win32':
path.insert(0, eggpath)
os.environ['Path'] = os.pathsep.join(path)
-from jcc import _jcc
+import jcc._jcc3 as _jcc3
-# used when jcc is invoked with -m from python 2.5
+# used when jcc is invoked with -m
if __name__ == '__main__':
import jcc.__main__
else:
- from _jcc import initVM
+ from ._jcc3 import initVM
CLASSPATH=os.path.join(os.path.abspath(os.path.dirname(__file__)), "classes")
-_jcc.CLASSPATH = CLASSPATH
+_jcc3.CLASSPATH = CLASSPATH
Modified: lucene/pylucene/trunk/jcc/jcc3/__main__.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/__main__.py?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/__main__.py (original)
+++ lucene/pylucene/trunk/jcc/jcc3/__main__.py Sun Mar 19 20:26:48 2017
@@ -12,7 +12,7 @@ if len(sys.argv) == 1 or '--help' in sys
Input options:
--jar JARFILE - make JCC wrap all public classes found in
JARFILE, add it to the module's CLASSPATH and
- include it in the distribution
+ include it in the distribution
--include JARFILE - include JARFILE in the distribution and add
it to the module's CLASSPATH
--import MODULE - link against the wrappers to classes shared
@@ -22,9 +22,9 @@ if len(sys.argv) == 1 or '--help' in sys
--package PACKAGE - add PACKAGE to the list of packages from
which dependencies are automatically wrapped
--classpath [PATH|JAR] - add [PATH|JAR] to CLASSPATH while generating
- wrappers
+ wrappers
--libpath [PATH] - add [PATH] to java.library.path while generating
- wrappers
+ wrappers
--module MODULE - include Python MODULE in the distribution
--reserved SYMBOL - mark SYMBOL as a reserved word that will be
mangled in the generated C++ code to avoid
@@ -70,7 +70,7 @@ if len(sys.argv) == 1 or '--help' in sys
'build' by default
--files N - split the generated wrapper file into at least
N files to workaround C++ compiler file size
- limitations
+ limitations
--arch - Mac OS X only: filter the -arch parameters
Python was configured with to build leaner
binaries, faster
@@ -101,7 +101,7 @@ if len(sys.argv) == 1 or '--help' in sys
--extra-setup-arg - pass an extra argument on setup.py command line
(pip install uses --egg-base and --record params)
'''
- print help
+ print(help)
sys.exit(0)
-
+
cpp.jcc(sys.argv)
Copied: lucene/pylucene/trunk/jcc/jcc3/cpp.py (from r1766805, lucene/pylucene/trunk/jcc/jcc/cpp.py)
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/cpp.py?p2=lucene/pylucene/trunk/jcc/jcc3/cpp.py&p1=lucene/pylucene/trunk/jcc/jcc/cpp.py&r1=1766805&r2=1787656&rev=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/cpp.py (original)
+++ lucene/pylucene/trunk/jcc/jcc3/cpp.py Sun Mar 19 20:26:48 2017
@@ -10,40 +10,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os, sys, zipfile, _jcc
+import os, sys, zipfile
+from . import _jcc3
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()
-
class JavaError(Exception):
@@ -62,9 +32,9 @@ class InvalidArgsError(Exception):
pass
-_jcc._set_exception_types(JavaError, InvalidArgsError)
-from _jcc import findClass as _findClass
-from _jcc import *
+_jcc3._set_exception_types(JavaError, InvalidArgsError)
+from ._jcc3 import findClass as _findClass
+from ._jcc3 import *
def findClass(className):
@@ -72,11 +42,11 @@ def findClass(className):
try:
cls = _findClass(className)
except:
- print >>sys.stderr, "While loading", className
+ print("While loading", className, file=sys.stderr)
raise
if cls is None:
- raise ValueError, className
+ raise ValueError(className)
return cls
@@ -154,9 +124,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
@@ -200,7 +170,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()
@@ -216,7 +186,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()
@@ -250,7 +220,7 @@ def addRequiredTypes(cls, typeset, gener
gat = GenericArrayType.cast_(cls)
addRequiredTypes(gat.getGenericComponentType(), typeset, True)
elif not (TypeVariable.instance_(cls) or WildcardType.instance_(cls)):
- raise NotImplementedError, repr(cls)
+ raise NotImplementedError(repr(cls))
else:
if cls not in typeset:
typeset.add(cls)
@@ -306,7 +276,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
@@ -355,7 +325,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:
@@ -383,7 +353,7 @@ def jcc(args):
listedMethodOrFieldNames = {}
packages = set()
jars = []
- classpath = [_jcc.CLASSPATH]
+ classpath = [_jcc3.CLASSPATH]
libpath = []
vmargs = ['-Djava.awt.headless=true']
moduleName = None
@@ -412,13 +382,13 @@ def jcc(args):
wininst = False
find_jvm_dll = False
compiler = None
- generics = hasattr(_jcc, "Type")
+ generics = hasattr(_jcc3, "Type")
arch = []
resources = []
imports = {}
extra_setup_args = []
initvm_args = {}
-
+
i = 1
while i < len(args):
arg = args[i]
@@ -448,23 +418,23 @@ def jcc(args):
i += 1
initvm_args['maxheap'] = 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 == '--egg-info':
- from python import compile
+ from .python import compile
egg_info = True
elif arg == '--extra-setup-arg':
i += 1
@@ -514,10 +484,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':
@@ -540,7 +510,7 @@ def jcc(args):
i += 1
imports[args[i]] = ()
else:
- raise ValueError, "Invalid argument: %s" %(arg)
+ raise ValueError("Invalid argument: %s" %(arg))
else:
if ':' in arg:
arg, method = arg.split(':', 1)
@@ -564,11 +534,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 or egg_info):
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,
@@ -578,7 +548,8 @@ def jcc(args):
egg_info, extra_setup_args)
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:],
@@ -586,7 +557,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))
@@ -635,22 +606,22 @@ 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()
pythonNames = {}
- for importset in imports.itervalues():
+ for importset in imports.values():
done.update(importset)
if moduleName:
for cls in importset:
- name = split_pkg(cls.getName(), '.')[-1]
+ name = cls.getName().rsplit('.', 1)[-1]
if not use_full_names:
if name in pythonNames:
- raise ValueError, (cls, 'python class name already in use, use --rename', name, pythonNames[name])
+ raise ValueError(cls, 'python class name already in use, use --rename', name, pythonNames[name])
else:
pythonNames[name] = cls
@@ -668,7 +639,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))
@@ -680,7 +651,7 @@ def jcc(args):
_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,
@@ -690,7 +661,7 @@ def jcc(args):
name = renames.get(className) or names[-1]
if not use_full_names:
if name in pythonNames:
- raise ValueError, (cls, 'python class name already in use, use --rename', name, pythonNames[name])
+ raise ValueError(cls, 'python class name already in use, use --rename', name, pythonNames[name])
else:
pythonNames[name] = cls
python(env, out_h, out_cpp,
@@ -713,9 +684,9 @@ def jcc(args):
out_cpp.close()
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')
classCount = 0
-
+
done.update(todo)
todo = typeset - done
@@ -723,7 +694,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, use_full_names)
out.close()
@@ -753,7 +724,7 @@ def header(env, out, cls, typeset, packa
pt = ParameterizedType.cast_(interface)
interface = Class.cast_(pt.getRawType())
else:
- raise NotImplementedError, repr(interface)
+ raise NotImplementedError(repr(interface))
if superCls and interface.isAssignableFrom(superCls):
continue
if known(interface, typeset, declares, packages, excludes, False):
@@ -814,7 +785,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 = []
@@ -850,14 +821,8 @@ def header(env, out, cls, typeset, packa
elif Modifier.isProtected(modifiers):
protectedMethods.append(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())))
methodNames = set([cppname(method.getName()) for method in methods])
for constructor in constructors:
@@ -892,8 +857,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('.')
@@ -974,7 +939,7 @@ def header(env, out, cls, typeset, packa
fieldType = field.getType()
fieldName = cppname(field.getName())
if fieldName in methodNames:
- print >>sys.stderr, " Warning: renaming static variable '%s' on class %s to '%s%s' since it is shadowed by a method of same name." %(fieldName, '.'.join(names), fieldName, RENAME_FIELD_SUFFIX)
+ print(" Warning: renaming static variable '%s' on class %s to '%s%s' since it is shadowed by a method of same name." %(fieldName, '.'.join(names), fieldName, RENAME_FIELD_SUFFIX), file=sys.stderr)
fieldName += RENAME_FIELD_SUFFIX
if fieldType.isPrimitive():
line(out, indent, 'static %s %s;',
Modified: lucene/pylucene/trunk/jcc/jcc3/python.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/python.py?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/python.py (original)
+++ lucene/pylucene/trunk/jcc/jcc3/python.py Sun Mar 19 20:26:48 2017
@@ -12,20 +12,20 @@
# limitations under the License.
#
-import os, sys, platform, shutil, _jcc
-from itertools import izip
+import os, sys, platform, shutil
+from . import _jcc3
-from cpp import PRIMITIVES, INDENT, HALF_INDENT
-from cpp import RENAME_METHOD_SUFFIX, RENAME_FIELD_SUFFIX
-from cpp import cppname, cppnames, absname, typename, findClass
-from cpp import line, signature, find_method, split_pkg, sort
-from cpp import Modifier, Class, Method
-from cpp import getActualTypeArguments, getTypeParameters
-from config import INCLUDES, CFLAGS, DEBUG_CFLAGS, LFLAGS, IMPLIB_LFLAGS, \
+from .cpp import PRIMITIVES, INDENT, HALF_INDENT
+from .cpp import RENAME_METHOD_SUFFIX, RENAME_FIELD_SUFFIX
+from .cpp import cppname, cppnames, absname, typename, findClass
+from .cpp import line, signature, find_method
+from .cpp import Modifier, Class, Method
+from .cpp import getActualTypeArguments, getTypeParameters
+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
@@ -35,18 +35,18 @@ if python_ver < '2.4':
RESULTS = { 'boolean': 'Py_RETURN_BOOL(%s);',
- 'byte': 'return PyInt_FromLong((long) %s);',
- 'char': 'return PyUnicode_FromUnicode((Py_UNICODE *) &%s, 1);',
+ 'byte': 'return PyLong_FromLong((long) %s);',
+ 'char': 'return c2p(%s);',
'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),
- 'char': ('O', 'PyUnicode_FromUnicode((Py_UNICODE *) &%s, 1)', True),
+ 'byte': ('O', 'PyLong_FromLong(%s)', True),
+ 'char': ('O', 'c2p(%s);', True),
'double': ('d', '(double) %s', False),
'float': ('f', '(float) %s', False),
'int': ('i', '(int) %s', False),
@@ -134,20 +134,20 @@ def parseArgs(params, current, generics,
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,
@@ -185,7 +185,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 generics:
@@ -208,7 +208,7 @@ def construct(out, indent, cls, inCase,
clsArg = '&%s::PY_TYPE(%s)' %(absname(cppnames(clsNames[:-1])), cppname(clsNames[-1]))
line(out, indent, 'self->parameters[%d] = %s;', i, clsArg)
i += 1
-
+
if inCase:
line(out, indent, 'break;')
@@ -226,7 +226,7 @@ def rpartition(string, sep):
if python_ver >= '2.5.0':
return string.rpartition(sep)
else:
- parts = split_pkg(string, sep)
+ parts = string.rsplit(sep, 1)
if len(parts) == 1:
return ('', '', parts[0])
return (parts[0], sep, parts[1])
@@ -376,16 +376,16 @@ def call(out, indent, cls, inCase, metho
if Modifier.isStatic(modifiers):
line(out, indent, 'OBJ_CALL(%s%s::%s(%s));',
result, absname(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, Py_TYPE(self)))')
line(out, indent, '{')
line(out, indent + 1, 'PyObject *_arg = ((t_fp *) arg)->object;')
line(out, indent + 1, '((t_JObject *) _arg)->object = object;')
@@ -437,7 +437,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
@@ -688,14 +688,14 @@ def python(env, out_h, out, cls, superCl
elif name + RENAME_METHOD_SUFFIX in allMethods:
allMethods[name + RENAME_METHOD_SUFFIX].append(method)
else:
- print >>sys.stderr, " Warning: renaming static method '%s' on class %s to '%s%s' since it is shadowed by non-static method of same name." %(name, '.'.join(names), name, RENAME_METHOD_SUFFIX)
+ print(" Warning: renaming static method '%s' on class %s to '%s%s' since it is shadowed by non-static method of same name." %(name, '.'.join(names), name, RENAME_METHOD_SUFFIX), file=sys.stderr)
allMethods[name + RENAME_METHOD_SUFFIX] = [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%s' since it is shadowed by non-static method of same name." %(name, '.'.join(names), name, RENAME_METHOD_SUFFIX)
+ print(" Warning: renaming static method '%s' on class %s to '%s%s' since it is shadowed by non-static method of same name." %(name, '.'.join(names), name, RENAME_METHOD_SUFFIX), file=sys.stderr)
allMethods[name + RENAME_METHOD_SUFFIX] = allMethods[name]
allMethods[name] = [method]
else:
@@ -718,15 +718,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
@@ -747,7 +747,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:
@@ -785,7 +785,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:
@@ -1160,7 +1160,7 @@ def python(env, out_h, out, cls, superCl
for constructor in constructors:
params = constructor.getParameterTypes()
if len(params) != currLen:
- if currLen >= 0:
+ if currLen > 0:
withErr = True
line(out, indent + 2, 'goto err;')
currLen = len(params)
@@ -1323,7 +1323,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
@@ -1429,7 +1429,7 @@ def python(env, out_h, out, cls, superCl
def package(out, allInOne, cppdir, namespace, names, use_full_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:
@@ -1447,8 +1447,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:
@@ -1549,10 +1549,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:
@@ -1575,11 +1575,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)
@@ -1589,6 +1595,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, '}')
@@ -1603,12 +1611,12 @@ 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'
+ 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
@@ -1618,7 +1626,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")
@@ -1627,11 +1635,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, 0, "else:")
- line(out, 1, "import %s", extname)
+ line(out, 1, "import jcc")
+ line(out, 0, "from . import %s", extname)
else:
- line(out, 0, 'import os, %s', extname)
+ line(out, 0, "import os")
+ line(out, 0, "from . import %s", extname)
line(out)
line(out, 0, '__dir__ = os.path.abspath(os.path.dirname(__file__))')
@@ -1711,7 +1719,7 @@ def compile(env, jccPath, output, module
if version:
line(out)
line(out, 0, 'VERSION = "%s"', version)
-
+
line(out, 0, 'CLASSPATH = [%s]' %(', '.join(['os.path.join(__dir__, "%s")' %(os.path.basename(jar)) for jar in jars])))
line(out, 0, 'CLASSPATH = os.pathsep.join(CLASSPATH)')
line(out, 0, '%s.CLASSPATH = CLASSPATH', extname)
@@ -1721,7 +1729,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 import *', extname)
if use_full_names:
line(out, 0, 'from java.io import PrintWriter, StringWriter')
out.close()
@@ -1821,7 +1829,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(_jcc3.__file__))
if sys.platform == 'darwin': # distutils no good with -R
machine = platform.machine()
if machine.startswith('iPod') or machine.startswith('iPhone'):
@@ -1829,11 +1837,11 @@ def compile(env, jccPath, output, module
else:
args['extra_link_args'] += ['-Wl,-rpath', shlibdir]
args['library_dirs'] = [shlibdir]
- args['libraries'] = ['jcc']
+ args['libraries'] = ['jcc3']
elif sys.platform == 'linux2': # distutils no good with -R
args['extra_link_args'] += ['-Wl,-rpath', shlibdir]
args['library_dirs'] = [shlibdir]
- args['libraries'] = ['jcc']
+ args['libraries'] = ['jcc3']
args['extra_link_args'] += [
getattr(import_, "_%s" %(import_.__name__)).__file__
for import_ in imports
@@ -1846,7 +1854,7 @@ def compile(env, jccPath, output, module
extlib = os.path.join('lib', "%s%s.lib" %(extname, _d))
package_data.append(extlib)
args['extra_link_args'] += [
- os.path.join(shlibdir, 'jcc', 'jcc%s.lib' %(_d)),
+ os.path.join(shlibdir, 'jcc3', 'jcc3%s.lib' %(_d)),
' '.join(IMPLIB_LFLAGS) %(os.path.join(modulePath, extlib))
]
args['libraries'] = [
@@ -1859,7 +1867,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
@@ -1891,6 +1899,6 @@ def compile(env, jccPath, output, module
if with_setuptools:
args['zip_safe'] = False
- print "setup args = %s" % args
+ print("setup args = %s" % args)
setup(**args)
Modified: lucene/pylucene/trunk/jcc/jcc3/sources/JArray.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/JArray.cpp?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/JArray.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/JArray.cpp Sun Mar 19 20:26:48 2017
@@ -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>
@@ -133,7 +133,7 @@ static PyObject *_format(U *self, PyObje
if (self->array.this$)
{
PyObject *list = toSequence<U>(self);
-
+
if (list)
{
PyObject *result = (*fn)(list);
@@ -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>
@@ -235,7 +235,7 @@ static PyObject *richcompare(U *self, Py
{
Py_DECREF(value);
return NULL;
- }
+ }
}
if (cmp)
@@ -358,7 +358,7 @@ static int seq_setslice(U *self, Py_ssiz
PyErr_SetString(PyExc_ValueError, "array size cannot change");
return -1;
}
-
+
if (lo < 0) lo = length + lo;
if (lo < 0) lo = 0;
else if (lo > length) lo = length;
@@ -399,13 +399,13 @@ static int seq_setslice(U *self, Py_ssiz
return -1;
}
-template<typename T>
+template<typename T>
static jclass initializeClass(bool getOnly)
{
return env->get_vm_env()->GetObjectClass(JArray<T>((Py_ssize_t) 0).this$);
}
-template<typename T>
+template<typename T>
static PyObject *cast_(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *arg, *clsObj;
@@ -442,12 +442,12 @@ static PyObject *cast_(PyTypeObject *typ
return JArray<T>(((t_JObject *) arg)->object.this$).wrap();
}
-template<typename T>
+template<typename T>
static PyObject *wrapfn_(const jobject &object) {
return JArray<T>(object).wrap();
}
-template<typename T>
+template<typename T>
static PyObject *instance_(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *arg, *clsObj;
@@ -475,7 +475,7 @@ static PyObject *instance_(PyTypeObject
Py_RETURN_TRUE;
}
-template<typename T>
+template<typename T>
static PyObject *assignable_(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
return instance_<T>(type, args, kwds);
@@ -507,8 +507,8 @@ public:
{
memset(&type_object, 0, sizeof(type_object));
- type_object.ob_refcnt = 1;
- type_object.ob_type = NULL;
+ Py_REFCNT(&type_object) = 1;
+ Py_TYPE(&type_object) = 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;
@@ -532,11 +532,11 @@ public:
make_descriptor(initializeClass<T>));
PyDict_SetItemString(type_object.tp_dict, "wrapfn_",
make_descriptor(wrapfn_<T>));
-
+
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);
}
@@ -582,20 +582,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;
+ Py_REFCNT(&type_object) = 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>;
@@ -629,12 +625,6 @@ template<> PyObject *toSequence(_t_jobje
return self->array.toSequence(self->wrapfn);
}
-template<> PyObject *toSequence(_t_jobjectarray<jobject> *self,
- Py_ssize_t lo, Py_ssize_t hi)
-{
- return self->array.toSequence(lo, hi, self->wrapfn);
-}
-
template<> int init< jobject,_t_jobjectarray<jobject> >(_t_jobjectarray<jobject> *self, PyObject *args, PyObject *kwds)
{
PyObject *obj, *clsObj = NULL;
@@ -659,7 +649,7 @@ template<> int init< jobject,_t_jobjecta
else
{
wrapfn = (PyObject *(*)(const jobject &))
- PyCObject_AsVoidPtr(cobj);
+ PyCapsule_GetPointer(cobj, "wrapfn");
Py_DECREF(cobj);
}
@@ -701,9 +691,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)
{
@@ -773,7 +763,8 @@ template<> PyObject *cast_<jobject>(PyTy
PyErr_Clear();
else
{
- wrapfn = (PyObject *(*)(const jobject &)) PyCObject_AsVoidPtr(cobj);
+ wrapfn = (PyObject *(*)(const jobject &))
+ PyCapsule_GetPointer(cobj, "wrapfn");
Py_DECREF(cobj);
}
@@ -809,7 +800,9 @@ template<> PyObject *wrapfn_<jobject>(co
PyErr_Clear();
else
{
- wrapfn = (PyObject *(*)(const jobject &)) PyCObject_AsVoidPtr(cobj);
+ wrapfn = (PyObject *(*)(const jobject &))
+ PyCapsule_GetPointer(cobj, "wrapfn");
+
Py_DECREF(cobj);
}
@@ -1105,7 +1098,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);
@@ -1126,7 +1119,7 @@ PyObject *JArray_Type(PyObject *self, Py
if (type_name != NULL)
{
- name = PyString_AsString(type_name);
+ name = PyUnicode_AsUTF8(type_name);
if (!name)
{
Py_DECREF(type_name);
@@ -1173,8 +1166,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/trunk/jcc/jcc3/sources/JArray.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/JArray.h?rev=1787656&r1=1759171&r2=1787656&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/JArray.h (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/JArray.h Sun Mar 19 20:26:48 2017
@@ -19,10 +19,6 @@
#include <Python.h>
#include "macros.h"
-#if PY_VERSION_HEX < 0x02050000
-typedef int Py_ssize_t;
-#endif
-
extern jobjectArray fromPySequence(jclass cls, PyObject *sequence);
extern jobjectArray fromPySequence(jclass cls, PyObject **args, int length);
extern PyObject *PyErr_SetJavaError();
@@ -161,7 +157,7 @@ template<> class JArray<jobject> : publi
PyList_SET_ITEM(list, i - lo, obj);
}
-
+
return list;
}
@@ -199,7 +195,7 @@ template<> class JArray<jobject> : publi
{
jobject jobj;
- if (PyString_Check(obj) || PyUnicode_Check(obj))
+ if (PyBytes_Check(obj) || PyUnicode_Check(obj))
jobj = env->fromPyString(obj);
else if (!PyObject_TypeCheck(obj, &PY_TYPE(JObject)))
{
@@ -301,7 +297,7 @@ template<> class JArray<jstring> : publi
PyList_SET_ITEM(list, i - lo, obj);
}
-
+
return list;
}
@@ -470,7 +466,7 @@ template<> class JArray<jboolean> : publ
Py_INCREF(obj);
PyList_SET_ITEM(list, i - lo, obj);
}
-
+
return list;
}
@@ -567,8 +563,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 (Py_ssize_t i = 0; i < length; i++) {
PyObject *obj = PySequence_GetItem(sequence, i);
@@ -576,14 +572,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
@@ -605,10 +601,10 @@ template<> class JArray<jbyte> : public
if (!obj)
break;
- if (PyString_Check(obj) && (PyString_GET_SIZE(obj) == 1))
- buf[i] = (jbyte) PyString_AS_STRING(obj)[0];
- else if (PyInt_CheckExact(obj))
- buf[i] = (jbyte) PyInt_AS_LONG(obj);
+ if (PyBytes_Check(obj) && (PyBytes_GET_SIZE(obj) == 1))
+ buf[i] = (jbyte) PyBytes_AS_STRING(obj)[0];
+ else if (PyLong_CheckExact(obj))
+ buf[i] = (jbyte) PyLong_AS_LONG(obj);
else
{
PyErr_SetObject(PyExc_TypeError, obj);
@@ -643,13 +639,24 @@ template<> class JArray<jbyte> : public
arrayElements elts = elements();
jbyte *buf = (jbyte *) elts;
PyObject *tuple = PyTuple_New(hi - lo);
-
+
for (Py_ssize_t 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)
@@ -658,7 +665,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(Py_ssize_t n)
@@ -671,7 +678,7 @@ template<> class JArray<jbyte> : public
if (n >= 0 && n < length)
{
jbyte b = (*this)[n];
- return PyInt_FromLong(b);
+ return PyLong_FromLong(b);
}
}
@@ -688,13 +695,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;
}
}
@@ -782,7 +789,7 @@ template<> class JArray<jchar> : public
if (!obj)
break;
- if (PyUnicode_Check(obj) && (PyUnicode_GET_SIZE(obj) == 1))
+ if (PyUnicode_Check(obj) && (PyUnicode_GET_LENGTH(obj) == 1))
{
buf[i] = (jchar) PyUnicode_AS_UNICODE(obj)[0];
Py_DECREF(obj);
@@ -806,7 +813,7 @@ template<> class JArray<jchar> : public
if (!obj)
break;
- if (PyUnicode_Check(obj) && (PyUnicode_GET_SIZE(obj) == 1))
+ if (PyUnicode_Check(obj) && (PyUnicode_GET_LENGTH(obj) == 1))
buf[i] = (jchar) PyUnicode_AS_UNICODE(obj)[0];
else
{
@@ -895,7 +902,7 @@ template<> class JArray<jchar> : public
PyErr_SetObject(PyExc_TypeError, obj);
return -1;
}
- if (PyUnicode_GET_SIZE(obj) != 1)
+ if (PyUnicode_GET_LENGTH(obj) != 1)
{
PyErr_SetObject(PyExc_ValueError, obj);
return -1;
@@ -1310,9 +1317,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
@@ -1334,8 +1341,8 @@ template<> class JArray<jint> : public j
if (!obj)
break;
- if (PyInt_Check(obj))
- buf[i] = (jint) PyInt_AS_LONG(obj);
+ if (PyLong_Check(obj))
+ buf[i] = (jint) PyLong_AS_LONG(obj);
else
{
PyErr_SetObject(PyExc_TypeError, obj);
@@ -1367,7 +1374,7 @@ template<> class JArray<jint> : public j
jint *buf = (jint *) elts;
for (Py_ssize_t 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;
}
@@ -1380,7 +1387,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");
@@ -1396,13 +1403,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;
}
}
@@ -1644,9 +1651,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
@@ -1668,8 +1675,8 @@ template<> class JArray<jshort> : public
if (!obj)
break;
- if (PyInt_Check(obj))
- buf[i] = (jshort) PyInt_AS_LONG(obj);
+ if (PyLong_Check(obj))
+ buf[i] = (jshort) PyLong_AS_LONG(obj);
else
{
PyErr_SetObject(PyExc_TypeError, obj);
@@ -1701,7 +1708,7 @@ template<> class JArray<jshort> : public
jshort *buf = (jshort *) elts;
for (Py_ssize_t 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;
}
@@ -1714,7 +1721,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");
@@ -1730,13 +1737,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;
}
}