hines@cme.nist.gov (Lynnwood Hines - pdes) (05/30/91)
OK, I solved the problem here, and the solution is:
C code that creates the string:
***************************************************
#include <stdio.h>
#include <lisp.h>
char back[] = "Hello from C...";
long lisp_value();
char * fill_string (bindex)
int bindex;
{
printf("C:setting string to: %s\n", back);
printf("C:bindex set to: %d\n", bindex);
fflush(stdout);
strcpy ((char *)lisp_value(bindex)+2, back);
printf("C:setting lisp_value to: %s\n", (char *)lisp_value(bindex));
fflush(stdout);
return ((char *)lisp_value(bindex));
}
************************************************************
and the lisp side looks like this:
(defconstant *msl* 256)
(defvar *lsb* (make-string *msl*))
(defvar *lsbi* (ff:register-value *lsb*))
(load "test.o")
(ff:defforeign 'fstring :entry-point (ff:convert-to-lang "fill_string")
:arguments '(integer)
:return-type :lisp)
(setq foo (fstring *lsbi*))
Turns out the problem was we had to add 2 to the char * before sending
it over due to the length of the string being stored in the first 2
bytes of the string returned by lisp_value. Our docs had told us to
use a bunch of elaborate macros in a file called lisp.h (which didn't exist),
but it looks like one of the macros did a char* and the other added 2
to the pointer!
Just thought this might be of use to others...
Lynwood Hines