re-enable alignment test on all targets
authorYann Collet <cyan@fb.com>
Sat, 7 Nov 2020 00:43:14 +0000 (16:43 -0800)
committerYann Collet <cyan@fb.com>
Sat, 7 Nov 2020 00:43:14 +0000 (16:43 -0800)
lib/README.md
lib/lz4.c
lib/lz4.h

index 7a9e4fd491ff3f58317f6624527af529946dc4cd..ee5d3ba2d5cbb04dac2aafa47afbe96af893daf7 100644 (file)
@@ -77,8 +77,9 @@ The following build macro can be selected to adjust source code behavior at comp
   In most cases, it's not expected to be necessary,
   but it can be legitimately considered for less common platforms.
 
-- `LZ4_ALIGN_TEST` : disable state alignment test when set to 0.
-  Is generally enabled by default, except on win32+visual.
+- `LZ4_ALIGN_TEST` : alignment test ensures that the memory area
+  passed as argument to become a compression state is suitable aligned.
+  This test can be disabled, if it proves flaky, by setting this value to 0.
 
 
 #### Amalgamation
index 9e6abbaacac7ced4155609b2bf31220850ec55ff..c902654a9cc482e1cc91ec0d9cab145ad518aae8 100644 (file)
--- a/lib/lz4.c
+++ b/lib/lz4.c
 #define unlikely(expr)   expect((expr) != 0, 0)
 #endif
 
-/* for some reason, Visual Studio can fail the aligment test on 32-bit x86 :
- * it sometimes report an aligment of 8-bytes (at least in some configurations),
- * while only providing a `malloc()` memory area aligned on 4-bytes,
- * which is inconsistent with malloc() contract.
- * The source of the issue is still unclear.
- * Mitigation : made the alignment test optional */
+/* Should the alignment test prove unreliable, for some reason,
+ * it can be disabled by setting LZ4_ALIGN_TEST to 0 */
 #ifndef LZ4_ALIGN_TEST  /* can be externally provided */
-#  if (defined(_MSC_VER) && !defined(_M_X64))
-#    define LZ4_ALIGN_TEST 0  /* disable on win32+visual */
-#  else
-#    define LZ4_ALIGN_TEST 1
-#  endif
+# define LZ4_ALIGN_TEST 1
 #endif
 
 
@@ -476,7 +468,7 @@ LZ4_memcpy_using_offset(BYTE* dstPtr, const BYTE* srcPtr, BYTE* dstEnd, const si
 
     switch(offset) {
     case 1:
-        memset(v, *srcPtr, 8);
+        MEM_INIT(v, *srcPtr, 8);
         break;
     case 2:
         LZ4_memcpy(v, srcPtr, 2);
@@ -1441,7 +1433,7 @@ LZ4_stream_t* LZ4_initStream (void* buffer, size_t size)
     if (buffer == NULL) { return NULL; }
     if (size < sizeof(LZ4_stream_t)) { return NULL; }
     if (!LZ4_isAligned(buffer, LZ4_stream_t_alignment())) return NULL;
-    MEM_INIT(buffer, 0, sizeof(LZ4_stream_t));
+    MEM_INIT(buffer, 0, sizeof(LZ4_stream_t_internal));
     return (LZ4_stream_t*)buffer;
 }
 
@@ -1450,7 +1442,7 @@ LZ4_stream_t* LZ4_initStream (void* buffer, size_t size)
 void LZ4_resetStream (LZ4_stream_t* LZ4_stream)
 {
     DEBUGLOG(5, "LZ4_resetStream (ctx:%p)", LZ4_stream);
-    MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t));
+    MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t_internal));
 }
 
 void LZ4_resetStream_fast(LZ4_stream_t* ctx) {
index 78c25427ffaf712e4886df4ac7d3cf30612187eb..026279bd73cdb8558e61d0d6fbb951e11ddf8a8a 100644 (file)
--- a/lib/lz4.h
+++ b/lib/lz4.h
@@ -618,7 +618,7 @@ typedef struct {
  *  (on stack, or as part of larger structure).
  *  Init this structure with LZ4_initStream() before first use.
  *  note : only use this definition in association with static linking !
- *    this definition is not API/ABI safe, and may change in future versions.
+ *  this definition is not API/ABI safe, and may change in future versions.
  */
 #define LZ4_STREAMSIZE_VOIDP ((sizeof(LZ4_stream_t_internal) + sizeof(void*)-1) / sizeof(void*))
 #define LZ4_STREAMSIZE       (LZ4_STREAMSIZE_VOIDP * sizeof(void*))