[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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 ...
^
|
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