*char => charptr everywhere

pull/2944/head
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
+ x64 machine code generation (ELF)
+ require explicit C.fn definitions, add all missing definitions
+ string.index() ?int

View File

@ -13,4 +13,4 @@ fn main(){
fn on_error(p eventbus.Params) {
println(p.get_string("error"))
}
}

View File

@ -24,4 +24,4 @@ pub fn do_work(){
pub fn get_subscriber() eventbus.Subscriber {
return eb.subscriber
}
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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
fn C.ReleaseMutex(voidptr) bool

View File

@ -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))
}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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)
}

View File

@ -111,4 +111,4 @@ fn test_field_or() {
'default'
}
assert mytitle == 'default'
}
}

View File

@ -134,4 +134,4 @@ fn (r mut Registry) delete_entry(index int) {
fn invoke(p voidptr, arr Params){
handler := EventHandler{p}.func
handler(arr)
}
}

View File

@ -39,4 +39,4 @@ fn test_params(){
fn on_test(p eventbus.Params) {
assert p.get_string("eventbus") == "vevent"
}
}

View File

@ -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 {

View File

@ -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()