[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with foreign functions



Hello,

The first problem is that some combinations of arguments (in fact,
my example is the only one I know) of C functions to called from
Lisp do not work.
  The function that does not work has 3 doubles and then one char*,
and the closest function that works has 2 doubles and then one char*.

#include <stdio.h>

double koe1(i,j,k,s) double i,j,k; char *s;
{
  printf("%f %f %f %s\n",i,j,k,s);
  return(i*2);
}

double koe2(i,j,s) double i,j; char *s;
{
  printf("%f %f %s\n",i,j,s);
  return(i*2);
}

That was my file koe.c, and what I get when running it is the following
(this is the 15a-something version. The 2 newer versions 15b something
and the brand-new 15c version do the same, though the exact error message
might be different):


CMU Common Lisp 16-Oct-1991 HUT, running on bishop.hut.fi
Hemlock <not loaded>, Python 1.0(16-Oct-1991 HUT), target SPARCstation/Sun 4
Send bug reports and questions to cmucl-bugs@cs.cmu.edu.
* (load-foreign "koe.o")
;;; Running library:load-foreign.csh...
;;; Loading object file...
;;; Parsing symbol table...
Warning:
"_etext" moved from #x00032E40 to #x00C000E8.

Warning:
"_edata" moved from #x00043C30 to #x00C00100.

Warning:
"_end" moved from #x0004E2D0 to #x00C00100.

;;; Done.
NIL
* (def-c-routine "koe1" (double-float)
  (d1 double-float) (d2 double-float) (d3 double-float) (s system:null-terminated-string))

KOE1
* (def-c-routine "koe2" (double-float)
  (d1 double-float) (d2 double-float) (s system:null-terminated-string))

KOE2

* (compile 'koe1)
Compiling FUNCTION LAMBDA:
Compiling Top-Level Form:

KOE1
NIL
NIL
* (compile 'koe2)
Compiling FUNCTION LAMBDA:
Compiling Top-Level Form:

KOE2
NIL
NIL
* (koe2 1d0 2d0 "asdfasfd")
1.000000 2.000000 asdfasfd

2.0d0
* (koe1 1d0 2d0 3d0 "asdfasdf")
segv_handler: No mapping fault: 0x00000004

Error in function MACH::SIGSEGV-HANDLER.
Segmentation Violation at #x246FC.

Restarts:
  0: Return to Top-Level.

Debug  (type H for help)

(DEBUG::DEBUG-LOOP)
0] d

(DEBUG:INTERNAL-DEBUG)
1] d

(INVOKE-DEBUGGER #<SIMPLE-ERROR.705437D>)
2] d

(ERROR "Segmentation Violation at #x~x." 149244)
3] d

(MACH::SIGSEGV-HANDLER #<unused-arg>
                       #<unused-arg>
                       #<System-Area pointer: #xF7FFE528>)
4] d

("Foreign function call land")
5] d

(KOE1 1.0d0 2.0d0 3.0d0 "asdfasdf")
6]


The second problem I have is when I load C object files twice using
load-foreign (it is the same irrespective of what's in the object
files, or how manu object files are loaded using the load-foreign.
E.g. the actual situation that bothers me is when I have loaded CLM,
and later want to have a single small C function residing in its
own .o file).

CMU Common Lisp 16-Oct-1991 HUT, running on bishop.hut.fi
Hemlock <not loaded>, Python 1.0(16-Oct-1991 HUT), target SPARCstation/Sun 4
Send bug reports and questions to cmucl-bugs@cs.cmu.edu.
* (load-foreign "test.o")
;;; Running library:load-foreign.csh...
;;; Loading object file...
;;; Parsing symbol table...
Warning:
"_etext" moved from #x00032E40 to #x00C00038.

Warning:
"_edata" moved from #x00043C30 to #x00C00038.

Warning:
"_end" moved from #x0004E2D0 to #x00C00FD8.

;;; Done.
NIL
* (load-foreign "koe.o")
;;; Running library:load-foreign.csh...
;;; Loading object file...



Error in function SYSTEM:GR-ERROR.
MACH:VM_ALLOCATE, kernal failure.

Restarts:
  0: Return to Top-Level.

Debug  (type H for help)

(DEBUG::DEBUG-LOOP)
0] d

(DEBUG:INTERNAL-DEBUG)
1] d

(INVOKE-DEBUGGER #<SIMPLE-ERROR.702B56D>)
2] d

(ERROR "~S~@[ ~A~], ~(~A~)." MACH:VM_ALLOCATE NIL "Kernal failure")
3] d

(SYSTEM:GR-ERROR MACH:VM_ALLOCATE 5 NIL)
4] d

(SYSTEM::ALLOCATE-SPACE-IN-FOREIGN-SEGMENT 408)
5] d

(SYSTEM::LOAD-OBJECT-FILE "/tmp/tmp5593B")
6] d

(LOAD-FOREIGN "koe.o" ("-lc") "library:load-foreign.csh" "path:lisp" ...)
7] d

(INTERACTIVE-EVAL (LOAD-FOREIGN "koe.o"))
8] d

(LISP::%TOP-LEVEL)
9]

This too happens in the more recent releases of CMU CL.

What I can hope is to have simple fixes for these problems. If that is not
possible I think I am happy to wait for the new version of the ff stuff.

Jussi Rintanen (Jussi.Rintanen@hut.fi)
Helsinki University of Technology
Department of Computer Science