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/05/17 03:51:33 UTC

svn commit: r944952 - in /lucene/pylucene/branches/branch_3x/jcc: _jcc/java/util/Iterator.cpp _jcc/java/util/Iterator.h jcc/python.py jcc/sources/JCCEnv.cpp jcc/sources/JCCEnv.h jcc/sources/functions.h

Author: vajda
Date: Mon May 17 01:51:32 2010
New Revision: 944952

URL: http://svn.apache.org/viewvc?rev=944952&view=rev
Log:
fixed bug with get_iterator methods

Modified:
    lucene/pylucene/branches/branch_3x/jcc/_jcc/java/util/Iterator.cpp
    lucene/pylucene/branches/branch_3x/jcc/_jcc/java/util/Iterator.h
    lucene/pylucene/branches/branch_3x/jcc/jcc/python.py
    lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.cpp
    lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.h
    lucene/pylucene/branches/branch_3x/jcc/jcc/sources/functions.h

Modified: lucene/pylucene/branches/branch_3x/jcc/_jcc/java/util/Iterator.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/_jcc/java/util/Iterator.cpp?rev=944952&r1=944951&r2=944952&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/_jcc/java/util/Iterator.cpp (original)
+++ lucene/pylucene/branches/branch_3x/jcc/_jcc/java/util/Iterator.cpp Mon May 17 01:51:32 2010
@@ -92,6 +92,18 @@ namespace java {
             }
             return obj;
         }
+
+        PyObject *t_Iterator::wrap_jobject(const jobject& object,
+                                           PyTypeObject *T)
+        {
+            PyObject *obj = t_Iterator::wrap_jobject(object);
+            if (obj != Py_None)
+            {
+                t_Iterator *self = (t_Iterator *) obj;
+                self->parameters[0] = T;
+            }
+            return obj;
+        }
 #endif
         static PyObject *t_Iterator_hasNext(t_Iterator *self)
         {

Modified: lucene/pylucene/branches/branch_3x/jcc/_jcc/java/util/Iterator.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/_jcc/java/util/Iterator.h?rev=944952&r1=944951&r2=944952&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/_jcc/java/util/Iterator.h (original)
+++ lucene/pylucene/branches/branch_3x/jcc/_jcc/java/util/Iterator.h Mon May 17 01:51:32 2010
@@ -54,11 +54,13 @@ namespace java {
             }
 #endif
             static PyObject *wrap_Object(const Iterator& object);
+            static PyObject *wrap_jobject(const jobject& object);
 #ifdef _java_generics
             static PyObject *wrap_Object(const Iterator& object,
                                          PyTypeObject *T);
+            static PyObject *wrap_jobject(const jobject& object,
+                                          PyTypeObject *T);
 #endif
-            static PyObject *wrap_jobject(const jobject& object);
         };
     }
 }

Modified: lucene/pylucene/branches/branch_3x/jcc/jcc/python.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/jcc/python.py?rev=944952&r1=944951&r2=944952&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/jcc/python.py (original)
+++ lucene/pylucene/branches/branch_3x/jcc/jcc/python.py Mon May 17 01:51:32 2010
@@ -573,11 +573,12 @@ def python(env, out_h, out, cls, superCl
 
     line(out_h, indent + 1, 'static PyObject *wrap_Object(const %s&);',
          cppname(names[-1]))
+    line(out_h, indent + 1, 'static PyObject *wrap_jobject(const jobject&);')
     if clsParams:
+        _clsParams = ', '.join(['PyTypeObject *'] * len(clsParams))
         line(out_h, indent + 1, 'static PyObject *wrap_Object(const %s&, %s);',
-             cppname(names[-1]),
-             ', '.join(['PyTypeObject *'] * len(clsParams)))
-    line(out_h, indent + 1, 'static PyObject *wrap_jobject(const jobject&);')
+             cppname(names[-1]), _clsParams)
+        line(out_h, indent + 1, 'static PyObject *wrap_jobject(const jobject&, %s);', _clsParams)
     line(out_h, indent + 1, 'static void install(PyObject *module);')
     line(out_h, indent + 1, 'static void initialize(PyObject *module);')
     line(out_h, indent, '};')
@@ -993,7 +994,27 @@ def python(env, out_h, out, cls, superCl
         line(out, indent, "{")
         line(out, indent + 1, "PyObject *obj = t_%s::wrap_Object(object);",
              names[-1])
-        line(out, indent + 1, "if (obj != Py_None)")
+        line(out, indent + 1, "if (obj != NULL && obj != Py_None)")
+        line(out, indent + 1, "{")
+        line(out, indent + 2, "t_%s *self = (t_%s *) obj;",
+             names[-1], names[-1])
+        i = 0;
+        for clsParam in clsParams:
+            line(out, indent + 2, "self->parameters[%d] = %s;",
+                 i, clsParam.getName())
+            i += 1
+        line(out, indent + 1, "}")
+        line(out, indent + 1, "return obj;");
+        line(out, indent, "}")
+
+        line(out)
+        line(out, indent, 
+             "PyObject *t_%s::wrap_jobject(const jobject& object, %s)",
+             cppname(names[-1]), ', '.join(clsArgs))
+        line(out, indent, "{")
+        line(out, indent + 1, "PyObject *obj = t_%s::wrap_jobject(object);",
+             names[-1])
+        line(out, indent + 1, "if (obj != NULL && obj != Py_None)")
         line(out, indent + 1, "{")
         line(out, indent + 2, "t_%s *self = (t_%s *) obj;",
              names[-1], names[-1])
@@ -1001,6 +1022,7 @@ def python(env, out_h, out, cls, superCl
         for clsParam in clsParams:
             line(out, indent + 2, "self->parameters[%d] = %s;",
                  i, clsParam.getName())
+            i += 1
         line(out, indent + 1, "}")
         line(out, indent + 1, "return obj;");
         line(out, indent, "}")

Modified: lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.cpp?rev=944952&r1=944951&r2=944952&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.cpp (original)
+++ lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.cpp Mon May 17 01:51:32 2010
@@ -111,6 +111,9 @@ void JCCEnv::set_vm(JavaVM *vm, JNIEnv *
         vm_env->GetMethodID(_obj, "getClass",
                             "()Ljava/lang/Class;");
 
+    _mids[mid_iterator] =
+        vm_env->GetMethodID(vm_env->FindClass("java/lang/Iterable"),
+                            "iterator", "()Ljava/util/Iterator;");
     _mids[mid_iterator_next] =
         vm_env->GetMethodID(vm_env->FindClass("java/util/Iterator"),
                             "next", "()Ljava/lang/Object;");
@@ -176,6 +179,11 @@ jstring JCCEnv::getJavaVersion() const
                                get_vm_env()->NewStringUTF("java.version"));
 }
 
+jobject JCCEnv::iterator(jobject obj) const
+{
+    return callObjectMethod(obj, _mids[mid_iterator]);
+}
+
 jobject JCCEnv::iteratorNext(jobject obj) const
 {
     return callObjectMethod(obj, _mids[mid_iterator_next]);

Modified: lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.h?rev=944952&r1=944951&r2=944952&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.h (original)
+++ lucene/pylucene/branches/branch_3x/jcc/jcc/sources/JCCEnv.h Mon May 17 01:51:32 2010
@@ -87,6 +87,7 @@ protected:
         mid_obj_toString,
         mid_obj_hashCode,
         mid_obj_getClass,
+        mid_iterator,
         mid_iterator_next,
         mid_enumeration_nextElement,
         mid_Boolean_booleanValue,
@@ -152,6 +153,7 @@ public:
     virtual void registerNatives(jclass cls, JNINativeMethod *methods,
                                  int n) const;
 
+    virtual jobject iterator(jobject obj) const;
     virtual jobject iteratorNext(jobject obj) const;
     virtual jobject enumerationNext(jobject obj) const;
 

Modified: lucene/pylucene/branches/branch_3x/jcc/jcc/sources/functions.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/jcc/sources/functions.h?rev=944952&r1=944951&r2=944952&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/jcc/sources/functions.h (original)
+++ lucene/pylucene/branches/branch_3x/jcc/jcc/sources/functions.h Mon May 17 01:51:32 2010
@@ -122,20 +122,20 @@ PyObject *callSuper(PyTypeObject *type, 
 
 template<class T> PyObject *get_iterator(T *self)
 {
-    java::util::Iterator iterator((jobject) NULL);
+    jobject iterator;
 
-    OBJ_CALL(iterator = self->object.iterator());
-    return java::util::t_Iterator::wrap_Object(iterator);
+    OBJ_CALL(iterator = env->iterator(self->object.this$));
+    return java::util::t_Iterator::wrap_jobject(iterator);
 }
 
 #ifdef _java_generics
 template<class T> PyObject *get_generic_iterator(T *self)
 {
-    java::util::Iterator iterator((jobject) NULL);
     PyTypeObject *param = self->parameters ? self->parameters[0] : NULL;
+    jobject iterator;
 
-    OBJ_CALL(iterator = self->object.iterator());
-    return java::util::t_Iterator::wrap_Object(iterator, param);
+    OBJ_CALL(iterator = env->iterator(self->object.this$));
+    return java::util::t_Iterator::wrap_jobject(iterator, param);
 }
 #endif