* [Caml-list] Bp_val and Data_custom_val @ 2002-09-18 19:54 Yaron M. Minsky [not found] ` <3D891635.4030002@htec.demon.co.uk> 2002-09-20 9:56 ` [Caml-list] Bp_val and Data_custom_val Xavier Leroy 0 siblings, 2 replies; 4+ messages in thread From: Yaron M. Minsky @ 2002-09-18 19:54 UTC (permalink / raw) To: caml-list I'm wondering if someone can help me out in understanding the difference between Bp_val and Data_custom_val. These are both macros for accessing caml values from C. I lifted and adapted some code from the distribution for building a berkeley DB interface. In that code, Bp_val is used to access the contents of finalized blocks. I adapted that code but shifted to custom blocks, which according to the docs have the same layout. The docs also suggest using Data_custom_val for custom blocks. But when I try to do that, I end up with segfaults. I'm wondering what precisely the difference is. Here's a snippet of my data type definitions and the macros I use for accessing the data contained in the custom blocks holding that data: 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) #define UW_txn(v) (((struct camltxn *)Bp_val(v))->txn) #define UW_txn_closed(v) (((struct camltxn *)Bp_val(v))->closed) Anything fishy about that? And any problem with replacing Bp_val with Data_custom_val here? By the way, in a separate post, I put a URL for where you can download the entire wrapper in question. Here it is again: http://minsky-primus.homeip.net/ocaml/bdb.tar.gz y ------------------- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <3D891635.4030002@htec.demon.co.uk>]
* Re: [Caml-list] Bp_val and Data_custom_val [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 0 siblings, 1 reply; 4+ messages in thread From: Yaron M. Minsky @ 2002-09-19 1:41 UTC (permalink / raw) To: caml-list Interesting. So I guess that my code has been overwriting the pointer to the custom operations block. I wonder, though, what the significance of the following paragraph from the documentation is, and in particular what is meant by "the format of custom blocks is compatible with that of finalized blocks". Custom blocks generalize the finalized blocks that were present in Objective Caml prior to version 3.00. For backward compatibility, the format of custom blocks is compatible with that of finalized blocks, and ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the alloc_final function is still available to allocate a custom block with a given finalization function, but default comparison, hashing and serialization functions. alloc_final(n, f, used, max) returns a fresh custom block of size n words, with finalization function f. The first word is reserved for storing the custom operations; the other n-1 words are available for your data. The two parameters used and max are used to control the speed of garbage collection, as described for alloc_custom. Christopher Quinn wrote: > hi, > > Bp_val() returns a pointer to the first word(byte really since Bp == > byte pointer) after the header, while Data_val_custom() returns the > address of the second word (value), which is because with finalisation > the first word is occupied by a pointer to the specific finalisation > struct of handlers (finalise, serialise, de-serialise et al). > > so it is not the same layout! > > - chris > > Yaron M. Minsky wrote: > >> I'm wondering if someone can help me out in understanding the >> difference between Bp_val and Data_custom_val. These are both macros >> for accessing caml values from C. I lifted and adapted some code from >> the distribution for building a berkeley DB interface. In that code, >> Bp_val is used to access the contents of finalized blocks. I adapted >> that code but shifted to custom blocks, which according to the docs >> have the same layout. The docs also suggest using Data_custom_val for >> custom blocks. But when I try to do that, I end up with segfaults. >> I'm wondering what precisely the difference is. Here's a snippet of >> my data type definitions and the macros I use for accessing the data >> contained in the custom blocks holding that data: >> >> >> 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) >> >> #define UW_txn(v) (((struct camltxn *)Bp_val(v))->txn) >> #define UW_txn_closed(v) (((struct camltxn *)Bp_val(v))->closed) >> >> Anything fishy about that? And any problem with replacing Bp_val with >> Data_custom_val here? >> >> By the way, in a separate post, I put a URL for where you can download >> the entire wrapper in question. Here it is again: >> >> http://minsky-primus.homeip.net/ocaml/bdb.tar.gz >> >> y >> >> >> ------------------- >> 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 >> > > ------------------- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Berkeley DB wrapper is fixed (was: Re: [Caml-list] Bp_val and Data_custom_val) 2002-09-19 1:41 ` Yaron M. Minsky @ 2002-09-19 2:32 ` Yaron M. Minsky 0 siblings, 0 replies; 4+ messages in thread From: Yaron M. Minsky @ 2002-09-19 2:32 UTC (permalink / raw) To: caml-list Now that I realize that custom blocks and finalized blocks don't actually have the same format, I was able to resolve the problems with my berkeley DB wrapper. If anyone is interested, the new version is now available here. The fixed version is now available in the same place as before: http://minsky-primus.homeip.net/ocaml/bdb.tar.gz Still no promises that it's bugless, but it seems to work for me. y Yaron M. Minsky wrote: > Interesting. So I guess that my code has been overwriting the pointer > to the custom operations block. > > I wonder, though, what the significance of the following paragraph from > the documentation is, and in particular what is meant by "the format of > custom blocks is compatible with that of finalized blocks". > > Custom blocks generalize the finalized blocks that were present in > Objective Caml prior to version 3.00. For backward compatibility, the > format of custom blocks is compatible with that of finalized blocks, and > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > the alloc_final function is still available to allocate a custom block > with a given finalization function, but default comparison, hashing and > serialization functions. alloc_final(n, f, used, max) returns a fresh > custom block of size n words, with finalization function f. The first > word is reserved for storing the custom operations; the other n-1 words > are available for your data. The two parameters used and max are used to > control the speed of garbage collection, as described for alloc_custom. > > Christopher Quinn wrote: > > hi, > > > > Bp_val() returns a pointer to the first word(byte really since Bp == > > byte pointer) after the header, while Data_val_custom() returns the > > address of the second word (value), which is because with finalisation > > the first word is occupied by a pointer to the specific finalisation > > struct of handlers (finalise, serialise, de-serialise et al). > > > > so it is not the same layout! > > > > - chris > > > > Yaron M. Minsky wrote: > > > >> I'm wondering if someone can help me out in understanding the > >> difference between Bp_val and Data_custom_val. These are both macros > >> for accessing caml values from C. I lifted and adapted some code from > >> the distribution for building a berkeley DB interface. In that code, > >> Bp_val is used to access the contents of finalized blocks. I adapted > >> that code but shifted to custom blocks, which according to the docs > >> have the same layout. The docs also suggest using Data_custom_val for > >> custom blocks. But when I try to do that, I end up with segfaults. > >> I'm wondering what precisely the difference is. Here's a snippet of > >> my data type definitions and the macros I use for accessing the data > >> contained in the custom blocks holding that data: > >> > >> > >> 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) > >> > >> #define UW_txn(v) (((struct camltxn *)Bp_val(v))->txn) > >> #define UW_txn_closed(v) (((struct camltxn *)Bp_val(v))->closed) > >> > >> Anything fishy about that? And any problem with replacing Bp_val with > >> Data_custom_val here? > >> > >> By the way, in a separate post, I put a URL for where you can download > >> the entire wrapper in question. Here it is again: > >> > >> http://minsky-primus.homeip.net/ocaml/bdb.tar.gz > >> > >> y > >> > >> > >> ------------------- > >> 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 > >> > > > > > > > ------------------- > 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 ------------------- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Bp_val and Data_custom_val 2002-09-18 19:54 [Caml-list] Bp_val and Data_custom_val Yaron M. Minsky [not found] ` <3D891635.4030002@htec.demon.co.uk> @ 2002-09-20 9:56 ` Xavier Leroy 1 sibling, 0 replies; 4+ messages in thread From: Xavier Leroy @ 2002-09-20 9:56 UTC (permalink / raw) To: Yaron M. Minsky; +Cc: caml-list > 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-09-20 9:57 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-09-18 19:54 [Caml-list] Bp_val and Data_custom_val 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 ` [Caml-list] Bp_val and Data_custom_val Xavier Leroy
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).