I tried using the shared library created from the modified test8 example, except I only called the functions from a C routine. That is, I didn't use Cython/Python. It looks like I'm getting the same problem here as when I tried using the shared library in Python:
$ ./gambit_tester setup done Gambit-C : (+ 1 2) 3 Gambit-C result : 3
There should also be a "cleanup done" printed out after the call to ___cleanup (), but it doesn't seem to finish that routine.
The code is attached. Do:
$ make tester $ ./gambit_tester
Thanks again.
-Dave
******************************************
Here's the code written out also:
----------------------------------------------------------------------
Use server.scm and server.h from gambit/tests
----------------------------------------------------------------------
/* 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
void gambit_setup( void ) { ___setup_params_struct setup_params; ___setup_params_reset (&setup_params); setup_params.version = ___VERSION; setup_params.linker = SCHEME_LIBRARY_LINKER; ___setup (&setup_params); }
char * gambit_eval( char *in_str ) { char *temp;
temp = eval_string (in_str); if (temp != 0){ printf ("%s\n", temp); } else { printf ("Error: temp == 0\n"); } ___release_string (temp); fflush ( stdout ); return temp; }
void gambit_cleanup ( void ) { fflush (stdout); ___cleanup (); }
----------------------------------------------------------------------
/* gambit_tester.c */
#include "client.h"
int main() {
char *temp;
gambit_setup(); printf("setup done\n");
printf ("Gambit-C : (+ 1 2)\n"); temp = gambit_eval("(+ 1 2)"); printf("Gambit-C result : %s\n", temp); ___release_string (temp);
fflush(stdout); gambit_cleanup(); printf("cleanup done\n"); fflush(stdout);
return 0; }
----------------------------------------------------------------------
C_COMPILER = /usr/bin/gcc-4.2 GAMBIT_GSC = gsc GAMBIT_INC_DIR = /usr/local/Gambit-C/include/ INC_DIR = . GAMBIT_LIB_DIR = /usr/local/Gambit-C/lib/ PYTHON = python PYTHON_INC = /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 PYTHON_LIB1 = /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib PYTHON_LIB2 = /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
all: extension standalone gsc tester
gsc: $(GAMBIT_GSC) -link server.scm $(C_COMPILER) -I$(GAMBIT_INC_DIR) -I$(INC_DIR) -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 $(C_COMPILER) -I$(GAMBIT_INC_DIR) -I$(INC_DIR) -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 $(C_COMPILER) -I$(GAMBIT_INC_DIR) -I$(INC_DIR) -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 $(C_COMPILER) -shared -I$(GAMBIT_INC_DIR) -I$(INC_DIR) -L$(GAMBIT_LIB_DIR) -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 tester: gsc $(C_COMPILER) gambit_tester.c -L. -lclient -I/usr/local/Gambit-C/include/ -o gambit_tester
extension: gsc # ======= Cython extension: $(PYTHON) server_setup.py build_ext --inplace standalone: gsc # ======= Cython standalone: $(PYTHON) /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Cython-0.14-py2.7-macosx-10.6-x86_64.egg/cython.py --embed server_setup.pyx $(C_COMPILER) -c server_setup.c -I$(PYTHON_INC) -I$(GAMBIT_INC_DIR) -I$(INC_DIR) $(C_COMPILER) -o server_setup server_setup.o client.o server.o server_.o -L$(GAMBIT_LIB_DIR) -lgambc -L$(PYTHON_LIB1) -L$(PYTHON_LIB2) -lpython2.7 -ldl -framework CoreFoundation
clean: rm -rf gambit.so libclient.so *.o server.c server_.c server_setup.c server_setup.o server_setup build/ gambit_tester
----------------------------------------------------------------------
Afficher les réponses par date
On 2011-01-13, at 11:38 PM, David Dreisigmeyer wrote:
I tried using the shared library created from the modified test8 example, except I only called the functions from a C routine. That is, I didn't use Cython/Python. It looks like I'm getting the same problem here as when I tried using the shared library in Python:
$ ./gambit_tester setup done Gambit-C : (+ 1 2) 3 Gambit-C result : 3
There should also be a "cleanup done" printed out after the call to ___cleanup (), but it doesn't seem to finish that routine.
The code is attached. Do:
$ make tester $ ./gambit_tester
Thanks again.
-Dave
This is what I get on Mac OS X, after making the corrections to os_io.c and os_tty.c that I suggested in previous messages:
$ ./gambit_tester setup done Gambit-C : (+ 1 2) 3 Gambit-C result : 3 cleanup done
Marc
My system again: OS X 10.6.6 and Gambit-C 4.6.0 from git.
I'm not getting that. The modified code is below. Here's what I get:
$ ./gambit_tester > hold
and hold looks like:
setup done Gambit-C : (+ 1 2) 3 Gambit-C result : 3
I even tried modifying ___cleanup:
___EXP_FUNC(void,___cleanup) ___PVOID { /* * Only do cleanup once after successful setup. */
printf ("setup_state : %i \n" , setup_state); fflush (stdout); sleep(30);
if (setup_state != 1) return;
setup_state = 2;
___cleanup_mem (); ___cleanup_os (); }
and it doesn't print or sleep.
--------------------------------------------------------
** Modified os_io.c:
/* #ifdef USE_POSIX if (close_no_EINTR (d->fd) < 0) return err_code_from_errno (); #endif */
#ifdef USE_POSIX if (d->fd > 2 && close_no_EINTR (d->fd) < 0) return err_code_from_errno (); #endif
#ifdef USE_WIN32 if (!CloseHandle (d->h)) return err_code_from_GetLastError (); #endif } else if (is_not_closed & direction & ___DIRECTION_RD) d->base.base.read_stage = ___STAGE_CLOSED; else if (is_not_closed & direction & ___DIRECTION_WR) d->base.base.write_stage = ___STAGE_CLOSED;
return ___FIX(___NO_ERR); }
--------------------------------------------------------
** Modified ___device_tty_cleanup (tried commenting out #ifdef USE_POSIX ... #endif also:
___HIDDEN ___SCMOBJ ___device_tty_cleanup ___P((___device_tty *self), (self) ___device_tty *self;) {
___device_tty *d = self; ___SCMOBJ e;
/* #ifdef USE_LINEEDITOR
lineeditor_cleanup (d);
#endif
if (d->stage >= TTY_STAGE_MODE_NOT_SAVED) { if (d->stage >= TTY_STAGE_MODE_NOT_SET) { if ((e = ___device_tty_mode_restore (d, 1)) != ___FIX(___NO_ERR)) return e; } */ #ifdef USE_POSIX if (close (d->fd) < 0) return err_code_from_errno (); #endif /* #ifdef USE_WIN32 if (!CloseHandle (d->hin)) return err_code_from_GetLastError (); if (!CloseHandle (d->hout)) return err_code_from_GetLastError (); #endif } */ return ___FIX(___NO_ERR); }
On 2011-01-15, at 12:26 PM, David Dreisigmeyer wrote:
#ifdef USE_POSIX if (close (d->fd) < 0) return err_code_from_errno (); #endif
This (in os_tty.c) must be commented out too, otherwise the controlling terminal will be closed when you get to the printf("cleanup done") which follows the call to ___cleanup. Please try that.
I will be changing the Gambit runtime so that file descriptors which were already open when ___setup was called, will not be closed when ___cleanup is called. The problem with the controlling terminal is that it is obtained by calling open("/dev/tty",...) so in principle it should be the Gambit runtime's responsibility to close it.
I think we are losing track of the original problem. The problem here is related to closing the file descriptors at the wrong time, so that subsequent output to the terminal (and stdout) do not occur. The original problem that you had was that Python was exiting with a non-zero process status. I don't think we are closer to a solution for that.
Marc
Hi Marc,
#ifdef USE_POSIX if (close (d->fd) < 0) return err_code_from_errno (); #endif
This (in os_tty.c) must be commented out too, otherwise the controlling terminal will be closed when you get to the printf("cleanup done") which follows the call to ___cleanup. Please try that.
*** I had tried that also, but it didn't work either.
I think we are losing track of the original problem. The problem here is related to closing the file descriptors at the wrong time, so that subsequent output to the terminal (and stdout) do not occur. The original problem that you had was that Python was exiting with a non-zero process status. I don't think we are closer to a solution for that.
*** I had tried getting help on the Cython mailing list on this also, incase the difficulty was arising from that. The suggestion was to first try calling the shared library using C and skipping any Cython stuff. That's where this came from -- I'm using gambit_tester.c to attempt to do in C only what I'd like to do using Python. I had also tried using Cython to create a standalone, but this didn't work either:
# This is for testing if Cython can at least get this running as a standalone print __name__
if __name__ == "__main__": print "Beginning Gambit-C setup" setup () print "Testing Gambit-C" my_str = "(+ 1 2)" print "Evaluating " + my_str + " :" eval(my_str) print "Beginning Gambit-C cleanup" cleanup () else: print "Huh?"
I guess I don't understand why this doesn't print or sleep either:
___EXP_FUNC(void,___cleanup) ___PVOID { /* * Only do cleanup once after successful setup. */
printf ("setup_state : %i \n" , setup_state); fflush (stdout); sleep(30);
if (setup_state != 1) return;
setup_state = 2;
___cleanup_mem (); ___cleanup_os (); }
I have done some refactoring of os_io.c to prevent closing file descriptors that were open when ___setup was called. The changes have been pushed to the repository. Could you please repeat your experiments with the new code?
Marc
On 2011-01-15, at 2:32 PM, David Dreisigmeyer wrote:
I guess I don't understand why this doesn't print or sleep either:
___EXP_FUNC(void,___cleanup) ___PVOID { /*
- Only do cleanup once after successful setup.
*/
printf ("setup_state : %i \n" , setup_state); fflush (stdout); sleep(30);
if (setup_state != 1) return;
setup_state = 2;
___cleanup_mem (); ___cleanup_os (); }
On 2011-01-17, at 4:20 PM, Marc Feeley wrote:
I have done some refactoring of os_io.c to prevent closing file descriptors that were open when ___setup was called. The changes have been pushed to the repository. Could you please repeat your experiments with the new code?
... and if you encounter problems, please make a tar ball with makefile with all the required files and I will investigate.
Marc
Will do Marc. Thanks again! -Dave
On Mon, Jan 17, 2011 at 6:26 PM, Marc Feeley feeley@iro.umontreal.ca wrote:
On 2011-01-17, at 4:20 PM, Marc Feeley wrote:
I have done some refactoring of os_io.c to prevent closing file descriptors that were open when ___setup was called. The changes have been pushed to the repository. Could you please repeat your experiments with the new code?
... and if you encounter problems, please make a tar ball with makefile with all the required files and I will investigate.
Marc
Hi Marc,
It's still not working. With the attached, doing:
$ make tester && ./gambit_tester > hold && nano hold
gives (in hold):
Beginning Gambit-C setup. Gambit-C setup done. |Gambit-C> (+ 1 2) 3 Releasing temp string. Beginning Gambit-C cleanup.
It should be:
Beginning Gambit-C setup. Gambit-C setup done. |Gambit-C> (+ 1 2) 3 Releasing temp string. Beginning Gambit-C cleanup. Gambit-C cleanup done.
Also, the following does not print or sleep (in setup.c):
___EXP_FUNC(void,___cleanup) ___PVOID { /* * Only do cleanup once after successful setup. */
printf ("setup_state : %i \n" , setup_state); fflush (stdout); sleep(30);
if (setup_state != 1) return;
setup_state = 2;
___cleanup_mem (); ___cleanup_os (); }
-Dave
On Mon, Jan 17, 2011 at 6:26 PM, Marc Feeley feeley@iro.umontreal.ca wrote:
On 2011-01-17, at 4:20 PM, Marc Feeley wrote:
I have done some refactoring of os_io.c to prevent closing file descriptors that were open when ___setup was called. The changes have been pushed to the repository. Could you please repeat your experiments with the new code?
... and if you encounter problems, please make a tar ball with makefile with all the required files and I will investigate.
Marc
On 2011-01-18, at 2:43 PM, David Dreisigmeyer wrote:
Hi Marc,
It's still not working. With the attached, doing:
$ make tester && ./gambit_tester > hold && nano hold
gives (in hold):
Beginning Gambit-C setup. Gambit-C setup done. |Gambit-C> (+ 1 2) 3 Releasing temp string. Beginning Gambit-C cleanup.
It should be:
Beginning Gambit-C setup. Gambit-C setup done. |Gambit-C> (+ 1 2) 3 Releasing temp string. Beginning Gambit-C cleanup. Gambit-C cleanup done.
When I try it on my Mac, with a Gambit-C updated to the latest commit, I get the correct output.
I have a hunch that you are linking with the *old* Gambit runtime library. I have attached the makefile that I use. Please try that.
The makefile has this comment at the top:
# Note: it is assumed that Gambit has been compiled in # ../gambc-v4_6_0-devel and that it has been updated to the latest # changes with a "git pull" and "make". # # This has been tested using: # # Gambit-C v4.6.0 updated to commit b67f817399fd6415874dc397432e1364be03b8c1 # Mac OS X 10.6.6 # # Here is the output: # # % make tester # % ./gambit_tester # Beginning Gambit-C setup. # Gambit-C setup done. # |Gambit-C> (+ 1 2) # 3 # Releasing temp string. # Beginning Gambit-C cleanup. # Gambit-C cleanup done. # # If a sleep is added to ___cleanup in lib/setup.c, then the program # sleeps as expected after the message "Beginning Gambit-C cleanup." # is printed.
Marc
Just checking. I gather that Cython is to Python as Gambit is to Scheme?
-- hendrik
Yes. I think it was mainly developed for Sage.
On Sat, Jan 15, 2011 at 2:49 PM, Hendrik Boom hendrik@topoi.pooq.com wrote:
Just checking. I gather that Cython is to Python as Gambit is to Scheme?
-- hendrik _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list