I'm working on the mysql client lib for Julia. I'm using the C api that 
support statement mode.  To retrieve data after executing the query, it 
needs C structs (MYSQL_BIND) to be created and passed to C.  Each field of 
the row retrieved from db will be stored in the corresponding struct and I 
should read the value from the struct.

 It is unfortunate that I did not notice the line in Julia documentation 
stating "Currently, it is not possible to pass structs and other 
non-primitive types from Julia to C libraries." and spent an inordinate 
amount of time trying to debug what I did wrong.

This particular struct is defined in mysql/mysql.h.  What are the options I 
have?

1.  Is there a julia call that can read the header files and create the 
struct or an equivalent feature?
2.  The non-statement mode doesn't seem to have complex structures.  Is 
that the better approach?  

For reference, to test passing structs, I created the following files
*teststruct.jl *
somenum= uint64(1)

type MyStruct
    somefield :: Ptr {Uint64}
end

function check(my :: MyStruct)
    ccall((:check, "structtest.so"), Cint, (Ptr{Void},) , 
pointer_from_objref(my))end

newstruct = MyStruct(pointer_from_objref(somenum))
print("The pointer address stored in somefield as seen in julia: ")
println(newstruct.somefield)
print("The pointer address of newstruct as seen in julia: ")
println(pointer_from_objref(newstruct))
check(newstruct)

*structtest.c *
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

typedef struct st_mystruct
{
    unsigned long *somefield;
    } MyStruct;

int check(MyStruct *my)
{

  printf("The pointer address of struct as seen in c: %p\n", my);
  printf("The pointer address stored in somefield as seen in c: %p\n", 
my->somefield);
 }


The output was




*The pointer address stored in somefield as seen in julia: Ptr{Uint64} 
@0x00000000020c1560The pointer address of newstruct as seen in julia: 
Ptr{Void} @0x00000000022e5540The pointer address of struct as seen in c: 
0x22e5540The pointer address stored in somefield as seen in c: 0x206ee90*

As we can see, the value of 'somefield' ends up garbled.



Reply via email to