Skip to content

Commit 23e513f

Browse files
Fix mingw build of lmdb 1.0.0 (LARGE_INTEGER usage in mdb.c)
lmdb 1.0.0 added incremental dump/load and MDB_RPAGE_CACHE remapping code that treats the Windows LARGE_INTEGER union as a scalar integer, which fails to compile with x86_64-w64-mingw32-gcc. Add a patch that accesses the .QuadPart member on Windows so offset arithmetic and SetFilePointerEx() use the correct type. POSIX builds are unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8d78ab0 commit 23e513f

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Ihor Aleksandrychiev <igor.aleksandrychev@northern.tech>
3+
Date: Tue, 14 Jul 2026 15:19:32 +0300
4+
Subject: [PATCH] Fix Windows/mingw LARGE_INTEGER usage in mdb.c
5+
6+
lmdb 1.0.0 introduced incremental dump/load and MDB_RPAGE_CACHE
7+
remapping code that treats the Windows LARGE_INTEGER union as a
8+
scalar integer. This does not compile with mingw (x86_64-w64-mingw32),
9+
failing with 'invalid initializer', 'incompatible types when assigning
10+
to type LARGE_INTEGER' and 'used union type value where scalar is
11+
required' in mdb_env_copyfd0() and mdb_env_incr_loadfd().
12+
13+
Access the .QuadPart member on Windows so the offset arithmetic and
14+
SetFilePointerEx() calls use the correct type.
15+
16+
Upstream tracking: fixed upstream by ITS#10539 ("lmdb: windows cleanup",
17+
mdb.RE/1.0 commit 8827c7d, 2026-07-14), which landed after the LMDB_1.0.0
18+
tag we build from. Drop this patch once we update to an lmdb snapshot that
19+
includes that commit.
20+
Ref: https://bugs.openldap.org/show_bug.cgi?id=10539
21+
---
22+
libraries/liblmdb/mdb.c | 22 +++++++++++++++++-----
23+
1 file changed, 17 insertions(+), 5 deletions(-)
24+
25+
diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c
26+
index 43fe7b9..6c7078c 100644
27+
--- a/libraries/liblmdb/mdb.c
28+
+++ b/libraries/liblmdb/mdb.c
29+
@@ -11623,7 +11623,7 @@ mdb_env_copyfd0(MDB_env *env, HANDLE fd)
30+
#endif
31+
#if MDB_RPAGE_CACHE
32+
#ifdef _WIN32
33+
- LARGE_INTEGER off = 0;
34+
+ LARGE_INTEGER off = {0};
35+
#else
36+
off_t off = 0;
37+
#endif
38+
@@ -11687,7 +11687,11 @@ mdb_env_copyfd0(MDB_env *env, HANDLE fd)
39+
}
40+
#if MDB_RPAGE_CACHE
41+
if (MDB_REMAPPING(env->me_flags)) {
42+
+#ifdef _WIN32
43+
+ off.QuadPart = wsize;
44+
+#else
45+
off = wsize;
46+
+#endif
47+
}
48+
#endif
49+
wsize = w3 - wsize;
50+
@@ -11713,7 +11717,11 @@ mdb_env_copyfd0(MDB_env *env, HANDLE fd)
51+
wsize -= len;
52+
#if MDB_RPAGE_CACHE
53+
if (MDB_REMAPPING(env->me_flags)) {
54+
+#ifdef _WIN32
55+
+ off.QuadPart += len;
56+
+#else
57+
off += len;
58+
+#endif
59+
}
60+
#endif
61+
continue;
62+
@@ -11955,7 +11963,8 @@ mdb_env_incr_loadfd(MDB_env *env, HANDLE fd)
63+
return ENOMEM;
64+
65+
#ifdef _WIN32
66+
- SetFilePointerEx(env->me_fd, 0, NULL, FILE_BEGIN);
67+
+ off.QuadPart = 0;
68+
+ SetFilePointerEx(env->me_fd, off, NULL, FILE_BEGIN);
69+
#else
70+
lseek(env->me_fd, 0, SEEK_SET);
71+
#endif
72+
@@ -12020,15 +12029,18 @@ mdb_env_incr_loadfd(MDB_env *env, HANDLE fd)
73+
ptr += rlen;
74+
rsize -= rlen;
75+
}
76+
- off = (pg-prevpg-numprev) * env->me_psize;
77+
rsize = numpgs * env->me_psize;
78+
- if (off) {
79+
#ifdef _WIN32
80+
+ off.QuadPart = (pg-prevpg-numprev) * env->me_psize;
81+
+ if (off.QuadPart) {
82+
SetFilePointerEx(env->me_fd, off, NULL, FILE_CURRENT);
83+
+ }
84+
#else
85+
+ off = (pg-prevpg-numprev) * env->me_psize;
86+
+ if (off) {
87+
lseek(env->me_fd, off, SEEK_CUR);
88+
-#endif
89+
}
90+
+#endif
91+
ptr = pbuf;
92+
while (rsize > 0) {
93+
w2 = (rsize > MAX_WRITE) ? MAX_WRITE: rsize;

0 commit comments

Comments
 (0)