Skip to content

Commit

Permalink
all: handle C. calls
Browse files Browse the repository at this point in the history
  • Loading branch information
JalonSolov committed Nov 1, 2023
1 parent a63f3e6 commit 28e8c6e
Show file tree
Hide file tree
Showing 118 changed files with 93 additions and 94 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linux_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ jobs:
run: ./v -autofree -o tetris examples/tetris/tetris.v
- name: Build blog tutorial with -autofree
run: ./v -autofree -o blog tutorials/building_a_simple_web_blog_with_vweb/code/blog
- name: Build option_test.v with -autofree
run: ./v -autofree vlib/v/tests/option_test.v
- name: Build option_test.c.v with -autofree
run: ./v -autofree vlib/v/tests/option_test.c.v
- name: V self compilation with -parallel-cc
run: |
./v -o v2 -parallel-cc cmd/v
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:
run: .\v.exe test-self
# - name: Test
# run: .\v.exe test-all
- name: Build option_test.v with -autofree
run: .\v.exe -autofree vlib/v/tests/option_test.v
- name: Build option_test.c.v with -autofree
run: .\v.exe -autofree vlib/v/tests/option_test.c.v
- name: Test v->js
run: ./v -o hi.js examples/hello_v_js.v && node hi.js
- name: Test v binaries
Expand Down
22 changes: 11 additions & 11 deletions cmd/tools/modules/testing/common.v
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub fn new_test_session(_vargs string, will_compile bool) TestSession {
skip_files << 'examples/coroutines/coroutines_bench.v'
$if msvc {
skip_files << 'vlib/v/tests/const_comptime_eval_before_vinit_test.v' // _constructor used
skip_files << 'vlib/v/tests/project_with_cpp_code/compiling_cpp_files_with_a_cplusplus_compiler_test.v'
skip_files << 'vlib/v/tests/project_with_cpp_code/compiling_cpp_files_with_a_cplusplus_compiler_test.c.v'
}
$if solaris {
skip_files << 'examples/gg/gg2.v'
Expand Down Expand Up @@ -230,31 +230,31 @@ pub fn new_test_session(_vargs string, will_compile bool) TestSession {
}
}
if testing.runner_os != 'Linux' || testing.github_job != 'tcc' {
skip_files << 'examples/c_interop_wkhtmltopdf.v' // needs installation of wkhtmltopdf from https://github.com/wkhtmltopdf/packaging/releases
skip_files << 'examples/c_interop_wkhtmltopdf.c.v' // needs installation of wkhtmltopdf from https://github.com/wkhtmltopdf/packaging/releases
skip_files << 'examples/call_v_from_python/test.v' // the example only makes sense to be compiled, when python is installed
skip_files << 'examples/call_v_from_ruby/test.v' // the example only makes sense to be compiled, when ruby is installed
skip_files << 'vlib/vweb/vweb_app_test.v' // imports the `sqlite` module, which in turn includes sqlite3.h
}
$if !macos {
skip_files << 'examples/macos_tray/tray.v'
skip_files << 'examples/macos_tray/tray.c.v'
}
if testing.github_job == 'ubuntu-docker-musl' {
skip_files << 'vlib/net/openssl/openssl_compiles_test.v'
skip_files << 'vlib/net/openssl/openssl_compiles_test.c.v'
skip_files << 'vlib/x/ttf/ttf_test.v'
}
if testing.github_job == 'tests-sanitize-memory-clang' {
skip_files << 'vlib/net/openssl/openssl_compiles_test.v'
skip_files << 'vlib/net/openssl/openssl_compiles_test.c.v'
}
if testing.github_job != 'misc-tooling' {
// These examples need .h files that are produced from the supplied .glsl files,
// using by the shader compiler tools in https://github.com/floooh/sokol-tools-bin/archive/pre-feb2021-api-changes.tar.gz
skip_files << 'examples/sokol/simple_shader_glsl/simple_shader.v'
skip_files << 'examples/sokol/02_cubes_glsl/cube_glsl.v'
skip_files << 'examples/sokol/03_march_tracing_glsl/rt_glsl.v'
skip_files << 'examples/sokol/04_multi_shader_glsl/rt_glsl.v'
skip_files << 'examples/sokol/05_instancing_glsl/rt_glsl.v'
skip_files << 'examples/sokol/simple_shader_glsl/simple_shader.c.v'
skip_files << 'examples/sokol/02_cubes_glsl/cube_glsl.c.v'
skip_files << 'examples/sokol/03_march_tracing_glsl/rt_glsl.c.v'
skip_files << 'examples/sokol/04_multi_shader_glsl/rt_glsl.c.v'
skip_files << 'examples/sokol/05_instancing_glsl/rt_glsl.c.v'
// Skip obj_viewer code in the CI
skip_files << 'examples/sokol/06_obj_viewer/show_obj.v'
skip_files << 'examples/sokol/06_obj_viewer/show_obj.c.v'
// skip the audio examples too on most CI jobs
skip_files << 'examples/sokol/sounds/melody.v'
skip_files << 'examples/sokol/sounds/wav_player.v'
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/tools/vcreate/project_model_bin.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module main

fn (mut c Create) set_bin_project_files(new bool) {
c.files << ProjectFiles{
path: if new { '${c.name}/src/main.v' } else { 'src/main.v' }
path: if new { '${c.name}/src/main.c.v' } else { 'src/main.c.v' }
content: "module main
fn main() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tools/vcreate/project_model_web.v
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ fn auth_verify(token string) bool {
"
}
c.files << ProjectFiles{
path: '${c.name}/src/main.v'
path: '${c.name}/src/main.c.v'
content: "module main
import vweb
Expand Down
2 changes: 1 addition & 1 deletion cmd/tools/vcreate/vcreate.v
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn init_project() {
}
println('Change the description of your project in `v.mod`')
}
if !os.exists('src/main.v') {
if !os.exists('src/main.c.v') {
c.set_bin_project_files(false)
}
c.create_files_and_directories()
Expand Down
8 changes: 4 additions & 4 deletions cmd/tools/vcreate/vcreate_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ fn init_and_check() ! {

// if main file already exist we should not tamper it
mut main_last_modified_time := i64(0)
is_main_file_preexisting := os.exists('src/main.v')
is_main_file_preexisting := os.exists('src/main.c.v')
if is_main_file_preexisting == true {
main_last_modified_time = os.file_last_mod_unix('src/main.v')
main_last_modified_time = os.file_last_mod_unix('src/main.c.v')
}
os.execute_or_exit('${os.quoted_path(@VEXE)} init')

Expand All @@ -27,9 +27,9 @@ fn init_and_check() ! {
assert x.output.trim_space() == 'Hello World!'

if is_main_file_preexisting == true {
assert main_last_modified_time == os.file_last_mod_unix('src/main.v')
assert main_last_modified_time == os.file_last_mod_unix('src/main.c.v')
} else {
assert os.read_file('src/main.v')! == [
assert os.read_file('src/main.c.v')! == [
'module main\n',
'fn main() {',
" println('Hello World!')",
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/tools/vdoc/tests/vdoc_file_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ fn clean_line_endings(s string) string {

[params]
struct CheckOutputParams {
program string = 'some/dir/main.v'
program string = 'some/dir/main.c.v'
cmd string = 'v doc'
main_filename string = 'main.v'
main_filename string = 'main.c.v'
out_filename string = 'main.out'
should_sort bool = true
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/tools/vgret.defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
# 'examples/hot_reload/graph.v' // Inaccurate captures
# 'examples/ttf_font/example_ttf.v', // OK
# 'examples/sokol/01_cubes/cube.v', // Can pass with a warning and diff at around 1.2%
# 'examples/sokol/02_cubes_glsl/cube_glsl.v', // Inaccurate captures
# 'examples/sokol/03_march_tracing_glsl/rt_glsl.v', // Inaccurate captures
# 'examples/sokol/04_multi_shader_glsl/rt_glsl.v', // Inaccurate captures
# 'examples/sokol/05_instancing_glsl/rt_glsl.v', // Inaccurate captures
# 'examples/sokol/06_obj_viewer/show_obj.v', // Inaccurate captures
# 'examples/sokol/02_cubes_glsl/cube_glsl.c.v', // Inaccurate captures
# 'examples/sokol/03_march_tracing_glsl/rt_glsl.c.v', // Inaccurate captures
# 'examples/sokol/04_multi_shader_glsl/rt_glsl.c.v', // Inaccurate captures
# 'examples/sokol/05_instancing_glsl/rt_glsl.c.v', // Inaccurate captures
# 'examples/sokol/06_obj_viewer/show_obj.c.v', // Inaccurate captures
4 changes: 2 additions & 2 deletions cmd/tools/vrepl.v
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ fn print_welcome_screen() {
cmd_list := highlight_repl_command('list')
cmd_help := highlight_repl_command('help')
cmd_v_help := highlight_console_command('v help')
cmd_v_run := highlight_console_command('v run main.v')
file_main := highlight_console_command('main.v')
cmd_v_run := highlight_console_command('v run main.c.v')
file_main := highlight_console_command('main.c.v')
vbar := term.bright_green('|')
width, _ := term.get_terminal_size() // get the size of the terminal
vlogo := [
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions cmd/tools/vtest-self.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
'vlib/builtin/float_test.v',
'vlib/builtin/byte_test.v',
'vlib/builtin/rune_test.v',
'vlib/builtin/builtin_test.v',
'vlib/builtin/builtin_test.c.v',
'vlib/builtin/map_of_floats_test.v',
'vlib/builtin/string_int_test.v',
'vlib/builtin/utf8_test.v',
Expand Down Expand Up @@ -49,11 +49,11 @@ const (
'vlib/io/os_file_reader_test.v',
'vlib/os/process_test.v',
'vlib/os/file_test.v',
'vlib/os/notify/notify_test.v',
'vlib/os/notify/notify_test.c.v',
'vlib/os/filepath_test.v',
'vlib/os/environment_test.v',
'vlib/os/glob_test.v',
'vlib/os/os_test.v',
'vlib/os/os_test.c.v',
'vlib/rand/random_numbers_test.v',
'vlib/rand/wyrand/wyrand_test.v',
'vlib/runtime/runtime_test.v',
Expand All @@ -63,7 +63,7 @@ const (
'vlib/sync/waitgroup_test.v',
'vlib/sync/pool/pool_test.v',
'vlib/strings/builder_test.v',
'vlib/strconv/atof_test.v',
'vlib/strconv/atof_test.c.v',
'vlib/strconv/atoi_test.v',
'vlib/strconv/f32_f64_to_string_test.v',
'vlib/strconv/format_test.v',
Expand Down Expand Up @@ -180,7 +180,7 @@ const (
'vlib/v/tests/orm_enum_test.v',
'vlib/v/tests/orm_sub_array_struct_test.v',
'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v',
'vlib/v/tests/project_with_cpp_code/compiling_cpp_files_with_a_cplusplus_compiler_test.v', // fails compilation with: undefined reference to vtable for __cxxabiv1::__function_type_info'
'vlib/v/tests/project_with_cpp_code/compiling_cpp_files_with_a_cplusplus_compiler_test.c.v', // fails compilation with: undefined reference to vtable for __cxxabiv1::__function_type_info'
]
skip_with_werror = [
'do_not_remove',
Expand Down Expand Up @@ -259,7 +259,7 @@ const (
'vlib/v/tests/const_and_global_with_same_name_test.v', // error C2099: initializer is not a constant
'vlib/v/tests/sumtype_as_cast_1_test.v', // error: cannot support compound statement expression ({expr; expr; expr;})
'vlib/v/tests/sumtype_as_cast_2_test.v', // error: cannot support compound statement expression ({expr; expr; expr;})
'vlib/v/tests/project_with_cpp_code/compiling_cpp_files_with_a_cplusplus_compiler_test.v', // TODO
'vlib/v/tests/project_with_cpp_code/compiling_cpp_files_with_a_cplusplus_compiler_test.c.v', // TODO
]
skip_on_windows = [
'do_not_remove',
Expand All @@ -271,7 +271,7 @@ const (
'vlib/net/unix/unix_test.v',
'vlib/net/unix/use_net_and_net_unix_together_test.v',
'vlib/net/websocket/websocket_test.v',
'vlib/net/openssl/openssl_compiles_test.v',
'vlib/net/openssl/openssl_compiles_test.c.v',
'vlib/net/http/request_test.v',
'vlib/net/smtp/smtp_test.v',
'vlib/net/ssl/ssl_compiles_test.v',
Expand Down Expand Up @@ -352,7 +352,7 @@ fn main() {

$if windows {
if github_job == 'tcc' {
tsession.skip_files << 'vlib/v/tests/project_with_cpp_code/compiling_cpp_files_with_a_cplusplus_compiler_test.v'
tsession.skip_files << 'vlib/v/tests/project_with_cpp_code/compiling_cpp_files_with_a_cplusplus_compiler_test.c.v'
}
}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/js_dom_draw_bechmark_chart/chart/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ WORKDIR /app

COPY . .

RUN v up && v -prod main.v
RUN v up && v -prod main.c.v
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion vlib/builtin/js/string_test.js.v
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ fn test_runes() {
}

fn test_contains() {
s := 'view.v'
s := 'view.c.v'
assert s.contains('vi')
assert !s.contains('random')
assert ''.contains('')
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion vlib/builtin/string_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ fn test_runes() {
}

fn test_contains() {
s := 'view.v'
s := 'view.c.v'
assert s.contains('vi')
assert !s.contains('random')
assert ''.contains('')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions vlib/db/pg/orm.v
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,6 @@ pub fn (db DB) drop(table string) ! {

// utils

fn pg_stmt_worker(db DB, query string, data orm.QueryData, where orm.QueryData) ![]Row {
mut param_types := []u32{}
mut param_vals := []&char{}
mut param_lens := []int{}
mut param_formats := []int{}

pg_stmt_binder(mut param_types, mut param_vals, mut param_lens, mut param_formats,
data)
pg_stmt_binder(mut param_types, mut param_vals, mut param_lens, mut param_formats,
where)

res := C.PQexecParams(db.conn, &char(query.str), param_vals.len, param_types.data,
param_vals.data, param_lens.data, param_formats.data, 0) // here, the last 0 means require text results, 1 - binary results
return db.handle_error_or_result(res, 'orm_stmt_worker')
}

fn pg_stmt_binder(mut types []u32, mut vals []&char, mut lens []int, mut formats []int, d orm.QueryData) {
for data in d.data {
pg_stmt_match(mut types, mut vals, mut lens, mut formats, data)
Expand Down
17 changes: 17 additions & 0 deletions vlib/db/pg/pg.v → vlib/db/pg/pg.c.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module pg

import io
import orm

$if $pkgconfig('libpq') {
#pkgconfig --cflags --libs libpq
Expand Down Expand Up @@ -363,3 +364,19 @@ pub fn (db DB) copy_expert(query string, mut file io.ReaderWriter) !int {

return 0
}

fn pg_stmt_worker(db DB, query string, data orm.QueryData, where orm.QueryData) ![]Row {
mut param_types := []u32{}
mut param_vals := []&char{}
mut param_lens := []int{}
mut param_formats := []int{}

pg_stmt_binder(mut param_types, mut param_vals, mut param_lens, mut param_formats,
data)
pg_stmt_binder(mut param_types, mut param_vals, mut param_lens, mut param_formats,
where)

res := C.PQexecParams(db.conn, &char(query.str), param_vals.len, param_types.data,
param_vals.data, param_lens.data, param_formats.data, 0) // here, the last 0 means require text results, 1 - binary results
return db.handle_error_or_result(res, 'orm_stmt_worker')
}
File renamed without changes.
4 changes: 1 addition & 3 deletions vlib/db/sqlite/sqlite_vfs_lowlevel_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ fn example_vfsfile_read(file &sqlite.Sqlite3_file, output voidptr, amount int, o

vfsfile.vfs_state.log << 'read file=${vfsfile.name}'

unsafe {
C.memset(output, 0, amount)
}
unsafe { vmemset(output, 0, amount) }

return sqlite.sqlite_ioerr_short_read
}
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions vlib/encoding/base64/base64_memory_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn test_long_encoding() {
//
encoded_size := base64.encode_in_buffer(s_original, ebuffer)
mut encoded_in_buf := []u8{len: encoded_size}
unsafe { C.memcpy(encoded_in_buf.data, ebuffer, encoded_size) }
unsafe { vmemcpy(encoded_in_buf.data, ebuffer, encoded_size) }
assert input_size * 4 / 3 == encoded_size
assert encoded_in_buf[0] == `Y`
assert encoded_in_buf[1] == `W`
Expand All @@ -38,7 +38,7 @@ fn test_long_encoding() {
decoded_size := base64.decode_in_buffer(s_encoded, dbuffer)
assert decoded_size == input_size
mut decoded_in_buf := []u8{len: decoded_size}
unsafe { C.memcpy(decoded_in_buf.data, dbuffer, decoded_size) }
unsafe { vmemcpy(decoded_in_buf.data, dbuffer, decoded_size) }
assert decoded_in_buf == s_original

mut s := 0
Expand Down
6 changes: 4 additions & 2 deletions vlib/encoding/utf8/utf8_util.v
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,13 @@ fn up_low(s string, upper_flag bool) string {
if ch_len == 1 {
if upper_flag == true {
unsafe {
str_res[index] = u8(C.toupper(s.str[index]))
c := str_res[index]
str_res[index] = if (c > 0x60 && c < 0x7b) { c - 0x60 } else { c }
}
} else {
unsafe {
str_res[index] = u8(C.tolower(s.str[index]))
c := str_res[index]
str_res[index] = if (c > 0x40 && c < 0x5b) { c + 0x20 } else { c }
}
}
} else if ch_len > 1 && ch_len < 5 {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 28e8c6e

Please sign in to comment.