Convert argv through the engine's own UTF-8 converter#29
Merged
Conversation
PR #28 gave the GUI a private strdupt_utf8() that hand-rolls CP_ACP -> wide -> CP_UTF8 to hand the engine UTF-8 argv. The engine has always done the same thing for its own command line; it now exports that converter as HTSEXT_API (hts_convertStringSystemToUTF8, engine #582), so keep one implementation, not two. Verified equivalent before swapping: - Codepage: the engine converter uses GetACP(), which is exactly the CP_ACP the GUI passed. Same bytes in, same bytes out. - Lifetime: malloct/freet/strdupt are thin aliases over libc malloc/free (htssafe.h), and the conversion path returns plain malloc'd memory. Under /MD everything shares the one ucrtbase heap, so an argv[] entry stays freet()-able across the DLL boundary. - Contract: the engine returns NULL on failure; strdupt_utf8() must not, since argv[] entries have to be non-NULL. The wrapper keeps the strdupt(s) fallback. The wrapper stays, so the argv call site and the --selftest are unchanged; CI still asserts "MBCS->UTF-8 ok". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replace the GUI's private
strdupt_utf8()— 30 lines of hand-rolledCP_ACP -> wide -> CP_UTF8— with a thin wrapper that delegates to the engine's own converter,hts_convertStringSystemToUTF8().Why
PR #28 added
strdupt_utf8()so the GUI hands the engine UTF-8 argv (MFC gives us the ANSI codepage; the engine reads everychar*as UTF-8). The engine has always done the identical conversion for its own command line, and it now exports that converter asHTSEXT_API(engine #582). Two copies of the same MBCS→UTF-8 logic is exactly the duplication that export was meant to remove.How
The wrapper stays (so the argv call site and the
--selftestare untouched); only its body changes. Verified equivalent before swapping:GetACP(), precisely theCP_ACPthe GUI passed. Same bytes in, same bytes out.malloct/freet/strduptare thin aliases over libcmalloc/free(htssafe.h), and the conversion path returns plainmalloc'd memory. Under/MDeverything shares the one ucrtbase heap, so anargv[]entry staysfreet()-able across the DLL boundary.NULLon failure;strdupt_utf8()must not, sinceargv[]entries have to be non-NULL. The wrapper keeps thestrdupt(s)fallback.hts_convertStringSystemToUTF8is declared locally withextern "C"(the GUI's pattern for engine functions) rather than by includinghtscharset.h, which has noextern "C"guard.CI still asserts
MBCS->UTF-8 okvia--selftest.🤖 Generated with Claude Code