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!
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; }