Skip to content

Commit

Permalink
Python3.7 fix (retro-compatible) (#10)
Browse files Browse the repository at this point in the history
* add char * copy(const char*) and fix error lines

* Small style changes.

* Fix syntax error

* Use Python 3.7 within CI build.

* Travis CI work-around for Python 3.7.

* Update requirements to numpy/scipy versions that have Python 3.7 wheels/support.
  • Loading branch information
Ricocotam authored and cvangysel committed Feb 17, 2019
1 parent 2ad61de commit f9c04ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ python:
- "3.4"
- "3.5"
- "3.6"
# Follow the work-around proposed in https://github.com/travis-ci/travis-ci/issues/9815 to enable Python 3.7 on Travis.
matrix:
include:
- python: 3.7
dist: xenial
sudo: true
install:
- pip install -r requirements.txt
- pip install .
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
numpy==1.11.1
scipy==0.18.1
numpy>=1.15.1
scipy>=1.1.0
10 changes: 8 additions & 2 deletions src/pytrec_eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ int PyDict_SetItemAndSteal(PyObject* p, PyObject* key, PyObject* val) {
return ret;
}

char* CopyCString(const char* originalCString) {
char* const newCString = new char[strlen(originalCString) + 1];
strcpy(newCString, originalCString);
return newCString;
}

static PyTypeObject RelevanceEvaluatorType;

// RelevanceEvaluator
Expand Down Expand Up @@ -128,7 +134,7 @@ class RankingBuilder {

Py_INCREF(key);

queries[query_idx].qid = PyUnicode_AsUTF8(key);
queries[query_idx].qid = CopyCString(PyUnicode_AsUTF8(key));
CHECK_NOTNULL(queries[query_idx].qid);

PairT* const query_document_pairs = Malloc(PyDict_Size(value), PairT);
Expand All @@ -147,7 +153,7 @@ class RankingBuilder {
return false; // TODO(cvangysel): need to clean up here!
}

query_document_pairs[pair_idx].docno = PyUnicode_AsUTF8(inner_key);
query_document_pairs[pair_idx].docno = CopyCString(PyUnicode_AsUTF8(inner_key));
CHECK_NOTNULL(query_document_pairs[pair_idx].docno);

if (!ProcessQueryDocumentPair(&query_document_pairs[pair_idx],
Expand Down

0 comments on commit f9c04ab

Please sign in to comment.