[AD] Internals (2)

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


I'm back with internals... and a complete proposal.

For each port, we provide 3 main header files:
- allegro.h: main header file, containing only API calls and variables,
entry points for inline functions (system_driver, ...) and related data type
definitions,

- allegint.h: header file for platform-independent internals, containing 2
calls (allegro_internals_init() and allegro_internals_exit()), 1 variable
(allegro_internals) and related data type definitions,

- *alleg.h (winalleg.h, ...): header file for platform-dependent stuff.


/* in allegint.h */
#ifdef STATICLINK
#define AL_INTERNAL(symbol)  symbol
#else
#define AL_INTERNAL(symbol)  (*allegro_internals->##symbol)
#endif

struct ALLEGRO_INTERNALS {
   int *_textmode;
   int *_sound_hq;
   ....
};

AL_VAR(struct ALLEGRO_INTERNALS *, allegro_internals);
AL_FUNC(int, allegro_internals_init, (void));
AL_FUNC(void, allegro_internals_exit, (void));


/* in src/allegint.c */
struct ALLEGRO_INTERNALS *allegro_internals = NULL;

int allegro_internals_init(void)
{
#ifndef STATICLINK
   allegro_internals = malloc(sizeof(struct ALLEGRO_INTERNALS));

   allegro_internals->_textmode = &_textmode;
   allegro_internals->_sound_hq = &_sound_hq;
   ...
#
   _add_exit_function(allegro_internals_exit);
   return 0;
}

void allegro_internals_exit(void)
{
#ifndef STATICLINK
   if (allegro_internals) {
      free(allegro_internals);
      allegro_internals = NULL;
   }
#endif
}


The amount of necessary changes in add-ons is minimal: calling
allegro_internals_init() right after allegro_init() and using the access
macro AL_INTERNAL().

Peter, you were talking about alignment issues in a previous message on this
topic, what did you mean exactly by that ?

--
Eric Botcazou
ebotcazou@xxxxxxxxxx



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