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

Camlidl: what about finalizers for abstract types? #3026

Closed
vicuna opened this issue Nov 12, 2001 · 1 comment
Closed

Camlidl: what about finalizers for abstract types? #3026

vicuna opened this issue Nov 12, 2001 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Nov 12, 2001

Original bug ID: 627
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: -for CamlIDL use https://github.com/xavierleroy/camlidl/issues

Bug description

OK, I have realized how errorcheck(fn) attribute works for abstract
types. But now there is another crazy idea :-)

Suppose I have the following .IDL definition

typedef [abstract] void* TYPE;
TYPE create_object();
void process_object( TYPE t );
...
void delete_object( TYPE t );

create_object() allocates some memory and other resources that should be
freed when the object is no longer needed. This job is done by
delete_object(), which should be explicitly called. If not, we are in
trouble:

let obj = create_object () in
begin
process_object obj;
...
(* no delete_object -- object is not destructed properly! *)
end

What I propose:

Let's allow optional "fn" parameter to "abstract" attribute, that will
specify finalizer function:

typedef [abstract(delete_object)] void* TYPE;
TYPE create_object();
void process_object( TYPE t );
...

finaliser function should have type "void fn(TYPE)"

Having such attribute, camlidl allocates custom block with the appropriate
finalizer, that will be called when the block (i.e. object) is
garbage-collected. So abstract camlidl types will be safe as any OCaml
types.

What do you think of this?

Hope to hear from you soon,
Dmitry

@vicuna
Copy link
Author

vicuna commented Apr 22, 2002

Comment author: administrator

Implemented 2002-04-19 by XL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant