Skip to content

Commit 5a106b8

Browse files
committed
REFACTOR: keep Python 3.15 support scoped
Remove the native-hardening and auth-test changes owned by PR #810, retaining only the Python 3.15 header-order compatibility flag and its focused contract.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e062c6d commit 5a106b8

4 files changed

Lines changed: 10 additions & 246 deletions

File tree

‎mssql_python/pybind/CMakeLists.txt‎

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,6 @@ endif()
255255

256256
message(STATUS "Final Python library directory: ${PYTHON_LIB_DIR}")
257257

258-
# Single-config POSIX generators ignore `cmake --build --config Release`.
259-
# Make the optimized release mode explicit instead of relying on simdutf to
260-
# populate this project-wide cache variable as a FetchContent side effect.
261-
if(UNIX AND NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
262-
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
263-
endif()
264-
265258
include(FetchContent)
266259
message(STATUS "Downloading simdutf v8.2.0 source archive with FetchContent")
267260
set(simdutf_fetchcontent_args
@@ -394,45 +387,10 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang
394387
endif()
395388
endif()
396389

397-
# Harden the Python extension against exploitation of a separate memory-safety
398-
# defect. Mach-O receives stack protection; ELF-specific flags stay Linux-only.
390+
# Python 3.15 defines newer POSIX feature levels than glibc's C++ headers.
391+
# Process Python.h first so libc sees the matching feature-test macros.
399392
if(UNIX)
400-
# Python 3.15 defines newer POSIX feature levels than glibc's C++ headers.
401-
# Force Python.h to be processed first in every translation unit.
402-
target_compile_options(ddbc_bindings PRIVATE
403-
-include Python.h
404-
-fstack-protector-strong
405-
)
406-
endif()
407-
408-
if(UNIX AND NOT APPLE)
409-
include(CheckCXXSourceCompiles)
410-
set(DDBC_REQUIRED_FLAGS_SAVED "${CMAKE_REQUIRED_FLAGS}")
411-
set(CMAKE_REQUIRED_FLAGS
412-
"${CMAKE_REQUIRED_FLAGS} -O2 -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"
413-
)
414-
check_cxx_source_compiles("
415-
#include <features.h>
416-
#if !defined(__USE_FORTIFY_LEVEL) || __USE_FORTIFY_LEVEL < 3
417-
#error _FORTIFY_SOURCE=3 is unavailable
418-
#endif
419-
int main() { return 0; }
420-
" DDBC_SUPPORTS_FORTIFY_SOURCE_3)
421-
set(CMAKE_REQUIRED_FLAGS "${DDBC_REQUIRED_FLAGS_SAVED}")
422-
if(DDBC_SUPPORTS_FORTIFY_SOURCE_3)
423-
set(DDBC_FORTIFY_LEVEL 3)
424-
else()
425-
set(DDBC_FORTIFY_LEVEL 2)
426-
endif()
427-
target_compile_options(ddbc_bindings PRIVATE
428-
$<$<NOT:$<CONFIG:Debug>>:-U_FORTIFY_SOURCE>
429-
$<$<NOT:$<CONFIG:Debug>>:-D_FORTIFY_SOURCE=${DDBC_FORTIFY_LEVEL}>
430-
)
431-
target_link_options(ddbc_bindings PRIVATE
432-
-Wl,-z,relro
433-
-Wl,-z,now
434-
-Wl,-z,noexecstack
435-
)
393+
target_compile_options(ddbc_bindings PRIVATE -include Python.h)
436394
endif()
437395

438396
# Add macOS-specific string conversion fix

‎tests/test_008_auth.py‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,13 +1554,7 @@ def test_multiple_connections_share_same_token_provider(self, mock_ddbc_conn):
15541554
@patch("mssql_python.connection.ddbc_bindings.Connection")
15551555
def test_concurrent_connections_with_same_token_provider(self, mock_ddbc_conn):
15561556
"""Concurrent connect() calls with one token provider should succeed."""
1557-
1558-
def create_native_connection(*_args, **_kwargs):
1559-
native_connection = MagicMock()
1560-
native_connection.get_autocommit.return_value = True
1561-
return native_connection
1562-
1563-
mock_ddbc_conn.side_effect = create_native_connection
1557+
mock_ddbc_conn.return_value = MagicMock()
15641558
mock_cred = MagicMock()
15651559
mock_cred.get_token.return_value = MagicMock(token=SAMPLE_TOKEN)
15661560
from mssql_python import connect

‎tests/test_038_mssql_odbc_daily_validation.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
PR_PIPELINE = ROOT / "eng" / "pipelines" / "pr-validation-pipeline.yml"
1616
PREFLIGHT = ROOT / "eng" / "scripts" / "verify_mssql_odbc_provider.py"
1717
RELEASE_PIPELINE = ROOT / "OneBranchPipelines" / "stages" / "build-linux-single-stage.yml"
18+
PYBIND_CMAKE = ROOT / "mssql_python" / "pybind" / "CMakeLists.txt"
1819

1920

2021
@unittest.skipUnless(sys.platform.startswith("linux"), "runner requires Linux GNU timeout and bash")
@@ -188,6 +189,11 @@ def test_python_315_validation_installs_stable_pyarrow(self):
188189
self.assertIn('pyarrow==26.0.0; python_version >= "3.15"', requirements)
189190
self.assertNotIn("scientific-python-nightly-wheels", requirements)
190191

192+
def test_python_315_processes_python_header_before_libc_headers(self):
193+
cmake = PYBIND_CMAKE.read_text(encoding="utf-8")
194+
195+
self.assertIn("target_compile_options(ddbc_bindings PRIVATE -include Python.h)", cmake)
196+
191197

192198
if __name__ == "__main__":
193199
unittest.main()

‎tests/test_040_native_binary_hardening.py‎

Lines changed: 0 additions & 194 deletions
This file was deleted.

0 commit comments

Comments
 (0)