Skip to content

Commit

Permalink
temporary fix for bytes classname
Browse files Browse the repository at this point in the history
  • Loading branch information
malajvan committed May 15, 2023
1 parent 66d7570 commit bf054da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions gamera-4/include/knnmodule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ inline int image_get_id_name(PyObject* image, char** id_name, int* len) {
PyErr_SetString(PyExc_TypeError, "knn: could not get string from id_name tuple.");
return -1;
}
Py_ssize_t lenTmp = 0;
if(PyBytes_AsStringAndSize(id, id_name, &lenTmp) < 0){
PyErr_SetString(PyExc_TypeError, "knn: could not get string from id_name tuple.");
return -1;
const char *id_str = PyUnicode_AsUTF8(id); //id is currently the class name, type PyUnicode (str)
PyObject *id_bytes = PyBytes_FromString(id_str);
Py_ssize_t lenTmp = 0;
if (PyBytes_AsStringAndSize(id_bytes, id_name, &lenTmp) < 0){
PyErr_SetString(PyExc_TypeError, "knn: could not get string from id_name tuple.");
return -1;
}
*len = lenTmp;
if (*id_name == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion gamera-4/src/knncore/knncoremodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ static PyObject* knn_classify_with_images(PyObject* self, PyObject* args) {
(This is most likely because features have not been generated.)");
return 0;
}

//id_name is equivalent to class_name in glyph (RODAN Comment)
char* id_name;
int len;
if (image_get_id_name(cur, &id_name, &len) < 0) {
Expand Down

0 comments on commit bf054da

Please sign in to comment.