Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 vmemcache (0.8-2) unstable; urgency=medium
 .
   * Fix test failure on 32-bit archs.
   * Don't Build-Depend: valgrind where not available.
Author: Adam Borowski <kilobyte@angband.pl>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2019-04-29

--- vmemcache-0.8.orig/src/vmemcache.c
+++ vmemcache-0.8/src/vmemcache.c
@@ -120,7 +120,7 @@ vmemcache_set_size(VMEMcache *cache, siz
 		return -1;
 	}
 
-	if (size >= (1ULL << 56)) {
+	if (size >= 1ULL << ((sizeof(void *) > 4) ? 56 : 31)) {
 		ERR("implausible large size %zu", size);
 		errno = EINVAL;
 		return -1;
--- vmemcache-0.8.orig/src/vmemcache_heap.c
+++ vmemcache-0.8/src/vmemcache_heap.c
@@ -43,7 +43,7 @@
 #define IS_FREE 0
 
 /* flag: this extent is allocated */
-#define FLAG_ALLOCATED ((uint64_t)1 << 63)
+#define FLAG_ALLOCATED ((sizeof(void *) > 4) ? (1ULL << 63) : (1UL << 31))
 
 /* mask of all flags */
 #define MASK_FLAGS (~FLAG_ALLOCATED)
--- vmemcache-0.8.orig/src/util.h
+++ vmemcache-0.8/src/util.h
@@ -251,14 +251,14 @@ typedef enum {
 #define util_bool_compare_and_swap64 __sync_bool_compare_and_swap
 #define util_val_compare_and_swap32 __sync_val_compare_and_swap
 #define util_val_compare_and_swap64 __sync_val_compare_and_swap
-#define util_fetch_and_add32 __sync_fetch_and_add
-#define util_fetch_and_add64 __sync_fetch_and_add
-#define util_fetch_and_sub32 __sync_fetch_and_sub
-#define util_fetch_and_sub64 __sync_fetch_and_sub
-#define util_fetch_and_and32 __sync_fetch_and_and
-#define util_fetch_and_and64 __sync_fetch_and_and
-#define util_fetch_and_or32 __sync_fetch_and_or
-#define util_fetch_and_or64 __sync_fetch_and_or
+#define util_fetch_and_add32(ptr,val) __atomic_fetch_add(ptr, val, __ATOMIC_SEQ_CST)
+#define util_fetch_and_add64(ptr,val) __atomic_fetch_add(ptr, val, __ATOMIC_SEQ_CST)
+#define util_fetch_and_sub32(ptr,val) __atomic_fetch_sub(ptr, val, __ATOMIC_SEQ_CST)
+#define util_fetch_and_sub64(ptr,val) __atomic_fetch_sub(ptr, val, __ATOMIC_SEQ_CST)
+#define util_fetch_and_and32(ptr,val) __atomic_fetch_and(ptr, val, __ATOMIC_SEQ_CST)
+#define util_fetch_and_and64(ptr,val) __atomic_fetch_and(ptr, val, __ATOMIC_SEQ_CST)
+#define util_fetch_and_or32(ptr,val) __atomic_fetch_or(ptr, val, __ATOMIC_SEQ_CST)
+#define util_fetch_and_or64(ptr,val) __atomic_fetch_or(ptr, val, __ATOMIC_SEQ_CST)
 #define util_synchronize __sync_synchronize
 #define util_popcount(value) ((unsigned char)__builtin_popcount(value))
 #define util_popcount64(value) ((unsigned char)__builtin_popcountll(value))
