[plt-scheme] foreign and C macros

From: David Van Horn (dvanhorn at cs.uvm.edu)
Date: Mon Mar 28 18:19:32 EST 2005

I was recently trying to rewrite my MySQL library to use foreign.ss instead of 
cffi.ss.  Unfortunately the MySQL C API uses macros in place of procedures for 
many of the library's functionalities.

Eg: #define mysql_num_rows(res) (res)->row_count

For the cffi.ss implementation of this library, this matters not and I can use 
c-lambda to access mysql_num_rows regardless of if it's defined as a macro, 
but obviously for the foreign.ss implementation this won't work since 
mysql_num_rows is not a defined symbol in the object file. So I have do some 
trickery which will likely break if MySQL changes their implementation.

So is there a graceful solution to this problem using foreign.ss?

Is there a not-so-graceful solution?  ie, how do I write ->row_count using 
foreign.ss?  Do I have to duplicate the entire C typedef definition in Scheme?


Posted on the users mailing list.