diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2019-08-29 18:42:26 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-09-01 22:44:45 -0400 |
commit | 9acba78004d4d4a149b9e1480d1d8c44b7a27cec (patch) | |
tree | 3bea723ccd1cccf43f9fcce550addb3c2c36da14 | |
parent | cfab4abeaffa8b6a78a19bbfa485169a9c772741 (diff) | |
download | haskell-9acba78004d4d4a149b9e1480d1d8c44b7a27cec.tar.gz |
Use C99 Fixed width types to avoid hack in base's configure
Define MD5Context in terms of `uint*_t` and don't use `HsFFI.h`.
-rw-r--r-- | hadrian/src/Settings/Builders/Cabal.hs | 3 | ||||
-rw-r--r-- | libraries/base/cbits/md5.c | 30 | ||||
-rw-r--r-- | libraries/base/configure.ac | 2 | ||||
-rw-r--r-- | libraries/base/include/md5.h | 17 | ||||
-rw-r--r-- | rules/build-package-data.mk | 4 |
5 files changed, 27 insertions, 29 deletions
diff --git a/hadrian/src/Settings/Builders/Cabal.hs b/hadrian/src/Settings/Builders/Cabal.hs index bf6322f14f..96f67b4abf 100644 --- a/hadrian/src/Settings/Builders/Cabal.hs +++ b/hadrian/src/Settings/Builders/Cabal.hs @@ -109,7 +109,8 @@ configureArgs = do , getStagedSettingList ConfCcArgs , arg $ "-I" ++ top -/- root -/- generatedDir -- See https://github.com/snowleopard/hadrian/issues/523 - , arg $ "-I" ++ top -/- pkgPath pkg + , arg $ "-iquote" + , arg $ top -/- pkgPath pkg , arg $ "-I" ++ top -/- "includes" ] ldFlags = ldArgs <> (getStagedSettingList ConfGccLinkerArgs) cppFlags = cppArgs <> (getStagedSettingList ConfCppArgs) diff --git a/libraries/base/cbits/md5.c b/libraries/base/cbits/md5.c index 0c019be290..0d93a8f1f1 100644 --- a/libraries/base/cbits/md5.c +++ b/libraries/base/cbits/md5.c @@ -20,9 +20,9 @@ #include <string.h> void __hsbase_MD5Init(struct MD5Context *context); -void __hsbase_MD5Update(struct MD5Context *context, byte const *buf, int len); -void __hsbase_MD5Final(byte digest[16], struct MD5Context *context); -void __hsbase_MD5Transform(word32 buf[4], word32 const in[16]); +void __hsbase_MD5Update(struct MD5Context *context, uint8_t const *buf, int len); +void __hsbase_MD5Final(uint8_t digest[16], struct MD5Context *context); +void __hsbase_MD5Transform(uint32_t buf[4], uint32_t const in[16]); /* @@ -30,12 +30,12 @@ void __hsbase_MD5Transform(word32 buf[4], word32 const in[16]); * MD5 spec. Note: this code works regardless of the byte order. */ static void -byteSwap(word32 *buf, unsigned words) +byteSwap(uint32_t *buf, unsigned words) { - byte *p = (byte *)buf; + uint8_t *p = (uint8_t *)buf; do { - *buf++ = (word32)((unsigned)p[3] << 8 | p[2]) << 16 | + *buf++ = (uint32_t)((unsigned)p[3] << 8 | p[2]) << 16 | ((unsigned)p[1] << 8 | p[0]); p += 4; } while (--words); @@ -62,9 +62,9 @@ __hsbase_MD5Init(struct MD5Context *ctx) * of bytes. */ void -__hsbase_MD5Update(struct MD5Context *ctx, byte const *buf, int len) +__hsbase_MD5Update(struct MD5Context *ctx, uint8_t const *buf, int len) { - word32 t; + uint32_t t; /* Update byte count */ @@ -74,11 +74,11 @@ __hsbase_MD5Update(struct MD5Context *ctx, byte const *buf, int len) t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */ if ((unsigned)t > len) { - memcpy((byte *)ctx->in + 64 - (unsigned)t, buf, len); + memcpy((uint8_t *)ctx->in + 64 - (unsigned)t, buf, len); return; } /* First chunk is an odd size */ - memcpy((byte *)ctx->in + 64 - (unsigned)t, buf, (unsigned)t); + memcpy((uint8_t *)ctx->in + 64 - (unsigned)t, buf, (unsigned)t); byteSwap(ctx->in, 16); __hsbase_MD5Transform(ctx->buf, ctx->in); buf += (unsigned)t; @@ -102,10 +102,10 @@ __hsbase_MD5Update(struct MD5Context *ctx, byte const *buf, int len) * 1 0* (64-bit count of bits processed, MSB-first) */ void -__hsbase_MD5Final(byte digest[16], struct MD5Context *ctx) +__hsbase_MD5Final(uint8_t digest[16], struct MD5Context *ctx) { int count = (int)(ctx->bytes[0] & 0x3f); /* Bytes in ctx->in */ - byte *p = (byte *)ctx->in + count; /* First unused byte */ + uint8_t *p = (uint8_t *)ctx->in + count; /* First unused byte */ /* Set the first char of padding to 0x80. There is always room. */ *p++ = 0x80; @@ -117,7 +117,7 @@ __hsbase_MD5Final(byte digest[16], struct MD5Context *ctx) memset(p, 0, count+8); byteSwap(ctx->in, 16); __hsbase_MD5Transform(ctx->buf, ctx->in); - p = (byte *)ctx->in; + p = (uint8_t *)ctx->in; count = 56; } memset(p, 0, count+8); @@ -153,9 +153,9 @@ __hsbase_MD5Final(byte digest[16], struct MD5Context *ctx) */ void -__hsbase_MD5Transform(word32 buf[4], word32 const in[16]) +__hsbase_MD5Transform(uint32_t buf[4], uint32_t const in[16]) { - register word32 a, b, c, d; + register uint32_t a, b, c, d; a = buf[0]; b = buf[1]; diff --git a/libraries/base/configure.ac b/libraries/base/configure.ac index a141a25a90..0fe2ca52c2 100644 --- a/libraries/base/configure.ac +++ b/libraries/base/configure.ac @@ -233,8 +233,6 @@ AS_IF([test "x$with_libcharset" != xno], fi -# Hack - md5.h needs HsFFI.h. Is there a better way to do this? -CFLAGS="-I../.. -I../../../../includes $CFLAGS" dnl Calling AC_CHECK_TYPE(T) makes AC_CHECK_SIZEOF(T) abort on failure dnl instead of considering sizeof(T) as 0. AC_CHECK_TYPE([struct MD5Context], [], [AC_MSG_ERROR([internal error])], [#include "include/md5.h"]) diff --git a/libraries/base/include/md5.h b/libraries/base/include/md5.h index a1b6157075..8d3441617a 100644 --- a/libraries/base/include/md5.h +++ b/libraries/base/include/md5.h @@ -1,18 +1,15 @@ /* MD5 message digest */ #pragma once -#include "HsFFI.h" - -typedef HsWord32 word32; -typedef HsWord8 byte; +#include <stdint.h> struct MD5Context { - word32 buf[4]; - word32 bytes[2]; - word32 in[16]; + uint32_t buf[4]; + uint32_t bytes[2]; + uint32_t in[16]; }; void __hsbase_MD5Init(struct MD5Context *context); -void __hsbase_MD5Update(struct MD5Context *context, byte const *buf, int len); -void __hsbase_MD5Final(byte digest[16], struct MD5Context *context); -void __hsbase_MD5Transform(word32 buf[4], word32 const in[16]); +void __hsbase_MD5Update(struct MD5Context *context, uint8_t const *buf, int len); +void __hsbase_MD5Final(uint8_t digest[16], struct MD5Context *context); +void __hsbase_MD5Transform(uint32_t buf[4], uint32_t const in[16]); diff --git a/rules/build-package-data.mk b/rules/build-package-data.mk index 49c54461d2..1c5987e63d 100644 --- a/rules/build-package-data.mk +++ b/rules/build-package-data.mk @@ -62,7 +62,9 @@ endif # We filter out -Werror from SRC_CC_OPTS, because when configure tests # for a feature it may not generate warning-free C code, and thus may # think that the feature doesn't exist if -Werror is on. -$1_$2_CONFIGURE_CFLAGS = $$(filter-out -Werror,$$(SRC_CC_OPTS)) $$(CONF_CC_OPTS_STAGE$3) $$($1_CC_OPTS) $$($1_$2_CC_OPTS) $$(SRC_CC_WARNING_OPTS) +# +# Do `-iquote $(TOP)/$1` so package configure scripts can access their own source. +$1_$2_CONFIGURE_CFLAGS = $$(filter-out -Werror,$$(SRC_CC_OPTS)) $$(CONF_CC_OPTS_STAGE$3) $$($1_CC_OPTS) $$($1_$2_CC_OPTS) $$(SRC_CC_WARNING_OPTS) -iquote $(TOP)/$1 $1_$2_CONFIGURE_LDFLAGS = $$(SRC_LD_OPTS) $$($1_LD_OPTS) $$($1_$2_LD_OPTS) $1_$2_CONFIGURE_CPPFLAGS = $$(SRC_CPP_OPTS) $$(CONF_CPP_OPTS_STAGE$3) $$($1_CPP_OPTS) $$($1_$2_CPP_OPTS) |