Re: [Vala] Vala volatile (C memory model & freedom to define types)



On Wed, 2011-04-20 at 21:51 +0200, Maciej Marcin Piechotka wrote:
Hello.

For some libgee work I need to have working volatile. The problem is
that this support needs a bit care (in short - it does not work on any
profile but it breaks in different places - see bug #622338 [1] for
breakage on lexer in non-dova profile and bug #648330 [2] for silently
not working in dova profile)

I guess that the problem is that from POV of vala there is no
possibility of annotating pointers. I.e. the modifications of types
applies to types only and not to pointers (for ex. const pointers are
not supported).

However the problem with most usage of volatile is that it *requires*
low-level access:

 - int volatile * specifies a pointer to volatile area (i.e. one that is
beyond control of processor). It can be specified as volatile int * as
well.
 - int * volatile specifies a pointer that is beyond control of
processor

Those are two distinct cases. Arguably the second one is more common in
mid-HL languages (the first one is need for the original use of volatile
i.e. the memory-mapped I/O).

I can produce patches for it but:

 - How should the volatile pointer be specified in syntax?
 - How should the pointer to volatile memory be specified? Is it needed
at all?
 - Do we want to keep compatibility with C bracketing?
 - What about brother of volatile (const)?

Solutions:

 - volatile brackets like in C. I.e. volatile int * is (volatile int) *
not volatile (int *)
 - volatile brackets like in C but can be only on RHS of the bracketing
int volatile * is (int volatile) * while int * volatile is (int *)
volatile
 - volatile only corresponds to memory it specifies. I.e. volatile int *
is volatile (int *). This is implemented by patches to bug 648330 [2]

Regards

[1] https://bugzilla.gnome.org/show_bug.cgi?id=622338
[2] https://bugzilla.gnome.org/show_bug.cgi?id=648330

I took the liberty of producing patch anyway and attaching it to bug as
well as to this e-mail.

The main difference is it makes it property of type (as is weak or
unowned). It also allows to have much more complicated types as volatile
pointer to volatile memory.

 - volatile on LHS keeps compatibility with C. I.e. int volatile * is
pointer to volatile int while int * volatile is volatile pointer to int.
 - volatile on RHS is not parsed as in C. it refers to field as whole.
So volatile void * is the same as void * volatile not void volatile *

Regards

PS. Happy <insert holidays you are celebrating>

Attachment: 0001-Implement-more-advanced-handling-of-volatile.patch
Description: Text Data

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]