Description: Avoid FTBFS on s390x This patch corrects field bit offsets in generated representation clauses when int=32 long=64 and endian=big, or at least on s390x. . A build log is available at https://buildd.debian.org/status/fetch.php?pkg=libncursesada&arch=s390x&ver=5.9.20110404-9&stamp=1390738352 . The asked size for the record is 32 while the fields ranges are 63, 62 and so on. The right values should be 32, 31 and so on. Form and field options have the same problem. Forwarded: yes Author: Nicolas Boulenguez --- a/gen/gen.c +++ b/gen/gen.c @@ -70,45 +70,41 @@ } name_attribute_pair; -static int -find_pos(char *s, unsigned len, int *low, int *high) -{ - unsigned int i, j; - int l = 0; - - *high = -1; - *low = (int)(8 * len); +static unsigned char +bit_is_set (const unsigned char * const data, + const unsigned int offset) +{ + const unsigned char byte = data [offset >> 3]; + unsigned int bit; + if (little_endian) + bit = offset; /* offset */ + else /* or */ + bit = ~offset; /* 7 - offset */ + bit &= 7; /* modulo 8 */ + return byte & (unsigned char)1 << bit; +} - for (i = 0; i < len; i++, s++) - { - if (*s) - { - for (j = 0; j < 8 * sizeof(char); j++) +/* Find lowest and highest used offset in a byte array. */ +/* Returns 0 if and only if all bits are unset. */ +static int +find_pos(const unsigned char * const data, + const unsigned int sizeof_data, + unsigned int * const low, + unsigned int * const high) +{ + const unsigned int last = (sizeof_data << 3) - 1; + unsigned int offset; + + for (offset = last; ! bit_is_set (data, offset); offset--) + if (! offset) /* All bits are 0. */ + return 0; + *high = offset; + + for (offset = 0; ! bit_is_set (data, offset); offset++) + {} + *low = offset; - { - if (((little_endian && ((*s) & 0x01)) || - (!little_endian && ((*s) & 0x80)))) - { - if (l > *high) - *high = l; - if (l < *low) - *low = l; - } - l++; - if (little_endian) - { - *s >>= 1; - } - else - { - *s = (char)(*s << 1); - } - } - } - else - l += 8; - } - return (*high >= 0 && (*low <= *high)) ? *low : -1; + return -1; } /* @@ -122,13 +118,13 @@ gen_reps( const name_attribute_pair * nap, /* array of name_attribute_pair records */ const char *name, /* name of the represented record type */ - int len, /* size of the record in bytes */ - int bias) + const unsigned int len, /* size of the record in bytes */ + const unsigned int bias) { - const int len_bits = (8 * len); - int i, l, low, high; + const unsigned int len_bits = len << 3; + int i, l; + unsigned int low, high; int width = strlen(RES_NAME) + 3; - unsigned long a; assert(nap != NULL); @@ -157,11 +153,8 @@ for (i = 0; nap[i].name != (char *)0; i++) if (nap[i].attr) { - a = nap[i].attr; - l = find_pos((char *)&a, sizeof(a), &low, &high); - if (l >= 0) - printf(" %-*s at 0 range %2d .. %2d;\n", width, nap[i].name, - low - bias, high - bias); + if (find_pos((unsigned char *)(&(nap[i].attr)) + bias, len, &low, &high)) + printf(" %-*s at 0 range %2d .. %2d;\n", width, nap[i].name, low, high); } printf(" end record;\n"); printf(" pragma Warnings (Off);\n"); @@ -176,10 +169,8 @@ { attr_t x = (attr_t)-1; attr_t t = x & mask; - int low, high; - int l = find_pos((char *)&t, sizeof(t), &low, &high); - - if (l >= 0) + unsigned int low, high; + if (find_pos((unsigned char *)(&t), sizeof(t), &low, &high)) printf(" %-5s at 0 range %2d .. %2d;\n", name, low, high); } @@ -200,10 +191,8 @@ static void mrep_rep(const char *name, void *rec) { - int low, high; - int l = find_pos((char *)rec, sizeof(MEVENT), &low, &high); - - if (l >= 0) + unsigned int low, high; + if (find_pos((unsigned char *)rec, sizeof(MEVENT), &low, &high)) printf(" %-7s at 0 range %3d .. %3d;\n", name, low, high); } @@ -289,7 +278,7 @@ } attr = attr >> 1; } - gen_reps(nap, name, (len + 7) / 8, little_endian ? start : 0); + gen_reps(nap, name, (len + 7) / 8, little_endian ? start >> 3 : 0); } static void @@ -312,7 +301,8 @@ {"Attributes_And_Colors", TRACE_ATTRS}, {(char *)0, 0} }; - gen_reps(nap, name, sizeof(int), 0); + gen_reps(nap, name, sizeof(unsigned int), + little_endian ? 0 : sizeof (nap[0].attr) - sizeof (unsigned int)); } static void @@ -340,7 +330,8 @@ #endif {(char *)0, 0} }; - gen_reps(nap, name, sizeof(int), 0); + gen_reps(nap, name, sizeof (Menu_Options), + little_endian ? 0 : sizeof (nap[0].attr) - sizeof (Menu_Options)); } static void @@ -353,7 +344,8 @@ #endif {(char *)0, 0} }; - gen_reps(nap, name, sizeof(int), 0); + gen_reps(nap, name, sizeof (Item_Options), + little_endian ? 0 : sizeof (nap[0].attr) - sizeof (Item_Options)); } static void @@ -369,7 +361,8 @@ #endif {(char *)0, 0} }; - gen_reps(nap, name, sizeof(int), 0); + gen_reps(nap, name, sizeof (Form_Options), + little_endian ? 0 : sizeof (nap[0].attr) - sizeof (Form_Options)); } /* @@ -412,7 +405,8 @@ #endif {(char *)0, 0} }; - gen_reps(nap, name, sizeof(int), 0); + gen_reps(nap, name, sizeof (Field_Options), + little_endian ? 0 : sizeof (nap[0].attr) - sizeof (Field_Options)); } /*