[Openmcl-devel] Calling foreign function with float array as argument?

Ronnie Hoogerwerf ronnieh at head-cfa.harvard.edu
Thu Nov 21 16:08:26 UTC 2002


I relatively new to openmcl but have some experience using mcl and cmucl.
I am trying to port a lisp interface to the PGPLOT graphics library to
openmcl (the orignal was written for cmucl) and am running into some
problems that I cannot seem to solve. I need to pass an array (of type 
single-float) to a foreign function. This function then changes the values
of the array and I would like to retrieve those changed values. 
An example of the c-code looks something like:

#include "cpgplot.h"
#include <string.h>
extern int pgcurs_();

int cpgcurs(float *x, float *y, char *ch_scalar)
  int len_ch_scalar = 1;
  int r_value;
  r_value = pgcurs_(x, y, ch_scalar, len_ch_scalar);
  return r_value;

The cmucl code solves the problem of passing pointers to float by 
obtaining the memory address of the lisp array (using
kernel:get-lisp-obj-address) and then passes the address to the function.

I am at a loss on how I do this in openmcl. So my questions are:

1) How do I call the foreign function?
   a) (ccl::external-call "_cpgcurs"
		          (:* float) x
		          (:* float) y
	     	          (:* char) c
   b) (ccl::external-call "_cpgcurs"
		          :address x
		          :address y
	     	          :address c

2) How do I obtain the memory address (or macptr) of a lisp object?
   Or is there some other way around this?

I am using openmcl 0.13 on Mac OS X 10.1.5.

I hope I make myself clean and I would appreciate any help.


P.S. I succeeded in calling a foreign function which had just a single
     float as its argument (not an array) but was unable to modify this
     to work with an array of floats:

(defun func (x)
  (rlet ((_x :float))
    (setf (pref _x :float) x)
    (ccl::external-call "_func"
  			(:* float) _x)
    (pref _x :float)))

Openmcl-devel mailing list
Openmcl-devel at clozure.com

More information about the Openmcl-devel mailing list