caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] RFH: can't figure out why my QT5 widget bindings segfault
Date: Thu, 24 Mar 2016 11:25:59 +0100	[thread overview]
Message-ID: <20160324102559.GB32689@frosties> (raw)
In-Reply-To: <56F2CFD4.4000401@cea.fr>

On Wed, Mar 23, 2016 at 06:18:12PM +0100, François Bobot wrote:
> On 23/03/2016 16:18, Anatoly Zaretsky wrote:
> >On Wed, Mar 23, 2016 at 12:50 PM, Goswin von Brederlow <goswin-v-b@web.de
> ><mailto:goswin-v-b@web.de>> wrote:
> >
> >    I'm stuck with a bug in the Tetrix example for my QT5 bindings:
> >
> >    https://github.com/mrvn/ocaml-qt5
> >
> >    The segfault happens when you click start and the first piece is moved
> >    one tile down in caml_mrvn_QT5_OPainter_fillRect. The arguments to the
> >    call all look ok but something must corrupt the painter. The segfault
> >    goes away when I force a Gc.full_major before creating a new OPainter
> >    in TetrixBoard:148.
> >
> >
> >Just a wild guess: there are a lot of raw c++ pointer casts to ocaml values in the code, and to
> >quote http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec424 "this can crash the garbage
> >collector" in some non-obvious circumstances.

I know about that and all c++ pointers are paired with an ocaml object
that holds them. The c++ object also holds a weak refrence to the
ocaml object. When the c++ object is destructed it removes the pointer
from the paired ocaml object before being freed. Therefore there can
never be a reachable danling pointer on the ocaml heap that could
potentially point the next ocaml heap. 

It also seems like the heap and c++ allocations are at opposite ends
of the address space, e.g. from the debug output:

  value caml_mrvn_Qt5_OClass_register_obj(OClass*, value)(0x113bbe8, 0x7f4cfac1cfa8)

The c++ object is at 0x113bbe8, the lower end of the heap and the
ocaml object at 0x7f4cfac1cfa8, the upper end of the heap.

> And in the future of no-naked pointer it will be forbidden. Perhaps it
> should be added to the ocaml documentation with the precise future rules
> [1].

That will break a lot of code and will be rather anyoing. I guess for
me it's time to overload operator new() to add a black colored ocaml
header before every allocation.

More generally what I often wish I had would be a block that holds
both ocaml values and at least one C pointer. Could we have a tag(s) for
blocks where the Gc skips the first field(s) and only scans the rest?

> The segfault is in C++ code, so I think it is not this problem. Moreover no
> asserts of the debug runtime are broken. On debian I don't know how to
> install qt5 in debug mode, so I'm not able to see in gdb which pointer is at
> fault.
> 
> NB: the INSTALL file forget to ask to install qt5 development file, even if it is obviously needed ;).
> 
> [1]: https://github.com/ocaml/ocaml/pull/297#issuecomment-159233967

Yeah, it's still at the proof-of-concept stage. The INSTALL is oasis
generated and I haven't even looked at what oasis puts in there. No
opam package yet either.

  reply	other threads:[~2016-03-24 10:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-23 10:50 Goswin von Brederlow
2016-03-23 15:18 ` Anatoly Zaretsky
2016-03-23 17:18   ` François Bobot
2016-03-24 10:25     ` Goswin von Brederlow [this message]
2016-03-25 11:28       ` Goswin von Brederlow
2016-03-29 22:29         ` SP
2016-03-31 10:21           ` Goswin von Brederlow
2016-03-31 11:00             ` Jonas Jensen
2016-04-02 11:38               ` Goswin von Brederlow
2016-04-06 22:56                 ` SP
2016-04-07  7:43                   ` Goswin von Brederlow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160324102559.GB32689@frosties \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).