Apply zetmodule.diff from debian packaging, makes the Python module compileable
authorNick Downing <nick@ndcode.org>
Mon, 5 Nov 2018 22:46:59 +0000 (09:46 +1100)
committerNick Downing <nick@ndcode.org>
Tue, 6 Nov 2018 00:08:37 +0000 (11:08 +1100)
src/pyzet/zetmodule.c

index 8eb6e98..0933b52 100644 (file)
 #include "vocab.h"
 #include "mlparse.h"
 #include "str.h"
-#include "ndocmap.h"
+#include "docmap.h"
 
 /* 
  *  Utility function forward declarations.
  */
 static PyObject * index_result_to_PyObject(struct index_result * result);
 static PyObject * index_results_to_PyObject(struct index_result * results,
-  unsigned int num_results, unsigned long int total_results);
+  unsigned int num_results, double/*unsigned long int*/ total_results);
 
 /* *****************************************************************
  *
@@ -321,7 +321,7 @@ static PyObject * SearchResult_str(zet_SearchResultObject * self) {
  */
 typedef struct {
     PyObject_HEAD
-    unsigned long int total_results;
+    double/*unsigned long int*/ total_results;
     PyObject * results;
 } zet_SearchResultsObject;
 
@@ -329,7 +329,7 @@ typedef struct {
  *  Members as visible from Python.
  */
 static PyMemberDef SearchResults_members[] = {
-    {"total_results", T_ULONG, offsetof(zet_SearchResultsObject, 
+    {"total_results", T_DOUBLE/*T_ULONG*/, offsetof(zet_SearchResultsObject, 
       total_results), 0, "total results"},
     {"results", T_OBJECT_EX, offsetof(zet_SearchResultsObject, 
       results), 0, "results" },
@@ -539,13 +539,13 @@ static PyObject * PostingsIterator_next(zet_PostingsIteratorObject * self) {
 
     vec.pos = self->postings->vec + self->vec_offset;
     vec.end = vec.pos + self->postings->size;
-    vec_vbyte_read_unchecked(&vec, &docno_d);
+    vec_vbyte_read/*unchecked*/(&vec, &docno_d);
 
     if (self->last_docno == (unsigned long) -1)
         posting->docno = docno_d;
     else 
         posting->docno = self->last_docno + docno_d + 1;
-    vec_vbyte_read_unchecked(&vec, &f_dt);
+    vec_vbyte_read/*unchecked*/(&vec, &f_dt);
     posting->f_dt = f_dt;
     posting->offsets = PyTuple_New(f_dt);
     if (posting->offsets == NULL) {
@@ -556,7 +556,7 @@ static PyObject * PostingsIterator_next(zet_PostingsIteratorObject * self) {
     for (i = 0; i < f_dt; i++) {
         unsigned long int offset_d;
         PyObject * pyOffset;
-        vec_vbyte_read_unchecked(&vec, &offset_d);
+        vec_vbyte_read/*unchecked*/(&vec, &offset_d);
         if (i == 0)
             offset = offset_d;
         else
@@ -607,7 +607,7 @@ static PyObject * PostingsIterator_skip_to(PyObject * self,
         unsigned long vec_save_pos;
 
         vec_save_pos = vec.pos - iterator->postings->vec;
-        vec_vbyte_read_unchecked(&vec, &docno_d);
+        vec_vbyte_read/*unchecked*/(&vec, &docno_d);
         prev_docno = curr_docno;
         if (curr_docno == (unsigned long) -1)
             curr_docno = docno_d;
@@ -617,8 +617,8 @@ static PyObject * PostingsIterator_skip_to(PyObject * self,
             /* skip the offsets */
             unsigned long f_dt;
             unsigned int scanned;
-            vec_vbyte_read_unchecked(&vec, &f_dt);
-            vec_vbyte_scan_unchecked(&vec, f_dt, &scanned);
+            vec_vbyte_read/*unchecked*/(&vec, &f_dt);
+            vec_vbyte_scan/*_unchecked*/(&vec, f_dt, &scanned);
         } else {
             vec.pos = iterator->postings->vec + vec_save_pos;
         }
@@ -925,7 +925,7 @@ static PyObject * Index_term_postings(PyObject * self, PyObject * args);
 static PyObject * Index_vocab_iterator(PyObject * self, PyObject * args);
 static PyObject * Index_num_docs(PyObject * self, PyObject * args);
 static PyObject * Index_vocab_size(PyObject * self, PyObject * args);
-static PyObject * Index_doc_aux(PyObject * self, PyObject * args);
+static PyObject * Index_doc_trecno/*Index_doc_aux*/(PyObject * self, PyObject * args);
 
 /*
  *  Object methods as visible from Python.
@@ -945,7 +945,7 @@ static PyMethodDef Index_methods[] = {
         "Get the total number of documents in the indexed collection"},
     {"vocab_size", Index_vocab_size, METH_NOARGS,
         "Get the number of terms in the index vocab" },
-    {"doc_aux", Index_doc_aux, METH_VARARGS,
+    {"doc_trecno"/*"doc_aux"*/, Index_doc_trecno/*Index_doc_aux*/, METH_VARARGS,
         "Get the auxiliary information for a document."},
     {NULL}
 };
@@ -1005,7 +1005,8 @@ static PyObject * Index_search(PyObject * self, PyObject * args,
     zet_IndexObject * Index = (zet_IndexObject *) self;
     struct index_result * result;
     unsigned int results;
-    unsigned long int total_results;
+    double/*unsigned long int*/ total_results;
+    int est;
     unsigned int accumulator_limit = 0;
     int opts = INDEX_SEARCH_NOOPT;
     struct index_search_opt opt;
@@ -1033,22 +1034,26 @@ static PyObject * Index_search(PyObject * self, PyObject * args,
             if (optArgsTuple == NULL) {
                 PyErr_SetString(PyExc_StandardError, "Must supply args to "
                   "search type");
+                free(result);
                 return NULL;
             }
             opts = INDEX_SEARCH_OKAPI_RANK;
             if (!PyArg_ParseTuple(optArgsTuple, "ddd",
                   &opt.u.okapi_k3.k1, &opt.u.okapi_k3.k3, &opt.u.okapi_k3.b)) {
+                free(result);
                 return NULL;
             }
         } else if (strcmp(optType, "HAWKAPI") == 0) {
             if (optArgsTuple == NULL) {
                 PyErr_SetString(PyExc_StandardError, "Must supply args to "
                   "search type");
+                free(result);
                 return NULL;
             }
             opts = INDEX_SEARCH_HAWKAPI_RANK;
             if (!PyArg_ParseTuple(optArgsTuple, "dd", &opt.u.hawkapi.alpha,
                   &opt.u.hawkapi.k3)) {
+                free(result);
                 return NULL;
             }
         } else if (strcmp(optType, "DIRICHLET") == 0) {
@@ -1057,6 +1062,7 @@ static PyObject * Index_search(PyObject * self, PyObject * args,
                 opt.u.dirichlet.mu = 2500.0;
             } else if (!PyArg_ParseTuple(optArgsTuple, "f",
                   &opt.u.dirichlet.mu)) {
+                free(result);
                 return NULL;
             }
         } else {
@@ -1069,7 +1075,7 @@ static PyObject * Index_search(PyObject * self, PyObject * args,
         opt.accumulator_limit = accumulator_limit;
     }
     if (!index_search(Index->idx, query, startdoc, len,
-          result, &results, &total_results, opts, &opt)) {
+          result, &results, &total_results, &est, opts, &opt)) {
         char err_buf[1024];
         snprintf(err_buf, 1024, "Unable to perform search for query '%s'; "
            "system error is '%s'\n", query, strerror(errno));
@@ -1252,7 +1258,7 @@ static PyObject * Index_num_docs(PyObject * self, PyObject * args) {
     struct index * idx = Index->idx;
     unsigned long num_docs;
 
-    num_docs = ndocmap_entries(idx->map);
+    num_docs = docmap_entries(idx->map);
     return Py_BuildValue("k", num_docs);
 }
 
@@ -1267,20 +1273,20 @@ static PyObject * Index_vocab_size(PyObject * self, PyObject * args) {
 
 #define AUX_BUF_LEN 1024
 
-static PyObject * Index_doc_aux(PyObject * self, PyObject * args) {
+static PyObject * Index_doc_trecno/*Index_doc_aux*/(PyObject * self, PyObject * args) {
     zet_IndexObject * Index = (zet_IndexObject *) self;
     struct index * idx = Index->idx;
-    struct ndocmap * docmap = idx->map;
+    struct docmap * docmap = idx->map;
     char aux_buf[AUX_BUF_LEN];
     unsigned aux_len;
     unsigned long int docno;
-    enum ndocmap_ret ret;
+    enum docmap_ret ret;
 
     if (!PyArg_ParseTuple(args, "k", &docno))
         return NULL;
-    ret = ndocmap_get_aux(docmap, docno, aux_buf, AUX_BUF_LEN, &aux_len);
-    if (ret != NDOCMAP_OK) {
-        /* error might be NDOCMAP_BUFSIZE_ERROR, but life is too short... */
+    ret = docmap_get_trecno/*docmap_get_aux*/(docmap, docno, aux_buf, AUX_BUF_LEN, &aux_len);
+    if (ret != DOCMAP_OK) {
+        /* error might be DOCMAP_BUFSIZE_ERROR, but life is too short... */
         PyErr_SetString(PyExc_IOError, "Unable to read aux info");
         return NULL;
     }
@@ -1328,7 +1334,7 @@ static PyObject * index_result_to_PyObject(struct index_result * result) {
 }
 
 static PyObject * index_results_to_PyObject(struct index_result * results,
-  unsigned int num_results, unsigned long int total_results) {
+  unsigned int num_results, double/*unsigned long int*/ total_results) {
     int i;
     zet_SearchResultsObject * pyResult = PyObject_New(zet_SearchResultsObject,
       &zet_SearchResultsType);
@@ -1398,7 +1404,8 @@ zet_search(PyObject *self, PyObject *args) {
     struct index * idx;
     struct index_result * result;
     unsigned int results;
-    unsigned long int total_results;
+    double/*unsigned long int*/ total_results;
+    int est;
     int opts = INDEX_SEARCH_NOOPT;
     struct index_search_opt opt;
 
@@ -1416,7 +1423,7 @@ zet_search(PyObject *self, PyObject *args) {
         return NULL;
     }
     if (!index_search(idx, query, startdoc, len, result, 
-          &results, &total_results, opts, &opt)) {
+          &results, &total_results, &est, opts, &opt)) {
         PyErr_SetString(PyExc_StandardError, "Unable to perform search");
         free(result);
         index_delete(idx);