Python Forum
I need help with a "deallocating none" error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help with a "deallocating none" error
#4
I may have found a bug in swig-generated code!? Py_None is being returned here without calling Py_INCREF. Fixing that still doesn't correct my issue, but it seems like something like this would be the culprit (if I'm understanding these dynamics correctly)

edit:Never mind about it being a swig issue; this was my boo boo. Swig was just following orders! This was indeed what was causing my exception. In my excitement after finding this issue, I forgot to install the recompiled binary before running the test. It runs fine now!

SWIGINTERN PyObject *_wrap_SomeClass_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
// ... 
result = (arg1)->get((std::string const &)*arg2);
  {
    if ((&result)->size() > 0) {
      resultobj = PyBytes_FromStringAndSize((&result)->data(),(&result)->size());
    } else {
      resultobj = Py_None;
    }
  }
  if (SWIG_IsNewObj(res2)) delete arg2;
  return resultobj;
}
The fix:
SWIGINTERN PyObject *_wrap_SomeClass_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
// ... 
result = (arg1)->get((std::string const &)*arg2);
  {
    if ((&result)->size() > 0) {
      resultobj = PyBytes_FromStringAndSize((&result)->data(),(&result)->size());
    } else {
      resultobj = Py_None;
      Py_INCREF(resultobj);
    }
  }
  if (SWIG_IsNewObj(res2)) delete arg2;
  return resultobj;
}
Reply


Messages In This Thread
RE: I need help with a "deallocating none" error - by Tails86 - Oct-13-2021, 10:02 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020