Ticket #1120 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

cffi problem (cl-opengl)

Reported by: vi1 Owned by:
Priority: normal Milestone:
Component: Foreign Function Interface Version: trunk
Keywords: cffi, cl-opengl Cc:


I ran into weird problem with cl-opengl and ccl. Looks like code is generated incorrectly for callbacks and program crashes.

Reproduces on Linux and Windows 64bit. Current trunk 1.10-dev-r15968M-trunk LinuxX8664 and 1.9 release. Up to date cffi_0.11.2, cl-opengl-20131003 from quicklisp.

Attached simple reduced test.


bug_reduced2.lisp Download (913 bytes) - added by vi1 3 years ago.
libfoo.c Download (216 bytes) - added by vi1 3 years ago.
test-cffi.lisp Download (1.2 KB) - added by vi1 3 years ago.

Change History

Changed 3 years ago by vi1

comment:1 Changed 3 years ago by gb

I actually tried to reproduce this. Installing quicklisp and doing

(ql:quickload :cl-opengl)

doesn't cause a package named GLUT to be defined for me; I don't know (or care) what I'd need to do to cause that to happen.

If you think that there's a CCL bug here, please isolate it so that it can be reproduced without any third-party code.

CCL comes with a simple GLUT example in "ccl:examples;opengl-ffi.lisp" that uses CCL's own FFI. I modified its display callback to funcall a function that calls "glColor4f"; it behaves correctly regardless of whether that function is a closure or a simple function.

comment:2 Changed 3 years ago by vi1

My bad, it should have been

(ql:quickload :cl-opengl) (ql:quickload :cl-glu) (ql:quickload :cl-glut)

Would you give it another try?

I'm sure it's cffi for ccl issue not ccl's ffi. Thanks.

Changed 3 years ago by vi1

Changed 3 years ago by vi1

comment:3 Changed 3 years ago by vi1

Spent some time learning a bit of cffi and was able to reduce to only cffi dependent test.

The problem appears when cffi's lisp wrapper for C function gets inlined.

Error: The value 17525671103806 is not of the expected type SINGLE-FLOAT.

I don't know if it's ccl or cffi related issue.

Attached two files: libfoo.c and test-cffi.lisp

I build C lib as follows:

gcc -shared -o libfoo.so -fPIC libfoo.c

and run lisp file as follows:

LD_LIBRARY_PATH=. ccl -l test-cffi.lisp

Commenting (declaim (inline foo)) fixes a problem. Thanks.

comment:4 Changed 3 years ago by gb

Thanks. It was a compiler bug that should now be fixed in the trunk in r15969.

comment:5 Changed 3 years ago by gb

Please hold on a second before upgrading to r15969; it may have broken something.

comment:6 Changed 3 years ago by gb

  • Status changed from new to closed
  • Resolution set to fixed

(In [15971]) Go back to using ra0/temp2 as foreign stack temp, but declare its usage.

Try again to fix ticket:1120 in the trunk.

comment:7 Changed 3 years ago by vi1

works perfectly, thanks

Note: See TracTickets for help on using tickets.