1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

*char => charptr everywhere

This commit is contained in:
Alexander Medvednikov 2019-12-01 10:33:26 +03:00
parent 698c3823ee
commit 3fea8f3de5
16 changed files with 30 additions and 28 deletions

View File

@ -43,5 +43,7 @@
+ inline assembly + inline assembly
+ x64 machine code generation (ELF) + x64 machine code generation (ELF)
+ require explicit C.fn definitions, add all missing definitions + require explicit C.fn definitions, add all missing definitions
+ string.index() ?int

View File

@ -330,7 +330,7 @@ pub fn (b []byte) hex() string {
mut hex := malloc(b.len*2+1) mut hex := malloc(b.len*2+1)
mut ptr := &hex[0] mut ptr := &hex[0]
for i := 0; i < b.len ; i++ { 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) return string(hex)
} }

View File

@ -67,7 +67,7 @@ $if msvc {
mut si := &sic.syminfo mut si := &sic.syminfo
si.f_size_of_struct = sizeof(SymbolInfo) // Note: C.SYMBOL_INFO is 88 si.f_size_of_struct = sizeof(SymbolInfo) // Note: C.SYMBOL_INFO is 88
si.f_max_name_len = sizeof(SymbolInfoContainer) - sizeof(SymbolInfo) - 1 si.f_max_name_len = sizeof(SymbolInfoContainer) - sizeof(SymbolInfo) - 1
fname := *char( &si.f_name ) fname := charptr( &si.f_name )
mut sline64 := Line64{} mut sline64 := Line64{}
sline64.f_size_of_struct = sizeof(Line64) sline64.f_size_of_struct = sizeof(Line64)

View File

@ -8,13 +8,13 @@ module builtin
pub fn (d f64) str() string { pub fn (d f64) str() string {
buf := malloc(sizeof(double) * 5 + 1)// TODO buf := malloc(sizeof(double) * 5 + 1)// TODO
C.sprintf(*char(buf), '%f', d) C.sprintf(charptr(buf), '%f', d)
return tos(buf, vstrlen(buf)) return tos(buf, vstrlen(buf))
} }
pub fn (d f32) str() string { pub fn (d f32) str() string {
buf := malloc(sizeof(double) * 5 + 1)// TODO buf := malloc(sizeof(double) * 5 + 1)// TODO
C.sprintf(*char(buf), '%f', d) C.sprintf(charptr(buf), '%f', d)
return tos(buf, vstrlen(buf)) return tos(buf, vstrlen(buf))
} }

View File

@ -6,7 +6,7 @@ module builtin
pub fn ptr_str(ptr voidptr) string { pub fn ptr_str(ptr voidptr) string {
buf := malloc(sizeof(double) * 5 + 1)// TODO buf := malloc(sizeof(double) * 5 + 1)// TODO
C.sprintf(*char(buf), '%p', ptr) C.sprintf(charptr(buf), '%p', ptr)
return tos(buf, vstrlen(buf)) return tos(buf, vstrlen(buf))
} }
@ -139,7 +139,7 @@ pub fn (n int) hex() string {
11 11
} }
hex := malloc(len) // 0x + \n 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) return tos(hex, count)
} }
@ -150,7 +150,7 @@ pub fn (n i64) hex() string {
19 19
} }
hex := malloc(len) 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) return tos(hex, count)
} }

View File

@ -60,7 +60,7 @@ pub:
} }
pub fn vstrlen(s byteptr) int { pub fn vstrlen(s byteptr) int {
return C.strlen(*char(s)) return C.strlen(charptr(s))
} }
// Converts a C string to a V string. // Converts a C string to a V string.
@ -200,11 +200,11 @@ pub fn (s string) i64() i64 {
} }
pub fn (s string) f32() f32 { pub fn (s string) f32() f32 {
return C.atof(*char(s.str)) return C.atof(charptr(s.str))
} }
pub fn (s string) f64() f64 { pub fn (s string) f64() f64 {
return C.atof(*char(s.str)) return C.atof(charptr(s.str))
} }
pub fn (s string) u32() u32 { pub fn (s string) u32() u32 {

View File

@ -181,8 +181,8 @@ fn test_replace() {
assert lol.replace('lol', 'LOL') == 'LOL LOL LOL' assert lol.replace('lol', 'LOL') == 'LOL LOL LOL'
b = 'oneBtwoBBthree' b = 'oneBtwoBBthree'
assert b.replace('B', '') == 'onetwothree' assert b.replace('B', '') == 'onetwothree'
b = '**char' b = '*charptr'
assert b.replace('*char', 'byteptr') == '*byteptr' assert b.replace('charptr', 'byteptr') == '*byteptr'
c :='abc' c :='abc'
assert c.replace('','-') == c assert c.replace('','-') == c
} }

View File

@ -1122,7 +1122,7 @@ pub fn verror(s string) {
pub fn vhash() string { pub fn vhash() string {
mut buf := [50]byte mut buf := [50]byte
buf[0] = 0 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) return tos_clone(buf)
} }

View File

@ -122,7 +122,7 @@ pub fn file_size(path string) int {
$if windows { $if windows {
C._wstat(path.to_wide(), voidptr(&s)) C._wstat(path.to_wide(), voidptr(&s))
} $else { } $else {
C.stat(*char(path.str), &s) C.stat(charptr(path.str), &s)
} }
return s.st_size return s.st_size
} }
@ -131,7 +131,7 @@ pub fn mv(old, new string) {
$if windows { $if windows {
C._wrename(old.to_wide(), new.to_wide()) C._wrename(old.to_wide(), new.to_wide())
} $else { } $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 { $if windows {
return C._wfopen(path.to_wide(), mode.to_wide()) return C._wfopen(path.to_wide(), mode.to_wide())
} $else { } $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 { } $else {
cpath := path.str cpath := path.str
file = File { file = File {
cfile: C.fopen(*char(cpath), 'rb') cfile: C.fopen(charptr(cpath), 'rb')
} }
} }
if isnil(file.cfile) { if isnil(file.cfile) {
@ -296,7 +296,7 @@ pub fn create(path string) ?File {
} $else { } $else {
cpath := path.str cpath := path.str
file = File { file = File {
cfile: C.fopen(*char(cpath), 'wb') cfile: C.fopen(charptr(cpath), 'wb')
} }
} }
if isnil(file.cfile) { if isnil(file.cfile) {
@ -316,7 +316,7 @@ pub fn open_append(path string) ?File {
} $else { } $else {
cpath := path.str cpath := path.str
file = File { file = File {
cfile: C.fopen(*char(cpath), 'ab') cfile: C.fopen(charptr(cpath), 'ab')
} }
} }
if isnil(file.cfile) { if isnil(file.cfile) {
@ -618,7 +618,7 @@ pub fn get_raw_line() string {
return '' return ''
} $else { } $else {
max := size_t(256) max := size_t(256)
buf := *char(malloc(int(max))) buf := charptr(malloc(int(max)))
nr_chars := C.getline(&buf, &max, stdin) nr_chars := C.getline(&buf, &max, stdin)
if nr_chars == 0 { if nr_chars == 0 {
return '' return ''
@ -859,7 +859,7 @@ pub fn getwd() string {
// NB: this particular rabbit hole is *deep* ... // NB: this particular rabbit hole is *deep* ...
pub fn realpath(fpath string) string { pub fn realpath(fpath string) string {
mut fullpath := calloc(MAX_PATH) mut fullpath := calloc(MAX_PATH)
mut ret := *char(0) mut ret := charptr(0)
$if windows { $if windows {
ret = C._fullpath(fullpath, fpath.str, MAX_PATH) ret = C._fullpath(fullpath, fpath.str, MAX_PATH)
if ret == 0 { if ret == 0 {

View File

@ -83,7 +83,7 @@ pub fn exec(cmd string) ?Result {
} }
buf := [1000]byte buf := [1000]byte
mut res := '' mut res := ''
for C.fgets(*char(buf), 1000, f) != 0 { for C.fgets(charptr(buf), 1000, f) != 0 {
res += tos(buf, vstrlen(buf)) res += tos(buf, vstrlen(buf))
} }
res = res.trim_space() res = res.trim_space()