I am trying to wrap a JLL I’m authoring and as part of creating the wrapper, I’m writing some tests. In this test, I create an instance of a struct:
conn_options = Ref(aws_mqtt_connection_options(
host_name_cur[],
UInt16(8883),
...
))
I then pass that instance to a C function: aws_mqtt_client_connection_connect(connection, conn_options)
. This C function is declared like so:
function aws_mqtt_client_connection_connect(connection, connection_options)
ccall((:aws_mqtt_client_connection_connect, libawsmqtt), Cint, (Ptr{aws_mqtt_client_connection}, Ptr{aws_mqtt_connection_options}), connection, connection_options)
end
I am having a problem where data I store in that struct looks good from Julia, but looks wrong in C. We can see the data looks correct when printed from Julia:
conn_options = Base.RefValue{aws_mqtt_connection_options}(aws_mqtt_connection_options(aws_byte_cursor(0x000000000000002e, Ptr{UInt8} @0x00007f7314c1f218), 0x22b3, Ptr{aws_socket_options} @0x00007ffff3c5d520, Ptr{aws_tls_connection_options} @0x00007ffff3c5d540, aws_byte_cursor(0x000000000000000e, Ptr{UInt8} @0x00007f7314c14938), 0x0000, 0x00000000, 0x00000000, Ptr{Nothing} @0x0000000000000000, Ptr{Nothing} @0x0000000000000000, true))
However, when printed from C, the data is wrong:
(rr) p *connection_options
$3 = {host_name = {len = 140476288574320, ptr = 0x7fc3221522b3 ""}, port = 33024, socket_options = 0x7ffc25b78120, tls_options = 0x7fc32fb3e9b0, client_id = {len = 573374464, ptr = 0x0},
keep_alive_time_secs = 0, ping_timeout_ms = 0, protocol_operation_timeout_ms = 0, on_connection_complete = 0x1, user_data = 0x0, clean_session = false}
An easy check is to look at the second parameter, the port number. It should be 8883
, but it is 33024
. As for the pointers, they do not point to valid memory. In fact, all the values in this struct change each time I run the program. Something is very wrong.
My question is, does anyone know what could be wrong? I’ve exhausted my abilities with rr
and other tools and I can’t figure out what is wrong or how to proceed from here. You can access all of the relevant code here. If anyone wants to see more, I’m happy to provide it.