Commit Graph

2 Commits

Author SHA1 Message Date
Neels Hofmeyr bd5869706d struct_endianess.py: also recognise unnamed substructs
Before this, the new dtap_header substruct construct would end up being split
up in a weird way:

	struct dtap_header {
		uint8_t type;
		union {
			uint8_t link_id;  /* Backward compatibility */
			struct {
				uint8_t dlci_cc:2,
				dlci_spare:3,
				dlci_sapi:3; /* enum gsm0406_dlc_sapi */
			};
		};
		uint8_t length;
	} __attribute__((packed));

would previously become

	struct dtap_header {
		uint8_t type;
		union {
			uint8_t link_id;  /* Backward compatibility */
			struct {
	#if OSMO_IS_LITTLE_ENDIAN
				uint8_t dlci_cc:2,
				dlci_spare:3,
				dlci_sapi:3; /* enum gsm0406_dlc_sapi */
			};
		};
		uint8_t length;
	#elif OSMO_IS_BIG_ENDIAN
	/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
				uint8_t dlci_sapi:3, dlci_spare:3, dlci_cc:2;
			};
		};
		uint8_t length;
	#endif
	} __attribute__((packed));

now becomes

	struct dtap_header {
		uint8_t type;
		union {
			uint8_t link_id;  /* Backward compatibility */
			struct {
	#if OSMO_IS_LITTLE_ENDIAN
				uint8_t dlci_cc:2,
				dlci_spare:3,
				dlci_sapi:3; /* enum gsm0406_dlc_sapi */
	#elif OSMO_IS_BIG_ENDIAN
	/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
				uint8_t dlci_sapi:3, dlci_spare:3, dlci_cc:2;
	#endif
			};
		};
		uint8_t length;
	} __attribute__((packed));

Change-Id: I3c4986ebd1e41aad8b279d6132b7e3b2539d7dc5
2020-05-15 16:13:54 +00:00
Neels Hofmeyr 7ab5fc1f3b add contrib/struct_endianess.py
In libosmocore (and likely elsewhere) we have scores of packed structs with
sub-byte integer members that lack the necessary member reversal shims to be
able to work on big endian architectures.

Instead of manually editing each one of them and probably introduce errors in
the process, this script handles the change automatically, and in the future
allows us to verify correctness in gerrit verifications.

Change-Id: I8e75b17d8071c7b3a2a171ba776fb76854b28a53
2018-11-22 13:49:24 +00:00