mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix dump(c_struct)
, where c_struct has fields of type &&char
This commit is contained in:
parent
9569c0504c
commit
7f2d731d19
@ -773,6 +773,10 @@ fn (g &Gen) type_to_fmt(typ ast.Type) StrIntpType {
|
|||||||
// return '%C\\000' // a C string
|
// return '%C\\000' // a C string
|
||||||
return .si_s
|
return .si_s
|
||||||
}
|
}
|
||||||
|
typ_nr_muls := typ.nr_muls()
|
||||||
|
if typ_nr_muls > 1 {
|
||||||
|
return .si_p
|
||||||
|
}
|
||||||
sym := g.table.sym(typ)
|
sym := g.table.sym(typ)
|
||||||
if typ.is_ptr() && (typ.is_int_valptr() || typ.is_float_valptr()) {
|
if typ.is_ptr() && (typ.is_int_valptr() || typ.is_float_valptr()) {
|
||||||
return .si_s
|
return .si_s
|
||||||
@ -902,7 +906,7 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri
|
|||||||
g.get_str_fn(ftyp_noshared)
|
g.get_str_fn(ftyp_noshared)
|
||||||
}
|
}
|
||||||
|
|
||||||
// manage the fact hat with float we use always the g representation
|
// with floats we use always the g representation:
|
||||||
if sym.kind !in [.f32, .f64] {
|
if sym.kind !in [.f32, .f64] {
|
||||||
fn_body.write_string('{_SLIT("$quote_str"), ${int(base_fmt)}, {.${data_str(base_fmt)}=')
|
fn_body.write_string('{_SLIT("$quote_str"), ${int(base_fmt)}, {.${data_str(base_fmt)}=')
|
||||||
} else {
|
} else {
|
||||||
@ -913,7 +917,8 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri
|
|||||||
mut funcprefix := ''
|
mut funcprefix := ''
|
||||||
mut func, mut caller_should_free := struct_auto_str_func(sym, field.typ, field_styp_fn_name,
|
mut func, mut caller_should_free := struct_auto_str_func(sym, field.typ, field_styp_fn_name,
|
||||||
field.name, sym_has_str_method, str_method_expects_ptr)
|
field.name, sym_has_str_method, str_method_expects_ptr)
|
||||||
if field.typ in ast.cptr_types {
|
ftyp_nr_muls := field.typ.nr_muls()
|
||||||
|
if ftyp_nr_muls > 1 || field.typ in ast.cptr_types {
|
||||||
func = '(voidptr) it.$field.name'
|
func = '(voidptr) it.$field.name'
|
||||||
caller_should_free = false
|
caller_should_free = false
|
||||||
} else if ftyp_noshared.is_ptr() {
|
} else if ftyp_noshared.is_ptr() {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "@VMODROOT/epoll.h"
|
#include "@VMODROOT/epoll.h"
|
||||||
|
#include "@VMODROOT/netdb.h"
|
||||||
|
|
||||||
pub struct C.epoll_event {
|
pub struct C.epoll_event {
|
||||||
mut:
|
mut:
|
||||||
@ -19,6 +20,14 @@ struct Epoll {
|
|||||||
ev C.epoll_event
|
ev C.epoll_event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct C.hostent {
|
||||||
|
h_name &char
|
||||||
|
h_aliases &&char
|
||||||
|
h_addrtype int
|
||||||
|
h_length int
|
||||||
|
h_addr_list &&char
|
||||||
|
}
|
||||||
|
|
||||||
fn test_dump_c_struct() {
|
fn test_dump_c_struct() {
|
||||||
ev := C.epoll_event{}
|
ev := C.epoll_event{}
|
||||||
unsafe { C.memset(&ev, 0, sizeof(ev)) }
|
unsafe { C.memset(&ev, 0, sizeof(ev)) }
|
||||||
@ -30,5 +39,12 @@ fn test_dump_c_struct() {
|
|||||||
}
|
}
|
||||||
dump(e)
|
dump(e)
|
||||||
println(e)
|
println(e)
|
||||||
|
//
|
||||||
|
mut hostent := &C.hostent{
|
||||||
|
h_addr_list: unsafe { nil }
|
||||||
|
h_aliases: unsafe { nil }
|
||||||
|
h_name: unsafe { nil }
|
||||||
|
}
|
||||||
|
dump(hostent)
|
||||||
assert true
|
assert true
|
||||||
}
|
}
|
||||||
|
9
vlib/v/tests/dump_c_structs/netdb.h
Normal file
9
vlib/v/tests/dump_c_structs/netdb.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
/* Description of data base entry for a single host. */
|
||||||
|
struct hostent {
|
||||||
|
char *h_name; /* Official name of host. */
|
||||||
|
char **h_aliases; /* Alias list. */
|
||||||
|
int h_addrtype; /* Host address type. */
|
||||||
|
int h_length; /* Length of address. */
|
||||||
|
char **h_addr_list; /* List of addresses from name server. */
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user