Re: Annotation for file descriptors



2014-07-03 12:03 GMT+02:00 Philip Withnall <philip tecnocode co uk>:
Hey,

I am thinking about doing static analysis of file descriptor operations
in Tartan[1], and for that I need a way to identify file descriptors in
function parameters and return values (and properties and signal
parameters too).

I can think of two options for this:

1. An (fd) annotation which marks an integer as a file descriptor.

2. A new type, GFileDescriptor, defined as
    typedef int GFileDescriptor
   and applied to all the relevant APIs with a (type) annotation.

Both options could be used with (transfer) to indicate ownership
transfer of the FD.

Unlike memory, FD transfer is often dynamic: GUnixInput/OutputStream
(which are the most common way to interact with a FD in a introspected
language) accept a close_fd property, so they either eat or not eat
their FD.

I think I’m favouring option 2 because file descriptors aren’t really
integers in any of the normal senses — you can’t really do arithmetic on
them, and any comparison between them (except equality) is useless. So
as far as introspection is concerned, they shouldn’t be integers.

But existing bindings assumes they are integers, so while a special
type is useful at the g-i level, in pratice they would keep being
exposed as integers in the languages (like we do for enums).

I’d appreciate other people’s thoughts on this. I suspect that a feature
like this could be used in bindings to automatically close open FDs when
they go out of scope. Is that done already somehow?

In languages with a GC, this would be tied to a GC cycle, and by the
time that runs, the FD limit probably has been reached already. FDs
need to be closed explicitly (not to mention error handling that
should happen around closing, and the fact that closing blocks)

Giovanni


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