vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.8k stars 2.16k forks source link

VLIB net module broken for SmartOS/Solaris #11003

Closed fantassin closed 2 years ago

fantassin commented 3 years ago

V version: OS:

[root@smart-vlan1 ~/v]# v doctor
OS: solaris, ,
Processor: 24 cpus, 64bit, little endian
CC version: cc (GCC) 9.3.0

getwd: /root/v
vmodules: /root/.vmodules
vroot: /root/v
vexe: /root/v/v
vexe mtime: 2021-07-30 14:26:26
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.2 afb7168

Git version: git version 2.29.2
Git vroot status: weekly.2021.30-51-gafb7168a (1 commit(s) behind V master)
.git/config present: true
thirdparty/tcc status: thirdparty-unknown-unknown de82a130

What did you do? Run example/news_fetcher.v

What did you expect to see? Compile and run

What did you see instead? Fail to compile

SunOS smart-vlan1 5.11 joyent_20210422T002312Z i86pc i386 i86pc
[root@smart-vlan1 ~/v]# v examples/news_fetcher.v
vlib/net/address.v:7:2: error: `net.Unix` is not a struct
    5 |
    6 | union AddrData {
    7 |     Unix
      |     ~~~~
    8 |     Ip
    9 |     Ip6
vlib/net/address.v:8:2: error: `net.Ip` is not a struct
    6 | union AddrData {
    7 |     Unix
    8 |     Ip
      |     ~~
    9 |     Ip6
   10 | }
vlib/net/address.v:9:2: error: `net.Ip6` is not a struct
    7 |     Unix
    8 |     Ip
    9 |     Ip6
      |     ~~~
   10 | }
   11 |
vlib/net/address.v:17:37: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
   15 | )
   16 |
   17 | fn new_ip6(port u16, addr [16]byte) Addr {
      |                                     ~~~~
   18 |     a := Addr{
   19 |         f: u16(AddrFamily.ip6)
vlib/net/address.v:18:7: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
   16 |
   17 | fn new_ip6(port u16, addr [16]byte) Addr {
   18 |     a := Addr{
      |          ~~~~~
   19 |         f: u16(AddrFamily.ip6)
   20 |         addr: AddrData{
vlib/net/address.v:27:9: error: `void` type has no fields
   25 |     }
   26 |
   27 |     copy(a.addr.Ip6.addr[0..], addr[0..])
      |            ~~~~
   28 |
   29 |     return a
vlib/net/address.v:29:9: error: cannot use `void` as type `net.Addr` in return argument
   27 |     copy(a.addr.Ip6.addr[0..], addr[0..])
   28 |
   29 |     return a
      |            ^
   30 | }
   31 |
vlib/net/address.v:32:35: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
   30 | }
   31 |
   32 | fn new_ip(port u16, addr [4]byte) Addr {
      |                                   ~~~~
   33 |     a := Addr{
   34 |         f: u16(AddrFamily.ip)
vlib/net/address.v:33:7: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
   31 |
   32 | fn new_ip(port u16, addr [4]byte) Addr {
   33 |     a := Addr{
      |          ~~~~~
   34 |         f: u16(AddrFamily.ip)
   35 |         addr: AddrData{
vlib/net/address.v:42:9: error: `void` type has no fields
   40 |     }
   41 |
   42 |     copy(a.addr.Ip6.addr[0..], addr[0..])
      |            ~~~~
   43 |
   44 |     return a
vlib/net/address.v:44:9: error: cannot use `void` as type `net.Addr` in return argument
   42 |     copy(a.addr.Ip6.addr[0..], addr[0..])
   43 |
   44 |     return a
      |            ^
   45 | }
   46 |
vlib/net/address.v:47:16: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
   45 | }
   46 |
   47 | fn temp_unix() ?Addr {
      |                ~~~~~
   48 |     // create a temp file to get a filename
   49 |     // close it
vlib/net/address.v:59:11: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
   57 | }
   58 |
   59 | pub fn (a Addr) family() AddrFamily {
      |           ~~~~
   60 |     return AddrFamily(a.f)
   61 | }
vlib/net/address.v:60:22: error: expression does not return a value so it cannot be cast
   58 |
   59 | pub fn (a Addr) family() AddrFamily {
   60 |     return AddrFamily(a.f)
      |                         ^
   61 | }
   62 |
vlib/net/address.v:68:7: error: unknown type `net.Ip`
   66 | )
   67 |
   68 | fn (a Ip) str() string {
      |       ~~
   69 |     buf := []byte{len: net.max_ip_len, init: 0}
   70 |
vlib/net/address.v:78:18: error: cannot use `void` as `u16` in argument 1 to `C.ntohs`
   76 |
   77 |     saddr := buf.bytestr()
   78 |     port := C.ntohs(a.port)
      |                     ~~~~~~
   79 |
   80 |     return '$saddr:$port'
vlib/net/address.v:83:7: error: unknown type `net.Ip6`
   81 | }
   82 |
   83 | fn (a Ip6) str() string {
      |       ~~~
   84 |     buf := []byte{len: net.max_ip6_len, init: 0}
   85 |
vlib/net/address.v:93:18: error: cannot use `void` as `u16` in argument 1 to `C.ntohs`
   91 |
   92 |     saddr := buf.bytestr()
   93 |     port := C.ntohs(a.port)
      |                     ~~~~~~
   94 |
   95 |     return '[$saddr]:$port'
vlib/net/address.v:98:17: error: first argument of __offsetof must be struct
   96 | }
   97 |
   98 | const aoffset = __offsetof(Addr, addr)
      |                 ~~~~~~~~~~
   99 |
  100 | fn (a Addr) len() u32 {
vlib/net/address.v:100:7: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
   98 | const aoffset = __offsetof(Addr, addr)
   99 |
  100 | fn (a Addr) len() u32 {
      |       ~~~~
  101 |     match a.family() {
  102 |         .ip {
vlib/net/address.v:117:72: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  115 | }
  116 |
  117 | pub fn resolve_addrs(addr string, family AddrFamily, @type SocketType) ?[]Addr {
      |                                                                        ~~~~~~~
  118 |     match family {
  119 |         .ip, .ip6, .unspec {
vlib/net/address.v:123:16: error: unknown type `net.Unix`
  121 |         }
  122 |         .unix {
  123 |             resolved := Unix{}
      |                         ~~~~~~
  124 |
  125 |             if addr.len > max_unix_path {
vlib/net/address.v:131:24: error: `void` type has no fields
  129 |             // Copy the unix path into the address struct
  130 |             unsafe {
  131 |                 C.memcpy(&resolved.path, addr.str, addr.len)
      |                                    ~~~~
  132 |             }
  133 |
vlib/net/address.v:134:12: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  132 |             }
  133 |
  134 |             return [Addr{
      |                     ~~~~~
  135 |                 f: u16(AddrFamily.unix)
  136 |                 addr: AddrData{
vlib/net/address.v:144:59: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  142 | }
  143 |
  144 | pub fn resolve_addrs_fuzzy(addr string, @type SocketType) ?[]Addr {
      |                                                           ~~~~~~~
  145 |     if addr.len == 0 {
  146 |         return none
vlib/net/address.v:161:72: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  159 | }
  160 |
  161 | pub fn resolve_ipaddrs(addr string, family AddrFamily, typ SocketType) ?[]Addr {
      |                                                                        ~~~~~~~
  162 |     address, port := split_address(addr) ?
  163 |
vlib/net/address.v:200:21: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  198 |     // Now that we have our linked list of addresses
  199 |     // convert them into an array
  200 |     mut addresses := []Addr{}
      |                        ~~~~
  201 |
  202 |     for result := results; !isnil(result); result = result.ai_next {
vlib/net/address.v:205:17: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  203 |         match AddrFamily(result.ai_family) {
  204 |             .ip, .ip6 {
  205 |                 new_addr := Addr{
      |                             ~~~~~
  206 |                     addr: AddrData{
  207 |                         Ip6: Ip6{}
vlib/net/address.v:213:18: error: cannot append `void` to `[]net.Addr`
  211 |                     C.memcpy(&new_addr, result.ai_addr, result.ai_addrlen)
  212 |                 }
  213 |                 addresses << new_addr
      |                              ~~~~~~~~
  214 |             }
  215 |             else {
vlib/net/address.v:224:7: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  222 | }
  223 |
  224 | fn (a Addr) str() string {
      |       ~~~~
  225 |     match AddrFamily(a.f) {
  226 |         .ip {
vlib/net/address.v:225:21: error: expression does not return a value so it cannot be cast
  223 |
  224 | fn (a Addr) str() string {
  225 |     match AddrFamily(a.f) {
      |                        ^
  226 |         .ip {
  227 |             unsafe {
vlib/net/address.v:228:19: error: `void` type has no fields
  226 |         .ip {
  227 |             unsafe {
  228 |                 return a.addr.Ip.str()
      |                               ~~
  229 |             }
  230 |         }
vlib/net/address.v:233:19: error: `void` type has no fields
  231 |         .ip6 {
  232 |             unsafe {
  233 |                 return a.addr.Ip6.str()
      |                               ~~~
  234 |             }
  235 |         }
vlib/net/address.v:238:29: error: `void` type has no fields
  236 |         .unix {
  237 |             unsafe {
  238 |                 return tos_clone(a.addr.Unix.path[0..max_unix_path].data)
      |                                         ~~~~
  239 |             }
  240 |         }
vlib/net/address.v:247:44: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  245 | }
  246 |
  247 | pub fn addr_from_socket_handle(handle int) Addr {
      |                                            ~~~~
  248 |     addr := Addr{
  249 |         addr: AddrData{
vlib/net/address.v:248:10: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  246 |
  247 | pub fn addr_from_socket_handle(handle int) Addr {
  248 |     addr := Addr{
      |             ~~~~~
  249 |         addr: AddrData{
  250 |             Ip6: Ip6{}
vlib/net/address.v:257:9: error: cannot use `void` as type `net.Addr` in return argument
  255 |     C.getsockname(handle, voidptr(&addr), &size)
  256 |
  257 |     return addr
      |            ~~~~
  258 | }
vlib/net/tcp.v:160:33: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  158 | }
  159 |
  160 | pub fn (c &TcpConn) peer_addr() ?Addr {
      |                                 ~~~~~
  161 |     mut addr := Addr{
  162 |         addr: AddrData{
vlib/net/tcp.v:168:9: error: cannot use `void` as type `?net.Addr` in return argument
  166 |     mut size := sizeof(Addr)
  167 |     socket_error(C.getpeername(c.sock.handle, voidptr(&addr), &size)) ?
  168 |     return addr
      |            ~~~~
  169 | }
  170 |
vlib/net/tcp.v:175:28: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  173 | }
  174 |
  175 | pub fn (c &TcpConn) addr() ?Addr {
      |                            ~~~~~
  176 |     return c.sock.address()
  177 | }
vlib/net/tcp.v:262:32: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  260 | }
  261 |
  262 | pub fn (c &TcpListener) addr() ?Addr {
      |                                ~~~~~
  263 |     return c.sock.address()
  264 | }
vlib/net/tcp.v:344:32: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  342 | )
  343 |
  344 | fn (mut s TcpSocket) connect(a Addr) ? {
      |                                ~~~~
  345 |     res := C.connect(s.handle, voidptr(&a), a.len())
  346 |     if res == 0 {
vlib/net/tcp.v:379:33: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  377 |
  378 | // address gets the address of a socket
  379 | pub fn (s &TcpSocket) address() ?Addr {
      |                                 ~~~~~
  380 |     return addr_from_socket_handle(s.handle)
  381 | }
vlib/net/udp.v:12:9: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
   10 | struct UdpSocket {
   11 |     handle int
   12 |     l      Addr
      |            ~~~~
   13 |     // TODO(emily): replace with option again
   14 |     // when i figure out how to coerce it properly
vlib/net/udp.v:74:42: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
   72 | }
   73 |
   74 | pub fn (mut c UdpConn) write_to_ptr(addr Addr, b &byte, len int) ?int {
      |                                          ~~~~
   75 |     res := C.sendto(c.sock.handle, b, len, 0, voidptr(&addr), addr.len())
   76 |     if res >= 0 {
vlib/net/udp.v:90:38: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
   88 |
   89 | // write_to blocks and writes the buf to the remote addr specified
   90 | pub fn (mut c UdpConn) write_to(addr Addr, buf []byte) ?int {
      |                                      ~~~~
   91 |     return c.write_to_ptr(addr, buf.data, buf.len)
   92 | }
vlib/net/udp.v:95:45: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
   93 |
   94 | // write_to_string blocks and writes the buf to the remote addr specified
   95 | pub fn (mut c UdpConn) write_to_string(addr Addr, s string) ?int {
      |                                             ~~~~
   96 |     return c.write_to_ptr(addr, s.str, s.len)
   97 | }
vlib/net/udp.v:101:14: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
   99 | // read reads from the socket into buf up to buf.len returning the number of bytes read
  100 | pub fn (mut c UdpConn) read(mut buf []byte) ?(int, Addr) {
  101 |     mut addr := Addr{
      |                 ~~~~~
  102 |         addr: AddrData{
  103 |             Ip6: Ip6{}
vlib/net/udp.v:110:15: error: cannot use `void` as type `net.Addr` in return argument
  108 |         0, voidptr(&addr), &len)) ?
  109 |     if res > 0 {
  110 |         return res, addr
      |                     ~~~~
  111 |     }
  112 |     code := error_code()
vlib/net/udp.v:119:16: error: cannot use `void` as type `net.Addr` in return argument
  117 |             voidptr(&addr), &len)) ?
  118 |         res2 := socket_error(res) ?
  119 |         return res2, addr
      |                      ~~~~
  120 |     } else {
  121 |         wrap_error(code) ?
vlib/net/udp.v:196:30: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  194 | }
  195 |
  196 | fn new_udp_socket(local_addr Addr) ?&UdpSocket {
      |                              ~~~~
  197 |     family := local_addr.family()
  198 |
vlib/net/udp.v:203:6: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  201 |         handle: sockfd
  202 |         l: local_addr
  203 |         r: Addr{
      |            ~~~~~
  204 |             addr: AddrData{
  205 |                 Ip6: Ip6{}
vlib/net/udp.v:229:36: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  227 | }
  228 |
  229 | fn new_udp_socket_for_remote(raddr Addr) ?&UdpSocket {
      |                                    ~~~~
  230 |     // Invent a sutible local address for this remote addr
  231 |     // Appease compiler
vlib/net/udp.v:232:14: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  230 |     // Invent a sutible local address for this remote addr
  231 |     // Appease compiler
  232 |     mut addr := Addr{
      |                 ~~~~~
  233 |         addr: AddrData{
  234 |             Ip6: Ip6{}
vlib/net/udp.v:249:29: error: cannot use `void` as `net.Addr` in argument 1 to `new_udp_socket`
  247 |         }
  248 |     }
  249 |     mut sock := new_udp_socket(addr) ?
      |                                ~~~~
  250 |     sock.has_r = true
  251 |     sock.r = raddr
vlib/net/udp.v:282:28: error: unknown type `net.Addr`.
Did you mean `net.AddrData`?
  280 | }
  281 |
  282 | fn (s &UdpSocket) remote() ?Addr {
      |                            ~~~~~
  283 |     if s.has_r {
  284 |         return s.r
fantassin commented 2 years ago

This issue was caused by this PR: https://github.com/vlang/v/pull/9904

spytheman commented 2 years ago

Try copying vlib/net/address_freebsd.c.v to vlib/net/address_solaris.c.v, then potentially editing the file (max_unix_path and struct C. declarations), to match the solaris definitions.

ylluminate commented 2 years ago

Please consider a way to execute a Solaris/SmartOS CI runner for each commit/PR to move support forward @fantassin. See: https://discordapp.com/channels/592103645835821068/592320321995014154/960280734894030918

After this making PRs should be relatively straight forward.