Skip to content

Instantly share code, notes, and snippets.

@mejedi
Created December 1, 2015 19:08
Show Gist options
  • Save mejedi/848bd83e70bd7ec06259 to your computer and use it in GitHub Desktop.
Save mejedi/848bd83e70bd7ec06259 to your computer and use it in GitHub Desktop.
diff --git a/sophia/database/sd_scheme.h b/sophia/database/sd_scheme.h
index 960e5c1..7ecb8df 100644
--- a/sophia/database/sd_scheme.h
+++ b/sophia/database/sd_scheme.h
@@ -53,8 +53,9 @@ sd_schemeu32(sdschemeopt *o) {
static inline uint64_t
sd_schemeu64(sdschemeopt *o) {
+ struct __C { uint64_t __v; } sspacked;
assert(o->type == SS_U64);
- return *(uint64_t*)((char*)o + sizeof(sdschemeopt));
+ return ((struct __C*)((char*)o + sizeof(sdschemeopt)))->__v;
}
int sd_schemebegin(sdscheme*, sr*);
diff --git a/sophia/index/si_branch.h b/sophia/index/si_branch.h
index 8f6d2ba..8a1b38e 100644
--- a/sophia/index/si_branch.h
+++ b/sophia/index/si_branch.h
@@ -16,7 +16,7 @@ struct sibranch {
sdindex index;
ssblob copy;
sibranch *next;
-};
+} sspacked;
static inline void
si_branchinit(sibranch *b)
diff --git a/sophia/runtime/sr_scheme.c b/sophia/runtime/sr_scheme.c
index ac99219..d6f4a2d 100644
--- a/sophia/runtime/sr_scheme.c
+++ b/sophia/runtime/sr_scheme.c
@@ -66,8 +66,9 @@ sr_cmpu32_reverse(char *a, int asz ssunused, char *b, int bsz ssunused, void *ar
static inline sshot int sr_compare_u64(const char *a, const char *b)
{
- uint64_t av = *(const uint64_t*)a;
- uint64_t bv = *(const uint64_t*)b;
+ struct __C { uint64_t __v; } sspacked;
+ uint64_t av = ((const struct __C*)a)->__v;
+ uint64_t bv = ((const struct __C*)b)->__v;
if (av == bv)
return 0;
return (av > bv) ? 1 : -1;
diff --git a/sophia/std/ss_file.h b/sophia/std/ss_file.h
index b19b68a..39fc6cb 100644
--- a/sophia/std/ss_file.h
+++ b/sophia/std/ss_file.h
@@ -17,7 +17,7 @@ struct ssfile {
uint64_t size;
char *file;
int fd;
-};
+} sspacked;
static inline void
ss_fileinit(ssfile *f, ssa *a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment