mirror of https://github.com/swig/swig
Correct const std::filesystem & typemaps
Marshal to pathlib.Path
This commit is contained in:
parent
d2221f1547
commit
9bbd176038
|
@ -24,6 +24,10 @@ path = makePath("foo")
|
|||
check_flag(isinstance(path, pathlib.Path))
|
||||
check(str(path), "foo")
|
||||
|
||||
pathConstRef = makePathConstRef("foo")
|
||||
check_flag(isinstance(pathConstRef, pathlib.Path))
|
||||
check(str(pathConstRef), "foo")
|
||||
|
||||
# Each of these should return a reference to a wrapped
|
||||
# std::filesystem::path object.
|
||||
pathPtr = makePathPtr("foo")
|
||||
|
@ -32,9 +36,6 @@ check_flag(not isinstance(pathPtr, pathlib.Path))
|
|||
pathRef = makePathRef("foo")
|
||||
check_flag(not isinstance(pathRef, pathlib.Path))
|
||||
|
||||
pathConstRef = makePathConstRef("foo")
|
||||
check_flag(not isinstance(pathConstRef, pathlib.Path))
|
||||
|
||||
# Now test various input typemaps. Each of the wrapped C++ functions
|
||||
# (pathToStr, pathConstRefToStr) is expecting an argument of a
|
||||
# different type (see li_std_filesystem.i). Typemaps should be in place to
|
||||
|
|
|
@ -86,10 +86,25 @@ SWIGINTERN bool SWIG_std_filesystem_isPathInstance(PyObject *obj) {
|
|||
%typemap(out, fragment="SWIG_std_filesystem") std::filesystem::path {
|
||||
PyObject *args;
|
||||
if constexpr (std::is_same_v<typename std::filesystem::path::value_type, wchar_t>) {
|
||||
const std::wstring s = $1.generic_wstring();
|
||||
std::wstring s = $1.generic_wstring();
|
||||
args = Py_BuildValue("(u)", s.data());
|
||||
} else {
|
||||
const std::string s = $1.generic_string();
|
||||
std::string s = $1.generic_string();
|
||||
args = Py_BuildValue("(s)", s.data());
|
||||
}
|
||||
PyObject *cls = SWIG_std_filesystem_importPathClass();
|
||||
$result = PyObject_CallObject(cls, args);
|
||||
Py_DECREF(cls);
|
||||
Py_DECREF(args);
|
||||
}
|
||||
|
||||
%typemap(out, fragment="SWIG_std_filesystem") const std::filesystem::path & {
|
||||
PyObject *args;
|
||||
if constexpr (std::is_same_v<typename std::filesystem::path::value_type, wchar_t>) {
|
||||
std::wstring s = $1->generic_wstring();
|
||||
args = Py_BuildValue("(u)", s.data());
|
||||
} else {
|
||||
std::string s = $1->generic_string();
|
||||
args = Py_BuildValue("(s)", s.data());
|
||||
}
|
||||
PyObject *cls = SWIG_std_filesystem_importPathClass();
|
||||
|
|
Loading…
Reference in New Issue