#42 [4.x]Make pack_fopen a weak symbol, add __allegro_pack_fopen


When porting AGS to Linux, I noticed they copied src/file.c from allegro in order to rename pack_fopen to old_pack_fopen and override it with a new pack_fopen that handles looking inside another file (and then falls back to calling old_pack_fopen).

Since this is a relatively dirty hack and doesn't work with static linking at all (and I can see valid reasons to do it), I'd propose to rename pack_fopen to allegro_pack_fopen and adding a pack_fopen that just calls allegro_pack_fopen, but is declared a weak symbol.

This way:
- "Normal" applications using allegro will keep working just fine
- AGS and others wanting to do the same thing can override pack_fopen without having to duplicate code
- Overridden pack_fopen functions can call the original (because it's available unconditionally through the __allegro_pack_fopen symbol)


  • Thomas Fjellstrom

    I don't see why AGS can't just make a wrapper for pack_fopen. Either directly or through a #define pack_fopen. That is, have a my_pack_fopen which gets called instead of pack_fopen, which then does what it wants, then tries pack_fopen.

  • Bernhard Rosenkraenzer

    Wrapping pack_fopen through #define doesn't do the trick because the override is needed for the uses of pack_open inside allegro as well (e.g. load_voc() in allegro/src/sound.c uses pack_fopen to load the sound files, and we can't #define that usage away, when in fact we need it to load the sound file from a container only the overloaded pack_fopen can handle).

    Also affects loading FLIs (allegro/src/fli.c), pictures (allegro/src/bmp.c, allegro/src/tga.c, allegro/src/pcx.c) and probably more.

  • Elias Pschernig

    Elias Pschernig - 2011-05-16

    Can't you use e.g. load_voc_pf instead and then simply pass a PACKFILE which reads from your container?


Log in to post a comment.