[AD] [ alleg-Bugs-2333410 ] think of a way to allocate user event type numbers.

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Bugs item #2333410, was opened at 2008-11-23 16:40
Message generated for change (Comment added) made by mmimica
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105665&aid=2333410&group_id=5665

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core Library
Group: 4.9
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Milan Mimica (mmimica)
Assigned to: Nobody/Anonymous (nobody)
Summary: think of a way to allocate user event type numbers.

Initial Comment:
Find a clever way to allocate a unique number for a user event type. Currently users freely choose the numbers which can easily lead to collisions between libs (and parts of allegro itself).

----------------------------------------------------------------------

Comment By: Milan Mimica (mmimica)
Date: 2008-11-27 08:44

Message:
That way you can't use event->type in switch (...) case statement which
seems to be the common practice to sort out events. But it is probably the
easiest and the safest thing to do.

The alternative is doing something at preprocessor level, like AL_ID:
#define MY_EVENT_TYPE     AL_ID('M','E','V','T')
but that can too easily collide as well. Maybe something with long long
and 8 chars and a documented naming scheme? Actually, if we reduce it to
7-bit chars we can fit one more. Or even more if we reduce it to caps only.
But it's still asking for trouble.

This would cause compile or link errors in case of duplicate ID, if I'm
not mistaken:
#define AL_declare_EVENT_ID(a, b, c, d) (((a)<<24) | ((b)<<16) | ((c)<<8)
| (d)) ; int _al_event_check_a##b##c##d;
... just giving some ideas.


----------------------------------------------------------------------

Comment By: Evert Glebbeek (eglebbk)
Date: 2008-11-27 02:52

Message:
How about:

static int allocated_user_events = 100;

int al_get_free_user_event_id(void) // Needs a better name
{
   return allocated_user_events++;
}

That way events 0-99 are "reserved" (although we can of course always
increase this if we need to).
I think this is the easiest and most straightforward way to do it. The
only thing to watch out for is multiple threads requesting event IDs at the
same time, although I suspect this wouldn't be a major problem in practice
if we leave it be. For good measure it should probably have a mutex lock in
there though.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105665&aid=2333410&group_id=5665




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/