Skip to content

Commit

Permalink
deal with different versions of gcc/clang handling pragmas inconsiste…
Browse files Browse the repository at this point in the history
…ntly
  • Loading branch information
quartzjer committed Oct 5, 2014
1 parent 2a1a64f commit 4cbf3b4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion js0n.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
// by jeremie miller - 2010
// public domain, contributions/improvements welcome via github at https://github.com/quartzjer/js0n

// gcc started warning for the init syntax used here, is not helpful so don't generate the spam
// gcc started warning for the init syntax used here, is not helpful so don't generate the spam, supressing the warning is really inconsistently supported across versions
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#pragma GCC diagnostic push
#endif
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Winitializer-overrides"
#pragma GCC diagnostic ignored "-Woverride-init"

// opportunity to further optimize would be having different jump tables for higher depths
#define PUSH(i) if(depth == 1) prev = *out++ = ((cur+i) - js)
#define CAP(i) if(depth == 1) prev = *out++ = ((cur+i) - (js + prev) + 1)

// this makes a single pass across the json bytes, using each byte as an index into a jump table to build an index and transition state
int js0n(const unsigned char *js, unsigned int len, unsigned short *out, unsigned int olen)
{
unsigned short prev = 0, *oend;
Expand Down Expand Up @@ -131,4 +137,6 @@ int js0n(const unsigned char *js, unsigned int len, unsigned short *out, unsigne

}

#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#pragma GCC diagnostic pop
#endif

0 comments on commit 4cbf3b4

Please sign in to comment.