From c17c0e16c4d8cfa381661ae1c3aa77c6fecf3e6f Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 28 Feb 2025 05:23:48 +0200 Subject: [PATCH] builtin: declare `fn C._vinit/2` and `fn C._vcleanup/0` (continuation from #23812) (#23820) --- vlib/builtin/builtin.c.v | 6 ++++++ vlib/builtin/builtin_windows.c.v | 16 ++++++++++++++++ vlib/v/tests/create_dll/create_win_dll.c.v | 1 - 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/vlib/builtin/builtin.c.v b/vlib/builtin/builtin.c.v index 17087eb66b..86fe555c31 100644 --- a/vlib/builtin/builtin.c.v +++ b/vlib/builtin/builtin.c.v @@ -6,6 +6,12 @@ pub type FnExitCb = fn () fn C.atexit(f FnExitCb) int fn C.strerror(int) &char +// These functions (_vinit, and _vcleanup), are generated by V, and if you have a `module no_main` program, +// you should ensure to call them when appropriate. +fn C._vinit(argc int, argv &&char) + +fn C._vcleanup() + @[markused] fn v_segmentation_fault_handler(signal_number i32) { $if freestanding { diff --git a/vlib/builtin/builtin_windows.c.v b/vlib/builtin/builtin_windows.c.v index 4f6d46ff79..2af19a09c3 100644 --- a/vlib/builtin/builtin_windows.c.v +++ b/vlib/builtin/builtin_windows.c.v @@ -7,6 +7,8 @@ module builtin // g_original_codepage - used to restore the original windows console code page when exiting __global g_original_codepage = u32(0) +// See https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types +// See https://www.codeproject.com/KB/string/cppstringguide1.aspx pub type C.BOOL = int pub type C.HINSTANCE = voidptr @@ -25,6 +27,20 @@ pub type C.HANDLE = voidptr pub type C.LRESULT = voidptr +pub type C.CHAR = char + +pub type C.TCHAR = u16 // It is u8 if UNICODE is not defined, but for V programs it always is + +pub type C.WCHAR = u16 + +pub type C.LPSTR = &char + +pub type C.LPWSTR = &C.WCHAR + +pub type C.LPTSTR = &C.TCHAR + +pub type C.LPCTSTR = &C.TCHAR + // utf8 to stdout needs C.SetConsoleOutputCP(cp_utf8) fn C.GetConsoleOutputCP() u32 diff --git a/vlib/v/tests/create_dll/create_win_dll.c.v b/vlib/v/tests/create_dll/create_win_dll.c.v index 10a15b4eb1..79f6a7bd1a 100644 --- a/vlib/v/tests/create_dll/create_win_dll.c.v +++ b/vlib/v/tests/create_dll/create_win_dll.c.v @@ -1,6 +1,5 @@ module test -fn C._vinit(int, voidptr) fn C.GC_INIT() const foo = 1