Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report (was Re: [Caml-list] Bp_val and Data_custom_val) #3753

Closed
vicuna opened this issue Sep 20, 2002 · 1 comment
Closed

Bug report (was Re: [Caml-list] Bp_val and Data_custom_val) #3753

vicuna opened this issue Sep 20, 2002 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Sep 20, 2002

Original bug ID: 1399
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Ok, so I think that I now have a bug report. In the file
otherlibs/db/dbstubs.c in the distribution, the following definitions
can be found:

#define Camldb_db(v) (((struct camldb *)(Bp_val(v)))->db)
#define Camldb_info(v) (((struct camldb *)(Bp_val(v)))->info)
#define Camldb_closed(v) (((struct camldb *)(Bp_val(v)))->closed)

These are allocated as finalized blocks, but my understanding is that
finalized blocks and custom blocks now have the same format, so this
code looks wrong. I don't think this code is actually compiled into the
distribution, but it seems like it should either be removed, fixed, or
at least marked as buggy somehow so someone doesn't try to use it as a
model for new code, as I did.

Thanks,
y

On Fri, 2002-09-20 at 05:56, Xavier Leroy wrote:

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.

Open PGP --- KeyID B1FFD916 (new key as of Dec 4th)
Fingerprint: 5BF6 83E1 0CE3 1043 95D8 F8D5 9F12 B3A9 B1FF D916

@vicuna
Copy link
Author

vicuna commented Jan 3, 2003

Comment author: administrator

otherlibs/db is obsolete and removed from the distribution
2003-01-03 DD and XL

@vicuna vicuna closed this as completed Jan 3, 2003
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant