caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* caml_alloc + 64 bits - caml_alloc.h
@ 2009-01-13  4:51 Daniel de Rauglaudre
  2009-01-13  4:58 ` [Caml-list] " Erik de Castro Lopo
  2009-01-13  9:37 ` malc
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel de Rauglaudre @ 2009-01-13  4:51 UTC (permalink / raw)
  To: caml-list

Hi everybody,

Possibly useful information. Is it already known?

When using calls to "caml_alloc" in a 64 bits architecture without
having included "caml/alloc.h", it raises "Segmentation fault" at
execution time.

Notice that I got no warning at compilation time for using caml_alloc
without a definition stub.

In 32 bits architecture, I never had any problem with that.

Morality:
   Don't forget to #include "caml/alloc.h" in your C programs
   if you alloc OCaml things!

-- 
Daniel de Rauglaudre
http://pauillac.inria.fr/~ddr/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] caml_alloc + 64 bits - caml_alloc.h
  2009-01-13  4:51 caml_alloc + 64 bits - caml_alloc.h Daniel de Rauglaudre
@ 2009-01-13  4:58 ` Erik de Castro Lopo
  2009-01-13  5:15   ` Daniel de Rauglaudre
  2009-01-13  9:37 ` malc
  1 sibling, 1 reply; 5+ messages in thread
From: Erik de Castro Lopo @ 2009-01-13  4:58 UTC (permalink / raw)
  To: caml-list

Daniel de Rauglaudre wrote:

> Morality:
>    Don't forget to #include "caml/alloc.h" in your C programs
>    if you alloc OCaml things!

If you are using GCC, GCC can warn you if you use the 
-Wmissing-prototypes warning flag.

Erik
-- 
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"The evolution of languages: FORTRAN is a non-typed language. C is a  
weakly typed language. Ada is a strongly typed language. C++ is a  
strongly hyped language."
-- Ron Sercely


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] caml_alloc + 64 bits - caml_alloc.h
  2009-01-13  4:58 ` [Caml-list] " Erik de Castro Lopo
@ 2009-01-13  5:15   ` Daniel de Rauglaudre
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel de Rauglaudre @ 2009-01-13  5:15 UTC (permalink / raw)
  To: caml-list

On Tue, Jan 13, 2009 at 03:58:10PM +1100, Erik de Castro Lopo wrote:

> If you are using GCC, GCC can warn you if you use the 
> -Wmissing-prototypes warning flag.

Hmm... does not work.
The correct option seems to be -Wimplicit-function-declaration

-- 
Daniel de Rauglaudre
http://pauillac.inria.fr/~ddr/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] caml_alloc + 64 bits - caml_alloc.h
  2009-01-13  4:51 caml_alloc + 64 bits - caml_alloc.h Daniel de Rauglaudre
  2009-01-13  4:58 ` [Caml-list] " Erik de Castro Lopo
@ 2009-01-13  9:37 ` malc
  2009-01-13 10:26   ` Olivier Andrieu
  1 sibling, 1 reply; 5+ messages in thread
From: malc @ 2009-01-13  9:37 UTC (permalink / raw)
  To: Daniel de Rauglaudre; +Cc: caml-list

On Tue, 13 Jan 2009, Daniel de Rauglaudre wrote:

> Hi everybody,
>
> Possibly useful information. Is it already known?
>
> When using calls to "caml_alloc" in a 64 bits architecture without
> having included "caml/alloc.h", it raises "Segmentation fault" at
> execution time.
>
> Notice that I got no warning at compilation time for using caml_alloc
> without a definition stub.
>
> In 32 bits architecture, I never had any problem with that.

caml_alloc returns value which is typedefed to intnat which in turn
is long which is 64bit on LP64 architectures (for all practical
intents and purposes anything that is not Win64), when prototype
for caml_alloc is missing it is assumed to be `int caml_alloc();'
assigning the return value of this call to value will sign extend
it with devastating results (upper 32bit lost forever)

> Morality:
>   Don't forget to #include "caml/alloc.h" in your C programs
>   if you alloc OCaml things!

Moraility is to follow relevant standard actually..

P.S. This whole value->intnat->long makes me wonder how OCaml is
      ever supposed to work on LLP64...

-- 
mailto:av1474@comtv.ru


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] caml_alloc + 64 bits - caml_alloc.h
  2009-01-13  9:37 ` malc
@ 2009-01-13 10:26   ` Olivier Andrieu
  0 siblings, 0 replies; 5+ messages in thread
From: Olivier Andrieu @ 2009-01-13 10:26 UTC (permalink / raw)
  To: malc; +Cc: caml-list

On Tue, Jan 13, 2009 at 10:37, malc <av1474@comtv.ru> wrote:

> P.S. This whole value->intnat->long makes me wonder how OCaml is
>     ever supposed to work on LLP64...

It does already, since 3.10. From byterun/config.h :

  /* Win64 model: IL32LLP64 */
  typedef ARCH_INT64_TYPE intnat;

where ARC_INT64_TYPE is either long long or __in64 depending on the
compiler (GCC or MSVC).

-- 
  Olivier


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-01-13 10:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-13  4:51 caml_alloc + 64 bits - caml_alloc.h Daniel de Rauglaudre
2009-01-13  4:58 ` [Caml-list] " Erik de Castro Lopo
2009-01-13  5:15   ` Daniel de Rauglaudre
2009-01-13  9:37 ` malc
2009-01-13 10:26   ` Olivier Andrieu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).