Compare commits

...

4 Commits

Author SHA1 Message Date
Ken Matsui
bd66fa4f55
Remove path from COMPILER_COMMAND (#1590) 2023-05-09 19:24:00 +08:00
Nitromelon
5baca75359
Bugfix: PgBatchConnection did not report error message. (#1588) 2023-05-09 19:20:23 +08:00
An Tao
29984f26e0
Revert modifications to the type of clientMaxBodySize (#1596) 2023-05-09 19:18:10 +08:00
Sqeaky
fddbc0abb7
Update SqlBinder.h (#1595)
On a fully updated Rasperry Pi OS using Raspberry Pi OS 2023-05-03 Drogon built fine, but a project linking to/including drogon would fail to build with `/usr/local/include/drogon/orm/SqlBinder.h:70:1: error: body of ‘constexpr’ function ‘constexpr T htonT(T) [with T = long unsigned int]’ not a return-statement 70 | }`.

Compiler details:
    $ gcc -v
    Using built-in specs.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/10/lto-wrapper
    Target: aarch64-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Debian 10.2.1-6' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-mutex
    Thread model: posix
    Supported LTO compression algorithms: zlib zstd
    gcc version 10.2.1 20210110 (Debian 10.2.1-6)

This is a proposed fix for this issue that adjusts this function to be a pair of IFDEFed return statements based on network byte order as the original function appeared to intend. This makes it so the function body is entirely a single return statement on each platform. 

The error message from the C++17 compiler (which is the latest version supported on Raspberry Pi OS currently) indicates that constexpr functions must be entirely single return statements.
2023-05-09 17:23:47 +08:00
7 changed files with 35 additions and 29 deletions

View File

@ -631,7 +631,7 @@ if (pg_FOUND OR DROGON_FOUND_MYSQL OR DROGON_FOUND_SQLite3)
endif (DROGON_FOUND_SQLite3)
endif (pg_FOUND OR DROGON_FOUND_MYSQL OR DROGON_FOUND_SQLite3)
set(COMPILER_COMMAND ${CMAKE_CXX_COMPILER})
get_filename_component(COMPILER_COMMAND ${CMAKE_CXX_COMPILER} NAME)
set(COMPILER_ID ${CMAKE_CXX_COMPILER_ID})
if (CMAKE_BUILD_TYPE)

View File

@ -356,7 +356,7 @@ class HttpAppFrameworkImpl final : public HttpAppFramework
}
HttpAppFramework &setGzipStatic(bool useGzipStatic) override;
HttpAppFramework &setBrStatic(bool useGzipStatic) override;
HttpAppFramework &setClientMaxBodySize(uint64_t maxSize) override
HttpAppFramework &setClientMaxBodySize(size_t maxSize) override
{
clientMaxBodySize_ = maxSize;
return *this;
@ -405,7 +405,7 @@ class HttpAppFrameworkImpl final : public HttpAppFramework
HttpAppFramework &setImplicitPage(
const std::string &implicitPageFile) override;
const std::string &getImplicitPage() const override;
uint64_t getClientMaxBodySize() const
size_t getClientMaxBodySize() const
{
return clientMaxBodySize_;
}
@ -686,7 +686,7 @@ class HttpAppFrameworkImpl final : public HttpAppFramework
std::pair<unsigned int, std::string> floatPrecisionInJson_{0,
"significant"};
bool usingCustomErrorHandler_{false};
uint64_t clientMaxBodySize_{1024 * 1024};
size_t clientMaxBodySize_{1024 * 1024};
size_t clientMaxMemoryBodySize_{64 * 1024};
size_t clientMaxWebSocketMessageSize_{128 * 1024};
std::string homePageFile_{"index.html"};

View File

@ -200,11 +200,6 @@ void *SharedLibManager::compileAndLoadLib(const std::string &sourceFile,
{
LOG_TRACE << "src:" << sourceFile;
std::string cmd = COMPILER_COMMAND;
auto pos = cmd.rfind('/');
if (pos != std::string::npos)
{
cmd = cmd.substr(pos + 1);
}
cmd.append(" ")
.append(sourceFile)
.append(" ")
@ -215,7 +210,7 @@ void *SharedLibManager::compileAndLoadLib(const std::string &sourceFile,
cmd.append(" -shared -fPIC -undefined dynamic_lookup -o ");
else
cmd.append(" -shared -fPIC --no-gnu-unique -o ");
pos = sourceFile.rfind('.');
auto pos = sourceFile.rfind('.');
auto soFile = sourceFile.substr(0, pos);
soFile.append(".so");
cmd.append(soFile);

View File

@ -63,10 +63,12 @@ template <typename T>
constexpr T htonT(T value) noexcept
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
char *ptr = reinterpret_cast<char *>(&value);
std::reverse(ptr, ptr + sizeof(T));
#endif
return (std::reverse(reinterpret_cast<char *>(&value),
reinterpret_cast<char *>(&value) + sizeof(T)),
value);
#else
return value;
#endif
}
inline uint64_t htonll(uint64_t value)
{

View File

@ -441,7 +441,7 @@ void PgConnection::handleRead()
if (type == PGRES_BAD_RESPONSE || type == PGRES_FATAL_ERROR ||
type == PGRES_PIPELINE_ABORTED)
{
handleFatalError(false);
handleFatalError(false, type == PGRES_PIPELINE_ABORTED);
continue;
}
if (type == PGRES_PIPELINE_SYNC)
@ -493,11 +493,14 @@ void PgConnection::doAfterPreparing()
{
}
void PgConnection::handleFatalError(bool clearAll)
void PgConnection::handleFatalError(bool clearAll, bool isAbortPipeline)
{
LOG_ERROR << PQerrorMessage(connectionPtr_.get());
auto exceptPtr =
std::make_exception_ptr(Failure(PQerrorMessage(connectionPtr_.get())));
std::string errmsg =
isAbortPipeline
? "Command didn't run because of an abort earlier in a pipeline"
: PQerrorMessage(connectionPtr_.get());
LOG_ERROR << errmsg;
auto exceptPtr = std::make_exception_ptr(Failure(errmsg));
if (clearAll)
{
for (auto &cmd : batchCommandsForWaitingResults_)
@ -522,19 +525,13 @@ void PgConnection::handleFatalError(bool clearAll)
else if (!batchCommandsForWaitingResults_.empty())
{
auto &cmd = batchCommandsForWaitingResults_.front();
if (!cmd->preparingStatement_.empty())
{
cmd->preparingStatement_.clear();
}
else
{
cmd->exceptionCallback_(exceptPtr);
batchCommandsForWaitingResults_.pop_front();
}
cmd->exceptionCallback_(exceptPtr);
batchCommandsForWaitingResults_.pop_front();
}
else
{
assert(false);
// PQsendPrepare failed, error message has already been reported
// Ignore PQsendQueryPrepared failure
}
}
}

View File

@ -132,7 +132,7 @@ class PgConnection : public DbConnection,
std::set<std::string> preparedStatements_;
string_view sql_;
#if LIBPQ_SUPPORTS_BATCH_MODE
void handleFatalError(bool clearAll);
void handleFatalError(bool clearAll, bool isAbortPipeline = false);
std::list<std::shared_ptr<SqlCmd>> batchCommandsForWaitingResults_;
std::deque<std::shared_ptr<SqlCmd>> batchSqlCommands_;
void sendBatchedSql();

View File

@ -44,6 +44,18 @@ DbClientPtr postgreClient;
DROGON_TEST(PostgreTest)
{
auto &clientPtr = postgreClient;
// Test bugfix #1588
// PgBatchConnection.cc did not report error message to application
try
{
clientPtr->execSqlSync("select * from t_not_exists");
}
catch (const DrogonDbException &e)
{
MANDATE(!std::string{e.base().what()}.empty());
}
// Prepare the test environment
*clientPtr << "DROP TABLE IF EXISTS USERS" >> [TEST_CTX,
clientPtr](const Result &r) {