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

net.openssl: add manual .str() methods for C.SSL and C.SSL_CTX, fix a bug in the V auto str generation as well.

This commit is contained in:
Delyan Angelov 2023-02-08 12:52:00 +02:00
parent 522a9f5908
commit 36dc7faf2c
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 26 additions and 1 deletions

View File

@ -42,6 +42,18 @@ pub struct C.SSL {
pub struct C.SSL_CTX {
}
// The above C structs, have incomplete declarations in the OpenSSL headers.
// For this reason, we have to prevent the automatic str() generation for them,
// by adding manual implementations of their .str() methods, that are defined on
// pointers to them:
fn (s &C.SSL) str() string {
return 'C.SSL(0x${voidptr(s)})'
}
fn (c &C.SSL_CTX) str() string {
return 'C.SSL_CTX(0x${voidptr(c)})'
}
fn C.BIO_new_ssl_connect(ctx &C.SSL_CTX) &C.BIO
fn C.BIO_set_conn_hostname(b &C.BIO, name &char) int

View File

@ -1,5 +1,16 @@
import net.openssl
struct Abc {
x &C.SSL_CTX
}
fn test_printing_struct_with_reference_field_of_type_ssl_ctx() {
a := Abc{&C.SSL_CTX(123)}
dump(a)
sa := a.str()
assert sa.contains('&C.SSL_CTX(0x7b)')
}
fn test_openssl_compiles() {
assert openssl.is_used == 1
assert true

View File

@ -912,7 +912,6 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, typ_str string,
} else {
g.get_str_fn(ftyp_noshared)
}
// with floats we use always the g representation:
if sym.kind !in [.f32, .f64] {
fn_body.write_string('{_SLIT("${quote_str}"), ${int(base_fmt)}, {.${data_str(base_fmt)}=')

View File

@ -435,6 +435,9 @@ fn (mut g Gen) c_fn_name(node &ast.FnDecl) !string {
return error('none')
}
name = g.cc_type(node.receiver.typ, false) + '_' + name
if unwrapped_rec_sym.language == .c {
name = name.replace_once('C__', '')
}
}
if node.language == .c {
name = util.no_dots(name)