Skip to content

Conversation

@bobot
Copy link

@bobot bobot commented Oct 27, 2025

When looking at the binding of mlcuddidl (1,2) and the C library Calcium that I started to bind using ocaml_ctypes , I found that it would be advantageous to add to camlidl support for the following common patterns:

  • initialization: some out parameter need to be initialized by calling a library function before making the C call
  • context: libraries can require to pass a common datastructure to all functions, like finalization and initialization .
  • reference counting

It is done in this proof of concept by adding attributes to typedef (for example for the C type ty):

  • initialize(ident) : The function void ident(ty *); is used to initialize out parameters of this type
  • internal_type(sizeof(ty2),get,set): the internal type used in the custom block or abstract tag can be different from ty. The function get and set convert between ty2 and ty. It allows to be able to store additional data (like a context) or just increase reference count in set.
  • context((ctx_ty) ctx_name): indicates that initialization, c2ml, checkerror and previous set function gain an additional argument of type ctx_ty. Functions that have an out parameter of this typedef, must also have a parameter with attribute context(ctx_name) (in place of in attribute). This attribute can appear multiple times.

For initialization someone proposed a similar modification of camlidl.

In typedef.idl, a toy library shows how the features can be used.

There is an additional change, ty * is initialiazing the pointer but also the ty. The other modifications should be backward compatible. The new features are not extended to struct, union, enum that contains such typedef. It requires a bigger change to the tool which is too early for this POC. What is your opinion on these additions?

  In order to be usable sooner, e.g. in cvtval
 attribute `initialize`` indicates how an output
 parameter should be initialized
    stored type (custom value or absstract value) different from C type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant