Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions mssql_python/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Enable verbose output to see actual compiler/linker commands
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Verbose output" FORCE)

# Treat CMake warnings as errors
set(CMAKE_ERROR_DEPRECATED TRUE)
set(CMAKE_WARN_DEPRECATED TRUE)

if (MSVC)
# Security compiler options for OneBranch compliance
message(STATUS "Applying MSVC security compiler options for OneBranch compliance")
Expand Down Expand Up @@ -302,6 +306,21 @@ if(MSVC)
target_compile_options(ddbc_bindings PRIVATE /W4 /WX)
endif()

# Add warning flags for GCC/Clang on Linux and macOS
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(ddbc_bindings PRIVATE
-Werror # Treat warnings as errors
-Wattributes # Enable attribute warnings (cross-compiler)
)

# GCC-specific warning flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(ddbc_bindings PRIVATE
-Wint-to-pointer-cast # GCC-specific warning for integer-to-pointer casts
)
endif()
endif()

# Add macOS-specific string conversion fix
if(APPLE)
message(STATUS "Enabling macOS string conversion fix")
Expand Down
16 changes: 13 additions & 3 deletions mssql_python/pybind/ddbc_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ py::object get_uuid_class() {

// Struct to hold parameter information for binding. Used by SQLBindParameter.
// This struct is shared between C++ & Python code.
// Suppress -Wattributes warning for ParamInfo struct
// The warning is triggered because pybind11 handles visibility attributes automatically,
// and having additional attributes on the struct can cause conflicts on Linux with GCC
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
#endif
struct ParamInfo {
SQLSMALLINT inputOutputType;
SQLSMALLINT paramCType;
Expand All @@ -124,6 +131,9 @@ struct ParamInfo {
bool isDAE = false; // Indicates if we need to stream
py::object dataPtr;
};
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

// Mirrors the SQL_NUMERIC_STRUCT. But redefined to replace val char array
// with std::string, because pybind doesn't allow binding char array.
Expand Down Expand Up @@ -713,23 +723,23 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params,
}
SQL_NUMERIC_STRUCT* numericPtr = reinterpret_cast<SQL_NUMERIC_STRUCT*>(dataPtr);
rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_PRECISION,
(SQLPOINTER)numericPtr->precision, 0);
reinterpret_cast<SQLPOINTER>(static_cast<uintptr_t>(numericPtr->precision)), 0);
if (!SQL_SUCCEEDED(rc)) {
LOG("BindParameters: SQLSetDescField(SQL_DESC_PRECISION) "
"failed for param[%d] - SQLRETURN=%d",
paramIndex, rc);
return rc;
}

rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_SCALE, (SQLPOINTER)numericPtr->scale, 0);
rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_SCALE, reinterpret_cast<SQLPOINTER>(static_cast<intptr_t>(numericPtr->scale)), 0);
if (!SQL_SUCCEEDED(rc)) {
LOG("BindParameters: SQLSetDescField(SQL_DESC_SCALE) failed "
"for param[%d] - SQLRETURN=%d",
paramIndex, rc);
return rc;
}

rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_DATA_PTR, (SQLPOINTER)numericPtr, 0);
rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_DATA_PTR, reinterpret_cast<SQLPOINTER>(numericPtr), 0);
if (!SQL_SUCCEEDED(rc)) {
LOG("BindParameters: SQLSetDescField(SQL_DESC_DATA_PTR) failed "
"for param[%d] - SQLRETURN=%d",
Expand Down
Loading