lucene-pylucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From va...@apache.org
Subject svn commit: r931300 - in /lucene/pylucene/trunk/jcc: CHANGES jcc/python.py jcc/sources/functions.cpp jcc/sources/functions.h
Date Tue, 06 Apr 2010 20:07:33 GMT
Author: vajda
Date: Tue Apr  6 20:07:33 2010
New Revision: 931300

URL: http://svn.apache.org/viewvc?rev=931300&view=rev
Log:
 - added support for auto-boxing CharSequence from python strings

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

Modified: lucene/pylucene/trunk/jcc/CHANGES
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/CHANGES?rev=931300&r1=931299&r2=931300&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/CHANGES (original)
+++ lucene/pylucene/trunk/jcc/CHANGES Tue Apr  6 20:07:33 2010
@@ -12,6 +12,7 @@ Version 2.5 ->
  - fixed bug with not heeding type parameter for --sequence get method
  - parameterized return values are now unboxed
  - improved auto-boxing of primitive type parameters
+ - added support for auto-boxing CharSequence from python strings
  - 
 
 Version 2.4 -> 2.5

Modified: lucene/pylucene/trunk/jcc/jcc/python.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/python.py?rev=931300&r1=931299&r2=931300&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/python.py (original)
+++ lucene/pylucene/trunk/jcc/jcc/python.py Tue Apr  6 20:07:33 2010
@@ -52,15 +52,23 @@ CALLARGS = { 'boolean': ('O', '(%s ? Py_
              'short': ('i', '(int) %s', False),
              'java.lang.String': ('O', 'env->fromJString((jstring) %s, 0)', True) }
 
-BOXED = set(('java.lang.Boolean',
-             'java.lang.Byte',
-             'java.lang.Character',
-             'java.lang.Double',
-             'java.lang.Float',
-             'java.lang.Integer',
-             'java.lang.Long',
-             'java.lang.Short',
-             'java.lang.String'))
+BOXED = { 'java.lang.Boolean': (True, True),
+          'java.lang.Byte': (True, True),
+          'java.lang.Character': (True, True),
+          'java.lang.CharSequence': (True, False),
+          'java.lang.Double': (True, True),
+          'java.lang.Float': (True, True),
+          'java.lang.Integer': (True, True),
+          'java.lang.Long': (True, True),
+          'java.lang.Short': (True, True),
+          'java.lang.String': (True, True) }
+
+
+def is_boxed(clsName):
+    return BOXED.get(clsName, (False, False))[0]
+
+def is_unboxed(clsName):
+    return BOXED.get(clsName, (False, False))[1]
 
 
 def getTypeParameters(cls):
@@ -107,7 +115,7 @@ def parseArgs(params, current, generics,
             return array + 's'
         if clsName == 'java.lang.Object':
             return array + 'o'
-        if clsName in BOXED:
+        if is_boxed(clsName):
             return array + 'O'
         if generics and getTypeParameters(cls):
             return array + 'K'
@@ -130,7 +138,7 @@ def parseArgs(params, current, generics,
         if (cls.isPrimitive() or
             clsName in ('java.lang.String', 'java.lang.Object')):
             return ''
-        if clsName in BOXED:
+        if is_boxed(clsName):
             clsNames = clsName.split('.')
             return ', &%s::%s$$Type' %('::'.join(cppnames(clsNames[:-1])), cppname(clsNames[-1]))
         return ', %s::initializeClass' %(typename(cls, current, False))
@@ -1015,7 +1023,7 @@ def python(env, out_h, out, cls, superCl
     line(out, indent + 1, 'PyDict_SetItemString(%s$$Type.tp_dict, "class_", make_descriptor(%s::initializeClass,
%s));',
          names[-1], cppname(names[-1]), generics and 1 or 0)
 
-    if cls.getName() in BOXED:
+    if is_unboxed(cls.getName()):
         wrapfn_ = "unbox%s" %(names[-1])
         boxfn_ = "box%s" %(names[-1])
     else:

Modified: lucene/pylucene/trunk/jcc/jcc/sources/functions.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/sources/functions.cpp?rev=931300&r1=931299&r2=931300&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/sources/functions.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc/sources/functions.cpp Tue Apr  6 20:07:33 2010
@@ -1610,6 +1610,28 @@ int boxCharacter(PyTypeObject *type, PyO
     return 0;
 }
 
+int boxCharSequence(PyTypeObject *type, PyObject *arg, java::lang::Object *obj)
+{
+    int result = boxJObject(type, arg, obj);
+
+    if (result <= 0)
+        return result;
+
+    if (PyString_Check(arg) || PyUnicode_Check(arg))
+    {
+        if (obj != NULL)
+        {
+            *obj = p2j(arg);
+            if (PyErr_Occurred())
+                return -1;
+        }
+    }
+    else
+        return -1;
+    
+    return 0;
+}
+
 int boxDouble(PyTypeObject *type, PyObject *arg, java::lang::Object *obj)
 {
     int result = boxJObject(type, arg, obj);

Modified: lucene/pylucene/trunk/jcc/jcc/sources/functions.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/sources/functions.h?rev=931300&r1=931299&r2=931300&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/sources/functions.h (original)
+++ lucene/pylucene/trunk/jcc/jcc/sources/functions.h Tue Apr  6 20:07:33 2010
@@ -85,6 +85,7 @@ PyObject *unboxString(const jobject& obj
 int boxBoolean(PyTypeObject *type, PyObject *arg, java::lang::Object *obj);
 int boxByte(PyTypeObject *type, PyObject *arg, java::lang::Object *obj);
 int boxCharacter(PyTypeObject *type, PyObject *arg, java::lang::Object *obj);
+int boxCharSequence(PyTypeObject *type, PyObject *arg, java::lang::Object *obj);
 int boxDouble(PyTypeObject *type, PyObject *arg, java::lang::Object *obj);
 int boxFloat(PyTypeObject *type, PyObject *arg, java::lang::Object *obj);
 int boxInteger(PyTypeObject *type, PyObject *arg, java::lang::Object *obj);



Mime
View raw message