mirror of
https://github.com/vlang/v.git
synced 2025-08-03 17:57:59 -04:00
This commit is contained in:
parent
0de2f742f0
commit
a5f400ee77
@ -112,7 +112,7 @@ fn create_server_socket(port int) int {
|
||||
server_fd := C.socket(C.AF_INET, C.SOCK_STREAM, 0)
|
||||
if server_fd < 0 {
|
||||
eprintln(@LOCATION)
|
||||
C.perror('Socket creation failed'.str)
|
||||
C.perror(c'Socket creation failed')
|
||||
return -1
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ fn create_server_socket(port int) int {
|
||||
opt := 1
|
||||
if C.setsockopt(server_fd, C.SOL_SOCKET, C.SO_REUSEPORT, &opt, sizeof(opt)) < 0 {
|
||||
eprintln(@LOCATION)
|
||||
C.perror('setsockopt SO_REUSEPORT failed'.str)
|
||||
C.perror(c'setsockopt SO_REUSEPORT failed')
|
||||
close_socket(server_fd)
|
||||
return -1
|
||||
}
|
||||
@ -136,13 +136,13 @@ fn create_server_socket(port int) int {
|
||||
|
||||
if C.bind(server_fd, voidptr(&server_addr), sizeof(server_addr)) < 0 {
|
||||
eprintln(@LOCATION)
|
||||
C.perror('Bind failed'.str)
|
||||
C.perror(c'Bind failed')
|
||||
close_socket(server_fd)
|
||||
return -1
|
||||
}
|
||||
if C.listen(server_fd, max_connection_size) < 0 {
|
||||
eprintln(@LOCATION)
|
||||
C.perror('Listen failed'.str)
|
||||
C.perror(c'Listen failed')
|
||||
close_socket(server_fd)
|
||||
return -1
|
||||
}
|
||||
@ -157,7 +157,7 @@ fn add_fd_to_epoll(epoll_fd int, fd int, events u32) int {
|
||||
ev.data.fd = fd
|
||||
if C.epoll_ctl(epoll_fd, C.EPOLL_CTL_ADD, fd, &ev) == -1 {
|
||||
eprintln(@LOCATION)
|
||||
C.perror('epoll_ctl'.str)
|
||||
C.perror(c'epoll_ctl')
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
@ -178,7 +178,7 @@ fn handle_accept_loop(mut server Server) {
|
||||
}
|
||||
|
||||
eprintln(@LOCATION)
|
||||
C.perror('Accept failed'.str)
|
||||
C.perror(c'Accept failed')
|
||||
return
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ fn (mut server Server) run() {
|
||||
for i := 0; i < max_thread_pool_size; i++ {
|
||||
server.epoll_fds[i] = C.epoll_create1(0)
|
||||
if server.epoll_fds[i] < 0 {
|
||||
C.perror('epoll_create1 failed'.str)
|
||||
C.perror(c'epoll_create1 failed')
|
||||
close_socket(server.socket_fd)
|
||||
return
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ fn prealloc_vcleanup() {
|
||||
path := $d('memdumpfile', 'memdump.bin')
|
||||
C.fprintf(C.stderr, c'prealloc_vcleanup dumping process memory to path: %s\n',
|
||||
path.str)
|
||||
stream := C.fopen(path.str, 'wb'.str)
|
||||
stream := C.fopen(path.str, c'wb')
|
||||
mut mb := start
|
||||
for {
|
||||
used := u64(mb.current) - u64(mb.start)
|
||||
|
@ -1019,7 +1019,7 @@ fn test_bytes_to_string() {
|
||||
}
|
||||
|
||||
fn test_charptr() {
|
||||
foo := &char('VLANG'.str)
|
||||
foo := &char(c'VLANG')
|
||||
assert typeof(foo).name == '&char'
|
||||
assert unsafe { foo.vstring() } == 'VLANG'
|
||||
assert unsafe { foo.vstring_with_len(3) } == 'VLA'
|
||||
|
@ -125,16 +125,16 @@ fn (mut l Log) log_file(s string, level Level) {
|
||||
|
||||
unsafe {
|
||||
l.ofile.write_ptr(timestamp.str, timestamp.len)
|
||||
l.ofile.write_ptr(' '.str, 1)
|
||||
l.ofile.write_ptr(c' ', 1)
|
||||
|
||||
l.ofile.write_ptr('['.str, 1)
|
||||
l.ofile.write_ptr(c'[', 1)
|
||||
l.ofile.write_ptr(e.str, e.len)
|
||||
l.ofile.write_ptr(']'.str, 1)
|
||||
l.ofile.write_ptr(c']', 1)
|
||||
|
||||
l.ofile.write_ptr(' '.str, 1)
|
||||
l.ofile.write_ptr(c' ', 1)
|
||||
l.ofile.write_ptr(s.str, s.len)
|
||||
|
||||
l.ofile.write_ptr('\n'.str, 1)
|
||||
l.ofile.write_ptr(c'\n', 1)
|
||||
}
|
||||
if l.always_flush {
|
||||
l.flush()
|
||||
|
@ -1,5 +1,5 @@
|
||||
fn main() {
|
||||
sys_write(1, 'hello\n'.str, 6)
|
||||
sys_write(1, c'hello\n', 6)
|
||||
s := 'test string\n'
|
||||
sys_write(1, s.str, u64(s.len))
|
||||
a := s[0]
|
||||
|
@ -230,7 +230,7 @@ pub fn parse_rfc3339(s string) !Time {
|
||||
}
|
||||
|
||||
// Check if it is UTC time
|
||||
if unsafe { vmemcmp(s.str + s.len - 5, '00:00'.str, 5) == 0 } {
|
||||
if unsafe { vmemcmp(s.str + s.len - 5, c'00:00', 5) == 0 } {
|
||||
return new(Time{
|
||||
year: year
|
||||
month: month
|
||||
|
@ -996,6 +996,7 @@ pub:
|
||||
is_test bool // true for _test.v files
|
||||
is_generated bool // true for `@[generated] module xyz` files; turn off notices
|
||||
is_translated bool // true for `@[translated] module xyz` files; turn off some checks
|
||||
language Language
|
||||
pub mut:
|
||||
idx int // index in an external container; can be used to refer to the file in a more efficient way, just by its integer index
|
||||
path string // absolute path of the source file - '/projects/v/file.v'
|
||||
|
@ -3,6 +3,7 @@
|
||||
// that can be found in the LICENSE file.
|
||||
module fmt
|
||||
|
||||
import os
|
||||
import strings
|
||||
import v.ast
|
||||
import v.util
|
||||
@ -3039,6 +3040,15 @@ pub fn (mut f Fmt) select_expr(node ast.SelectExpr) {
|
||||
}
|
||||
|
||||
pub fn (mut f Fmt) selector_expr(node ast.SelectorExpr) {
|
||||
// TODO(StunxFS): Even though we ignored the JS backend, the `v/gen/js/tests/js.v`
|
||||
// file was still formatted/transformed, so it is specifically ignored here. Fix this.
|
||||
if f.file.language != .js && node.expr is ast.StringLiteral && node.field_name == 'str'
|
||||
&& !f.pref.backend.is_js()
|
||||
&& !f.file.path.ends_with(os.join_path('v', 'gen', 'js', 'tests', 'js.v')) {
|
||||
f.write('c')
|
||||
f.expr(node.expr)
|
||||
return
|
||||
}
|
||||
f.expr(node.expr)
|
||||
f.write('.')
|
||||
f.write(node.field_name)
|
||||
|
@ -34,7 +34,7 @@ fn (mut g Gen) lookup_system_dll(dll string) !SystemDll {
|
||||
$if windows {
|
||||
unsafe {
|
||||
buffer := malloc(1024)
|
||||
len := C.SearchPathA(nil, dll.str, '.dll'.str, 1024, buffer, nil)
|
||||
len := C.SearchPathA(nil, dll.str, c'.dll', 1024, buffer, nil)
|
||||
if len == 0 {
|
||||
err_code := C.GetLastError()
|
||||
err_msg := cstring_to_vstring(C.strerror(err_code))
|
||||
|
@ -342,6 +342,7 @@ pub fn (mut p Parser) parse() &ast.File {
|
||||
is_test: p.inside_test_file
|
||||
is_generated: p.is_generated
|
||||
is_translated: p.is_translated
|
||||
language: p.file_backend_mode
|
||||
nr_lines: p.scanner.line_nr
|
||||
nr_bytes: p.scanner.text.len
|
||||
nr_tokens: p.scanner.all_tokens.len
|
||||
|
@ -82,7 +82,7 @@ fn create_server_socket(port int) int {
|
||||
server_fd := C.socket(C.AF_INET, C.SOCK_STREAM, 0)
|
||||
if server_fd < 0 {
|
||||
eprintln(@LOCATION)
|
||||
C.perror('Socket creation failed'.str)
|
||||
C.perror(c'Socket creation failed')
|
||||
exit(1)
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ fn create_server_socket(port int) int {
|
||||
opt := 1
|
||||
if C.setsockopt(server_fd, C.SOL_SOCKET, C.SO_REUSEPORT, &opt, sizeof(opt)) < 0 {
|
||||
eprintln(@LOCATION)
|
||||
C.perror('setsockopt SO_REUSEPORT failed'.str)
|
||||
C.perror(c'setsockopt SO_REUSEPORT failed')
|
||||
close_socket(server_fd)
|
||||
exit(1)
|
||||
}
|
||||
@ -105,14 +105,14 @@ fn create_server_socket(port int) int {
|
||||
|
||||
if C.bind(server_fd, &server_addr, sizeof(server_addr)) < 0 {
|
||||
eprintln(@LOCATION)
|
||||
C.perror('Bind failed'.str)
|
||||
C.perror(c'Bind failed')
|
||||
close_socket(server_fd)
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if C.listen(server_fd, max_connection_size) < 0 {
|
||||
eprintln(@LOCATION)
|
||||
C.perror('Listen failed'.str)
|
||||
C.perror(c'Listen failed')
|
||||
close_socket(server_fd)
|
||||
exit(1)
|
||||
}
|
||||
@ -123,7 +123,7 @@ fn create_server_socket(port int) int {
|
||||
fn create_epoll_fd() int {
|
||||
epoll_fd := C.epoll_create1(0)
|
||||
if epoll_fd < 0 {
|
||||
C.perror('epoll_create1'.str)
|
||||
C.perror(c'epoll_create1')
|
||||
}
|
||||
return epoll_fd
|
||||
}
|
||||
@ -135,7 +135,7 @@ fn add_fd_to_epoll(epoll_fd int, fd int, events u32) int {
|
||||
ev.data.fd = fd
|
||||
if C.epoll_ctl(epoll_fd, C.EPOLL_CTL_ADD, fd, &ev) == -1 {
|
||||
eprintln(@LOCATION)
|
||||
C.perror('epoll_ctl'.str)
|
||||
C.perror(c'epoll_ctl')
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
@ -155,7 +155,7 @@ fn handle_accept_loop(mut server Server, main_epoll_fd int) {
|
||||
if C.errno == C.EINTR {
|
||||
continue
|
||||
}
|
||||
C.perror('epoll_wait'.str)
|
||||
C.perror(c'epoll_wait')
|
||||
break
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ fn handle_accept_loop(mut server Server, main_epoll_fd int) {
|
||||
break // No more incoming connections; exit loop.
|
||||
}
|
||||
eprintln(@LOCATION)
|
||||
C.perror('Accept failed'.str)
|
||||
C.perror(c'Accept failed')
|
||||
continue
|
||||
}
|
||||
set_blocking(client_conn_fd, false)
|
||||
@ -201,7 +201,7 @@ fn process_events(mut server Server, epoll_fd int) {
|
||||
continue
|
||||
}
|
||||
eprintln(@LOCATION)
|
||||
C.perror('epoll_wait'.str)
|
||||
C.perror(c'epoll_wait')
|
||||
break
|
||||
}
|
||||
|
||||
@ -229,7 +229,7 @@ fn process_events(mut server Server, epoll_fd int) {
|
||||
break // No more data to read
|
||||
}
|
||||
eprintln(@LOCATION)
|
||||
C.perror('recv'.str)
|
||||
C.perror(c'recv')
|
||||
remove_fd_from_epoll(epoll_fd, client_conn_fd)
|
||||
close_socket(client_conn_fd)
|
||||
break
|
||||
@ -265,7 +265,7 @@ fn process_events(mut server Server, epoll_fd int) {
|
||||
C.MSG_NOSIGNAL | C.MSG_ZEROCOPY)
|
||||
if sent < 0 && C.errno != C.EAGAIN && C.errno != C.EWOULDBLOCK {
|
||||
eprintln(@LOCATION)
|
||||
C.perror('send'.str)
|
||||
C.perror(c'send')
|
||||
remove_fd_from_epoll(epoll_fd, client_conn_fd)
|
||||
close_socket(client_conn_fd)
|
||||
}
|
||||
@ -302,7 +302,7 @@ pub fn (mut server Server) run() {
|
||||
for i in 0 .. max_thread_pool_size {
|
||||
server.epoll_fds[i] = create_epoll_fd()
|
||||
if server.epoll_fds[i] < 0 {
|
||||
C.perror('epoll_create1'.str)
|
||||
C.perror(c'epoll_create1')
|
||||
for j in 0 .. i {
|
||||
close_socket(server.epoll_fds[j])
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user