You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by va...@apache.org on 2009/10/11 00:56:52 UTC

svn commit: r823974 - in /lucene/pylucene/trunk/jcc: CHANGES jcc/python.py jcc/sources/JCCEnv.cpp jcc/sources/JCCEnv.h jcc/sources/functions.cpp jcc/sources/jcc.cpp jcc/sources/jccfuncs.h

Author: vajda
Date: Sat Oct 10 22:56:51 2009
New Revision: 823974

URL: http://svn.apache.org/viewvc?rev=823974&view=rev
Log:
   - added env.jni_version for the JNI version as returned by GetVersion()
   - added env.java_version for java.lang.System.getProperty('java.version')
   - default value to initVM's classpath parameter now is importing module's

Modified:
    lucene/pylucene/trunk/jcc/CHANGES
    lucene/pylucene/trunk/jcc/jcc/python.py
    lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.cpp
    lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.h
    lucene/pylucene/trunk/jcc/jcc/sources/functions.cpp
    lucene/pylucene/trunk/jcc/jcc/sources/jcc.cpp
    lucene/pylucene/trunk/jcc/jcc/sources/jccfuncs.h

Modified: lucene/pylucene/trunk/jcc/CHANGES
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/CHANGES?rev=823974&r1=823973&r2=823974&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/CHANGES (original)
+++ lucene/pylucene/trunk/jcc/CHANGES Sat Oct 10 22:56:51 2009
@@ -1,4 +1,11 @@
 
+Version 2.4 ->
+------------------
+ - added env.jni_version for the JNI version as returned by JNI's GetVersion()
+ - added env.java_version for java.lang.System.getProperty('java.version')
+ - default value to initVM's classpath parameter now is importing module's
+ - 
+
 Version 2.3 -> 2.4
 ------------------
  - added 'typeof' to reserved word list

Modified: lucene/pylucene/trunk/jcc/jcc/python.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/python.py?rev=823974&r1=823973&r2=823974&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/python.py (original)
+++ lucene/pylucene/trunk/jcc/jcc/python.py Sat Oct 10 22:56:51 2009
@@ -1364,6 +1364,9 @@
         
     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)
+    line(out, 0, '%s._set_initVM_self(%s.initVM, %s)',
+         extname, extname, extname)
 
     line(out)
     line(out, 0, 'from %s import *', extname)

Modified: lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.cpp?rev=823974&r1=823973&r2=823974&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.cpp Sat Oct 10 22:56:51 2009
@@ -97,6 +97,9 @@
     _mids[mid_sys_setProperty] =
         vm_env->GetStaticMethodID(_sys, "setProperty",
                                   "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
+    _mids[mid_sys_getProperty] =
+        vm_env->GetStaticMethodID(_sys, "getProperty",
+                                  "(Ljava/lang/String;)Ljava/lang/String;");
     _mids[mid_obj_toString] =
         vm_env->GetMethodID(_obj, "toString",
                             "()Ljava/lang/String;");
@@ -128,6 +131,18 @@
 
 #endif
 
+jint JCCEnv::getJNIVersion()
+{
+    return get_vm_env()->GetVersion();
+}
+
+jstring JCCEnv::getJavaVersion()
+{
+    return (jstring)
+        callStaticObjectMethod(_sys, _mids[mid_sys_getProperty],
+                               get_vm_env()->NewStringUTF("java.version"));
+}
+
 jclass JCCEnv::findClass(const char *className)
 {
     jclass cls = NULL;

Modified: lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.h?rev=823974&r1=823973&r2=823974&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.h (original)
+++ lucene/pylucene/trunk/jcc/jcc/sources/JCCEnv.h Sat Oct 10 22:56:51 2009
@@ -82,6 +82,7 @@
     enum {
         mid_sys_identityHashCode,
         mid_sys_setProperty,
+        mid_sys_getProperty,
         mid_obj_toString,
         mid_obj_hashCode,
         mid_obj_getClass,
@@ -130,6 +131,9 @@
     virtual void set_vm(JavaVM *vm, JNIEnv *vm_env);
     virtual void set_vm_env(JNIEnv *vm_env);
 
+    virtual jint getJNIVersion();
+    virtual jstring getJavaVersion();
+
     virtual jclass findClass(const char *className);
     virtual void registerNatives(jclass cls, JNINativeMethod *methods, int n);
     virtual jobject newGlobalRef(jobject obj, int id);

Modified: lucene/pylucene/trunk/jcc/jcc/sources/functions.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/sources/functions.cpp?rev=823974&r1=823973&r2=823974&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/sources/functions.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc/sources/functions.cpp Sat Oct 10 22:56:51 2009
@@ -43,6 +43,28 @@
     Py_RETURN_NONE;
 }
 
+PyObject *_set_initVM_self(PyObject *self, PyObject *args)
+{
+    PyObject *initVM, *module;
+
+    if (!PyArg_ParseTuple(args, "OO", &initVM, &module))
+        return NULL;
+
+    if (!PyCFunction_Check(initVM))
+    {
+        PyErr_SetObject(PyExc_TypeError, initVM);
+        return NULL;
+    }
+
+    PyCFunctionObject *fn = (PyCFunctionObject *) initVM;
+
+    Py_INCREF(module);
+    Py_XDECREF(fn->m_self);
+    fn->m_self = module;
+
+    Py_RETURN_NONE;
+}
+
 PyObject *findClass(PyObject *self, PyObject *args)
 {
     char *className;

Modified: lucene/pylucene/trunk/jcc/jcc/sources/jcc.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/sources/jcc.cpp?rev=823974&r1=823973&r2=823974&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/sources/jcc.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc/sources/jcc.cpp Sat Oct 10 22:56:51 2009
@@ -45,6 +45,14 @@
 static PyObject *t_jccenv_strhash(PyObject *self, PyObject *arg);
 static PyObject *t_jccenv__dumpRefs(PyObject *self,
                                     PyObject *args, PyObject *kwds);
+static PyObject *t_jccenv__get_jni_version(PyObject *self, void *data);
+static PyObject *t_jccenv__get_java_version(PyObject *self, void *data);
+
+static PyGetSetDef t_jccenv_properties[] = {
+    { "jni_version", (getter) t_jccenv__get_jni_version, NULL, NULL, NULL },
+    { "java_version", (getter) t_jccenv__get_java_version, NULL, NULL, NULL },
+    { NULL, NULL, NULL, NULL, NULL }
+};
 
 static PyMemberDef t_jccenv_members[] = {
     { NULL, 0, 0, 0, NULL }
@@ -95,6 +103,7 @@
     0,                                   /* tp_iternext */
     t_jccenv_methods,                    /* tp_methods */
     t_jccenv_members,                    /* tp_members */
+    t_jccenv_properties,                 /* tp_getset */
     0,                                   /* tp_getset */
     0,                                   /* tp_base */
     0,                                   /* tp_dict */
@@ -145,7 +154,7 @@
         return NULL;
 
     JavaVMAttachArgs attach = {
-        JNI_VERSION_1_2, name, NULL
+        JNI_VERSION_1_4, name, NULL
     };
 
     if (asDaemon)
@@ -259,6 +268,16 @@
 }
 
 
+static PyObject *t_jccenv__get_jni_version(PyObject *self, void *data)
+{
+    return PyInt_FromLong(env->getJNIVersion());
+}
+
+static PyObject *t_jccenv__get_java_version(PyObject *self, void *data)
+{
+    return env->fromJString(env->getJavaVersion());
+}
+
 _DLL_EXPORT PyObject *getVMEnv(PyObject *self)
 {
     if (env->vm != NULL)
@@ -313,6 +332,8 @@
 
     if (env->vm)
     {
+        PyObject *module_cp = NULL;
+
         if (initialheap || maxheap || maxstack || vmargs)
         {
             PyErr_SetString(PyExc_ValueError,
@@ -320,9 +341,18 @@
             return NULL;
         }
 
+        if (classpath == NULL && self != NULL)
+        {
+            module_cp = PyObject_GetAttrString(self, "CLASSPATH");
+            if (module_cp != NULL)
+                classpath = PyString_AsString(module_cp);
+        }
+
         if (classpath && classpath[0])
             env->setClassPath(classpath);
 
+        Py_XDECREF(module_cp);
+
         return getVMEnv(self);
     }
     else
@@ -332,10 +362,18 @@
         JNIEnv *vm_env;
         JavaVM *vm;
         unsigned int nOptions = 0;
+        PyObject *module_cp = NULL;
 
         vm_args.version = JNI_VERSION_1_4;
         JNI_GetDefaultJavaVMInitArgs(&vm_args);
 
+        if (classpath == NULL && self != NULL)
+        {
+            module_cp = PyObject_GetAttrString(self, "CLASSPATH");
+            if (module_cp != NULL)
+                classpath = PyString_AsString(module_cp);
+        }
+
 #ifdef _jcc_lib
         PyObject *jcc = PyImport_ImportModule("jcc");
         PyObject *cp = PyObject_GetAttrString(jcc, "CLASSPATH");
@@ -354,6 +392,9 @@
             add_option("-Djava.class.path=", classpath,
                        &vm_options[nOptions++]);
 #endif
+
+        Py_XDECREF(module_cp);
+
         if (initialheap)
             add_option("-Xms", initialheap, &vm_options[nOptions++]);
         if (maxheap)

Modified: lucene/pylucene/trunk/jcc/jcc/sources/jccfuncs.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/sources/jccfuncs.h?rev=823974&r1=823973&r2=823974&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/sources/jccfuncs.h (original)
+++ lucene/pylucene/trunk/jcc/jcc/sources/jccfuncs.h Sat Oct 10 22:56:51 2009
@@ -21,6 +21,7 @@
 PyObject *initVM(PyObject *self, PyObject *args, PyObject *kwds);
 PyObject *getVMEnv(PyObject *self);
 PyObject *_setExceptionTypes(PyObject *self, PyObject *args);
+PyObject *_set_initVM_self(PyObject *self, PyObject *args);
 PyObject *findClass(PyObject *self, PyObject *args);
 PyObject *JArray_Type(PyObject *self, PyObject *arg);
 
@@ -33,6 +34,8 @@
       METH_VARARGS, NULL },
     { "_setExceptionTypes", (PyCFunction) _setExceptionTypes,
       METH_VARARGS, NULL },
+    { "_set_initVM_self", (PyCFunction) _set_initVM_self,
+      METH_VARARGS, NULL },
     { "JArray", (PyCFunction) JArray_Type,
       METH_O, NULL },
     { NULL, NULL, 0, NULL }