From 0dcbb3a0b11aa65558733822a781e5d3a1233776 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 27 Apr 2026 04:36:15 +0300 Subject: [PATCH] all: fix more tests --- vlib/fasthttp/fasthttp_bsd.c.v | 2 +- vlib/v/builder/cc.v | 2 +- vlib/v/builder/cc_test.v | 2 +- vlib/v/gen/c/cheaders.v | 23 ++++++++++++++----- .../gen/c/cheaders_manual_stdlib_decls_test.v | 5 ++-- vlib/v/gen/c/coutput_test.v | 8 +++++++ ...ows_clang_bootstrap_regression.c.must_have | 4 +--- vlib/v/gen/wasm/gen.v | 2 +- .../skip_unused/generics_as_receiver.run.out | 2 +- vlib/v/tests/skip_unused/ierror_str.run.out | 2 +- vlib/veb/veb_fasthttp.v | 15 ++++++++++-- 11 files changed, 47 insertions(+), 20 deletions(-) diff --git a/vlib/fasthttp/fasthttp_bsd.c.v b/vlib/fasthttp/fasthttp_bsd.c.v index 3466c3f75..5ea1ea7dc 100644 --- a/vlib/fasthttp/fasthttp_bsd.c.v +++ b/vlib/fasthttp/fasthttp_bsd.c.v @@ -336,7 +336,7 @@ fn process_request(server Server, kq int, c_ptr voidptr, mut clients map[int]voi c.should_close = resp.should_close c.write_buf = resp.content.clone() if resp.file_path != '' { - fd := C.open(resp.file_path.str, C.O_RDONLY) + fd := C.open(resp.file_path.str, C.O_RDONLY, 0) if fd != -1 { mut st := C.stat{} if C.fstat(fd, &st) == 0 { diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index c9b71caf1..91afd5f58 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -270,7 +270,7 @@ fn c_error_missing_library_name(c_output string) string { ] { if line.contains(marker) { lib_name := line.all_after(marker).trim_space() - return lib_name.all_before('`').all_before("'").all_before('"').all_before(' ') + return lib_name.all_before('`').all_before("'").all_before('"').all_before(' ').all_before(':') } } } diff --git a/vlib/v/builder/cc_test.v b/vlib/v/builder/cc_test.v index 1a4b782b7..ff81cf5e7 100644 --- a/vlib/v/builder/cc_test.v +++ b/vlib/v/builder/cc_test.v @@ -398,7 +398,7 @@ fn main() { panic(err) } res := - os.execute('${os.quoted_path(@VEXE)} -dump-c-flags - -cc tcc -arch arm64 ${os.quoted_path(src_file)}') + os.execute('${os.quoted_path(@VEXE)} -dump-c-flags - -os linux -cc tcc -arch arm64 ${os.quoted_path(src_file)}') assert res.exit_code == 0, res.output assert !res.output.contains('thirdparty/stdatomic/nix/atomic.S') assert res.output.contains('libatomic.so') diff --git a/vlib/v/gen/c/cheaders.v b/vlib/v/gen/c/cheaders.v index 016edcfef..b4f911ee6 100644 --- a/vlib/v/gen/c/cheaders.v +++ b/vlib/v/gen/c/cheaders.v @@ -385,11 +385,16 @@ typedef int (*qsort_callback_func)(const void*, const void*); #define _TRUNCATE ((size_t)-1) #endif #elif defined(__MINGW32__) || defined(__MINGW64__) || (defined(__clang__) && (defined(_WIN32) || defined(_WIN64))) -typedef struct _iobuf FILE; -FILE* __cdecl __acrt_iob_func(unsigned index); -#define stdin (__acrt_iob_func(0)) -#define stdout (__acrt_iob_func(1)) -#define stderr (__acrt_iob_func(2)) +#include +#include +#include +#include +#ifndef va_copy + #define va_copy(dest, src) ((dest) = (src)) +#endif +#ifndef _TRUNCATE + #define _TRUNCATE ((size_t)-1) +#endif #elif defined(__TINYC__) && (defined(_WIN32) || defined(_WIN64)) #ifndef _FILE_DEFINED struct _iobuf { @@ -476,7 +481,10 @@ typedef __builtin_va_list va_list; #define va_copy(dest, src) __builtin_va_copy(dest, src) #endif #endif -#if !defined(_MSC_VER) || defined(__clang__) +#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__MINGW64__) && !(defined(__clang__) && (defined(_WIN32) || defined(_WIN64))) +#ifdef __cplusplus +extern "C" { +#endif V_CRT_LINKAGE int V_CRT_CALL vfprintf(FILE *stream, const char *format, va_list ap); V_CRT_LINKAGE int V_CRT_CALL vsnprintf(char *str, size_t size, const char *format, va_list ap); V_CRT_LINKAGE int V_CRT_CALL fprintf(FILE *stream, const char *format, ...); @@ -559,6 +567,9 @@ V_CRT_LINKAGE int V_CRT_CALL _wputenv(const unsigned short *envstring); V_CRT_LINKAGE int V_CRT_CALL _vscprintf(const char *format, va_list ap); V_CRT_LINKAGE int V_CRT_CALL _vsnprintf_s(char *buffer, size_t size, size_t count, const char *format, va_list ap); #endif +#ifdef __cplusplus +} +#endif #endif #ifndef _IOFBF #define _IOFBF 0 diff --git a/vlib/v/gen/c/cheaders_manual_stdlib_decls_test.v b/vlib/v/gen/c/cheaders_manual_stdlib_decls_test.v index 0a375031a..5c651b868 100644 --- a/vlib/v/gen/c/cheaders_manual_stdlib_decls_test.v +++ b/vlib/v/gen/c/cheaders_manual_stdlib_decls_test.v @@ -32,7 +32,6 @@ fn test_default_c_prelude_uses_manual_stdio_stdlib_string_and_stdarg_decls() { assert generated_c.contains('RAND_MAX = 2147483647'), generated_c assert generated_c.contains('V_CRT_LINKAGE double V_CRT_CALL atof(const char *str);'), generated_c assert generated_c.contains('extern FILE* stdout;'), generated_c - assert generated_c.contains('#define stdout (__acrt_iob_func(1))'), generated_c assert generated_c.contains('#if defined(_MSC_VER) && !defined(__clang__)\n#include \n#include \n#include \n#include '), generated_c assert generated_c.contains('#if defined(_MSC_VER) && !defined(__clang__)\n\t#define V_CRT_LINKAGE __declspec(dllimport)\n\t#define V_CRT_CALL VCALLCONV(cdecl)\n#else\n\t#define V_CRT_LINKAGE\n\t#define V_CRT_CALL\n#endif'), generated_c assert generated_c.contains('V_CRT_LINKAGE int V_CRT_CALL _vscprintf(const char *format, va_list ap);'), generated_c @@ -42,7 +41,7 @@ fn test_default_c_prelude_uses_manual_stdio_stdlib_string_and_stdarg_decls() { assert generated_c.contains('V_CRT_LINKAGE void V_CRT_CALL _aligned_free(void *memory);'), generated_c assert generated_c.contains('V_CRT_LINKAGE unsigned short * V_CRT_CALL _wgetenv(const unsigned short *varname);'), generated_c assert generated_c.contains('V_CRT_LINKAGE int V_CRT_CALL _wputenv(const unsigned short *envstring);'), generated_c - assert generated_c.contains('#elif defined(__MINGW32__) || defined(__MINGW64__) || (defined(__clang__) && (defined(_WIN32) || defined(_WIN64)))\ntypedef struct _iobuf FILE;\nFILE* __cdecl __acrt_iob_func(unsigned index);\n#define stdin (__acrt_iob_func(0))\n#define stdout (__acrt_iob_func(1))\n#define stderr (__acrt_iob_func(2))'), generated_c + assert generated_c.contains('#elif defined(__MINGW32__) || defined(__MINGW64__) || (defined(__clang__) && (defined(_WIN32) || defined(_WIN64)))\n#include \n#include \n#include \n#include '), generated_c assert generated_c.contains('#elif defined(__TINYC__) && (defined(_WIN32) || defined(_WIN64))'), generated_c assert generated_c.contains('#ifndef _FILE_DEFINED\nstruct _iobuf {\n\tchar *_ptr;\n\tint _cnt;\n\tchar *_base;\n\tint _flag;\n\tint _file;\n\tint _charbuf;\n\tint _bufsiz;\n\tchar *_tmpfname;\n};\ntypedef struct _iobuf FILE;\n#define _FILE_DEFINED'), generated_c assert generated_c.contains('FILE* __cdecl __iob_func(void);'), generated_c @@ -72,7 +71,7 @@ fn test_msvc_windows_prelude_uses_msvc_crt_headers() { assert !generated_c.contains('#if defined(_MSC_VER) && !defined(__clang__)\ntypedef struct _iobuf FILE;'), generated_c assert generated_c.contains('#ifndef va_copy\n\t#define va_copy(dest, src) ((dest) = (src))\n#endif\n#ifndef _TRUNCATE'), generated_c assert generated_c.contains('#if defined(_MSC_VER) && !defined(__clang__)\n\t#define V_CRT_LINKAGE __declspec(dllimport)\n\t#define V_CRT_CALL VCALLCONV(cdecl)\n#else\n\t#define V_CRT_LINKAGE\n\t#define V_CRT_CALL\n#endif'), generated_c - assert generated_c.contains('#if !defined(_MSC_VER) || defined(__clang__)\nV_CRT_LINKAGE int V_CRT_CALL vfprintf(FILE *stream, const char *format, va_list ap);'), generated_c + assert generated_c.contains('#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__MINGW64__) && !(defined(__clang__) && (defined(_WIN32) || defined(_WIN64)))\n#ifdef __cplusplus\nextern "C" {\n#endif\nV_CRT_LINKAGE int V_CRT_CALL vfprintf(FILE *stream, const char *format, va_list ap);'), generated_c assert generated_c.contains('V_CRT_LINKAGE int V_CRT_CALL _vscprintf(const char *format, va_list ap);'), generated_c assert generated_c.contains('V_CRT_LINKAGE int V_CRT_CALL _vsnprintf_s(char *buffer, size_t size, size_t count, const char *format, va_list ap);'), generated_c assert generated_c.contains('#include '), generated_c diff --git a/vlib/v/gen/c/coutput_test.v b/vlib/v/gen/c/coutput_test.v index 2a837115e..25abf376b 100644 --- a/vlib/v/gen/c/coutput_test.v +++ b/vlib/v/gen/c/coutput_test.v @@ -533,6 +533,14 @@ fn should_skip(relpath string) bool { } } } + if gcc_path == '' { + test_path := os.join_path(testdata_folder, relpath) + file_options := get_file_options(test_path) + if file_options.vflags.contains('-cc gcc') { + eprintln('> skipping ${relpath} since its vflags require gcc, which is not detected') + return true + } + } return false } diff --git a/vlib/v/gen/c/testdata/windows_clang_bootstrap_regression.c.must_have b/vlib/v/gen/c/testdata/windows_clang_bootstrap_regression.c.must_have index d6900d79a..42f12b103 100644 --- a/vlib/v/gen/c/testdata/windows_clang_bootstrap_regression.c.must_have +++ b/vlib/v/gen/c/testdata/windows_clang_bootstrap_regression.c.must_have @@ -1,9 +1,7 @@ #if defined(_MSC_VER) && !defined(__clang__) #include #elif defined(__MINGW32__) || defined(__MINGW64__) || (defined(__clang__) && (defined(_WIN32) || defined(_WIN64))) -FILE* __cdecl __acrt_iob_func(unsigned index); -#define stdout (__acrt_iob_func(1)) -#if !defined(_MSC_VER) || defined(__clang__) +#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__MINGW64__) && !(defined(__clang__) && (defined(_WIN32) || defined(_WIN64))) int V_CRT_CALL _fileno(FILE *stream); FILE * V_CRT_CALL _wfopen(const unsigned short *filename, const unsigned short *mode); int V_CRT_CALL _vscprintf(const char *format, va_list ap); diff --git a/vlib/v/gen/wasm/gen.v b/vlib/v/gen/wasm/gen.v index addf51cfc..916e488d0 100644 --- a/vlib/v/gen/wasm/gen.v +++ b/vlib/v/gen/wasm/gen.v @@ -1743,7 +1743,7 @@ fn (mut g Gen) eval_enum_field_expr(expr ast.Expr) ?i64 { return left % right } .left_shift { - return left << int(right) + return i64(u64(left) << int(right)) } .right_shift { return left >> int(right) diff --git a/vlib/v/tests/skip_unused/generics_as_receiver.run.out b/vlib/v/tests/skip_unused/generics_as_receiver.run.out index ddc2d74b1..fd64514d1 100644 --- a/vlib/v/tests/skip_unused/generics_as_receiver.run.out +++ b/vlib/v/tests/skip_unused/generics_as_receiver.run.out @@ -1 +1 @@ -0000-00-00T00:00:00.000000000Z +0000-01-01T00:00:00.000000000Z diff --git a/vlib/v/tests/skip_unused/ierror_str.run.out b/vlib/v/tests/skip_unused/ierror_str.run.out index 88e9183d7..a8d5ebeec 100644 --- a/vlib/v/tests/skip_unused/ierror_str.run.out +++ b/vlib/v/tests/skip_unused/ierror_str.run.out @@ -1 +1 @@ -No such file or directory; code: 2 +os: failed to find executable diff --git a/vlib/veb/veb_fasthttp.v b/vlib/veb/veb_fasthttp.v index 574976110..8249fa7f9 100644 --- a/vlib/veb/veb_fasthttp.v +++ b/vlib/veb/veb_fasthttp.v @@ -58,13 +58,24 @@ pub fn run_new[A, X](mut global_app A, params RunParams) ! { eprintln('Failed to create server: ${err}') return } - maybe_init_server[A](mut global_app, new_server_with_lifecycle(server.handle())) + handle := server.handle() + maybe_init_server[A](mut global_app, new_server_with_lifecycle(handle)) println('[veb] Running multi-threaded app on ${server_protocol(params)}://${startup_host(params)}:${params.port}/') flush_stdout() $if A is BeforeAcceptApp { + mut server_thread := spawn_fasthttp_server_run(mut server) + // Wait until the listener is bound before invoking before_accept_loop, + // so callers using `<-app.started` actually see the server ready. + handle.wait_till_running() or {} global_app.before_accept_loop() + server_thread.wait() or { panic(err) } + } $else { + server.run() or { panic(err) } } - server.run() or { panic(err) } +} + +fn spawn_fasthttp_server_run(mut server fasthttp.Server) thread ! { + return spawn server.run() } fn parallel_request_handler[A, X](req fasthttp.HttpRequest) !fasthttp.HttpResponse { -- 2.39.5