Skip to content

Commit

Permalink
Merge branch 'vlang:master' into encoding.iconv
Browse files Browse the repository at this point in the history
  • Loading branch information
kbkpbot authored Sep 30, 2024
2 parents 30dd17f + be26233 commit a617594
Show file tree
Hide file tree
Showing 39 changed files with 906 additions and 126 deletions.
276 changes: 276 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

29 changes: 26 additions & 3 deletions cmd/tools/changelog_helper.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module main

import os

const delete_skipped = true

const git_log_cmd = 'git log -n 500 --pretty=format:"%s" --simplify-merges'

enum Category {
Expand Down Expand Up @@ -162,8 +164,15 @@ fn (mut app App) process_line(text string) ! {
if text.contains('checker:') {
category = .checker
} else if is_examples(text) {
// Always skip examples and typos fixes
category = .examples
// println("Skipping line (example) $text")
// return
} else if is_skip(text) {
// Always skip cleanups, typos etc
println('Skipping line (cleanup/typo)\n${text}\n')
if delete_skipped {
delete_processed_line_from_log(text)!
}
return
} else if is_os_support(text) {
category = .os_support
Expand Down Expand Up @@ -196,6 +205,10 @@ fn (mut app App) process_line(text string) ! {
delete_processed_line_from_log(text)!
return
} else {
println('Skipping line (unknown category)\n${text}\n')
// if delete_skipped {
// delete_processed_line_from_log(text)!
//}
return
}
println('process_line: cat=${category} "${text}"')
Expand All @@ -207,7 +220,7 @@ fn (mut app App) process_line(text string) ! {
// exit(0)
//}
if (semicolon_pos < 15
&& prefix in ['checker', 'cgen', 'parser', 'v.parser', 'ast', 'jsgen', 'v.gen.js', 'fmt', 'vfmt', 'tools'])
&& prefix in ['checker', 'cgen', 'parser', 'v.parser', 'ast', 'jsgen', 'v.gen.js', 'fmt', 'vfmt', 'tools', 'examples'])
|| (semicolon_pos < 30 && prefix.contains(', ')) {
s = '- ' + text[semicolon_pos + 2..].capitalize()
}
Expand Down Expand Up @@ -385,6 +398,9 @@ const stdlib_strings = [
'log:',
'flag:',
'regex:',
'tmpl:',
'hash:',
'stbi:',
]

fn is_stdlib(text string) bool {
Expand All @@ -405,6 +421,7 @@ fn is_orm(text string) bool {

const cgen_strings = [
'cgen:',
'cgen,',
'v.gen.c:',
]

Expand Down Expand Up @@ -447,6 +464,8 @@ fn is_improvements(text string) bool {

const examples_strings = [
'example',
]
const skip_strings = [
'tests',
'readme:',
'.md:',
Expand All @@ -460,10 +479,14 @@ fn is_examples(text string) bool {
return is_xxx(text, examples_strings)
}

fn is_skip(text string) bool {
return is_xxx(text, skip_strings)
}

const tools_strings = [
'tools:',
'vpm:',
'ci',
'ci:',
'github:',
'gitignore',
'benchmark',
Expand Down
3 changes: 3 additions & 0 deletions cmd/tools/vdoc/theme/doc.css
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ hr {
.doc-nav > .content a:hover {
text-decoration: underline;
}
.doc-nav .search {
overflow: scroll;
}
.doc-nav .search.hidden {
display: none;
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/tools/vtest-self.v
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const skip_with_fsanitize_memory = [
'vlib/orm/orm_option_time_test.v',
'vlib/db/sqlite/sqlite_test.v',
'vlib/db/sqlite/sqlite_orm_test.v',
'vlib/db/sqlite/sqlite_comptime_field_test.v',
'vlib/db/sqlite/parent_child_test.v',
'vlib/db/sqlite/sqlite_vfs_lowlevel_test.v',
'vlib/v/tests/orm_enum_test.v',
Expand Down Expand Up @@ -240,6 +241,7 @@ const skip_on_ubuntu_musl = [
'vlib/net/http/status_test.v',
'vlib/db/sqlite/sqlite_test.v',
'vlib/db/sqlite/sqlite_orm_test.v',
'vlib/db/sqlite/sqlite_comptime_field_test.v',
'vlib/db/sqlite/sqlite_vfs_lowlevel_test.v',
'vlib/db/sqlite/parent_child_test.v',
'vlib/orm/orm_test.v',
Expand Down
2 changes: 1 addition & 1 deletion v.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Module {
name: 'V'
description: 'The V programming language.'
version: '0.4.7'
version: '0.4.8'
license: 'MIT'
repo_url: 'https://github.com/vlang/v'
dependencies: []
Expand Down
43 changes: 43 additions & 0 deletions vlib/db/sqlite/sqlite_comptime_field_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module main

import db.sqlite

@[table: 'blog']
pub struct Blog {
id int @[primary; sql: serial]
slug string
language string
}

fn records_by_field[T](db sqlite.DB, fieldname string, value string) ![]T {
$for field in T.fields {
if field.name == fieldname {
entries := sql db {
select from Blog where field.name == value
} or { return err }
return entries
}
}
return error('fieldname not found')
}

fn test_main() {
db := sqlite.connect(':memory:')!
sql db {
create table Blog
}!

row := Blog{
slug: 'Test'
language: 'v'
}

sql db {
insert row into Blog
}!
rows := records_by_field[Blog](db, 'language', 'v') or {
println(err)
return
}
assert rows.len == 1
}
34 changes: 34 additions & 0 deletions vlib/encoding/csv/csv_reader_eol_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import encoding.csv

fn test_no_ending() {
data := 'x,y,d
a,b
w'
mut parser := csv.new_reader(data)
mut arr := []string{}
for {
items := parser.read() or { break }
arr << items.join('-')
}
dump(arr)
assert arr[0].str() == 'x-y-d'
assert arr[1].str() == 'a-b'
assert arr[2].str() == 'w'
}

fn test_with_ending() {
data := 'x,y,d
a,b
w
'
mut parser := csv.new_reader(data)
mut arr := []string{}
for {
items := parser.read() or { break }
arr << items.join('-')
}
dump(arr)
assert arr[0].str() == 'x-y-d'
assert arr[1].str() == 'a-b'
assert arr[2].str() == 'w'
}
4 changes: 2 additions & 2 deletions vlib/encoding/csv/reader.v
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn (mut r Reader) read() ![]string {
// }
fn (mut r Reader) read_line() !string {
// last record
if r.row_pos == r.data.len {
if r.row_pos >= r.data.len {
return &EndOfFileError{}
}
le := if r.is_mac_pre_osx_le { '\r' } else { '\n' }
Expand All @@ -108,7 +108,7 @@ fn (mut r Reader) read_line() !string {
}
} else {
// No line ending on file
i = r.data.len - 1
i = r.data.len
}
}
mut line := r.data[r.row_pos..i]
Expand Down
54 changes: 51 additions & 3 deletions vlib/math/big/big_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@ struct AddTest {

// vfmt off
const add_test_data = [
AddTest{ 0, 0, 0},
AddTest{ 1, -1, 0 },
AddTest{ -1, 1, 0 },
AddTest{ 0, 2, 2},
AddTest{ 2, 0, 2 },
AddTest{ 0, -2, -2},
AddTest{ -2, 0, -2 },
AddTest{ 2, -2, 0 },
AddTest{ -2, 2, 0 },
AddTest{ -1, 200, 199},
AddTest{ 200, -1, 199},
AddTest{ -2, 100, 98},
AddTest{ 100, -2, 98},
AddTest{ -100, -2, -102},
AddTest{ -2, -100, -102},
//
AddTest{ 1, 200, 201},
AddTest{ -200, -1, -201},
AddTest{ 2, 100, 102},
AddTest{ -100, -2, -102},
AddTest{ 100, -2, 98},
AddTest{ 2, -100, -98},
//
AddTest{ 2, 3, 5 },
AddTest{ 1024, 1024, 2048 },
AddTest{ 1024, 1024, 2048 },
Expand All @@ -155,6 +178,24 @@ struct SubTest {

// vfmt off
const sub_test_data = [
SubTest{ 0, 0, 0 },
SubTest{ 0, -1, 1 },
SubTest{ -1, 0, -1 },
SubTest{ 1, 1, 0},
SubTest{ 1, -1, 2},
SubTest{ 2, -1, 3},
SubTest{ -1, 2, -3},
SubTest{ -100, 100, -200},
SubTest{ 100, -100, 200},
SubTest{ -100, -100, 0},
//
SubTest{ 1, 200, -199},
SubTest{ -200, -1, -199},
SubTest{ 2, 100, -98},
SubTest{ -100, -2, -98},
SubTest{ 100, -2, 102},
SubTest{ 2, -100, 102},
//
SubTest{ 2, 3, -1 },
SubTest{ 3, 2, 1 },
SubTest{ 1024, 1024, 0 },
Expand All @@ -177,8 +218,13 @@ struct MulTest {
// vfmt off
const mul_test_data = [
MulTest{ 2, 3, 6 },
MulTest{ -2, 0, 0},
MulTest{ 2, 0, 0},
MulTest{ 0, -2, 0},
MulTest{ 0, -2, 0},
MulTest{ -869, 789, -685641 },
MulTest{ -869, 789, -685641 },
MulTest{ 869, -789, -685641 },
MulTest{ -869, -789, 685641 },
MulTest{
'58347508324752098346789015701837509173586123875823769823749056132786590812379812508163208610983759827349812730',
'14213098571932561236783245987342583245873465877179284713298718093758173895718957198751983759745983467856287759872365123980571298307512352359812753907',
Expand Down Expand Up @@ -229,6 +275,8 @@ struct DivTest {

// vfmt off
const div_test_data = [
DivTest{0, 1, 0},
DivTest{0, -1, 0},
DivTest{1234, 10, 123},
DivTest{-1234, 10, -123},
DivTest{1234, -10, -123},
Expand Down Expand Up @@ -545,13 +593,13 @@ fn test_is_odd() {

fn test_addition() {
for t in add_test_data {
assert t.augend.parse() + t.addend.parse() == t.sum.parse()
assert t.augend.parse() + t.addend.parse() == t.sum.parse(), 't.augend: ${t.augend} + t.addend: ${t.addend}'
}
}

fn test_subtraction() {
for t in sub_test_data {
assert t.minuend.parse() - t.subtrahend.parse() == t.difference.parse()
assert t.minuend.parse() - t.subtrahend.parse() == t.difference.parse(), 't.minuend: ${t.minuend} - t.subtrahend: ${t.subtrahend}'
}
}

Expand Down
26 changes: 18 additions & 8 deletions vlib/math/big/integer.v
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,21 @@ pub fn (augend Integer) + (addend Integer) Integer {
return augend.clone()
}
// Non-zero cases
return if augend.signum == addend.signum {
augend.add(addend)
} else { // Unequal signs
augend.subtract(addend)
if augend.signum == addend.signum {
return augend.add(addend)
}
// Unequal signs, left is negative:
if augend.signum == -1 {
// -1 + 5 == 5 - 1
return addend.subtract(augend)
}
// Unequal signs, left is positive:
res := augend.subtract(addend)
cmp := augend.abs_cmp(addend)
if cmp < 0 {
return res.neg()
}
return res
}

// - returns the difference of the integers `minuend` and `subtrahend`
Expand All @@ -317,11 +327,11 @@ pub fn (minuend Integer) - (subtrahend Integer) Integer {
return minuend.clone()
}
// Non-zero cases
return if minuend.signum == subtrahend.signum {
minuend.subtract(subtrahend)
} else {
minuend.add(subtrahend)
if minuend.signum == subtrahend.signum {
return minuend.subtract(subtrahend)
}
// Unequal signs:
return minuend.add(subtrahend)
}

fn (integer Integer) add(addend Integer) Integer {
Expand Down
2 changes: 1 addition & 1 deletion vlib/semver/v.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Module {
name: 'semver'
version: '0.4.7'
version: '0.4.8'
deps: []
}
5 changes: 5 additions & 0 deletions vlib/v/ast/ast.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import v.util
import v.pref
import sync.stdatomic

// V type names that cannot be used as global var name
pub const global_reserved_type_names = ['byte', 'bool', 'char', 'i8', 'i16', 'int', 'i64', 'u8',
'u16', 'u32', 'u64', 'f32', 'f64', 'map', 'string', 'rune', 'usize', 'isize', 'voidptr', 'thread',
'array']

pub type TypeDecl = AliasTypeDecl | FnTypeDecl | SumTypeDecl

// pub const int_type_name = $if amd64 || arm64 {
Expand Down
6 changes: 6 additions & 0 deletions vlib/v/ast/table.v
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,12 @@ pub fn (t &Table) is_interface_var(var ScopeObject) bool {
&& t.sym(var.smartcasts.last()).kind != .interface_
}

@[inline]
pub fn (t &Table) is_interface_smartcast(var ScopeObject) bool {
return var is Var && var.orig_type != 0 && t.sym(var.orig_type).kind == .interface_
&& var.smartcasts.len > 0
}

// only used for debugging V compiler type bugs
pub fn (t &Table) known_type_names() []string {
mut res := []string{cap: t.type_idxs.len}
Expand Down
Loading

0 comments on commit a617594

Please sign in to comment.