Skip to content

Commit

Permalink
fixed crash of classifier constructor on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
cdalitz committed Apr 23, 2015
1 parent f32d840 commit c4cbb5c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
6 changes: 4 additions & 2 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Changes made between Gamera File Releases
=========================================

Version 3.4.2, Apr 23, 2015
----------------------------

- updated zlib to version 1.2.8 (only used under Windows)

- enabled exceptions in compiler options on Windows
(this unfortunately does not fix the crash of the classifier on Windows)
- fixed classifier crash on Windows

- fixed hang with wxpython 3.0 after quitting gamera_gui

Expand Down
2 changes: 1 addition & 1 deletion include/knncoremodule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace Gamera { namespace kNN {
// The id_names for the feature vectors
char** id_names;
// confidence types to be computed during classification
std::vector<int> confidence_types;
std::vector<int> *confidence_types;
// The current selected features
int *selection_vector;
// The current weights applied to the distance calculation
Expand Down
16 changes: 9 additions & 7 deletions src/knncoremodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ static PyObject* knn_new(PyTypeObject* pytype, PyObject* args,
o->unknown = 0;
o->num_k = 1;
o->distance_type = CITY_BLOCK;
o->confidence_types.push_back(CONFIDENCE_DEFAULT);
o->confidence_types = new std::vector<int>();
o->confidence_types->push_back(CONFIDENCE_DEFAULT);

Py_INCREF(Py_None);
return (PyObject*)o;
Expand Down Expand Up @@ -265,6 +266,7 @@ static void knn_dealloc(PyObject* self) {
delete o->normalize;
if (o->unknown != 0)
delete[] o->unknown;
delete o->confidence_types;
self->ob_type->tp_free(self);
}

Expand Down Expand Up @@ -432,7 +434,7 @@ static PyObject* knn_classify(PyObject* self, PyObject* args) {

// create the kNN object
kNearestNeighbors<char*, ltstr, eqstr> knn(o->num_k);
knn.confidence_types = o->confidence_types;
knn.confidence_types = *(o->confidence_types);

double *current_known;

Expand Down Expand Up @@ -508,7 +510,7 @@ static PyObject* knn_classify_with_images(PyObject* self, PyObject* args) {
}

kNearestNeighbors<char*, ltstr, eqstr> knn(o->num_k);
knn.confidence_types = o->confidence_types;
knn.confidence_types = *(o->confidence_types);

PyObject* cur;
while ((cur = PyIter_Next(iterator))) {
Expand Down Expand Up @@ -909,10 +911,10 @@ static PyObject* knn_get_confidence_types(PyObject* self) {
size_t n,i;
PyObject* entry;
KnnObject* o = ((KnnObject*)self);
n = o->confidence_types.size();
n = o->confidence_types->size();
PyObject* result = PyList_New(n);
for (i=0; i<n; i++) {
entry = PyInt_FromLong(o->confidence_types[i]);
entry = PyInt_FromLong(o->confidence_types->at(i));
PyList_SetItem(result, i, entry);
}
return result;
Expand All @@ -927,7 +929,7 @@ static int knn_set_confidence_types(PyObject* self, PyObject* list) {
int ct;
PyObject* entry;
KnnObject* o = ((KnnObject*)self);
o->confidence_types.clear();
o->confidence_types->clear();
n = PyList_Size(list);
for (i=0; i<n; i++) {
entry = PyList_GetItem(list, i);
Expand All @@ -936,7 +938,7 @@ static int knn_set_confidence_types(PyObject* self, PyObject* list) {
return -1;
}
ct = (ConfidenceTypes)PyInt_AsLong(entry);
o->confidence_types.push_back(ct);
o->confidence_types->push_back(ct);
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.4.1
3.4.2

0 comments on commit c4cbb5c

Please sign in to comment.