From e494b523557630637779fc0bbfd1ecbbee632012 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Fri, 31 Jul 2026 08:56:12 -0400 Subject: [PATCH 1/4] fix(atomic): make Windows/MSVC db build compile clean Two independent MSVC breaks in the Windows atomics path: 1. os_atomic.c's Windows Interlocked tier casts through interlocked_val (LONG volatile *) but that macro was only defined in mut_win32.c, so the type was undeclared in this TU -> C2065/C2064. Define it locally in the same self-contained way mut_win32.c does. 2. db.h's legacy unprefixed 4BSD dbm(3) aliases (store, fetch, firstkey, nextkey, dbminit, dbmclose, delete) are object/function-like macros. In a C++ translation unit (the cxx_*.cpp files in db.vcxproj) MSVC's is pulled in transitively and its std::atomic<>::store member collides with the 'store' macro -> C4003/C2059/C2039/C2086. These names are a C-only historic interface (delete was already guarded); guard the whole set with #if !defined(__cplusplus). Fixed in the template src/dbinc/db.in and regenerated build_windows/db.h via dist/s_windows. --- build_windows/db.h | 9 +++++++-- src/dbinc/db.in | 9 +++++++-- src/os/os_atomic.c | 9 +++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/build_windows/db.h b/build_windows/db.h index d421edc1d..ddf07507f 100644 --- a/build_windows/db.h +++ b/build_windows/db.h @@ -2809,16 +2809,21 @@ typedef struct { * * The global variables dbrdonly, dirf and pagf were not retained when 4BSD * replaced the dbm interface with ndbm, and are not supported here. + * + * These unprefixed 4BSD names (delete, fetch, firstkey, nextkey, store, ...) + * are C-only historic aliases: they collide with C++ keywords and standard + * library member names (e.g. std::atomic<>::store, which MSVC's + * pulls into any C++ translation unit). Suppress them for C++. */ +#if !defined(__cplusplus) #define dbminit(a) __db_dbm_init(a) #define dbmclose __db_dbm_close -#if !defined(__cplusplus) #define delete(a) __db_dbm_delete(a) -#endif #define fetch(a) __db_dbm_fetch(a) #define firstkey __db_dbm_firstkey #define nextkey(a) __db_dbm_nextkey(a) #define store(a, b) __db_dbm_store(a, b) +#endif /******************************************************* * Hsearch historic interface. diff --git a/src/dbinc/db.in b/src/dbinc/db.in index b8a24e623..e7a00974f 100644 --- a/src/dbinc/db.in +++ b/src/dbinc/db.in @@ -2778,16 +2778,21 @@ typedef struct { * * The global variables dbrdonly, dirf and pagf were not retained when 4BSD * replaced the dbm interface with ndbm, and are not supported here. + * + * These unprefixed 4BSD names (delete, fetch, firstkey, nextkey, store, ...) + * are C-only historic aliases: they collide with C++ keywords and standard + * library member names (e.g. std::atomic<>::store, which MSVC's + * pulls into any C++ translation unit). Suppress them for C++. */ +#if !defined(__cplusplus) #define dbminit(a) __db_dbm_init@DB_VERSION_UNIQUE_NAME@(a) #define dbmclose __db_dbm_close@DB_VERSION_UNIQUE_NAME@ -#if !defined(__cplusplus) #define delete(a) __db_dbm_delete@DB_VERSION_UNIQUE_NAME@(a) -#endif #define fetch(a) __db_dbm_fetch@DB_VERSION_UNIQUE_NAME@(a) #define firstkey __db_dbm_firstkey@DB_VERSION_UNIQUE_NAME@ #define nextkey(a) __db_dbm_nextkey@DB_VERSION_UNIQUE_NAME@(a) #define store(a, b) __db_dbm_store@DB_VERSION_UNIQUE_NAME@(a, b) +#endif /******************************************************* * Hsearch historic interface. diff --git a/src/os/os_atomic.c b/src/os/os_atomic.c index 8b9c2ca88..8a50aa176 100644 --- a/src/os/os_atomic.c +++ b/src/os/os_atomic.c @@ -1895,6 +1895,15 @@ __os_atomic_thread_fence() !defined(HAVE_ATOMIC_GCC_BUILTIN) && \ !defined(HAVE_ATOMIC_SYNC_BUILTIN) +/* + * The Interlocked* intrinsics take a `LONG volatile *`. We cast the address + * of db_atomic_t::value to that type through `interlocked_val` (matching + * mut_win32.c); it was referenced here but never defined for this TU. + */ +#ifndef interlocked_val +#define interlocked_val long volatile * +#endif + /* * __os_atomic_init -- * Initialize an atomic variable (Windows). From 2a109a14f9bff3d41dc3b65b67c86c5ee9283a9c Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Fri, 31 Jul 2026 08:59:14 -0400 Subject: [PATCH 2/4] fix(atomic): guard atomic_init macro from C++ collision MSVC's C++ standard library transitively includes in every C++ translation unit (e.g. the cxx_*.cpp sources in db.vcxproj). dbinc/atomic.h defines a function-like macro atomic_init(p, val) whose name exactly matches the standard std::atomic_init free function template, so the macro rewrote that declaration and broke (C2059/C2086 redefinition of std::__os_atomic_init). Berkeley DB only calls atomic_init() from C sources, so define the macro only for C. --- src/dbinc/atomic.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/dbinc/atomic.h b/src/dbinc/atomic.h index ae994fa21..1cc3d10a5 100644 --- a/src/dbinc/atomic.h +++ b/src/dbinc/atomic.h @@ -108,7 +108,16 @@ typedef struct { * Modification operations delegate to ENV-aware functions. */ #define atomic_read(p) __os_atomic_read(p) +/* + * atomic_init collides with the C++ free function std::atomic_init + * (and C11 atomic_init). MSVC's C++ standard library pulls + * into any C++ translation unit, and the macro would rewrite that + * declaration -> compile failure. Berkeley DB only calls atomic_init() from + * C sources, so define the macro only for C. + */ +#if !defined(__cplusplus) #define atomic_init(p, val) __os_atomic_init((p), (val)) +#endif /* * atomic_read_relaxed: torn-read-free load with no ordering, for pure From 87f0be109a450851cf6da03108b1c7c1eccd8fe2 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Fri, 31 Jul 2026 09:15:27 -0400 Subject: [PATCH 3/4] fix(os): add os_atomic.c to Windows db projects os_atomic.c holds the Windows Interlocked implementations of __os_atomic_* but was never listed in the Windows VS project files (it is in the Unix Makefile.in). The db library therefore linked with unresolved externals (__os_atomic_read/_inc/_dec/_cas, referenced by mut_win32.c, mp_*.c, lock.c, txn.c, ...). Add it next to os_alloc.c in the VS10 (.vcxproj) and VS8 (.vcproj) db and db_small projects. --- build_windows/VS10/db.vcxproj | 1 + build_windows/VS10/db_small.vcxproj | 1 + build_windows/VS8/db.vcproj | 1 + build_windows/VS8/db_small.vcproj | 1 + 4 files changed, 4 insertions(+) diff --git a/build_windows/VS10/db.vcxproj b/build_windows/VS10/db.vcxproj index 2fd172d6f..a9901a9f4 100644 --- a/build_windows/VS10/db.vcxproj +++ b/build_windows/VS10/db.vcxproj @@ -335,6 +335,7 @@ + diff --git a/build_windows/VS10/db_small.vcxproj b/build_windows/VS10/db_small.vcxproj index 3c67d5728..89e47cbf8 100644 --- a/build_windows/VS10/db_small.vcxproj +++ b/build_windows/VS10/db_small.vcxproj @@ -303,6 +303,7 @@ + diff --git a/build_windows/VS8/db.vcproj b/build_windows/VS8/db.vcproj index a0bf7bd1c..5e8fb69af 100644 --- a/build_windows/VS8/db.vcproj +++ b/build_windows/VS8/db.vcproj @@ -279,6 +279,7 @@ + diff --git a/build_windows/VS8/db_small.vcproj b/build_windows/VS8/db_small.vcproj index 3bbb9e269..993cb9eee 100644 --- a/build_windows/VS8/db_small.vcproj +++ b/build_windows/VS8/db_small.vcproj @@ -236,6 +236,7 @@ + From c0dc0458aa7d22f2cb4b4c4898fb46b305c180c9 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Fri, 31 Jul 2026 09:19:15 -0400 Subject: [PATCH 4/4] fix(os): add os_aio sources to Windows db projects The async-I/O layer (__os_aio_create/submit/reap/destroy/available/ ctx_available in os_aio.c, referenced by mp_bh.c and mp_region.c) was added to the Unix Makefile.in but never to the Windows VS project files, leaving the db library with unresolved externals at link time. Add os_aio.c (the generic layer + synchronous fallback, always compiled) plus the os_aio_iocp.c and os_aio_pool.c backends (empty TUs unless HAVE_IOCP / HAVE_AIO_THREADPOOL are configured) to the VS10 and VS8 db/db_small projects, mirroring the Unix build. --- build_windows/VS10/db.vcxproj | 3 +++ build_windows/VS10/db_small.vcxproj | 3 +++ build_windows/VS8/db.vcproj | 3 +++ build_windows/VS8/db_small.vcproj | 3 +++ 4 files changed, 12 insertions(+) diff --git a/build_windows/VS10/db.vcxproj b/build_windows/VS10/db.vcxproj index a9901a9f4..b4c784d86 100644 --- a/build_windows/VS10/db.vcxproj +++ b/build_windows/VS10/db.vcxproj @@ -336,6 +336,9 @@ + + + diff --git a/build_windows/VS10/db_small.vcxproj b/build_windows/VS10/db_small.vcxproj index 89e47cbf8..565561c48 100644 --- a/build_windows/VS10/db_small.vcxproj +++ b/build_windows/VS10/db_small.vcxproj @@ -304,6 +304,9 @@ + + + diff --git a/build_windows/VS8/db.vcproj b/build_windows/VS8/db.vcproj index 5e8fb69af..8afbd58ea 100644 --- a/build_windows/VS8/db.vcproj +++ b/build_windows/VS8/db.vcproj @@ -280,6 +280,9 @@ + + + diff --git a/build_windows/VS8/db_small.vcproj b/build_windows/VS8/db_small.vcproj index 993cb9eee..528a351f4 100644 --- a/build_windows/VS8/db_small.vcproj +++ b/build_windows/VS8/db_small.vcproj @@ -237,6 +237,9 @@ + + +