Skip to content

Commit 250e4b3

Browse files
re-define "pragma pack()" on a per-struct base (fabiangreffrath#20)
* re-define "pragma pack()" on a per-struct base Fixes fabiangreffrath#20 let's see what this breaks first * pack structs in dosbox/dbopl.h * game runs, config loads, savegames load
1 parent 78cc9d6 commit 250e4b3

File tree

7 files changed

+46
-25
lines changed

7 files changed

+46
-25
lines changed

‎dosbox/dbopl.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
//#include "dosbox.h"
4949
#include "dbopl.h"
5050

51+
5152
#ifndef PI
5253
#define PI 3.14159265358979323846
5354
#endif

‎dosbox/dbopl.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ enum {
8282
SHIFT_KEYCODE = 24,
8383
};
8484

85-
struct Operator {
85+
PACKED_STRUCT( Operator {
8686
public:
8787
//Masks for operator 20 values
8888
enum {
@@ -171,9 +171,9 @@ struct Operator {
171171
Bits GetWave( Bitu index, Bitu vol );
172172
public:
173173
Operator();
174-
};
174+
});
175175

176-
struct Channel {
176+
PACKED_STRUCT( Channel {
177177
Operator op[2];
178178
inline Operator* Op( Bitu index ) {
179179
return &( ( this + (index >> 1) )->op[ index & 1 ]);
@@ -207,9 +207,9 @@ struct Channel {
207207
template<SynthMode mode>
208208
Channel* BlockTemplate( Chip* chip, Bit32u samples, Bit32s* output );
209209
Channel();
210-
};
210+
});
211211

212-
struct Chip {
212+
PACKED_STRUCT( Chip {
213213
//This is used as the base counter for vibrato and tremolo
214214
Bit32u lfoCounter;
215215
Bit32u lfoAdd;
@@ -261,7 +261,7 @@ struct Chip {
261261
void Setup( Bit32u r );
262262

263263
Chip();
264-
};
264+
});
265265

266266
/*struct Handler : public Adlib::Handler {
267267
DBOPL::Chip chip;

‎id_ca.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ loaded into the data segment
3636
=============================================================================
3737
*/
3838

39-
typedef struct
39+
typedef PACKED_STRUCT(
4040
{
4141
word bit0,bit1; // 0-255 is a character, > is a pointer to a node
42-
} huffnode;
42+
}) huffnode;
4343

4444

45-
typedef struct
45+
typedef PACKED_STRUCT(
4646
{
4747
word RLEWtag;
4848
int32_t headeroffsets[100];
49-
} mapfiletype;
49+
}) mapfiletype;
5050

5151

5252
/*

‎id_ca.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
//===========================================================================
1717

18-
typedef struct
18+
typedef PACKED_STRUCT(
1919
{
2020
int32_t planestart[3];
2121
word planelength[3];
2222
word width,height;
2323
char name[16];
24-
} maptype;
24+
}) maptype;
2525

2626
//===========================================================================
2727

‎id_us.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
#define MaxHighName 57
2323
#define MaxScores 7
24-
typedef struct
24+
typedef PACKED_STRUCT(
2525
{
2626
char name[MaxHighName + 1];
2727
int32_t score;
2828
word completed,episode;
29-
} HighScore;
29+
}) HighScore;
3030

3131
#define MaxGameName 32
3232
#define MaxSaveGames 6

‎wl_def.h‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,27 @@
2525
# define O_BINARY 0
2626
#endif
2727

28-
#pragma pack(1)
28+
#ifdef __WATCOMC__
29+
#define PACKEDPREFIX _Packed
30+
#elif defined(_MSC_VER)
31+
#define PACKEDPREFIX __pragma(pack(push,1))
32+
#else
33+
#define PACKEDPREFIX
34+
#endif
35+
36+
#ifdef __GNUC__
37+
#if defined(_WIN32) && !defined(__clang__)
38+
#define PACKEDSUFFIX __attribute__((packed,gcc_struct))
39+
#else
40+
#define PACKEDSUFFIX __attribute__((packed))
41+
#endif
42+
#elif defined(_MSC_VER)
43+
#define PACKEDSUFFIX __pragma(pack(pop))
44+
#else
45+
#define PACKEDSUFFIX
46+
#endif
47+
48+
#define PACKED_STRUCT(...) PACKEDPREFIX struct __VA_ARGS__ PACKEDSUFFIX
2949

3050
#if defined(_arch_dreamcast)
3151
#define YESBUTTONNAME "A"
@@ -741,14 +761,14 @@ extern statetype states[numstates]; // [FG] statetype states[] array
741761
//
742762
//---------------------
743763

744-
typedef struct statstruct
764+
typedef PACKED_STRUCT( statstruct
745765
{
746766
byte tilex,tiley;
747767
short shapenum; // if shapenum == -1 the obj has been removed
748768
byte *visspot;
749769
uint32_t flags;
750770
byte itemnumber;
751-
} statobj_t;
771+
}) statobj_t;
752772

753773

754774
//---------------------
@@ -762,14 +782,14 @@ typedef enum
762782
dr_open,dr_closed,dr_opening,dr_closing
763783
} doortype;
764784

765-
typedef struct doorstruct
785+
typedef PACKED_STRUCT( doorstruct
766786
{
767787
byte tilex,tiley;
768788
boolean vertical;
769789
byte lock;
770790
doortype action;
771791
short ticcount;
772-
} doorobj_t;
792+
}) doorobj_t;
773793

774794

775795
//--------------------
@@ -778,7 +798,7 @@ typedef struct doorstruct
778798
//
779799
//--------------------
780800

781-
typedef struct objstruct
801+
typedef PACKED_STRUCT( objstruct
782802
{
783803
activetype active;
784804
short ticcount;
@@ -804,7 +824,7 @@ typedef struct objstruct
804824

805825
short temp1,temp2,hidden;
806826
struct objstruct *next,*prev;
807-
} objtype;
827+
}) objtype;
808828

809829
enum
810830
{
@@ -855,7 +875,7 @@ enum
855875
//
856876
//---------------
857877

858-
typedef struct
878+
typedef PACKED_STRUCT(
859879
{
860880
short difficulty;
861881
short mapon;
@@ -874,7 +894,7 @@ typedef struct
874894
int32_t TimeCount;
875895
int32_t killx,killy;
876896
boolean victoryflag; // set during victory animations
877-
} gametype;
897+
}) gametype;
878898

879899

880900
typedef enum

‎wl_menu.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ enum menuitems
229229
//
230230
// WL_INTER
231231
//
232-
typedef struct {
232+
typedef PACKED_STRUCT( {
233233
int kill,secret,treasure;
234234
int32_t time;
235-
} LRstruct;
235+
}) LRstruct;
236236

237237
extern LRstruct LevelRatios[];
238238

0 commit comments

Comments
 (0)