On 25/06/12 18:43, Aleks Kissinger wrote:
Yes, I realise this is a bit evil, so maybe it's just lucky that it didn't cause problems on the linux side. However, I get the same crash when I call a test function (with the correct signature) that is simply *linking* the gtk library:
#include<gtk/gtk.h>
int times2(int i) { return i*2; }
This, built with:
gcc -fPIC -c ml_helpers.c -o ml_helpers.o `pkg-config --cflags gtk+-2.0` gcc -shared -Wl -o ../libpolygtk.so ml_helpers.o `pkg-config --libs gtk+-2.0`
Unfortunately I can't reproduce the issue as I don't have OS X. Still, it would be useful to know the exact version of Poly/ML that you are using.
On my machine (Linux x86_64) the file libpolygtk.so, generated with the commands you give, is identical whether or not the #include line is present, which probably explains why I don't get any error. Once the SO file is built, the following works fine:
LD_LIBRARY_PATH=..: poly << ++++ local open CInterface; val lib = load_lib "libpolygtk.so"; in val times2 = call1 (load_sym lib "times2") INT INT; end; times2 3; ++++
To answer your other question: I am in the process of writing some very basic GTK bindings for Poly, at least initially for rapid prototyping and testing. There's a github project:
https://github.com/akissinger/polygtk
I've had success getting the two included examples (some buttons w. callbacks and text entry) working in linux, but this mysterious crash is holding up OS X support.
I've been working on GTK+ bindings for quite a while now. These support both MLton and Poly/ML but it's still not quite ready for release. (Initially I started extending mGTK, but it's now a 100% rewrite.) For that reason, I'm very interested in why including gtk.h breaks dynamic libraries.
Phil
On 25 June 2012 16:27, Phil Claytonphil.clayton@lineone.net wrote:
On 24/06/12 01:47, Aleks Kissinger wrote:
Any idea why calling symbols from certain shared libraries would cause poly/ML to crash on OS X? Example:
val gtk = load_lib "libgtk-quartz-2.0.dylib";
val gtk = ?: dylib
val gtk_init = call2 (load_sym gtk "gtk_init") (INT,INT) VOID;
val gtk_init = fn: int * int -> unit
gtk_init(0,0);
[1] 96630 killed rlwrap -z poly
It doesn't completely surprise me that this crashes: gtk_init has the signature
void gtk_init (int *argc, char ***argv);
so you're using the conversion INT for passing a pointer. INT is same size as the C int, which is likely to be 32 bits on a 64 bit platform. However, on a 64 bit platform, a pointer should be 64 bits. I suspect that this, possibly along with different calling conventions, might cause the variation you see between platforms.
The conversion LONG will give you the C long, usually the same size as a pointer, but you really want to be using the conversions POINTER or POINTERTO for passing pointers.
Out of interest, are you attempting to use GTK+ from SML?
Phil