python: Add std::vector<std::string> support (Fix #2453)

This commit is contained in:
Mizux Seiha
2021-03-23 18:36:02 +01:00
parent 78b814ddcb
commit 9d5fd8079e
2 changed files with 9 additions and 0 deletions

View File

@@ -218,6 +218,14 @@ inline int SwigPyIntOrLong_Check(PyObject* o) {
); // NOLINT
}
inline int SwigString_Check(PyObject* o) {
#if PY_VERSION_HEX >= 0x03030000
return PyUnicode_Check(o);
#else
return true;
#endif
}
inline PyObject* SwigString_FromString(const std::string& s) {
return PyString_FromStringAndSize(s.data(), s.size());
}

View File

@@ -86,6 +86,7 @@
PY_LIST_INPUT_OUTPUT_TYPEMAP(int, PyInt_Check, PyInt_FromLong);
PY_LIST_INPUT_OUTPUT_TYPEMAP(int64, SwigPyIntOrLong_Check, PyLong_FromLongLong);
PY_LIST_INPUT_OUTPUT_TYPEMAP(double, PyFloat_Check, PyFloat_FromDouble);
PY_LIST_INPUT_OUTPUT_TYPEMAP(std::string, SwigString_Check, SwigString_FromString);
// Add conversion list(tuple(int)) -> std::vector<std::vector>.
// TODO(user): see if we can also get rid of this and utilize already