[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG/src - indexsupport.c:1.1.2.5
Andreas Jung
andreas@digicool.com
Mon, 18 Mar 2002 18:07:28 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG/src
In directory cvs.zope.org:/tmp/cvs-serv28168/src
Modified Files:
Tag: ajung-textindexng-branch
indexsupport.c
Log Message:
- additional error checks
- fixed potential coredump
- minor cleanup
=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/src/indexsupport.c 1.1.2.4 => 1.1.2.5 ===
*/
-PyObject *vocabularyBatchInsert(PyObject *self,PyObject *args) {
+PyObject *vocabularyBatchInsert(PyObject *modinfo,PyObject *args) {
PyObject *fwdIdx,*revIdx, *lst, *word, *wid;
- PyObject *ids;
+ PyObject *wids;
int i;
- ids = PyList_New(0);
+ if (! PyArg_ParseTuple(args, "OOO", &fwdIdx,&revIdx,&lst)) return NULL;
- if (PyArg_ParseTuple(args, "OOO", &fwdIdx,&revIdx,&lst)<0) return NULL;
+ if (! PyMapping_Check(fwdIdx)) {
+ PyErr_SetString(PyExc_TypeError, "1st argument must be OIBTree instance"); \
+ return NULL;
+ }
+
+ if (! PyMapping_Check(revIdx)) {
+ PyErr_SetString(PyExc_TypeError, "2nd argument must be IOTree instance"); \
+ return NULL;
+ }
if (! PySequence_Check(lst)) {
- PyErr_SetString(PyExc_TypeError, "sequence expected"); \
+ PyErr_SetString(PyExc_TypeError, "3rd argument must be sequence");
return NULL;
}
+ wids = PyList_New(0);
for (i=0; i<PySequence_Length(lst);i++) {
word = PySequence_GetItem(lst,i);
@@ -99,16 +108,15 @@
do {
wid = PyInt_FromLong( rand() );
} while(PyMapping_HasKey(revIdx, wid));
-
PyObject_SetItem(fwdIdx, word, wid);
PyObject_SetItem(revIdx, wid,word);
}
- PyList_Append(ids, wid);
+ PyList_Append(wids, wid);
}
- return ids;
+ return wids;
}
static struct PyMethodDef indexsupport_module_methods[] =
@@ -117,7 +125,7 @@
"stopwordfilter(wordslist,stopword dict') " "-- filters words from wordslist that are stopwords"
},
{ "vocabBatchInsert", (PyCFunction) vocabularyBatchInsert, METH_VARARGS,
- "vocabBatchInsert(fwdIdx,revIdx,wordLst') " "-- inserts forward and backward entries for vocabularies"
+ "vocabBatchInsert(fwdIdx,revIdx,wordLst)" "-- inserts forward and backward entries for vocabularies"
},
{ "listIndexes", (PyCFunction) listIndexes, METH_VARARGS,
"listIndexes(list of words',word) " "-- find all positions of word in a list of words"