Gambit-C problem

58 views
Skip to first unread message

David

unread,
Jan 13, 2011, 3:17:23 PM1/13/11
to cython-users
Hi everyone,

I've been having problem trying to use Gambit-C scheme in Python.
Everything works fine if I compile Gambit-C alone and run it. But if
I try to combine it with Cython to make a extension it doesn't work.
I've been working on the problem with the Gambit-C folks and was
hoping there might be some suggestions on the Python side. I've
attached my code -- just run make. To run the standalone created by
Cython:

$ ./server_setup

-----------------------------------------------------------------------------------------------------------------

Here's a typical Python session:

Process Python finished
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 gambit

In [3]: gambit.cleanup ()
Gambit-C cleanup complete

In [4]: gambit.setup ()
Gambit-C setup successful

In [5]: gambit.cleanup ()

Process Python exited abnormally with code 1

-----------------------------------------------------------------------------------------------------------------

This is on OS X 10.6.6 with gcc-4.2, Cython 0.14, Python 2.7.1 and
Gambit-C 4.6.0 from git. To install Gambit-C see:

http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Contributing_Patches_to_Gambit_Source_Code

or maybe http://www.iro.umontreal.ca/~gambit/download/gambit/v4.6/prebuilt/
though I'm using the above. Macports might work also.

The code for this is here:

https://docs.google.com/leaf?id=0B4PJONnq-MgAZGNiZTg4ZGUtNmRmYy00ZGE4LTgxNjMtMzY3NmRkMDM5MWE2&hl=en&authkey=CPzbuq4C

I should mention that neither printf nor sleep work if, e.g., I
modify the Gambit-C source code like the following (in
gambit/lib/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 ();
}

Thanks!

-Dave

Robert Bradshaw

unread,
Jan 13, 2011, 4:59:33 PM1/13/11
to cython...@googlegroups.com

Both printf and sleep should work just fine from Cython, I've used
them myself. Are you sure that gambit is not starting up threads
and/or trying to run an interpreter/event loop itself?

Can you even run the C program

int main() {
gambit_setup();
printf("setup done\n");
printf("%s\n", gambit_eval("(+, 1, 2)"));
gambit_cleanup();
printf("cleanup done\n");
}

?

- Robert

David Dreisigmeyer

unread,
Jan 13, 2011, 5:28:00 PM1/13/11
to cython...@googlegroups.com
Yes, everything works fine if I only use Gambit-C.

Robert Bradshaw

unread,
Jan 13, 2011, 5:32:55 PM1/13/11
to cython...@googlegroups.com
On Thu, Jan 13, 2011 at 2:28 PM, David Dreisigmeyer
<dwdreis...@gmail.com> wrote:
> Yes, everything works fine if I only use Gambit-C.

What do you mean by "only use Gambit-C"? The shipped binary?

- Robert

David Dreisigmeyer

unread,
Jan 13, 2011, 5:42:36 PM1/13/11
to cython...@googlegroups.com
I meant that I used Gambit's gsc to create an executable. So I didn't
first create a shared-library with Gambit and then use that library
with Cython. Instead I just run the test8 example included with the
Gambit-C source code. It's essentially the same as the example you
suggested.

Robert Bradshaw

unread,
Jan 13, 2011, 5:45:36 PM1/13/11
to cython...@googlegroups.com
On Thu, Jan 13, 2011 at 2:42 PM, David Dreisigmeyer
<dwdreis...@gmail.com> wrote:
> I meant that I used Gambit's gsc to create an executable.  So I didn't
> first create a shared-library with Gambit and then use that library
> with Cython.  Instead I just run the test8 example included with the
> Gambit-C source code.  It's essentially the same as the example you
> suggested.

Then I would suggest trying to use it as a shared library (with all
the linking options that you're using for the Python version, but
linking against a pain C program rather than a Cython exception) and
see if you can get that working before trying to throw Cython in the
mix. (I'm saying this because the Cython part itself seems pretty
straightforward, so I think the issue is elsewhere.)

- Robert

David Dreisigmeyer

unread,
Jan 13, 2011, 11:23:24 PM1/13/11
to cython...@googlegroups.com
It does seem to be a problem on the Gambit-C side. Thanks Robert, -Dave

Robert Bradshaw

unread,
Jan 14, 2011, 2:21:47 AM1/14/11
to cython...@googlegroups.com
On Thu, Jan 13, 2011 at 8:23 PM, David Dreisigmeyer
<dwdreis...@gmail.com> wrote:
> It does seem to be a problem on the Gambit-C side.  Thanks Robert, -Dave

You're welcome; good luck.

Reply all
Reply to author
Forward
0 new messages