Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix_map_as_t
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Dec 29, 2024
2 parents a785110 + 0351332 commit 100021f
Show file tree
Hide file tree
Showing 35 changed files with 772 additions and 692 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/v_apps_and_modules_compile_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,14 @@ jobs:
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
echo "Install vsql"
v retry -- v install elliotchance.vsql ; cd ~/.vmodules/elliotchance/vsql
echo "Generate vsql/grammar.v"
make vsql/grammar.v
v retry -- v install elliotchance.vsql
cd ~/.vmodules/elliotchance/vsql
echo "Compile vsql"
v -o bin/vsql cmd/vsql
echo "Compile vsql with -skip-unused"
v -skip-unused -o bin/vsql cmd/vsql
make bin/vsql
echo "Run examples"
make examples
echo "Run vsql/connection_test.v"
v vsql/connection_test.v
echo "Run vsql/connection_test.v with -skip-unused"
v -skip-unused vsql/connection_test.v
- name: Test discord.v
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
Expand Down
6 changes: 3 additions & 3 deletions cmd/tools/modules/vgit/vgit.v
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub fn (mut vgit_context VGitContext) compile_oldv_if_needed() {
mut c_flags := '-std=gnu11 -I ./thirdparty/stdatomic/nix -w'
mut c_ldflags := '-lm -lpthread'
mut vc_source_file_location := os.join_path_single(vgit_context.path_vc, 'v.c')
mut vc_v_cpermissive_flags := '${vgit_context.cc_options} -Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration -Wno-error=int-conversion'
mut vc_v_cpermissive_flags := '${vgit_context.cc_options} -Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration -Wno-error=int-conversion -fpermissive'
// after 85b58b0 2021-09-28, -no-parallel is supported, and can be used to force the cgen stage to be single threaded, which increases the chances of successful bootstraps
mut vc_v_bootstrap_flags := ''
if vgit_context.commit_v__ts >= 1632778086 {
Expand Down Expand Up @@ -254,10 +254,10 @@ pub fn (mut vgit_context VGitContext) compile_oldv_if_needed() {
c_flags += '-lws2_32'
}
command_for_building_v_from_c_source = c(vgit_context.cc, '${vc_v_cpermissive_flags} ${c_flags} -o cv.exe "${vc_source_file_location}" ${c_ldflags}')
command_for_selfbuilding = c('.\\cv.exe', '${vc_v_bootstrap_flags} -o ${vgit_context.vexename} {SOURCE}')
command_for_selfbuilding = c('.\\cv.exe', '${vc_v_bootstrap_flags} -cflags "${vc_v_cpermissive_flags}" -o ${vgit_context.vexename} {SOURCE}')
} else {
command_for_building_v_from_c_source = c(vgit_context.cc, '${vc_v_cpermissive_flags} ${c_flags} -o cv "${vc_source_file_location}" ${c_ldflags}')
command_for_selfbuilding = c('./cv', '${vc_v_bootstrap_flags} -o ${vgit_context.vexename} {SOURCE}')
command_for_selfbuilding = c('./cv', '${vc_v_bootstrap_flags} -cflags "${vc_v_cpermissive_flags}" -o ${vgit_context.vexename} {SOURCE}')
}

scripting.run(command_for_building_v_from_c_source)
Expand Down
14 changes: 14 additions & 0 deletions vlib/builtin/array.v
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum ArrayFlags {

// Internal function, used by V (`nums := []int`)
fn __new_array(mylen int, cap int, elm_size int) array {
panic_on_negative_len(mylen)
cap_ := if cap < mylen { mylen } else { cap }
arr := array{
element_size: elm_size
Expand All @@ -41,6 +42,7 @@ fn __new_array(mylen int, cap int, elm_size int) array {
}

fn __new_array_with_default(mylen int, cap int, elm_size int, val voidptr) array {
panic_on_negative_len(mylen)
cap_ := if cap < mylen { mylen } else { cap }
mut arr := array{
element_size: elm_size
Expand Down Expand Up @@ -79,6 +81,7 @@ fn __new_array_with_default(mylen int, cap int, elm_size int, val voidptr) array
}

fn __new_array_with_multi_default(mylen int, cap int, elm_size int, val voidptr) array {
panic_on_negative_len(mylen)
cap_ := if cap < mylen { mylen } else { cap }
mut arr := array{
element_size: elm_size
Expand Down Expand Up @@ -106,6 +109,7 @@ fn __new_array_with_multi_default(mylen int, cap int, elm_size int, val voidptr)
}

fn __new_array_with_array_default(mylen int, cap int, elm_size int, val array, depth int) array {
panic_on_negative_len(mylen)
cap_ := if cap < mylen { mylen } else { cap }
mut arr := array{
element_size: elm_size
Expand All @@ -127,6 +131,7 @@ fn __new_array_with_array_default(mylen int, cap int, elm_size int, val array, d
}

fn __new_array_with_map_default(mylen int, cap int, elm_size int, val map) array {
panic_on_negative_len(mylen)
cap_ := if cap < mylen { mylen } else { cap }
mut arr := array{
element_size: elm_size
Expand All @@ -149,6 +154,7 @@ fn __new_array_with_map_default(mylen int, cap int, elm_size int, val map) array

// Private function, used by V (`nums := [1, 2, 3]`)
fn new_array_from_c_array(len int, cap int, elm_size int, c_array voidptr) array {
panic_on_negative_len(len)
cap_ := if cap < len { len } else { cap }
arr := array{
element_size: elm_size
Expand All @@ -163,6 +169,7 @@ fn new_array_from_c_array(len int, cap int, elm_size int, c_array voidptr) array

// Private function, used by V (`nums := [1, 2, 3] !`)
fn new_array_from_c_array_no_alloc(len int, cap int, elm_size int, c_array voidptr) array {
panic_on_negative_len(len)
arr := array{
element_size: elm_size
data: c_array
Expand Down Expand Up @@ -1035,3 +1042,10 @@ pub fn (data voidptr) vbytes(len int) []u8 {
pub fn (data &u8) vbytes(len int) []u8 {
return unsafe { voidptr(data).vbytes(len) }
}

@[if !no_bounds_checking ?; inline]
fn panic_on_negative_len(len int) {
if len < 0 {
panic('negative .len')
}
}
5 changes: 5 additions & 0 deletions vlib/builtin/array_d_gcboehm_opt.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module builtin

fn __new_array_noscan(mylen int, cap int, elm_size int) array {
panic_on_negative_len(mylen)
cap_ := if cap < mylen { mylen } else { cap }
arr := array{
element_size: elm_size
Expand All @@ -17,6 +18,7 @@ fn __new_array_noscan(mylen int, cap int, elm_size int) array {
}

fn __new_array_with_default_noscan(mylen int, cap int, elm_size int, val voidptr) array {
panic_on_negative_len(mylen)
cap_ := if cap < mylen { mylen } else { cap }
mut arr := array{
element_size: elm_size
Expand All @@ -43,6 +45,7 @@ fn __new_array_with_default_noscan(mylen int, cap int, elm_size int, val voidptr
}

fn __new_array_with_multi_default_noscan(mylen int, cap int, elm_size int, val voidptr) array {
panic_on_negative_len(mylen)
cap_ := if cap < mylen { mylen } else { cap }
mut arr := array{
element_size: elm_size
Expand All @@ -59,6 +62,7 @@ fn __new_array_with_multi_default_noscan(mylen int, cap int, elm_size int, val v
}

fn __new_array_with_array_default_noscan(mylen int, cap int, elm_size int, val array) array {
panic_on_negative_len(mylen)
cap_ := if cap < mylen { mylen } else { cap }
mut arr := array{
element_size: elm_size
Expand All @@ -75,6 +79,7 @@ fn __new_array_with_array_default_noscan(mylen int, cap int, elm_size int, val a

// Private function, used by V (`nums := [1, 2, 3]`)
fn new_array_from_c_array_noscan(len int, cap int, elm_size int, c_array voidptr) array {
panic_on_negative_len(len)
cap_ := if cap < len { len } else { cap }
arr := array{
element_size: elm_size
Expand Down
54 changes: 29 additions & 25 deletions vlib/db/sqlite/sqlite.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ fn get_int_from_stmt(stmt &C.sqlite3_stmt) int {
if x != C.SQLITE_OK && x != C.SQLITE_DONE {
C.puts(C.sqlite3_errstr(x))
}

res := C.sqlite3_column_int(stmt, 0)
C.sqlite3_finalize(stmt)
return res
Expand All @@ -183,31 +182,35 @@ pub fn (db &DB) get_affected_rows_count() int {
// q_int returns a single integer value, from the first column of the result of executing `query`, or an error on failure
pub fn (db &DB) q_int(query string) !int {
stmt := &C.sqlite3_stmt(unsafe { nil })
pres := C.sqlite3_prepare_v2(db.conn, &char(query.str), query.len, &stmt, 0)
if pres != sqlite_ok {
return db.error_message(pres, query)
}
defer {
C.sqlite3_finalize(stmt)
}
C.sqlite3_prepare_v2(db.conn, &char(query.str), query.len, &stmt, 0)
code := C.sqlite3_step(stmt)
if code != sqlite_row {
return db.error_message(code, query)
}

res := C.sqlite3_column_int(stmt, 0)
return res
}

// q_string returns a single string value, from the first column of the result of executing `query`, or an error on failure
pub fn (db &DB) q_string(query string) !string {
stmt := &C.sqlite3_stmt(unsafe { nil })
pres := C.sqlite3_prepare_v2(db.conn, &char(query.str), query.len, &stmt, 0)
if pres != sqlite_ok {
return db.error_message(pres, query)
}
defer {
C.sqlite3_finalize(stmt)
}
C.sqlite3_prepare_v2(db.conn, &char(query.str), query.len, &stmt, 0)
code := C.sqlite3_step(stmt)
if code != sqlite_row {
return db.error_message(code, query)
}

val := unsafe { &u8(C.sqlite3_column_text(stmt, 0)) }
return if val != &u8(0) { unsafe { tos_clone(val) } } else { '' }
}
Expand All @@ -216,14 +219,13 @@ pub fn (db &DB) q_string(query string) !string {
@[manualfree]
pub fn (db &DB) exec_map(query string) ![]map[string]string {
stmt := &C.sqlite3_stmt(unsafe { nil })
defer {
C.sqlite3_finalize(stmt)
}
mut code := C.sqlite3_prepare_v2(db.conn, &char(query.str), query.len, &stmt, 0)
if code != sqlite_ok {
return db.error_message(code, query)
}

defer {
C.sqlite3_finalize(stmt)
}
nr_cols := C.sqlite3_column_count(stmt)
mut res := 0
mut rows := []map[string]string{}
Expand All @@ -236,7 +238,7 @@ pub fn (db &DB) exec_map(query string) ![]map[string]string {
for i in 0 .. nr_cols {
val := unsafe { &u8(C.sqlite3_column_text(stmt, i)) }
col_char := unsafe { &u8(C.sqlite3_column_name(stmt, i)) }
col := unsafe { tos_clone(col_char) }
col := unsafe { col_char.vstring() }
if val == &u8(0) {
row[col] = ''
} else {
Expand All @@ -248,18 +250,19 @@ pub fn (db &DB) exec_map(query string) ![]map[string]string {
return rows
}

fn C.sqlite3_memory_used() i64

// exec executes the query on the given `db`, and returns an array of all the results, or an error on failure
@[manualfree]
pub fn (db &DB) exec(query string) ![]Row {
stmt := &C.sqlite3_stmt(unsafe { nil })
defer {
C.sqlite3_finalize(stmt)
}
mut code := C.sqlite3_prepare_v2(db.conn, &char(query.str), query.len, &stmt, 0)
if code != sqlite_ok {
return db.error_message(code, query)
}

defer {
C.sqlite3_finalize(stmt)
}
nr_cols := C.sqlite3_column_count(stmt)
mut res := 0
mut rows := []Row{}
Expand All @@ -276,7 +279,7 @@ pub fn (db &DB) exec(query string) ![]Row {
if val == &u8(0) {
row.vals << ''
} else {
row.vals << unsafe { tos_clone(val) }
row.vals << unsafe { val.vstring() }
}
}
rows << row
Expand Down Expand Up @@ -319,32 +322,34 @@ pub fn (db &DB) error_message(code int, query string) IError {
// e.g. for queries like these: `INSERT INTO ... VALUES (...)`
pub fn (db &DB) exec_none(query string) int {
stmt := &C.sqlite3_stmt(unsafe { nil })
C.sqlite3_prepare_v2(db.conn, &char(query.str), query.len, &stmt, 0)
pres := C.sqlite3_prepare_v2(db.conn, &char(query.str), query.len, &stmt, 0)
if pres != sqlite_ok {
return -1
}
defer {
C.sqlite3_finalize(stmt)
}
code := C.sqlite3_step(stmt)
C.sqlite3_finalize(stmt)
return code
}

// exec_param_many executes a query with parameters provided as ?,
// and returns either an error on failure, or the full result set on success
pub fn (db &DB) exec_param_many(query string, params []string) ![]Row {
mut stmt := &C.sqlite3_stmt(unsafe { nil })
defer {
C.sqlite3_finalize(stmt)
}

mut code := C.sqlite3_prepare_v2(db.conn, &char(query.str), -1, &stmt, 0)
if code != 0 {
return db.error_message(code, query)
}

defer {
C.sqlite3_finalize(stmt)
}
for i, param in params {
code = C.sqlite3_bind_text(stmt, i + 1, voidptr(param.str), param.len, 0)
if code != 0 {
return db.error_message(code, query)
}
}

nr_cols := C.sqlite3_column_count(stmt)
mut res := 0
mut rows := []Row{}
Expand All @@ -362,12 +367,11 @@ pub fn (db &DB) exec_param_many(query string, params []string) ![]Row {
if val == &u8(0) {
row.vals << ''
} else {
row.vals << unsafe { tos_clone(val) }
row.vals << unsafe { val.vstring() }
}
}
rows << row
}

return rows
}

Expand Down
8 changes: 1 addition & 7 deletions vlib/net/http/cookie.v
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,7 @@ pub fn read_cookies(h Header, filter string) []&Cookie {
if part.len == 0 {
continue
}
mut name := part
mut val := ''
if part.contains('=') {
val_parts := part.split('=')
name = val_parts[0]
val = val_parts[1]
}
mut name, mut val := part.split_once('=') or { part, '' }
if !is_cookie_name_valid(name) {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion vlib/net/smtp/smtp.v
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn (mut c Client) reconnect() ! {
conn := net.dial_tcp('${c.server}:${c.port}') or { return error('Connecting to server failed') }
c.conn = conn

if c.ssl {
if c.ssl || c.encrypted {
c.connect_ssl()!
} else {
c.reader = io.new_buffered_reader(reader: c.conn)
Expand Down
2 changes: 1 addition & 1 deletion vlib/os/os.v
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ pub fn input_opt(prompt string) ?string {
}

// input returns a one-line string from stdin, after printing a prompt.
// Returns `EOF` in case of an error (end of input).
// Returns `<EOF>` in case of an error (end of input).
pub fn input(prompt string) string {
res := input_opt(prompt) or { return '<EOF>' }
return res
Expand Down
11 changes: 6 additions & 5 deletions vlib/v/checker/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
&& right.or_expr.kind == .absent {
right_obj_var := right.obj as ast.Var
if right_obj_var.ct_type_var != .no_comptime {
ctyp := c.comptime.get_type(right)
ctyp := c.type_resolver.get_type(right)
if ctyp != ast.void_type {
left.obj.ct_type_var = right_obj_var.ct_type_var
left.obj.typ = ctyp
Expand All @@ -416,7 +416,8 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
} else if left.obj.ct_type_var in [.generic_var, .no_comptime]
&& c.table.cur_fn != unsafe { nil }
&& c.table.cur_fn.generic_names.len != 0
&& !right.comptime_ret_val && c.is_generic_expr(right) {
&& !right.comptime_ret_val
&& c.type_resolver.is_generic_expr(right) {
// mark variable as generic var because its type changes according to fn return generic resolution type
left.obj.ct_type_var = .generic_var
if right.return_type_generic.has_flag(.generic) {
Expand All @@ -428,7 +429,7 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
} else {
fn_ret_type.clear_option_and_result()
}
c.comptime.type_map['g.${left.name}.${left.obj.pos.pos}'] = var_type
c.type_resolver.type_map['g.${left.name}.${left.obj.pos.pos}'] = var_type
}
} else if right.is_static_method
&& right.left_type.has_flag(.generic) {
Expand All @@ -438,7 +439,7 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
} else {
fn_ret_type.clear_option_and_result()
}
c.comptime.type_map['g.${left.name}.${left.obj.pos.pos}'] = var_type
c.type_resolver.type_map['g.${left.name}.${left.obj.pos.pos}'] = var_type
}
}
}
Expand Down Expand Up @@ -514,7 +515,7 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
if (left.is_map || left.is_farray) && left.is_setter {
left.recursive_mapset_is_setter(true)
}
right_type = c.comptime.get_type_or_default(right, right_type)
right_type = c.type_resolver.get_type_or_default(right, right_type)
}
if mut left is ast.InfixExpr {
c.error('cannot use infix expression on the left side of `${node.op}`',
Expand Down
Loading

0 comments on commit 100021f

Please sign in to comment.