Re: Should we work around msvc failing to compile tab-complete.c?

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Dave Page <dpage(at)pgadmin(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Should we work around msvc failing to compile tab-complete.c?
Date: 2024-07-09 22:59:34
Message-ID: 20240709225934.746y5fg3kgxkyant@awork3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2024-07-09 17:44:27 -0400, Tom Lane wrote:
> Worst case: the reason no one uses readline under Windows is that it flat
> out doesn't work.

I've just tried it again, it works after splitting the else-if chain.

> One thing that struck me while looking at tab-complete.c just now is
> that there are aspects of the readline API that require strings to be
> malloc'd by the client (tab-complete.c) and later free'd within
> libreadline. I wonder how that will play with Windows' weird rules
> about when one DLL's malloc pool will interoperate with another's
> (cf PQfreemem).

It seems to work fine as long as a debug-readline is paired with a debug-psql
or a release-readline is paired with a release-psql.

Intentionally cross-matching the two does indeed quickly crash, with stack
trace that looks like exactly the issue you describe. This is a release
readline in a debug psql, but it shouldn't matter which way round.

Just doing "tab":

# Child-SP RetAddr Call Site
00 00000017`db5ff430 00007ff9`1fa18182 ntdll!RtlReportCriticalFailure+0x56
01 00000017`db5ff520 00007ff9`1fa1846a ntdll!RtlpHeapHandleError+0x12
02 00000017`db5ff550 00007ff9`1fa1e0f1 ntdll!RtlpHpHeapHandleError+0x7a
03 00000017`db5ff580 00007ff9`1f9b79d2 ntdll!RtlpLogHeapFailure+0x45
04 00000017`db5ff5b0 00007ff9`1f9347b1 ntdll!RtlpFreeHeapInternal+0x822c2
05 00000017`db5ff670 00007ff9`1d7df05b ntdll!RtlFreeHeap+0x51
*** WARNING: Unable to verify checksum for C:\dev\postgres-meson\build-ninja-2022\tmp_install\usr\local\pgsql\bin\readline.dll
06 00000017`db5ff6b0 00007ff8`f7ab637c ucrtbase!_free_base+0x1b
07 (Inline Function) --------`-------- readline!_rl_free_match_list+0x19 [C:\dev\vcpkg\buildtrees\readline-win32\src\e6f798e014-dba5d3560f.clean\complete.c @ 1627]
08 00000017`db5ff6e0 00007ff8`f7ab12fc readline!rl_complete_internal+0x4dc [C:\dev\vcpkg\buildtrees\readline-win32\src\e6f798e014-dba5d3560f.clean\complete.c @ 1755]
09 00000017`db5ff750 00007ff8`f7ab1725 readline!_rl_dispatch_subseq+0x2dc [C:\dev\vcpkg\buildtrees\readline-win32\src\e6f798e014-dba5d3560f.clean\readline.c @ 582]
0a (Inline Function) --------`-------- readline!_rl_dispatch+0x18 [C:\dev\vcpkg\buildtrees\readline-win32\src\e6f798e014-dba5d3560f.clean\readline.c @ 530]
0b 00000017`db5ff7a0 00007ff8`f7ab1625 readline!readline_internal_char+0xd5 [C:\dev\vcpkg\buildtrees\readline-win32\src\e6f798e014-dba5d3560f.clean\readline.c @ 449]
0c (Inline Function) --------`-------- readline!readline_internal_charloop+0x13 [C:\dev\vcpkg\buildtrees\readline-win32\src\e6f798e014-dba5d3560f.clean\readline.c @ 490]
0d (Inline Function) --------`-------- readline!readline_internal+0x18 [C:\dev\vcpkg\buildtrees\readline-win32\src\e6f798e014-dba5d3560f.clean\readline.c @ 504]
0e 00000017`db5ff7e0 00007ff7`6f1e9dba readline!readline+0xb5 [C:\dev\vcpkg\buildtrees\readline-win32\src\e6f798e014-dba5d3560f.clean\readline.c @ 300]
0f 00000017`db5ff810 00007ff7`6f1eb211 psql!gets_interactive+0x3a [C:\dev\postgres-meson\src\bin\psql\input.c @ 91]
10 00000017`db5ff850 00007ff7`6f1ee7ec psql!MainLoop+0x3a1 [C:\dev\postgres-meson\src\bin\psql\mainloop.c @ 166]
11 00000017`db5ff980 00007ff7`6f287a99 psql!main+0xcfc [C:\dev\postgres-meson\src\bin\psql\startup.c @ 462]
12 00000017`db5ffaa0 00007ff7`6f2879e2 psql!invoke_main+0x39 [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 79]
13 00000017`db5ffaf0 00007ff7`6f28789e psql!__scrt_common_main_seh+0x132 [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288]
14 00000017`db5ffb60 00007ff7`6f287b0e psql!__scrt_common_main+0xe [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 331]
15 00000017`db5ffb90 00007ff9`1e9a7374 psql!mainCRTStartup+0xe [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp @ 17]
16 00000017`db5ffbc0 00007ff9`1f95cc91 KERNEL32!BaseThreadInitThunk+0x14
17 00000017`db5ffbf0 00000000`00000000 ntdll!RtlUserThreadStart+0x21

executing a statement (crashes after execution):

# Child-SP RetAddr Call Site
00 000000db`ae3ff898 00007ff9`1f9cd088 ntdll!RtlpBreakPointHeap+0x16
01 000000db`ae3ff8a0 00007ff9`1f96f6f5 ntdll!RtlpValidateHeapEntry+0x5d858
02 000000db`ae3ff8e0 00007ff9`1d2b6edb ntdll!RtlValidateHeap+0x95
03 000000db`ae3ff930 00007ff8`ba38dc52 KERNELBASE!HeapValidate+0xb
04 000000db`ae3ff960 00007ff8`ba390a76 ucrtbased!_CrtIsValidHeapPointer+0x42 [minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp @ 1407]
05 000000db`ae3ff9a0 00007ff8`ba38f565 ucrtbased!free_dbg_nolock+0x136 [minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp @ 904]
06 000000db`ae3ffaa0 00007ff8`ba392118 ucrtbased!_free_dbg+0x55 [minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp @ 1030]
07 000000db`ae3ffae0 00007ff7`6f1ebd00 ucrtbased!free+0x28 [minkernel\crts\ucrt\src\appcrt\heap\free.cpp @ 39]
08 000000db`ae3ffb20 00007ff7`6f1ee7ec psql!MainLoop+0xe90 [C:\dev\postgres-meson\src\bin\psql\mainloop.c @ 579]
09 000000db`ae3ffc50 00007ff7`6f287a99 psql!main+0xcfc [C:\dev\postgres-meson\src\bin\psql\startup.c @ 462]
0a 000000db`ae3ffd70 00007ff7`6f2879e2 psql!invoke_main+0x39 [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 79]
0b 000000db`ae3ffdc0 00007ff7`6f28789e psql!__scrt_common_main_seh+0x132 [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288]
0c 000000db`ae3ffe30 00007ff7`6f287b0e psql!__scrt_common_main+0xe [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 331]
0d 000000db`ae3ffe60 00007ff9`1e9a7374 psql!mainCRTStartup+0xe [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp @ 17]
0e 000000db`ae3ffe90 00007ff9`1f95cc91 KERNEL32!BaseThreadInitThunk+0x14
0f 000000db`ae3ffec0 00000000`00000000 ntdll!RtlUserThreadStart+0x21

Note that the line numbers seem to commonly point to where the next frame
would return to (i.e. mainloop.c:579 is the call to free, but on return the if
(slashCmdStatus == PSQL_CMD_TERMINATE) would be reached, so that's displayed -
why I don't know).

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2024-07-09 23:07:24 Re: Should we work around msvc failing to compile tab-complete.c?
Previous Message Peter Smith 2024-07-09 22:51:55 Re: Pgoutput not capturing the generated columns