caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] How safe is caml_get_public_method() to check if an object has a method?
Date: Mon, 7 Mar 2016 09:52:38 +0100	[thread overview]
Message-ID: <20160307085238.GA4659@frosties> (raw)
In-Reply-To: <2D39E7D1-1E36-4481-9195-168184047A51@math.nagoya-u.ac.jp>

On Mon, Mar 07, 2016 at 02:05:48PM +0900, Jacques Garrigue wrote:
> On 2016/03/07 11:43, Goswin von Brederlow wrote:
> > 
> > Hi,
> > 
> > /usr/include/caml/mlvalues.h says:
> > 
> > CAMLextern value caml_get_public_method (value obj, value tag);
> > /* Called as:
> >   caml_callback(caml_get_public_method(obj, caml_hash_variant(name)), obj) */
> > /* caml_get_public_method returns 0 if tag not in the table.
> >   Note however that tags being hashed, same tag does not necessarily mean
> >   same method name. */
> > 
> > In QT5 the classes have virtual methods that can be overloaded. I'm
> > considering allowing the ocaml classes to have methods by the same
> > name. The C glue would then check if the ocaml class has such a method
> > and call it. Otherwise the original method from QT5 would be called.
> > 
> > The question now is wether that is save to do? Is it save as long as
> > the names produce unique hash_variant values? Or are the hash tables
> > in objects only parts of the bits of the hash_variant and therefore
> > collide far more often (given a non-existant method name)?
> 
> 
> The function used is exactly hash_variant, so if it gives different results on all
> your method names, this is safe.
> For debugging purposes, I'm also considering adding the method names
> as string to the vritual method table. It could help, but you can already extract
> all the ocaml method names from your program, and check that there is
> no discrepancy. (The probability of having a conflict is very low.)
> 
> Jacques

That is good to know. Thx.

MfG
	Goswin

      reply	other threads:[~2016-03-07  8:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-07  2:43 Goswin von Brederlow
2016-03-07  5:05 ` Jacques Garrigue
2016-03-07  8:52   ` Goswin von Brederlow [this message]

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=20160307085238.GA4659@frosties \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    /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).