POC: Add initializer, internal_type, custom context #32
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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:
It is done in this proof of concept by adding attributes to typedef (for example for the C type
ty):initialize(ident): The functionvoid ident(ty *);is used to initialize out parameters of this typeinternal_type(sizeof(ty2),get,set): the internal type used in the custom block or abstract tag can be different fromty. The functiongetandsetconvert betweenty2andty. It allows to be able to store additional data (like a context) or just increase reference count inset.context((ctx_ty) ctx_name): indicates that initialization, c2ml, checkerror and previous set function gain an additional argument of typectx_ty. Functions that have an out parameter of this typedef, must also have a parameter with attributecontext(ctx_name)(in place ofinattribute). 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 thety. 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?