Skip to content

Commit

Permalink
improve how calc compiles on big endian machines
Browse files Browse the repository at this point in the history
Fixed bug that caused calc to fail to compile filepos2z() in file.c
on little endian machines for the Debian apcalc package.  Thanks to
Martin Buck (m at rtin-buck dor de) for for fix.

Removed unused macros from zmath.h:

    SWAP_B32_IN_HASH(dest, src)
    SWAP_B16_IN_HASH(dest, src)
    SWAP_B8_IN_HASH(dest, src)
    SWAP_B32_IN_FLAG(dest, src)
    SWAP_B16_IN_FLAG(dest, src)
    SWAP_B8_IN_FLAG(dest, src)

When SWAP_HALF_IN_B32(dest, src), SWAP_B32_IN_FULL(dest, src),
SWAP_B16_IN_HALF(dest, src), SWAP_B32_IN_bool(dest, src),
or SWAP_B32_IN_LEN(dest, src), SWAP_HALF_IN_FILEPOS(dest, src)
is an assignment such as:

    (*(dest) = *(src))

We now case the dest and src pointers to the proper type before
referencing and performing the assignment.
  • Loading branch information
lcn2 committed Dec 15, 2023
1 parent 8d6f83a commit d91e966
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
26 changes: 26 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
The following are the changes from calc version 2.15.0.3 to date:

Fixed bug that caused calc to fail to compile filepos2z() in file.c
on little endian machines for the Debian apcalc package. Thanks to
Martin Buck (m at rtin-buck dor de) for for fix.

Removed unused macros from zmath.h:

SWAP_B32_IN_HASH(dest, src)
SWAP_B16_IN_HASH(dest, src)
SWAP_B8_IN_HASH(dest, src)
SWAP_B32_IN_FLAG(dest, src)
SWAP_B16_IN_FLAG(dest, src)
SWAP_B8_IN_FLAG(dest, src)

When SWAP_HALF_IN_B32(dest, src), SWAP_B32_IN_FULL(dest, src),
SWAP_B16_IN_HALF(dest, src), SWAP_B32_IN_bool(dest, src),
or SWAP_B32_IN_LEN(dest, src), SWAP_HALF_IN_FILEPOS(dest, src)
is an assignment such as:

(*(dest) = *(src))

We now case the dest and src pointers to the proper type before
referencing and performing the assignment.


The following are the changes from calc version 2.15.0.1 to 2.15.0.2:

Updated BUGS about MSYS2 on Windows compiling of calc.
Expand Down
2 changes: 1 addition & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ filepos2z(FILEPOS pos)
ret.len = FILEPOS_BITS/BASEB;
ret.v = alloc(ret.len);
zclearval(ret);
SWAP_HALF_IN_FILEPOS(ret.v, &pos);
SWAP_HALF_IN_FILEPOS(ret.v, (HALF *)&pos);
ret.sign = 0;
ztrim(&ret);

Expand Down
2 changes: 1 addition & 1 deletion fposval.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ main(int UNUSED(argc), char **argv)
*/
#if defined(HAVE_FILEPOS_SCALAR)
printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
"\t(*(dest) = *(src))\n");
"\t(*((HALF *)(dest)) = *((HALF *)(src)))\n");
#else /* HAVE_FILEPOS_SCALAR */
/*
* Normally a "(*(dest) = *(src))" would do, but on some
Expand Down
18 changes: 5 additions & 13 deletions zmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ typedef USB64 FULL; /* double unit of number storage */
typedef SB64 SFULL; /* signed FULL */

#define SWAP_HALF_IN_B64(dest, src) SWAP_B32_IN_B64(dest, src)
#define SWAP_HALF_IN_B32(dest, src) (*(dest) = *(src))
#define SWAP_HALF_IN_B32(dest, src) (*((HALF *)(dest)) = *((HALF *)(src)))
#define SWAP_HALF_IN_FULL(dest, src) SWAP_B32_IN_B64(dest, src)
#define SWAP_HALF_IN_HASH(dest, src) SWAP_B16_IN_HASH(dest, src)
#define SWAP_HALF_IN_FLAG(dest, src) SWAP_B16_IN_FLAG(dest, src)
Expand All @@ -106,9 +106,9 @@ typedef SB32 SFULL; /* signed FULL */
#define SWAP_HALF_IN_FLAG(dest, src) SWAP_B16_IN_FLAG(dest, src)
#define SWAP_HALF_IN_bool(dest, src) SWAP_B16_IN_bool(dest, src)
#define SWAP_HALF_IN_LEN(dest, src) SWAP_B16_IN_LEN(dest, src)
#define SWAP_B32_IN_FULL(dest, src) (*(dest) = *(src))
#define SWAP_B32_IN_FULL(dest, src) (*((FULL *)(dest)) = *((FULL *)(src)))
#define SWAP_B16_IN_FULL(dest, src) SWAP_B16_IN_B32(dest, src)
#define SWAP_B16_IN_HALF(dest, src) (*(dest) = *(src))
#define SWAP_B16_IN_HALF(dest, src) (*((HALF *)(dest)) = *((HALF *)(src)))
#define SWAP_B8_IN_FULL(dest, src) SWAP_B8_IN_B32(dest, src)
#define SWAP_B8_IN_HALF(dest, src) SWAP_B8_IN_B16(dest, src)

Expand Down Expand Up @@ -171,19 +171,11 @@ typedef SB32 LEN; /* calc v2 compatible unit of length storage */
typedef uintptr_t LEN; /* unit of length storage */
#endif /* MAJOR_VER < 3 */

#define SWAP_B32_IN_HASH(dest, src) (*(dest) = *(src))
#define SWAP_B16_IN_HASH(dest, src) SWAP_B16_IN_B32(dest, src)
#define SWAP_B8_IN_HASH(dest, src) SWAP_B8_IN_B32(dest, src)

#define SWAP_B32_IN_FLAG(dest, src) (*(dest) = *(src))
#define SWAP_B16_IN_FLAG(dest, src) SWAP_B16_IN_B32(dest, src)
#define SWAP_B8_IN_FLAG(dest, src) SWAP_B8_IN_B32(dest, src)

#define SWAP_B32_IN_bool(dest, src) (*(dest) = *(src))
#define SWAP_B32_IN_bool(dest, src) (*((bool *)(dest)) = *((bool *)(src)))
#define SWAP_B16_IN_bool(dest, src) SWAP_B16_IN_B32(dest, src)
#define SWAP_B8_IN_bool(dest, src) SWAP_B8_IN_B32(dest, src)

#define SWAP_B32_IN_LEN(dest, src) (*(dest) = *(src))
#define SWAP_B32_IN_LEN(dest, src) (*((LEN *)(dest)) = *((LEN *)(src)))
#define SWAP_B16_IN_LEN(dest, src) SWAP_B16_IN_B32(dest, src)
#define SWAP_B8_IN_LEN(dest, src) SWAP_B8_IN_B32(dest, src)

Expand Down

0 comments on commit d91e966

Please sign in to comment.