Skip to content

Commit 7f8fc05

Browse files
committed
all: fix more tests
1 parent 35e0295 commit 7f8fc05

6 files changed

Lines changed: 53 additions & 7 deletions

File tree

vlib/os/os_windows.c.v

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ fn wide_ptr_to_string(wstr &u16) string {
119119
}
120120

121121
fn looks_like_utf16le_captured_output(raw string) bool {
122-
if raw.len < 2 || raw.len % 2 != 0 {
122+
if raw.len < 2 {
123123
return false
124124
}
125+
// Allow odd-length buffers: Windows text-mode translation can insert
126+
// extra bytes (e.g. \r before \n), producing odd-length UTF-16LE output.
127+
// In that case, just ignore the trailing byte during detection.
125128
if raw[0] == 0xff && raw[1] == 0xfe {
126129
return true
127130
}
@@ -189,7 +192,32 @@ fn decode_windows_captured_output(raw string) string {
189192
return utf16_captured_output_to_string(raw, false)
190193
}
191194
if validate.utf8_string(raw) {
192-
return raw
195+
// Check for embedded null bytes, which suggest this is actually UTF-16
196+
// that wasn't detected (e.g. due to text-mode \r\n translation corrupting
197+
// the byte alignment). Strip null bytes as a recovery heuristic.
198+
mut has_null := false
199+
for i in 0 .. raw.len {
200+
if raw[i] == 0 {
201+
has_null = true
202+
break
203+
}
204+
}
205+
if !has_null {
206+
return raw
207+
}
208+
// Contains null bytes — likely corrupted UTF-16LE.
209+
// Strip null bytes and normalize \r\n to \n (text-mode artifacts).
210+
mut cleaned := strings.new_builder(raw.len)
211+
for i in 0 .. raw.len {
212+
if raw[i] == 0 {
213+
continue
214+
}
215+
if raw[i] == 0x0D && i + 1 < raw.len && raw[i + 1] == 0x0A {
216+
continue
217+
}
218+
cleaned.write_u8(raw[i])
219+
}
220+
return cleaned.str()
193221
}
194222
mut wide := raw.to_wide(from_ansi: true)
195223
if isnil(wide) {

vlib/v/ast/comptime_valid_idents.v

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ pub fn eval_comptime_not_user_defined_ident(ident string, the_pref &pref.Prefere
8989
is_true = !the_pref.m64
9090
}
9191
'little_endian' {
92-
is_true = $if little_endian { true } $else { false }
92+
// ppc64le is little-endian (the 'le' suffix), all others below are big-endian
93+
is_true = the_pref.arch !in [.ppc64, .ppc, .sparc64, .s390x]
9394
}
9495
'big_endian' {
95-
is_true = $if big_endian { true } $else { false }
96+
is_true = the_pref.arch in [.ppc64, .ppc, .sparc64, .s390x]
9697
}
9798
else {
9899
return error('invalid \$if condition: unknown cpu_features `${ident}`')

vlib/v/ast/table.v

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,16 @@ fn (mut t Table) rewrite_already_registered_symbol(typ TypeSymbol, existing_idx
11321132
}
11331133
return existing_idx
11341134
}
1135+
// Allow C type aliases to override existing C types (e.g. `type C.WCHAR = u16`
1136+
// on Windows where WCHAR is already registered from system headers):
1137+
if typ.kind == .alias && typ.language == .c && existing_symbol.language == .c {
1138+
t.type_symbols[existing_idx] = &TypeSymbol{
1139+
...typ
1140+
idx: existing_idx
1141+
is_builtin: existing_symbol.is_builtin
1142+
}
1143+
return existing_idx
1144+
}
11351145
// Override the already registered builtin types with the actual
11361146
// v struct declarations in the vlib/builtin module sources:
11371147
if (existing_idx >= string_type_idx && existing_idx <= map_type_idx)

vlib/v/gen/c/auto_free_methods.v

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ fn (mut g Gen) gen_free_for_interface(sym ast.TypeSymbol, info ast.Interface, st
118118
continue
119119
}
120120
type_styp := g.gen_type_name_for_free_call(typ_)
121-
fn_builder.writeln('\tif (it->_typ == _${sym.cname}_${sub_sym.cname}_index) { ${type_styp}_free(it->_${sub_sym.cname}); return; }')
121+
free_fn_name := if sub_sym.is_builtin() {
122+
'builtin__${type_styp}_free'
123+
} else {
124+
'${type_styp}_free'
125+
}
126+
fn_builder.writeln('\tif (it->_typ == _${sym.cname}_${sub_sym.cname}_index) { ${free_fn_name}(it->_${sub_sym.cname}); return; }')
122127
}
123128
fn_builder.writeln('}')
124129
}

vlib/v/gen/c/cgen.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7892,7 +7892,8 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
78927892
&& sym.info.parent_type !in [expr_type, ast.string_type]) {
78937893
if sym.kind == .string && !node_typ.is_ptr() {
78947894
cast_label = '*(string*)&'
7895-
} else if !((g.is_cc_msvc && g.styp(node_typ) == g.styp(expr_type))
7895+
} else if !((g.is_cc_msvc && (g.styp(node_typ) == g.styp(expr_type)
7896+
|| g.styp(g.table.unaliased_type(node_typ)) == g.styp(g.table.unaliased_type(expr_type))))
78967897
|| (final_sym.kind == .array_fixed && final_expr_sym == final_sym)) {
78977898
// not cast fixed array, which will use `memcpy`
78987899
cast_label = '(${styp})'

vlib/v/parser/parser.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,8 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
22762276
} else {
22772277
p.name_error = true
22782278
}
2279-
if ast.builtin_array_generic_methods_matcher.matches(field_name) {
2279+
if ast.builtin_array_generic_methods_matcher.matches(field_name) && (p.tok.kind == .lpar
2280+
|| is_generic_call || (p.tok.kind == .not && p.peek_tok.kind == .lpar)) {
22802281
if p.file_backend_mode == .v || p.file_backend_mode == .c {
22812282
p.register_auto_import('builtin.closure')
22822283
}

0 commit comments

Comments
 (0)