On Mon, 9 Jan 2006, tsuraan wrote:

It also looks like p2j suffers from the same stack allocation flaw you
reported yesterday. I should be fixing this shortly.

I finally ran into this today, and I'm wondering what sort of fix
you're doing.  Initializing JvNewString on NULL doesn't work, nor does
doing heap allocation of jstring (causes internal compiler error for
me, anyhow).  I'm currently doing a malloc to get data for the jchar
array and initializing the JvNewString off that.  I don't know how bad
an idea that is, but I can't imagine it's very good.  Doing an svn
update off the PyLucene tree didn't show any interesting changes, so I
guess I'm waiting on a good fix for that whenever you get the time.

This bug is fixed in the patch included below.

Thank you for your patience.

Andi..

Index: PyLucene.i
===================================================================
--- PyLucene.i  (revision 225)
+++ PyLucene.i  (working copy)
@@ -490,12 +490,13 @@
         {
             int len = PyUnicode_GET_SIZE(object);
             Py_UNICODE *pchars = PyUnicode_AS_UNICODE(object);
-            jchar jchars[len];
+            jstring str = JvAllocString(len);
+            jchar *jchars = JvGetStringChars(str);

             for (int i = 0; i < len; i++)
                 jchars[i] = pchars[i];

-            return JvNewString((const jchar *) jchars, len);
+            return str;
         }
     }
     else
@@ -504,12 +505,8 @@
         jstring js = JvNewStringUTF(ps);

         if (!js)
-        {
-            char msg[strlen(ps) + 64];
- - sprintf(msg, "python str is not unicode or utf-8 encoded: %s", ps);
-            PyErr_SetString(PyExc_ValueError, msg);
-        }
+            PyErr_Format(PyExc_ValueError,
+                         "python str is not unicode or utf-8 encoded: %s", ps);

         return js;
     }
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev

Reply via email to