[gambit-list] Cython example : seg fault
David Dreisigmeyer
dwdreisigmeyer at gmail.com
Mon Jan 3 14:56:37 EST 2011
Hi,
Any advice on this would be greatly appreciated.
Thanks,
-Dave
---- I've been trying to get the server.scm example included in
gambit/tests to work with Cython. Here's the code from the example:
;------------------------------------------------------------------------------
; File: "server.scm", Time-stamp: <2007-04-04 11:40:46 feeley>
; Copyright (c) 1996-2007 by Marc Feeley, All Rights Reserved.
(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))
(c-define (eval-string str) (char-string) char-string "eval_string" "extern"
(catch-all-errors
(lambda () (write-to-string (eval (read-from-string str))))))
;------------------------------------------------------------------------------
---- I was finally able to get things "to work" by doing the following
(using the source code from here:
http://www.devx.com/opensource/Article/42778/1763/page/3 ):
$ gsc -verbose -c server.scm
Parsing:
catch-all-errors
write-to-string
read-from-string
eval-string
Compiling:
catch-all-errors
"unknown"
write-to-string
"unknown"
read-from-string
eval-string
"unknown"
Dumping:
#<primitive | server|>
#<procedure catch-all-errors>
#<procedure write-to-string>
#<procedure read-from-string>
#<procedure eval-string>
Compilation finished.
$ gsc -link server.c
$ gcc -Wall -dynamiclib -I/usr/local/Gambit-C/include
-L/usr/local/Gambit-C/lib -lgambc server.c server_.c -o
libserver.dylib
server.c: In function '___H__20_server':
server.c:151:1: warning: label '___L__20_server' defined but not used
server.c:142:1: warning: unused variable '___u64_temp'
server.c:142:1: warning: unused variable '___s64_temp'
server.c:142:1: warning: unused variable '___u32_temp'
server.c:142:1: warning: unused variable '___s32_temp'
server.c:142:1: warning: unused variable '___temp'
server.c: In function '___H_catch_2d_all_2d_errors':
server.c:183:1: warning: label '___L_catch_2d_all_2d_errors' defined
but not used
server.c:171:1: warning: unused variable '___u64_temp'
server.c:171:1: warning: unused variable '___s64_temp'
server.c:171:1: warning: unused variable '___u32_temp'
server.c:171:1: warning: unused variable '___s32_temp'
server.c: In function '___H_write_2d_to_2d_string':
server.c:224:1: warning: label '___L_write_2d_to_2d_string' defined but not used
server.c:211:1: warning: unused variable '___u64_temp'
server.c:211:1: warning: unused variable '___s64_temp'
server.c:211:1: warning: unused variable '___u32_temp'
server.c:211:1: warning: unused variable '___s32_temp'
server.c: In function '___H_read_2d_from_2d_string':
server.c:268:1: warning: label '___L_read_2d_from_2d_string' defined
but not used
server.c:258:1: warning: unused variable '___u64_temp'
server.c:258:1: warning: unused variable '___s64_temp'
server.c:258:1: warning: unused variable '___u32_temp'
server.c:258:1: warning: unused variable '___s32_temp'
server.c: In function '___H_eval_2d_string':
server.c:302:1: warning: label '___L_eval_2d_string' defined but not used
server.c:286:1: warning: unused variable '___u64_temp'
server.c:286:1: warning: unused variable '___s64_temp'
server.c:286:1: warning: unused variable '___u32_temp'
server.c:286:1: warning: unused variable '___s32_temp'
$ python server_setup.py build_ext --inplace
---- For my Python files I have:
** server_setup.py **
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 = ["server" , "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
)
** server_setup.pyx **
cdef extern from "server.h":
DEF VERSION = 406000 # Defining a constat with DEF (all caps).
char * eval_string ( char * )
def cpy_eval_string ( char *str ):
return eval_string ( str )
---- So now I open a REPL in Emacs:
In [2]: import cython_gambit_test
In [3]: cython_gambit_test.cpy_eval_string
Out[3]: <built-in function cpy_eval_string>
---- Seems good (why is that a built-in function?) until:
In [4]: cython_gambit_test.cpy_eval_string ("(print \"Hello\n\")")
Process Python segmentation fault
More information about the Gambit-list
mailing list