fq - a dynamic ffi for kdb+ 3.1

Hi guys,Before I post this to the k4 list, I’d appreciate it if anyone wouldlike to try this out: http://www.ivorykite.com/fq/from that page: . load any shared object (.so) or .dll q)c:.fq.dlolibc.so.6 . load any functions or variables from a library q)fwrite:.fq.dlf[c;fwrite] q)stdout:.fq.dls[c;`stdout] . call any function in q (providing a call signature) q).fq.call[fwrite;“iCiiz”;(“ho\n”;3i;1i;stdout)]ThanksJack.

To: personal-kdbplus@googlegroups.com
X-Mailer: Apple Mail (2.1283)

how is it different from ffiq?

http://code.kx.com/wsvn/code/contrib/serpent.speak/trunk/ffiq/README

is it possible to call C functions taking struct/* as parameters?

thanks,
Ye

> how is it different from ffiq?i plan to support it…> is it possible to call C functions taking struct/* as parameters?..such as adding support for struct parametersta, jack.

support will be provided to define libc function prototypes like connect()
support for struct parameters will include .q files defining the structs used in functions like connect()

struct sockaddr_in server;
connect (sock, (struct sockaddr *) &server, sizeof server);

where server is a:? struct sockaddr_in
? {
? ? sa_family_t sin_family;
? ? in_port_t sin_port;
? ? struct in_addr sin_addr;
? ? unsigned char sin_zero[sizeof (struct sockaddr) -
? ? ? (sizeof (unsigned short int)) -
? ? ? sizeof (in_port_t) -
? ? ? sizeof (struct in_addr)];
? };

not a simple problem - but there are tools that will generate descriptions of structs - but will need to be done for each platform.

ta, jack

Sounds great, that’ll make it very useful.
– you can almost call any c library.

Hi Ye,Yes, you can call any function in any shared object.I’ll add support for passing struct* to functions in the next week or so.Thanks,Jack.On 19 July 2013 21:55, Ye Tian wrote:> Sounds great, that’ll make it very useful.> – you can almost call any c library.>> On Jul 19, 2013, at 1:27 AM, Jack Andrews wrote:>> support will be provided to define libc function prototypes like connect()> support for struct parameters will include .q files defining the structs> used in functions like connect()>> struct sockaddr_in server;> connect (sock, (struct sockaddr *) &server, sizeof server);>> where server is a: struct sockaddr_in> {> sa_family_t sin_family;> in_port_t sin_port;> struct in_addr sin_addr;> unsigned char sin_zero[sizeof (struct sockaddr) -> (sizeof (unsigned short int)) -> sizeof (in_port_t) -> sizeof (struct in_addr)];> };>> not a simple problem - but there are tools that will generate descriptions> of structs - but will need to be done for each platform.>> ta, jack>> –>

Submitted via Google Groups

On Thursday, July 18, 2013 11:22:14 PM UTC-4, Jack Andrews wrote:

Before I post this to the k4 list, I’d appreciate it if anyone would
like to try this out:
  http://www.ivorykite.com/fq/

How does it compare to ffiq?

http://code.kx.com/wsvn/code/contrib/serpent.speak/trunk/ffiq/README

 

On 25 July 2013 01:23, Sasha <alexander.belopolsky> wrote:
>> Before I post this to the k4 list, I’d appreciate it if anyone would
>> like to try this out:
>> http://www.ivorykite.com/fq/
>>
> How does it compare to ffiq?

i’m working on struct/union, function prototypes and macro values

eg: an HTTP client using .fq*

$"fq Copyright (C) 2013 Ivorykite."<br>.fq:(fq 2:(fq;1))
c:.fq.libc
h:c.gethostbyname “google.com
dest:c.sockaddr_in 0
sockfd:c.socket[dest.sin_family:c.AF_INET;c.SOCK_STREAM;0]
dest.sin_port:c.htons 80
c.memcpy[dest.sin_addr;h.h_addr;h.h_length]
connect[sockfd;dest;c.sizeof dest]
send[sockfd;g:“GET / HTTP/1.0\n\n”;count g]
({buffer:999#0x0;0<0N!c.recv[sockfd;buffer;count buffer]}/)`

if you have a similar small example for me to work off, please
send it through to me.

ta, jack


*which is similar to:
int main(int c, char *v)
{ int sockfd, bytes_read;
struct sockaddr_in dest;
char buffer[999];
if ( c != 2 )
return fprintf(stderr,“usage: %s host\neg. %s google.com\n”,v,v);
if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
EX(“socket”);
bzero(&dest, sizeof(dest));
dest.sin_family = AF_INET;
dest.sin_port = htons(80);
struct hostent
h=gethostbyname(v[1]);
memcpy(&dest.sin_addr,h->h_addr,h->h_length);
if ( inet_addr(v[1], &dest.sin_addr.s_addr) == 0 )
EX(v[1]);
if ( connect(sockfd, (struct sockaddr
)&dest, sizeof(dest)) != 0 )
EX(“connect”);
sprintf(buffer,“GET / HTTP/1.0\n\n”);
send(sockfd, buffer, strlen(buffer), 0);
do {
bzero(buffer, sizeof(buffer));
bytes_read = recv(sockfd, buffer, sizeof(buffer), 0);
if ( bytes_read > 0 )
printf(“%s”, buffer);
} while ( bytes_read > 0 );
return 0;
}

</alexander.belopolsky>