Changeset 11158
- Timestamp:
- 2008-09-03 06:24:47 (3 months ago)
- Location:
- trunk/xapian-bindings
- Files:
-
- 2 modified
-
ChangeLog (modified) (1 diff)
-
python/util.i (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/xapian-bindings/ChangeLog
r11059 r11158 1 Wed Sep 03 05:22:09 GMT 2008 Richard Boulton <richard@lemurconsulting.com> 2 3 * python/util.i: Fix memory leaks in query constructor typemaps. 4 Also, remove old, commented out, code which almost certainly had 5 similar memory leaks - I don't think we're going to want this 6 code, but if we do, rewriting it by copying the maintained and 7 working code for the query constructor is less likely to lead to 8 subtle errors. 9 1 10 Mon Aug 04 05:06:46 GMT 2008 Olly Betts <olly@survex.com> 2 11 -
trunk/xapian-bindings/python/util.i
r10784 r11158 55 55 PyObject * mythis = PyObject_GetAttrString(obj, "this"); 56 56 #endif 57 if (!mythis) 58 return 0; 59 57 60 Query * retval = 0; 58 if (!mythis || SWIG_ConvertPtr(mythis, (void **)&retval, 59 SWIGTYPE_p_Xapian__Query, 0) < 0) { 61 int res = SWIG_ConvertPtr(mythis, (void **)&retval, 62 SWIGTYPE_p_Xapian__Query, 0); 63 if (!SWIG_IsOK(res)) { 60 64 retval = 0; 61 65 } 66 Py_DECREF(mythis); 62 67 return retval; 63 68 } 64 65 #if 0 // Currently unused66 RSet *get_py_rset(PyObject *obj) {67 PyObject * mythis = PyObject_GetAttrString(obj, "this");68 Rset * retval = 0;69 if (!mythis || SWIG_ConvertPtr(mythis, (void **)&retval,70 SWIGTYPE_p_Xapian__RSet, 0) < 0) {71 retval = 0;72 }73 return retval;74 }75 #endif76 77 #if 0 // FIXME78 MatchDecider *get_py_matchdecider(PyObject *obj) {79 PyObject * mythis = PyObject_GetAttrString(obj, "this");80 MatchDecider * retval = 0;81 if (!mythis || SWIG_ConvertPtr(mythis, (void **)&retval,82 SWIGTYPE_p_Xapian__MatchDecider, 0) < 0) {83 retval = 0;84 }85 return retval;86 }87 #endif88 89 #if 090 int get_py_int(PyObject *obj) {91 if (!PyNumber_Check(obj)) {92 throw PythonProblem();93 }94 return PyInt_AsLong(PyNumber_Int(obj));95 }96 #endif97 69 } 98 70 %} … … 104 76 } else { 105 77 $1 = 1; 106 int numitems = PySequence_Size($input); 78 PyObject * fastseq = PySequence_Fast($input, "expected sequence of strings or queries"); 79 if (!fastseq) { 80 // We've already checked that we have a sequence, so the failure of 81 // PySequence_Fast() is a serious error, not just a failure of 82 // typecheck. 83 SWIG_fail; 84 } 85 int numitems = PySequence_Fast_GET_SIZE(fastseq); 107 86 for (int i = 0; i < numitems; ++i) { 108 PyObject *obj = PySequence_ GetItem($input, i);87 PyObject *obj = PySequence_Fast_GET_ITEM(fastseq, i); 109 88 if (!PyUnicode_Check(obj) && 110 89 %#if PY_VERSION_HEX >= 0x03000000 … … 118 97 } 119 98 } 99 Py_DECREF(fastseq); 120 100 } 121 101 } 122 102 123 103 %typemap(in) const vector<Xapian::Query> & (vector<Xapian::Query> v) { 124 if (!PySequence_Check($input)) {125 PyErr_SetString(PyExc_TypeError, "expected list of strings or queries"); 126 return NULL;127 } 128 129 int numitems = PySequence_ Size($input);104 PyObject * fastseq = PySequence_Fast($input, "expected sequence of strings or queries"); 105 if (!fastseq) { 106 SWIG_fail; 107 } 108 109 int numitems = PySequence_Fast_GET_SIZE(fastseq); 130 110 v.reserve(numitems); 131 111 for (int i = 0; i < numitems; ++i) { 132 PyObject *obj = PySequence_GetItem($input, i); 112 PyObject *obj = PySequence_Fast_GET_ITEM(fastseq, i); 113 PyObject *decrefme = NULL; 133 114 if (PyUnicode_Check(obj)) { 134 115 PyObject *strobj = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(obj), PyUnicode_GET_SIZE(obj), "ignore"); 135 116 if (!strobj) SWIG_fail; 136 Py_DECREF(obj);137 117 obj = strobj; 118 decrefme = strobj; 138 119 } 139 120 %#if PY_VERSION_HEX >= 0x03000000 … … 157 138 if (!subqp) { 158 139 PyErr_SetString(PyExc_TypeError, "expected string or query"); 140 Py_XDECREF(decrefme); 159 141 SWIG_fail; 160 142 } 161 143 v.push_back(*subqp); 162 144 } 145 Py_XDECREF(decrefme); 163 146 } 164 147 $1 = &v; 148 Py_DECREF(fastseq); 165 149 } 166 150
