Hi everyone!
I'm trying to create binding for Quiche, I managed to map several functions but as it's my very first time creating any bindings, I faced some issues.
First I used H2Pas but the result was overwhelming, it seemed to need plenty of manual adjustment so for educational purposes I decided to do it manually from the ground up. I started with seemingly most important functions, testing them on-the-go. I managed to map several BoringSSL functions needed to create SSL context and a couple of Quiche functions needed to create a QUIC connection Till this point, everything seemed to be working, so I took up
quiche_conn_recv and that's where I faced first issues. I mapped it the same way I learn so far but calling it gives me
Access violation.
the header:
typedef struct {
struct sockaddr *from;
socklen_t from_len;
struct sockaddr *to;
socklen_t to_len;
} quiche_recv_info;
ssize_t quiche_conn_recv(quiche_conn *conn, uint8_t *buf, size_t buf_len,
const quiche_recv_info *info);
mapped as:
type
PQuiche_conn = ^Quiche_conn;
Quiche_conn = record
end;
Pquiche_recv_info = ^quiche_recv_info;
quiche_recv_info = record
from : Psockaddr;
from_len : socklen_t;
to_ : Psockaddr; //'to_' since 'to' is a reserved word
to_len : socklen_t;
end;
quiche_conn_recv(conn: PQuiche_Conn; buf: PByte; buf_len: CSize_t;
info: PQuiche_Recv_Info): CSsize_t; cdecl; external QUICHE_LIB;
and the way I call the function:
var
bytes_received: CSsize_t;
buf: array of Byte;
//buffer: array[0..8191] of Char;
recv_info: Quiche_recv_info;
Precv_info: PQuiche_recv_info;
SetLength(buf, 8192);
FillChar(recv_info, SizeOf(recv_info), 0);
Precv_info := @recv_info;
bytes_received := quiche_conn_recv(conn, @buf[0], length(buf), Precv_info);
I was experimenting with the parameters but I wasn't able to make it work and I'm not sure if the problem is the mapping of the function or the parameters I pass to.
Calling
quiche_conn_recv is giving:
An unhandled exception occurred at $00007F22FA45392A:
EAccessViolation: Access violation
$00007F22FA45392A
--------------------------------------------------
After being stuck at this for a couple of days, I peeked on the file generated by H2Pas and it looks different to my solution:
type
Pquiche_conn = ^quiche_conn;
Pquiche_recv_info = ^quiche_recv_info;
quiche_recv_info = record
from : Psockaddr;
from_len : socklen_t;
to : Psockaddr;
to_len : socklen_t;
end;
function quiche_conn_recv(var conn:quiche_conn; var buf:uint8_t; buf_len:size_t;
var info:quiche_recv_info):ssize_t;cdecl;external External_library name 'quiche_conn_recv';
here,
var conn:quiche_conn and
var info:quiche_recv_info are not pointers.
I'm puzzled. Any clue what I'm doing wrong?
thanks in advance!