caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Obj.dup crash ?
@ 2004-12-29 13:38 Nicolas Cannasse
  2004-12-29 15:49 ` [Caml-list] " Alain Frisch
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Cannasse @ 2004-12-29 13:38 UTC (permalink / raw)
  To: caml-list

Hi list,

I don't understand why the following is making ocaml 3.08.0 win32msvc crash
:

let test() =
    let a = Obj.new_block 0 0 in
    let b = Obj.dup a in
    Gc.major()
;;

Any insights ?

Nicolas Cannasse


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

* Re: [Caml-list] Obj.dup crash ?
  2004-12-29 13:38 Obj.dup crash ? Nicolas Cannasse
@ 2004-12-29 15:49 ` Alain Frisch
  2004-12-29 16:49   ` Nicolas Cannasse
  0 siblings, 1 reply; 5+ messages in thread
From: Alain Frisch @ 2004-12-29 15:49 UTC (permalink / raw)
  To: Nicolas Cannasse, caml users

Nicolas Cannasse wrote:
> let test() =
>     let a = Obj.new_block 0 0 in
>     let b = Obj.dup a in
>     Gc.major()
> ;;

Because the function caml_obj_dup returns directly the argument
when it has size 0. I guess it should use CAMLreturn and not return, 
because it defines local variables with CAMLlocal.

-- Alain


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

* Re: [Caml-list] Obj.dup crash ?
  2004-12-29 15:49 ` [Caml-list] " Alain Frisch
@ 2004-12-29 16:49   ` Nicolas Cannasse
       [not found]     ` <41D358E2.4000604@inria.fr>
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Cannasse @ 2004-12-29 16:49 UTC (permalink / raw)
  To: Alain Frisch, caml users

> Nicolas Cannasse wrote:
> > let test() =
> >     let a = Obj.new_block 0 0 in
> >     let b = Obj.dup a in
> >     Gc.major()
> > ;;
>
> Because the function caml_obj_dup returns directly the argument
> when it has size 0. I guess it should use CAMLreturn and not return,
> because it defines local variables with CAMLlocal.
>
> -- Alain

Exact.
Could this be fixed in next release ?
I don't understand why it returns the argument since even with 0 fields the
tag is mutable using Obj.set_tag.

Regards,
Nicolas


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

* Re: [Caml-list] Obj.dup crash ?
       [not found]     ` <41D358E2.4000604@inria.fr>
@ 2004-12-30 11:04       ` Nicolas Cannasse
  2004-12-30 21:48         ` skaller
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Cannasse @ 2004-12-30 11:04 UTC (permalink / raw)
  To: Alain Frisch, caml-list

> Concerning Obj.dup, I guess it is never actually called when the block
> has 0 fields. Actually, where is Obj.dup used except in
> CamlinternalOO.copy ?  Quick look. It is used in the code generator:
> for array constants of size > 4, and for record expressions { ... with
> ... } that copy the original record and then modify it (but the empty
> record is not a valid type !). So indeed, it seems that Obj.dup is never
> called for 0 fields blocks. The implementation has dead code, but
> it is not buggy ;-)

It's also used in ExtLib DynArray when copying an array ;)
I understand that Obj is an undocumented/unspecified module but it should at
least work as expected.
Is there a particular reason for 0 fields blocks not being allocated ?
Actually Obj.tag (Obj.new_block 0 0) returns 500 which is not really the
expected result.

> but the empty record is not a valid type

It can't be parsed using default caml syntax but it surely can be
represented into the AST since I expect it to be a "something list". Now I'm
not sure such a type would pass the type checker or even how you're supposed
to instanciate it :)

Having 0 fields blocks might be useful for high level language features that
want to use OCaml as their runtime system, because of its very good native
compilation.

Nicolas Cannasse


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

* Re: [Caml-list] Obj.dup crash ?
  2004-12-30 11:04       ` Nicolas Cannasse
@ 2004-12-30 21:48         ` skaller
  0 siblings, 0 replies; 5+ messages in thread
From: skaller @ 2004-12-30 21:48 UTC (permalink / raw)
  To: Nicolas Cannasse; +Cc: Alain Frisch, caml-list

On Thu, 2004-12-30 at 22:04, Nicolas Cannasse wrote:
> > Concerning Obj.dup, I guess it is never actually called when the block
> > has 0 fields. Actually, where is Obj.dup used except in
> > CamlinternalOO.copy ?  Quick look. It is used in the code generator:
> > for array constants of size > 4, and for record expressions { ... with
> > ... } that copy the original record and then modify it (but the empty
> > record is not a valid type !). So indeed, it seems that Obj.dup is never
> > called for 0 fields blocks. The implementation has dead code, but
> > it is not buggy ;-)
> 
> It's also used in ExtLib DynArray when copying an array ;)

Obj.dup (Obj.magic (Array.make 0 0)); Gc.major();;
Warning S: this expression should have type unit.
Segmentation fault

What's the representation of a 0 length Array?

The weird message is due to CVS ocaml 3.09+dev12.
Array.copy doesn't exhibit this fault.


-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net




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

end of thread, other threads:[~2004-12-30 21:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-29 13:38 Obj.dup crash ? Nicolas Cannasse
2004-12-29 15:49 ` [Caml-list] " Alain Frisch
2004-12-29 16:49   ` Nicolas Cannasse
     [not found]     ` <41D358E2.4000604@inria.fr>
2004-12-30 11:04       ` Nicolas Cannasse
2004-12-30 21:48         ` skaller

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).