Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Type of udata in kevent



On Sun, 11 Nov 2012 01:03:52 -0500
Thor Lancelot Simon <tls%panix.com@localhost> wrote:

> On Sat, Nov 10, 2012 at 10:40:19AM -0500, D'Arcy J.M. Cain wrote:
> > In /usr/include/sys/event.h we define udata in the kevent structure
> > as intptr_t.  FreeBSD defines it as a void *.  This is a problem
> > with portability.  The comment describes udata as "opaque user data
> > identifier" suggesting that FreeBSD is correct.  Does anyone know
> > why we call it a pointer to an int?
> 
> Because the API comes from OS X, and it is intptr_t in OS X.
> 
> Why FreeBSD chose to break compatibility, I don't know.
> 
> Thor

Well FreeBSD were the first to design and implement kqueue. Maybe
originally udata was defined as intptr_t and later FreeBSD changed it
to void * as it made more sense. There is probably no standard on what
kqueue API should be, and OS X are not the authority, since they copied
it from FreeBSD.

Anyway intptr_t type is not "a pointer to int", but a signed data type
which is at least as big as a void *. This means you can store void *
in intptr_t safely AND you can do signed integer comparison on this
type. So depending on computer architecture, intptr_t will be defined
as int, or long.

Aside from incompatible APIs, I think kqueue design is flawed, i.e. for
read/write events on files, it can return the same file descriptor,
which makes tracking those descriptors a bit of a chore.


Home | Main Index | Thread Index | Old Index