* AW: [Caml-list] OCaml-3.08.1/MinGW: alloc_tuple fails
@ 2004-10-14 14:59 Bauer, Christoph
2004-10-14 16:19 ` Richard Jones
0 siblings, 1 reply; 8+ messages in thread
From: Bauer, Christoph @ 2004-10-14 14:59 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 212 bytes --]
> > t = alloc_tuple( 100 );
> > for( i=0 ; i < 100; ++i )
> > Store_field( t, i, Int_val ( i ));
>
> s/Int_val/Val_int/
Ok, that's correct. But the problem is before the for-loop.
Christoph Bauer
[-- Attachment #2: Type: text/html, Size: 791 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] OCaml-3.08.1/MinGW: alloc_tuple fails
2004-10-14 14:59 AW: [Caml-list] OCaml-3.08.1/MinGW: alloc_tuple fails Bauer, Christoph
@ 2004-10-14 16:19 ` Richard Jones
0 siblings, 0 replies; 8+ messages in thread
From: Richard Jones @ 2004-10-14 16:19 UTC (permalink / raw)
To: Bauer, Christoph; +Cc: caml-list
[-- Attachment #1: Type: text/plain, Size: 918 bytes --]
On Thu, Oct 14, 2004 at 04:59:01PM +0200, Bauer, Christoph wrote:
>
> > > t = alloc_tuple( 100 );
> > > for( i=0 ; i < 100; ++i )
> > > Store_field( t, i, Int_val ( i ));
> >
> > s/Int_val/Val_int/
>
>
> Ok, that's correct. But the problem is before the for-loop.
It looks correct to me, but often memory corruption happens earlier
than is detected. Try adding a call to Gc.full_major () just before
you call your C function. If it crashes in the Gc, then you've got
memory corruption, and you'll need to pepper your code with calls to
Gc.full_major () to try and narrow it down.
Hope that helps anyway,
Rich.
--
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
Learning Objective CAML for C, C++, Perl and Java programmers:
http://www.merjis.com/richj/computers/ocaml/tutorial/
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Caml-list] OCaml-3.08.1/MinGW: alloc_tuple fails
@ 2004-10-14 13:23 Bauer, Christoph
2004-10-15 13:20 ` Damien Doligez
2004-10-15 15:04 ` Xavier Leroy
0 siblings, 2 replies; 8+ messages in thread
From: Bauer, Christoph @ 2004-10-14 13:23 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 1080 bytes --]
Hi Caml-List,
I have a problem with alloc_tuple. Maybe it's a bug, maybe it's me...
A program (from the OCam'Ole package) segfaults in a alloc_tuple call.
This behavior is shown only with native compilation. Here is a small
program to reproduce the problem (OCaml 3.08.1/MinGW):
/* test.c */
#include <caml/alloc.h>
#include <caml/memory.h>
CAMLprim value test( value _ )
{
CAMLparam1( _ );
CAMLlocal1( t );
int i;
t = alloc_tuple( 100 );
for( i=0 ; i < 100; ++i )
Store_field( t, i, Int_val ( i ));
CAMLreturn ( Val_unit );
}
/* test_it.ml */
external test : unit -> unit = "test"
let _ = test ()
/* compile.sh */
#!/bin/sh -v
gcc -mno-cygwin -c -shared -O -mms-bitfields -DCAML_DLL -DDLL=1 -I
c:/ocamlmgw/lib test.cpp -D_DEBUG -g
gcc -shared -mno-cygwin -mms-bitfields -I C:/ocamlmgw/lib -o dlltest.dll
-Wl,--out-implib,libtest.a test.o c:/ocamlmgw/lib/ocamlrun.a
chmod 777 dlltest.dll
ocamlopt -ccopt dlltest.dll -ccopt -g -o test_it.exe test_it.ml
ocamlc -dllib dlltest.dll -ccopt -g -o test_it_bc.exe test_it.ml
Thanks for any help,
Christoph Bauer
[-- Attachment #2: Type: text/html, Size: 2269 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] OCaml-3.08.1/MinGW: alloc_tuple fails
2004-10-14 13:23 Bauer, Christoph
@ 2004-10-15 13:20 ` Damien Doligez
2004-10-15 13:45 ` Olivier Andrieu
2004-10-15 15:04 ` Xavier Leroy
1 sibling, 1 reply; 8+ messages in thread
From: Damien Doligez @ 2004-10-15 13:20 UTC (permalink / raw)
To: Bauer, Christoph, caml users
On Oct 14, 2004, at 15:23, Bauer, Christoph wrote:
> CAMLprim value test( value _ )
> {
> CAMLparam1( _ );
> CAMLlocal1( t );
> int i;
> t = alloc_tuple( 100 );
> for( i=0 ; i < 100; ++i )
> Store_field( t, i, Int_val ( i ));
> CAMLreturn ( Val_unit );
> }
You are not supposed to use Store_field on a value that is not yet
initialized. You should write this instead:
caml_initialize (&Field (t, i), Val_int (i));
-- Damien
-------------------
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] 8+ messages in thread
* Re: [Caml-list] OCaml-3.08.1/MinGW: alloc_tuple fails
2004-10-15 13:20 ` Damien Doligez
@ 2004-10-15 13:45 ` Olivier Andrieu
2004-10-15 14:49 ` Damien Doligez
0 siblings, 1 reply; 8+ messages in thread
From: Olivier Andrieu @ 2004-10-15 13:45 UTC (permalink / raw)
To: damien.doligez; +Cc: Christoph.Bauer, caml-list
Damien Doligez [Fri, 15 Oct 2004]:
> On Oct 14, 2004, at 15:23, Bauer, Christoph wrote:
>
> > CAMLprim value test( value _ )
> > {
> > CAMLparam1( _ );
> > CAMLlocal1( t );
> > int i;
> > t = alloc_tuple( 100 );
> > for( i=0 ; i < 100; ++i )
> > Store_field( t, i, Int_val ( i ));
> > CAMLreturn ( Val_unit );
> > }
>
> You are not supposed to use Store_field on a value that is not yet
> initialized. You should write this instead:
>
> caml_initialize (&Field (t, i), Val_int (i));
Hum, doesn't alloc_tuple(n) (which is simply alloc(n, 0)) already
initialise the block with zeroes ?
--
Olivier
-------------------
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] 8+ messages in thread
* Re: [Caml-list] OCaml-3.08.1/MinGW: alloc_tuple fails
2004-10-15 13:45 ` Olivier Andrieu
@ 2004-10-15 14:49 ` Damien Doligez
2004-10-16 23:56 ` Erik de Castro Lopo
0 siblings, 1 reply; 8+ messages in thread
From: Damien Doligez @ 2004-10-15 14:49 UTC (permalink / raw)
To: caml users
On Oct 15, 2004, at 15:45, Olivier Andrieu wrote:
> Hum, doesn't alloc_tuple(n) (which is simply alloc(n, 0)) already
> initialise the block with zeroes ?
Oops, that's true, so it's OK to use Store_field.
I have another theory for Christoph's problem: maybe some
incompatibility between C and C++ calling conventions. Is it
supposed to work when you compile a C file with a C++ compiler,
then link it with other C files compiled with a C compiler?
-- Damien
-------------------
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] 8+ messages in thread
* Re: [Caml-list] OCaml-3.08.1/MinGW: alloc_tuple fails
2004-10-15 14:49 ` Damien Doligez
@ 2004-10-16 23:56 ` Erik de Castro Lopo
0 siblings, 0 replies; 8+ messages in thread
From: Erik de Castro Lopo @ 2004-10-16 23:56 UTC (permalink / raw)
To: caml users
On Fri, 15 Oct 2004 16:49:33 +0200
Damien Doligez <damien.doligez@inria.fr> wrote:
> I have another theory for Christoph's problem: maybe some
> incompatibility between C and C++ calling conventions. Is it
> supposed to work when you compile a C file with a C++ compiler,
> then link it with other C files compiled with a C compiler?
It will work only if all public functions (ie functions called from
the other C files) are declared as extern "C".
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo nospam@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"There is no satisfactory substitute for excellence."
-- Dr. Arnold O. Beckman
-------------------
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] 8+ messages in thread
* Re: [Caml-list] OCaml-3.08.1/MinGW: alloc_tuple fails
2004-10-14 13:23 Bauer, Christoph
2004-10-15 13:20 ` Damien Doligez
@ 2004-10-15 15:04 ` Xavier Leroy
1 sibling, 0 replies; 8+ messages in thread
From: Xavier Leroy @ 2004-10-15 15:04 UTC (permalink / raw)
To: Bauer, Christoph; +Cc: caml-list
> A program (from the OCam'Ole package) segfaults in a alloc_tuple call.
> This behavior is shown only with native compilation.
There have been many theories on what could be wrong in the C
function you showed. However, I believe the problem comes from the
way you link it with the native code produced by ocamlopt:
> gcc -mno-cygwin -c -shared -O -mms-bitfields -DCAML_DLL -DDLL=1 -I
> c:/ocamlmgw/lib test.cpp -D_DEBUG -g
> gcc -shared -mno-cygwin -mms-bitfields -I C:/ocamlmgw/lib -o dlltest.dll
> -Wl,--out-implib,libtest.a test.o c:/ocamlmgw/lib/ocamlrun.a
By linking with the import library ocamlrun.a, you bind your C code to
the bytecode Caml runtime system. Any program that links with
dlltest.dll will cause ocamlrun.dll to be loaded, and your test.c code
will use the alloc_tuple() function from ocamlrun.dll.
This is fine if you later use dlltest.dll with an ocamlc-compiled
program, since the latter also uses ocamlrun.dll as its runtime
system.
This is wrong if you use dlltest.dll with an ocamlopt-compiled
program, as in
ocamlopt -ccopt dlltest.dll -ccopt -g -o test_it.exe test_it.ml
since the latter is statically linked with a different runtime system
(libasmrun.a, the native-code runtime system). You get two different
runtime systems that don't "speak" to each other.
So, there is no way you can use the same DLL with both bytecode and
native-code.
You should however be able to compile your test.c code to a static
library (libtest.a). This static lib is not pre-bound to a particular
version of the runtime system. So,
ocamlc -custom .... libtest.a
will link everything with the bytecode runtime system, and
ocamlopt ... libtest.a
will link everything with the native-code runtime system.
More generally speaking, given the way Windows DLLs work, I don't
think it is possible at all to put Caml-C stub code in a DLL and pass
that DLL to ocamlopt. Static linking is your friend here.
- 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] 8+ messages in thread
end of thread, other threads:[~2004-10-16 23:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-14 14:59 AW: [Caml-list] OCaml-3.08.1/MinGW: alloc_tuple fails Bauer, Christoph
2004-10-14 16:19 ` Richard Jones
-- strict thread matches above, loose matches on Subject: below --
2004-10-14 13:23 Bauer, Christoph
2004-10-15 13:20 ` Damien Doligez
2004-10-15 13:45 ` Olivier Andrieu
2004-10-15 14:49 ` Damien Doligez
2004-10-16 23:56 ` Erik de Castro Lopo
2004-10-15 15:04 ` Xavier Leroy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox