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/10/18 23:38:33 UTC

svn commit: r1812596 - in /lucene/pylucene/trunk/jcc: CHANGES jcc3/sources/JArray.cpp jcc3/sources/jcc.cpp jcc3/sources/macros.h setup.py

Author: vajda
Date: Wed Oct 18 23:38:33 2017
New Revision: 1812596

URL: http://svn.apache.org/viewvc?rev=1812596&view=rev
Log:
 - fixed bug PYLUCENE-39  (slicing JArray in Python 3)

Modified:
    lucene/pylucene/trunk/jcc/CHANGES
    lucene/pylucene/trunk/jcc/jcc3/sources/JArray.cpp
    lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp
    lucene/pylucene/trunk/jcc/jcc3/sources/macros.h
    lucene/pylucene/trunk/jcc/setup.py

Modified: lucene/pylucene/trunk/jcc/CHANGES
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/CHANGES?rev=1812596&r1=1812595&r2=1812596&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/CHANGES (original)
+++ lucene/pylucene/trunk/jcc/CHANGES Wed Oct 18 23:38:33 2017
@@ -5,6 +5,7 @@ Version 3.0 ->
  - added 'm' suffix to linux -lpython statement for shared jcc lib
  - fixed bug with using split instead of rpartition on path (Petrus Hyvönen)
  - fixed bug PYLUCENE-38 (Aric Coady)
+ - fixed bug PYLUCENE-39
  - 
 
 Version 2.23 -> 3.0

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/JArray.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/JArray.cpp?rev=1812596&r1=1812595&r2=1812596&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/JArray.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/JArray.cpp Wed Oct 18 23:38:33 2017
@@ -337,15 +337,15 @@ static PyObject *seq_repeat(U *self, Py_
 }
 
 template<typename U>
-static PyObject *seq_getslice(U *self, Py_ssize_t lo, Py_ssize_t hi)
+static int seq_set(U *self, Py_ssize_t n, PyObject *value)
 {
-    return toSequence<U>(self, lo, hi);
+    return self->array.set(n, value);
 }
 
 template<typename U>
-static int seq_set(U *self, Py_ssize_t n, PyObject *value)
+static PyObject *seq_getslice(U *self, Py_ssize_t lo, Py_ssize_t hi)
 {
-    return self->array.set(n, value);
+    return toSequence<U>(self, lo, hi);
 }
 
 template<typename U>
@@ -399,6 +399,76 @@ static int seq_setslice(U *self, Py_ssiz
     return -1;
 }
 
+
+template<typename U>
+static PyObject *map_subscript(U *self, PyObject *key)
+{
+  if (PySlice_Check(key))
+  {
+      Py_ssize_t from, to, step, slicelength;
+
+      if (PySlice_GetIndicesEx(key, seq_length(self), &from, &to, &step,
+                               &slicelength) < 0)
+          return NULL;
+
+      if (step != 1)
+      {
+          PyErr_SetString(PyExc_ValueError, "slice step must be 1");
+          return NULL;
+      }
+
+      return seq_getslice<U>(self, from, to);
+  }
+
+  if (PyIndex_Check(key))
+  {
+      Py_ssize_t at = PyNumber_AsSsize_t(key, PyExc_IndexError);
+
+      if (at == -1 && PyErr_Occurred())
+          return NULL;
+
+      return seq_get<U>(self, at);
+  }
+
+  PyErr_SetObject(PyExc_TypeError, key);
+  return NULL;
+}
+
+template<typename U>
+static int map_ass_subscript(U *self, PyObject *key, PyObject *value)
+{
+  if (PySlice_Check(key))
+  {
+      Py_ssize_t from, to, step, slicelength;
+
+      if (PySlice_GetIndicesEx(key, seq_length(self), &from, &to, &step,
+                               &slicelength) < 0)
+          return -1;
+
+      if (step != 1)
+      {
+          PyErr_SetString(PyExc_ValueError, "slice step must be 1");
+          return -1;
+      }
+
+      return seq_setslice<U>(self, from, to, value);
+  }
+
+  if (PyIndex_Check(key))
+  {
+      Py_ssize_t at = PyNumber_AsSsize_t(key, PyExc_IndexError);
+
+      if (at == -1 && PyErr_Occurred())
+          return -1;
+
+      return seq_set<U>(self, at, value);
+  }
+
+  PyErr_SetObject(PyExc_TypeError, key);
+  return -1;
+}
+
+
 template<typename T>
 static jclass initializeClass(bool getOnly)
 {
@@ -484,6 +554,7 @@ static PyObject *assignable_(PyTypeObjec
 template< typename T, typename U = _t_JArray<T> > class jarray_type {
 public:
     PySequenceMethods seq_methods;
+    PyMappingMethods map_methods;
     PyTypeObject type_object;
 
     class iterator_type {
@@ -553,6 +624,7 @@ public:
     jarray_type()
     {
         memset(&seq_methods, 0, sizeof(seq_methods));
+        memset(&map_methods, 0, sizeof(map_methods));
         memset(&type_object, 0, sizeof(type_object));
 
         static PyMethodDef methods[] = {
@@ -591,11 +663,20 @@ public:
         seq_methods.sq_inplace_concat = NULL;
         seq_methods.sq_inplace_repeat = NULL;
 
+        map_methods.mp_length =
+            (lenfunc) (Py_ssize_t (*)(U *)) seq_length<U>;
+        map_methods.mp_subscript =
+            (binaryfunc) (PyObject *(*)(U *, PyObject *)) map_subscript<U>;
+        map_methods.mp_ass_subscript =
+            (objobjargproc) (int (*)(U *, PyObject *,
+                                     PyObject *)) map_ass_subscript<U>;
+
         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>;
         type_object.tp_as_sequence = &seq_methods;
+        type_object.tp_as_mapping = &map_methods;
         type_object.tp_str = (reprfunc) (PyObject *(*)(U *)) str<U>;
         type_object.tp_flags = Py_TPFLAGS_DEFAULT;
         type_object.tp_doc = "JArray<T> wrapper type";
@@ -624,6 +705,11 @@ 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)
 {

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp?rev=1812596&r1=1812595&r2=1812596&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/jcc.cpp Wed Oct 18 23:38:33 2017
@@ -211,7 +211,7 @@ static PyObject *t_jccenv_strhash(PyObje
     uintmax_t hash = (uintmax_t) PyObject_Hash(arg);
     char buffer[hexdig + 1];
 
-    sprintf(buffer, "%0*"PRIxMAX, (int) hexdig, hash);
+    sprintf(buffer, "%0*" PRIxMAX, (int) hexdig, hash);
     return PyUnicode_FromStringAndSize(buffer, hexdig);
 }
 #endif

Modified: lucene/pylucene/trunk/jcc/jcc3/sources/macros.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc3/sources/macros.h?rev=1812596&r1=1812595&r2=1812596&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc3/sources/macros.h (original)
+++ lucene/pylucene/trunk/jcc/jcc3/sources/macros.h Wed Oct 18 23:38:33 2017
@@ -91,8 +91,8 @@ PyObject *t_name::wrap_Object(const java
 {                                                                       \
     if (!!object)                                                       \
     {                                                                   \
-        t_name *self =                                                  \
-            (t_name *) PY_TYPE(name)->tp_alloc(PY_TYPE(name), 0);       \
+        t_name *self = (t_name *)                                       \
+            PyType_GenericAlloc(PY_TYPE(name), 0);                      \
         if (self)                                                       \
             self->object = object;                                      \
         return (PyObject *) self;                                       \
@@ -110,7 +110,7 @@ PyObject *t_name::wrap_jobject(const job
             return NULL;                                                \
         }                                                               \
         t_name *self = (t_name *)                                       \
-            PY_TYPE(name)->tp_alloc(PY_TYPE(name), 0);                  \
+            PyType_GenericAlloc(PY_TYPE(name), 0);                      \
         if (self)                                                       \
             self->object = javaClass(object);                           \
         return (PyObject *) self;                                       \

Modified: lucene/pylucene/trunk/jcc/setup.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/setup.py?rev=1812596&r1=1812595&r2=1812596&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/setup.py (original)
+++ lucene/pylucene/trunk/jcc/setup.py Wed Oct 18 23:38:33 2017
@@ -116,7 +116,7 @@ INCLUDES = {
 
 CFLAGS = {
     'darwin': ['-fno-strict-aliasing', '-Wno-write-strings',
-               '-mmacosx-version-min=10.5'],
+               '-mmacosx-version-min=10.9', '-std=c++11', '-stdlib=libc++'],
     'ipod': ['-Wno-write-strings'],
     'linux': ['-fno-strict-aliasing', '-Wno-write-strings'],
     'sunos5': ['-features=iddollar',
@@ -138,12 +138,12 @@ DEBUG_CFLAGS = {
 }
 
 LFLAGS = {
-    'darwin/frameworks': ['-framework', 'JavaVM', '-mmacosx-version-min=10.5'],
+    'darwin/frameworks': ['-framework', 'JavaVM', '-mmacosx-version-min=10.9'],
     'darwin/home': ['-L%(darwin)s/jre/lib' %(JDK), '-ljava',
                     '-L%(darwin)s/jre/lib/server' %(JDK), '-ljvm',
                     '-Wl,-rpath', '-Wl,%(darwin)s/jre/lib' %(JDK),
                     '-Wl,-rpath', '-Wl,%(darwin)s/jre/lib/server' %(JDK),
-                    '-mmacosx-version-min=10.5'],
+                    '-mmacosx-version-min=10.9'],
     'ipod': ['-ljvm', '-lpython%s.%s' %(sys.version_info[0:2]),
              '-L/usr/lib/gcc/arm-apple-darwin9/4.0.1'],
     'linux/i386': ['-L%(linux)s/jre/lib/i386' %(JDK), '-ljava',