caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xavier.leroy@inria.fr>
To: "Yaron M. Minsky" <yminsky@CS.Cornell.EDU>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Bp_val and Data_custom_val
Date: Fri, 20 Sep 2002 11:56:57 +0200	[thread overview]
Message-ID: <20020920115657.A15003@pauillac.inria.fr> (raw)
In-Reply-To: <3D88DA09.4010906@cs.cornell.edu>; from yminsky@CS.Cornell.EDU on Wed, Sep 18, 2002 at 03:54:49PM -0400

> I'm wondering if someone can help me out in understanding the difference 
> between Bp_val and Data_custom_val.

Caml heap blocks are composed of a GC header and a number of words of data.
Bp_val points to the first word of data:

        header  data0  data1  data2  ...
                ^
                |
             Bp_val

For finalized and custom blocks, the first word of "data" holds a
pointer to a record of functions (finalization functions, comparison
functions, etc), and Data_custom_val points to the second word of data,
i.e. the beginning of the user data space:

        header  function  data1  data2  ...
                pointer
                          ^
                          |
                        Data_custom_val

> struct camldb {
>    DB *db;
>    int closed;
> };
> 
> struct camltxn {
>    DB_TXN *txn;
>    int closed;
> };
> 
> #define UW_db(v) (((struct camldb *)Bp_val(v))->db)
> #define UW_db_closed(v) (((struct camldb *)Bp_val(v))->closed)

This is incorrect, you should use Data_custom_val(v) instead of
Bp_val(v), otherwise the db field will overwrite the function pointer
at the beginning of the custom/finalized block.

- 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


      parent reply	other threads:[~2002-09-20  9:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-18 19:54 Yaron M. Minsky
     [not found] ` <3D891635.4030002@htec.demon.co.uk>
2002-09-19  1:41   ` Yaron M. Minsky
2002-09-19  2:32     ` Berkeley DB wrapper is fixed (was: Re: [Caml-list] Bp_val and Data_custom_val) Yaron M. Minsky
2002-09-20  9:56 ` Xavier Leroy [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=20020920115657.A15003@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=yminsky@CS.Cornell.EDU \
    /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).