Skip to content

Commit 52fe6d5

Browse files
Timcodex
andcommitted
Keep released lock-sidecar cleanup buildable with MSVC
Use the MSVC stack allocator when preparing released amalgamations that contain a variable-length lock-path array. Preserve the source everywhere else and keep existing releases usable with the Windows publishing toolchain. Co-Authored-By: OpenAI Codex <noreply@openai.com>
1 parent 1206625 commit 52fe6d5

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

‎scripts/build-amalgamation.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ console.log("Preparing released doltlite amalgamation...")
3232
fs.mkdirSync(outDir, { recursive: true })
3333
let amalgamation = fs.readFileSync(inC, "utf8")
3434

35+
const lockPathVla = ' char zLock[nDir + (nPath - nDir) + sizeof(".-lock") + 1];'
36+
if (amalgamation.includes(lockPathVla)) {
37+
amalgamation = `/* DOLTLITE_NODE_MSVC_LOCK_PATH_FALLBACK */
38+
#ifdef _MSC_VER
39+
# include <malloc.h>
40+
#endif
41+
42+
${amalgamation.replace(lockPathVla, [
43+
"#ifdef _MSC_VER",
44+
' char *zLock = (char*)_alloca(nPath + sizeof(".-lock"));',
45+
"#else",
46+
lockPathVla,
47+
"#endif",
48+
].join("\n"))}`
49+
}
50+
3551
// DoltLite releases before v0.11.37 emitted the Winsock 2 headers after
3652
// SQLite's Windows VFS had already included windows.h. Keep those releases
3753
// buildable while newer release amalgamations carry the ordering fix directly.

‎test/amalgamation.test.ts‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,27 @@ describe("released amalgamation preparation", () => {
2727
expect(winsock).toBeLessThan(windows)
2828
})
2929

30-
test("uses an unmodified fixed release amalgamation", () => {
30+
test("keeps lock-path allocation on the stack with MSVC", () => {
3131
const source = readFileSync(sourcePath, "utf8")
3232
const output = readFileSync(outputPath, "utf8")
33+
const vla = ' char zLock[nDir + (nPath - nDir) + sizeof(".-lock") + 1];'
3334

34-
if (source.includes("DOLTLITE_AMALGAMATION_WINSOCK2_EARLY")) {
35-
expect(output).toBe(source)
36-
} else {
37-
expect(output).toContain("DOLTLITE_NODE_WINSOCK2_EARLY_FALLBACK")
35+
if (source.includes(vla)) {
36+
expect(output).toContain("DOLTLITE_NODE_MSVC_LOCK_PATH_FALLBACK")
37+
expect(output).toContain('#ifdef _MSC_VER\n char *zLock = (char*)_alloca(nPath + sizeof(".-lock"));')
38+
expect(output).toContain(`#else\n${vla}\n#endif`)
3839
}
3940
})
41+
42+
test("preserves release source outside compiler compatibility fixes", () => {
43+
const source = readFileSync(sourcePath, "utf8")
44+
const output = readFileSync(outputPath, "utf8")
45+
const vla = ' char zLock[nDir + (nPath - nDir) + sizeof(".-lock") + 1];'
46+
const restored = output
47+
.replace(/^\/\* DOLTLITE_NODE_WINSOCK2_EARLY_FALLBACK \*\/\n#ifdef _WIN32\n# include <winsock2.h>\n# include <ws2tcpip.h>\n#endif\n\n/, "")
48+
.replace(/^\/\* DOLTLITE_NODE_MSVC_LOCK_PATH_FALLBACK \*\/\n#ifdef _MSC_VER\n# include <malloc.h>\n#endif\n\n/, "")
49+
.replace(`#ifdef _MSC_VER\n char *zLock = (char*)_alloca(nPath + sizeof(".-lock"));\n#else\n${vla}\n#endif`, vla)
50+
51+
expect(restored).toBe(source)
52+
})
4053
})

0 commit comments

Comments
 (0)