* CamlIDL question
@ 2005-10-25 22:26 Christian Stork
2005-10-26 5:03 ` [Caml-list] " Igor Pechtchanski
0 siblings, 1 reply; 7+ messages in thread
From: Christian Stork @ 2005-10-25 22:26 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 1185 bytes --]
I must be making a stupid mistake but I just don't see it. I put together a
simple example that shows the problem. Even though the camlidl library is
found its symbol "camlidl_free" is not. How can that be? Can anybody
reproduce the problem or is this some hickup on my system?
Here's what make produces (all files attached):
make extest
camlidl -header ex.idl
ocamlc -c ex.mli
ocamlc -c extest.ml
gcc -c ex.c
gcc -c ex_stubs.c
ocamlc -c ex.ml
ocamlc -verbose -custom -cclib -lcamlidl -o extest \
ex.o ex_stubs.o ex.cmo extest.cmo
+ gcc -Wl,-E -o 'extest' -I'/usr/lib/ocaml/3.08.3' /home/chs/tmp/camlprim262817.c '-L/usr/lib/ocaml/3.08.3' '-lcamlidl' 'ex.o' 'ex_stubs.o' -lcamlrun -lm -ldl -lcurses -lpthread
ex_stubs.o: In function `camlidl_ex_g':
ex_stubs.c:(.text+0x79): undefined reference to `camlidl_free'
ex_stubs.o: In function `camlidl_ex_f':
ex_stubs.c:(.text+0xd3): undefined reference to `camlidl_free'
collect2: ld returned 1 exit status
Error while building custom runtime system
make: *** [extest] Error 2
--
Chris Stork <> Support eff.org! <> http://www.ics.uci.edu/~cstork/
OpenPGP fingerprint: B08B 602C C806 C492 D069 021E 41F3 8C8D 50F9 CA2F
[-- Attachment #2: Makefile --]
[-- Type: text/plain, Size: 521 bytes --]
OCAMLC := ocamlc
all: extest
ex.cmi: ex.mli
$(OCAMLC) -c ex.mli
ex.cmo: ex.cmi ex.ml
$(OCAMLC) -c ex.ml
ex.h ex.ml ex.mli ex_stubs.c: ex.idl
camlidl -header ex.idl
ex.o: ex.c ex.h
gcc -c ex.c
ex_stubs.o: ex_stubs.c ex.h
gcc -c ex_stubs.c
extest.cmo: ex.cmi extest.ml
$(OCAMLC) -c extest.ml
extest: extest.cmo ex.o ex_stubs.o ex.cmo
$(OCAMLC) -verbose -custom -cclib -lcamlidl -o extest \
ex.o ex_stubs.o ex.cmo extest.cmo
clean:
rm -f *.cmo *.cmi *.o *~
rm -f ex_stubs.* ex.h ex.ml ex.mli extest
[-- Attachment #3: ex.idl --]
[-- Type: text/plain, Size: 64 bytes --]
typedef [abstract] struct foo_s * foo;
foo g();
int f(foo e);
[-- Attachment #4: ex.c --]
[-- Type: text/x-csrc, Size: 161 bytes --]
#include "ex.h"
struct foo_s {int i;};
foo g()
{
foo e = (foo) malloc (sizeof(struct foo_s));
e->i = 10;
return e;
}
int f(foo e)
{
return e->i;
}
[-- Attachment #5: extest.ml --]
[-- Type: text/plain, Size: 65 bytes --]
open Ex
;;
let e = g ();;
print_int (f e);;
print_string "\n";;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] CamlIDL question
2005-10-25 22:26 CamlIDL question Christian Stork
@ 2005-10-26 5:03 ` Igor Pechtchanski
2005-10-26 11:11 ` Christian Stork
0 siblings, 1 reply; 7+ messages in thread
From: Igor Pechtchanski @ 2005-10-26 5:03 UTC (permalink / raw)
To: Christian Stork; +Cc: caml-list
On Tue, 25 Oct 2005, Christian Stork wrote:
> I must be making a stupid mistake but I just don't see it. I put together a
> simple example that shows the problem. Even though the camlidl library is
> found its symbol "camlidl_free" is not. How can that be? Can anybody
> reproduce the problem or is this some hickup on my system?
>
> Here's what make produces (all files attached):
> [snip]
> make extest
> ocamlc -verbose -custom -cclib -lcamlidl -o extest \
> ex.o ex_stubs.o ex.cmo extest.cmo
Shouldn't this be
ocamlc -verbose -custom -cclib -o extest \
ex.o ex_stubs.o ex.cmo extest.cmo -lcamlidl
instead? Libraries should follow objects that refer to them...
HTH,
Igor
--
http://cs.nyu.edu/~pechtcha/
|\ _,,,---,,_ pechtcha@cs.nyu.edu
ZZZzz /,`.-'`' -. ;-;;,_ igor@watson.ibm.com
|,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D.
'---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!
If there's any real truth it's that the entire multidimensional infinity
of the Universe is almost certainly being run by a bunch of maniacs. /DA
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] CamlIDL question
2005-10-26 5:03 ` [Caml-list] " Igor Pechtchanski
@ 2005-10-26 11:11 ` Christian Stork
0 siblings, 0 replies; 7+ messages in thread
From: Christian Stork @ 2005-10-26 11:11 UTC (permalink / raw)
To: caml-list
On Wed, Oct 26, 2005 at 01:03:45AM -0400, Igor Pechtchanski wrote:
> On Tue, 25 Oct 2005, Christian Stork wrote:
> > I must be making a stupid mistake but I just don't see it. I put together a
> > simple example that shows the problem. Even though the camlidl library is
> > found its symbol "camlidl_free" is not. How can that be? Can anybody
> > reproduce the problem or is this some hickup on my system?
> > Here's what make produces (all files attached):
> > [snip]
> > make extest
> > ocamlc -verbose -custom -cclib -lcamlidl -o extest \
> > ex.o ex_stubs.o ex.cmo extest.cmo
> Shouldn't this be
> ocamlc -verbose -custom -cclib -o extest \
> ex.o ex_stubs.o ex.cmo extest.cmo -lcamlidl
> instead? Libraries should follow objects that refer to them...
Thanks, that was it.
--
Chris Stork <> Support eff.org! <> http://www.ics.uci.edu/~cstork/
OpenPGP fingerprint: B08B 602C C806 C492 D069 021E 41F3 8C8D 50F9 CA2F
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Caml-list] CamlIDL question
@ 2002-10-07 14:02 Yurii A. Rashkovskii
2002-10-13 8:48 ` Xavier Leroy
0 siblings, 1 reply; 7+ messages in thread
From: Yurii A. Rashkovskii @ 2002-10-07 14:02 UTC (permalink / raw)
To: caml-list
Gentlemen,
Is the below trick is possible in CamlIDL?
I want to wrap C library that uses structs for storing
pointers to functions, like
typedef struct {
int (*open)(char *filename);
} blablabla;
I want to wrap it automatically to something like
type blablabla =
{
open: (string -> int)
}
;;
Is it possible?
--
Thanks in advance,
Yurii.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] CamlIDL question
2002-10-07 14:02 Yurii A. Rashkovskii
@ 2002-10-13 8:48 ` Xavier Leroy
2002-10-13 17:10 ` Dmitry Bely
0 siblings, 1 reply; 7+ messages in thread
From: Xavier Leroy @ 2002-10-13 8:48 UTC (permalink / raw)
To: Yurii A. Rashkovskii; +Cc: caml-list
> Is the below trick is possible in CamlIDL?
> I want to wrap C library that uses structs for storing
> pointers to functions
No, CamlIDL doesn't support C function pointers. The reason is that
mapping C functions pointers to Caml functions is easy, but mapping
Caml function closures to C functions is nearly impossible (there is
nowhere to store and pass the environment part of the closure).
However, CamlIDL support COM interfaces, which are basically a subset
of C++ classes. These support two-way conversions between OCaml
objects (i.e. more or less collections of Caml functions) and COM objects
(i.e. more or less collections of C function pointers + instance
variables).
- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] CamlIDL question
2002-10-13 8:48 ` Xavier Leroy
@ 2002-10-13 17:10 ` Dmitry Bely
2002-10-13 23:12 ` Chris Hecker
0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Bely @ 2002-10-13 17:10 UTC (permalink / raw)
To: caml-list
Xavier Leroy <xavier.leroy@inria.fr> writes:
>> Is the below trick is possible in CamlIDL?
>> I want to wrap C library that uses structs for storing
>> pointers to functions
>
> No, CamlIDL doesn't support C function pointers. The reason is that
> mapping C functions pointers to Caml functions is easy, but mapping
> Caml function closures to C functions is nearly impossible (there is
> nowhere to store and pass the environment part of the closure).
It's possible using the "trampoline" technique, when the necessary small
stub functions are generated on the fly in the data (or stack)
segment. This is how gcc's nested functions work. There is "ffcall" library
that implements trampolines for (probably) all hardware platforms where
OCaml may run. Am I using it with OcamlIDL to do just what Youry asked
for. Unfortinately ffcall's author website has been disappeared, but it
should not be a problem to find "ffcall-1.8c.tar.gz" somethere in the
Internet.
- Dmitry Bely
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] CamlIDL question
2002-10-13 17:10 ` Dmitry Bely
@ 2002-10-13 23:12 ` Chris Hecker
0 siblings, 0 replies; 7+ messages in thread
From: Chris Hecker @ 2002-10-13 23:12 UTC (permalink / raw)
To: Dmitry Bely, caml-list
>There is "ffcall" library
>that implements trampolines for (probably) all hardware platforms where
>OCaml may run. Am I using it with OcamlIDL to do just what Youry asked
>for.
I was planning on using the ffcall library to make dynalinking to C
functions that take function pointers myself (you can see in the list
archive a year or so ago). I'm glad somebody's made it work.
However, the new bee in my bonnet is to have ocaml generate (or have it in
the asm files for each platform) a sort of meta-routine that can be called
at runtime to dynamically generate a range of different platform-specific
functions that are necessary for this kind of lowlevel work. You want some
kind of routine that can generate a closure/thunk like ffcall, or switch
the stack and cpu state like in the fiber/thread stuff, etc. The idea is
that since the ocaml runtime knows the platform (since it was compiled), it
makes sense to have it do the work of generating the necessary low level
code. This would be way better than forcing every library that wants to do
something cross-platform but low-level write asm or wacky C stuff or
include ffcall or another redundant cross-platform low level library (like
GNU pth, or whatever). If we got the generator function(s) right, you
could write a caml library that does wacky stuff and do it in a
cross-platform way (and if the meta-function was right and well debugged
you wouldn't have to exhaustively test your new library on every platform
before releasing it...well, maybe that's a bit optimistic, but you get the
idea).
The problem is to define the correct meta-function (or set of them), and
I'm not sure what that would be yet, but I'm pretty sure it's possible. I
got the idea from the concept of the "fold" function (homomorphisms)...you
can use fold to generate tons of other useful functions. I want the fold
for platform-specific low-level craziness. :)
Enough rambling,
Chris
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-10-26 11:11 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-25 22:26 CamlIDL question Christian Stork
2005-10-26 5:03 ` [Caml-list] " Igor Pechtchanski
2005-10-26 11:11 ` Christian Stork
-- strict thread matches above, loose matches on Subject: below --
2002-10-07 14:02 Yurii A. Rashkovskii
2002-10-13 8:48 ` Xavier Leroy
2002-10-13 17:10 ` Dmitry Bely
2002-10-13 23:12 ` Chris Hecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox