diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 700a815..5dda943 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -16,6 +16,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . +Changes in v0.17.1: + 1/ Fix crash when using localised exceptions on Windows. + Changes in v0.17.0: 1/ API change: derived classes of BasicIo are omitted from Python. 2/ Binary wheels incorporate libexiv2 v0.28.3. diff --git a/README.rst b/README.rst index 60ff9db..1c4208e 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -python-exiv2 v\ 0.17.0 +python-exiv2 v\ 0.17.1 ====================== python-exiv2 is a low level interface (or binding) to the exiv2_ C++ library. diff --git a/pyproject.toml b/pyproject.toml index 2adcb7b..04ef7ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ dynamic = ["version"] [project.urls] Homepage = "https://github.com/jim-easterbrook/python-exiv2" Changelog = "https://github.com/jim-easterbrook/python-exiv2/blob/main/CHANGELOG.txt" -Documentation = "https://github.com/jim-easterbrook/python-exiv2/blob/main/USAGE.rst" +Documentation = "https://python-exiv2.readthedocs.io/" [tool.setuptools] platforms = ["POSIX", "MacOS", "Windows"] diff --git a/setup.py b/setup.py index c8360ab..8d5d0fa 100644 --- a/setup.py +++ b/setup.py @@ -84,6 +84,8 @@ def get_mod_src_dir(exiv2_version): packages.append('exiv2.lib') if platform == 'linux': path = os.path.join(exiv2_root, 'lib64') + if not os.path.exists(path): + path = os.path.join(exiv2_root, 'lib') library_dirs = [path] package_dir['exiv2.lib'] = path package_data['exiv2.lib'] = [x for x in os.listdir(path) diff --git a/src/doc/requirements.txt b/src/doc/requirements.txt index 306fadd..cd43bb2 100644 --- a/src/doc/requirements.txt +++ b/src/doc/requirements.txt @@ -1,3 +1,3 @@ -exiv2 <= 0.17.0 +exiv2 <= 0.17.1 sphinx == 7.2.6 sphinx-rtd-theme == 2.0.0 diff --git a/src/interface/error.i b/src/interface/error.i index 59e637b..d28cf13 100644 --- a/src/interface/error.i +++ b/src/interface/error.i @@ -39,13 +39,14 @@ static PyObject* logger = NULL; static void log_to_python(int level, const char* msg) { std::string copy = msg; - utf8_to_wcp(©, false); + if (wcp_to_utf8(©)) + copy = msg; Py_ssize_t len = copy.size(); while (len > 0 && copy[len-1] == '\n') len--; PyGILState_STATE gstate = PyGILState_Ensure(); PyObject* res = PyObject_CallMethod( - logger, "log", "(is#)", (level + 1) * 10, copy.c_str(), len); + logger, "log", "(is#)", (level + 1) * 10, copy.data(), len); Py_XDECREF(res); PyGILState_Release(gstate); }; diff --git a/src/interface/shared/exception.i b/src/interface/shared/exception.i index 64d200b..eb237e1 100644 --- a/src/interface/shared/exception.i +++ b/src/interface/shared/exception.i @@ -47,7 +47,8 @@ static void _set_python_exception() { #if EXIV2_VERSION_HEX < 0x001c0000 catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -55,8 +56,11 @@ static void _set_python_exception() { } #else catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } diff --git a/src/interface/shared/windows_cp.i b/src/interface/shared/windows_cp.i index 6ee6db2..709774d 100644 --- a/src/interface/shared/windows_cp.i +++ b/src/interface/shared/windows_cp.i @@ -22,34 +22,45 @@ #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif }; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif +}; + %} diff --git a/src/interface/shared/windows_path.i b/src/interface/shared/windows_path.i index be5fb7f..d36e269 100644 --- a/src/interface/shared/windows_path.i +++ b/src/interface/shared/windows_path.i @@ -22,8 +22,10 @@ %define WINDOWS_PATH(signature) %typemap(check, fragment="utf8_to_wcp") signature { %#ifdef _WIN32 - if (utf8_to_wcp($1, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp($1); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } %#endif } @@ -33,8 +35,10 @@ %define WINDOWS_PATH_OUT(function) %typemap(out, fragment="utf8_to_wcp") std::string function { %#ifdef _WIN32 - if (utf8_to_wcp(&$1, false) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode result"); + int error = wcp_to_utf8(&$1); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } %#endif $result = SWIG_FromCharPtrAndSize($1.data(), $1.size()); @@ -42,8 +46,10 @@ %typemap(out, fragment="utf8_to_wcp") const std::string& function { std::string copy = *$1; %#ifdef _WIN32 - if (utf8_to_wcp(©, false) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode result"); + int error = wcp_to_utf8(©); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } %#endif $result = SWIG_FromCharPtrAndSize(copy.data(), copy.size()); diff --git a/src/swig-0_27_7/__init__.py b/src/swig-0_27_7/__init__.py index 62863e2..7374b9e 100644 --- a/src/swig-0_27_7/__init__.py +++ b/src/swig-0_27_7/__init__.py @@ -20,9 +20,9 @@ def __init__(self, code, message): self.message = message #: python-exiv2 version as a string -__version__ = "0.17.0" +__version__ = "0.17.1" #: python-exiv2 version as a tuple of ints -__version_tuple__ = tuple((0, 17, 0)) +__version_tuple__ = tuple((0, 17, 1)) __all__ = ["Exiv2Error"] from exiv2.basicio import * diff --git a/src/swig-0_27_7/basicio_wrap.cxx b/src/swig-0_27_7/basicio_wrap.cxx index bf85abe..cbf13b9 100644 --- a/src/swig-0_27_7/basicio_wrap.cxx +++ b/src/swig-0_27_7/basicio_wrap.cxx @@ -4200,38 +4200,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else + return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4239,7 +4250,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4253,6 +4265,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); @@ -5524,8 +5539,10 @@ SWIGINTERN PyObject *_wrap_BasicIo_path(PyObject *self, PyObject *args) { result = ((Exiv2::BasicIo const *)arg1)->path(); { #ifdef _WIN32 - if (utf8_to_wcp(&result, false) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode result"); + int error = wcp_to_utf8(&result); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif resultobj = SWIG_FromCharPtrAndSize((&result)->data(), (&result)->size()); diff --git a/src/swig-0_27_7/datasets_wrap.cxx b/src/swig-0_27_7/datasets_wrap.cxx index edf06ad..0d6a612 100644 --- a/src/swig-0_27_7/datasets_wrap.cxx +++ b/src/swig-0_27_7/datasets_wrap.cxx @@ -4222,38 +4222,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4261,7 +4272,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4275,6 +4287,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); diff --git a/src/swig-0_27_7/easyaccess_wrap.cxx b/src/swig-0_27_7/easyaccess_wrap.cxx index 076fb40..cf47c97 100644 --- a/src/swig-0_27_7/easyaccess_wrap.cxx +++ b/src/swig-0_27_7/easyaccess_wrap.cxx @@ -4178,38 +4178,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4217,7 +4228,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4231,6 +4243,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); diff --git a/src/swig-0_27_7/error_wrap.cxx b/src/swig-0_27_7/error_wrap.cxx index 28ae65b..5f6b91b 100644 --- a/src/swig-0_27_7/error_wrap.cxx +++ b/src/swig-0_27_7/error_wrap.cxx @@ -4149,48 +4149,60 @@ static PyObject* exiv2_module = NULL; #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; +#endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else + return 0; #endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else return 0; +#endif }; + static PyObject* logger = NULL; static void log_to_python(int level, const char* msg) { std::string copy = msg; - utf8_to_wcp(©, false); + if (wcp_to_utf8(©)) + copy = msg; Py_ssize_t len = copy.size(); while (len > 0 && copy[len-1] == '\n') len--; PyGILState_STATE gstate = PyGILState_Ensure(); PyObject* res = PyObject_CallMethod( - logger, "log", "(is#)", (level + 1) * 10, copy.c_str(), len); + logger, "log", "(is#)", (level + 1) * 10, copy.data(), len); Py_XDECREF(res); PyGILState_Release(gstate); }; diff --git a/src/swig-0_27_7/exif_wrap.cxx b/src/swig-0_27_7/exif_wrap.cxx index 058a6bb..5e93c16 100644 --- a/src/swig-0_27_7/exif_wrap.cxx +++ b/src/swig-0_27_7/exif_wrap.cxx @@ -4238,38 +4238,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; +#endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else + return 0; #endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4277,7 +4288,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4291,6 +4303,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); @@ -8651,8 +8666,10 @@ SWIGINTERN PyObject *_wrap_ExifThumbC_writeFile(PyObject *self, PyObject *args) } { #ifdef _WIN32 - if (utf8_to_wcp(arg2, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg2); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } @@ -8865,8 +8882,10 @@ SWIGINTERN PyObject *_wrap_ExifThumb_setJpegThumbnail__SWIG_0(PyObject *self, Py arg5 = static_cast< uint16_t >(val5); { #ifdef _WIN32 - if (utf8_to_wcp(arg2, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg2); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } @@ -9000,8 +9019,10 @@ SWIGINTERN PyObject *_wrap_ExifThumb_setJpegThumbnail__SWIG_2(PyObject *self, Py } { #ifdef _WIN32 - if (utf8_to_wcp(arg2, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg2); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } diff --git a/src/swig-0_27_7/image_wrap.cxx b/src/swig-0_27_7/image_wrap.cxx index 3fc7b44..ad8f2f6 100644 --- a/src/swig-0_27_7/image_wrap.cxx +++ b/src/swig-0_27_7/image_wrap.cxx @@ -4251,37 +4251,48 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif }; +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif +}; + + static void _set_python_exception() { try { @@ -4290,7 +4301,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4304,6 +4316,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); @@ -6342,8 +6357,10 @@ SWIGINTERN PyObject *_wrap_ImageFactory_createIo__SWIG_0(PyObject *self, Py_ssiz } { #ifdef _WIN32 - if (utf8_to_wcp(arg1, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg1); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } @@ -6400,8 +6417,10 @@ SWIGINTERN PyObject *_wrap_ImageFactory_open__SWIG_0(PyObject *self, Py_ssize_t } { #ifdef _WIN32 - if (utf8_to_wcp(arg1, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg1); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } @@ -6550,8 +6569,10 @@ SWIGINTERN PyObject *_wrap_ImageFactory_create__SWIG_0(PyObject *self, Py_ssize_ } { #ifdef _WIN32 - if (utf8_to_wcp(arg2, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg2); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } @@ -6669,8 +6690,10 @@ SWIGINTERN PyObject *_wrap_ImageFactory_getType__SWIG_0(PyObject *self, Py_ssize } { #ifdef _WIN32 - if (utf8_to_wcp(arg1, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg1); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } diff --git a/src/swig-0_27_7/iptc_wrap.cxx b/src/swig-0_27_7/iptc_wrap.cxx index 80e9027..afce7de 100644 --- a/src/swig-0_27_7/iptc_wrap.cxx +++ b/src/swig-0_27_7/iptc_wrap.cxx @@ -4236,38 +4236,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4275,7 +4286,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4289,6 +4301,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); diff --git a/src/swig-0_27_7/metadatum_wrap.cxx b/src/swig-0_27_7/metadatum_wrap.cxx index 2c6c1a1..edd8a60 100644 --- a/src/swig-0_27_7/metadatum_wrap.cxx +++ b/src/swig-0_27_7/metadatum_wrap.cxx @@ -4222,38 +4222,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4261,7 +4272,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4275,6 +4287,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); diff --git a/src/swig-0_27_7/preview_wrap.cxx b/src/swig-0_27_7/preview_wrap.cxx index d4e0f00..45be809 100644 --- a/src/swig-0_27_7/preview_wrap.cxx +++ b/src/swig-0_27_7/preview_wrap.cxx @@ -4406,38 +4406,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4445,7 +4456,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4459,6 +4471,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); @@ -6388,8 +6403,10 @@ SWIGINTERN PyObject *_wrap_PreviewImage_writeFile(PyObject *self, PyObject *args } { #ifdef _WIN32 - if (utf8_to_wcp(arg2, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg2); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } @@ -6452,8 +6469,10 @@ SWIGINTERN PyObject *_wrap_PreviewImage_extension(PyObject *self, PyObject *args result = ((Exiv2::PreviewImage const *)arg1)->extension(); { #ifdef _WIN32 - if (utf8_to_wcp(&result, false) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode result"); + int error = wcp_to_utf8(&result); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif resultobj = SWIG_FromCharPtrAndSize((&result)->data(), (&result)->size()); diff --git a/src/swig-0_27_7/properties_wrap.cxx b/src/swig-0_27_7/properties_wrap.cxx index b65e1c6..10c36ab 100644 --- a/src/swig-0_27_7/properties_wrap.cxx +++ b/src/swig-0_27_7/properties_wrap.cxx @@ -4224,38 +4224,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4263,7 +4274,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4277,6 +4289,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); diff --git a/src/swig-0_27_7/tags_wrap.cxx b/src/swig-0_27_7/tags_wrap.cxx index d06a3f5..6e7c83f 100644 --- a/src/swig-0_27_7/tags_wrap.cxx +++ b/src/swig-0_27_7/tags_wrap.cxx @@ -4224,38 +4224,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4263,7 +4274,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4277,6 +4289,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); diff --git a/src/swig-0_27_7/types_wrap.cxx b/src/swig-0_27_7/types_wrap.cxx index 092f875..2cb304d 100644 --- a/src/swig-0_27_7/types_wrap.cxx +++ b/src/swig-0_27_7/types_wrap.cxx @@ -4210,38 +4210,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4249,7 +4260,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4263,6 +4275,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); diff --git a/src/swig-0_27_7/value_wrap.cxx b/src/swig-0_27_7/value_wrap.cxx index bcf0f5e..46325b8 100644 --- a/src/swig-0_27_7/value_wrap.cxx +++ b/src/swig-0_27_7/value_wrap.cxx @@ -4394,38 +4394,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4433,7 +4444,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4447,6 +4459,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); diff --git a/src/swig-0_27_7/version_wrap.cxx b/src/swig-0_27_7/version_wrap.cxx index f5f35ef..07a0a57 100644 --- a/src/swig-0_27_7/version_wrap.cxx +++ b/src/swig-0_27_7/version_wrap.cxx @@ -4190,38 +4190,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4229,7 +4240,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4243,6 +4255,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); diff --git a/src/swig-0_27_7/xmp_wrap.cxx b/src/swig-0_27_7/xmp_wrap.cxx index d1bd1e2..3714cdb 100644 --- a/src/swig-0_27_7/xmp_wrap.cxx +++ b/src/swig-0_27_7/xmp_wrap.cxx @@ -4238,38 +4238,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4277,7 +4288,8 @@ static void _set_python_exception() { catch(Exiv2::AnyError const& e) { std::string msg = e.what(); - utf8_to_wcp(&msg, false); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); @@ -4291,6 +4303,9 @@ static void _set_python_exception() { + + + /*@SWIG:/usr/local/share/swig/4.2.1/typemaps/exception.swg,59,SWIG_CATCH_STDEXCEPT@*/ /* catching std::exception */ catch (std::invalid_argument& e) { SWIG_exception_fail(SWIG_ValueError, e.what() ); diff --git a/src/swig-0_28_3/__init__.py b/src/swig-0_28_3/__init__.py index 62863e2..7374b9e 100644 --- a/src/swig-0_28_3/__init__.py +++ b/src/swig-0_28_3/__init__.py @@ -20,9 +20,9 @@ def __init__(self, code, message): self.message = message #: python-exiv2 version as a string -__version__ = "0.17.0" +__version__ = "0.17.1" #: python-exiv2 version as a tuple of ints -__version_tuple__ = tuple((0, 17, 0)) +__version_tuple__ = tuple((0, 17, 1)) __all__ = ["Exiv2Error"] from exiv2.basicio import * diff --git a/src/swig-0_28_3/basicio_wrap.cxx b/src/swig-0_28_3/basicio_wrap.cxx index 2b2ed8a..c5a2c59 100644 --- a/src/swig-0_28_3/basicio_wrap.cxx +++ b/src/swig-0_28_3/basicio_wrap.cxx @@ -4201,38 +4201,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; +#endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else + return 0; #endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4247,9 +4258,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } @@ -5792,8 +5807,10 @@ SWIGINTERN PyObject *_wrap_BasicIo_path(PyObject *self, PyObject *args) { { std::string copy = *result; #ifdef _WIN32 - if (utf8_to_wcp(©, false) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode result"); + int error = wcp_to_utf8(©); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif resultobj = SWIG_FromCharPtrAndSize(copy.data(), copy.size()); diff --git a/src/swig-0_28_3/datasets_wrap.cxx b/src/swig-0_28_3/datasets_wrap.cxx index 0f8e68a..c1c7432 100644 --- a/src/swig-0_28_3/datasets_wrap.cxx +++ b/src/swig-0_28_3/datasets_wrap.cxx @@ -4222,37 +4222,48 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif }; +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif +}; + + static void _set_python_exception() { try { @@ -4268,9 +4279,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } diff --git a/src/swig-0_28_3/easyaccess_wrap.cxx b/src/swig-0_28_3/easyaccess_wrap.cxx index dc975d7..aa1cc6c 100644 --- a/src/swig-0_28_3/easyaccess_wrap.cxx +++ b/src/swig-0_28_3/easyaccess_wrap.cxx @@ -4178,37 +4178,48 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif }; +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif +}; + + static void _set_python_exception() { try { @@ -4224,9 +4235,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } diff --git a/src/swig-0_28_3/error_wrap.cxx b/src/swig-0_28_3/error_wrap.cxx index bb7c132..af2bb1e 100644 --- a/src/swig-0_28_3/error_wrap.cxx +++ b/src/swig-0_28_3/error_wrap.cxx @@ -4149,48 +4149,60 @@ static PyObject* exiv2_module = NULL; #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; +#endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else + return 0; #endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else return 0; +#endif }; + static PyObject* logger = NULL; static void log_to_python(int level, const char* msg) { std::string copy = msg; - utf8_to_wcp(©, false); + if (wcp_to_utf8(©)) + copy = msg; Py_ssize_t len = copy.size(); while (len > 0 && copy[len-1] == '\n') len--; PyGILState_STATE gstate = PyGILState_Ensure(); PyObject* res = PyObject_CallMethod( - logger, "log", "(is#)", (level + 1) * 10, copy.c_str(), len); + logger, "log", "(is#)", (level + 1) * 10, copy.data(), len); Py_XDECREF(res); PyGILState_Release(gstate); }; diff --git a/src/swig-0_28_3/exif_wrap.cxx b/src/swig-0_28_3/exif_wrap.cxx index a371413..b5b028e 100644 --- a/src/swig-0_28_3/exif_wrap.cxx +++ b/src/swig-0_28_3/exif_wrap.cxx @@ -4238,38 +4238,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else + return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4284,9 +4295,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } @@ -8855,8 +8870,10 @@ SWIGINTERN PyObject *_wrap_ExifThumbC_writeFile(PyObject *self, PyObject *args) } { #ifdef _WIN32 - if (utf8_to_wcp(arg2, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg2); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } @@ -9069,8 +9086,10 @@ SWIGINTERN PyObject *_wrap_ExifThumb_setJpegThumbnail__SWIG_0(PyObject *self, Py arg5 = static_cast< uint16_t >(val5); { #ifdef _WIN32 - if (utf8_to_wcp(arg2, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg2); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } @@ -9204,8 +9223,10 @@ SWIGINTERN PyObject *_wrap_ExifThumb_setJpegThumbnail__SWIG_2(PyObject *self, Py } { #ifdef _WIN32 - if (utf8_to_wcp(arg2, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg2); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } diff --git a/src/swig-0_28_3/image_wrap.cxx b/src/swig-0_28_3/image_wrap.cxx index 85ebfa7..cb8eb05 100644 --- a/src/swig-0_28_3/image_wrap.cxx +++ b/src/swig-0_28_3/image_wrap.cxx @@ -4251,38 +4251,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4297,9 +4308,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } @@ -6342,8 +6357,10 @@ SWIGINTERN PyObject *_wrap_ImageFactory_createIo__SWIG_0(PyObject *self, Py_ssiz } { #ifdef _WIN32 - if (utf8_to_wcp(arg1, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg1); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } @@ -6400,8 +6417,10 @@ SWIGINTERN PyObject *_wrap_ImageFactory_open__SWIG_0(PyObject *self, Py_ssize_t } { #ifdef _WIN32 - if (utf8_to_wcp(arg1, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg1); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } @@ -6550,8 +6569,10 @@ SWIGINTERN PyObject *_wrap_ImageFactory_create__SWIG_0(PyObject *self, Py_ssize_ } { #ifdef _WIN32 - if (utf8_to_wcp(arg2, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg2); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } @@ -6673,8 +6694,10 @@ SWIGINTERN PyObject *_wrap_ImageFactory_getType__SWIG_0(PyObject *self, Py_ssize } { #ifdef _WIN32 - if (utf8_to_wcp(arg1, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg1); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } diff --git a/src/swig-0_28_3/iptc_wrap.cxx b/src/swig-0_28_3/iptc_wrap.cxx index 266c64a..015f806 100644 --- a/src/swig-0_28_3/iptc_wrap.cxx +++ b/src/swig-0_28_3/iptc_wrap.cxx @@ -4236,37 +4236,48 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif }; +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif +}; + + static void _set_python_exception() { try { @@ -4282,9 +4293,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } diff --git a/src/swig-0_28_3/metadatum_wrap.cxx b/src/swig-0_28_3/metadatum_wrap.cxx index 0ac3197..22d2124 100644 --- a/src/swig-0_28_3/metadatum_wrap.cxx +++ b/src/swig-0_28_3/metadatum_wrap.cxx @@ -4222,37 +4222,48 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif }; +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif +}; + + static void _set_python_exception() { try { @@ -4268,9 +4279,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } diff --git a/src/swig-0_28_3/preview_wrap.cxx b/src/swig-0_28_3/preview_wrap.cxx index a54273c..d7bc1b4 100644 --- a/src/swig-0_28_3/preview_wrap.cxx +++ b/src/swig-0_28_3/preview_wrap.cxx @@ -4406,38 +4406,49 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif +}; + +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif }; + static void _set_python_exception() { try { throw; @@ -4452,9 +4463,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } @@ -6388,8 +6403,10 @@ SWIGINTERN PyObject *_wrap_PreviewImage_writeFile(PyObject *self, PyObject *args } { #ifdef _WIN32 - if (utf8_to_wcp(arg2, true) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode path"); + int error = utf8_to_wcp(arg2); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif } @@ -6452,8 +6469,10 @@ SWIGINTERN PyObject *_wrap_PreviewImage_extension(PyObject *self, PyObject *args result = ((Exiv2::PreviewImage const *)arg1)->extension(); { #ifdef _WIN32 - if (utf8_to_wcp(&result, false) < 0) { - SWIG_exception_fail(SWIG_ValueError, "failed to transcode result"); + int error = wcp_to_utf8(&result); + if (error) { + PyErr_SetFromWindowsErr(error); + SWIG_fail; } #endif resultobj = SWIG_FromCharPtrAndSize((&result)->data(), (&result)->size()); diff --git a/src/swig-0_28_3/properties_wrap.cxx b/src/swig-0_28_3/properties_wrap.cxx index b5b85d4..15b0aba 100644 --- a/src/swig-0_28_3/properties_wrap.cxx +++ b/src/swig-0_28_3/properties_wrap.cxx @@ -4224,37 +4224,48 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif }; +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif +}; + + static void _set_python_exception() { try { @@ -4270,9 +4281,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } diff --git a/src/swig-0_28_3/tags_wrap.cxx b/src/swig-0_28_3/tags_wrap.cxx index c34aa9e..75b5a03 100644 --- a/src/swig-0_28_3/tags_wrap.cxx +++ b/src/swig-0_28_3/tags_wrap.cxx @@ -4224,37 +4224,48 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif }; +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif +}; + + static void _set_python_exception() { try { @@ -4270,9 +4281,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } diff --git a/src/swig-0_28_3/types_wrap.cxx b/src/swig-0_28_3/types_wrap.cxx index 7569ad2..3000c42 100644 --- a/src/swig-0_28_3/types_wrap.cxx +++ b/src/swig-0_28_3/types_wrap.cxx @@ -4210,37 +4210,48 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif }; +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif +}; + + static void _set_python_exception() { try { @@ -4256,9 +4267,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } diff --git a/src/swig-0_28_3/value_wrap.cxx b/src/swig-0_28_3/value_wrap.cxx index 9afc3fc..66cc558 100644 --- a/src/swig-0_28_3/value_wrap.cxx +++ b/src/swig-0_28_3/value_wrap.cxx @@ -4394,37 +4394,48 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif }; +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif +}; + + static void _set_python_exception() { try { @@ -4440,9 +4451,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } diff --git a/src/swig-0_28_3/version_wrap.cxx b/src/swig-0_28_3/version_wrap.cxx index c13df2f..bd3a784 100644 --- a/src/swig-0_28_3/version_wrap.cxx +++ b/src/swig-0_28_3/version_wrap.cxx @@ -4190,37 +4190,48 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif }; +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif +}; + + static void _set_python_exception() { try { @@ -4236,9 +4247,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } diff --git a/src/swig-0_28_3/xmp_wrap.cxx b/src/swig-0_28_3/xmp_wrap.cxx index e344c9d..36bed8e 100644 --- a/src/swig-0_28_3/xmp_wrap.cxx +++ b/src/swig-0_28_3/xmp_wrap.cxx @@ -4238,37 +4238,48 @@ static PyObject* py_from_enum(Exiv2::ErrorCode value) { #include #endif -static int utf8_to_wcp(std::string *str, bool to_cp) { #ifdef _WIN32 - UINT cp_in = CP_UTF8; - UINT cp_out = GetACP(); +static int _transcode(std::string *str, UINT cp_in, UINT cp_out) { if (cp_out == cp_in) return 0; - if (!to_cp) { - cp_in = cp_out; - cp_out = CP_UTF8; - } int size = MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), NULL, 0); if (!size) - return -1; + return GetLastError(); std::wstring wide_str; wide_str.resize(size); if (!MultiByteToWideChar(cp_in, 0, &(*str)[0], (int)str->size(), &wide_str[0], size)) - return -1; + return GetLastError(); size = WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), NULL, 0, NULL, NULL); if (!size) - return -1; + return GetLastError(); str->resize(size); if (!WideCharToMultiByte(cp_out, 0, &wide_str[0], (int)wide_str.size(), &(*str)[0], size, NULL, NULL)) - return -1; + return GetLastError(); + return 0; +}; #endif + +static int utf8_to_wcp(std::string *str) { +#ifdef _WIN32 + return _transcode(str, CP_UTF8, GetACP()); +#else return 0; +#endif }; +static int wcp_to_utf8(std::string *str) { +#ifdef _WIN32 + return _transcode(str, GetACP(), CP_UTF8); +#else + return 0; +#endif +}; + + static void _set_python_exception() { try { @@ -4284,9 +4295,13 @@ static void _set_python_exception() { + catch(Exiv2::Error const& e) { + std::string msg = e.what(); + if (wcp_to_utf8(&msg)) + msg = e.what(); PyObject* args = Py_BuildValue( - "Ns", py_from_enum(e.code()), e.what()); + "Ns", py_from_enum((Exiv2::ErrorCode)e.code()), msg.c_str()); PyErr_SetObject(PyExc_Exiv2Error, args); Py_DECREF(args); } diff --git a/tests/test_types.py b/tests/test_types.py index 8fc69da..1e0a36e 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -138,9 +138,9 @@ def test_localisation(self): self.assertEqual(cm.output, [ 'WARNING:exiv2:Ungültiger Zeichensatz: "invalid"']) with self.assertRaises(exiv2.Exiv2Error) as cm: - image = exiv2.ImageFactory.open(bytes()) + key = exiv2.ExifKey('not.a.tag') self.assertEqual(cm.exception.message, - 'Die Eingabedaten konnten nicht gelesen werden.') + "Ungültiger Schlüssel 'not.a.tag'") # clear locale name = 'en_US.UTF-8' os.environ['LC_ALL'] = name