Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Bp_val and Data_custom_val
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-09-20 (09:57)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Bp_val and Data_custom_val
> 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  ...

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

> 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 Archives:
Bug reports: FAQ:
Beginner's list: