From 3fea8f3de59336bc7a226274b3f89da3ad79b952 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 1 Dec 2019 10:33:26 +0300 Subject: [PATCH] *char => charptr everywhere --- 0.2_roadmap.txt | 2 ++ examples/eventbus/eventbus.v | 2 +- examples/eventbus/some_module/some_module.v | 2 +- vlib/builtin/array.v | 2 +- vlib/builtin/builtin_windows.v | 2 +- vlib/builtin/cfns.v | 2 +- vlib/builtin/float.v | 4 ++-- vlib/builtin/int.v | 6 +++--- vlib/builtin/string.v | 6 +++--- vlib/builtin/string_test.v | 4 ++-- vlib/compiler/main.v | 2 +- vlib/compiler/tests/option_test.v | 2 +- vlib/eventbus/eventbus.v | 2 +- vlib/eventbus/eventbus_test.v | 2 +- vlib/os/os.v | 16 ++++++++-------- vlib/os/os_nix.v | 2 +- 16 files changed, 30 insertions(+), 28 deletions(-) diff --git a/0.2_roadmap.txt b/0.2_roadmap.txt index 20afb921f5..faa2f44cb1 100644 --- a/0.2_roadmap.txt +++ b/0.2_roadmap.txt @@ -43,5 +43,7 @@ + inline assembly + x64 machine code generation (ELF) + require explicit C.fn definitions, add all missing definitions ++ string.index() ?int + diff --git a/examples/eventbus/eventbus.v b/examples/eventbus/eventbus.v index cedc2004b4..ac4c68d8aa 100644 --- a/examples/eventbus/eventbus.v +++ b/examples/eventbus/eventbus.v @@ -13,4 +13,4 @@ fn main(){ fn on_error(p eventbus.Params) { println(p.get_string("error")) -} \ No newline at end of file +} diff --git a/examples/eventbus/some_module/some_module.v b/examples/eventbus/some_module/some_module.v index f7db6b9555..5fd501f691 100644 --- a/examples/eventbus/some_module/some_module.v +++ b/examples/eventbus/some_module/some_module.v @@ -24,4 +24,4 @@ pub fn do_work(){ pub fn get_subscriber() eventbus.Subscriber { return eb.subscriber -} \ No newline at end of file +} diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 85671c138f..997497dca7 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -330,7 +330,7 @@ pub fn (b []byte) hex() string { mut hex := malloc(b.len*2+1) mut ptr := &hex[0] for i := 0; i < b.len ; i++ { - ptr += C.sprintf(*char(ptr), '%02x', b[i]) + ptr += C.sprintf(charptr(ptr), '%02x', b[i]) } return string(hex) } diff --git a/vlib/builtin/builtin_windows.v b/vlib/builtin/builtin_windows.v index c27f7c4139..ea04878492 100644 --- a/vlib/builtin/builtin_windows.v +++ b/vlib/builtin/builtin_windows.v @@ -67,7 +67,7 @@ $if msvc { mut si := &sic.syminfo si.f_size_of_struct = sizeof(SymbolInfo) // Note: C.SYMBOL_INFO is 88 si.f_max_name_len = sizeof(SymbolInfoContainer) - sizeof(SymbolInfo) - 1 - fname := *char( &si.f_name ) + fname := charptr( &si.f_name ) mut sline64 := Line64{} sline64.f_size_of_struct = sizeof(Line64) diff --git a/vlib/builtin/cfns.v b/vlib/builtin/cfns.v index a803c611b7..a324ef6bb6 100644 --- a/vlib/builtin/cfns.v +++ b/vlib/builtin/cfns.v @@ -161,4 +161,4 @@ fn C.CreateDirectory(byteptr, int) bool fn C.BCryptGenRandom(int,voidptr,int,int) int fn C.CreateMutex(int,bool,byteptr) voidptr fn C.WaitForSingleObject(voidptr,int) int -fn C.ReleaseMutex(voidptr) bool \ No newline at end of file +fn C.ReleaseMutex(voidptr) bool diff --git a/vlib/builtin/float.v b/vlib/builtin/float.v index adcc189c05..b7651753bc 100644 --- a/vlib/builtin/float.v +++ b/vlib/builtin/float.v @@ -8,13 +8,13 @@ module builtin pub fn (d f64) str() string { buf := malloc(sizeof(double) * 5 + 1)// TODO - C.sprintf(*char(buf), '%f', d) + C.sprintf(charptr(buf), '%f', d) return tos(buf, vstrlen(buf)) } pub fn (d f32) str() string { buf := malloc(sizeof(double) * 5 + 1)// TODO - C.sprintf(*char(buf), '%f', d) + C.sprintf(charptr(buf), '%f', d) return tos(buf, vstrlen(buf)) } diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index ce1191fb5e..36cc0319bb 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -6,7 +6,7 @@ module builtin pub fn ptr_str(ptr voidptr) string { buf := malloc(sizeof(double) * 5 + 1)// TODO - C.sprintf(*char(buf), '%p', ptr) + C.sprintf(charptr(buf), '%p', ptr) return tos(buf, vstrlen(buf)) } @@ -139,7 +139,7 @@ pub fn (n int) hex() string { 11 } hex := malloc(len) // 0x + \n - count := int(C.sprintf(*char(hex), '0x%x', n)) + count := int(C.sprintf(charptr(hex), '0x%x', n)) return tos(hex, count) } @@ -150,7 +150,7 @@ pub fn (n i64) hex() string { 19 } hex := malloc(len) - count := int(C.sprintf(*char(hex), '0x%' C.PRIx64, n)) + count := int(C.sprintf(charptr(hex), '0x%' C.PRIx64, n)) return tos(hex, count) } diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 07a2c1744b..515d53e194 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -60,7 +60,7 @@ pub: } pub fn vstrlen(s byteptr) int { - return C.strlen(*char(s)) + return C.strlen(charptr(s)) } // Converts a C string to a V string. @@ -200,11 +200,11 @@ pub fn (s string) i64() i64 { } pub fn (s string) f32() f32 { - return C.atof(*char(s.str)) + return C.atof(charptr(s.str)) } pub fn (s string) f64() f64 { - return C.atof(*char(s.str)) + return C.atof(charptr(s.str)) } pub fn (s string) u32() u32 { diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 7e69a44967..4bfe4c50d9 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -181,8 +181,8 @@ fn test_replace() { assert lol.replace('lol', 'LOL') == 'LOL LOL LOL' b = 'oneBtwoBBthree' assert b.replace('B', '') == 'onetwothree' - b = '**char' - assert b.replace('*char', 'byteptr') == '*byteptr' + b = '*charptr' + assert b.replace('charptr', 'byteptr') == '*byteptr' c :='abc' assert c.replace('','-') == c } diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index 7b22f3480c..1784dcbfa2 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -1122,7 +1122,7 @@ pub fn verror(s string) { pub fn vhash() string { mut buf := [50]byte buf[0] = 0 - C.snprintf(*char(buf), 50, '%s', C.V_COMMIT_HASH ) + C.snprintf(charptr(buf), 50, '%s', C.V_COMMIT_HASH ) return tos_clone(buf) } diff --git a/vlib/compiler/tests/option_test.v b/vlib/compiler/tests/option_test.v index 098d822fa0..40e1399bc6 100644 --- a/vlib/compiler/tests/option_test.v +++ b/vlib/compiler/tests/option_test.v @@ -111,4 +111,4 @@ fn test_field_or() { 'default' } assert mytitle == 'default' -} \ No newline at end of file +} diff --git a/vlib/eventbus/eventbus.v b/vlib/eventbus/eventbus.v index 8a3986447e..70cd3e65a2 100644 --- a/vlib/eventbus/eventbus.v +++ b/vlib/eventbus/eventbus.v @@ -134,4 +134,4 @@ fn (r mut Registry) delete_entry(index int) { fn invoke(p voidptr, arr Params){ handler := EventHandler{p}.func handler(arr) -} \ No newline at end of file +} diff --git a/vlib/eventbus/eventbus_test.v b/vlib/eventbus/eventbus_test.v index 92cf9b0712..17df358e60 100644 --- a/vlib/eventbus/eventbus_test.v +++ b/vlib/eventbus/eventbus_test.v @@ -39,4 +39,4 @@ fn test_params(){ fn on_test(p eventbus.Params) { assert p.get_string("eventbus") == "vevent" -} \ No newline at end of file +} diff --git a/vlib/os/os.v b/vlib/os/os.v index 7ec73fb0ba..e0f2c5e267 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -122,7 +122,7 @@ pub fn file_size(path string) int { $if windows { C._wstat(path.to_wide(), voidptr(&s)) } $else { - C.stat(*char(path.str), &s) + C.stat(charptr(path.str), &s) } return s.st_size } @@ -131,7 +131,7 @@ pub fn mv(old, new string) { $if windows { C._wrename(old.to_wide(), new.to_wide()) } $else { - C.rename(*char(old.str), *char(new.str)) + C.rename(charptr(old.str), charptr(new.str)) } } @@ -210,7 +210,7 @@ fn vfopen(path, mode string) *C.FILE { $if windows { return C._wfopen(path.to_wide(), mode.to_wide()) } $else { - return C.fopen(*char(path.str), *char(mode.str)) + return C.fopen(charptr(path.str), charptr(mode.str)) } } @@ -275,7 +275,7 @@ pub fn open(path string) ?File { } $else { cpath := path.str file = File { - cfile: C.fopen(*char(cpath), 'rb') + cfile: C.fopen(charptr(cpath), 'rb') } } if isnil(file.cfile) { @@ -296,7 +296,7 @@ pub fn create(path string) ?File { } $else { cpath := path.str file = File { - cfile: C.fopen(*char(cpath), 'wb') + cfile: C.fopen(charptr(cpath), 'wb') } } if isnil(file.cfile) { @@ -316,7 +316,7 @@ pub fn open_append(path string) ?File { } $else { cpath := path.str file = File { - cfile: C.fopen(*char(cpath), 'ab') + cfile: C.fopen(charptr(cpath), 'ab') } } if isnil(file.cfile) { @@ -618,7 +618,7 @@ pub fn get_raw_line() string { return '' } $else { max := size_t(256) - buf := *char(malloc(int(max))) + buf := charptr(malloc(int(max))) nr_chars := C.getline(&buf, &max, stdin) if nr_chars == 0 { return '' @@ -859,7 +859,7 @@ pub fn getwd() string { // NB: this particular rabbit hole is *deep* ... pub fn realpath(fpath string) string { mut fullpath := calloc(MAX_PATH) - mut ret := *char(0) + mut ret := charptr(0) $if windows { ret = C._fullpath(fullpath, fpath.str, MAX_PATH) if ret == 0 { diff --git a/vlib/os/os_nix.v b/vlib/os/os_nix.v index 7d9263feee..6cee8983e1 100644 --- a/vlib/os/os_nix.v +++ b/vlib/os/os_nix.v @@ -83,7 +83,7 @@ pub fn exec(cmd string) ?Result { } buf := [1000]byte mut res := '' - for C.fgets(*char(buf), 1000, f) != 0 { + for C.fgets(charptr(buf), 1000, f) != 0 { res += tos(buf, vstrlen(buf)) } res = res.trim_space()