Return-Path: Delivered-To: apmail-lucene-pylucene-commits-archive@minotaur.apache.org Received: (qmail 86499 invoked from network); 13 Jul 2010 10:43:45 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 Jul 2010 10:43:45 -0000 Received: (qmail 90263 invoked by uid 500); 13 Jul 2010 10:43:45 -0000 Delivered-To: apmail-lucene-pylucene-commits-archive@lucene.apache.org Received: (qmail 90244 invoked by uid 500); 13 Jul 2010 10:43:44 -0000 Mailing-List: contact pylucene-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: pylucene-dev@lucene.apache.org Delivered-To: mailing list pylucene-commits@lucene.apache.org Received: (qmail 90236 invoked by uid 99); 13 Jul 2010 10:43:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Jul 2010 10:43:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Jul 2010 10:43:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 607A22388900; Tue, 13 Jul 2010 10:42:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r963670 - in /lucene/pylucene/branches/python_3/jcc/jcc/sources: JArray.cpp functions.cpp functions.h jcc.cpp Date: Tue, 13 Jul 2010 10:42:16 -0000 To: pylucene-commits@lucene.apache.org From: vajda@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100713104216.607A22388900@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: vajda Date: Tue Jul 13 10:42:15 2010 New Revision: 963670 URL: http://svn.apache.org/viewvc?rev=963670&view=rev Log: - reworked flawed PyUnicode_AsString to use a buffer Modified: lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.cpp lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.cpp lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.h lucene/pylucene/branches/python_3/jcc/jcc/sources/jcc.cpp Modified: lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.cpp URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.cpp?rev=963670&r1=963669&r2=963670&view=diff ============================================================================== --- lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.cpp (original) +++ lucene/pylucene/branches/python_3/jcc/jcc/sources/JArray.cpp Tue Jul 13 10:42:15 2010 @@ -1070,6 +1070,7 @@ PyObject *JArray_Type(PyObject *self, Py { PyObject *type_name = NULL, *type; char const *name = NULL; + char buffer[16]; if (PyType_Check(arg)) { @@ -1098,7 +1099,7 @@ PyObject *JArray_Type(PyObject *self, Py if (type_name != NULL) { - name = PyUnicode_AsString(type_name); + name = PyUnicode_AsString(type_name, buffer, sizeof(buffer)); Py_DECREF(type_name); if (!name) return NULL; Modified: lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.cpp URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.cpp?rev=963670&r1=963669&r2=963670&view=diff ============================================================================== --- lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.cpp (original) +++ lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.cpp Tue Jul 13 10:42:15 2010 @@ -980,6 +980,32 @@ PyObject *j2p(const String& js) return env->fromJString((jstring) js.this$, 0); } +char *PyUnicode_AsString(PyObject *obj, char *buffer, Py_ssize_t size) +{ + PyObject *bytes = PyUnicode_AsUTF8String(obj); + + if (bytes == NULL) + return NULL; + + const char *str = PyBytes_AS_STRING(bytes); + Py_ssize_t len = PyBytes_GET_SIZE(bytes); + + if (len < size) + { + memcpy(buffer, str, len); + buffer[len] = '\0'; + } + else if (size > 0) + { + memcpy(buffer, str, size - 1); + buffer[size] = '\0'; + } + + Py_XDECREF(bytes); + + return buffer; +} + PyObject *PyErr_SetArgsError(char *name, PyObject *args) { if (!PyErr_Occurred()) @@ -1083,9 +1109,11 @@ void throwPythonError(void) if (exc) { PyObject *name = PyObject_GetAttrString(exc, "__name__"); + char buffer[128]; env->get_vm_env()->ThrowNew(env->getPythonExceptionClass(), - PyUnicode_AsString(name)); + PyUnicode_AsString(name, buffer, + sizeof(buffer))); Py_DECREF(name); } else Modified: lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.h URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.h?rev=963670&r1=963669&r2=963670&view=diff ============================================================================== --- lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.h (original) +++ lucene/pylucene/branches/python_3/jcc/jcc/sources/functions.h Tue Jul 13 10:42:15 2010 @@ -33,7 +33,7 @@ typedef intintobjargproc ssizessizeobjar typedef PyTypeObject **(*getparametersfn)(void *); typedef int (*boxfn)(PyTypeObject *, PyObject *, java::lang::Object *); -const char *PyUnicode_AsString(PyObject *obj); +char *PyUnicode_AsString(PyObject *obj, char *buffer, Py_ssize_t size); PyObject *PyErr_SetArgsError(char *name, PyObject *args); PyObject *PyErr_SetArgsError(PyObject *self, char *name, PyObject *args); Modified: lucene/pylucene/branches/python_3/jcc/jcc/sources/jcc.cpp URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/python_3/jcc/jcc/sources/jcc.cpp?rev=963670&r1=963669&r2=963670&view=diff ============================================================================== --- lucene/pylucene/branches/python_3/jcc/jcc/sources/jcc.cpp (original) +++ lucene/pylucene/branches/python_3/jcc/jcc/sources/jcc.cpp Tue Jul 13 10:42:15 2010 @@ -335,16 +335,6 @@ _DLL_EXPORT PyObject *getVMEnv(PyObject static void registerNatives(JNIEnv *vm_env); #endif -_DLL_EXPORT const char *PyUnicode_AsString(PyObject *obj) -{ - PyObject *bytes = PyUnicode_AsUTF8String(obj); - const char *str = PyBytes_AsString(bytes); - - Py_XDECREF(bytes); - - return str; -} - _DLL_EXPORT PyObject *initJCC(PyObject *module) { static int _once_only = 1; @@ -390,6 +380,7 @@ _DLL_EXPORT PyObject *initVM(PyObject *s if (env->vm) { PyObject *module_cp = NULL; + PyObject *bytes = NULL; if (initialheap || maxheap || maxstack || vmargs) { @@ -402,12 +393,22 @@ _DLL_EXPORT PyObject *initVM(PyObject *s { module_cp = PyObject_GetAttrString(self, "CLASSPATH"); if (module_cp != NULL) - classpath = PyUnicode_AsString(module_cp); + { + bytes = PyUnicode_AsUTF8String(module_cp); + if (!bytes) + { + Py_DECREF(module_cp); + return NULL; + } + + classpath = PyBytes_AS_STRING(bytes); + } } if (classpath && classpath[0]) env->setClassPath(classpath); + Py_XDECREF(bytes); Py_XDECREF(module_cp); return getVMEnv(self); @@ -420,6 +421,7 @@ _DLL_EXPORT PyObject *initVM(PyObject *s JavaVM *vm; unsigned int nOptions = 0; PyObject *module_cp = NULL; + PyObject *bytes = NULL; vm_args.version = JNI_VERSION_1_4; JNI_GetDefaultJavaVMInitArgs(&vm_args); @@ -427,21 +429,47 @@ _DLL_EXPORT PyObject *initVM(PyObject *s if (classpath == NULL && self != NULL) { module_cp = PyObject_GetAttrString(self, "CLASSPATH"); - if (module_cp != NULL) - classpath = PyUnicode_AsString(module_cp); + if (module_cp) + { + bytes = PyUnicode_AsUTF8String(module_cp); + if (!bytes) + { + Py_DECREF(module_cp); + return NULL; + } + + classpath = PyBytes_AS_STRING(bytes); + } } #ifdef _jcc_lib PyObject *jcc = PyImport_ImportModule("jcc"); + if (!jcc) + return NULL; + PyObject *cp = PyObject_GetAttrString(jcc, "CLASSPATH"); + if (!cp) + { + Py_DECREF(jcc); + return NULL; + } + + PyObject *cpbytes = PyUnicode_AsUTF8String(cp); + if (!cpbytes) + { + Py_DECREF(cp); + Py_DECREF(jcc); + return NULL; + } if (classpath) - add_paths("-Djava.class.path=", PyUnicode_AsString(cp), classpath, - &vm_options[nOptions++]); + add_paths("-Djava.class.path=", PyBytes_AS_STRING(cpbytes), + classpath, &vm_options[nOptions++]); else - add_option("-Djava.class.path=", PyUnicode_AsString(cp), + add_option("-Djava.class.path=", PyBytes_AS_STRING(cpbytes), &vm_options[nOptions++]); - + + Py_DECREF(cpbytes); Py_DECREF(cp); Py_DECREF(jcc); #else @@ -450,6 +478,7 @@ _DLL_EXPORT PyObject *initVM(PyObject *s &vm_options[nOptions++]); #endif + Py_XDECREF(bytes); Py_XDECREF(module_cp); if (initialheap)