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 );
------------------------------------------------------
Afficher les réponses par date
Sorry, the command looked terrible. Here they are again:
new-host:python daviddreisigmeyer$ rm *.o *.so server.c server_.c server_setup.cnew-host:python daviddreisigmeyer$ gsc -link server.scm
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 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
On 2011-01-05, at 12:14 PM, David Dreisigmeyer wrote:
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
If I understand correctly, it is Python that is exiting abnormally. In other words it is not during the call to ___cleanup() that the process exits (but to make sure, add a printf just before and just after the call to ___cleanup()).
Assuming that that is true, it looks like a bad interaction between Gambit's runtime system and Python's runtime system. For example, Gambit restoring a signal handler that Python relies on, or changing the terminal settings, the timers, etc. You'll have to dig deeper to find the actual problem (with strace on Linux, I don't remember what it is called on Mac OS X).
If you want a quick an dirty solution, just don't call ___cleanup()!
Marc
It will print before the call to __cleanup() but not after the call.
What would the downside of not calling __cleanup() be? (I'm currently using this way.)
Thanks Marc,
-Dave
On Wed, Jan 5, 2011 at 2:43 PM, Marc Feeley feeley@iro.umontreal.ca wrote:
On 2011-01-05, at 12:14 PM, David Dreisigmeyer wrote:
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
If I understand correctly, it is Python that is exiting abnormally. In other words it is not during the call to ___cleanup() that the process exits (but to make sure, add a printf just before and just after the call to ___cleanup()).
Assuming that that is true, it looks like a bad interaction between Gambit's runtime system and Python's runtime system. For example, Gambit restoring a signal handler that Python relies on, or changing the terminal settings, the timers, etc. You'll have to dig deeper to find the actual problem (with strace on Linux, I don't remember what it is called on Mac OS X).
If you want a quick an dirty solution, just don't call ___cleanup()!
Marc
On 2011-01-05, at 2:52 PM, David Dreisigmeyer wrote:
It will print before the call to __cleanup() but not after the call.
Are you sure (I've seen situations where you have to fflush(stdout); after each printf to get the output).
Please run "dtruss ipython" (you may have to do "sudo dtruss ipython") with your code to see all the system calls that are made, which might indicate quickly where things went wrong during the call to ___cleanup.
What would the downside of not calling __cleanup() be? (I'm currently using this way.)
The memory for the Scheme heap won't be deallocated (probably not much in this example, but could be as large as the code asked for). Also, some file descriptors for open files will not be closed. And the terminal settings will not be restored correctly. And some signal handlers will still be installed (and under the control of the Gambit runtime).
Marc
The "sudo dtruss ipython" prints out a whole bunch of stuff but never allows me to use a prompt. I tried it with python also but it doesn't start.
There was an fflush(stdout) in the C code before the call to __cleanup(). This code works as long as __cleanup() is commented out:
void gambit_eval( char *in_str ) { char *temp;
temp = eval_string (in_str); if (temp != 0){ printf ("Gambit-C > %s", temp); } else { printf ("Error: temp == 0"); } ___release_string (temp); fflush (stdout); ___cleanup (); }
On Wed, Jan 5, 2011 at 3:16 PM, Marc Feeley feeley@iro.umontreal.ca wrote:
On 2011-01-05, at 2:52 PM, David Dreisigmeyer wrote:
It will print before the call to __cleanup() but not after the call.
Are you sure (I've seen situations where you have to fflush(stdout); after each printf to get the output).
Please run "dtruss ipython" (you may have to do "sudo dtruss ipython") with your code to see all the system calls that are made, which might indicate quickly where things went wrong during the call to ___cleanup.
What would the downside of not calling __cleanup() be? (I'm currently using this way.)
The memory for the Scheme heap won't be deallocated (probably not much in this example, but could be as large as the code asked for). Also, some file descriptors for open files will not be closed. And the terminal settings will not be restored correctly. And some signal handlers will still be installed (and under the control of the Gambit runtime).
Marc
On 2011-01-05, at 4:09 PM, David Dreisigmeyer wrote:
The "sudo dtruss ipython" prints out a whole bunch of stuff but never allows me to use a prompt. I tried it with python also but it doesn't start.
There was an fflush(stdout) in the C code before the call to __cleanup(). This code works as long as __cleanup() is commented out:
void gambit_eval( char *in_str ) { char *temp;
temp = eval_string (in_str); if (temp != 0){ printf ("Gambit-C > %s", temp); } else { printf ("Error: temp == 0"); } ___release_string (temp); fflush (stdout); ___cleanup (); }
Wait... are you calling ___cleanup() every time you evaluate something?
That won't work! The call to ___setup(...) is balanced by a call to ___cleanup(). In between those calls, you can call Scheme functions (such as eval_string).
Marc
All of my code is attached if anyone wants to take a look at it. The makefile assumes that Gambit is installed in /usr/local/Gambit-C and that cython is installed. Here's an example ipython session:
In [4]: import gambit
In [5]: gambit.setup () Gambit-C setup successful
In [6]: gambit.gamval ("(+ 1 2)") Gambit-C > 3
In [7]: gambit.cleanup () Trying Gambit-C cleanup Process Python exited abnormally with code 1
Thanks again,
-Dave
On Wed, Jan 5, 2011 at 4:14 PM, Marc Feeley feeley@iro.umontreal.ca wrote:
On 2011-01-05, at 4:09 PM, David Dreisigmeyer wrote:
The "sudo dtruss ipython" prints out a whole bunch of stuff but never allows me to use a prompt. I tried it with python also but it doesn't start.
There was an fflush(stdout) in the C code before the call to __cleanup(). This code works as long as __cleanup() is commented out:
void gambit_eval( char *in_str ) { char *temp;
temp = eval_string (in_str); if (temp != 0){ printf ("Gambit-C > %s", temp); } else { printf ("Error: temp == 0"); } ___release_string (temp); fflush (stdout); ___cleanup (); }
Wait... are you calling ___cleanup() every time you evaluate something?
That won't work! The call to ___setup(...) is balanced by a call to ___cleanup(). In between those calls, you can call Scheme functions (such as eval_string).
Marc