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

ci: fix compilation

This commit is contained in:
Delyan Angelov 2021-04-04 20:14:51 +03:00
parent 824790a2bd
commit accd4d83bf
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
7 changed files with 115 additions and 11 deletions

View File

@ -13,7 +13,7 @@ fn new_a2d(maxx int, maxy int) &A2D {
return &A2D{
maxx: maxx
maxy: maxy
data: &int(vcalloc(size))
data: unsafe { &int(vcalloc(size)) }
}
}

View File

@ -91,7 +91,7 @@ fn new_image(w int, h int) Image {
return Image{
width: w
height: h
data: &Vec(vcalloc(vecsize * w * h))
data: unsafe { &Vec(vcalloc(vecsize * w * h)) }
}
}

View File

@ -653,6 +653,6 @@ pub fn (data voidptr) vbytes(len int) []byte {
// byteptr.vbytes() - makes a V []byte structure from a C style memory buffer. NB: the data is reused, NOT copied!
[unsafe]
pub fn (data byteptr) vbytes(len int) []byte {
pub fn (data &byte) vbytes(len int) []byte {
return unsafe { voidptr(data).vbytes(len) }
}

View File

@ -43,7 +43,7 @@ NB: A V string should be/is immutable from the point of view of
*/
pub struct string {
pub:
str &byte // points to a C style 0 terminated string of bytes.
str &byte = 0 // points to a C style 0 terminated string of bytes.
len int // the length of the .str field, excluding the ending 0 byte. It is always equal to strlen(.str).
mut:
is_lit int

View File

@ -0,0 +1,104 @@
module builtin
// NB: this file will be removed soon
// byteptr.vbytes() - makes a V []byte structure from a C style memory buffer. NB: the data is reused, NOT copied!
[unsafe]
pub fn (data byteptr) vbytes(len int) []byte {
return unsafe { voidptr(data).vbytes(len) }
}
// vstring converts a C style string to a V string. NB: the string data is reused, NOT copied.
// strings returned from this function will be normal V strings beside that (i.e. they would be
// freed by V's -autofree mechanism, when they are no longer used).
[unsafe]
pub fn (bp byteptr) vstring() string {
return string{
str: bp
len: unsafe { C.strlen(&char(bp)) }
}
}
// vstring_with_len converts a C style string to a V string.
// NB: the string data is reused, NOT copied.
[unsafe]
pub fn (bp byteptr) vstring_with_len(len int) string {
return string{
str: bp
len: len
is_lit: 0
}
}
// vstring converts C char* to V string.
// NB: the string data is reused, NOT copied.
[unsafe]
pub fn (cp charptr) vstring() string {
return string{
str: byteptr(cp)
len: unsafe { C.strlen(&char(cp)) }
is_lit: 0
}
}
// vstring_with_len converts C char* to V string.
// NB: the string data is reused, NOT copied.
[unsafe]
pub fn (cp charptr) vstring_with_len(len int) string {
return string{
str: byteptr(cp)
len: len
is_lit: 0
}
}
// vstring_literal converts a C style string to a V string.
// NB: the string data is reused, NOT copied.
// NB2: unlike vstring, vstring_literal will mark the string
// as a literal, so it will not be freed by autofree.
// This is suitable for readonly strings, C string literals etc,
// that can be read by the V program, but that should not be
// managed by it, for example `os.args` is implemented using it.
[unsafe]
pub fn (bp byteptr) vstring_literal() string {
return string{
str: bp
len: unsafe { C.strlen(&char(bp)) }
is_lit: 1
}
}
// vstring_with_len converts a C style string to a V string.
// NB: the string data is reused, NOT copied.
[unsafe]
pub fn (bp byteptr) vstring_literal_with_len(len int) string {
return string{
str: bp
len: len
is_lit: 1
}
}
// vstring_literal converts C char* to V string.
// See also vstring_literal defined on byteptr for more details.
// NB: the string data is reused, NOT copied.
[unsafe]
pub fn (cp charptr) vstring_literal() string {
return string{
str: byteptr(cp)
len: unsafe { C.strlen(&char(cp)) }
is_lit: 1
}
}
// vstring_literal_with_len converts C char* to V string.
// See also vstring_literal_with_len defined on byteptr.
// NB: the string data is reused, NOT copied.
[unsafe]
pub fn (cp charptr) vstring_literal_with_len(len int) string {
return string{
str: byteptr(cp)
len: len
is_lit: 1
}
}

View File

@ -190,12 +190,12 @@ fn json_parse(s string) &C.cJSON {
// json_string := json_print(encode_User(user))
fn json_print(json &C.cJSON) string {
s := C.cJSON_PrintUnformatted(json)
return unsafe { tos(byteptr(s), C.strlen(s)) }
return unsafe { tos(byteptr(s), C.strlen(&char(s))) }
}
fn json_print_pretty(json &C.cJSON) string {
s := C.cJSON_Print(json)
return unsafe { tos(byteptr(s), C.strlen(s)) }
return unsafe { tos(byteptr(s), C.strlen(&char(s))) }
}
// / cjson wrappers

View File

@ -118,7 +118,7 @@ pub fn file_size(path string) u64 {
$if x64 {
$if windows {
mut swin := C.__stat64{}
C._wstat64(path.to_wide(), voidptr(&swin))
C._wstat64(&char(path.to_wide()), voidptr(&swin))
return swin.st_size
} $else {
C.stat(&char(path.str), &s)
@ -308,7 +308,7 @@ pub fn system(cmd string) int {
unsafe {
arg := [c'/bin/sh', c'-c', &byte(cmd.str), 0]
pid := 0
ret = C.posix_spawn(&pid, '/bin/sh', 0, 0, arg.data, 0)
ret = C.posix_spawn(&pid, c'/bin/sh', 0, 0, arg.data, 0)
status := 0
ret = C.waitpid(pid, &status, 0)
if C.WIFEXITED(status) {
@ -405,7 +405,7 @@ pub fn rm(path string) ? {
// rmdir removes a specified directory.
pub fn rmdir(path string) ? {
$if windows {
rc := C.RemoveDirectory(path.to_wide())
rc := C.RemoveDirectory(&char(path.to_wide()))
if rc == 0 {
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-removedirectorya - 0 is failure
return error('Failed to remove "$path": ' + posix_get_error_msg(C.errno))
@ -566,7 +566,7 @@ pub fn executable() string {
$if windows {
max := 512
size := max * 2 // max_path_len * sizeof(wchar_t)
mut result := &u16(vcalloc(size))
mut result := unsafe { &u16(vcalloc(size)) }
len := C.GetModuleFileName(0, result, max)
// determine if the file is a windows symlink
attrs := C.GetFileAttributesW(result)
@ -575,7 +575,7 @@ pub fn executable() string {
// gets handle with GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0
file := C.CreateFile(result, 0x80000000, 1, 0, 3, 0x80, 0)
if file != voidptr(-1) {
final_path := &u16(vcalloc(size))
final_path := unsafe { &u16(vcalloc(size)) }
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew
final_len := C.GetFinalPathNameByHandleW(file, final_path, size, 0)
if final_len < size {