#I cant figure out why anyopaque won't work

1 messages · Page 1 of 1 (latest)

keen briar
#

I am working with openssl from system(for now) and I need to send data using SSL_write witch expects

SSL_write(ssl: ?*SSL, buf: ?*const anyopaque, num: c_int)

This is the code I have writing https://zigbin.io/a8c4bd

I get this error

src/main.zig:103:32: error: expected type '?*const anyopaque', found '*const []u8'
    if (openssl.SSL_write(ssl, &data, data.len) <= 0) {
                               ^~~~~
src/main.zig:103:32: note: cannot implicitly cast double pointer '*const []u8' to anyopaque pointer '?*const anyopaque'
/home/redviking/projects/gemini-protocol/.zig-cache/o/8ea255c94f3e7fa3025fd9d3a12386ad/cimport.zig:8619:42: note: parameter type declared here
pub extern fn SSL_write(ssl: ?*SSL, buf: ?*const anyopaque, num: c_int) c_int;
                                         ^~~~~~~~~~~~~~~~~

Can anyone explain why this happens and how to fix it

placid spire
#

the error explains itself quite well: a *const []const u8 cannot implicitly coerce into ?*const anyopaque: the former is a double indirection and so the cast is likely a bug. indeed that seems like the case: it looks like you should be passing data.ptr as the second argument to SSL_write, rather than &data.
&data is a pointer to the stack variable containing the pointer to the bytes - it itself isn't a pointer to the bytes.