diff --git a/NEWS b/NEWS index 0faf410e..d0a77df1 100644 --- a/NEWS +++ b/NEWS @@ -43,6 +43,7 @@ Noteworthy changes in version 1.24.0 (unrelease) cpp: Key::numRevocationKeys NEW. cpp: Key::revocationKeys NEW. cpp: Error::asStdString NEW. + cpp: Error::asString DEPRECATED. qt: DecryptVerifyJob::setInputFile NEW. qt: DecryptVerifyJob::inputFile NEW. qt: DecryptVerifyJob::setOutputFile NEW. diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp index 4882c80c..8150d08b 100644 --- a/lang/cpp/src/context.cpp +++ b/lang/cpp/src/context.cpp @@ -195,7 +195,7 @@ Error Error::fromCode(unsigned int err, unsigned int src) std::ostream &operator<<(std::ostream &os, const Error &err) { - return os << "GpgME::Error(" << err.encodedError() << " (" << err.asString() << "))"; + return os << "GpgME::Error(" << err.encodedError() << " (" << err.asStdString() << "))"; } Context::KeyListModeSaver::KeyListModeSaver(Context *ctx) diff --git a/lang/cpp/src/editinteractor.cpp b/lang/cpp/src/editinteractor.cpp index 72ed92f7..84ddf398 100644 --- a/lang/cpp/src/editinteractor.cpp +++ b/lang/cpp/src/editinteractor.cpp @@ -138,7 +138,7 @@ public: if (writeAll(fd, result, len) != len) { err = Error::fromSystemError(); if (ei->debug) { - std::fprintf(ei->debug, "EditInteractor: Could not write to fd %d (%s)\n", fd, err.asString()); + std::fprintf(ei->debug, "EditInteractor: Could not write to fd %d (%s)\n", fd, err.asStdString().c_str()); } goto error; } @@ -147,7 +147,7 @@ public: if (writeAll(fd, "\n", 1) != 1) { err = Error::fromSystemError(); if (ei->debug) { - std::fprintf(ei->debug, "EditInteractor: Could not write to fd %d (%s)\n", fd, err.asString()); + std::fprintf(ei->debug, "EditInteractor: Could not write to fd %d (%s)\n", fd, err.asStdString().c_str()); } goto error; } diff --git a/lang/cpp/src/error.h b/lang/cpp/src/error.h index bc970e36..000b562b 100644 --- a/lang/cpp/src/error.h +++ b/lang/cpp/src/error.h @@ -47,7 +47,10 @@ public: explicit Error(unsigned int e) : mErr(e), mMessage() {} const char *source() const; - const char *asString() const; + /* This function is deprecated. Use asStdString() instead. asString() may + * return wrongly encoded (i.e. not UTF-8) results on Windows for the main + * thread if the function was first called from a secondary thread. */ + GPGMEPP_DEPRECATED const char *asString() const; std::string asStdString() const; int code() const; diff --git a/lang/cpp/tests/run-getkey.cpp b/lang/cpp/tests/run-getkey.cpp index c47da0b5..97d863e1 100644 --- a/lang/cpp/tests/run-getkey.cpp +++ b/lang/cpp/tests/run-getkey.cpp @@ -150,7 +150,7 @@ main (int argc, char **argv) const GpgME::Key key = ctx->key (*argv, err, only_secret); std::stringstream ss; - ss << "Key " << key << " Err: " << err.asString() << "\n"; + ss << "Key " << key << " Err: " << err.asStdString() << "\n"; std::cout << ss.str(); diff --git a/lang/cpp/tests/run-keylist.cpp b/lang/cpp/tests/run-keylist.cpp index b46a815a..6581567c 100644 --- a/lang/cpp/tests/run-keylist.cpp +++ b/lang/cpp/tests/run-keylist.cpp @@ -153,7 +153,7 @@ main (int argc, char **argv) } Error err = ctx->startKeyListing (*argv, only_secret); if (err) { - std::cout << "Error: " << err.asString() << "\n"; + std::cout << "Error: " << err.asStdString() << "\n"; return -1; } GpgME::Key key; diff --git a/lang/cpp/tests/run-wkdlookup.cpp b/lang/cpp/tests/run-wkdlookup.cpp index 4a3966b0..1e18c9a8 100644 --- a/lang/cpp/tests/run-wkdlookup.cpp +++ b/lang/cpp/tests/run-wkdlookup.cpp @@ -75,31 +75,31 @@ main (int argc, char **argv) Error err; auto ctx = std::unique_ptr{Context::createForEngine(AssuanEngine, &err)}; if (!ctx) { - std::cerr << "Failed to get context (Error: " << err.asString() << ")\n"; + std::cerr << "Failed to get context (Error: " << err.asStdString() << ")\n"; return -1; } const std::string dirmngrSocket = GpgME::dirInfo("dirmngr-socket"); if ((err = ctx->setEngineFileName(dirmngrSocket.c_str()))) { - std::cerr << "Failed to set engine file name (Error: " << err.asString() << ")\n"; + std::cerr << "Failed to set engine file name (Error: " << err.asStdString() << ")\n"; return -1; } if ((err = ctx->setEngineHomeDirectory(""))) { - std::cerr << "Failed to set engine home directory (Error: " << err.asString() << ")\n"; + std::cerr << "Failed to set engine home directory (Error: " << err.asStdString() << ")\n"; return -1; } // try to connect to dirmngr err = ctx->assuanTransact("GETINFO version"); if (err && err.code() != GPG_ERR_ASS_CONNECT_FAILED) { - std::cerr << "Failed to start assuan transaction (Error: " << err.asString() << ")\n"; + std::cerr << "Failed to start assuan transaction (Error: " << err.asStdString() << ")\n"; return -1; } if (err.code() == GPG_ERR_ASS_CONNECT_FAILED) { std::cerr << "Starting dirmngr ...\n"; auto spawnCtx = std::unique_ptr{Context::createForEngine(SpawnEngine, &err)}; if (!spawnCtx) { - std::cerr << "Failed to get context for spawn engine (Error: " << err.asString() << ")\n"; + std::cerr << "Failed to get context for spawn engine (Error: " << err.asStdString() << ")\n"; return -1; } @@ -120,7 +120,7 @@ main (int argc, char **argv) ignoreIO, ignoreIO, ignoreIO, Context::SpawnDetached); if (err) { - std::cerr << "Failed to start dirmngr (Error: " << err.asString() << ")\n"; + std::cerr << "Failed to start dirmngr (Error: " << err.asStdString() << ")\n"; return -1; } @@ -137,7 +137,7 @@ main (int argc, char **argv) const auto cmd = std::string{"WKD_GET "} + email; err = ctx->assuanTransact(cmd.c_str()); if (err && err.code() != GPG_ERR_NO_NAME && err.code() != GPG_ERR_NO_DATA) { - std::cerr << "Error: WKD_GET returned " << err.asString() << "\n"; + std::cerr << "Error: WKD_GET returned " << err.asStdString() << "\n"; return -1; }