This is on OS X 10.6.5 using Gambit-C 4.6.0 from the git repository.
I'm trying out the client.c example from gambit/test. The problem is the call to __cleanup(). If I comment that out everything works. Here's the commands I'm using:
new-host:python daviddreisigmeyer$ rm *.o *.so server.c server_.c server_setup.cnew-host:python daviddreisigmeyer$ gsc -link server.scmnew-host:python daviddreisigmeyer$ gcc -I/usr/local/Gambit-C/include/ -I/Users/daviddreisigmeyer/Programming/python -Wno-unused -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fomit-frame-pointer -fPIC -fno-common -mieee-fp -c -o client.o client.c new-host:python daviddreisigmeyer$ gcc -I/usr/local/Gambit-C/include/ -I/Users/daviddreisigmeyer/Programming/python -Wno-unused -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fomit-frame-pointer -fPIC -fno-common -mieee-fp -c -o server.o server.c -D___LIBRARY new-host:python daviddreisigmeyer$ gcc -I/usr/local/Gambit-C/include/ -I/Users/daviddreisigmeyer/Programming/python -Wno-unused -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fomit-frame-pointer -fPIC -fno-common -mieee-fp -c -o server_.o server_.c -D___LIBRARY new-host:python daviddreisigmeyer$ gcc -shared -I/usr/local/Gambit-C/include/ -I/Users/daviddreisigmeyer/Programming/python -L/usr/local/Gambit-C/lib/ -lgambc -Wno-unused -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fomit-frame-pointer -fno-common -mieee-fp -o libclient.so client.o server.o server_.o new-host:python daviddreisigmeyer$ python server_setup.py build_ext --inplacerunning build_ext cythoning server_setup.pyx to server_setup.c building 'cython_gambit_test' extension /usr/bin/gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -pipe -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Gambit-C/include -I/Users/daviddreisigmeyer/Programming/python -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c server_setup.c -o build/temp.macosx-10.6-x86_64-2.7/server_setup.o /usr/bin/gcc-4.2 -L/opt/local/lib -bundle -undefined dynamic_lookup -L/opt/local/lib build/temp.macosx-10.6-x86_64-2.7/server_setup.o -L/usr/local/Gambit-C/lib -L/Users/daviddreisigmeyer/Programming/python -lclient -lgambc -o /Users/daviddreisigmeyer/Programming/python/cython_gambit_test.so
Then in ipython:
Python 2.7.1 (r271:86832, Dec 29 2010, 01:38:09) Type "copyright", "credits" or "license" for more information.
IPython 0.10.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more.
In [2]: import cython_gambit_test
In [3]: cython_gambit_test.cython_gambit_test () result = #!void result = 16 result = #<datum-parsing-exception #2> result = #<unbound-global-exception #3>
Process Python exited abnormally with code 1
Below is the code I'm using. Any help would be really appreciated.
Thanks!
-Dave
------------------------------------------------------
/* File: "client.c", Time-stamp: <2007-09-12 00:07:21 feeley> */
#include <stdio.h> #include <stdlib.h> #define ___VERSION 406000 #include "gambit.h" #include "server.h" #define SCHEME_LIBRARY_LINKER ____20_server__
___BEGIN_C_LINKAGE extern ___mod_or_lnk SCHEME_LIBRARY_LINKER (___global_state_struct*); ___END_C_LINKAGE
int gambit_test ( void ) { char *temp;
___setup_params_struct setup_params; ___setup_params_reset (&setup_params); setup_params.version = ___VERSION; setup_params.linker = SCHEME_LIBRARY_LINKER; ___setup (&setup_params);
temp = eval_string ("(define x 4)"); if (temp != 0) { printf ("result = %s\n", temp); ___release_string (temp); // don't forget to reclaim string } temp = eval_string ("(expt 2 x)"); if (temp != 0) { printf ("result = %s\n", temp); ___release_string (temp); } temp = eval_string ("(+ 1 2"); // note: missing closing parenthesis if (temp != 0) { printf ("result = %s\n", temp); ___release_string (temp); } temp = eval_string ("(+ x y)"); // note: y is unbound if (temp != 0) { printf ("result = %s\n", temp); ___release_string (temp); }
fflush (stdout);
___cleanup ();
return 0; }
************
/* server.h */
extern char *eval_string (char *);
************
; File: "server.scm" ; Copyright (c) 1996-2007 by Marc Feeley, All Rights Reserved.
; This is a simple server that can evaluate a string of Scheme code.
(define (catch-all-errors thunk) (with-exception-catcher (lambda (exc) (write-to-string exc)) thunk))
(define (write-to-string obj) (with-output-to-string '() (lambda () (write obj))))
(define (read-from-string str) (with-input-from-string str read))
; The following "c-define" form will define the function "eval_string" ; which can be called from C just like an ordinary C function. The ; single argument is a character string (C type "char*") and the ; result is also a character string.
(c-define (eval-string str) (char-string) char-string "eval_string" "extern" (catch-all-errors (lambda () (write-to-string (eval (read-from-string str))))))
;------------------------------------------------------------------------------
************
from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext
ext_modules=[ Extension("cython_gambit_test", ["server_setup.pyx"], include_dirs = ['/usr/local/Gambit-C/include' , "/Users/daviddreisigmeyer/Programming/python"], libraries = ["client" , "gambc"], library_dirs = ['/usr/local/Gambit-C/lib' , "/Users/daviddreisigmeyer/Programming/python"]) ]
setup( name = "SERVER-setup", cmdclass = {"build_ext": build_ext}, ext_modules = ext_modules )
************
cdef extern from "server.h": char * eval_string ( char * )
cdef extern from "client.h": int gambit_test ()
def cython_gambit_test (): return gambit_test ()
************
/* client.h */
#include <stdio.h> #include <stdlib.h> #define ___VERSION 406000 #include "gambit.h" #include "server.h"
int gambit_test ( void );
------------------------------------------------------