Skip to content

Commit

Permalink
version 0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zdzhaoyong committed Oct 26, 2021
1 parent d3d5547 commit 33bfcfe
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/python/svarpy/src/SvarPy.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,12 @@ struct SvarPy: public PyObject{
lut[&PyLong_Type] =[](PyObject* o)->Svar{return (int)PyLong_AsLong(o);};

lut[&PyUnicode_Type] =[](PyObject* obj)->Svar{
PyObject* buf=PyUnicode_AsUTF8String(obj);
PyObjectHolder buf(PyUnicode_AsUTF8String(obj),false);
char *buffer=nullptr;
ssize_t length=0;

if (SVAR_BYTES_AS_STRING_AND_SIZE(buf, &buffer, &length))
if (SVAR_BYTES_AS_STRING_AND_SIZE(buf.obj, &buffer, &length))
LOG(ERROR)<<("Unable to extract string contents! (invalid type)");
decref(buf);// important, prevent memory leak
return std::string(buffer, (size_t) length);
};

Expand All @@ -438,8 +437,8 @@ struct SvarPy: public PyObject{
Py_ssize_t pos = 0;

while (PyDict_Next(obj, &pos, &key, &value)) {
if(!PyUnicode_Check(obj)) continue;
dict[fromPy(key).castAs<std::string>()] = fromPy(value);
if(!PyUnicode_Check(key)) continue;
dict[fromPy(key).unsafe_as<std::string>()] = fromPy(value);
}
return dict;
};
Expand Down

0 comments on commit 33bfcfe

Please sign in to comment.